]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Import/controller.php
Release 6.5.0
[Github/sugarcrm.git] / modules / Import / controller.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3
4 /*********************************************************************************
5  * SugarCRM Community Edition is a customer relationship management program developed by
6  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
7  * 
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.
14  * 
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
18  * details.
19  * 
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
23  * 02110-1301 USA.
24  * 
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.
27  * 
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.
31  * 
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  ********************************************************************************/
38
39 /*********************************************************************************
40
41  * Description: Controller for the Import module
42  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
43  * All Rights Reserved.
44  ********************************************************************************/
45
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');
50
51 class ImportController extends SugarController
52 {
53     /**
54      * @see SugarController::loadBean()
55      */
56     public function loadBean()
57     {
58         global $mod_strings;
59
60         $this->importModule = isset($_REQUEST['import_module']) ? $_REQUEST['import_module'] : '';
61
62         $this->bean = loadBean($this->importModule);
63         if ( $this->bean ) {
64             if ( !$this->bean->importable )
65                 $this->bean = false;
66             elseif ( $_REQUEST['import_module'] == 'Users' && !is_admin($GLOBALS['current_user']) )
67                 $this->bean = false;
68             elseif ( $this->bean->bean_implements('ACL')){
69                 if(!ACLController::checkAccess($this->bean->module_dir, 'import', true)){
70                     ACLController::displayNoAccess();
71                     sugar_die('');
72                 }
73             }
74         }
75         
76         if ( !$this->bean ) {
77             $_REQUEST['message'] = $mod_strings['LBL_ERROR_IMPORTS_NOT_SET_UP'];
78             $this->view = 'error';
79         }
80         else
81             $GLOBALS['FOCUS'] = $this->bean;
82     }
83     
84     function action_index()
85     {
86         $this->action_Step1();
87     }
88
89     function action_mapping()
90     {
91         global $mod_strings, $current_user;
92         $results = array('message' => '');
93         // handle publishing and deleting import maps
94         if(isset($_REQUEST['delete_map_id']))
95         {
96             $import_map = new ImportMap();
97             $import_map->mark_deleted($_REQUEST['delete_map_id']);
98         }
99
100         if(isset($_REQUEST['publish']) )
101         {
102             $import_map = new ImportMap();
103
104             $import_map = $import_map->retrieve($_REQUEST['import_map_id'], false);
105
106             if($_REQUEST['publish'] == 'yes')
107             {
108                 $result = $import_map->mark_published($current_user->id,true);
109                 if (!$result)
110                     $results['message'] = $mod_strings['LBL_ERROR_UNABLE_TO_PUBLISH'];
111             }
112             elseif( $_REQUEST['publish'] == 'no')
113             {
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);
116                 if (!$result)
117                     $results['message'] = $mod_strings['LBL_ERROR_UNABLE_TO_UNPUBLISH'];
118             }
119         }
120         
121         echo json_encode($results);
122         sugar_cleanup(TRUE);
123     }
124     function action_RefreshMapping()
125     {
126         global $mod_strings;
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') {
133             $delim = "\t";
134         }
135         $enclosure = $_REQUEST['qualif'];
136         $enclosure = html_entity_decode($enclosure, ENT_QUOTES);
137         $hasHeader = isset($_REQUEST['header']) && !empty($_REQUEST['header']) ? TRUE : FALSE;
138
139         $importFile = new ImportFile( $fileName, $delim, $enclosure, FALSE);
140         $importFile->setHeaderRow($hasHeader);
141         $rows = $v->getSampleSet($importFile);
142
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');
149         sugar_cleanup(TRUE);
150
151     }
152
153     function action_RefreshTable()
154     {
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();
160         else
161             $tableFilename = ImportCacheFiles::getErrorRecordsFileName();
162
163         $if = new ImportFile($tableFilename, ",", '"', FALSE, FALSE);
164         $if->setHeaderRow($has_header);
165         $lv = new ImportListView($if,array('offset'=> $offset), $tableID);
166         $lv->display(FALSE);
167         
168         sugar_cleanup(TRUE);
169     }
170     
171         function action_Step1()
172     {
173         $fromAdminView = isset($_REQUEST['from_admin_wizard']) ? $_REQUEST['from_admin_wizard'] : FALSE;
174         if( $this->importModule == 'Administration' || $fromAdminView
175         )
176         {
177                 $this->view = 'step1';
178         }
179         else
180             $this->view = 'step2';
181     }
182     
183     function action_Step2()
184     {
185                 $this->view = 'step2';
186     }
187
188     function action_Confirm()
189     {
190                 $this->view = 'confirm';
191     }
192
193     function action_Step3()
194     {
195                 $this->view = 'step3';
196     }
197
198     function action_DupCheck()
199     {
200                 $this->view = 'dupcheck';
201     }
202
203     function action_Step4()
204     {
205                 $this->view = 'step4';
206     }
207     
208     function action_Last()
209     {
210                 $this->view = 'last';
211     }
212     
213     function action_Undo()
214     {
215                 $this->view = 'undo';
216     }
217     
218     function action_Error()
219     {
220                 $this->view = 'error';
221     }
222
223     function action_ExtStep1()
224     {
225         $this->view = 'extStep1';
226     }
227
228     function action_Extdupcheck()
229     {
230         $this->view = 'extdupcheck';
231     }
232
233     function action_Extimport()
234     {
235         $this->view = 'extimport';
236     }
237     
238     function action_GetControl()
239     {
240         echo getControl($_REQUEST['import_module'],$_REQUEST['field_name']);
241         exit;
242     }
243 }
244 ?>