示例#1
0
 /**
  * \brief Delete
  * Creates a job to detele the folder
  *
  * \param $folderpk - the folder_pk to remove
  * \return NULL on success, string on failure.
  */
 function Delete($folderpk, $userId)
 {
     /* Can't remove top folder */
     if ($folderpk == FolderGetTop()) {
         $text = _("Can Not Delete Root Folder");
         return $text;
     }
     /* Get the folder's name */
     $FolderName = FolderGetName($folderpk);
     /* Prepare the job: job "Delete" */
     $groupId = Auth::getGroupId();
     $jobpk = JobAddJob($userId, $groupId, "Delete Folder: {$FolderName}");
     if (empty($jobpk) || $jobpk < 0) {
         $text = _("Failed to create job record");
         return $text;
     }
     /* Add job: job "Delete" has jobqueue item "delagent" */
     $jqargs = "DELETE FOLDER {$folderpk}";
     $jobqueuepk = JobQueueAdd($jobpk, "delagent", $jqargs, NULL, NULL);
     if (empty($jobqueuepk)) {
         $text = _("Failed to place delete in job queue");
         return $text;
     }
     /* Tell the scheduler to check the queue. */
     $success = fo_communicate_with_scheduler("database", $output, $error_msg);
     if (!$success) {
         return $error_msg . "\n" . $output;
     }
     return NULL;
 }
 /**
  * \brief Delete
  * Creates a job to detele the folder
  *
  * \param $folderpk - the folder_pk to remove
  * \return NULL on success, string on failure.
  */
 function Delete($folderpk, $Depends = NULL)
 {
     global $SysConf;
     /* Can't remove top folder */
     if ($folderpk == FolderGetTop()) {
         $text = _("Can Not Delete Root Folder");
         return $text;
     }
     /* Get the folder's name */
     $FolderName = FolderGetName($folderpk);
     /* Prepare the job: job "Delete" */
     $user_pk = $SysConf['auth']['UserId'];
     $jobpk = JobAddJob($user_pk, "Delete Folder: {$FolderName}");
     if (empty($jobpk) || $jobpk < 0) {
         $text = _("Failed to create job record");
         return $text;
     }
     /* Add job: job "Delete" has jobqueue item "delagent" */
     $jqargs = "DELETE FOLDER {$folderpk}";
     $jobqueuepk = JobQueueAdd($jobpk, "delagent", $jqargs, NULL, NULL);
     if (empty($jobqueuepk)) {
         $text = _("Failed to place delete in job queue");
         return $text;
     }
     return NULL;
 }
示例#3
0
/**
 * \brief Given a folder_pk, return the full path to this folder.
 *  This is recursive!
 *  NOTE: If there is a recursive loop in the folder table, then
 *  this will loop INFINITELY.
 *
 * \param $FolderPk
 * \param $Top Optional, default is user's top folder. folder_pk of top of desired path.
 *
 * \return string full path of this folder
 */
function FolderGetName($FolderPk, $Top = -1)
{
    global $PG_CONN;
    if ($Top == -1) {
        $Top = FolderGetTop();
    }
    $sql = "SELECT folder_name,foldercontents.parent_fk FROM folder\n\tLEFT JOIN foldercontents ON foldercontents_mode = " . FolderDao::MODE_FOLDER . "\n\tAND child_id = '{$FolderPk}'\n\tWHERE folder_pk = '{$FolderPk}'\n\tLIMIT 1;";
    $result = pg_query($PG_CONN, $sql);
    DBCheckResult($result, $sql, __FILE__, __LINE__);
    $row = pg_fetch_assoc($result);
    $Parent = $row['parent_fk'];
    $Name = $row['folder_name'];
    if (!empty($Parent) && $FolderPk != $Top) {
        $Name = FolderGetName($Parent, $Top) . "/" . $Name;
    }
    return $Name;
}
 public function Output()
 {
     $V = "";
     $upload_id = GetParm('upload', PARM_INTEGER);
     $manage = GetParm('manage', PARM_TEXT);
     /* If this is a POST, then process the request. */
     $Folder = GetParm('folder', PARM_INTEGER);
     if (empty($Folder)) {
         $Folder = FolderGetTop();
     }
     $rc = $this->ManageTag($Folder, $upload_id, $manage);
     if (1 == $rc) {
         $text1 = _("all uploads in folder");
         $text2 = _("in folder");
         $folder_path = FolderGetName($Folder);
         $upload_name = GetUploadName($upload_id);
         if (empty($upload_id)) {
             $text = $text1;
         } else {
             $text = "'{$upload_name}' {$text2}";
         }
         $Msg = "{$manage} {$text} '{$folder_path}'";
         $this->vars['message'] = $Msg;
         // reset form fields
     }
     /**
      * Create the AJAX (Active HTTP) javascript for doing the reply
      * and showing the response.
      * get upload list under one folder
      */
     $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";
     $V .= "    document.getElementById('tagdiv').innerHTML = '<select size=\\'10\\' name=\\'upload\\' onChange=\\'Tagging_Get(\"" . Traceback_uri() . "?mod=upload_tagging&upload=\" + this.value)\\'>' + Uploads.responseText+ '</select><P/>';\n";
     $V .= "    document.getElementById('manage_tag').style.display= 'none';\n";
     $V .= "    document.getElementById('manage_tag_all').style.display= 'block';\n";
     $V .= "    }\n";
     $V .= "  }\n";
     $V .= "</script>\n";
     /** select one upload */
     $V .= ActiveHTTPscript("Tagging");
     $V .= "<script language='javascript'>\n";
     $V .= "function Tagging_Reply()\n";
     $V .= "  {\n";
     $V .= "  if ((Tagging.readyState==4) && (Tagging.status==200))\n";
     $V .= "    {\n";
     $V .= "    document.getElementById('manage_tag_all').style.display= 'none';\n";
     $V .= "    document.getElementById('manage_tag').style.display= 'block';\n";
     $V .= "    document.getElementById('manage_tag').innerHTML = Tagging.responseText;\n";
     $V .= "    }\n";
     $V .= "  }\n";
     $V .= "</script>\n";
     $V .= "<form name='formy' method='post'>\n";
     // no url = this url
     $V .= _("Displaying tags while browsing can be slow for large uploads.  This interface allows you to select an upload to disable (or enable) the tag display.  By default the tag display is enabled.<p>\n");
     $V .= "<ol>\n";
     $text = _("Select the folder containing the upload you wish to enable/disable:");
     $V .= "<li>{$text}<br>\n";
     $V .= "<select name='folder'\n";
     $V .= "onLoad='Uploads_Get((\"" . Traceback_uri() . "?mod=upload_options&folder={$Folder}' ";
     $V .= "onChange='Uploads_Get(\"" . Traceback_uri() . "?mod=upload_options&folder=\" + this.value)'>\n";
     $V .= FolderListOption(-1, 0, 1, $Folder);
     $V .= "</select><P />\n";
     $text = _("Select the upload to  enable/disable:");
     $V .= "<li>{$text}<br>";
     $V .= "<div id='tagdiv'>\n";
     $V .= "<select size='10' name='upload' onChange='Tagging_Get(\"" . Traceback_uri() . "?mod=upload_tagging&upload=\" + this.value)'>\n";
     $List = FolderListUploads_perm($Folder, 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']) . ")";
         }
         $V .= "</option>\n";
     }
     $V .= "</select><P />\n";
     $V .= "</div>\n";
     $V .= "<div id='manage_tag_all'>";
     $text = _("Disable");
     $V .= "<input type='submit' name='manage'  value='{$text}'>\n";
     $text = _("Enable");
     $V .= "<input type='submit' name='manage' value='{$text}'>\n";
     $V .= "</div>";
     $V .= "<div id='manage_tag'>";
     $V .= "</div>";
     return $V;
 }
 /**
  * \brief Process the upload request.  Call the upload by the Name passed in or by
  * the filename if no name is supplied.
  *
  * \param $FolderPk - folder fk to load into
  * \param $SourceFiles - files to upload, file, tar, directory, etc...
  * \param $GroupNames - flag for indicating if group names were requested.
  *        passed on as -A option to cp2foss.
  * \param $Desc - optional description for the upload
  * \param $Name - optional Name for the upload
  * \param $public_perm public permission on the upload
  *
  * \return NULL on success, string on failure.
  */
 function Upload($FolderPk, $SourceFiles, $GroupNames, $Desc, $Name, $HostName, $public_perm)
 {
     global $Plugins;
     global $SysConf;
     $FolderPath = FolderGetName($FolderPk);
     $SourceFiles = trim($SourceFiles);
     // $FolderPath = str_replace('\\','\\\\',$FolderPath);
     // $FolderPath = str_replace('"','\"',$FolderPath);
     $FolderPath = str_replace('`', '\\`', $FolderPath);
     $FolderPath = str_replace('$', '\\$', $FolderPath);
     if (!empty($Desc)) {
         // $Desc = str_replace('\\','\\\\',$Desc);
         // $Desc = str_replace('"','\"',$Desc);
         $Desc = str_replace('`', '\\`', $Desc);
         $Desc = str_replace('$', '\\$', $Desc);
     }
     if (!empty($Name)) {
         // $Name = str_replace('\\','\\\\',$Name);
         // $Name = str_replace('"','\"',$Name);
         $Name = str_replace('`', '\\`', $Name);
         $Name = str_replace('$', '\\$', $Name);
     } else {
         $Name = $SourceFiles;
     }
     // $SourceFiles = str_replace('\\','\\\\',$SourceFiles);
     // $SourceFiles = str_replace('"','\"',$SourceFiles);
     $SourceFiles = str_replace('`', '\\`', $SourceFiles);
     $SourceFiles = str_replace('$', '\\$', $SourceFiles);
     $SourceFiles = str_replace('|', '\\|', $SourceFiles);
     $SourceFiles = str_replace(' ', '\\ ', $SourceFiles);
     $SourceFiles = str_replace("\t", "\\\t", $SourceFiles);
     /* Add the job to the queue */
     // create the job
     $ShortName = basename($Name);
     if (empty($ShortName)) {
         $ShortName = $Name;
     }
     $wildcardpath = strstr($SourceFiles, '*');
     /** check if the file/directory is existed (the path does not include wildcards) */
     if (empty($wildcardpath) && !$this->remote_file_exists($SourceFiles, $HostName)) {
         $text = _("'{$SourceFiles}' does not exist.\n");
         return $text;
     }
     /** check if has the read permission */
     if (empty($wildcardpath) && !$this->remote_file_permission($SourceFiles, $HostName, "r")) {
         $text = _("Have no READ permission on '{$SourceFiles}'.\n");
         return $text;
     }
     // Create an upload record.
     $jobq = NULL;
     $Mode = 1 << 3;
     // code for "it came from web upload"
     $user_pk = $SysConf['auth']['UserId'];
     $uploadpk = JobAddUpload($user_pk, $ShortName, $SourceFiles, $Desc, $Mode, $FolderPk, $public_perm);
     /* Prepare the job: job "wget" */
     $jobpk = JobAddJob($user_pk, "wget", $uploadpk);
     if (empty($jobpk) || $jobpk < 0) {
         $text = _("Failed to insert job record");
         return $text;
     }
     $jq_args = "{$uploadpk} - {$SourceFiles}";
     $jobqueuepk = JobQueueAdd($jobpk, "wget_agent", $jq_args, "no", NULL, $HostName);
     if (empty($jobqueuepk)) {
         $text = _("Failed to insert task 'wget' into job queue");
         return $text;
     }
     /* schedule agents */
     $unpackplugin =& $Plugins[plugin_find_id("agent_unpack")];
     $ununpack_jq_pk = $unpackplugin->AgentAdd($jobpk, $uploadpk, $ErrorMsg, array("wget_agent"));
     if ($ununpack_jq_pk < 0) {
         return $ErrorMsg;
     }
     $adj2nestplugin =& $Plugins[plugin_find_id("agent_adj2nest")];
     $adj2nest_jq_pk = $adj2nestplugin->AgentAdd($jobpk, $uploadpk, $ErrorMsg, array());
     if ($adj2nest_jq_pk < 0) {
         return $ErrorMsg;
     }
     AgentCheckBoxDo($jobpk, $uploadpk);
     $msg = "";
     /** check if the scheudler is running */
     $status = GetRunnableJobList();
     if (empty($status)) {
         $msg .= _("Is the scheduler running? ");
     }
     $Url = Traceback_uri() . "?mod=showjobs&upload={$uploadpk}";
     $msg .= "The file {$SourceFiles} has been uploaded. ";
     $keep = "It is <a href='{$Url}'>upload #" . $uploadpk . "</a>.\n";
     print displayMessage($msg, $keep);
     return NULL;
 }