1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
//------------------------------------------------------------------------------ |
4
|
|
|
// |
5
|
|
|
// eTraxis - Records tracking web-based system |
6
|
|
|
// Copyright (C) 2005-2011 Artem Rodygin |
7
|
|
|
// |
8
|
|
|
// This program is free software: you can redistribute it and/or modify |
9
|
|
|
// it under the terms of the GNU General Public License as published by |
10
|
|
|
// the Free Software Foundation, either version 3 of the License, or |
11
|
|
|
// (at your option) any later version. |
12
|
|
|
// |
13
|
|
|
// This program is distributed in the hope that it will be useful, |
14
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16
|
|
|
// GNU General Public License for more details. |
17
|
|
|
// |
18
|
|
|
// You should have received a copy of the GNU General Public License |
19
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. |
20
|
|
|
// |
21
|
|
|
//------------------------------------------------------------------------------ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @package eTraxis |
25
|
|
|
* @ignore |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
|
/**#@+ |
29
|
|
|
* Dependency. |
30
|
|
|
*/ |
31
|
|
|
require_once('../engine/engine.php'); |
32
|
|
|
require_once('../dbo/groups.php'); |
33
|
|
|
require_once('../dbo/projects.php'); |
34
|
|
|
/**#@-*/ |
35
|
|
|
|
36
|
|
|
init_page(LOAD_INLINE); |
37
|
|
|
|
38
|
|
|
$error = NO_ERROR; |
39
|
|
|
|
40
|
|
|
if (get_user_level() != USER_LEVEL_ADMIN) |
41
|
|
|
{ |
42
|
|
|
debug_write_log(DEBUG_NOTICE, 'User must have admin rights to be allowed.'); |
43
|
|
|
header('HTTP/1.1 307 index.php'); |
44
|
|
|
exit; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
// check that requested project exists |
48
|
|
|
|
49
|
|
|
$id = ustr2int(try_request('id')); |
50
|
|
|
$project = project_find($id); |
51
|
|
|
|
52
|
|
|
if (!$project) |
|
|
|
|
53
|
|
|
{ |
54
|
|
|
debug_write_log(DEBUG_NOTICE, 'Project cannot be found.'); |
55
|
|
|
header('HTTP/1.1 307 index.php'); |
56
|
|
|
exit; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
// new group has been submitted |
60
|
|
|
|
61
|
|
View Code Duplication |
if (try_request('submitted') == 'createform') |
62
|
|
|
{ |
63
|
|
|
debug_write_log(DEBUG_NOTICE, 'Data are submitted.'); |
64
|
|
|
|
65
|
|
|
$group_name = ustrcut($_REQUEST['group_name'], MAX_GROUP_NAME); |
66
|
|
|
$description = ustrcut($_REQUEST['description'], MAX_GROUP_DESCRIPTION); |
67
|
|
|
|
68
|
|
|
$error = group_validate($group_name); |
69
|
|
|
|
70
|
|
|
if ($error == NO_ERROR) |
71
|
|
|
{ |
72
|
|
|
$error = group_create($id, $group_name, $description); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
switch ($error) |
76
|
|
|
{ |
77
|
|
|
case NO_ERROR: |
78
|
|
|
header('HTTP/1.0 200 OK'); |
79
|
|
|
break; |
80
|
|
|
|
81
|
|
|
case ERROR_INCOMPLETE_FORM: |
82
|
|
|
send_http_error(get_html_resource(RES_ALERT_REQUIRED_ARE_EMPTY_ID)); |
83
|
|
|
break; |
84
|
|
|
|
85
|
|
|
case ERROR_ALREADY_EXISTS: |
86
|
|
|
send_http_error(get_html_resource(RES_ALERT_GROUP_ALREADY_EXISTS_ID)); |
87
|
|
|
break; |
88
|
|
|
|
89
|
|
|
default: |
90
|
|
|
send_http_error(get_html_resource(RES_ALERT_UNKNOWN_ERROR_ID)); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
exit; |
94
|
|
|
} |
95
|
|
|
else |
96
|
|
|
{ |
97
|
|
|
debug_write_log(DEBUG_NOTICE, 'Data are being requested.'); |
98
|
|
|
|
99
|
|
|
$group_name = NULL; |
100
|
|
|
$description = NULL; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
// local JS functions |
104
|
|
|
|
105
|
|
|
$resTitle = get_js_resource(RES_ERROR_ID); |
106
|
|
|
$resOK = get_js_resource(RES_OK_ID); |
107
|
|
|
|
108
|
|
|
$xml = <<<JQUERY |
109
|
|
|
<script> |
110
|
|
|
|
111
|
|
|
function createSuccess () |
112
|
|
|
{ |
113
|
|
|
closeModal(); |
114
|
|
|
reloadTab(); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
function createError (XMLHttpRequest) |
118
|
|
|
{ |
119
|
|
|
jqAlert("{$resTitle}", XMLHttpRequest.responseText, "{$resOK}"); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
</script> |
123
|
|
|
JQUERY; |
124
|
|
|
|
125
|
|
|
// generate page |
126
|
|
|
|
127
|
|
|
$xml .= '<form name="createform" action="gcreate.php?id=' . $id . '" success="createSuccess" error="createError">' |
128
|
|
|
. '<group>' |
129
|
|
|
. '<control name="group_name" required="' . get_html_resource(RES_REQUIRED3_ID) . '">' |
130
|
|
|
. '<label>' . get_html_resource(RES_GROUP_NAME_ID) . '</label>' |
131
|
|
|
. '<editbox maxlen="' . MAX_GROUP_NAME . '">' . ustr2html($group_name) . '</editbox>' |
132
|
|
|
. '</control>' |
133
|
|
|
. '<control name="description">' |
134
|
|
|
. '<label>' . get_html_resource(RES_DESCRIPTION_ID) . '</label>' |
135
|
|
|
. '<editbox maxlen="' . MAX_GROUP_DESCRIPTION . '">' . ustr2html($description) . '</editbox>' |
136
|
|
|
. '</control>' |
137
|
|
|
. '</group>' |
138
|
|
|
. '<note>' . get_html_resource(RES_ALERT_REQUIRED_ARE_EMPTY_ID) . '</note>' |
139
|
|
|
. '</form>'; |
140
|
|
|
|
141
|
|
|
echo(xml2html($xml)); |
142
|
|
|
|
143
|
|
|
?> |
|
|
|
|
144
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.