function dbUpdateGroup($group_id, $name, $is_default, $home_page_id) { try { // Make sure group exists if (!groupIdExists($group_id)) { addAlert("danger", lang("GROUP_INVALID_ID")); return false; } $db = pdoConnect(); global $db_table_prefix; // If this group is being set as the primary default group, then the current primary default group must be reset if ($is_default == '2') { $stmt_reset = $db->prepare("UPDATE " . $db_table_prefix . "groups\n SET is_default = '1' \n WHERE\n is_default = '2'"); $stmt_reset->execute(); } $stmt = $db->prepare("UPDATE " . $db_table_prefix . "groups\n SET name = :name, is_default = :is_default, home_page_id = :home_page_id \n WHERE\n id = :group_id\n LIMIT 1"); $sqlVars = array(":group_id" => $group_id, ":name" => $name, ":is_default" => $is_default, ":home_page_id" => $home_page_id); if ($stmt->execute($sqlVars)) { return true; } else { return false; } } catch (PDOException $e) { addAlert("danger", "Oops, looks like our database encountered an error."); error_log("Error in " . $e->getFile() . " on line " . $e->getLine() . ": " . $e->getMessage()); return false; } catch (ErrorException $e) { addAlert("danger", "Oops, looks like our server might have goofed. If you're an admin, please check the PHP error logs."); return false; } }
/** * Update group based on new details * @param int $group_id the id of the group to edit. * @param string $name the new name of the group * @param int $is_default 0 if the group is not a default group for new users, 1 if it is, 2 if it is also the primary default group for new users * @param int $home_page_id the id of the home page for users who have this group as their primary group * @return boolean true for success, false if failed */ function updateGroup($group_id, $name, $is_default, $home_page_id) { // This block automatically checks this action against the permissions database before running. if (!checkActionPermissionSelf(__FUNCTION__, func_get_args())) { addAlert("danger", "Sorry, you do not have permission to access this resource."); return false; } //Check if selected group exists if (!groupIdExists($group_id)) { addAlert("danger", "I'm sorry, the group id you specified is invalid!"); return false; } $groupDetails = fetchGroupDetails($group_id); //Fetch information specific to group //Update group name, if different from previous and not already taken $name = trim($name); if (strtolower($name) != strtolower($groupDetails['name'])) { if (groupNameExists($name)) { addAlert("danger", lang("ACCOUNT_PERMISSIONNAME_IN_USE", array($name))); return false; } elseif (minMaxRange(1, 50, $name)) { addAlert("danger", lang("ACCOUNT_PERMISSION_CHAR_LIMIT", array(1, 50))); return false; } } if (dbUpdateGroup($group_id, $name, $is_default, $home_page_id)) { addAlert("success", lang("GROUP_UPDATE", array($name))); return true; } else { return false; } }