예제 #1
0
 public function copyFromFileToDB()
 {
     $fileReader = Import_Utils_Helper::getFileReader($this->request, $this->user);
     $fileReader->read();
     $fileReader->deleteFile();
     if ($fileReader->getStatus() == 'success') {
         $this->numberOfRecords = $fileReader->getNumberOfRecordsRead();
         return true;
     } else {
         Import_Utils_Helper::showErrorPage(vtranslate('ERR_FILE_READ_FAILED', 'Import') . ' - ' . vtranslate($fileReader->getErrorMessage(), 'Import'));
         return false;
     }
 }
예제 #2
0
 public static function validateFileUpload($request)
 {
     $current_user = Users_Record_Model::getCurrentUserModel();
     $uploadMaxSize = self::getMaxUploadSize();
     $importDirectory = self::getImportDirectory();
     $temporaryFileName = self::getImportFilePath($current_user);
     if ($_FILES['import_file']['error']) {
         $request->set('error_message', self::fileUploadErrorMessage($_FILES['import_file']['error']));
         return false;
     }
     if (!is_uploaded_file($_FILES['import_file']['tmp_name'])) {
         $request->set('error_message', vtranslate('LBL_FILE_UPLOAD_FAILED', 'Import'));
         return false;
     }
     if ($_FILES['import_file']['size'] > $uploadMaxSize) {
         $request->set('error_message', vtranslate('LBL_IMPORT_ERROR_LARGE_FILE', 'Import') . $uploadMaxSize . ' ' . vtranslate('LBL_IMPORT_CHANGE_UPLOAD_SIZE', 'Import'));
         return false;
     }
     if (!is_writable($importDirectory)) {
         $request->set('error_message', vtranslate('LBL_IMPORT_DIRECTORY_NOT_WRITABLE', 'Import'));
         return false;
     }
     $fileCopied = move_uploaded_file($_FILES['import_file']['tmp_name'], $temporaryFileName);
     if (!$fileCopied) {
         $request->set('error_message', vtranslate('LBL_IMPORT_FILE_COPY_FAILED', 'Import'));
         return false;
     }
     $fileReader = Import_Utils_Helper::getFileReader($request, $current_user);
     if ($fileReader == null) {
         $request->set('error_message', vtranslate('LBL_INVALID_FILE', 'Import'));
         return false;
     }
     $hasHeader = $fileReader->hasHeader();
     $firstRow = $fileReader->getFirstRowData($hasHeader);
     if ($firstRow === false) {
         $request->set('error_message', vtranslate('LBL_NO_ROWS_FOUND', 'Import'));
         return false;
     }
     return true;
 }
예제 #3
0
 function uploadAndParse(Vtiger_Request $request)
 {
     if (Import_Utils_Helper::validateFileUpload($request)) {
         $moduleName = $request->getModule();
         $user = Users_Record_Model::getCurrentUserModel();
         $fileReader = Import_Utils_Helper::getFileReader($request, $user);
         if ($fileReader == null) {
             $request->set('error_message', vtranslate('LBL_INVALID_FILE', 'Import'));
             $this->importBasicStep($request);
             exit;
         }
         $hasHeader = $fileReader->hasHeader();
         $rowData = $fileReader->getFirstRowData($hasHeader);
         $viewer = $this->getViewer($request);
         $autoMerge = $request->get('auto_merge');
         if (!$autoMerge) {
             $request->set('merge_type', 0);
             $request->set('merge_fields', '');
         } else {
             $viewer->assign('MERGE_FIELDS', Zend_Json::encode($request->get('merge_fields')));
         }
         $moduleName = $request->getModule();
         $moduleModel = Vtiger_Module_Model::getInstance($moduleName);
         $moduleMeta = $moduleModel->getModuleMeta();
         $viewer->assign('DATE_FORMAT', $user->date_format);
         $viewer->assign('FOR_MODULE', $moduleName);
         $viewer->assign('MODULE', 'Import');
         $viewer->assign('HAS_HEADER', $hasHeader);
         $viewer->assign('ROW_1_DATA', $rowData);
         $viewer->assign('USER_INPUT', $request);
         $viewer->assign('AVAILABLE_FIELDS', $moduleMeta->getImportableFields($moduleName));
         $viewer->assign('ENCODED_MANDATORY_FIELDS', Zend_Json::encode($moduleMeta->getMandatoryFields($moduleName)));
         $viewer->assign('SAVED_MAPS', Import_Map_Model::getAllByModule($moduleName));
         $viewer->assign('USERS_LIST', Import_Utils_Helper::getAssignedToUserList($moduleName));
         $viewer->assign('GROUPS_LIST', Import_Utils_Helper::getAssignedToGroupList($moduleName));
         return $viewer->view('ImportAdvanced.tpl', 'Import');
     } else {
         $this->importBasicStep($request);
     }
 }