_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE); if ($this->_id) { $params = "reset=1&id={$this->_id}"; } else { $params = "reset=1"; } $session->pushUserContext(CRM_Utils_System::url('civicrm/import/custom', $params)); // check for post max size CRM_Core_Config_Defaults::formatUnitSize(ini_get('post_max_size'), TRUE); } /** * @return array */ public function setDefaultValues() { $config = CRM_Core_Config::singleton(); $defaults = array( 'contactType' => CRM_Import_Parser::CONTACT_INDIVIDUAL, 'fieldSeparator' => $config->fieldSeparator, 'multipleCustomData' => $this->_id, ); if ($loadeMapping = $this->get('loadedMapping')) { $this->assign('loadedMapping', $loadeMapping); $defaults['savedMapping'] = $loadeMapping; } return $defaults; } /** * Build the form object. * * @return void */ public function buildQuickForm() { $multipleCustomData = CRM_Core_BAO_CustomGroup::getMultipleFieldGroup(); $this->add('select', 'multipleCustomData', ts('Multi-value Custom Data'), array('' => ts('- select -')) + $multipleCustomData, TRUE); //Setting Upload File Size $config = CRM_Core_Config::singleton(); $uploadFileSize = CRM_Core_Config_Defaults::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')); //get the saved mapping details $mappingArray = CRM_Core_BAO_Mapping::getMappings(CRM_Core_OptionGroup::getValue('mapping_type', 'Import Multi value custom data', 'name' )); $this->assign('savedMapping', $mappingArray); $this->add('select', 'savedMapping', ts('Mapping Option'), array('' => ts('- select -')) + $mappingArray); if ($loadeMapping = $this->get('loadedMapping')) { $this->assign('loadedMapping', $loadeMapping); $this->setDefaults(array('savedMapping' => $loadeMapping)); } //contact types option $contactOptions = array(); if (CRM_Contact_BAO_ContactType::isActive('Individual')) { $contactOptions[] = $this->createElement('radio', NULL, NULL, ts('Individual'), CRM_Import_Parser::CONTACT_INDIVIDUAL ); } if (CRM_Contact_BAO_ContactType::isActive('Household')) { $contactOptions[] = $this->createElement('radio', NULL, NULL, ts('Household'), CRM_Import_Parser::CONTACT_HOUSEHOLD ); } if (CRM_Contact_BAO_ContactType::isActive('Organization')) { $contactOptions[] = $this->createElement('radio', NULL, NULL, ts('Organization'), CRM_Import_Parser::CONTACT_ORGANIZATION ); } $this->addGroup($contactOptions, 'contactType', ts('Contact Type') ); $this->setDefaults(array( 'contactType' => CRM_Import_Parser::CONTACT_INDIVIDUAL, )); //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'), ), ) ); } /** * Process the uploaded file. * * @return void */ public function postProcess() { $this->controller->resetPage('MapField'); $fileName = $this->controller->exportValue($this->_name, 'uploadFile'); $skipColumnHeader = $this->controller->exportValue($this->_name, 'skipColumnHeader'); $contactType = $this->controller->exportValue($this->_name, 'contactType'); $dateFormats = $this->controller->exportValue($this->_name, 'dateFormats'); $savedMapping = $this->controller->exportValue($this->_name, 'savedMapping'); $multipleCustomData = $this->controller->exportValue($this->_name, 'multipleCustomData'); $this->set('contactType', $contactType); $this->set('dateFormats', $dateFormats); $this->set('savedMapping', $savedMapping); $this->set('multipleCustomData', $multipleCustomData); $session = CRM_Core_Session::singleton(); $session->set("dateTypes", $dateFormats); $config = CRM_Core_Config::singleton(); $seperator = $config->fieldSeparator; $mapper = array(); $parser = new CRM_Custom_Import_Parser_Api($mapper); $parser->setEntity($multipleCustomData); $parser->setMaxLinesToProcess(100); $parser->run($fileName, $seperator, $mapper, $skipColumnHeader, CRM_Import_Parser::MODE_MAPFIELD, $contactType ); // add all the necessary variables to the form $parser->set($this); } /** * Return a descriptive name for the page, used in wizard header * * @return string */ public function getTitle() { return ts('Upload Data'); } }