Example #1
0
 public function wizard_import()
 {
     if (!isset($_SESSION['CATS']) || empty($_SESSION['CATS'])) {
         echo 'CATS has lost your session!';
         return;
     }
     $siteID = $_SESSION['CATS']->getSiteID();
     // Echos Ok to redirect to the import stage, or Fail to go to home module
     $files = ImportUtility::getDirectoryFiles(FileUtility::getUploadPath($siteID, 'massimport'));
     if (count($files)) {
         echo 'Ok';
     } else {
         echo 'Fail';
     }
 }
Example #2
0
 public function massImport($step = 1)
 {
     if (isset($_SESSION['CATS']) && !empty($_SESSION['CATS'])) {
         $siteID = $_SESSION['CATS']->getSiteID();
     } else {
         CommonErrors::fatal(COMMONERROR_NOTLOGGEDIN, $this);
     }
     if ($_SESSION['CATS']->getAccessLevel() < ACCESS_LEVEL_EDIT) {
         CommonErrors::fatal(COMMONERROR_PERMISSION, $this, 'You do not have permission to import ' . 'mass resume documents.');
     }
     // Figure out what stage of the process we're on
     if (isset($_GET['step']) && ($step = intval($_GET['step'])) >= 1 && $step <= 4) {
     }
     $this->_template->assign('step', $step);
     if ($step == 1) {
         if (isset($_SESSION['CATS_PARSE_TEMP'])) {
             unset($_SESSION['CATS_PARSE_TEMP']);
         }
         $uploadDir = FileUtility::getUploadPath($siteID, 'massimport');
         $files = ImportUtility::getDirectoryFiles($uploadDir);
         if (is_array($files) && count($files)) {
             // User already has files for upload
             $this->_template->assign('documents', $files);
         }
         // Figure out the path to post resumes
         $script = $_SERVER['SCRIPT_FILENAME'];
         $mp = explode('/', $script);
         $rootPath = implode('/', array_slice($mp, 0, count($mp) - 1));
         $subPath = FileUtility::getUploadPath($siteID, 'massimport');
         if ($subPath !== false) {
             $uploadPath = $rootPath . '/' . $subPath . '/';
         } else {
             $uploadPath = false;
         }
         $this->_template->assign('flashUploaderEnabled', file_exists('modules/asp') ? true : false);
         $this->_template->assign('multipleFilesEnabled', true);
         $this->_template->assign('uploadPath', $uploadPath);
     } else {
         if ($step == 2) {
             /**
              * Step 1: Find any uploaded files and get them into an array.
              */
             if (isset($_SESSION['CATS_PARSE_TEMP'])) {
                 unset($_SESSION['CATS_PARSE_TEMP']);
             }
             $uploadDir = FileUtility::getUploadPath($siteID, 'massimport');
             $files = ImportUtility::getDirectoryFiles($uploadDir);
             if ($files === -1 || !is_array($files) || !count($files)) {
                 $this->_template->assign('errorMessage', 'You didn\'t upload any files or there was a ' . 'problem working with any files you uploaded. Please use the ' . '<a href="javascript:back()"><b>Back</b></a> button on your web browser ' . 'and select one or more files to import.');
                 $this->_template->assign('files', array());
                 $this->_template->assign('js', '');
             } else {
                 if (!eval(Hooks::get('MASS_IMPORT_SPACE_CHECK'))) {
                     return;
                 }
                 // Build the javascript to handle the ajax parsing (for progress bar)
                 $js = '';
                 foreach ($files as $fileData) {
                     $js .= sprintf('addDocument(\'%s\', \'%s\', \'%s\', %d, %d);%s', addslashes($fileData['name']), addslashes($fileData['realName']), addslashes($fileData['ext']), $fileData['type'], $fileData['cTime'], "\n");
                 }
                 $this->_template->assign('files', $files);
                 $this->_template->assign('js', $js);
             }
         } else {
             if ($step == 3) {
                 // Make sure the processed files exists, is an array, and is not empty
                 list($documents, $success, $failed) = $this->getMassImportDocuments();
                 if (!count($documents)) {
                     $this->_template->assign('errorMessage', 'None of the files you uploaded were able ' . 'to be imported!');
                 }
                 $this->_template->assign('documents', $documents);
             } else {
                 if ($step == 4) {
                     // Final step, import all applicable candidates
                     list($importedCandidates, $importedDocuments, $importedFailed, $importedDuplicates) = $this->getMassImportCandidates();
                     if (!count($importedCandidates) && !count($importedDocuments) && !count($importedFailed) && !count($importedDuplicates)) {
                         $this->_template->assign('errorMessage', '<b style="font-size: 20px;">Information no Longer ' . 'Available</b><br /><br />' . 'Ooops! You probably used the <b>back</b> or <b>refresh</b> ' . 'buttons on your browser. The information you previously had here is no longer ' . 'available. To start a new ' . 'mass resume import, <a style="font-size: 16px;" href="' . CATSUtility::getIndexName() . '?m=import&a=massImport&' . 'step=1">click here</a>.');
                     }
                     //if (!eval(Hooks::get('IMPORT_NOTIFY_DEV'))) return;
                     $this->_template->assign('importedCandidates', $importedCandidates);
                     $this->_template->assign('importedDocuments', $importedDocuments);
                     $this->_template->assign('importedFailed', $importedFailed);
                     $this->_template->assign('importedDuplicates', $importedDuplicates);
                     unset($_SESSION['CATS_PARSE_TEMP']);
                 } else {
                     if ($step == 99) {
                         // User wants to delete all files in their upload folder
                         $uploadDir = FileUtility::getUploadPath($siteID, 'massimport');
                         $files = ImportUtility::getDirectoryFiles($uploadDir);
                         if (is_array($files) && count($files)) {
                             foreach ($files as $file) {
                                 @unlink($file['name']);
                             }
                         }
                         echo 'Ok';
                         return;
                     }
                 }
             }
         }
     }
     $this->_template->assign('active', $this);
     // ->isDemo() doesn't work here... oddly.
     $this->_template->assign('isDemo', $_SESSION['CATS']->getSiteID() == 201);
     // Build the sub-template to pass to the container
     ob_start();
     $this->_template->display(sprintf('./modules/import/MassImportStep%d.tpl', $step));
     $subTemplateContents = ob_get_contents();
     ob_end_clean();
     // Show the main template (the container with the large status sections)
     $this->_template->assign('subTemplateContents', $subTemplateContents);
     $this->_template->display('./modules/import/MassImport.tpl');
 }