} $rarr['success'] = !empty($rarr['item']); die(json_encode($rarr)); } // delete item if (isset($_POST['del_item'])) { $item = $db->query('SELECT * FROM users WHERE id=:gid;', array(':gid' => $_POST['del_item']), 'dbRow', true); $rarr['success'] = $item->delete(); $rarr['notify'][] = array('User was successfully deleted', 'User Deleted', 'success'); die(json_encode($rarr)); } // check if we are updating a user or creating one if (isset($_POST['id']) && $_POST['id'] != '') { $item = $db->query('SELECT * FROM users WHERE id=:uid;', array(':uid' => $_POST['id']), 'dbRow', true); $rarr['notify'][] = array('User was successfully updated', 'User Updated', 'success'); } else { $item = new dbRow($db->handle, 'users'); $rarr['notify'][] = array('User was successfully created', 'User Created', 'success'); } // save user info $item->username = $_POST['username']; $item->groups = isset($_POST['groups']) ? implode(',', $_POST['groups']) : ''; // check if we need to update the password if (!empty($_POST['password'])) { $hash = version_compare(phpversion(), '5.3.7', '>') ? '$2y$12$' : '$1$'; $salt = substr(strtr(base64_encode(openssl_random_pseudo_bytes(22)), '+', '.'), 0, 22); $item->password = crypt($_POST['password'], $hash . $salt); } // save the user data to the database $rarr['success'] = $item->save(); die(json_encode($rarr));
} break; case '2': require 'inc/common/site/database.php'; require 'inc/classes/database.class.php'; $db = new database(); // generate a hash $hash = version_compare(phpversion(), '5.3.7', '>') ? '$2y$12$' : '$1$'; // generate random salt $salt = substr(strtr(base64_encode(openssl_random_pseudo_bytes(22)), '+', '.'), 0, 22); // add fisrt user $udata = new dbRow($db->handle, 'users'); $udata->username = $_POST['su']['user']; $udata->password = crypt($_POST['su']['pass'], $hash . $salt); $udata->groups = 'xSU'; $udata->save(); break; } $rarr['success'] = true; return_data(); } // the current step of setup $step = 1; // go to next step if file exists $step += file_exists('inc/common/site/database.php') ? 1 : 0; // check if we are on step 2 if ($step == 2) { require 'inc/common/site/database.php'; require 'inc/classes/database.class.php'; $db = new database(); // get the number of superusers