Ejemplo n.º 1
0
 /**
  * \brief Generate the text for this plugin.
  */
 function Output()
 {
     global $PG_CONN;
     global $SysConf;
     if ($this->State != PLUGIN_STATE_READY) {
         return;
     }
     $user_pk = $SysConf['auth']['UserId'];
     /* Get array of groups that this user is an admin of */
     $GroupArray = GetGroupArray($user_pk);
     $V = "";
     /* If this is a POST, then process the request. */
     $Group = GetParm('grouppk', PARM_TEXT);
     if (!empty($Group)) {
         $rc = DeleteGroup($Group);
         if (empty($rc)) {
             /* Need to refresh the screen */
             $text = _("Group");
             $text1 = _("Deleted");
             $V .= displayMessage("{$text} {$GroupArray[$Group]} {$text1}.");
         } else {
             $V .= displayMessage($rc);
         }
     }
     /* Build HTML form */
     $text = _("Delete a Group");
     $V .= "<h4>{$text}</h4>\n";
     $V .= "<form name='formy' method='POST' action=" . Traceback_uri() . "?mod=group_delete>\n";
     /* Get array of users */
     $UserArray = Table2Array('user_pk', 'user_name', 'users');
     /* Remove from $GroupArray any active users.  A user must always have a group by the same name */
     foreach ($GroupArray as $group_fk => $group_name) {
         if (array_search($group_name, $UserArray)) {
             unset($GroupArray[$group_fk]);
         }
     }
     if (empty($GroupArray)) {
         $text = _("You have no groups you can delete.");
         echo "<p>{$text}<p>";
         return;
     }
     reset($GroupArray);
     if (empty($group_pk)) {
         $group_pk = key($GroupArray);
     }
     $text = _("Select the group to delete:  \n");
     $V .= "{$text}";
     /*** Display group select list, on change request new page with group= in url ***/
     $V .= Array2SingleSelect($GroupArray, "grouppk", $group_pk, false, false);
     $text = _("Delete");
     $V .= "<input type='submit' value='{$text}'>\n";
     $V .= "</form>\n";
     if (!$this->OutputToStdout) {
         return $V;
     }
     print "{$V}";
     return;
 }
 function Output()
 {
     global $PG_CONN;
     global $PERM_NAMES;
     global $SysConf;
     $user_pk = $SysConf['auth']['UserId'];
     /* GET parameters */
     $group_pk = GetParm('group', PARM_INTEGER);
     /* group_pk to manage */
     $gum_pk = GetParm('gum_pk', PARM_INTEGER);
     /* group_user_member_pk */
     $perm = GetParm('perm', PARM_INTEGER);
     /* Updated permission for gum_pk */
     $newuser = GetParm('newuser', PARM_INTEGER);
     /* New group      */
     $newperm = GetParm('newperm', PARM_INTEGER);
     /* New permission */
     if (empty($newperm)) {
         $newperm = 0;
     }
     /* If gum_pk is passed in, update either the group_perm or user_pk */
     $sql = "";
     if (!empty($gum_pk)) {
         /* Verify user has access */
         if (empty($group_pk)) {
             $gum_rec = GetSingleRec("group_user_member", "where group_user_member_pk='{$gum_pk}'");
             $group_pk = $gum_rec['group_fk'];
         }
         $this->VerifyAccess($user_pk, $group_pk);
         if ($perm === 0 or $perm === 1) {
             $sql = "update group_user_member set group_perm='{$perm}' where group_user_member_pk='{$gum_pk}'";
             $result = pg_query($PG_CONN, $sql);
             DBCheckResult($result, $sql, __FILE__, __LINE__);
             pg_free_result($result);
         } else {
             if ($perm === -1) {
                 $sql = "delete from group_user_member where group_user_member_pk='{$gum_pk}'";
                 $result = pg_query($PG_CONN, $sql);
                 DBCheckResult($result, $sql, __FILE__, __LINE__);
                 pg_free_result($result);
             }
         }
     } else {
         if (!empty($newuser) && !empty($group_pk)) {
             // before inserting this new record, delete any record for the same upload and group since
             // that would be a duplicate
             $sql = "delete from group_user_member where group_fk='{$group_pk}' and user_fk='{$newuser}'";
             $result = pg_query($PG_CONN, $sql);
             DBCheckResult($result, $sql, __FILE__, __LINE__);
             pg_free_result($result);
             if ($newperm >= 0) {
                 $sql = "insert into group_user_member (group_fk, user_fk, group_perm) values ({$group_pk}, {$newuser}, {$newperm})";
                 $result = pg_query($PG_CONN, $sql);
                 DBCheckResult($result, $sql, __FILE__, __LINE__);
                 pg_free_result($result);
             }
             $newperm = $newuser = 0;
         }
     }
     // start building the output buffer
     $V = "";
     /* define js_url */
     $V .= js_url();
     /* Get array of groups that this user is an admin of */
     $GroupArray = GetGroupArray($user_pk);
     if (empty($GroupArray)) {
         $text = _("You have no permission to manage any group.");
         echo "<p>{$text}<p>";
         return;
     }
     reset($GroupArray);
     if (empty($group_pk)) {
         $group_pk = key($GroupArray);
     }
     $text = _("Select the group to manage:  \n");
     $V .= "{$text}";
     /*** Display group select list, on change request new page with group= in url ***/
     $url = Traceback_uri() . "?mod=group_manage_users&group=";
     $onchange = "onchange=\"js_url(this.value, '{$url}')\"";
     $V .= Array2SingleSelect($GroupArray, "groupselect", $group_pk, false, false, $onchange);
     /* Create array of group_user_member group_perm possible values for use in a select list */
     $group_permArray = array(-1 => "None", 0 => "User", 1 => "Admin");
     /* Select all the user members of this group */
     $sql = "select group_user_member_pk, user_fk, group_perm, user_name from group_user_member, users\n              where group_fk='{$group_pk}' and user_fk=user_pk order by user_name";
     $result = pg_query($PG_CONN, $sql);
     DBCheckResult($result, $sql, __FILE__, __LINE__);
     $GroupMembersArray = pg_fetch_all($result);
     pg_free_result($result);
     /* Permissions Table */
     $V .= "<p><table border=1>";
     $UserText = _("User");
     $PermText = _("Permission");
     $V .= "<tr><th>{$UserText}</th><th>{$PermText}</th></tr>";
     if (!empty($GroupMembersArray)) {
         // does this group have childen ?
         foreach ($GroupMembersArray as $GroupMember) {
             $V .= "<tr>";
             $V .= "<td>";
             // user
             $V .= $GroupMember['user_name'];
             $V .= "</td>";
             $V .= "<td>";
             // permission
             $url = Traceback_uri() . "?mod=group_manage_users&gum_pk={$GroupMember['group_user_member_pk']}&perm=";
             $onchange = "onchange=\"js_url(this.value, '{$url}')\"";
             $V .= Array2SingleSelect($group_permArray, "permselect", $GroupMember['group_perm'], false, false, $onchange);
             $V .= "</td>";
             $V .= "</tr>";
         }
     }
     /* Print one extra row for adding perms */
     $V .= "<tr>";
     $V .= "<td>";
     // user
     $url = Traceback_uri() . "?mod=group_manage_users&newperm={$newperm}&group={$group_pk}&newuser="******"onchange=\"js_url(this.value, '{$url}')\"";
     $Selected = empty($newuser) ? "" : $newuser;
     $UserArray = Table2Array("user_pk", "user_name", "users", " ", "order by user_name");
     $V .= Array2SingleSelect($UserArray, "userselectnew", $Selected, true, false, $onchange);
     $V .= "</td>";
     $V .= "<td>";
     // permission
     $url = Traceback_uri() . "?mod=group_manage_users&newuser={$newuser}&group={$group_pk}&newperm=";
     $onchange = "onchange=\"js_url(this.value, '{$url}')\"";
     $Selected = $newperm;
     $V .= Array2SingleSelect($group_permArray, "permselectnew", $Selected, false, false, $onchange);
     $V .= "</td>";
     $V .= "</tr>";
     $V .= "</table>";
     $text = _("All user permissions take place immediately when a value is changed.  There is no submit button.");
     $V .= "<p>" . $text;
     $text = _("Add new users on the last line.");
     $V .= "<br>" . $text;
     if (!$this->OutputToStdout) {
         return $V;
     }
     print "{$V}";
     return;
 }