/** * \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; /* GET parameters */ $folder_pk = GetParm('folder', PARM_INTEGER); $upload_pk = GetParm('upload', PARM_INTEGER); $users_group_pk = GetParm('group_pk', PARM_INTEGER); $group_pk = GetParm('group', PARM_INTEGER); $perm_upload_pk = GetParm('permupk', PARM_INTEGER); $perm = GetParm('perm', PARM_INTEGER); $newgroup = GetParm('newgroup', PARM_INTEGER); $newperm = GetParm('newperm', PARM_INTEGER); $public_perm = GetParm('public', PARM_INTEGER); // start building the output buffer $V = ""; /* If perm_upload_pk is passed in, update either the perm or group_pk */ $sql = ""; if (!empty($perm_upload_pk)) { if ($perm === 0) { $sql = "delete from perm_upload where perm_upload_pk='{$perm_upload_pk}'"; } else { if (!empty($perm)) { $sql = "update perm_upload set perm='{$perm}' where perm_upload_pk='{$perm_upload_pk}'"; } else { if (!empty($group_pk)) { $sql = "update perm_upload set group_fk='{$group_pk}' where perm_upload_pk='{$perm_upload_pk}'"; } } } if (!empty($sql)) { $result = @pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); pg_free_result($result); } } else { if (!empty($newgroup) and !empty($newperm)) { // before inserting this new record, delete any record for the same upload and group since // that would be a duplicate $sql = "delete from perm_upload where upload_fk={$upload_pk} and group_fk={$newgroup}"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); pg_free_result($result); // Don't insert a PERM_NONE. NONE is the default if ($newperm != PERM_NONE) { $sql = "insert into perm_upload (perm, upload_fk, group_fk) values ({$newperm}, {$upload_pk}, {$newgroup})"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); pg_free_result($result); } $newperm = $newgroup = 0; } else { if (!empty($public_perm)) { $sql = "update upload set public_perm='{$public_perm}' where upload_pk='{$upload_pk}'"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); pg_free_result($result); } } } $root_folder_pk = GetUserRootFolder(); if (empty($folder_pk)) { $folder_pk = $root_folder_pk; } // Get folder array folder_pk => folder_name $FolderArray = array(); GetFolderArray($root_folder_pk, $FolderArray); /* define js_url */ $V .= js_url(); $text = _("Select the folder that contains the upload: \n"); $V .= "{$text}"; /*** Display folder select list, on change request new page with folder= in url ***/ $url = Traceback_uri() . "?mod=upload_permissions&folder="; $onchange = "onchange=\"js_url(this.value, '{$url}')\""; $V .= Array2SingleSelect($FolderArray, "folderselect", $folder_pk, false, false, $onchange); /*** Display upload select list, on change, request new page with new upload= in url ***/ $text = _("Select the upload you wish to edit: \n"); $V .= "<br>{$text}"; // Get list of all upload records in this folder that the user has PERM_ADMIN $UploadList = FolderListUploads_perm($folder_pk, PERM_ADMIN); /* if (empty($UploadList)) { echo "You have no uploads in this folder for which you are an admin. Hit the back button"; return; } */ // Make data array for upload select list. Key is upload_pk, value is a composite // of the upload_filename and upload_ts. // Note that $UploadList may be empty so $UploadArray will be empty $UploadArray = array(); foreach ($UploadList as $UploadRec) { $SelectText = htmlentities($UploadRec['name']); if (!empty($UploadRec['upload_ts'])) { $SelectText .= ", " . substr($UploadRec['upload_ts'], 0, 19); } $UploadArray[$UploadRec['upload_pk']] = $SelectText; } /* Get selected upload info to display*/ if (empty($upload_pk)) { // no upload selected, so use the top one in the select list reset($UploadArray); $upload_pk = key($UploadArray); } /* Upload select list */ $url = Traceback_uri() . "?mod=upload_permissions&folder={$folder_pk}&upload="; $onchange = "onchange=\"js_url(this.value, '{$url}')\""; $V .= Array2SingleSelect($UploadArray, "uploadselect", $upload_pk, false, false, $onchange); /* Get permissions for this upload */ if (!empty($UploadArray)) { // Get upload.public_perm $sql = "select public_perm from upload where upload_pk='{$upload_pk}'"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); $Row = pg_fetch_all($result); $public_perm = $Row[0]['public_perm']; pg_free_result($result); $text1 = _("Public Permission"); $V .= "<p>{$text1} "; $url = Traceback_uri() . "?mod=upload_permissions&folder={$folder_pk}&upload={$upload_pk}&public="; $onchange = "onchange=\"js_url(this.value, '{$url}')\""; $V .= Array2SingleSelect($PERM_NAMES, "publicpermselect", $public_perm, false, false, $onchange); $sql = "select perm_upload_pk, perm, group_pk, group_name from groups, perm_upload where group_fk=group_pk and upload_fk='{$upload_pk}'"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); $PermArray = pg_fetch_all($result); pg_free_result($result); /* Get master array of groups */ $sql = "select group_pk, group_name from groups order by group_name"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); $GroupArray = array(); while ($GroupRow = pg_fetch_assoc($result)) { $GroupArray[$GroupRow['group_pk']] = $GroupRow['group_name']; } pg_free_result($result); /* Permissions Table */ $V .= "<p><table border=1>"; $GroupText = _("Group"); $PermText = _("Permission"); $V .= "<tr><th>{$GroupText}</th><th>{$PermText}</th></tr>"; foreach ($PermArray as $PermRow) { $V .= "<tr>"; $V .= "<td>"; // group $url = Traceback_uri() . "?mod=upload_permissions&group_pk={$users_group_pk}&upload={$upload_pk}&folder={$folder_pk}&permupk={$PermRow['perm_upload_pk']}&group="; $onchange = "onchange=\"js_url(this.value, '{$url}')\""; $V .= Array2SingleSelect($GroupArray, "groupselect", $PermRow['group_pk'], false, false, $onchange); $V .= "</td>"; $V .= "<td>"; // permission $url = Traceback_uri() . "?mod=upload_permissions&group_pk={$users_group_pk}&upload={$upload_pk}&folder={$folder_pk}&permupk={$PermRow['perm_upload_pk']}&perm="; $onchange = "onchange=\"js_url(this.value, '{$url}')\""; $V .= Array2SingleSelect($PERM_NAMES, "permselect", $PermRow['perm'], false, false, $onchange); $V .= "</td>"; $V .= "</tr>"; } /* Print one extra row for adding perms */ $V .= "<tr>"; $V .= "<td>"; // group $url = Traceback_uri() . "?mod=upload_permissions&group_pk={$users_group_pk}&upload={$upload_pk}&folder={$folder_pk}&newperm={$newperm}&newgroup="; $onchange = "onchange=\"js_url(this.value, '{$url}')\""; $Selected = empty($newgroup) ? "" : $newgroup; $V .= Array2SingleSelect($GroupArray, "groupselectnew", $Selected, true, false, $onchange); $V .= "</td>"; $V .= "<td>"; // permission $url = Traceback_uri() . "?mod=upload_permissions&group_pk={$users_group_pk}&upload={$upload_pk}&folder={$folder_pk}&newgroup={$newgroup}&newperm="; $onchange = "onchange=\"js_url(this.value, '{$url}')\""; $Selected = empty($newperm) ? "" : $newperm; $V .= Array2SingleSelect($PERM_NAMES, "permselectnew", $Selected, false, false, $onchange); $V .= "</td>"; $V .= "</tr>"; $V .= "</table>"; $text = _("All upload permissions take place immediately when a value is changed. There is no submit button."); $V .= "<p>" . $text; $text = _("Add new groups on the last line."); $V .= "<br>" . $text; } else { $text = _("You have no permission to change permissions on any upload in this folder."); $V .= "<p>{$text}<p>"; } $V .= "<hr>"; $V .= $this->DisplayGroupMembership(); if (!$this->OutputToStdout) { return $V; } print "{$V}"; return; }
/** * \brief Update forms * * \param $rf_pk - for the license to update, empty to add * * \return The input form as a string */ function Updatefm($rf_pk) { global $PG_CONN; $text = _("The Short Name and License Text must be unique."); echo "<b>{$text}</b><br>"; $rf_active = $marydone = $rf_shortname = $rf_fullname = $rf_text_updatable = $rf_detector_type = $rf_text = $rf_url = $rf_notes = ""; $rf_pk_update = ""; if (0 < count($_POST)) { $rf_pk_update = $_POST['rf_pk']; if (!empty($rf_pk)) { $rf_pk_update = $rf_pk; } else { if (empty($rf_pk_update)) { $rf_pk_update = $_GET['rf_pk']; } } $rf_active = $_POST['rf_active']; $marydone = $_POST['marydone']; $rf_text_updatable = $_POST['rf_text_updatable']; $rf_detector_type = $_POST['rf_detector_type']; $rf_shortname = pg_escape_string($_POST['rf_shortname']); $rf_fullname = pg_escape_string($_POST['rf_fullname']); $rf_url = pg_escape_string($_POST['rf_url']); $rf_notes = pg_escape_string($_POST['rf_notes']); $rf_text = pg_escape_string($_POST['rf_text']); } $ob = ""; // output buffer $ob .= "<FORM name='Updatefm' action='?mod=" . $this->Name . "&rf_pk={$rf_pk_update}" . "' method='POST'>"; $req_marydone = $req_shortname = ""; if ($rf_pk) { $req_marydone = $_GET['req_marydone']; $req_shortname = $_GET['req_shortname']; } $ob .= "<input type=hidden name=rf_pk value='{$rf_pk}'>"; $ob .= "<input type=hidden name=req_marydone value='{$req_marydone}'"; $ob .= "<input type=hidden name=req_shortname value='{$req_shortname}'>"; $ob .= "<table>"; if ($rf_pk) { $sql = "select * from license_ref where rf_pk='{$rf_pk}'"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); // print simple message if we have no results if (pg_num_rows($result) == 0) { $ob .= "</table>"; $text = _("No licenses matching this key"); $text1 = _("was found"); $ob .= "<br>{$text} ({$rf_pk}) {$text1}.<br>"; pg_free_result($result); return $ob; } $ob .= "<input type=hidden name=updateit value=true>"; $row = pg_fetch_assoc($result); pg_free_result($result); } else { $ob .= "<input type=hidden name=addit value=true>"; $row = array(); } if ($row) { $rf_active = $row['rf_active']; $marydone = $row['marydone']; $rf_shortname = $row['rf_shortname']; $rf_fullname = $row['rf_fullname']; $rf_text_updatable = $row['rf_text_updatable']; $rf_detector_type = $row['rf_detector_type']; $rf_text = $row['rf_text']; $rf_url = $row['rf_url']; $rf_notes = $row['rf_notes']; } $ob .= "<tr>"; $active = $rf_active == 't' || $rf_active == 'true' ? "Yes" : "No"; $select = Array2SingleSelect(array("true" => "Yes", "false" => "No"), "rf_active", $active); $text = _("Active"); $ob .= "<td align=right>{$text}</td>"; $ob .= "<td align=left>{$select}</td>"; $ob .= "</tr>"; $ob .= "<tr>"; $marydone = $marydone == 't' || 'true' == $marydone ? "Yes" : "No"; $select = Array2SingleSelect(array("true" => "Yes", "false" => "No"), "marydone", $marydone); $text = _("Checked"); $ob .= "<td align=right>{$text}</td>"; $ob .= "<td align=left>{$select}</td>"; $ob .= "</tr>"; $ob .= "<tr>"; // $ob .= "<td align=right>Short name<br>(read only)</td>"; // $ob .= "<td><input readonly='readonly' type='text' name='rf_shortname' value='$row[rf_shortname]' size=80></td>"; $text = _("Short name"); $ob .= "<td align=right>{$text}</td>"; $ob .= "<td><input type='text' name='rf_shortname' value='{$rf_shortname}' size=80></td>"; $ob .= "</tr>"; $ob .= "<tr>"; $text = _("Full name"); $ob .= "<td align=right>{$text}</td>"; $ob .= "<td><input type='text' name='rf_fullname' value='{$rf_fullname}' size=80></td>"; $ob .= "</tr>"; $ob .= "<tr>"; $updatable = $rf_text_updatable == 't' || 'true' == $rf_text_updatable ? true : false; if (empty($rf_pk) || $updatable) { $rotext = ''; $rooption = ''; } else { $text = _("(read only)"); $rotext = "<br>{$text}"; $rooption = "readonly='readonly'"; } $text = _("License Text"); $ob .= "<td align=right>{$text} {$rotext}</td>"; $ob .= "<td><textarea name='rf_text' rows=10 cols=80 {$rooption}>" . $rf_text . "</textarea></td> "; $ob .= "</tr>"; $ob .= "<tr>"; $tupable = $rf_text_updatable == 't' || 'true' == $rf_text_updatable ? "Yes" : "No"; $select = Array2SingleSelect(array("true" => "Yes", "false" => "No"), "rf_text_updatable", $tupable); $text = _("Text Updatable"); $ob .= "<td align=right>{$text}</td>"; $ob .= "<td align=left>{$select}</td>"; $ob .= "</tr>"; $ob .= "<tr>"; $dettype = $rf_detector_type == '2' ? "Nomos" : "Reference License"; $select = Array2SingleSelect(array("1" => "Reference License", "2" => "Nomos"), "rf_detector_type", $dettype); $text = _("Detector Type"); $ob .= "<td align=right>{$text}</td>"; $ob .= "<td align=left>{$select}</td>"; $ob .= "</tr>"; $ob .= "<tr>"; $text = _("URL"); $ob .= "<td align=right>{$text}"; $ob .= "<a href='{$rf_url}'><image border=0 src=" . Traceback_uri() . "images/right-point-bullet.gif></a></td>"; $ob .= "<td><input type='text' name='rf_url' value='{$rf_url}' size=80></td>"; $ob .= "</tr>"; $ob .= "<tr>"; $text = _("Public Notes"); $ob .= "<td align=right>{$text}</td>"; $ob .= "<td><textarea name='rf_notes' rows=5 cols=80>" . $rf_notes . "</textarea></td> "; $ob .= "</tr>"; $ob .= "</table>"; if ($rf_pk || $rf_pk_update) { $text = _("Update"); $ob .= "<INPUT type='submit' value='{$text}'>\n"; } else { $text = _("Add License"); $ob .= "<INPUT type='submit' value='{$text}'>\n"; } $ob .= "</FORM>\n"; return $ob; }
/** * \brief Build the input form * * \return The input form as a string */ function Inputfm() { $V = "<FORM name='Inputfm' action='?mod=" . $this->Name . "' method='POST'>"; $V .= _("What license family do you wish to view:<br>"); // qualify by marydone, short name and long name // all are optional $V .= "<p>"; $V .= _("Filter: "); $V .= "<SELECT name='req_marydone'>\n"; $Selected = @$_REQUEST['req_marydone'] == 'all' ? " SELECTED " : ""; $text = _("All"); $V .= "<option value='all' {$Selected}> {$text} </option>"; $Selected = @$_REQUEST['req_marydone'] == 'done' ? " SELECTED " : ""; $text = _("Checked"); $V .= "<option value='done' {$Selected}> {$text} </option>"; $Selected = @$_REQUEST['req_marydone'] == 'notdone' ? " SELECTED " : ""; $text = _("Not Checked"); $V .= "<option value='notdone' {$Selected}> {$text} </option>"; $V .= "</SELECT>"; $V .= " "; // by short name -ajax-> fullname $V .= _("License family name: "); $Shortnamearray = $this->FamilyNames(); $Shortnamearray = array("All" => "All") + $Shortnamearray; $Selected = @$_REQUEST['req_shortname']; $Pulldown = Array2SingleSelect($Shortnamearray, "req_shortname", $Selected); $V .= $Pulldown; $V .= " "; $text = _("Find"); $V .= "<INPUT type='submit' value='{$text}'>\n"; $V .= "</FORM>\n"; $V .= "<hr>"; return $V; }
function Output() { global $PG_CONN; if ($this->State != PLUGIN_STATE_READY) { return; } $V = ""; $folder_pk = GetParm('folder', PARM_TEXT); $FolderSelectId = GetParm('selectfolderid', PARM_INTEGER); if (empty($FolderSelectId)) { $FolderSelectId = GetUserRootFolder(); } $NewName = GetArrayVal("newname", $_POST); $NewDesc = GetArrayVal("newdesc", $_POST); $upload_pk = GetArrayVal("upload_pk", $_POST); if (empty($upload_pk)) { $upload_pk = GetParm('upload', PARM_INTEGER); } /* Check Upload permission */ if (!empty($upload_pk)) { $UploadPerm = GetUploadPerm($upload_pk); if ($UploadPerm < PERM_WRITE) { $text = _("Permission Denied"); echo "<h2>{$text}<h2>"; return; } } $rc = $this->UpdateUploadProperties($upload_pk, $NewName, $NewDesc); if ($rc == 0) { $text = _("Nothing to Change"); $V .= displayMessage($text); } else { if ($rc == 1) { $text = _("Upload Properties successfully changed"); $V .= displayMessage($text); } } /* define js_url */ $V .= js_url(); /* Build the HTML form */ $V .= "<form name='formy' method='post'>\n"; // no url = this url $V .= "<ol>\n"; $text = _("Select the folder that contains the upload: \n"); $V .= "<li>{$text}"; /*** Display folder select list, on change request new page with folder= in url ***/ $Uri = Traceback_uri() . "?mod=" . $this->Name . "&selectfolderid="; $V .= "<select name='oldfolderid' onChange='window.location.href=\"{$Uri}\" + this.value'>\n"; $V .= FolderListOption(-1, 0, 1, $FolderSelectId); $V .= "</select><P />\n"; /*** Display upload select list, on change, request new page with new upload= in url ***/ $text = _("Select the upload you wish to edit: \n"); $V .= "<li>{$text}"; // Get list of all upload records in this folder $UploadList = FolderListUploads_perm($FolderSelectId, PERM_WRITE); // Make data array for upload select list. Key is upload_pk, value is a composite // of the upload_filename and upload_ts. $UploadArray = array(); foreach ($UploadList as $UploadRec) { $SelectText = htmlentities($UploadRec['name']); if (!empty($UploadRec['upload_ts'])) { $SelectText .= ", " . substr($UploadRec['upload_ts'], 0, 19); } $UploadArray[$UploadRec['upload_pk']] = $SelectText; } /* Get selected upload info to display*/ if (empty($upload_pk)) { // no upload selected, so use the top one in the select list reset($UploadArray); $upload_pk = key($UploadArray); } if ($upload_pk) { // case where upload is set in the URL $sql = "SELECT * FROM upload WHERE upload_pk = '{$upload_pk}'"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); if (pg_num_rows($result) == 0) { /* Bad upload_pk */ $text = _("Missing upload."); $V .= displayMessage($text); pg_free_result($result); return 0; } $UploadRec = pg_fetch_assoc($result); pg_free_result($result); $V .= "<INPUT type='hidden' name='upload_pk' value='{$upload_pk}' />\n"; } else { // no uploads in the folder $UploadRec = array(); } $url = Traceback_uri() . "?mod=upload_properties&folder={$folder_pk}&upload="; $onchange = "onchange=\"js_url(this.value, '{$url}')\""; $V .= Array2SingleSelect($UploadArray, "uploadselect", $upload_pk, false, false, $onchange); /* Input upload_filename */ $text = _("Upload name: \n"); $V .= "<li>{$text}"; if (empty($UploadRec['upload_filename'])) { $upload_filename = ""; } else { $upload_filename = htmlentities($UploadRec['upload_filename']); } $V .= "<INPUT type='text' name='newname' size=40 value='{$upload_filename}' />\n"; /* Input upload_desc */ $text = _("Upload description: \n"); $V .= "<li>{$text}"; if (empty($UploadRec['upload_desc'])) { $upload_desc = ""; } else { $upload_desc = htmlentities($UploadRec['upload_desc'], ENT_QUOTES); } $V .= "<INPUT type='text' name='newdesc' size=60 value='{$upload_desc}' />\n"; $V .= "</ol>\n"; $text = _("Edit"); $V .= "<input type='submit' value='{$text}!'>\n"; $V .= "</form>\n"; if (!$this->OutputToStdout) { return $V; } print "{$V}"; return; }
/** * \brief Search the whole repository for containers with names * similar to $FileName (based on the beggining text of $FileName) * * \param $uploadtree_pk - the pk of $FileName. * * \return html (select list) for picking suggestions. */ function SuggestionsPick($FileName, $uploadtree_pk, &$rtncount) { global $PG_CONN; /* find the root of $FileName. Thats the beginning alpha part. */ $BaseFN = basename($FileName); $delims = "/-.0123456789 \t\n\rxb"; $NameRoot = ltrim($BaseFN, $delims); $NameRoot = strtok($NameRoot, $delims); /* Only make suggestions with matching file extensions */ $ext = GetFileExt($FileName); $tail = ".{$ext}"; if (empty($NameRoot)) { return ""; } /* find non artifact containers with names similar to $FileName */ $sql = "select uploadtree_pk from uploadtree\n where ((ufile_mode & (1<<29))!=0) AND ((ufile_mode & (1<<28))=0)\n and (ufile_name like '{$NameRoot}%{$tail}') \n and (uploadtree_pk != '{$uploadtree_pk}') limit 100"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); $SuggestionsArray = array(); while ($row = pg_fetch_assoc($result)) { $PathArray = Dir2Path($row['uploadtree_pk'], 'uploadtree'); $SuggestionsArray[$row['uploadtree_pk']] = Uploadtree2PathStr($PathArray); } pg_free_result($result); $rtncount = count($SuggestionsArray); if ($rtncount == 0) { return ""; } /* Order the select list by the beginning of the path */ natsort($SuggestionsArray); $Options = "id=SuggestPick onchange='AppJump(this.value)')"; $SelectList = Array2SingleSelect($SuggestionsArray, "SuggestionsPick", "", true, true, $Options); return $SelectList; }
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; }
/** * \brief Generate html to pick the application that will be called after * the items are identified. * * Select list element ID is "apick" * * \param $SLName - select list name * \param $SelectedVal - selected value * \param $label - label of select list * * \return string containing html to pick the application that will be called after * the items are identified */ function ApplicationPick($SLName, $SelectedVal, $label) { /* select the apps that are registered to accept item1, item2 pairs. * At this time (pre 2.x) we don't know enough about the plugins * to know if they can take a pair. Till then, the list is * hardcoded. */ $AppList = array("nomosdiff" => "License Difference", "bucketsdiff" => "Bucket Difference"); $Options = "id=apick"; $SelectList = Array2SingleSelect($AppList, $SLName, $SelectedVal, false, true, $Options); $StrOut = "{$SelectList} {$label}"; return $StrOut; }