28 const NAME =
'ui_reportImport';
35 function __construct()
37 parent::__construct(self::NAME, array(
38 self::TITLE => _(
"Report Import"),
40 self::REQUIRES_LOGIN => TRUE
42 $this->uploadDao = $GLOBALS[
'container']->get(
'dao.upload');
43 $this->folderDao = $GLOBALS[
'container']->get(
'dao.folder');
48 $text = _(
"Import Report");
49 menu_insert(
"Browse-Pfile::Import Report", 0, self::NAME, $text);
50 menu_insert(
"Main::Upload::Import Report", 0, self::NAME, $text);
53 protected function handle(Request $request)
55 $uploadId = intval(
GetArrayVal(
"uploadselect", $_POST));
56 if (empty($uploadId) ||
57 !array_key_exists(
'report',$_FILES) ||
58 sizeof($_FILES[
'report'][
'name']) != 1)
60 return $this->showUiToChoose();
64 $jobMetaData = $this->runImport($uploadId, $_FILES[
'report'], $request);
66 $showJobsPlugin->OutputOpen();
67 return $showJobsPlugin->getResponse();
71 protected function showUiToChoose()
74 $groupId = Auth::getGroupId();
75 $vars[
'userIsAdmin'] = Auth::isAdmin();
77 $rootFolder = $this->folderDao->getRootFolder(Auth::getUserId());
79 if (empty($folder_pk)) {
80 $folder_pk = $rootFolder->getId();
82 $vars[
'folderId'] = $folder_pk;
84 $folderUploads = $this->folderDao->getFolderUploads($folder_pk, $groupId);
85 $uploadsById = array();
87 foreach ($folderUploads as $uploadProgress)
89 if ($uploadProgress->getGroupId() != $groupId) {
92 if (!$this->uploadDao->isEditable($uploadProgress->getId(), $groupId)) {
95 $display = $uploadProgress->getFilename() . _(
" from ") .
Convert2BrowserTime(date(
"Y-m-d H:i:s",$uploadProgress->getTimestamp()));
96 $uploadsById[$uploadProgress->getId()] = $display;
98 $vars[
'uploadList'] = $uploadsById;
101 if (empty($uploadId))
104 $uploadId = key($uploadsById);
106 $vars[
'uploadId'] = $uploadId;
108 $folderStructure = $this->folderDao->getFolderStructure($rootFolder->getId());
109 $vars[
'folderStructure'] = $folderStructure;
110 $vars[
'baseUri'] = $Uri =
Traceback_uri() .
"?mod=" . self::NAME .
"&folder=";
112 return $this->
render(
'ReportImportPlugin.html.twig', $this->mergeWithDefault($vars));
115 protected function runImport($uploadId, $report, $request)
117 $reportImportAgent =
plugin_find(
'agent_reportImport');
119 $jqCmdArgs = $reportImportAgent->addReport($report);
120 $jqCmdArgs .= $reportImportAgent->setAdditionalJqCmdArgs($request);
122 $userId = Auth::getUserId();
123 $groupId = Auth::getGroupId();
124 $dbManager = $this->
getObject(
'db.manager');
125 $sql =
'SELECT jq_pk,job_pk FROM jobqueue, job ' 126 .
'WHERE jq_job_fk=job_pk AND jq_type=$1 AND job_group_fk=$4 AND job_user_fk=$3 AND jq_args=$2 AND jq_endtime IS NULL';
127 $params = array($reportImportAgent->AgentName,$uploadId,$userId,$groupId);
128 $statementName = __METHOD__;
130 $sql .=
' AND jq_cmd_args=$5';
131 $params[] = $jqCmdArgs;
132 $statementName .=
'.args';
135 $sql .=
' AND jq_cmd_args IS NULL';
138 $scheduled = $dbManager->getSingleRow($sql,$params,$statementName);
139 if (!empty($scheduled)) {
140 return array($scheduled[
'job_pk'],$scheduled[
'jq_pk']);
143 $upload = $this->getUpload($uploadId, $groupId);
144 $jobId = JobAddJob($userId, $groupId, $upload->getFilename(), $uploadId);
146 $jobQueueId = $reportImportAgent->AgentAdd($jobId, $uploadId, $error, array(), $jqCmdArgs);
149 throw new Exception(_(
"Cannot schedule").
": ".$error);
151 return array($jobId,$jobQueueId);
154 protected function getUpload($uploadId, $groupId)
158 throw new Exception(_(
"parameter error: $uploadId"));
160 if (!$this->uploadDao->isAccessible($uploadId, $groupId))
162 throw new Exception(_(
"permission denied"));
165 $upload = $this->uploadDao->getUpload($uploadId);
166 if ($upload === null)
168 throw new Exception(_(
'cannot find uploadId'));
Traceback_uri()
Get the URI without query to this location.
render($templateName, $vars=null, $headers=null)
Convert2BrowserTime($server_time)
Convert the server time to browser time.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
plugin_find($pluginName)
Given the official name of a plugin, return the $Plugins object.
GetArrayVal($Key, $Arr)
Get the value from a array(map)
#define PERM_WRITE
Read-Write permission.