Skip to content

Commit f50ae31

Browse files
committed
Update patterns_edit.inc.php
Fix of error with DB strict mode enabled.
1 parent 8c49fde commit f50ae31

File tree

1 file changed

+133
-188
lines changed

1 file changed

+133
-188
lines changed
+133-188
Original file line numberDiff line numberDiff line change
@@ -1,222 +1,167 @@
11
<?php
2-
/*
3-
* @version 0.1 (wizard)
4-
*/
5-
6-
global $parent_id;
7-
$out['PARENT_ID']=$parent_id;
8-
9-
if(defined('SETTINGS_CODEEDITOR_TURNONSETTINGS')) {
10-
$out['SETTINGS_CODEEDITOR_TURNONSETTINGS'] = SETTINGS_CODEEDITOR_TURNONSETTINGS;
11-
$out['SETTINGS_CODEEDITOR_UPTOLINE'] = SETTINGS_CODEEDITOR_UPTOLINE;
12-
$out['SETTINGS_CODEEDITOR_SHOWERROR'] = SETTINGS_CODEEDITOR_SHOWERROR;
13-
}
14-
15-
if ($this->owner->name=='panel') {
16-
$out['CONTROLPANEL']=1;
17-
}
18-
$table_name='patterns';
19-
$rec=SQLSelectOne("SELECT * FROM $table_name WHERE ID='$id'");
20-
if ($this->mode=='update') {
21-
$ok=1;
22-
//updating 'TITLE' (varchar, required)
23-
global $title;
24-
$rec['TITLE']=$title;
25-
if ($rec['TITLE']=='') {
26-
$out['ERR_TITLE']=1;
27-
$ok=0;
28-
}
29-
//updating 'PATTERN' (text)
30-
global $pattern;
31-
$rec['PATTERN']=$pattern;
32-
//updating 'SCRIPT_ID' (int)
33-
34-
global $script;
35-
36-
$old_code=$rec['SCRIPT'];
37-
$rec['SCRIPT'] = trim($script);
38-
39-
if ($rec['SCRIPT']!='') {
40-
$errors = php_syntax_error($rec['SCRIPT']);
41-
2+
3+
$out['PARENT_ID'] = gr('$parent_id');
4+
5+
if (defined('SETTINGS_CODEEDITOR_TURNONSETTINGS')) {
6+
$out['SETTINGS_CODEEDITOR_TURNONSETTINGS'] = SETTINGS_CODEEDITOR_TURNONSETTINGS;
7+
$out['SETTINGS_CODEEDITOR_UPTOLINE'] = SETTINGS_CODEEDITOR_UPTOLINE;
8+
$out['SETTINGS_CODEEDITOR_SHOWERROR'] = SETTINGS_CODEEDITOR_SHOWERROR;
9+
}
10+
11+
if ($this->owner->name == 'panel') {
12+
$out['CONTROLPANEL'] = 1;
13+
}
14+
$table_name = 'patterns';
15+
$rec = SQLSelectOne("SELECT * FROM $table_name WHERE ID='$id'");
16+
17+
if ($this->mode == 'update') {
18+
$ok = 1;
19+
$rec['TITLE'] = gr('title');
20+
if ($rec['TITLE'] == '') {
21+
$out['ERR_TITLE'] = 1;
22+
$ok = 0;
23+
}
24+
25+
$rec['PATTERN'] = gr('pattern');
26+
$script = gr('script');
27+
$old_code = $rec['SCRIPT'];
28+
$rec['SCRIPT'] = trim($script);
29+
30+
if ($rec['SCRIPT'] != '') {
31+
$errors = php_syntax_error($rec['SCRIPT']);
32+
4233
if ($errors) {
43-
$out['ERR_LINE'] = preg_replace('/[^0-9]/', '', substr(stristr($errors, 'php on line '), 0, 18))-2;
34+
$out['ERR_LINE'] = preg_replace('/[^0-9]/', '', substr(stristr($errors, 'php on line '), 0, 18)) - 2;
4435
$out['ERR_CODE'] = 1;
45-
$errorStr = explode('Parse error: ', htmlspecialchars(strip_tags(nl2br($errors))));
46-
$errorStr = explode('Errors parsing', $errorStr[1]);
47-
$errorStr = explode(' in ', $errorStr[0]);
48-
//var_dump($errorStr);
36+
$errorStr = explode('Parse error: ', htmlspecialchars(strip_tags(nl2br($errors))));
37+
$errorStr = explode('Errors parsing', $errorStr[1]);
38+
$errorStr = explode(' in ', $errorStr[0]);
39+
//var_dump($errorStr);
4940
$out['ERRORS'] = $errorStr[0];
50-
$out['ERR_FULL'] = $errorStr[0].' '.$errorStr[1];
51-
$out['ERR_OLD_CODE'] = $old_code;
41+
$out['ERR_FULL'] = $errorStr[0] . ' ' . $errorStr[1];
42+
$out['ERR_OLD_CODE'] = $old_code;
5243
$ok = 0;
5344
}
54-
}
55-
56-
57-
if (file_exists(ROOT . "lib/phpmorphy/common.php")) {
58-
global $usemorphy;
59-
$rec['USEMORPHY']=(int)$usemorphy;
60-
}
61-
62-
global $script_exit;
63-
global $use_script_exit;
64-
65-
if (!$use_script_exit) {
66-
$script_exit='';
67-
}
68-
69-
$rec['SCRIPT_EXIT']=trim($script_exit);
70-
71-
if ($rec['SCRIPT_EXIT']!='') {
72-
$errors=php_syntax_error($rec['SCRIPT_EXIT']);
73-
if ($errors) {
74-
$out['ERR_SCRIPT_EXIT']=1;
75-
$out['ERRORS_SCRIPT_EXIT']=nl2br($errors);
76-
$ok=0;
7745
}
78-
}
79-
8046

81-
if (!$rec['ID']) {
82-
global $pattern_type;
83-
$rec['PATTERN_TYPE']=(int)$pattern_type;
84-
}
8547

86-
87-
global $run_type;
88-
89-
if ($run_type=='script') {
90-
global $script_id;
91-
$rec['SCRIPT_ID']=$script_id;
92-
} else {
93-
$rec['SCRIPT_ID']=0;
94-
}
95-
96-
97-
98-
if ($rec['SCRIPT']!='' && $run_type=='code') {
99-
//echo $content;
100-
$errors=php_syntax_error($rec['SCRIPT']);
101-
if ($errors) {
102-
$out['ERR_SCRIPT']=1;
103-
$out['ERRORS']=nl2br($errors);
104-
$ok=0;
48+
if (file_exists(ROOT . "lib/phpmorphy/common.php")) {
49+
$rec['USEMORPHY'] = gr('usemorphy', 'int');
10550
}
106-
}
107-
108-
//updating 'TIME_LIMIT' (int, required)
109-
global $time_limit;
110-
$rec['TIME_LIMIT']=(int)$time_limit;
111-
/*
112-
if (!$rec['TIME_LIMIT']) {
113-
$out['ERR_TIME_LIMIT']=1;
114-
$ok=0;
115-
}
116-
*/
117-
118-
global $is_context;
119-
$rec['IS_CONTEXT']=(int)$is_context;
120-
121-
global $is_common_context;
122-
$rec['IS_COMMON_CONTEXT']=(int)$is_common_context;
123-
124-
global $matched_context_id;
125-
$rec['MATCHED_CONTEXT_ID']=(int)$matched_context_id;
126-
127-
global $timeout;
128-
$rec['TIMEOUT']=(int)$timeout;
129-
130-
global $is_last;
131-
$rec['IS_LAST']=(int)$is_last;
132-
133-
global $priority;
134-
$rec['PRIORITY']=(int)$priority;
135-
136-
global $skipsystem;
137-
$rec['SKIPSYSTEM']=(int)$skipsystem;
138-
139-
global $onetime;
140-
$rec['ONETIME']=(int)$onetime;
14151

52+
$script_exit = gr('script_exit');
53+
$use_script_exit = gr('use_script_exit');
54+
if (!$use_script_exit) {
55+
$script_exit = '';
56+
}
14257

58+
$rec['SCRIPT_EXIT'] = trim($script_exit);
14359

144-
global $timeout_context_id;
145-
$rec['TIMEOUT_CONTEXT_ID']=(int)$timeout_context_id;
60+
if ($rec['SCRIPT_EXIT'] != '') {
61+
$errors = php_syntax_error($rec['SCRIPT_EXIT']);
62+
if ($errors) {
63+
$out['ERR_SCRIPT_EXIT'] = 1;
64+
$out['ERRORS_SCRIPT_EXIT'] = nl2br($errors);
65+
$ok = 0;
66+
}
67+
}
14668

14769

148-
global $timeout_script;
149-
if ($timeout_script!='') {
150-
$rec['TIMEOUT_SCRIPT']=$timeout_script;
151-
$errors=php_syntax_error($rec['TIMEOUT_SCRIPT']);
152-
if ($errors) {
153-
$out['ERR_TIMEOUT_SCRIPT']=1;
154-
$out['ERRORS_TIMEOUT_SCRIPT']=nl2br($errors);
155-
$ok=0;
70+
if (!$rec['ID']) {
71+
$rec['PATTERN_TYPE'] = gr('pattern_type', 'int');
15672
}
157-
} else {
158-
$rec['TIMEOUT_SCRIPT']='';
159-
}
16073

16174

162-
$rec['PARENT_ID']=(int)$parent_id;
75+
$run_type = gr('run_type');
16376

164-
if ($rec['PATTERN_TYPE']==1) {
165-
$rec['PARENT_ID']=0;
77+
if ($run_type == 'script') {
78+
$rec['SCRIPT_ID'] = gr('script_id', 'int');
79+
} else {
80+
$rec['SCRIPT_ID'] = 0;
81+
}
16682

167-
global $linked_object;
168-
$rec['LINKED_OBJECT']=$linked_object;
16983

170-
global $linked_property;
171-
$rec['LINKED_PROPERTY']=$linked_property;
84+
if ($rec['SCRIPT'] != '' && $run_type == 'code') {
85+
//echo $content;
86+
$errors = php_syntax_error($rec['SCRIPT']);
87+
if ($errors) {
88+
$out['ERR_SCRIPT'] = 1;
89+
$out['ERRORS'] = nl2br($errors);
90+
$ok = 0;
91+
}
92+
}
93+
$rec['TIME_LIMIT'] = gr('time_limit', 'int');
94+
$rec['IS_CONTEXT'] = gr('is_context', 'int');
95+
$rec['IS_COMMON_CONTEXT'] = gr('is_common_context', 'int');
96+
$rec['MATCHED_CONTEXT_ID'] = gr('matched_context_id', 'int');
97+
$rec['TIMEOUT'] = gr('timeout', 'int');
98+
$rec['IS_LAST'] = gr('is_last', 'int');
99+
$rec['PRIORITY'] = gr('priority', 'int');
100+
$rec['SKIPSYSTEM'] = gr('skipsystem', 'int');
101+
$rec['ONETIME'] = gr('onetime', 'int');
102+
$rec['TIMEOUT_CONTEXT_ID'] = gr('timeout_context_id', 'int');
103+
104+
$timeout_script = gr('timeout_script');
105+
if ($timeout_script != '') {
106+
$rec['TIMEOUT_SCRIPT'] = $timeout_script;
107+
$errors = php_syntax_error($rec['TIMEOUT_SCRIPT']);
108+
if ($errors) {
109+
$out['ERR_TIMEOUT_SCRIPT'] = 1;
110+
$out['ERRORS_TIMEOUT_SCRIPT'] = nl2br($errors);
111+
$ok = 0;
112+
}
113+
} else {
114+
$rec['TIMEOUT_SCRIPT'] = '';
115+
}
172116

173-
global $condition;
174-
$rec['CONDITION']=$condition;
175117

176-
global $condition_value;
177-
$rec['CONDITION_VALUE']=$condition_value;
118+
$rec['PARENT_ID'] = (int)$parent_id;
178119

179-
if ($rec['LINKED_OBJECT'] && $rec['LINKED_PROPERTY']) {
180-
addLinkedProperty($rec['LINKED_OBJECT'], $rec['LINKED_PROPERTY'], $this->name);
120+
if ($rec['PATTERN_TYPE'] == 1) {
121+
$rec['PARENT_ID'] = 0;
122+
$rec['LINKED_OBJECT'] = gr('linked_object');
123+
$rec['LINKED_PROPERTY'] = gr('linked_property');
124+
$rec['CONDITION'] = gr('condition', 'int');
125+
$rec['CONDITION_VALUE'] = gr('condition_value');
126+
if ($rec['LINKED_OBJECT'] && $rec['LINKED_PROPERTY']) {
127+
addLinkedProperty($rec['LINKED_OBJECT'], $rec['LINKED_PROPERTY'], $this->name);
128+
}
181129
}
182130

183-
}
184-
185131

186-
//UPDATING RECORD
187-
if ($ok) {
188-
if ($rec['ID']) {
189-
SQLUpdate($table_name, $rec); // update
132+
//UPDATING RECORD
133+
if ($ok) {
134+
if ($rec['ID']) {
135+
SQLUpdate($table_name, $rec); // update
136+
} else {
137+
$new_rec = 1;
138+
$rec['ID'] = SQLInsert($table_name, $rec); // adding new record
139+
}
140+
$out['OK'] = 1;
190141
} else {
191-
$new_rec=1;
192-
$rec['ID']=SQLInsert($table_name, $rec); // adding new record
142+
$out['ERR'] = 1;
193143
}
194-
$out['OK']=1;
195-
} else {
196-
$out['ERR']=1;
197-
}
198-
}
199-
if (is_array($rec)) {
200-
foreach($rec as $k=>$v) {
201-
if (!is_array($v)) {
202-
$rec[$k]=htmlspecialchars($v);
144+
}
145+
146+
if (is_array($rec)) {
147+
foreach ($rec as $k => $v) {
148+
if (!is_array($v)) {
149+
$rec[$k] = htmlspecialchars($v);
150+
}
203151
}
204-
}
205-
}
206-
outHash($rec, $out);
152+
}
153+
outHash($rec, $out);
207154

208-
$out['SCRIPTS']=SQLSelect("SELECT ID, TITLE FROM scripts ORDER BY TITLE");
209-
$out['LOG']=nl2br($rec['LOG']);
155+
$out['SCRIPTS'] = SQLSelect("SELECT ID, TITLE FROM scripts ORDER BY TITLE");
156+
$out['LOG'] = nl2br($rec['LOG']);
157+
$out['CONTEXTS'] = SQLSelect("SELECT ID, TITLE FROM patterns WHERE IS_CONTEXT=1 AND ID!=" . (int)$rec['ID'] . " ORDER BY PARENT_ID, TITLE");
210158

211-
$out['CONTEXTS']=SQLSelect("SELECT ID, TITLE FROM patterns WHERE IS_CONTEXT=1 AND ID!=".(int)$rec['ID']." ORDER BY PARENT_ID, TITLE");
212-
213-
if ($rec['ID']) {
214-
$out['CHILDREN']=SQLSelect("SELECT ID, TITLE FROM patterns WHERE PARENT_ID='".(int)$rec['ID']."'");
215-
$out['SAME_LEVEL']=SQLSelect("SELECT ID, TITLE FROM patterns WHERE PARENT_ID='".(int)$rec['PARENT_ID']."'");
216-
}
159+
if ($rec['ID']) {
160+
$out['CHILDREN'] = SQLSelect("SELECT ID, TITLE FROM patterns WHERE PARENT_ID='" . (int)$rec['ID'] . "'");
161+
$out['SAME_LEVEL'] = SQLSelect("SELECT ID, TITLE FROM patterns WHERE PARENT_ID='" . (int)$rec['PARENT_ID'] . "'");
162+
}
217163

218-
if (file_exists(ROOT . "lib/phpmorphy/common.php")) {
219-
$out['SHOW_MORPHY']=1;
220-
}
164+
if (file_exists(ROOT . "lib/phpmorphy/common.php")) {
165+
$out['SHOW_MORPHY'] = 1;
166+
}
221167

222-
?>

0 commit comments

Comments
 (0)