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-2012 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 if ($delim == '\t') {
135 $enclosure = $_REQUEST['qualif'];
136 $enclosure = html_entity_decode($enclosure, ENT_QUOTES);
137 $hasHeader = isset($_REQUEST['header']) && !empty($_REQUEST['header']) ? TRUE : FALSE;
139 $importFile = new ImportFile( $fileName, $delim, $enclosure, FALSE);
140 $importFile->setHeaderRow($hasHeader);
141 $rows = $v->getSampleSet($importFile);
143 $ss = new Sugar_Smarty();
144 $ss->assign("SAMPLE_ROWS",$rows);
145 $ss->assign("HAS_HEADER",$hasHeader);
146 $ss->assign("column_count",$v->getMaxColumnsInSampleSet($rows));
147 $ss->assign("MOD",$mod_strings);
148 $ss->display('modules/Import/tpls/confirm_table.tpl');
153 function action_RefreshTable()
155 $offset = isset($_REQUEST['offset']) ? $_REQUEST['offset'] : 0;
156 $tableID = isset($_REQUEST['tableID']) ? $_REQUEST['tableID'] : 'errors';
157 $has_header = $_REQUEST['has_header'] == 'on' ? TRUE : FALSE;
158 if($tableID == 'dup')
159 $tableFilename = ImportCacheFiles::getDuplicateFileName();
161 $tableFilename = ImportCacheFiles::getErrorRecordsFileName();
163 $if = new ImportFile($tableFilename, ",", '"', FALSE, FALSE);
164 $if->setHeaderRow($has_header);
165 $lv = new ImportListView($if,array('offset'=> $offset), $tableID);
171 function action_Step1()
173 $fromAdminView = isset($_REQUEST['from_admin_wizard']) ? $_REQUEST['from_admin_wizard'] : FALSE;
174 if( $this->importModule == 'Administration' || $fromAdminView
177 $this->view = 'step1';
180 $this->view = 'step2';
183 function action_Step2()
185 $this->view = 'step2';
188 function action_Confirm()
190 $this->view = 'confirm';
193 function action_Step3()
195 $this->view = 'step3';
198 function action_DupCheck()
200 $this->view = 'dupcheck';
203 function action_Step4()
205 $this->view = 'step4';
208 function action_Last()
210 $this->view = 'last';
213 function action_Undo()
215 $this->view = 'undo';
218 function action_Error()
220 $this->view = 'error';
223 function action_ExtStep1()
225 $this->view = 'extStep1';
228 function action_Extdupcheck()
230 $this->view = 'extdupcheck';
233 function action_Extimport()
235 $this->view = 'extimport';
238 function action_GetControl()
240 echo getControl($_REQUEST['import_module'],$_REQUEST['field_name']);