diff --git a/src/www/ui/showjobs.php b/src/www/ui/showjobs.php index f39bd63d..5e900135 100644 --- a/src/www/ui/showjobs.php +++ b/src/www/ui/showjobs.php @@ -1,235 +1,231 @@ Name = "showjobs"; $this->Title = TITLE_showjobs; $this->MenuOrder = 5; $this->Dependency = array("browse"); $this->DBaccess = PLUGIN_DB_WRITE; global $container; $this->showJobsDao = $container->get('dao.show_jobs'); $this->uploadDao = $container->get('dao.upload'); parent::__construct(); } function RegisterMenus() { menu_insert("Main::Jobs::My Recent Jobs",$this->MenuOrder -1,$this->Name, $this->MenuTarget); if ($_SESSION[Auth::USER_LEVEL] != PLUGIN_DB_ADMIN) return; if (GetParm("mod", PARM_STRING) == $this->Name){ /* Set micro menu to select either all users or this user */ $allusers = GetParm("allusers",PARM_INTEGER); if ($allusers == 0){ $text = _("Show uploads from all users"); $URI = $this->Name . Traceback_parm_keep(array( "page" )) . "&allusers=1"; }else{ $text = _("Show only your own uploads"); $URI = $this->Name . Traceback_parm_keep(array( "page")) . "&allusers=0"; } menu_insert("showjobs::$text", 1, $URI, $text); } } // RegisterMenus() /** * @brief Returns geeky scan details about the jobqueue item * @param $job_pk * @return Return job and jobqueue record data in an html table. **/ function showJobDB($job_pk) { global $container; /** @var DbManager */ $dbManager = $container->get('db.manager'); $statementName = __METHOD__."ShowJobDBforjob"; $dbManager->prepare($statementName, - "SELECT *, jq_endtime-jq_starttime as elapsed FROM jobqueue LEFT JOIN job ON job.job_pk = jobqueue.jq_job_fk WHERE jobqueue.jq_pk = $1"); + "SELECT *, jq_endtime-jq_starttime as elapsed FROM jobqueue LEFT JOIN job ON job.job_pk = jobqueue.jq_job_fk WHERE jobqueue.jq_pk = $1"); $result = $dbManager->execute($statementName, array($job_pk)); $row = $dbManager->fetchArray($result); $dbManager->freeResult($result); if (!empty($row["job_upload_fk"])){ /* get the upload filename */ $statementName = __METHOD__."upload_filenameforShowJobDB"; - $dbManager->prepare($statementName, - "select upload_filename, upload_desc from upload where upload_pk =$1"); + $dbManager->prepare($statementName, "select upload_filename from upload where upload_pk =$1"); $uploadresult = $dbManager->execute($statementName, array($row['job_upload_fk'])); $uploadRow = $dbManager->fetchArray($uploadresult); if (empty($uploadRow)){ /* upload has been deleted so try to get the job name from the original upload job record */ $jobName = $this->showJobsDao->getJobName($row["job_upload_fk"]); $upload_filename = "Deleted " . $jobName; - $upload_desc = ''; }else{ $upload_filename = $uploadRow['upload_filename']; - $upload_desc = $uploadRow['upload_desc']; } $dbManager->freeResult($uploadresult); if (empty($row['jq_pk'])){ return _("Job history record is no longer available"); } $uploadtree_tablename = $this->uploadDao->getUploadtreeTableName($row['job_upload_fk']); /* Find the uploadtree_pk for this upload so that it can be used in the browse link */ $statementName = __METHOD__."uploadtreeRec"; $uploadtreeRec = $dbManager->getSingleRow( - "select * from $uploadtree_tablename where parent is NULL and upload_fk=$1", - array($row['job_upload_fk']), - $statementName - ); + "select * from $uploadtree_tablename where parent is NULL and upload_fk=$1", + array($row['job_upload_fk']), + $statementName); $uploadtree_pk = $uploadtreeRec['uploadtree_pk']; } /* upload file name link to browse */ if (!empty($row['job_upload_fk'])){ - $uploadTreeName = ""; $uploadTreeName = "" . $upload_filename . ""; return $uploadTreeName; } } // showJobDB() public function Output() { $page = ""; $uploadPk = GetParm('upload',PARM_INTEGER); if (empty($uploadPk)){ $uploadPk = -1; } elseif($uploadPk>0){ if (!$this->uploadDao->isEditable($uploadPk, Auth::getGroupId())){ $text = _("Permission Denied"); return "

$text

"; } } $this->vars['uploadId']= $uploadPk; // micro menus menu_to_1html(menu_find($this->Name, $MenuDepth),0); /* Process any actions */ if ($_SESSION[Auth::USER_LEVEL] >= PLUGIN_DB_WRITE){ $jq_pk = GetParm("jobid",PARM_INTEGER); $action = GetParm("action",PARM_STRING); $uploadPk = GetParm("upload",PARM_INTEGER); if (!empty($uploadPk) && !$this->uploadDao->isEditable($uploadPk, Auth::getGroupId())){ $text = _("Permission Denied"); return "

$text

"; } $page = GetParm('page',PARM_INTEGER) ?: 0; $thisURL = Traceback_uri() . "?mod=" . $this->Name . "&upload=$uploadPk"; switch($action) { case 'pause': if (empty($jq_pk)) break; $command = "pause $jq_pk"; $rv = fo_communicate_with_scheduler($command, $response_from_scheduler, $error_info); if ($rv == false) $this->vars['errorInfo'] = _("Unable to pause job.") . " " . $response_from_scheduler . $error_info; echo ""; break; case 'restart': if (empty($jq_pk)) break; $command = "restart $jq_pk"; $rv = fo_communicate_with_scheduler($command, $response_from_scheduler, $error_info); if ($rv == false) $this->vars['errorInfo'] = _("Unable to restart job.") . " " . $response_from_scheduler . $error_info; echo ""; break; case 'cancel': if (empty($jq_pk)) break; $Msg = "\"" . _("Killed by") . " " . $_SESSION[Auth::USER_NAME] . "\""; $command = "kill $jq_pk $Msg"; $rv = fo_communicate_with_scheduler($command, $response_from_scheduler, $error_info); if ($rv == false) $this->vars['errorInfo'] = _("Unable to cancel job.") . $response_from_scheduler . $error_info; echo ""; break; + default: break; } } $job = GetParm('job',PARM_INTEGER); if (!empty($job)){ $this->vars['jobId'] = $job; $this->vars['uploadName'] = $this->showJobDB($job); }else{ $allusersval=GetParm("allusers",PARM_INTEGER); if(!$allusersval) $allusersval = 0; $this->vars['allusersval'] = $allusersval; if(!$page) $page=0; $this->vars['page'] = $page; $this->vars['clockTime'] = $this->getTimeToRefresh(); $this->vars['allusersdiv'] = menu_to_1html(menu_find($this->Name, $MenuDepth),0); $this->vars['injectedFoot'] = $_GET['injectedFoot']; $this->vars['message'] = $_GET['injectedMessage']; } } /** * @brief getTimeToRefresh() get the refresh time from DB. * @Returns time in seconds to refresh the jobs. **/ public function getTimeToRefresh() { global $SysConf; return $SysConf['SYSCONFIG']['ShowJobsAutoRefresh']; } /* getTimeToRefresh() */ public function getTemplateName() { $job = GetParm('job', PARM_INTEGER); if (empty($job)) { return "ui-showjobs.html.twig"; } else { return "ui-job-show.html.twig"; } } } $NewPlugin = new showjobs; $NewPlugin->Initialize();