/** * Common form elements. */ public function buildQuickForm() { $config = CRM_Core_Config::singleton(); $uploadFileSize = CRM_Utils_Number::formatUnitSize($config->maxFileSize . 'm', TRUE); $uploadSize = round($uploadFileSize / (1024 * 1024), 2); $this->assign('uploadSize', $uploadSize); $this->add('File', 'uploadFile', ts('Import Data File'), 'size=30 maxlength=255', TRUE); $this->setMaxFileSize($uploadFileSize); $this->addRule('uploadFile', ts('File size should be less than %1 MBytes (%2 bytes)', array(1 => $uploadSize, 2 => $uploadFileSize)), 'maxfilesize', $uploadFileSize); $this->addRule('uploadFile', ts('A valid file must be uploaded.'), 'uploadedfile'); $this->addRule('uploadFile', ts('Input file must be in CSV format'), 'utf8File'); $this->addElement('checkbox', 'skipColumnHeader', ts('First row contains column headers')); $this->add('text', 'fieldSeparator', ts('Import Field Separator'), array('size' => 2), TRUE); $this->setDefaults(array('fieldSeparator' => $config->fieldSeparator)); //get the saved mapping details $mappingArray = CRM_Core_BAO_Mapping::getMappings(CRM_Core_OptionGroup::getValue('mapping_type', 'Import ' . static::IMPORT_ENTITY, 'name')); $this->assign('savedMapping', $mappingArray); $this->add('select', 'savedMapping', ts('Mapping Option'), array('' => ts('- select -')) + $mappingArray); if ($loadedMapping = $this->get('loadedMapping')) { $this->assign('loadedMapping', $loadedMapping); $this->setDefaults(array('savedMapping' => $loadedMapping)); } //build date formats CRM_Core_Form_Date::buildAllowedDateFormats($this); $this->addButtons(array(array('type' => 'upload', 'name' => ts('Continue'), 'spacing' => ' ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); }
/** * Basic setup. */ public function preProcess() { $config = CRM_Core_Config::singleton(); $this->_uploadMaxSize = (int) ini_get('upload_max_filesize'); // check for post max size CRM_Utils_Number::formatUnitSize(ini_get('post_max_size'), TRUE); }
/** * Basic setup. */ public function preProcess() { $this->_uploadMaxSize = (int) ini_get('upload_max_filesize'); // check for post max size CRM_Utils_Number::formatUnitSize(ini_get('post_max_size'), TRUE); // This is a temp hack for the fact we really don't need to hard-code each setting in the tpl but // we haven't worked through NOT doing that. These settings have been un-hardcoded. $this->assign('pure_config_settings', array('empoweredBy', 'max_attachments', 'maxFileSize', 'secondDegRelPermissions', 'recentItemsMaxCount', 'recentItemsProviders', 'dedupe_default_limit')); }
/** * Set variables up before form is built. */ public function preProcess() { //Test database user privilege to create table(Temporary) CRM-4725 $errorScope = CRM_Core_TemporaryErrorScope::ignoreException(); $daoTestPrivilege = new CRM_Core_DAO(); $daoTestPrivilege->query("CREATE TEMPORARY TABLE import_job_permission_one(test int) ENGINE=InnoDB"); $daoTestPrivilege->query("CREATE TEMPORARY TABLE import_job_permission_two(test int) ENGINE=InnoDB"); $daoTestPrivilege->query("DROP TEMPORARY TABLE IF EXISTS import_job_permission_one, import_job_permission_two"); unset($errorScope); if ($daoTestPrivilege->_lastError) { CRM_Core_Error::fatal(ts('Database Configuration Error: Insufficient permissions. Import requires that the CiviCRM database user has permission to create temporary tables. Contact your site administrator for assistance.')); } $results = array(); $config = CRM_Core_Config::singleton(); $handler = opendir($config->uploadDir); $errorFiles = array('sqlImport.errors', 'sqlImport.conflicts', 'sqlImport.duplicates', 'sqlImport.mismatch'); // check for post max size avoid when called twice $snippet = CRM_Utils_Array::value('snippet', $_GET, 0); if (empty($snippet)) { CRM_Utils_Number::formatUnitSize(ini_get('post_max_size'), TRUE); } while ($file = readdir($handler)) { if ($file != '.' && $file != '..' && in_array($file, $errorFiles) && !is_writable($config->uploadDir . $file)) { $results[] = $file; } } closedir($handler); if (!empty($results)) { CRM_Core_Error::fatal(ts('<b>%1</b> file(s) in %2 directory are not writable. Listed file(s) might be used during the import to log the errors occurred during Import process. Contact your site administrator for assistance.', array(1 => implode(', ', $results), 2 => $config->uploadDir))); } $this->_dataSourceIsValid = FALSE; $this->_dataSource = CRM_Utils_Request::retrieve('dataSource', 'String', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'GET'); $this->_params = $this->controller->exportValues($this->_name); if (!$this->_dataSource) { //considering dataSource as base criteria instead of hidden_dataSource. $this->_dataSource = CRM_Utils_Array::value('dataSource', $_POST, CRM_Utils_Array::value('dataSource', $this->_params)); $this->assign('showOnlyDataSourceFormPane', FALSE); } else { $this->assign('showOnlyDataSourceFormPane', TRUE); } $dataSources = $this->_getDataSources(); if ($this->_dataSource && isset($dataSources[$this->_dataSource])) { $this->_dataSourceIsValid = TRUE; $this->assign('showDataSourceFormPane', TRUE); $dataSourcePath = explode('_', $this->_dataSource); $templateFile = "CRM/Contact/Import/Form/" . $dataSourcePath[3] . ".tpl"; $this->assign('dataSourceFormTemplateFile', $templateFile); } elseif ($this->_dataSource) { throw new \CRM_Core_Exception("Invalid data source"); } }
/** * This is function is called by the form object to get the DataSource's * form snippet. It should add all fields necesarry to get the data * uploaded to the temporary table in the DB. * * @param CRM_Core_Form $form * * @return void * (operates directly on form argument) */ public function buildQuickForm(&$form) { $form->add('hidden', 'hidden_dataSource', 'CRM_Import_DataSource_CSV'); $config = CRM_Core_Config::singleton(); $uploadFileSize = CRM_Utils_Number::formatUnitSize($config->maxFileSize . 'm', TRUE); $uploadSize = round($uploadFileSize / (1024 * 1024), 2); $form->assign('uploadSize', $uploadSize); $form->add('File', 'uploadFile', ts('Import Data File'), 'size=30 maxlength=255', TRUE); $form->setMaxFileSize($uploadFileSize); $form->addRule('uploadFile', ts('File size should be less than %1 MBytes (%2 bytes)', array(1 => $uploadSize, 2 => $uploadFileSize)), 'maxfilesize', $uploadFileSize); $form->addRule('uploadFile', ts('Input file must be in CSV format'), 'utf8File'); $form->addRule('uploadFile', ts('A valid file must be uploaded.'), 'uploadedfile'); $form->addElement('checkbox', 'skipColumnHeader', ts('First row contains column headers')); }
/** * Function to actually build the form - this appears to be entirely code that should be in a shared base class in core * * @return None * @access public */ public function buildQuickForm() { // Setting Upload File Size. $config = CRM_Core_Config::singleton(); // This conditional block is important as the "maxImportFileSize" has been changed to "maxFileSize" // in the newer versions. In order to remove version support, remove this block and // replace by $uploadFileSize = $config->maxFileSize. if (!empty($config->maxImportFileSize)) { $uploadFileSize = $config->maxImportFileSize; } else { $uploadFileSize = CRM_Utils_Number::formatUnitSize($config->maxFileSize . 'm', TRUE); } if ($uploadFileSize >= 8388608) { $uploadFileSize = 8388608; } $uploadSize = round($uploadFileSize / (1024 * 1024), 2); $this->assign('uploadSize', $uploadSize); $this->add('file', 'uploadFile', ts('Import Data File'), 'size=30 maxlength=255', TRUE); $this->addRule('uploadFile', ts('A valid file must be uploaded.'), 'uploadedfile'); $this->addRule('uploadFile', ts('File size should be less than %1 MBytes (%2 bytes)', array(1 => $uploadSize, 2 => $uploadFileSize)), 'maxfilesize', $uploadFileSize); $this->setMaxFileSize($uploadFileSize); $this->addRule('uploadFile', ts('Input file must be in CSV format'), 'utf8File'); $this->addElement('checkbox', 'skipColumnHeader', ts('First row contains column headers')); if ($this->isDuplicateOptions) { $duplicateOptions = array(); $duplicateOptions[] = $this->createElement('radio', NULL, NULL, ts('Skip'), CRM_Import_Parser::DUPLICATE_SKIP); $duplicateOptions[] = $this->createElement('radio', NULL, NULL, ts('Update'), CRM_Import_Parser::DUPLICATE_UPDATE); $duplicateOptions[] = $this->createElement('radio', NULL, NULL, ts('No Duplicate Checking'), CRM_Import_Parser::DUPLICATE_NOCHECK); $this->addGroup($duplicateOptions, 'onDuplicate', ts('On Duplicate Entries')); } //get the saved mapping details $mappingArray = CRM_Core_BAO_Mapping::getMappings(CRM_Core_OptionGroup::getValue('mapping_type', $this->_mappingType, 'name')); $this->assign('savedMapping', $mappingArray); $this->add('select', 'savedMapping', ts('Mapping Option'), array('' => ts('- select -')) + $mappingArray); if ($loadedMapping = $this->get('loadedMapping')) { $this->assign('loadedMapping', $loadedMapping); $this->setDefaults(array('savedMapping' => $loadedMapping)); } $this->setDefaults(array('onDuplicate' => CRM_Import_Parser::DUPLICATE_SKIP)); if ($this->_enableContactOptions) { $this->addContactOptions(); } $this->setDefaults(array('contactType' => CRM_Import_Parser::CONTACT_INDIVIDUAL)); $this->addElement('text', 'fieldSeparator', ts('Import Field Separator'), array('size' => 2)); //build date formats CRM_Core_Form_Date::buildAllowedDateFormats($this); $this->addButtons(array(array('type' => 'upload', 'name' => ts('Continue >>'), 'spacing' => ' ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); }