3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2013
37 * This class gets the name of the file to upload
39 class CRM_Activity_Import_Form_UploadFile
extends CRM_Core_Form
{
42 * Function to set variables up before form is built
47 public function preProcess() {
48 $session = CRM_Core_Session
::singleton();
49 $session->pushUserContext(CRM_Utils_System
::url('civicrm/import/activity', 'reset=1'));
53 * Function to actually build the form
58 public function buildQuickForm() {
59 //Setting Upload File Size
60 $config = CRM_Core_Config
::singleton();
61 if ($config->maxImportFileSize
>= 8388608) {
62 $uploadFileSize = 8388608;
65 $uploadFileSize = $config->maxImportFileSize
;
67 $uploadSize = round(($uploadFileSize / (1024 * 1024)), 2);
69 $this->assign('uploadSize', $uploadSize);
71 $this->add('file', 'uploadFile', ts('Import Data File'), 'size=30 maxlength=255', TRUE);
73 $this->addRule('uploadFile', ts('A valid file must be uploaded.'), 'uploadedfile');
74 $this->addRule('uploadFile', ts('File size should be less than %1 MBytes (%2 bytes)', array(1 => $uploadSize, 2 => $uploadFileSize)), 'maxfilesize', $uploadFileSize);
75 $this->setMaxFileSize($uploadFileSize);
76 $this->addRule('uploadFile', ts('Input file must be in CSV format'), 'utf8File');
78 $this->addElement('checkbox', 'skipColumnHeader', ts('First row contains column headers'));
80 $duplicateOptions = array();
81 $duplicateOptions[] = $this->createElement('radio',
82 NULL, NULL, ts('Skip'), CRM_Activity_Import_Parser
::DUPLICATE_SKIP
84 $duplicateOptions[] = $this->createElement('radio',
85 NULL, NULL, ts('Update'), CRM_Activity_Import_Parser
::DUPLICATE_UPDATE
87 $duplicateOptions[] = $this->createElement('radio',
88 NULL, NULL, ts('Fill'), CRM_Activity_Import_Parser
::DUPLICATE_FILL
91 $this->addGroup($duplicateOptions, 'onDuplicate',
92 ts('On duplicate entries')
95 //get the saved mapping details
96 $mappingArray = CRM_Core_BAO_Mapping
::getMappings(CRM_Core_OptionGroup
::getValue('mapping_type',
100 $this->assign('savedMapping', $mappingArray);
101 $this->add('select', 'savedMapping', ts('Mapping Option'), array('' => ts('- select -')) +
$mappingArray);
103 if ($loadeMapping = $this->get('loadedMapping')) {
104 $this->assign('loadedMapping', $loadeMapping);
105 $this->setDefaults(array('savedMapping' => $loadeMapping));
108 $this->setDefaults(array(
110 CRM_Activity_Import_Parser
::DUPLICATE_SKIP
,
114 CRM_Core_Form_Date
::buildAllowedDateFormats($this);
116 $this->addButtons(array(
119 'name' => ts('Continue >>'),
120 'spacing' => ' ',
125 'name' => ts('Cancel'),
132 * Process the uploaded file
137 public function postProcess() {
138 $this->controller
->resetPage('MapField');
140 $fileName = $this->controller
->exportValue($this->_name
, 'uploadFile');
141 $skipColumnHeader = $this->controller
->exportValue($this->_name
, 'skipColumnHeader');
142 $onDuplicate = $this->controller
->exportValue($this->_name
, 'onDuplicate');
143 $dateFormats = $this->controller
->exportValue($this->_name
, 'dateFormats');
144 $savedMapping = $this->controller
->exportValue($this->_name
, 'savedMapping');
146 $this->set('onDuplicate', $onDuplicate);
147 $this->set('dateFormats', $dateFormats);
148 $this->set('savedMapping', $savedMapping);
150 $session = CRM_Core_Session
::singleton();
151 $session->set("dateTypes", $dateFormats);
153 $config = CRM_Core_Config
::singleton();
154 $seperator = $config->fieldSeparator
;
158 $parser = new CRM_Activity_Import_Parser_Activity($mapper);
159 $parser->setMaxLinesToProcess(100);
160 $parser->run($fileName, $seperator,
163 CRM_Activity_Import_Parser
::MODE_MAPFIELD
166 // add all the necessary variables to the form
171 * Return a descriptive name for the page, used in wizard header
176 public function getTitle() {
177 return ts('Upload Data');