Completed
Push — develop ( 62a102...75b835 )
by Maxim
05:41
created
manager/processors/save_module.processor.php 1 patch
Switch Indentation   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -59,125 +59,125 @@
 block discarded – undo
59 59
 }
60 60
 
61 61
 switch ($_POST['mode']) {
62
-    case '107':
63
-        // invoke OnBeforeModFormSave event
64
-        $modx->invokeEvent("OnBeforeModFormSave", array(
65
-                "mode" => "new",
66
-                "id" => $id
67
-            ));
68
-
69
-        // disallow duplicate names for new modules
70
-        $rs = $modx->db->select('count(id)', $modx->getFullTableName('site_modules'), "name='{$name}'");
71
-        $count = $modx->db->getValue($rs);
72
-        if ($count > 0) {
73
-            $modx->manager->saveFormValues(107);
74
-            $modx->webAlertAndQuit(sprintf($_lang['duplicate_name_found_module'], $name), "index.php?a=107");
75
-        }
62
+        case '107':
63
+            // invoke OnBeforeModFormSave event
64
+            $modx->invokeEvent("OnBeforeModFormSave", array(
65
+                    "mode" => "new",
66
+                    "id" => $id
67
+                ));
68
+
69
+            // disallow duplicate names for new modules
70
+            $rs = $modx->db->select('count(id)', $modx->getFullTableName('site_modules'), "name='{$name}'");
71
+            $count = $modx->db->getValue($rs);
72
+            if ($count > 0) {
73
+                $modx->manager->saveFormValues(107);
74
+                $modx->webAlertAndQuit(sprintf($_lang['duplicate_name_found_module'], $name), "index.php?a=107");
75
+            }
76 76
 
77
-        // save the new module
78
-        $newid = $modx->db->insert(array(
79
-            'name' => $name,
80
-            'description' => $description,
81
-            'disabled' => $disabled,
82
-            'wrap' => $wrap,
83
-            'locked' => $locked,
84
-            'icon' => $icon,
85
-            'resourcefile' => $resourcefile,
86
-            'enable_resource' => $enable_resource,
87
-            'category' => $categoryid,
88
-            'enable_sharedparams' => $enable_sharedparams,
89
-            'guid' => $guid,
90
-            'modulecode' => $modulecode,
91
-            'properties' => $properties,
92
-            'createdon' => $currentdate,
93
-            'editedon' => $currentdate
94
-        ), $modx->getFullTableName('site_modules'));
95
-
96
-        // save user group access permissions
97
-        saveUserGroupAccessPermissons();
98
-
99
-        // invoke OnModFormSave event
100
-        $modx->invokeEvent("OnModFormSave", array(
101
-                "mode" => "new",
102
-                "id" => $newid
103
-            ));
104
-
105
-        // Set the item name for logger
106
-        $_SESSION['itemname'] = $name;
107
-
108
-        // empty cache
109
-        $modx->clearCache('full');
110
-
111
-        // finished emptying cache - redirect
112
-        if ($_POST['stay'] != '') {
113
-            $a = ($_POST['stay'] == '2') ? "108&id=$newid" : "107";
114
-            $header = "Location: index.php?a=" . $a . "&r=2&stay=" . $_POST['stay'];
115
-            header($header);
116
-        } else {
117
-            $header = "Location: index.php?a=106&r=2";
118
-            header($header);
119
-        }
120
-        break;
121
-    case '108':
122
-        // invoke OnBeforeModFormSave event
123
-        $modx->invokeEvent("OnBeforeModFormSave", array(
124
-                "mode" => "upd",
125
-                "id" => $id
126
-            ));
127
-
128
-        // disallow duplicate names for new modules
129
-        $rs = $modx->db->select('count(id)', $modx->getFullTableName('site_modules'), "name='{$name}' AND id!='{$id}'");
130
-        if ($modx->db->getValue($rs) > 0) {
131
-            $modx->manager->saveFormValues(108);
132
-            $modx->webAlertAndQuit(sprintf($_lang['duplicate_name_found_module'], $name), "index.php?a=108&id={$id}");
133
-        }
77
+            // save the new module
78
+            $newid = $modx->db->insert(array(
79
+                'name' => $name,
80
+                'description' => $description,
81
+                'disabled' => $disabled,
82
+                'wrap' => $wrap,
83
+                'locked' => $locked,
84
+                'icon' => $icon,
85
+                'resourcefile' => $resourcefile,
86
+                'enable_resource' => $enable_resource,
87
+                'category' => $categoryid,
88
+                'enable_sharedparams' => $enable_sharedparams,
89
+                'guid' => $guid,
90
+                'modulecode' => $modulecode,
91
+                'properties' => $properties,
92
+                'createdon' => $currentdate,
93
+                'editedon' => $currentdate
94
+            ), $modx->getFullTableName('site_modules'));
95
+
96
+            // save user group access permissions
97
+            saveUserGroupAccessPermissons();
98
+
99
+            // invoke OnModFormSave event
100
+            $modx->invokeEvent("OnModFormSave", array(
101
+                    "mode" => "new",
102
+                    "id" => $newid
103
+                ));
104
+
105
+            // Set the item name for logger
106
+            $_SESSION['itemname'] = $name;
107
+
108
+            // empty cache
109
+            $modx->clearCache('full');
110
+
111
+            // finished emptying cache - redirect
112
+            if ($_POST['stay'] != '') {
113
+                $a = ($_POST['stay'] == '2') ? "108&id=$newid" : "107";
114
+                $header = "Location: index.php?a=" . $a . "&r=2&stay=" . $_POST['stay'];
115
+                header($header);
116
+            } else {
117
+                $header = "Location: index.php?a=106&r=2";
118
+                header($header);
119
+            }
120
+            break;
121
+        case '108':
122
+            // invoke OnBeforeModFormSave event
123
+            $modx->invokeEvent("OnBeforeModFormSave", array(
124
+                    "mode" => "upd",
125
+                    "id" => $id
126
+                ));
127
+
128
+            // disallow duplicate names for new modules
129
+            $rs = $modx->db->select('count(id)', $modx->getFullTableName('site_modules'), "name='{$name}' AND id!='{$id}'");
130
+            if ($modx->db->getValue($rs) > 0) {
131
+                $modx->manager->saveFormValues(108);
132
+                $modx->webAlertAndQuit(sprintf($_lang['duplicate_name_found_module'], $name), "index.php?a=108&id={$id}");
133
+            }
134 134
 
135
-        // save the edited module
136
-        $modx->db->update(array(
137
-            'name' => $name,
138
-            'description' => $description,
139
-            'icon' => $icon,
140
-            'enable_resource' => $enable_resource,
141
-            'resourcefile' => $resourcefile,
142
-            'disabled' => $disabled,
143
-            'wrap' => $wrap,
144
-            'locked' => $locked,
145
-            'category' => $categoryid,
146
-            'enable_sharedparams' => $enable_sharedparams,
147
-            'guid' => $guid,
148
-            'modulecode' => $modulecode,
149
-            'properties' => $properties,
150
-            'editedon' => $currentdate
151
-        ), $modx->getFullTableName('site_modules'), "id='{$id}'");
152
-
153
-        // save user group access permissions
154
-        saveUserGroupAccessPermissons();
155
-
156
-        // invoke OnModFormSave event
157
-        $modx->invokeEvent("OnModFormSave", array(
158
-                "mode" => "upd",
159
-                "id" => $id
160
-            ));
161
-
162
-        // Set the item name for logger
163
-        $_SESSION['itemname'] = $name;
164
-
165
-        // empty cache
166
-        $modx->clearCache('full');
167
-
168
-        // finished emptying cache - redirect
169
-        if ($_POST['stay'] != '') {
170
-            $a = ($_POST['stay'] == '2') ? "108&id=$id" : "107";
171
-            $header = "Location: index.php?a=" . $a . "&r=2&stay=" . $_POST['stay'];
172
-            header($header);
173
-        } else {
174
-            $modx->unlockElement(6, $id);
175
-            $header = "Location: index.php?a=106&r=2";
176
-            header($header);
177
-        }
178
-        break;
179
-    default:
180
-        $modx->webAlertAndQuit("No operation set in request.");
135
+            // save the edited module
136
+            $modx->db->update(array(
137
+                'name' => $name,
138
+                'description' => $description,
139
+                'icon' => $icon,
140
+                'enable_resource' => $enable_resource,
141
+                'resourcefile' => $resourcefile,
142
+                'disabled' => $disabled,
143
+                'wrap' => $wrap,
144
+                'locked' => $locked,
145
+                'category' => $categoryid,
146
+                'enable_sharedparams' => $enable_sharedparams,
147
+                'guid' => $guid,
148
+                'modulecode' => $modulecode,
149
+                'properties' => $properties,
150
+                'editedon' => $currentdate
151
+            ), $modx->getFullTableName('site_modules'), "id='{$id}'");
152
+
153
+            // save user group access permissions
154
+            saveUserGroupAccessPermissons();
155
+
156
+            // invoke OnModFormSave event
157
+            $modx->invokeEvent("OnModFormSave", array(
158
+                    "mode" => "upd",
159
+                    "id" => $id
160
+                ));
161
+
162
+            // Set the item name for logger
163
+            $_SESSION['itemname'] = $name;
164
+
165
+            // empty cache
166
+            $modx->clearCache('full');
167
+
168
+            // finished emptying cache - redirect
169
+            if ($_POST['stay'] != '') {
170
+                $a = ($_POST['stay'] == '2') ? "108&id=$id" : "107";
171
+                $header = "Location: index.php?a=" . $a . "&r=2&stay=" . $_POST['stay'];
172
+                header($header);
173
+            } else {
174
+                $modx->unlockElement(6, $id);
175
+                $header = "Location: index.php?a=106&r=2";
176
+                header($header);
177
+            }
178
+            break;
179
+        default:
180
+            $modx->webAlertAndQuit("No operation set in request.");
181 181
 }
182 182
 
183 183
 // saves module user group access
Please login to merge, or discard this patch.
manager/processors/save_web_user.processor.php 1 patch
Switch Indentation   +224 added lines, -224 removed lines patch added patch discarded remove patch
@@ -60,108 +60,108 @@  discard block
 block discarded – undo
60 60
 }
61 61
 
62 62
 switch($input['mode']) {
63
-	case '87' : // new user
64
-		// check if this user name already exist
65
-		$rs = $modx->db->select('count(id)', $tbl_web_users, "username='{$esc_newusername}'");
66
-		$limit = $modx->db->getValue($rs);
67
-		if($limit > 0) {
68
-			webAlertAndQuit("User name is already in use!");
69
-		}
70
-
71
-		// check if the email address already exist
72
-		$rs = $modx->db->select('count(id)', $tbl_web_user_attributes, "email='{$esc_email}' AND id!='{$id}'");
73
-		$limit = $modx->db->getValue($rs);
74
-		if($limit > 0) {
75
-			webAlertAndQuit("Email is already in use!");
76
-		}
63
+	    case '87' : // new user
64
+		    // check if this user name already exist
65
+		    $rs = $modx->db->select('count(id)', $tbl_web_users, "username='{$esc_newusername}'");
66
+		    $limit = $modx->db->getValue($rs);
67
+		    if($limit > 0) {
68
+			    webAlertAndQuit("User name is already in use!");
69
+		    }
70
+
71
+		    // check if the email address already exist
72
+		    $rs = $modx->db->select('count(id)', $tbl_web_user_attributes, "email='{$esc_email}' AND id!='{$id}'");
73
+		    $limit = $modx->db->getValue($rs);
74
+		    if($limit > 0) {
75
+			    webAlertAndQuit("Email is already in use!");
76
+		    }
77
+
78
+		    // generate a new password for this user
79
+		    if($specifiedpassword != "" && $passwordgenmethod == "spec") {
80
+			    if(strlen($specifiedpassword) < 6) {
81
+				    webAlertAndQuit("Password is too short!");
82
+			    } else {
83
+				    $newpassword = $specifiedpassword;
84
+			    }
85
+		    } elseif($specifiedpassword == "" && $passwordgenmethod == "spec") {
86
+			    webAlertAndQuit("You didn't specify a password for this user!");
87
+		    } elseif($passwordgenmethod == 'g') {
88
+			    $newpassword = generate_password(8);
89
+		    } else {
90
+			    webAlertAndQuit("No password generation method specified!");
91
+		    }
92
+
93
+		    // invoke OnBeforeWUsrFormSave event
94
+		    $modx->invokeEvent("OnBeforeWUsrFormSave", array(
95
+			    "mode" => "new",
96
+		    ));
97
+
98
+		    // create the user account
99
+		    $field = array();
100
+		    $field['username'] = $esc_newusername;
101
+		    $field['password'] = md5($newpassword);
102
+		    $internalKey = $modx->db->insert($field, $tbl_web_users);
103
+
104
+		    $field = compact('internalKey', 'fullname', 'role', 'email', 'phone', 'mobilephone', 'fax', 'zip', 'street', 'city', 'state', 'country', 'gender', 'dob', 'photo', 'comment', 'blocked', 'blockeduntil', 'blockedafter');
105
+		    $field = $modx->db->escape($field);
106
+		    $modx->db->insert($field, $tbl_web_user_attributes);
107
+
108
+		    // Save User Settings
109
+		    saveUserSettings($internalKey);
110
+
111
+		    // Set the item name for logger
112
+		    $_SESSION['itemname'] = $newusername;
113
+
114
+		    /*******************************************************************************/
115
+		    // put the user in the user_groups he/ she should be in
116
+		    // first, check that up_perms are switched on!
117
+		    if($use_udperms == 1) {
118
+			    if(!empty($user_groups)) {
119
+				    for($i = 0; $i < count($user_groups); $i++) {
120
+					    $f = array();
121
+					    $f['webgroup'] = intval($user_groups[$i]);
122
+					    $f['webuser'] = $internalKey;
123
+					    $modx->db->insert($f, $tbl_web_groups);
124
+				    }
125
+			    }
126
+		    }
127
+		    // end of user_groups stuff!
128
+
129
+            // invoke OnWebSaveUser event
130
+            $modx->invokeEvent("OnWebSaveUser", array(
131
+                "mode" => "new",
132
+                "userid" => $internalKey,
133
+                "username" => $newusername,
134
+                "userpassword" => $newpassword,
135
+                "useremail" => $email,
136
+                "userfullname" => $fullname
137
+            ));
77 138
 
78
-		// generate a new password for this user
79
-		if($specifiedpassword != "" && $passwordgenmethod == "spec") {
80
-			if(strlen($specifiedpassword) < 6) {
81
-				webAlertAndQuit("Password is too short!");
82
-			} else {
83
-				$newpassword = $specifiedpassword;
84
-			}
85
-		} elseif($specifiedpassword == "" && $passwordgenmethod == "spec") {
86
-			webAlertAndQuit("You didn't specify a password for this user!");
87
-		} elseif($passwordgenmethod == 'g') {
88
-			$newpassword = generate_password(8);
89
-		} else {
90
-			webAlertAndQuit("No password generation method specified!");
91
-		}
139
+            // invoke OnWUsrFormSave event
140
+            $modx->invokeEvent("OnWUsrFormSave", array(
141
+                "mode" => "new",
142
+                "id" => $internalKey
143
+            ));
92 144
 
93
-		// invoke OnBeforeWUsrFormSave event
94
-		$modx->invokeEvent("OnBeforeWUsrFormSave", array(
95
-			"mode" => "new",
96
-		));
97
-
98
-		// create the user account
99
-		$field = array();
100
-		$field['username'] = $esc_newusername;
101
-		$field['password'] = md5($newpassword);
102
-		$internalKey = $modx->db->insert($field, $tbl_web_users);
103
-
104
-		$field = compact('internalKey', 'fullname', 'role', 'email', 'phone', 'mobilephone', 'fax', 'zip', 'street', 'city', 'state', 'country', 'gender', 'dob', 'photo', 'comment', 'blocked', 'blockeduntil', 'blockedafter');
105
-		$field = $modx->db->escape($field);
106
-		$modx->db->insert($field, $tbl_web_user_attributes);
107
-
108
-		// Save User Settings
109
-		saveUserSettings($internalKey);
110
-
111
-		// Set the item name for logger
112
-		$_SESSION['itemname'] = $newusername;
113
-
114
-		/*******************************************************************************/
115
-		// put the user in the user_groups he/ she should be in
116
-		// first, check that up_perms are switched on!
117
-		if($use_udperms == 1) {
118
-			if(!empty($user_groups)) {
119
-				for($i = 0; $i < count($user_groups); $i++) {
120
-					$f = array();
121
-					$f['webgroup'] = intval($user_groups[$i]);
122
-					$f['webuser'] = $internalKey;
123
-					$modx->db->insert($f, $tbl_web_groups);
124
-				}
125
-			}
126
-		}
127
-		// end of user_groups stuff!
128
-
129
-        // invoke OnWebSaveUser event
130
-        $modx->invokeEvent("OnWebSaveUser", array(
131
-            "mode" => "new",
132
-            "userid" => $internalKey,
133
-            "username" => $newusername,
134
-            "userpassword" => $newpassword,
135
-            "useremail" => $email,
136
-            "userfullname" => $fullname
137
-        ));
138
-
139
-        // invoke OnWUsrFormSave event
140
-        $modx->invokeEvent("OnWUsrFormSave", array(
141
-            "mode" => "new",
142
-            "id" => $internalKey
143
-        ));
144
-
145
-		if($passwordnotifymethod == 'e') {
146
-			sendMailMessage($email, $newusername, $newpassword, $fullname);
147
-			if($input['stay'] != '') {
148
-				$a = ($input['stay'] == '2') ? "88&id={$internalKey}" : "87";
149
-				$header = "Location: index.php?a={$a}&r=2&stay=" . $input['stay'];
150
-				header($header);
151
-			} else {
152
-				$header = "Location: index.php?a=99&r=2";
153
-				header($header);
154
-			}
155
-		} else {
156
-			if($input['stay'] != '') {
157
-				$a = ($input['stay'] == '2') ? "88&id={$internalKey}" : "87";
158
-				$stayUrl = "index.php?a={$a}&r=2&stay=" . $input['stay'];
159
-			} else {
160
-				$stayUrl = "index.php?a=99&r=2";
161
-			}
162
-
163
-			include_once "header.inc.php";
164
-			?>
145
+		    if($passwordnotifymethod == 'e') {
146
+			    sendMailMessage($email, $newusername, $newpassword, $fullname);
147
+			    if($input['stay'] != '') {
148
+				    $a = ($input['stay'] == '2') ? "88&id={$internalKey}" : "87";
149
+				    $header = "Location: index.php?a={$a}&r=2&stay=" . $input['stay'];
150
+				    header($header);
151
+			    } else {
152
+				    $header = "Location: index.php?a=99&r=2";
153
+				    header($header);
154
+			    }
155
+		    } else {
156
+			    if($input['stay'] != '') {
157
+				    $a = ($input['stay'] == '2') ? "88&id={$internalKey}" : "87";
158
+				    $stayUrl = "index.php?a={$a}&r=2&stay=" . $input['stay'];
159
+			    } else {
160
+				    $stayUrl = "index.php?a=99&r=2";
161
+			    }
162
+
163
+			    include_once "header.inc.php";
164
+			    ?>
165 165
 
166 166
 			<h1><?php echo $_lang['web_user_title']; ?></h1>
167 167
 
@@ -183,122 +183,122 @@  discard block
 block discarded – undo
183 183
 			</div>
184 184
 			<?php
185 185
 
186
-			include_once "footer.inc.php";
187
-		}
188
-		break;
189
-	case '88' : // edit user
190
-		// generate a new password for this user
191
-		if($genpassword == 1) {
192
-			if($specifiedpassword != "" && $passwordgenmethod == "spec") {
193
-				if(strlen($specifiedpassword) < 6) {
194
-					webAlertAndQuit("Password is too short!");
195
-				} else {
196
-					$newpassword = $specifiedpassword;
197
-				}
198
-			} elseif($specifiedpassword == "" && $passwordgenmethod == "spec") {
199
-				webAlertAndQuit("You didn't specify a password for this user!");
200
-			} elseif($passwordgenmethod == 'g') {
201
-				$newpassword = generate_password(8);
202
-			} else {
203
-				webAlertAndQuit("No password generation method specified!");
204
-			}
205
-		}
206
-		if($passwordnotifymethod == 'e') {
207
-			sendMailMessage($email, $newusername, $newpassword, $fullname);
208
-		}
209
-
210
-		// check if the username already exist
211
-		$rs = $modx->db->select('count(id)', $tbl_web_users, "username='{$esc_newusername}' AND id!='{$id}'");
212
-		$limit = $modx->db->getValue($rs);
213
-		if($limit > 0) {
214
-			webAlertAndQuit("User name is already in use!");
215
-		}
216
-
217
-		// check if the email address already exists
218
-		$rs = $modx->db->select('count(internalKey)', $tbl_web_user_attributes, "email='{$esc_email}' AND internalKey!='{$id}'");
219
-		$limit = $modx->db->getValue($rs);
220
-		if($limit > 0) {
221
-			webAlertAndQuit("Email is already in use!");
222
-		}
223
-
224
-		// invoke OnBeforeWUsrFormSave event
225
-		$modx->invokeEvent("OnBeforeWUsrFormSave", array(
226
-			"mode" => "upd",
227
-			"id" => $id
228
-		));
229
-
230
-		// update user name and password
231
-		$field = array();
232
-		$field['username'] = $esc_newusername;
233
-		if($genpassword == 1) {
234
-			$field['password'] = md5($newpassword);
235
-		}
236
-		$modx->db->update($field, $tbl_web_users, "id='{$id}'");
237
-		$field = compact('fullname', 'role', 'email', 'phone', 'mobilephone', 'fax', 'zip', 'street', 'city', 'state', 'country', 'gender', 'dob', 'photo', 'comment', 'failedlogincount', 'blocked', 'blockeduntil', 'blockedafter');
238
-		$field = $modx->db->escape($field);
239
-		$modx->db->update($field, $tbl_web_user_attributes, "internalKey='{$id}'");
240
-
241
-		// Save User Settings
242
-		saveUserSettings($id);
243
-
244
-		// Set the item name for logger
245
-		$_SESSION['itemname'] = $newusername;
246
-
247
-		/*******************************************************************************/
248
-		// put the user in the user_groups he/ she should be in
249
-		// first, check that up_perms are switched on!
250
-		if($use_udperms == 1) {
251
-			// as this is an existing user, delete his/ her entries in the groups before saving the new groups
252
-			$modx->db->delete($tbl_web_groups, "webuser='{$id}'");
253
-			if(!empty($user_groups)) {
254
-				for($i = 0; $i < count($user_groups); $i++) {
255
-					$field = array();
256
-					$field['webgroup'] = intval($user_groups[$i]);
257
-					$field['webuser'] = $id;
258
-					$modx->db->insert($field, $tbl_web_groups);
259
-				}
260
-			}
261
-		}
262
-		// end of user_groups stuff!
263
-		/*******************************************************************************/
264
-
265
-        // invoke OnWebSaveUser event
266
-        $modx->invokeEvent("OnWebSaveUser", array(
267
-            "mode" => "upd",
268
-            "userid" => $id,
269
-            "username" => $newusername,
270
-            "userpassword" => $newpassword,
271
-            "useremail" => $email,
272
-            "userfullname" => $fullname,
273
-            "oldusername" => (($oldusername != $newusername) ? $oldusername : ""),
274
-            "olduseremail" => (($oldemail != $email) ? $oldemail : "")
275
-        ));
276
-
277
-        // invoke OnWebChangePassword event
278
-        if($genpassword == 1) {
279
-            $modx->invokeEvent("OnWebChangePassword", array(
186
+			    include_once "footer.inc.php";
187
+		    }
188
+		    break;
189
+	    case '88' : // edit user
190
+		    // generate a new password for this user
191
+		    if($genpassword == 1) {
192
+			    if($specifiedpassword != "" && $passwordgenmethod == "spec") {
193
+				    if(strlen($specifiedpassword) < 6) {
194
+					    webAlertAndQuit("Password is too short!");
195
+				    } else {
196
+					    $newpassword = $specifiedpassword;
197
+				    }
198
+			    } elseif($specifiedpassword == "" && $passwordgenmethod == "spec") {
199
+				    webAlertAndQuit("You didn't specify a password for this user!");
200
+			    } elseif($passwordgenmethod == 'g') {
201
+				    $newpassword = generate_password(8);
202
+			    } else {
203
+				    webAlertAndQuit("No password generation method specified!");
204
+			    }
205
+		    }
206
+		    if($passwordnotifymethod == 'e') {
207
+			    sendMailMessage($email, $newusername, $newpassword, $fullname);
208
+		    }
209
+
210
+		    // check if the username already exist
211
+		    $rs = $modx->db->select('count(id)', $tbl_web_users, "username='{$esc_newusername}' AND id!='{$id}'");
212
+		    $limit = $modx->db->getValue($rs);
213
+		    if($limit > 0) {
214
+			    webAlertAndQuit("User name is already in use!");
215
+		    }
216
+
217
+		    // check if the email address already exists
218
+		    $rs = $modx->db->select('count(internalKey)', $tbl_web_user_attributes, "email='{$esc_email}' AND internalKey!='{$id}'");
219
+		    $limit = $modx->db->getValue($rs);
220
+		    if($limit > 0) {
221
+			    webAlertAndQuit("Email is already in use!");
222
+		    }
223
+
224
+		    // invoke OnBeforeWUsrFormSave event
225
+		    $modx->invokeEvent("OnBeforeWUsrFormSave", array(
226
+			    "mode" => "upd",
227
+			    "id" => $id
228
+		    ));
229
+
230
+		    // update user name and password
231
+		    $field = array();
232
+		    $field['username'] = $esc_newusername;
233
+		    if($genpassword == 1) {
234
+			    $field['password'] = md5($newpassword);
235
+		    }
236
+		    $modx->db->update($field, $tbl_web_users, "id='{$id}'");
237
+		    $field = compact('fullname', 'role', 'email', 'phone', 'mobilephone', 'fax', 'zip', 'street', 'city', 'state', 'country', 'gender', 'dob', 'photo', 'comment', 'failedlogincount', 'blocked', 'blockeduntil', 'blockedafter');
238
+		    $field = $modx->db->escape($field);
239
+		    $modx->db->update($field, $tbl_web_user_attributes, "internalKey='{$id}'");
240
+
241
+		    // Save User Settings
242
+		    saveUserSettings($id);
243
+
244
+		    // Set the item name for logger
245
+		    $_SESSION['itemname'] = $newusername;
246
+
247
+		    /*******************************************************************************/
248
+		    // put the user in the user_groups he/ she should be in
249
+		    // first, check that up_perms are switched on!
250
+		    if($use_udperms == 1) {
251
+			    // as this is an existing user, delete his/ her entries in the groups before saving the new groups
252
+			    $modx->db->delete($tbl_web_groups, "webuser='{$id}'");
253
+			    if(!empty($user_groups)) {
254
+				    for($i = 0; $i < count($user_groups); $i++) {
255
+					    $field = array();
256
+					    $field['webgroup'] = intval($user_groups[$i]);
257
+					    $field['webuser'] = $id;
258
+					    $modx->db->insert($field, $tbl_web_groups);
259
+				    }
260
+			    }
261
+		    }
262
+		    // end of user_groups stuff!
263
+		    /*******************************************************************************/
264
+
265
+            // invoke OnWebSaveUser event
266
+            $modx->invokeEvent("OnWebSaveUser", array(
267
+                "mode" => "upd",
280 268
                 "userid" => $id,
281 269
                 "username" => $newusername,
282
-                "userpassword" => $newpassword
270
+                "userpassword" => $newpassword,
271
+                "useremail" => $email,
272
+                "userfullname" => $fullname,
273
+                "oldusername" => (($oldusername != $newusername) ? $oldusername : ""),
274
+                "olduseremail" => (($oldemail != $email) ? $oldemail : "")
283 275
             ));
284
-        }
285 276
 
286
-        // invoke OnWUsrFormSave event
287
-        $modx->invokeEvent("OnWUsrFormSave", array(
288
-            "mode" => "upd",
289
-            "id" => $id
290
-        ));
277
+            // invoke OnWebChangePassword event
278
+            if($genpassword == 1) {
279
+                $modx->invokeEvent("OnWebChangePassword", array(
280
+                    "userid" => $id,
281
+                    "username" => $newusername,
282
+                    "userpassword" => $newpassword
283
+                ));
284
+            }
285
+
286
+            // invoke OnWUsrFormSave event
287
+            $modx->invokeEvent("OnWUsrFormSave", array(
288
+                "mode" => "upd",
289
+                "id" => $id
290
+            ));
291 291
 
292
-		if($genpassword == 1 && $passwordnotifymethod == 's') {
293
-			if($input['stay'] != '') {
294
-				$a = ($input['stay'] == '2') ? "88&id={$id}" : "87";
295
-				$stayUrl = "index.php?a={$a}&r=2&stay=" . $input['stay'];
296
-			} else {
297
-				$stayUrl = "index.php?a=99&r=2";
298
-			}
292
+		    if($genpassword == 1 && $passwordnotifymethod == 's') {
293
+			    if($input['stay'] != '') {
294
+				    $a = ($input['stay'] == '2') ? "88&id={$id}" : "87";
295
+				    $stayUrl = "index.php?a={$a}&r=2&stay=" . $input['stay'];
296
+			    } else {
297
+				    $stayUrl = "index.php?a=99&r=2";
298
+			    }
299 299
 
300
-			include_once "header.inc.php";
301
-			?>
300
+			    include_once "header.inc.php";
301
+			    ?>
302 302
 
303 303
 			<h1><?php echo $_lang['web_user_title']; ?></h1>
304 304
 
@@ -318,20 +318,20 @@  discard block
 block discarded – undo
318 318
 			</div>
319 319
 			<?php
320 320
 
321
-			include_once "footer.inc.php";
322
-		} else {
323
-			if($input['stay'] != '') {
324
-				$a = ($input['stay'] == '2') ? "88&id={$id}" : "87";
325
-				$header = "Location: index.php?a={$a}&r=2&stay=" . $input['stay'];
326
-				header($header);
327
-			} else {
328
-				$header = "Location: index.php?a=99&r=2";
329
-				header($header);
330
-			}
331
-		}
332
-		break;
333
-	default :
334
-		webAlertAndQuit("No operation set in request.");
321
+			    include_once "footer.inc.php";
322
+		    } else {
323
+			    if($input['stay'] != '') {
324
+				    $a = ($input['stay'] == '2') ? "88&id={$id}" : "87";
325
+				    $header = "Location: index.php?a={$a}&r=2&stay=" . $input['stay'];
326
+				    header($header);
327
+			    } else {
328
+				    $header = "Location: index.php?a=99&r=2";
329
+				    header($header);
330
+			    }
331
+		    }
332
+		    break;
333
+	    default :
334
+		    webAlertAndQuit("No operation set in request.");
335 335
 }
336 336
 
337 337
 // in case any plugins include a quoted_printable function
Please login to merge, or discard this patch.
manager/processors/save_snippet.processor.php 1 patch
Switch Indentation   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -66,111 +66,111 @@
 block discarded – undo
66 66
 }
67 67
 
68 68
 switch ($_POST['mode']) {
69
-    case '23': // Save new snippet
70
-
71
-        // invoke OnBeforeSnipFormSave event
72
-        $modx->invokeEvent("OnBeforeSnipFormSave", array(
73
-            "mode" => "new",
74
-            "id" => $id
75
-        ));
76
-
77
-        // disallow duplicate names for new snippets
78
-        $rs = $modx->db->select('COUNT(id)', $modx->getFullTableName('site_snippets'), "name='{$name}'");
79
-        $count = $modx->db->getValue($rs);
80
-        if ($count > 0) {
81
-            $modx->manager->saveFormValues(23);
82
-            $modx->webAlertAndQuit(sprintf($_lang['duplicate_name_found_general'], $_lang['snippet'], $name), "index.php?a=23");
83
-        }
84
-
85
-        //do stuff to save the new doc
86
-        $newid = $modx->db->insert(array(
87
-            'name' => $name,
88
-            'description' => $description,
89
-            'snippet' => $snippet,
90
-            'moduleguid' => $moduleguid,
91
-            'locked' => $locked,
92
-            'properties' => $properties,
93
-            'category' => $categoryid,
94
-            'disabled' => $disabled,
95
-            'createdon' => $currentdate,
96
-            'editedon' => $currentdate
97
-        ), $modx->getFullTableName('site_snippets'));
98
-
99
-        // invoke OnSnipFormSave event
100
-        $modx->invokeEvent("OnSnipFormSave", array(
101
-            "mode" => "new",
102
-            "id" => $newid
103
-        ));
104
-
105
-        // Set the item name for logger
106
-        $_SESSION['itemname'] = $name;
107
-
108
-        // empty cache
109
-        $modx->clearCache('full');
110
-
111
-        // finished emptying cache - redirect
112
-        if ($_POST['stay'] != '') {
113
-            $a = ($_POST['stay'] == '2') ? "22&id=$newid" : "23";
114
-            $header = "Location: index.php?a=" . $a . "&r=2&stay=" . $_POST['stay'];
115
-            header($header);
116
-        } else {
117
-            $header = "Location: index.php?a=76&r=2";
118
-            header($header);
119
-        }
120
-        break;
121
-    case '22': // Save existing snippet
122
-        // invoke OnBeforeSnipFormSave event
123
-        $modx->invokeEvent("OnBeforeSnipFormSave", array(
124
-            "mode" => "upd",
125
-            "id" => $id
126
-        ));
127
-
128
-        // disallow duplicate names for snippets
129
-        $rs = $modx->db->select('COUNT(*)', $modx->getFullTableName('site_snippets'), "name='{$name}' AND id!='{$id}'");
130
-        if ($modx->db->getValue($rs) > 0) {
131
-            $modx->manager->saveFormValues(22);
132
-            $modx->webAlertAndQuit(sprintf($_lang['duplicate_name_found_general'], $_lang['snippet'], $name), "index.php?a=22&id={$id}");
133
-        }
134
-
135
-        //do stuff to save the edited doc
136
-        $modx->db->update(array(
137
-            'name' => $name,
138
-            'description' => $description,
139
-            'snippet' => $snippet,
140
-            'moduleguid' => $moduleguid,
141
-            'locked' => $locked,
142
-            'properties' => $properties,
143
-            'category' => $categoryid,
144
-            'disabled' => $disabled,
145
-            'editedon' => $currentdate
146
-        ), $modx->getFullTableName('site_snippets'), "id='{$id}'");
147
-
148
-        // invoke OnSnipFormSave event
149
-        $modx->invokeEvent("OnSnipFormSave", array(
150
-            "mode" => "upd",
151
-            "id" => $id
152
-        ));
153
-
154
-        // Set the item name for logger
155
-        $_SESSION['itemname'] = $name;
156
-
157
-        // empty cache
158
-        $modx->clearCache('full');
159
-
160
-        if ($_POST['runsnippet']) {
161
-            run_snippet($snippet);
162
-        }
163
-        // finished emptying cache - redirect
164
-        if ($_POST['stay'] != '') {
165
-            $a = ($_POST['stay'] == '2') ? "22&id=$id" : "23";
166
-            $header = "Location: index.php?a=" . $a . "&r=2&stay=" . $_POST['stay'];
167
-            header($header);
168
-        } else {
169
-            $modx->unlockElement(4, $id);
170
-            $header = "Location: index.php?a=76&r=2";
171
-            header($header);
172
-        }
173
-        break;
174
-    default:
175
-        $modx->webAlertAndQuit("No operation set in request.");
69
+        case '23': // Save new snippet
70
+
71
+            // invoke OnBeforeSnipFormSave event
72
+            $modx->invokeEvent("OnBeforeSnipFormSave", array(
73
+                "mode" => "new",
74
+                "id" => $id
75
+            ));
76
+
77
+            // disallow duplicate names for new snippets
78
+            $rs = $modx->db->select('COUNT(id)', $modx->getFullTableName('site_snippets'), "name='{$name}'");
79
+            $count = $modx->db->getValue($rs);
80
+            if ($count > 0) {
81
+                $modx->manager->saveFormValues(23);
82
+                $modx->webAlertAndQuit(sprintf($_lang['duplicate_name_found_general'], $_lang['snippet'], $name), "index.php?a=23");
83
+            }
84
+
85
+            //do stuff to save the new doc
86
+            $newid = $modx->db->insert(array(
87
+                'name' => $name,
88
+                'description' => $description,
89
+                'snippet' => $snippet,
90
+                'moduleguid' => $moduleguid,
91
+                'locked' => $locked,
92
+                'properties' => $properties,
93
+                'category' => $categoryid,
94
+                'disabled' => $disabled,
95
+                'createdon' => $currentdate,
96
+                'editedon' => $currentdate
97
+            ), $modx->getFullTableName('site_snippets'));
98
+
99
+            // invoke OnSnipFormSave event
100
+            $modx->invokeEvent("OnSnipFormSave", array(
101
+                "mode" => "new",
102
+                "id" => $newid
103
+            ));
104
+
105
+            // Set the item name for logger
106
+            $_SESSION['itemname'] = $name;
107
+
108
+            // empty cache
109
+            $modx->clearCache('full');
110
+
111
+            // finished emptying cache - redirect
112
+            if ($_POST['stay'] != '') {
113
+                $a = ($_POST['stay'] == '2') ? "22&id=$newid" : "23";
114
+                $header = "Location: index.php?a=" . $a . "&r=2&stay=" . $_POST['stay'];
115
+                header($header);
116
+            } else {
117
+                $header = "Location: index.php?a=76&r=2";
118
+                header($header);
119
+            }
120
+            break;
121
+        case '22': // Save existing snippet
122
+            // invoke OnBeforeSnipFormSave event
123
+            $modx->invokeEvent("OnBeforeSnipFormSave", array(
124
+                "mode" => "upd",
125
+                "id" => $id
126
+            ));
127
+
128
+            // disallow duplicate names for snippets
129
+            $rs = $modx->db->select('COUNT(*)', $modx->getFullTableName('site_snippets'), "name='{$name}' AND id!='{$id}'");
130
+            if ($modx->db->getValue($rs) > 0) {
131
+                $modx->manager->saveFormValues(22);
132
+                $modx->webAlertAndQuit(sprintf($_lang['duplicate_name_found_general'], $_lang['snippet'], $name), "index.php?a=22&id={$id}");
133
+            }
134
+
135
+            //do stuff to save the edited doc
136
+            $modx->db->update(array(
137
+                'name' => $name,
138
+                'description' => $description,
139
+                'snippet' => $snippet,
140
+                'moduleguid' => $moduleguid,
141
+                'locked' => $locked,
142
+                'properties' => $properties,
143
+                'category' => $categoryid,
144
+                'disabled' => $disabled,
145
+                'editedon' => $currentdate
146
+            ), $modx->getFullTableName('site_snippets'), "id='{$id}'");
147
+
148
+            // invoke OnSnipFormSave event
149
+            $modx->invokeEvent("OnSnipFormSave", array(
150
+                "mode" => "upd",
151
+                "id" => $id
152
+            ));
153
+
154
+            // Set the item name for logger
155
+            $_SESSION['itemname'] = $name;
156
+
157
+            // empty cache
158
+            $modx->clearCache('full');
159
+
160
+            if ($_POST['runsnippet']) {
161
+                run_snippet($snippet);
162
+            }
163
+            // finished emptying cache - redirect
164
+            if ($_POST['stay'] != '') {
165
+                $a = ($_POST['stay'] == '2') ? "22&id=$id" : "23";
166
+                $header = "Location: index.php?a=" . $a . "&r=2&stay=" . $_POST['stay'];
167
+                header($header);
168
+            } else {
169
+                $modx->unlockElement(4, $id);
170
+                $header = "Location: index.php?a=76&r=2";
171
+                header($header);
172
+            }
173
+            break;
174
+        default:
175
+            $modx->webAlertAndQuit("No operation set in request.");
176 176
 }
Please login to merge, or discard this patch.
install/actions/action_options.php 1 patch
Switch Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -190,53 +190,53 @@
 block discarded – undo
190 190
 }
191 191
 
192 192
 switch($installMode){
193
-    case 0:
194
-    case 2:
195
-        $database_collation = isset($_POST['database_collation']) ? $_POST['database_collation'] : 'utf8_general_ci';
196
-        $database_charset = substr($database_collation, 0, strpos($database_collation, '_'));
197
-        $_POST['database_connection_charset'] = $database_charset;
198
-        if(empty($_SESSION['databaseloginpassword']))
199
-            $_SESSION['databaseloginpassword'] = $_POST['databaseloginpassword'];
200
-        if(empty($_SESSION['databaseloginname']))
201
-            $_SESSION['databaseloginname'] = $_POST['databaseloginname'];
202
-        break;
203
-    case 1:
204
-        include $base_path . MGR_DIR . '/includes/config.inc.php';
205
-        if (@ $conn = mysqli_connect($database_server, $database_user, $database_password)) {
206
-            if (@ mysqli_query($conn, "USE {$dbase}")) {
207
-                if (!$rs = mysqli_query($conn, "show session variables like 'collation_database'")) {
208
-                    $rs = mysqli_query($conn, "show session variables like 'collation_server'");
209
-                }
210
-                if ($rs && $collation = mysqli_fetch_row($rs)) {
211
-                    $database_collation = trim($collation[1]);
193
+        case 0:
194
+        case 2:
195
+            $database_collation = isset($_POST['database_collation']) ? $_POST['database_collation'] : 'utf8_general_ci';
196
+            $database_charset = substr($database_collation, 0, strpos($database_collation, '_'));
197
+            $_POST['database_connection_charset'] = $database_charset;
198
+            if(empty($_SESSION['databaseloginpassword']))
199
+                $_SESSION['databaseloginpassword'] = $_POST['databaseloginpassword'];
200
+            if(empty($_SESSION['databaseloginname']))
201
+                $_SESSION['databaseloginname'] = $_POST['databaseloginname'];
202
+            break;
203
+        case 1:
204
+            include $base_path . MGR_DIR . '/includes/config.inc.php';
205
+            if (@ $conn = mysqli_connect($database_server, $database_user, $database_password)) {
206
+                if (@ mysqli_query($conn, "USE {$dbase}")) {
207
+                    if (!$rs = mysqli_query($conn, "show session variables like 'collation_database'")) {
208
+                        $rs = mysqli_query($conn, "show session variables like 'collation_server'");
209
+                    }
210
+                    if ($rs && $collation = mysqli_fetch_row($rs)) {
211
+                        $database_collation = trim($collation[1]);
212
+                    }
212 213
                 }
213 214
             }
214
-        }
215
-        if (empty ($database_collation)) $database_collation = 'utf8_general_ci';
215
+            if (empty ($database_collation)) $database_collation = 'utf8_general_ci';
216 216
 
217
-        $database_charset = substr($database_collation, 0, strpos($database_collation, '_'));
218
-        if (!isset ($database_connection_charset) || empty ($database_connection_charset)) {
219
-            $database_connection_charset = $database_charset;
220
-        }
217
+            $database_charset = substr($database_collation, 0, strpos($database_collation, '_'));
218
+            if (!isset ($database_connection_charset) || empty ($database_connection_charset)) {
219
+                $database_connection_charset = $database_charset;
220
+            }
221 221
 
222
-        if (!isset ($database_connection_method) || empty ($database_connection_method)) {
223
-            $database_connection_method = 'SET CHARACTER SET';
224
-            if (function_exists('mysqli_set_charset')) mysqli_set_charset($conn, $database_connection_charset);
225
-        }
226
-        if ($database_connection_method != 'SET NAMES' && $database_connection_charset != $database_charset) {
227
-            $database_connection_method = 'SET NAMES';
228
-        }
222
+            if (!isset ($database_connection_method) || empty ($database_connection_method)) {
223
+                $database_connection_method = 'SET CHARACTER SET';
224
+                if (function_exists('mysqli_set_charset')) mysqli_set_charset($conn, $database_connection_charset);
225
+            }
226
+            if ($database_connection_method != 'SET NAMES' && $database_connection_charset != $database_charset) {
227
+                $database_connection_method = 'SET NAMES';
228
+            }
229 229
 
230
-        $_POST['database_name'] = $dbase;
231
-        $_POST['tableprefix'] = $table_prefix;
232
-        $_POST['database_connection_charset'] = $database_connection_charset;
233
-        $_POST['database_connection_method'] = $database_connection_method;
234
-        $_POST['databasehost'] = $database_server;
235
-        $_SESSION['databaseloginname'] = $database_user;
236
-        $_SESSION['databaseloginpassword'] = $database_password;
237
-        break;
238
-    default:
239
-        throw new Exception('installmode is undefined');
230
+            $_POST['database_name'] = $dbase;
231
+            $_POST['tableprefix'] = $table_prefix;
232
+            $_POST['database_connection_charset'] = $database_connection_charset;
233
+            $_POST['database_connection_method'] = $database_connection_method;
234
+            $_POST['databasehost'] = $database_server;
235
+            $_SESSION['databaseloginname'] = $database_user;
236
+            $_SESSION['databaseloginpassword'] = $database_password;
237
+            break;
238
+        default:
239
+            throw new Exception('installmode is undefined');
240 240
 }
241 241
 
242 242
 $ph['install_language'] = $install_language;
Please login to merge, or discard this patch.
manager/processors/save_content.processor.php 1 patch
Switch Indentation   +220 added lines, -220 removed lines patch added patch discarded remove patch
@@ -275,11 +275,11 @@  discard block
 block discarded – undo
275 275
 }
276 276
 
277 277
 switch ($actionToTake) {
278
-    case 'new' :
278
+        case 'new' :
279 279
 
280
-        // invoke OnBeforeDocFormSave event
281
-        switch($modx->config['docid_incrmnt_method'])
282
-        {
280
+            // invoke OnBeforeDocFormSave event
281
+            switch($modx->config['docid_incrmnt_method'])
282
+            {
283 283
             case '1':
284 284
                 $from = "{$tbl_site_content} AS T0 LEFT JOIN {$tbl_site_content} AS T1 ON T0.id + 1 = T1.id";
285 285
                 $where = "T1.id IS NULL";
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
 
294 294
             default:
295 295
                 $id = '';
296
-        }
296
+            }
297 297
 
298 298
         $modx->invokeEvent("OnBeforeDocFormSave", array (
299 299
             "mode" => "new",
@@ -444,256 +444,256 @@  discard block
 block discarded – undo
444 444
 
445 445
 
446 446
         break;
447
-    case 'edit' :
448
-
449
-        // get the document's current parent
450
-        $oldparent = $existingDocument['parent'];
451
-        $doctype = $existingDocument['type'];
452
-
453
-        if ($id == $site_start && $published == 0) {
454
-            $modx->manager->saveFormValues(27);
455
-            $modx->webAlertAndQuit("Document is linked to site_start variable and cannot be unpublished!");
456
-        }
457
-        $today = $_SERVER['REQUEST_TIME'] + $modx->config['server_offset_time'];
458
-        if ($id == $site_start && ($pub_date > $today || $unpub_date != "0")) {
459
-            $modx->manager->saveFormValues(27);
460
-            $modx->webAlertAndQuit("Document is linked to site_start variable and cannot have publish or unpublish dates set!");
461
-        }
462
-        if ($parent == $id) {
463
-            $modx->manager->saveFormValues(27);
464
-            $modx->webAlertAndQuit("Document can not be it's own parent!");
465
-        }
447
+        case 'edit' :
466 448
 
467
-        $parents = $modx->getParentIds($parent);
468
-        if (in_array($id, $parents)) {
469
-            $modx->webAlertAndQuit("Document descendant can not be it's parent!");
470
-        }
449
+            // get the document's current parent
450
+            $oldparent = $existingDocument['parent'];
451
+            $doctype = $existingDocument['type'];
471 452
 
472
-        // check to see document is a folder
473
-        $rs = $modx->db->select('count(id)', $tbl_site_content, "parent='{$id}'");
474
-        $count = $modx->db->getValue($rs);
475
-        if ($count > 0) {
476
-            $isfolder = 1;
477
-        }
453
+            if ($id == $site_start && $published == 0) {
454
+                $modx->manager->saveFormValues(27);
455
+                $modx->webAlertAndQuit("Document is linked to site_start variable and cannot be unpublished!");
456
+            }
457
+            $today = $_SERVER['REQUEST_TIME'] + $modx->config['server_offset_time'];
458
+            if ($id == $site_start && ($pub_date > $today || $unpub_date != "0")) {
459
+                $modx->manager->saveFormValues(27);
460
+                $modx->webAlertAndQuit("Document is linked to site_start variable and cannot have publish or unpublish dates set!");
461
+            }
462
+            if ($parent == $id) {
463
+                $modx->manager->saveFormValues(27);
464
+                $modx->webAlertAndQuit("Document can not be it's own parent!");
465
+            }
478 466
 
479
-        // set publishedon and publishedby
480
-        $was_published = $existingDocument['published'];
467
+            $parents = $modx->getParentIds($parent);
468
+            if (in_array($id, $parents)) {
469
+                $modx->webAlertAndQuit("Document descendant can not be it's parent!");
470
+            }
481 471
 
482
-        // keep original publish state, if change is not permitted
483
-        if (!$modx->hasPermission('publish_document')) {
484
-            $published = $was_published;
485
-            $pub_date = 'pub_date';
486
-            $unpub_date = 'unpub_date';
487
-        }
472
+            // check to see document is a folder
473
+            $rs = $modx->db->select('count(id)', $tbl_site_content, "parent='{$id}'");
474
+            $count = $modx->db->getValue($rs);
475
+            if ($count > 0) {
476
+                $isfolder = 1;
477
+            }
488 478
 
489
-        // if it was changed from unpublished to published
490
-        if (!$was_published && $published) {
491
-            $publishedon = $currentdate;
492
-            $publishedby = $modx->getLoginUserID();
493
-            }elseif ((!empty($pub_date)&& $pub_date<=$currentdate && $published)) {
494
-            $publishedon = $pub_date;
495
-            $publishedby = $modx->getLoginUserID();
496
-               }elseif ($was_published && !$published) {
497
-            $publishedon = 0;
498
-            $publishedby = 0;
499
-        } else {
500
-            $publishedon = 'publishedon';
501
-            $publishedby = 'publishedby';
502
-        }
479
+            // set publishedon and publishedby
480
+            $was_published = $existingDocument['published'];
503 481
 
504
-        // invoke OnBeforeDocFormSave event
505
-        $modx->invokeEvent("OnBeforeDocFormSave", array (
506
-            "mode" => "upd",
507
-            "id" => $id
508
-        ));
482
+            // keep original publish state, if change is not permitted
483
+            if (!$modx->hasPermission('publish_document')) {
484
+                $published = $was_published;
485
+                $pub_date = 'pub_date';
486
+                $unpub_date = 'unpub_date';
487
+            }
509 488
 
510
-        // update the document
511
-        $modx->db->update(
512
-            "introtext='{$introtext}', "
513
-            . "content='{$content}', "
514
-            . "pagetitle='{$pagetitle}', "
515
-            . "longtitle='{$longtitle}', "
516
-            . "type='{$type}', "
517
-            . "description='{$description}', "
518
-            . "alias='{$alias}', "
519
-            . "link_attributes='{$link_attributes}', "
520
-            . "isfolder={$isfolder}, "
521
-            . "richtext={$richtext}, "
522
-            . "published={$published}, "
523
-            . "pub_date={$pub_date}, "
524
-            . "unpub_date={$unpub_date}, "
525
-            . "parent={$parent}, "
526
-            . "template={$template}, "
527
-            . "menuindex={$menuindex}, "
528
-            . "searchable={$searchable}, "
529
-            . "cacheable={$cacheable}, "
530
-            . "editedby=" . $modx->getLoginUserID() . ", "
531
-            . "editedon={$currentdate}, "
532
-            . "publishedon={$publishedon}, "
533
-            . "publishedby={$publishedby}, "
534
-            . "contentType='{$contentType}', "
535
-            . "content_dispo={$contentdispo}, "
536
-            . "donthit={$donthit}, "
537
-            . "menutitle='{$menutitle}', "
538
-            . "hidemenu={$hidemenu}, "
539
-            . "alias_visible={$aliasvisible}"
540
-            , $tbl_site_content, "id='{$id}'");
541
-
542
-        // update template variables
543
-        $rs = $modx->db->select('id, tmplvarid', $tbl_site_tmplvar_contentvalues, "contentid='{$id}'");
544
-        $tvIds = array ();
545
-        while ($row = $modx->db->getRow($rs)) {
546
-            $tvIds[$row['tmplvarid']] = $row['id'];
547
-        }
548
-        $tvDeletions = array();
549
-        $tvChanges = array();
550
-        foreach ($tmplvars as $field => $value) {
551
-            if (!is_array($value)) {
552
-                if (isset($tvIds[$value])) $tvDeletions[] = $tvIds[$value];
489
+            // if it was changed from unpublished to published
490
+            if (!$was_published && $published) {
491
+                $publishedon = $currentdate;
492
+                $publishedby = $modx->getLoginUserID();
493
+                }elseif ((!empty($pub_date)&& $pub_date<=$currentdate && $published)) {
494
+                $publishedon = $pub_date;
495
+                $publishedby = $modx->getLoginUserID();
496
+                   }elseif ($was_published && !$published) {
497
+                $publishedon = 0;
498
+                $publishedby = 0;
553 499
             } else {
554
-                $tvId = $value[0];
555
-                $tvVal = $value[1];
500
+                $publishedon = 'publishedon';
501
+                $publishedby = 'publishedby';
502
+            }
556 503
 
557
-                if (isset($tvIds[$tvId])) {
558
-                    $tvChanges[] = array(array('tmplvarid' => $tvId, 'contentid' => $id, 'value' => $modx->db->escape($tvVal)), array('id' => $tvIds[$tvId]));
504
+            // invoke OnBeforeDocFormSave event
505
+            $modx->invokeEvent("OnBeforeDocFormSave", array (
506
+                "mode" => "upd",
507
+                "id" => $id
508
+            ));
509
+
510
+            // update the document
511
+            $modx->db->update(
512
+                "introtext='{$introtext}', "
513
+                . "content='{$content}', "
514
+                . "pagetitle='{$pagetitle}', "
515
+                . "longtitle='{$longtitle}', "
516
+                . "type='{$type}', "
517
+                . "description='{$description}', "
518
+                . "alias='{$alias}', "
519
+                . "link_attributes='{$link_attributes}', "
520
+                . "isfolder={$isfolder}, "
521
+                . "richtext={$richtext}, "
522
+                . "published={$published}, "
523
+                . "pub_date={$pub_date}, "
524
+                . "unpub_date={$unpub_date}, "
525
+                . "parent={$parent}, "
526
+                . "template={$template}, "
527
+                . "menuindex={$menuindex}, "
528
+                . "searchable={$searchable}, "
529
+                . "cacheable={$cacheable}, "
530
+                . "editedby=" . $modx->getLoginUserID() . ", "
531
+                . "editedon={$currentdate}, "
532
+                . "publishedon={$publishedon}, "
533
+                . "publishedby={$publishedby}, "
534
+                . "contentType='{$contentType}', "
535
+                . "content_dispo={$contentdispo}, "
536
+                . "donthit={$donthit}, "
537
+                . "menutitle='{$menutitle}', "
538
+                . "hidemenu={$hidemenu}, "
539
+                . "alias_visible={$aliasvisible}"
540
+                , $tbl_site_content, "id='{$id}'");
541
+
542
+            // update template variables
543
+            $rs = $modx->db->select('id, tmplvarid', $tbl_site_tmplvar_contentvalues, "contentid='{$id}'");
544
+            $tvIds = array ();
545
+            while ($row = $modx->db->getRow($rs)) {
546
+                $tvIds[$row['tmplvarid']] = $row['id'];
547
+            }
548
+            $tvDeletions = array();
549
+            $tvChanges = array();
550
+            foreach ($tmplvars as $field => $value) {
551
+                if (!is_array($value)) {
552
+                    if (isset($tvIds[$value])) $tvDeletions[] = $tvIds[$value];
559 553
                 } else {
560
-                    $tvAdded[] = array('tmplvarid' => $tvId, 'contentid' => $id, 'value' => $modx->db->escape($tvVal));
554
+                    $tvId = $value[0];
555
+                    $tvVal = $value[1];
556
+
557
+                    if (isset($tvIds[$tvId])) {
558
+                        $tvChanges[] = array(array('tmplvarid' => $tvId, 'contentid' => $id, 'value' => $modx->db->escape($tvVal)), array('id' => $tvIds[$tvId]));
559
+                    } else {
560
+                        $tvAdded[] = array('tmplvarid' => $tvId, 'contentid' => $id, 'value' => $modx->db->escape($tvVal));
561
+                    }
561 562
                 }
562 563
             }
563
-        }
564 564
 
565
-        if (!empty($tvDeletions)) {
566
-            $modx->db->delete($tbl_site_tmplvar_contentvalues, 'id IN('.implode(',', $tvDeletions).')');
567
-        }
568
-
569
-        if (!empty($tvAdded)) {
570
-            foreach ($tvAdded as $tv) {
571
-                $modx->db->insert($tv, $tbl_site_tmplvar_contentvalues);
565
+            if (!empty($tvDeletions)) {
566
+                $modx->db->delete($tbl_site_tmplvar_contentvalues, 'id IN('.implode(',', $tvDeletions).')');
572 567
             }
573
-        }
574 568
 
575
-        if (!empty($tvChanges)) {
576
-            foreach ($tvChanges as $tv) {
577
-                $modx->db->update($tv[0], $tbl_site_tmplvar_contentvalues, "id='{$tv[1]['id']}'");
569
+            if (!empty($tvAdded)) {
570
+                foreach ($tvAdded as $tv) {
571
+                    $modx->db->insert($tv, $tbl_site_tmplvar_contentvalues);
572
+                }
578 573
             }
579
-        }
580 574
 
581
-        // set document permissions
582
-        if ($use_udperms == 1 && is_array($document_groups)) {
583
-            $new_groups = array();
584
-            // process the new input
585
-            foreach ($document_groups as $value_pair) {
586
-                list($group, $link_id) = explode(',', $value_pair); // @see actions/mutate_content.dynamic.php @ line 1138 (permissions list)
587
-                $new_groups[$group] = $link_id;
575
+            if (!empty($tvChanges)) {
576
+                foreach ($tvChanges as $tv) {
577
+                    $modx->db->update($tv[0], $tbl_site_tmplvar_contentvalues, "id='{$tv[1]['id']}'");
578
+                }
588 579
             }
589 580
 
590
-            // grab the current set of permissions on this document the user can access
591
-            $isManager = $modx->hasPermission('access_permissions');
592
-            $isWeb     = $modx->hasPermission('web_access_permissions');
593
-            $rs = $modx->db->select(
594
-                'groups.id, groups.document_group',
595
-                "{$tbl_document_groups} AS groups
581
+            // set document permissions
582
+            if ($use_udperms == 1 && is_array($document_groups)) {
583
+                $new_groups = array();
584
+                // process the new input
585
+                foreach ($document_groups as $value_pair) {
586
+                    list($group, $link_id) = explode(',', $value_pair); // @see actions/mutate_content.dynamic.php @ line 1138 (permissions list)
587
+                    $new_groups[$group] = $link_id;
588
+                }
589
+
590
+                // grab the current set of permissions on this document the user can access
591
+                $isManager = $modx->hasPermission('access_permissions');
592
+                $isWeb     = $modx->hasPermission('web_access_permissions');
593
+                $rs = $modx->db->select(
594
+                    'groups.id, groups.document_group',
595
+                    "{$tbl_document_groups} AS groups
596 596
                     LEFT JOIN {$tbl_documentgroup_names} AS dgn ON dgn.id = groups.document_group",
597
-                "((1=".(int)$isManager." AND dgn.private_memgroup) OR (1=".(int)$isWeb." AND dgn.private_webgroup)) AND groups.document = '{$id}'"
598
-                );
599
-            $old_groups = array();
600
-            while ($row = $modx->db->getRow($rs)) $old_groups[$row['document_group']] = $row['id'];
601
-
602
-            // update the permissions in the database
603
-            $insertions = $deletions = array();
604
-            foreach ($new_groups as $group => $link_id) {
605
-                if (array_key_exists($group, $old_groups)) {
606
-                    unset($old_groups[$group]);
607
-                    continue;
608
-                } elseif ($link_id == 'new') {
609
-                    $insertions[] = '('.(int)$group.','.$id.')';
597
+                    "((1=".(int)$isManager." AND dgn.private_memgroup) OR (1=".(int)$isWeb." AND dgn.private_webgroup)) AND groups.document = '{$id}'"
598
+                    );
599
+                $old_groups = array();
600
+                while ($row = $modx->db->getRow($rs)) $old_groups[$row['document_group']] = $row['id'];
601
+
602
+                // update the permissions in the database
603
+                $insertions = $deletions = array();
604
+                foreach ($new_groups as $group => $link_id) {
605
+                    if (array_key_exists($group, $old_groups)) {
606
+                        unset($old_groups[$group]);
607
+                        continue;
608
+                    } elseif ($link_id == 'new') {
609
+                        $insertions[] = '('.(int)$group.','.$id.')';
610
+                    }
611
+                }
612
+                if (!empty($insertions)) {
613
+                    $modx->db->query("INSERT INTO {$tbl_document_groups} (document_group, document) VALUES ".implode(',', $insertions));
614
+                }
615
+                if (!empty($old_groups)) {
616
+                    $modx->db->delete($tbl_document_groups, "id IN (".implode(',', $old_groups).")");
617
+                }
618
+                // necessary to remove all permissions as document is public
619
+                if ((isset($_POST['chkalldocs']) && $_POST['chkalldocs'] == 'on')) {
620
+                    $modx->db->delete($tbl_document_groups, "document='{$id}'");
610 621
                 }
611 622
             }
612
-            if (!empty($insertions)) {
613
-                $modx->db->query("INSERT INTO {$tbl_document_groups} (document_group, document) VALUES ".implode(',', $insertions));
614
-            }
615
-            if (!empty($old_groups)) {
616
-                $modx->db->delete($tbl_document_groups, "id IN (".implode(',', $old_groups).")");
617
-            }
618
-            // necessary to remove all permissions as document is public
619
-            if ((isset($_POST['chkalldocs']) && $_POST['chkalldocs'] == 'on')) {
620
-                $modx->db->delete($tbl_document_groups, "document='{$id}'");
623
+
624
+            // do the parent stuff
625
+            if ($parent != 0) {
626
+                $fields = array('isfolder' => 1);
627
+                $modx->db->update($fields, $tbl_site_content, "id='{$_REQUEST['parent']}'");
621 628
             }
622
-        }
623 629
 
624
-        // do the parent stuff
625
-        if ($parent != 0) {
626
-            $fields = array('isfolder' => 1);
627
-            $modx->db->update($fields, $tbl_site_content, "id='{$_REQUEST['parent']}'");
628
-        }
630
+            // finished moving the document, now check to see if the old_parent should no longer be a folder
631
+            $rs = $modx->db->select('COUNT(id)', $tbl_site_content, "parent='{$oldparent}'");
632
+            $limit = $modx->db->getValue($rs);
629 633
 
630
-        // finished moving the document, now check to see if the old_parent should no longer be a folder
631
-        $rs = $modx->db->select('COUNT(id)', $tbl_site_content, "parent='{$oldparent}'");
632
-        $limit = $modx->db->getValue($rs);
634
+            if ($limit == 0) {
635
+                $fields = array('isfolder' => 0);
636
+                $modx->db->update($fields, $tbl_site_content, "id='{$oldparent}'");
637
+            }
633 638
 
634
-        if ($limit == 0) {
635
-            $fields = array('isfolder' => 0);
636
-            $modx->db->update($fields, $tbl_site_content, "id='{$oldparent}'");
637
-        }
638 639
 
640
+            // invoke OnDocFormSave event
641
+            $modx->invokeEvent("OnDocFormSave", array (
642
+                "mode" => "upd",
643
+                "id" => $id
644
+            ));
639 645
 
640
-        // invoke OnDocFormSave event
641
-        $modx->invokeEvent("OnDocFormSave", array (
642
-            "mode" => "upd",
643
-            "id" => $id
644
-        ));
646
+            // secure web documents - flag as private
647
+            include MODX_MANAGER_PATH . "includes/secure_web_documents.inc.php";
648
+            secureWebDocument($id);
645 649
 
646
-        // secure web documents - flag as private
647
-        include MODX_MANAGER_PATH . "includes/secure_web_documents.inc.php";
648
-        secureWebDocument($id);
649
-
650
-        // secure manager documents - flag as private
651
-        include MODX_MANAGER_PATH . "includes/secure_mgr_documents.inc.php";
652
-        secureMgrDocument($id);
650
+            // secure manager documents - flag as private
651
+            include MODX_MANAGER_PATH . "includes/secure_mgr_documents.inc.php";
652
+            secureMgrDocument($id);
653 653
 
654
-        // Set the item name for logger
655
-        $_SESSION['itemname'] = $no_esc_pagetitle;
654
+            // Set the item name for logger
655
+            $_SESSION['itemname'] = $no_esc_pagetitle;
656 656
 
657
-        if ($syncsite == 1) {
658
-            // empty cache
659
-            $keys = array('alias','parent','published','isfolder','menuindex','alias_visible');
660
-            $flag = '';
661
-            foreach($keys as $key) {
662
-                if ($existingDocument[$key]===$_POST[$key]) continue;
663
-                $flag = 'full';
664
-                break;
657
+            if ($syncsite == 1) {
658
+                // empty cache
659
+                $keys = array('alias','parent','published','isfolder','menuindex','alias_visible');
660
+                $flag = '';
661
+                foreach($keys as $key) {
662
+                    if ($existingDocument[$key]===$_POST[$key]) continue;
663
+                    $flag = 'full';
664
+                    break;
665
+                }
666
+                if($flag==='full') $modx->clearCache('full');
667
+                else               $modx->clearCache($id);
665 668
             }
666
-            if($flag==='full') $modx->clearCache('full');
667
-            else               $modx->clearCache($id);
668
-        }
669 669
 
670
-        if ($_POST['refresh_preview'] == '1')
671
-            $header = "Location: ".MODX_SITE_URL."index.php?id=$id&z=manprev";
672
-        else {
673
-            if ($_POST['stay'] != '2' && $id > 0) {
674
-                $modx->unlockElement(7, $id);
675
-            }
676
-            if ($_POST['stay'] != '') {
677
-                $id = $_REQUEST['id'];
678
-                if ($type == "reference") {
679
-                    // weblink
680
-                    $a = ($_POST['stay'] == '2') ? "27&id=$id" : "72&pid=$parent";
670
+            if ($_POST['refresh_preview'] == '1')
671
+                $header = "Location: ".MODX_SITE_URL."index.php?id=$id&z=manprev";
672
+            else {
673
+                if ($_POST['stay'] != '2' && $id > 0) {
674
+                    $modx->unlockElement(7, $id);
675
+                }
676
+                if ($_POST['stay'] != '') {
677
+                    $id = $_REQUEST['id'];
678
+                    if ($type == "reference") {
679
+                        // weblink
680
+                        $a = ($_POST['stay'] == '2') ? "27&id=$id" : "72&pid=$parent";
681
+                    } else {
682
+                        // document
683
+                        $a = ($_POST['stay'] == '2') ? "27&id=$id" : "4&pid=$parent";
684
+                    }
685
+                    $header = "Location: index.php?a=" . $a . "&r=1&stay=" . $_POST['stay'].$add_path;
681 686
                 } else {
682
-                    // document
683
-                    $a = ($_POST['stay'] == '2') ? "27&id=$id" : "4&pid=$parent";
687
+                    $header = "Location: index.php?a=3&id=$id&r=1".$add_path;
684 688
                 }
685
-                $header = "Location: index.php?a=" . $a . "&r=1&stay=" . $_POST['stay'].$add_path;
689
+            }
690
+            if (headers_sent()) {
691
+                $header = str_replace('Location: ','',$header);
692
+                echo "<script>document.location.href='$header';</script>\n";
686 693
             } else {
687
-                $header = "Location: index.php?a=3&id=$id&r=1".$add_path;
694
+                header($header);
688 695
             }
689
-        }
690
-        if (headers_sent()) {
691
-            $header = str_replace('Location: ','',$header);
692
-            echo "<script>document.location.href='$header';</script>\n";
693
-        } else {
694
-            header($header);
695
-        }
696
-        break;
697
-    default :
698
-        $modx->webAlertAndQuit("No operation set in request.");
696
+            break;
697
+        default :
698
+            $modx->webAlertAndQuit("No operation set in request.");
699 699
 }
Please login to merge, or discard this patch.