function action_RefreshTable()
 {
     $offset = isset($_REQUEST['offset']) ? $_REQUEST['offset'] : 0;
     $tableID = isset($_REQUEST['tableID']) ? $_REQUEST['tableID'] : 'errors';
     $has_header = $_REQUEST['has_header'] == 'on' ? TRUE : FALSE;
     if ($tableID == 'dup') {
         $tableFilename = ImportCacheFiles::getDuplicateFileName();
     } else {
         $tableFilename = ImportCacheFiles::getErrorRecordsFileName();
     }
     $if = new ImportFile($tableFilename, ",", '"', FALSE, FALSE);
     $if->setHeaderRow($has_header);
     $lv = new ImportListView($if, array('offset' => $offset), $tableID);
     $lv->display(FALSE);
     sugar_cleanup(TRUE);
 }
 /**
  * Writes the row out to the ImportCacheFiles::getErrorRecordsFileName() file
  */
 public function writeErrorRecord($errorMessage = '')
 {
     $rowData = !$this->_currentRow ? array() : $this->_currentRow;
     $fp = sugar_fopen(ImportCacheFiles::getErrorRecordsFileName(), 'a');
     $fpNoErrors = sugar_fopen(ImportCacheFiles::getErrorRecordsWithoutErrorFileName(), 'a');
     //Write records only for download without error message.
     fputcsv($fpNoErrors, $rowData);
     //Add the error message to the first column
     array_unshift($rowData, $errorMessage);
     fputcsv($fp, $rowData);
     fclose($fp);
     fclose($fpNoErrors);
 }
Exemple #3
0
 /**
  * Writes the row out to the ImportCacheFiles::getErrorRecordsFileName() file
  */
 public function writeErrorRecord()
 {
     $fp = sugar_fopen(ImportCacheFiles::getErrorRecordsFileName(), 'a');
     if (empty($this->_enclosure)) {
         fputs($fp, implode($this->_delimiter, $this->_currentRow) . PHP_EOL);
     } else {
         fputcsv($fp, $this->_currentRow, $this->_delimiter, $this->_enclosure);
     }
     fclose($fp);
 }
Exemple #4
0
 /**
  * @see SugarView::display()
  */
 public function display()
 {
     global $mod_strings, $app_strings, $current_user, $sugar_config, $current_language;
     $this->ss->assign("IMPORT_MODULE", $_REQUEST['import_module']);
     $this->ss->assign("TYPE", $_REQUEST['type']);
     $this->ss->assign("HEADER", $app_strings['LBL_IMPORT'] . " " . $mod_strings['LBL_MODULE_NAME']);
     $this->ss->assign("MODULE_TITLE", $this->getModuleTitle(false));
     // lookup this module's $mod_strings to get the correct module name
     $module_mod_strings = return_module_language($current_language, $_REQUEST['import_module']);
     $this->ss->assign("MODULENAME", $module_mod_strings['LBL_MODULE_NAME']);
     // read status file to get totals for records imported, errors, and duplicates
     $count = 0;
     $errorCount = 0;
     $dupeCount = 0;
     $createdCount = 0;
     $updatedCount = 0;
     $fp = sugar_fopen(ImportCacheFiles::getStatusFileName(), 'r');
     while (($row = fgetcsv($fp, 8192)) !== FALSE) {
         $count += (int) $row[0];
         $errorCount += (int) $row[1];
         $dupeCount += (int) $row[2];
         $createdCount += (int) $row[3];
         $updatedCount += (int) $row[4];
     }
     fclose($fp);
     $this->ss->assign("showUndoButton", FALSE);
     if ($createdCount > 0) {
         $this->ss->assign("showUndoButton", TRUE);
     }
     if ($errorCount > 0 && ($createdCount <= 0 && $updatedCount <= 0)) {
         $activeTab = 2;
     } else {
         if ($dupeCount > 0 && ($createdCount <= 0 && $updatedCount <= 0)) {
             $activeTab = 1;
         } else {
             $activeTab = 0;
         }
     }
     $this->ss->assign("JAVASCRIPT", $this->_getJS($activeTab));
     $this->ss->assign("errorCount", $errorCount);
     $this->ss->assign("dupeCount", $dupeCount);
     $this->ss->assign("createdCount", $createdCount);
     $this->ss->assign("updatedCount", $updatedCount);
     $this->ss->assign("errorFile", ImportCacheFiles::convertFileNameToUrl(ImportCacheFiles::getErrorFileName()));
     $this->ss->assign("errorrecordsFile", ImportCacheFiles::convertFileNameToUrl(ImportCacheFiles::getErrorRecordsWithoutErrorFileName()));
     $this->ss->assign("dupeFile", ImportCacheFiles::convertFileNameToUrl(ImportCacheFiles::getDuplicateFileName()));
     if ($this->bean->object_name == "Prospect") {
         $this->ss->assign("PROSPECTLISTBUTTON", $this->_addToProspectListButton());
     } else {
         $this->ss->assign("PROSPECTLISTBUTTON", "");
     }
     $resultsTable = "";
     foreach (UsersLastImport::getBeansByImport($_REQUEST['import_module']) as $beanname) {
         // load bean
         if (!$this->bean instanceof $beanname) {
             $this->bean = new $beanname();
         }
         $resultsTable .= $this->getListViewResults();
     }
     if (empty($resultsTable)) {
         $resultsTable = $this->getListViewResults();
     }
     $this->ss->assign("RESULTS_TABLE", $resultsTable);
     $this->ss->assign("ERROR_TABLE", $this->getListViewTableFromFile(ImportCacheFiles::getErrorRecordsFileName(), 'errors'));
     $this->ss->assign("DUP_TABLE", $this->getListViewTableFromFile(ImportCacheFiles::getDuplicateFileDisplayName(), 'dup'));
     $content = $this->ss->fetch('modules/Import/tpls/last.tpl');
     $this->ss->assign("CONTENT", $content);
     $this->ss->display('modules/Import/tpls/wizardWrapper.tpl');
 }
Exemple #5
0
 /** 
  * @see SugarView::display()
  */
 public function display()
 {
     global $mod_strings, $app_strings, $current_user, $sugar_config, $current_language;
     $this->ss->assign("MOD", $mod_strings);
     $this->ss->assign("APP", $app_strings);
     $this->ss->assign("IMPORT_MODULE", $_REQUEST['import_module']);
     $this->ss->assign("TYPE", $_REQUEST['type']);
     $this->ss->assign("HEADER", $app_strings['LBL_IMPORT'] . " " . $mod_strings['LBL_MODULE_NAME']);
     $this->ss->assign("MODULE_TITLE", $this->getModuleTitle());
     // lookup this module's $mod_strings to get the correct module name
     $language = isset($current_language) ? $current_language : $sugar_config['default_language'];
     $module_mod_strings = return_module_language($current_language, $_REQUEST['import_module']);
     $this->ss->assign("MODULENAME", $module_mod_strings['LBL_MODULE_NAME']);
     $this->ss->assign("JAVASCRIPT", $this->_getJS());
     // read status file to get totals for records imported, errors, and duplicates
     $count = 0;
     $errorCount = 0;
     $dupeCount = 0;
     $createdCount = 0;
     $updatedCount = 0;
     $fp = sugar_fopen(ImportCacheFiles::getStatusFileName(), 'r');
     while (($row = fgetcsv($fp, 8192)) !== FALSE) {
         $count += (int) $row[0];
         $errorCount += (int) $row[1];
         $dupeCount += (int) $row[2];
         $createdCount += (int) $row[3];
         $updatedCount += (int) $row[4];
     }
     fclose($fp);
     $this->ss->assign("errorCount", $errorCount);
     $this->ss->assign("dupeCount", $dupeCount);
     $this->ss->assign("createdCount", $createdCount);
     $this->ss->assign("updatedCount", $updatedCount);
     $this->ss->assign("errorFile", ImportCacheFiles::getErrorFileName());
     $this->ss->assign("errorrecordsFile", ImportCacheFiles::getErrorRecordsFileName());
     $this->ss->assign("dupeFile", ImportCacheFiles::getDuplicateFileName());
     // load bean
     $focus = loadImportBean($_REQUEST['import_module']);
     if (!$focus) {
         showImportError($mod_strings['LBL_ERROR_IMPORTS_NOT_SET_UP'], $_REQUEST['import_module']);
         return;
     }
     if ($focus->object_name == "Prospect") {
         $this->ss->assign("PROSPECTLISTBUTTON", $this->_addToProspectListButton());
     } else {
         $this->ss->assign("PROSPECTLISTBUTTON", "");
     }
     $this->ss->display('modules/Import/tpls/last.tpl');
     foreach (UsersLastImport::getBeansByImport($_REQUEST['import_module']) as $beanname) {
         // load bean
         if (!$focus instanceof $beanname) {
             require_once $GLOBALS['beanFiles'][$beanname];
             $focus = new $beanname();
         }
         // build listview to show imported records
         require_once 'include/ListView/ListViewFacade.php';
         $lvf = new ListViewFacade($focus, $focus->module_dir, 0);
         $params = array();
         if (!empty($_REQUEST['orderBy'])) {
             $params['orderBy'] = $_REQUEST['orderBy'];
             $params['overrideOrder'] = true;
             if (!empty($_REQUEST['sortOrder'])) {
                 $params['sortOrder'] = $_REQUEST['sortOrder'];
             }
         }
         $beanname = $focus->object_name == 'Case' ? 'aCase' : $focus->object_name;
         // add users_last_import joins so we only show records done in this import
         $params['custom_from'] = ', users_last_import';
         $params['custom_where'] = " AND users_last_import.assigned_user_id = '{$GLOBALS['current_user']->id}' \n                AND users_last_import.bean_type = '{$beanname}' \n                AND users_last_import.bean_id = {$focus->table_name}.id \n                AND users_last_import.deleted = 0 \n                AND {$focus->table_name}.deleted = 0";
         $where = " {$focus->table_name}.id IN ( \n                        SELECT users_last_import.bean_id\n                            FROM users_last_import\n                            WHERE users_last_import.assigned_user_id = '{$GLOBALS['current_user']->id}' \n                                AND users_last_import.bean_type = '{$beanname}' \n                                AND users_last_import.deleted = 0 )";
         $lbl_last_imported = $mod_strings['LBL_LAST_IMPORTED'];
         $lvf->lv->mergeduplicates = false;
         $module_mod_strings = return_module_language($current_language, $focus->module_dir);
         $lvf->setup('', $where, $params, $module_mod_strings, 0, -1, '', strtoupper($beanname), array(), 'id');
         $lvf->display($lbl_last_imported . ": " . $module_mod_strings['LBL_MODULE_NAME']);
     }
 }
 public function testWriteStatusWithTwoErrorsInOneRow()
 {
     $file = SugarTestImportUtilities::createFile(3, 2);
     $importFile = new ImportFile($file, ',', '"');
     $row = $importFile->getNextRow();
     $importFile->writeError('Some Error', 'field1', 'foo');
     $importFile->writeError('Some Error', 'field1', 'foo');
     $importFile->getNextRow();
     $importFile->markRowAsImported();
     $importFile->getNextRow();
     $importFile->markRowAsImported();
     $importFile->writeStatus();
     $fp = sugar_fopen(ImportCacheFiles::getStatusFileName(), 'r');
     $statusrow = fgetcsv($fp);
     fclose($fp);
     $this->assertEquals(array(3, 1, 0, 2, 0, $file), $statusrow);
     $fp = sugar_fopen(ImportCacheFiles::getErrorRecordsFileName(), 'r');
     $errorrecordrow = fgetcsv($fp);
     $this->assertEquals($row, $errorrecordrow);
     $this->assertFalse(fgetcsv($fp), 'Should be only 1 record in the csv file');
     fclose($fp);
 }