/** * Returns a JSON response containing information regarding the galley formats enabled * for this submission. * @param $args array * @param $request Request * @return JSONMessage JSON object */ function fetchFormatInfo($args, $request) { $submission = $this->getSubmission(); $galleyDao = DAORegistry::getDAO('ArticleGalleyDAO'); $galleys = $galleyDao->getBySubmissionId($submission->getId()); $formats = array(); while ($galley = $galleys->next()) { $formats[$galley->getId()] = $galley->getLocalizedName(); } $json = new JSONMessage(true, true); $json->setAdditionalAttributes(array('formats' => $formats)); return $json; }
/** * Save form to generate custom reports. * @param $args array * @param $request Request * @return JSONMessage JSON object */ function saveReportGenerator($args, $request) { $this->setupTemplate($request); $reportGeneratorForm = $this->_getReportGeneratorForm($request); $reportGeneratorForm->readInputData(); $json = new JSONMessage(true); if ($reportGeneratorForm->validate()) { $reportUrl = $reportGeneratorForm->execute($request); $json->setAdditionalAttributes(array('reportUrl' => $reportUrl)); } else { $json->setStatus(false); } return $json; }
/** * Upload a new cover image file. * @param $args array * @param $request PKPRequest * @return JSONMessage JSON object */ function uploadCoverImage($args, $request) { $user = $request->getUser(); import('lib.pkp.classes.file.TemporaryFileManager'); $temporaryFileManager = new TemporaryFileManager(); $temporaryFile = $temporaryFileManager->handleUpload('uploadedFile', $user->getId()); if ($temporaryFile) { $json = new JSONMessage(true); $json->setAdditionalAttributes(array('temporaryFileId' => $temporaryFile->getId())); return $json; } else { return new JSONMessage(false, __('common.uploadFailed')); } }
/** * Returns a JSON response containing information regarding the galley formats enabled * for this submission. * @param $args array * @param $request Request */ function fetchFormatInfo($args, $request) { $submission = $this->getSubmission(); $json = new JSONMessage(); $galleyDao = DAORegistry::getDAO('ArticleGalleyDAO'); $galleys = $galleyDao->getGalleysByArticle($submission->getId()); $formats = array(); foreach ($galleys as $galley) { $formats[$galley->getId()] = $galley->getLocalizedName(); } $json->setStatus(true); $json->setContent(true); $json->setAdditionalAttributes(array('formats' => $formats)); return $json->getString(); }
/** * Render a category with all the rows inside of it. * @param $args array * @param $request Request * @return string the serialized row JSON message or a flag * that indicates that the row has not been found. */ function fetchCategory(&$args, &$request) { // Instantiate the requested row (includes a // validity check on the row id). $row =& $this->getRequestedCategoryRow($request, $args); $json = new JSONMessage(true); if (is_null($row)) { // Inform the client that the category does no longer exist. $json->setAdditionalAttributes(array('elementNotFound' => (int) $args['rowId'])); } else { // Render the requested category $this->setFirstDataColumn(); $json->setContent($this->_renderCategoryInternally($request, $row)); } // Render and return the JSON message. return $json->getString(); }
/** * Fetch a file that has been uploaded. * * @param $args array * @param $request Request * @return string */ function fetchFile($args, $request) { // Get the setting name. $settingName = $args['settingName']; // Try to fetch the file. $tabForm = $this->getTabForm(); $tabForm->initData($request); $renderedElement = $tabForm->renderFileView($settingName, $request); $json = new JSONMessage(); if ($renderedElement == false) { $json->setAdditionalAttributes(array('noData' => $settingName)); } else { $json->setElementId($settingName); $json->setContent($renderedElement); } return $json->getString(); }
/** * Display the plugin. * @param $args array * @param $request PKPRequest */ function display($args, $request) { $templateMgr = TemplateManager::getManager($request); $context = $request->getContext(); parent::display($args, $request); $templateMgr->assign('plugin', $this); switch (array_shift($args)) { case 'index': case '': $templateMgr->display($this->getTemplatePath() . 'index.tpl'); break; case 'uploadImportXML': $user = $request->getUser(); import('lib.pkp.classes.file.TemporaryFileManager'); $temporaryFileManager = new TemporaryFileManager(); $temporaryFile = $temporaryFileManager->handleUpload('uploadedFile', $user->getId()); if ($temporaryFile) { $json = new JSONMessage(true); $json->setAdditionalAttributes(array('temporaryFileId' => $temporaryFile->getId())); } else { $json = new JSONMessage(false, __('common.uploadFailed')); } return $json->getString(); case 'importBounce': $json = new JSONMessage(true); $json->setEvent('addTab', array('title' => __('plugins.importexport.users.results'), 'url' => $request->url(null, null, null, array('plugin', $this->getName(), 'import'), array('temporaryFileId' => $request->getUserVar('temporaryFileId'))))); return $json->getString(); case 'import': $temporaryFileId = $request->getUserVar('temporaryFileId'); $temporaryFileDao = DAORegistry::getDAO('TemporaryFileDAO'); $user = $request->getUser(); $temporaryFile = $temporaryFileDao->getTemporaryFile($temporaryFileId, $user->getId()); if (!$temporaryFile) { $json = new JSONMessage(true, __('plugins.importexport.users.uploadFile')); return $json->getString(); } $temporaryFilePath = $temporaryFile->getFilePath(); $users = $this->importUsers(file_get_contents($temporaryFilePath), $context, $user); $templateMgr->assign('users', $users); $json = new JSONMessage(true, $templateMgr->fetch($this->getTemplatePath() . 'results.tpl')); return $json->getString(); case 'export': $exportXml = $this->exportUsers((array) $request->getUserVar('selectedUsers'), $request->getContext(), $request->getUser()); header('Content-type: application/xml'); echo $exportXml; break; case 'exportAllUsers': $exportXml = $this->exportAllUsers($request->getContext(), $request->getUser()); header('Content-type: application/xml'); echo $exportXml; break; default: $dispatcher = $request->getDispatcher(); $dispatcher->handle404(); } }
/** * Render a row and send it to the client. If the row no * longer exists then inform the client. * @param $args array * @param $request Request * @return JSONMessage JSON object. */ function fetchRow(&$args, $request) { // Instantiate the requested row (includes a // validity check on the row id). $row = $this->getRequestedRow($request, $args); $json = new JSONMessage(true); if (is_null($row)) { // Inform the client that the row does no longer exist. $json->setAdditionalAttributes(array('elementNotFound' => $args['rowId'])); } else { // Render the requested row $renderedRow = $this->renderRow($request, $row); $json->setContent($renderedRow); // Add the sequence map so grid can place the row at the correct position. $sequenceMap = $this->getRowsSequence($request); $json->setAdditionalAttributes(array('sequenceMap' => $sequenceMap)); } $this->callFeaturesHook('fetchRow', array('request' => &$request, 'grid' => &$this, 'row' => &$row, 'jsonMessage' => &$json)); // Render and return the JSON message. return $json; }
/** * Display the plugin. * @param $args array * @param $request PKPRequest */ function display($args, $request) { $templateMgr = TemplateManager::getManager($request); $press = $request->getPress(); parent::display($args, $request); $templateMgr->assign('plugin', $this); switch (array_shift($args)) { case 'index': case '': $templateMgr->display($this->getTemplatePath() . 'index.tpl'); break; case 'uploadImportXML': $user = $request->getUser(); import('lib.pkp.classes.file.TemporaryFileManager'); $temporaryFileManager = new TemporaryFileManager(); $temporaryFile = $temporaryFileManager->handleUpload('uploadedFile', $user->getId()); if ($temporaryFile) { $json = new JSONMessage(true); $json->setAdditionalAttributes(array('temporaryFileId' => $temporaryFile->getId())); } else { $json = new JSONMessage(false, __('common.uploadFailed')); } return $json->getString(); case 'importBounce': $json = new JSONMessage(true); $json->setEvent('addTab', array('title' => __('plugins.importexport.native.results'), 'url' => $request->url(null, null, null, array('plugin', $this->getName(), 'import'), array('temporaryFileId' => $request->getUserVar('temporaryFileId'))))); return $json->getString(); case 'import': AppLocale::requireComponents(LOCALE_COMPONENT_PKP_SUBMISSION); $temporaryFileId = $request->getUserVar('temporaryFileId'); $temporaryFileDao = DAORegistry::getDAO('TemporaryFileDAO'); $user = $request->getUser(); $temporaryFile = $temporaryFileDao->getTemporaryFile($temporaryFileId, $user->getId()); if (!$temporaryFile) { $json = new JSONMessage(true, __('plugins.inportexport.native.uploadFile')); return $json->getString(); } $temporaryFilePath = $temporaryFile->getFilePath(); $deployment = new NativeImportExportDeployment($press, $user); libxml_use_internal_errors(true); $submissions = $this->importSubmissions(file_get_contents($temporaryFilePath), $deployment); $templateMgr->assign('submissions', $submissions); $validationErrors = array_filter(libxml_get_errors(), create_function('$a', 'return $a->level == LIBXML_ERR_ERROR || $a->level == LIBXML_ERR_FATAL;')); $templateMgr->assign('validationErrors', $validationErrors); libxml_clear_errors(); // Are there any submissions import errors $processedSubmissionsIds = $deployment->getProcessedObjectsIds(ASSOC_TYPE_SUBMISSION); if (!empty($processedSubmissionsIds)) { $submissionsErrors = array_filter($processedSubmissionsIds, create_function('$a', 'return !empty($a);')); if (!empty($submissionsErrors)) { $templateMgr->assign('submissionsErrors', $processedSubmissionsIds); } } // If there are any submissions or validataion errors // delete imported submissions. if (!empty($submissionsErrors) || !empty($validationErrors)) { // remove all imported sumissions $deployment->removeImportedObjects(ASSOC_TYPE_SUBMISSION); } // Display the results $json = new JSONMessage(true, $templateMgr->fetch($this->getTemplatePath() . 'results.tpl')); return $json->getString(); case 'export': $exportXml = $this->exportSubmissions((array) $request->getUserVar('selectedSubmissions'), $request->getContext(), $request->getUser()); import('lib.pkp.classes.file.FileManager'); $fileManager = new FileManager(); $exportFileName = $this->getExportFileName($this->getExportPath(), 'monographs', $press, '.xml'); $fileManager->writeFile($exportFileName, $exportXml); $fileManager->downloadFile($exportFileName); $fileManager->deleteFile($exportFileName); break; default: $dispatcher = $request->getDispatcher(); $dispatcher->handle404(); } }
/** * Upload a plugin file. * @param $args array * @param $request PKPRequest * @return JSONMessage JSON object */ function uploadPluginFile($args, $request) { import('lib.pkp.classes.file.TemporaryFileManager'); $temporaryFileManager = new TemporaryFileManager(); $user = $request->getUser(); // Return the temporary file id. if ($temporaryFile = $temporaryFileManager->handleUpload('uploadedFile', $user->getId())) { $json = new JSONMessage(true); $json->setAdditionalAttributes(array('temporaryFileId' => $temporaryFile->getId())); return $json; } else { return new JSONMessage(false, __('manager.plugins.uploadError')); } }
/** * Save the forms handled by this Handler. * @param $request Request * @param $args array * @return string JSON message */ function saveForm($args, $request) { $json = new JSONMessage(); $form = null; $submission = $this->getSubmission(); $stageId = $this->getStageId(); $notificationKey = null; $this->_getFormFromCurrentTab($form, $notificationKey, $request); if ($form) { // null if we didn't have a valid tab $form->readInputData(); if ($form->validate($request)) { $form->execute($request); // Create trivial notification in place on the form $notificationManager = new NotificationManager(); $user = $request->getUser(); $notificationManager->createTrivialNotification($user->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __($notificationKey))); } else { // Could not validate; redisplay the form. $json->setStatus(true); $json->setContent($form->fetch($request)); } if ($request->getUserVar('displayedInContainer')) { $router = $request->getRouter(); $dispatcher = $router->getDispatcher(); $url = $dispatcher->url($request, ROUTE_COMPONENT, null, $this->_getHandlerClassPath(), 'fetch', null, array('submissionId' => $submission->getId(), 'stageId' => $stageId, 'tabPos' => $this->getTabPosition(), 'hideHelp' => true)); $json->setAdditionalAttributes(array('reloadContainer' => true, 'tabsUrl' => $url)); $json->setContent(true); // prevents modal closure } return $json; } else { fatalError('Unknown or unassigned format id!'); } }
/** * Update submission pub ids. * @param $args array * @param $request PKPRequest * @return JSONMessage JSON object */ function updateIdentifiers($args, $request) { import('lib.pkp.controllers.tab.pubIds.form.PKPPublicIdentifiersForm'); $submission = $this->getSubmission(); $stageId = $this->getStageId(); $form = new PKPPublicIdentifiersForm($submission, $stageId, array('displayedInContainer' => true)); $form->readInputData(); if ($form->validate($request)) { $form->execute($request); $json = new JSONMessage(); if ($request->getUserVar('displayedInContainer')) { $router = $request->getRouter(); $dispatcher = $router->getDispatcher(); $url = $dispatcher->url($request, ROUTE_COMPONENT, null, $this->_getHandlerClassPath(), 'fetch', null, array('submissionId' => $submission->getId(), 'stageId' => $stageId, 'tabPos' => $this->getTabPosition(), 'hideHelp' => true)); $json->setAdditionalAttributes(array('reloadContainer' => true, 'tabsUrl' => $url)); $json->setContent(true); // prevents modal closure } return $json; } else { return new JSONMessage(true, $form->fetch($request)); } }
/** * Returns a JSON response containing information regarding the formats enabled * for this submission. * @param $args array * @param $request Request * @return JSONMessage JSON object */ function fetchFormatInfo($args, $request) { $submission = $this->getSubmission(); $publicationFormatDao = DAORegistry::getDAO('PublicationFormatDAO'); $formats = $publicationFormatDao->getBySubmissionId($submission->getId()); $publicationFormats = array(); while ($format = $formats->next()) { $publicationFormats[$format->getId()] = $format->getLocalizedName(); } $json = new JSONMessage(true, true); $json->setAdditionalAttributes(array('formats' => $publicationFormats)); return $json; }
/** * Display the plugin. * @param $args array * @param $request PKPRequest */ function display($args, $request) { $templateMgr = TemplateManager::getManager($request); $context = $request->getContext(); parent::display($args, $request); $templateMgr->assign('plugin', $this); switch (array_shift($args)) { case 'index': case '': $templateMgr->display($this->getTemplatePath() . 'index.tpl'); break; case 'uploadImportXML': $user = $request->getUser(); import('lib.pkp.classes.file.TemporaryFileManager'); $temporaryFileManager = new TemporaryFileManager(); $temporaryFile = $temporaryFileManager->handleUpload('uploadedFile', $user->getId()); if ($temporaryFile) { $json = new JSONMessage(true); $json->setAdditionalAttributes(array('temporaryFileId' => $temporaryFile->getId())); } else { $json = new JSONMessage(false, __('common.uploadFailed')); } return $json->getString(); case 'importBounce': $json = new JSONMessage(true); $json->setEvent('addTab', array('title' => __('plugins.importexport.users.results'), 'url' => $request->url(null, null, null, array('plugin', $this->getName(), 'import'), array('temporaryFileId' => $request->getUserVar('temporaryFileId'))))); return $json->getString(); case 'import': $temporaryFileId = $request->getUserVar('temporaryFileId'); $temporaryFileDao = DAORegistry::getDAO('TemporaryFileDAO'); $user = $request->getUser(); $temporaryFile = $temporaryFileDao->getTemporaryFile($temporaryFileId, $user->getId()); if (!$temporaryFile) { $json = new JSONMessage(true, __('plugins.importexport.users.uploadFile')); return $json->getString(); } $temporaryFilePath = $temporaryFile->getFilePath(); libxml_use_internal_errors(true); $users = $this->importUsers(file_get_contents($temporaryFilePath), $context, $user); $validationErrors = array_filter(libxml_get_errors(), create_function('$a', 'return $a->level == LIBXML_ERR_ERROR || $a->level == LIBXML_ERR_FATAL;')); $templateMgr->assign('validationErrors', $validationErrors); libxml_clear_errors(); $templateMgr->assign('users', $users); $json = new JSONMessage(true, $templateMgr->fetch($this->getTemplatePath() . 'results.tpl')); return $json->getString(); case 'export': $exportXml = $this->exportUsers((array) $request->getUserVar('selectedUsers'), $request->getContext(), $request->getUser()); import('lib.pkp.classes.file.FileManager'); $fileManager = new FileManager(); $exportFileName = $this->getExportFileName($this->getExportPath(), 'users', $context, '.xml'); $fileManager->writeFile($exportFileName, $exportXml); $fileManager->downloadFile($exportFileName); $fileManager->deleteFile($exportFileName); break; case 'exportAllUsers': $exportXml = $this->exportAllUsers($request->getContext(), $request->getUser()); import('lib.pkp.classes.file.TemporaryFileManager'); $fileManager = new TemporaryFileManager(); $exportFileName = $this->getExportFileName($this->getExportPath(), 'users', $context, '.xml'); $fileManager->writeFile($exportFileName, $exportXml); $fileManager->downloadFile($exportFileName); $fileManager->deleteFile($exportFileName); break; default: $dispatcher = $request->getDispatcher(); $dispatcher->handle404(); } }