/**
  * \brief Generate the text for this plugin.
  */
 public function Output()
 {
     /* If this is a POST, then process the request. */
     $ParentId = GetParm('parentid', PARM_INTEGER);
     $NewFolder = GetParm('newname', PARM_TEXT);
     $Desc = GetParm('description', PARM_TEXT);
     if (!empty($ParentId) && !empty($NewFolder)) {
         $rc = $this->create($ParentId, $NewFolder, $Desc);
         if ($rc == 1) {
             /* Need to refresh the screen */
             $text = _("Folder");
             $text1 = _("Created");
             $this->vars['message'] = "{$text} " . htmlentities($NewFolder) . " {$text1}";
         } else {
             if ($rc == 4) {
                 $text = _("Folder");
                 $text1 = _("Exists");
                 $this->vars['message'] = "{$text} " . htmlentities($NewFolder) . " {$text1}";
             }
         }
     }
     $root_folder_pk = GetUserRootFolder();
     $formVars["folderOptions"] = FolderListOption($root_folder_pk, 0);
     return $this->renderString("admin-folder-create-form.html.twig", $formVars);
 }
/**
 * \brief Returns an array of uploads in a folder.
 *  Only uploads for which the user has permission >= $perm are returned
 *  This does NOT recurse.
 *  The returned array is sorted by ufile_name and upload_pk.
 * \param $ParentFolder Optional folder_pk, default is users root folder.
 * \param $perm minimum permission
 * \return array{upload_pk, upload_desc, upload_ts, ufile_name}
 *  for all uploads in a given folder.
 *
 */
function FolderListUploads_perm($ParentFolder, $perm)
{
    global $PG_CONN;
    if (empty($PG_CONN)) {
        return;
    }
    if (empty($ParentFolder)) {
        return;
    }
    if ($ParentFolder == "-1") {
        $ParentFolder = GetUserRootFolder();
    }
    $groupId = Auth::getGroupId();
    /* @var $uploadDao UploadDao */
    $uploadDao = $GLOBALS['container']->get('dao.upload');
    $List = array();
    /* Get list of uploads under $ParentFolder */
    /** mode 2 = upload_fk **/
    $sql = "SELECT upload_pk, upload_desc, upload_ts, upload_filename\n\tFROM foldercontents,upload\n  INNER JOIN uploadtree ON upload_fk = upload_pk AND upload.pfile_fk = uploadtree.pfile_fk AND parent IS NULL AND lft IS NOT NULL\n\tWHERE foldercontents.parent_fk = '{$ParentFolder}'\n\tAND foldercontents.foldercontents_mode = " . FolderDao::MODE_UPLOAD . "\n\tAND foldercontents.child_id = upload.upload_pk\n\tORDER BY upload_filename,upload_pk;";
    $result = pg_query($PG_CONN, $sql);
    DBCheckResult($result, $sql, __FILE__, __LINE__);
    while ($R = pg_fetch_assoc($result)) {
        if (empty($R['upload_pk'])) {
            continue;
        }
        if ($perm == Auth::PERM_READ && !$uploadDao->isAccessible($R['upload_pk'], $groupId)) {
            continue;
        }
        if ($perm == Auth::PERM_WRITE && !$uploadDao->isEditable($R['upload_pk'], $groupId)) {
            continue;
        }
        $New['upload_pk'] = $R['upload_pk'];
        $New['upload_desc'] = $R['upload_desc'];
        $New['upload_ts'] = substr($R['upload_ts'], 0, 19);
        $New['name'] = $R['upload_filename'];
        array_push($List, $New);
    }
    pg_free_result($result);
    return $List;
}
 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} &nbsp;";
         $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 Generate the text for this plugin.
  */
 public function Output()
 {
     $V = "";
     /* If this is a POST, then process the request. */
     $uploadpk = GetParm('upload', PARM_INTEGER);
     if (!empty($uploadpk)) {
         $rc = $this->Delete($uploadpk);
         if (empty($rc)) {
             /* Need to refresh the screen */
             $URL = Traceback_uri() . "?mod=showjobs&upload={$uploadpk} ";
             $LinkText = _("View Jobs");
             $text = _("Deletion added to job queue.");
             $msg = "{$text} <a href={$URL}>{$LinkText}</a>";
             $V .= displayMessage($msg);
         } else {
             $text = _("Deletion Scheduling failed: ");
             $V .= DisplayMessage($text . $rc);
         }
     }
     /* Create the AJAX (Active HTTP) javascript for doing the reply
        and showing the response. */
     $V .= ActiveHTTPscript("Uploads");
     $V .= "<script language='javascript'>\n";
     $V .= "function Uploads_Reply()\n";
     $V .= "  {\n";
     $V .= "  if ((Uploads.readyState==4) && (Uploads.status==200))\n";
     $V .= "    {\n";
     /* Remove all options */
     //$V.= "    document.formy.upload.innerHTML = Uploads.responseText;\n";
     $V .= "    document.getElementById('uploaddiv').innerHTML = '<BR><select name=\\'upload\\' size=\\'10\\'>' + Uploads.responseText + '</select><P />';\n";
     /* Add new options */
     $V .= "    }\n";
     $V .= "  }\n";
     $V .= "</script>\n";
     /* Build HTML form */
     $V .= "<form name='formy' method='post'>\n";
     // no url = this url
     $text = _("Select the uploaded file to");
     $text1 = _("delete");
     $V .= "{$text} <em>{$text1}</em>\n";
     $V .= "<ul>\n";
     $text = _("This will");
     $text1 = _("delete");
     $text2 = _("the upload file!");
     $V .= "<li>{$text} <em>{$text1}</em> {$text2}\n";
     $text = _("Be very careful with your selection since you can delete a lot of work!\n");
     $V .= "<li>{$text}";
     $text = _("All analysis only associated with the deleted upload file will also be deleted.\n");
     $V .= "<li>{$text}";
     $text = _("THERE IS NO UNDELETE. When you select something to delete, it will be removed from the database and file repository.\n");
     $V .= "<li>{$text}";
     $V .= "</ul>\n";
     $text = _("Select the uploaded file to delete:");
     $V .= "<P>{$text}<P>\n";
     $V .= "<ol>\n";
     $text = _("Select the folder containing the file to delete: ");
     $V .= "<li>{$text}";
     $V .= "<select name='folder' ";
     $V .= "onLoad='Uploads_Get((\"" . Traceback_uri() . "?mod=upload_options&folder=-1' ";
     $V .= "onChange='Uploads_Get(\"" . Traceback_uri() . "?mod=upload_options&folder=\" + this.value)'>\n";
     $root_folder_pk = GetUserRootFolder();
     $V .= FolderListOption($root_folder_pk, 0);
     $V .= "</select><P />\n";
     $text = _("Select the uploaded project to delete:");
     $V .= "<li>{$text}";
     $V .= "<div id='uploaddiv'>\n";
     $V .= "<BR><select name='upload' size='10'>\n";
     $List = FolderListUploads_perm($root_folder_pk, Auth::PERM_WRITE);
     foreach ($List as $L) {
         $V .= "<option value='" . $L['upload_pk'] . "'>";
         $V .= htmlentities($L['name']);
         if (!empty($L['upload_desc'])) {
             $V .= " (" . htmlentities($L['upload_desc']) . ")";
         }
         if (!empty($L['upload_ts'])) {
             $V .= " :: " . substr($L['upload_ts'], 0, 19);
         }
         $V .= "</option>\n";
     }
     $V .= "</select><P />\n";
     $V .= "</div>\n";
     $V .= "</ol>\n";
     $text = _("Delete");
     $V .= "<input type='submit' value='{$text}!'>\n";
     $V .= "</form>\n";
     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 Generate the text for this plugin.
  */
 public function Output()
 {
     $V = "";
     /* If this is a POST, then process the request. */
     $ParentId = GetParm('parentid', PARM_INTEGER);
     $NewFolder = GetParm('newname', PARM_TEXT);
     $Desc = GetParm('description', PARM_TEXT);
     if (!empty($ParentId) && !empty($NewFolder)) {
         $rc = $this->create($ParentId, $NewFolder, $Desc);
         if ($rc == 1) {
             /* Need to refresh the screen */
             $text = _("Folder");
             $text1 = _("Created");
             $this->vars['message'] = "{$text} {$NewFolder} {$text1}";
         } else {
             if ($rc == 4) {
                 $text = _("Folder");
                 $text1 = _("Exists");
                 $this->vars['message'] = "{$text} {$NewFolder} {$text1}";
             }
         }
     }
     /* Display the form */
     $V .= "<form method='POST'>\n";
     // no url = this url
     $V .= "<ol>\n";
     $text = _("Select the parent folder:  \n");
     $V .= "<li>{$text}";
     $V .= "<select name='parentid'>\n";
     $root_folder_pk = GetUserRootFolder();
     $V .= FolderListOption($root_folder_pk, 0);
     $V .= "</select><P />\n";
     $text = _("Enter the new folder name:  \n");
     $V .= "<li>{$text}";
     $V .= "<INPUT type='text' name='newname' size=40 />\n<br>";
     $text = _("Enter a meaningful description:  \n");
     $V .= "<br><li>{$text}";
     $V .= "<INPUT type='text' name='description' size=80 />\n";
     $V .= "</ol>\n";
     $text = _("Create");
     $V .= "<input type='submit' value='{$text}!'>\n";
     $V .= "</form>\n";
     return $V;
 }
Exemple #7
0
    $agent_count = count($agent_list);
    for ($ac = 0; $ac < $agent_count; $ac++) {
        $Found = 0;
        foreach (explode(',', $options["A"]) as $Val) {
            if (!strcmp($Val, $agent_list[$ac]->URI)) {
                $Found = 1;
            }
        }
        if ($Found == 0) {
            $agent_list[$ac]->URI = NULL;
        }
    }
}
/* List available uploads */
if (array_key_exists("u", $options)) {
    $root_folder_pk = GetUserRootFolder();
    $FolderPath = NULL;
    $FolderList = FolderListUploadsRecurse($root_folder_pk, $FolderPath, Auth::PERM_WRITE);
    print "# The following uploads are available (upload id: name)\n";
    foreach ($FolderList as $Folder) {
        $Label = $Folder['name'] . " (" . $Folder['upload_desc'] . ')';
        print $Folder['upload_pk'] . ": {$Label}\n";
    }
    exit(0);
}
/* @var $uploadDao UploadDao */
$uploadDao = $GLOBALS['container']->get('dao.upload');
if (array_key_exists("U", $options)) {
    /* $options['U'] can either be 'ALL', a string (the upload_pk), 
         or an array of upload_pk's if multiple -U's were specified. 
       */
 /**
  * \brief This function returns the output html
  */
 function Output()
 {
     global $PG_CONN;
     global $Plugins;
     if ($this->State != PLUGIN_STATE_READY) {
         return 0;
     }
     $V = "";
     $folder_pk = GetParm("folder", PARM_INTEGER);
     $Upload = GetParm("upload", PARM_INTEGER);
     // upload_pk to browse
     $Item = GetParm("item", PARM_INTEGER);
     // uploadtree_pk to browse
     /* check permission if $Upload is given */
     if (!empty($Upload)) {
         $UploadPerm = GetUploadPerm($Upload);
         if ($UploadPerm < PERM_READ) {
             $text = _("Permission Denied");
             echo "<h2>{$text}<h2>";
             return;
         }
     }
     /* kludge for plugins not supplying a folder parameter.
      * Find what folder this upload is in.  Error if in multiple folders.
      */
     if (empty($folder_pk)) {
         if (empty($Upload)) {
             $folder_pk = GetUserRootFolder();
         } else {
             /* Make sure the upload record exists */
             $sql = "select upload_pk from upload where upload_pk={$Upload}";
             $result = pg_query($PG_CONN, $sql);
             DBCheckResult($result, $sql, __FILE__, __LINE__);
             if (pg_num_rows($result) < 1) {
                 echo "This upload no longer exists on this system.";
                 return;
             }
             $sql = "select parent_fk from foldercontents where child_id={$Upload} and foldercontents_mode=2";
             $result = pg_query($PG_CONN, $sql);
             DBCheckResult($result, $sql, __FILE__, __LINE__);
             if (pg_num_rows($result) > 1) {
                 Fatal("Upload {$Upload} found in multiple folders.", __FILE__, __LINE__);
             }
             if (pg_num_rows($result) < 1) {
                 Fatal("Upload {$Upload} missing from foldercontents.", __FILE__, __LINE__);
             }
             $row = pg_fetch_assoc($result);
             $folder_pk = $row['parent_fk'];
             pg_free_result($result);
         }
     }
     $Folder = $folder_pk;
     $Show = 'detail';
     // always use detail
     switch ($this->OutputType) {
         case "XML":
             break;
         case "HTML":
             /************************/
             /* Show the folder path */
             /************************/
             $uploadtree_tablename = "";
             if (!empty($Item)) {
                 /* Make sure the item is not a file */
                 $sql = "SELECT ufile_mode, upload_fk FROM uploadtree WHERE uploadtree_pk = '{$Item}';";
                 $result = pg_query($PG_CONN, $sql);
                 DBCheckResult($result, $sql, __FILE__, __LINE__);
                 $row = pg_fetch_assoc($result);
                 pg_free_result($result);
                 $Upload = $row['upload_fk'];
                 $UploadPerm = GetUploadPerm($Upload);
                 if ($UploadPerm < PERM_READ) {
                     $text = _("Permission Denied");
                     echo "<h2>{$text}<h2>";
                     return;
                 }
                 if (!Iscontainer($row['ufile_mode'])) {
                     /* Not a container! */
                     $View =& $Plugins[plugin_find_id("view")];
                     if (!empty($View)) {
                         return $View->ShowView(NULL, "browse");
                     }
                 }
                 $V .= "<font class='text'>\n";
                 $uploadtree_tablename = GetUploadtreeTableName($row['upload_fk']);
                 $V .= Dir2Browse($this->Name, $Item, NULL, 1, "Browse", -1, '', '', $uploadtree_tablename) . "\n";
             } else {
                 if (!empty($Upload)) {
                     $V .= "<font class='text'>\n";
                     $uploadtree_tablename = GetUploadtreeTableName($Upload);
                     $V .= Dir2BrowseUpload($this->Name, $Upload, NULL, 1, "Browse", $uploadtree_tablename) . "\n";
                 } else {
                     $V .= "<font class='text'>\n";
                 }
             }
             /******************************/
             /* Get the folder description */
             /******************************/
             if (!empty($Upload)) {
                 if (empty($Item)) {
                     $sql = "select uploadtree_pk from uploadtree\n                where parent is NULL and upload_fk={$Upload} ";
                     $result = pg_query($PG_CONN, $sql);
                     DBCheckResult($result, $sql, __FILE__, __LINE__);
                     if (pg_num_rows($result)) {
                         $row = pg_fetch_assoc($result);
                         $Item = $row['uploadtree_pk'];
                     } else {
                         $text = _("Missing upload tree parent for upload");
                         $V .= "<hr><h2>{$text} {$Upload}</h2><hr>";
                         break;
                     }
                     pg_free_result($result);
                 }
                 $V .= $this->ShowItem($Upload, $Item, $Show, $Folder, $uploadtree_tablename);
             } else {
                 $V .= $this->ShowFolder($Folder, $Show);
             }
             $V .= "</font>\n";
             break;
         case "Text":
             break;
         default:
             break;
     }
     if (!$this->OutputToStdout) {
         return $V;
     }
     print "{$V}";
     return;
 }
/**
 * \brief Returns an array of uploads in a folder.
 *  Only uploads for which the user has permission >= $perm are returned
 *  This does NOT recurse.
 *  The returned array is sorted by ufile_name and upload_pk.
 * \param $ParentFolder Optional folder_pk, default is users root folder.
 * \param $perm minimum permission
 * \return array{upload_pk, upload_desc, upload_ts, ufile_name}
 *  for all uploads in a given folder.
 *
 */
function FolderListUploads_perm($ParentFolder = -1, $perm)
{
    global $PG_CONN;
    if (empty($PG_CONN)) {
        return;
    }
    if (empty($ParentFolder)) {
        return;
    }
    if ($ParentFolder == "-1") {
        $ParentFolder = GetUserRootFolder();
    }
    $List = array();
    /* Get list of uploads under $ParentFolder */
    /** mode 2 = upload_fk **/
    $sql = "SELECT upload_pk, upload_desc, upload_ts, upload_filename\n\tFROM foldercontents,upload\n  INNER JOIN uploadtree ON upload_fk = upload_pk AND upload.pfile_fk = uploadtree.pfile_fk AND parent IS NULL AND lft IS NOT NULL\n\tWHERE foldercontents.parent_fk = '{$ParentFolder}'\n\tAND foldercontents.foldercontents_mode = 2\n\tAND foldercontents.child_id = upload.upload_pk\n\tORDER BY upload_filename,upload_pk;";
    $result = pg_query($PG_CONN, $sql);
    DBCheckResult($result, $sql, __FILE__, __LINE__);
    while ($R = pg_fetch_assoc($result)) {
        if (empty($R['upload_pk'])) {
            continue;
        }
        // Filter out uploads where the user doesn't have sufficient permission
        if (GetUploadPerm($R['upload_pk']) < $perm) {
            continue;
        }
        $New['upload_pk'] = $R['upload_pk'];
        $New['upload_desc'] = $R['upload_desc'];
        $New['upload_ts'] = substr($R['upload_ts'], 0, 19);
        $New['name'] = $R['upload_filename'];
        array_push($List, $New);
    }
    pg_free_result($result);
    return $List;
}
 /**
  * \brief Generate the text for this plugin.
  */
 function Output()
 {
     global $Plugins;
     global $PG_CONN;
     global $PERM_NAMES;
     if ($this->State != PLUGIN_STATE_READY) {
         return;
     }
     $V = "";
     switch ($this->OutputType) {
         case "XML":
             break;
         case "HTML":
             $text = _("Move upload to different folder.");
             $V .= "<H2>{$text}</H1>\n";
             /* If this is a POST, then process the request. */
             $OldFolderId = GetParm('oldfolderid', PARM_INTEGER);
             $UploadId = GetParm('uploadid', PARM_INTEGER);
             $TargetFolderId = GetParm('targetfolderid', PARM_INTEGER);
             if (!empty($OldFolderId) && !empty($TargetFolderId)) {
                 /* check upload permission */
                 $UploadPerm = GetUploadPerm($UploadId);
                 if ($UploadPerm < PERM_WRITE) {
                     $text = _("Permission Denied");
                     echo "<h2>{$text}<h2>";
                     return;
                 }
                 $rc = $this->Move($UploadId, $TargetFolderId, $OldFolderId);
                 if ($rc == 1) {
                     /* Need to refresh the screen */
                     $sql = "SELECT * FROM folder where folder_pk = '{$TargetFolderId}';";
                     $result = pg_query($PG_CONN, $sql);
                     DBCheckResult($result, $sql, __FILE__, __LINE__);
                     $NRow = pg_fetch_assoc($result);
                     pg_free_result($result);
                     $sql = "SELECT pfile_fk FROM upload WHERE upload_pk='{$UploadId}';";
                     $result = pg_query($PG_CONN, $sql);
                     DBCheckResult($result, $sql, __FILE__, __LINE__);
                     $row = pg_fetch_assoc($result);
                     pg_free_result($result);
                     $pfileNum = $row['pfile_fk'];
                     $sql = "SELECT ufile_name FROM uploadtree WHERE " . "upload_fk='{$UploadId}' and pfile_fk={$pfileNum};";
                     $result = pg_query($PG_CONN, $sql);
                     DBCheckResult($result, $sql, __FILE__, __LINE__);
                     $row = pg_fetch_assoc($result);
                     pg_free_result($result);
                     $base = basename($row['ufile_name']);
                     $sql = "SELECT * FROM folder where folder_pk = '{$OldFolderId}';";
                     $result = pg_query($PG_CONN, $sql);
                     DBCheckResult($result, $sql, __FILE__, __LINE__);
                     $ORow = pg_fetch_assoc($result);
                     pg_free_result($result);
                     $text = _("Moved");
                     $text1 = _("from folder");
                     $text2 = _("to folder");
                     $success = "{$text} {$base} {$text1} {$ORow['folder_name']} {$text2} {$NRow['folder_name']}";
                     $V .= displayMessage($success);
                 }
             }
             /* Create the AJAX (Active HTTP) javascript for doing the reply
                and showing the response. */
             $V .= ActiveHTTPscript("Uploads");
             $V .= "<script language='javascript'>\n";
             $V .= "function Uploads_Reply()\n";
             $V .= "  {\n";
             $V .= "  if ((Uploads.readyState==4) && (Uploads.status==200))\n";
             $V .= "    {\n";
             /* Remove all options */
             $V .= "    document.getElementById('uploaddiv').innerHTML = '<select name=\\'uploadid\\'>' + Uploads.responseText + '</select><P />';\n";
             /* Add new options */
             $V .= "    }\n";
             $V .= "  }\n";
             $V .= "</script>\n";
             /* Build the  HTML form */
             $V .= "<form name='formy' method='post'>\n";
             // no url = this url
             /* Display the form */
             $V .= "<form method='post'>\n";
             // no url = this url
             $V .= "<ol>\n";
             $text = _("Select the folder containing the upload you wish to move:  \n");
             $V .= "<li>{$text}";
             $V .= "<select name='oldfolderid'\n";
             $V .= "onLoad='Uploads_Get((\"" . Traceback_uri() . "?mod=upload_options&folder=-1' ";
             $V .= "onChange='Uploads_Get(\"" . Traceback_uri() . "?mod=upload_options&folder=\" + this.value)'>\n";
             $root_folder_pk = GetUserRootFolder();
             $V .= FolderListOption($root_folder_pk, 0);
             $V .= "</select><P />\n";
             $text = _("Select the upload you wish to move:  \n");
             $V .= "<li>{$text}";
             $V .= "<div id='uploaddiv'>\n";
             $V .= "<select name='uploadid'>\n";
             $List = FolderListUploads_perm($root_folder_pk, PERM_WRITE);
             foreach ($List as $L) {
                 $V .= "<option value='" . $L['upload_pk'] . "'>";
                 $V .= htmlentities($L['name']);
                 if (!empty($L['upload_desc'])) {
                     $V .= " (" . htmlentities($L['upload_desc']) . ")";
                 }
                 if (!empty($L['upload_ts'])) {
                     $V .= " :: " . substr($L['upload_ts'], 0, 19);
                 }
                 $V .= "</option>\n";
             }
             $V .= "</select><P />\n";
             $V .= "</div>\n";
             $text = _("Select the destination folder:  \n");
             $V .= "<li>{$text}";
             $V .= "<select name='targetfolderid'>\n";
             $V .= FolderListOption($root_folder_pk, 0);
             $V .= "</select><P />\n";
             $V .= "</ol>\n";
             $text = "Move";
             $V .= "<input type='submit' value='{$text}!'>\n";
             $V .= "</form>\n";
             break;
         case "Text":
             break;
         default:
             break;
     }
     if (!$this->OutputToStdout) {
         return $V;
     }
     print "{$V}";
     return;
 }
 /**
  * \brief Generate the text for this plugin.
  */
 function Output()
 {
     if ($this->State != PLUGIN_STATE_READY) {
         return;
     }
     $V = "";
     $R = "";
     switch ($this->OutputType) {
         case "XML":
             break;
         case "HTML":
             /* If this is a POST, then process the request. */
             $ParentId = GetParm('parentid', PARM_INTEGER);
             $NewFolder = GetParm('newname', PARM_TEXT);
             $Desc = GetParm('description', PARM_TEXT);
             if (!empty($ParentId) && !empty($NewFolder)) {
                 $rc = $this->Create($ParentId, $NewFolder, $Desc);
                 $Uri = Traceback_uri() . "?mod=refresh&remod=" . $this->Name;
                 if ($rc == 1) {
                     /* Need to refresh the screen */
                     $text = _("Folder");
                     $text1 = _("Created");
                     $R .= displayMessage("{$text} {$NewFolder} {$text1}");
                 } else {
                     if ($rc == 4) {
                         $text = _("Folder");
                         $text1 = _("Exists");
                         $R .= displayMessage("{$text} {$NewFolder} {$text1}");
                     }
                 }
             }
             /* Display the form */
             $V .= "{$R}\n";
             $V .= "<form method='POST'>\n";
             // no url = this url
             $V .= "<ol>\n";
             $text = _("Select the parent folder:  \n");
             $V .= "<li>{$text}";
             $V .= "<select name='parentid'>\n";
             $root_folder_pk = GetUserRootFolder();
             $V .= FolderListOption($root_folder_pk, 0);
             $V .= "</select><P />\n";
             $text = _("Enter the new folder name:  \n");
             $V .= "<li>{$text}";
             $V .= "<INPUT type='text' name='newname' size=40 />\n<br>";
             $text = _("Enter a meaningful description:  \n");
             $V .= "<br><li>{$text}";
             $V .= "<INPUT type='text' name='description' size=80 />\n";
             $V .= "</ol>\n";
             $text = _("Create");
             $V .= "<input type='submit' value='{$text}!'>\n";
             $V .= "</form>\n";
             break;
         case "Text":
             break;
         default:
             break;
     }
     if (!$this->OutputToStdout) {
         return $V;
     }
     print "{$V}";
     return;
 }