assignPreviewVariables(); } /** * Build the form object. */ public function buildQuickForm() { // FIXME: This is a hack... // The tpl contains javascript that starts the import on form submit // Since our back/cancel buttons are of html type "submit" we have to prevent a form submit event when they are clicked // Hacking in some onclick js to make them act more like links instead of buttons $path = CRM_Utils_System::currentPath(); $query = ['_qf_MapField_display' => 'true']; $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String'); if (CRM_Utils_Rule::qfKey($qfKey)) { $query['qfKey'] = $qfKey; } $previousURL = CRM_Utils_System::url($path, $query, FALSE, NULL, FALSE); $cancelURL = CRM_Utils_System::url($path, 'reset=1', FALSE, NULL, FALSE); $this->addButtons([ [ 'type' => 'back', 'name' => ts('Previous'), 'js' => ['onclick' => "location.href='{$previousURL}'; return false;"], ], [ 'type' => 'next', 'name' => ts('Import Now'), 'spacing' => '          ', 'isDefault' => TRUE, ], [ 'type' => 'cancel', 'name' => ts('Cancel'), 'js' => ['onclick' => "location.href='{$cancelURL}'; return false;"], ], ]); } /** * Set status url for ajax. */ public function setStatusUrl() { $statusID = $this->get('statusID'); if (!$statusID) { $statusID = md5(uniqid(rand(), TRUE)); $this->set('statusID', $statusID); } $statusUrl = CRM_Utils_System::url('civicrm/ajax/status', "id={$statusID}", FALSE, NULL, FALSE); $this->assign('statusUrl', $statusUrl); } /** * Assign smarty variables for the preview screen. * * @throws \API_Exception * @throws \CRM_Core_Exception */ protected function assignPreviewVariables(): void { $this->assign('downloadErrorRecordsUrl', $this->getDownloadURL(CRM_Import_Parser::ERROR)); $this->assign('invalidRowCount', $this->getRowCount(CRM_Import_Parser::ERROR)); $this->assign('validRowCount', $this->getRowCount(CRM_Import_Parser::VALID)); $this->assign('totalRowCount', $this->getRowCount([])); $this->assign('mapper', $this->getMappedFieldLabels()); $this->assign('dataValues', $this->getDataRows([], 2)); $this->assign('columnNames', $this->getColumnHeaders()); //get the mapping name displayed if the mappingId is set $mappingId = $this->get('loadMappingId'); if ($mappingId) { $mapDAO = new CRM_Core_DAO_Mapping(); $mapDAO->id = $mappingId; $mapDAO->find(TRUE); } $this->assign('savedMappingName', $mappingId ? $mapDAO->name : NULL); $this->assign('skipColumnHeader', $this->getSubmittedValue('skipColumnHeader')); // rowDisplayCount is deprecated - it used to be used with {section} but we have nearly gotten rid of it. $this->assign('rowDisplayCount', $this->getSubmittedValue('skipColumnHeader') ? 3 : 2); } /** * Process the mapped fields and map it into the uploaded file * preview the file and extract some summary statistics * * @return void */ public function postProcess() { CRM_Import_Parser::runImport(NULL, $this->getUserJobID(), 0); } }