public static function edit()
 {
     Controller::requirePermissions(["AdminAccessDashboard", "AdminUsers"]);
     if (empty($_POST)) {
         View::load("acp/user_edit.twig", ["object" => current(UserModel::get($_GET["id"])), "groups" => UserGroup::get(), "organizations" => Organization::get()]);
     } else {
         UserModel::update($_POST["id"], $_POST["email"], $_POST["full-name"], $_POST["phone-number"], $_POST["password"], $_POST["group"], $_POST["organization"]);
     }
     Controller::addAlert(new Alert("success", "User updated successfully"));
     Controller::redirect("/acp/user");
 }
 public static function install()
 {
     if (InstallerModel::databaseLocked()) {
         View::load("install/database_locked.twig");
     } else {
         if (empty($_POST)) {
             View::load("install/install.twig", ["checks" => InstallerModel::checkRequirements()]);
         } else {
             InstallerModel::installDatabase(true);
             $adminGroupId = current(UserGroup::get(null, "Root Admin"))->id;
             User::add($_POST["email"], $_POST["full-name"], $_POST["phone-number"], $_POST["password"], $adminGroupId);
             View::load("install/complete.twig");
         }
     }
 }
 public static function delete()
 {
     Controller::requirePermissions(["AdminAccessDashboard", "AdminUserGroups", "PerformDeletionOperations"]);
     if (!array_key_exists("id", $_GET)) {
         Controller::redirect("/acp/group");
     }
     $group = current(UserGroupModel::get($_GET["id"]));
     if (!$group) {
         Controller::addAlert(new Alert("danger", "The specified group does not exist"));
     } else {
         if ($group->special) {
             Controller::addAlert(new Alert("danger", "The specified group is a special group and cannot be deleted as it would break core functionality"));
         } else {
             if (($count = count($group->getUsers())) > 0) {
                 Controller::addAlert(new Alert("danger", "There are " . $count . " users currently in " . "the specified group, you must assign them to a different group before you can delete this group"));
             } else {
                 $group->delete();
                 Controller::addAlert(new Alert("success", "User group deleted successfully"));
             }
         }
     }
     Controller::redirect("/acp/group");
 }
 /**
  * Load initial data
  */
 protected static function loadInitialData()
 {
     $allPermissions = Permission::get();
     $allPermissionIds = [];
     foreach ($allPermissions as $permission) {
         $allPermissionIds[] = $permission->id;
     }
     UserGroup::add("Root Admin", true, true);
     UserGroup::add("Committee", ["AccessAdminDashboard"]);
     UserGroup::add("Head Coach");
     UserGroup::add("Coach");
     UserGroup::add("Guest", [], true);
 }
 /**
  * Get the current visitor
  *
  * @return \sma\models\User visitor
  */
 public static function getVisitor()
 {
     if (!static::$visitor) {
         if (!array_key_exists("user_id", $_SESSION)) {
             self::attemptAutologin();
         }
         if (array_key_exists("user_id", $_SESSION)) {
             static::$visitor = self::get($_SESSION["user_id"])[0];
         } else {
             $guestGroup = current(UserGroup::get(null, "Guest"));
             $user = new User();
             $user->id = 0;
             $user->group = $guestGroup;
             $user->groupId = $guestGroup->id;
             static::$visitor = $user;
         }
     }
     return static::$visitor;
 }