コード例 #1
0
ファイル: member.php プロジェクト: BackupTheBerlios/k4bb
 public function Execute(Template $template, Session $session, $request)
 {
     /* Create the ancestors bar (if we run into any trouble */
     $template = CreateAncestors($template, $template['L_INFORMATION']);
     $this->dba = DBA::Open();
     /* If we're logged in */
     if ($session['user'] instanceof Member) {
         $groups = $this->dba->Query("SELECT * FROM " . GROUPS . " WHERE id = " . intval($request['gid']));
         /* Get the group from the database */
         if ($groups->NumRows() == 1) {
             /* Set the group variable */
             $group = $groups->FetchRow();
             /* If we fit the profile of the groups moderator */
             if ($group['mod_name'] == $session['user']['name'] && $group['mod_id'] == $session['user']['id']) {
                 /* Get the user's profile that we would like to add */
                 $user = $this->dba->GetRow("SELECT * FROM " . USERS . " WHERE name = '" . htmlspecialchars($request['username']) . "'");
                 if (!empty($user) && isset($user['id'])) {
                     /* Check if this user is already a part of this group */
                     if ($this->dba->Query("SELECT * FROM " . USER_IN_GROUP . " WHERE group_id = " . $group['id'] . " AND id = " . $user['id'])->NumRows() == 0) {
                         $ug = new Usergroup($session);
                         /* Add the user to the group */
                         if ($ug->AddUserToUsergroup($group['id'], $user['id'], $user['name'])) {
                             /* Redirect us */
                             header("Location: member.php?act=lookup&gid=" . $group['id']);
                         } else {
                             return new Error($template['L_ERRORADDINGUTG'], $template);
                         }
                     } else {
                         return new Error($template['L_USERINGROUP'], $template);
                     }
                 } else {
                     return new Error($template['L_USERDOESNTEXIST'], $template);
                 }
             } else {
                 return new Error($template['L_YOUNEEDPERMS'], $template);
             }
         } else {
             return new Error($template['L_GROUPDOESNTEXIST'], $template);
         }
     } else {
         return new Error($template['L_NEEDLOGGEDIN'], $template);
     }
     /* Set the number of queries */
     $template['num_queries'] = $session->dba->num_queries;
     return TRUE;
 }