2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
4 /*********************************************************************************
5 * SugarCRM Community Edition is a customer relationship management program developed by
6 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU Affero General Public License version 3 as published by the
10 * Free Software Foundation with the addition of the following permission added
11 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
12 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
13 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
20 * You should have received a copy of the GNU Affero General Public License along with
21 * this program; if not, see http://www.gnu.org/licenses or write to the Free
22 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
26 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
28 * The interactive user interfaces in modified source and object code versions
29 * of this program must display Appropriate Legal Notices, as required under
30 * Section 5 of the GNU Affero General Public License version 3.
32 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
33 * these Appropriate Legal Notices must retain the display of the "Powered by
34 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
35 * technical reasons, the Appropriate Legal Notices must display the words
36 * "Powered by SugarCRM".
37 ********************************************************************************/
39 /*********************************************************************************
41 * Description: Controller for the Import module
42 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
43 * All Rights Reserved.
44 ********************************************************************************/
46 require_once("modules/Import/Forms.php");
47 require_once("include/MVC/Controller/SugarController.php");
48 require_once('modules/Import/sources/ImportFile.php');
49 require_once('modules/Import/views/ImportListView.php');
51 class ImportController extends SugarController
54 * @see SugarController::loadBean()
56 public function loadBean()
60 $this->importModule = isset($_REQUEST['import_module']) ? $_REQUEST['import_module'] : '';
62 $this->bean = loadBean($this->importModule);
64 if ( !$this->bean->importable )
66 elseif ( $_REQUEST['import_module'] == 'Users' && !is_admin($GLOBALS['current_user']) )
68 elseif ( $this->bean->bean_implements('ACL')){
69 if(!ACLController::checkAccess($this->bean->module_dir, 'import', true)){
70 ACLController::displayNoAccess();
77 $_REQUEST['message'] = $mod_strings['LBL_ERROR_IMPORTS_NOT_SET_UP'];
78 $this->view = 'error';
81 $GLOBALS['FOCUS'] = $this->bean;
84 function action_index()
86 $this->action_Step1();
89 function action_mapping()
91 global $mod_strings, $current_user;
92 $results = array('message' => '');
93 // handle publishing and deleting import maps
94 if(isset($_REQUEST['delete_map_id']))
96 $import_map = new ImportMap();
97 $import_map->mark_deleted($_REQUEST['delete_map_id']);
100 if(isset($_REQUEST['publish']) )
102 $import_map = new ImportMap();
104 $import_map = $import_map->retrieve($_REQUEST['import_map_id'], false);
106 if($_REQUEST['publish'] == 'yes')
108 $result = $import_map->mark_published($current_user->id,true);
110 $results['message'] = $mod_strings['LBL_ERROR_UNABLE_TO_PUBLISH'];
112 elseif( $_REQUEST['publish'] == 'no')
114 // if you don't own this importmap, you do now, unless you have a map by the same name
115 $result = $import_map->mark_published($current_user->id,false);
117 $results['message'] = $mod_strings['LBL_ERROR_UNABLE_TO_UNPUBLISH'];
121 echo json_encode($results);
124 function action_RefreshMapping()
127 require_once('modules/Import/sources/ImportFile.php');
128 require_once('modules/Import/views/view.confirm.php');
129 $v = new ImportViewConfirm();
130 $fileName = $_REQUEST['importFile'];
131 $delim = $_REQUEST['delim'];
132 $enclosure = $_REQUEST['qualif'];
133 $enclosure = html_entity_decode($enclosure, ENT_QUOTES);
134 $hasHeader = isset($_REQUEST['header']) && !empty($_REQUEST['header']) ? TRUE : FALSE;
136 $importFile = new ImportFile( $fileName, $delim, $enclosure, FALSE);
137 $importFile->setHeaderRow($hasHeader);
138 $rows = $v->getSampleSet($importFile);
140 $ss = new Sugar_Smarty();
141 $ss->assign("SAMPLE_ROWS",$rows);
142 $ss->assign("HAS_HEADER",$hasHeader);
143 $ss->assign("column_count",$v->getMaxColumnsInSampleSet($rows));
144 $ss->assign("MOD",$mod_strings);
145 $ss->display('modules/Import/tpls/confirm_table.tpl');
150 function action_RefreshTable()
152 $offset = isset($_REQUEST['offset']) ? $_REQUEST['offset'] : 0;
153 $tableID = isset($_REQUEST['tableID']) ? $_REQUEST['tableID'] : 'errors';
154 $has_header = $_REQUEST['has_header'] == 'on' ? TRUE : FALSE;
155 if($tableID == 'dup')
156 $tableFilename = ImportCacheFiles::getDuplicateFileName();
158 $tableFilename = ImportCacheFiles::getErrorRecordsFileName();
160 $if = new ImportFile($tableFilename, ",", '"', FALSE, FALSE);
161 $if->setHeaderRow($has_header);
162 $lv = new ImportListView($if,array('offset'=> $offset), $tableID);
168 function action_Step1()
170 $fromAdminView = isset($_REQUEST['from_admin_wizard']) ? $_REQUEST['from_admin_wizard'] : FALSE;
171 if( $this->importModule == 'Administration' || $fromAdminView
174 $this->view = 'step1';
177 $this->view = 'step2';
180 function action_Step2()
182 $this->view = 'step2';
185 function action_Confirm()
187 $this->view = 'confirm';
190 function action_Step3()
192 $this->view = 'step3';
195 function action_DupCheck()
197 $this->view = 'dupcheck';
200 function action_Step4()
202 $this->view = 'step4';
205 function action_Last()
207 $this->view = 'last';
210 function action_Undo()
212 $this->view = 'undo';
215 function action_Error()
217 $this->view = 'error';
220 function action_ExtStep1()
222 $this->view = 'extStep1';
225 function action_Extdupcheck()
227 $this->view = 'extdupcheck';
230 function action_Extimport()
232 $this->view = 'extimport';
235 function action_GetControl()
237 echo getControl($_REQUEST['import_module'],$_REQUEST['field_name']);