]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Import/views/view.step1.php
Release 6.2.3
[Github/sugarcrm.git] / modules / Import / views / view.step1.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM Community Edition is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Affero General Public License version 3 as published by the
9  * Free Software Foundation with the addition of the following permission added
10  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
19  * You should have received a copy of the GNU Affero General Public License along with
20  * this program; if not, see http://www.gnu.org/licenses or write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
31  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32  * these Appropriate Legal Notices must retain the display of the "Powered by
33  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34  * technical reasons, the Appropriate Legal Notices must display the words
35  * "Powered by SugarCRM".
36  ********************************************************************************/
37
38 /*********************************************************************************
39
40  * Description: view handler for step 1 of the import process
41  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42  * All Rights Reserved.
43  ********************************************************************************/
44 require_once('include/MVC/View/SugarView.php');
45
46         
47 class ImportViewStep1 extends SugarView 
48 {       
49         /**
50      * @see SugarView::getMenu()
51      */
52     public function getMenu(
53         $module = null
54         )
55     {
56         global $mod_strings, $current_language;
57         
58         if ( empty($module) )
59             $module = $_REQUEST['import_module'];
60         
61         $old_mod_strings = $mod_strings;
62         $mod_strings = return_module_language($current_language, $module);
63         $returnMenu = parent::getMenu($module);
64         $mod_strings = $old_mod_strings;
65         
66         return $returnMenu;
67     }
68     
69         /**
70      * @see SugarView::_getModuleTab()
71      */
72         protected function _getModuleTab()
73     {
74         global $app_list_strings, $moduleTabMap;
75         
76                 // Need to figure out what tab this module belongs to, most modules have their own tabs, but there are exceptions.
77         if ( !empty($_REQUEST['module_tab']) )
78             return $_REQUEST['module_tab'];
79         elseif ( isset($moduleTabMap[$_REQUEST['import_module']]) )
80             return $moduleTabMap[$_REQUEST['import_module']];
81         // Default anonymous pages to be under Home
82         elseif ( !isset($app_list_strings['moduleList'][$_REQUEST['import_module']]) )
83             return 'Home';
84         else
85             return $_REQUEST['import_module'];
86         }
87         
88         /**
89          * @see SugarView::_getModuleTitleParams()
90          */
91         protected function _getModuleTitleParams($browserTitle = false)
92         {
93             global $mod_strings, $app_list_strings;
94             
95             $iconPath = $this->getModuleTitleIconPath($this->module);
96             $returnArray = array();
97             if (!empty($iconPath) && !$browserTitle) {
98                 $returnArray[] = "<a href='index.php?module={$_REQUEST['import_module']}&action=index'><img src='{$iconPath}' alt='{$app_list_strings['moduleList'][$_REQUEST['import_module']]}' title='{$app_list_strings['moduleList'][$_REQUEST['import_module']]}' align='absmiddle'></a>";
99         }
100         else {
101             $returnArray[] = $app_list_strings['moduleList'][$_REQUEST['import_module']];
102         }
103             $returnArray[] = "<a href='index.php?module=Import&action=Step1&import_module={$_REQUEST['import_module']}'>".$mod_strings['LBL_MODULE_NAME']."</a>";
104             $returnArray[] = $mod_strings['LBL_STEP_1_TITLE'];
105         
106             return $returnArray;
107     }
108         
109     private function _retrieveParams() {
110                 $selectedData = new stdClass();
111                 foreach ($_POST as $key => &$value) {
112                         trim(strip_tags($value));
113                         $selectedData->$key = $value;
114                 }
115                 if (isset($selectedData->custom_enclosure)) {                   
116                         if ($selectedData->custom_enclosure != '&quot;' and $selectedData->custom_enclosure != '&#039;' and $selectedData->custom_enclosure != '') {
117                                 $selectedData->custom_other = true; 
118                         }
119                 }
120                 $this->ss->assign('selectedData', $selectedData);
121                 return $selectedData;
122         }
123         
124         /** 
125      * @see SugarView::display()
126      */
127         public function display()
128     {
129         global $mod_strings, $app_strings, $current_user;
130         global $sugar_config;
131                 
132         $selectedData = $this->_retrieveParams();
133         
134         $this->ss->assign("MODULE_TITLE", $this->getModuleTitle());
135         $this->ss->assign("DELETE_INLINE_PNG",  SugarThemeRegistry::current()->getImage('delete_inline','align="absmiddle" alt="'.$app_strings['LNK_DELETE'].'" border="0"'));
136         $this->ss->assign("PUBLISH_INLINE_PNG",  SugarThemeRegistry::current()->getImage('publish_inline','align="absmiddle" alt="'.$mod_strings['LBL_PUBLISH'].'" border="0"'));
137         $this->ss->assign("UNPUBLISH_INLINE_PNG",  SugarThemeRegistry::current()->getImage('unpublish_inline','align="absmiddle" alt="'.$mod_strings['LBL_UNPUBLISH'].'" border="0"'));
138         $this->ss->assign("IMPORT_MODULE", $_REQUEST['import_module']);
139         $this->ss->assign("JAVASCRIPT", $this->_getJS(isset($selectedData->source) ? $selectedData->source : false));
140         
141         
142         // handle publishing and deleting import maps
143         if (isset($_REQUEST['delete_map_id'])) {
144             $import_map = new ImportMap();
145             $import_map->mark_deleted($_REQUEST['delete_map_id']);
146         }
147         
148         if (isset($_REQUEST['publish']) ) {
149             $import_map = new ImportMap();
150             $result = 0;
151         
152             $import_map = $import_map->retrieve($_REQUEST['import_map_id'], false);
153         
154             if ($_REQUEST['publish'] == 'yes') {
155                 $result = $import_map->mark_published($current_user->id,true);
156                 if (!$result) {
157                     $this->ss->assign("ERROR",$mod_strings['LBL_ERROR_UNABLE_TO_PUBLISH']);
158                 }
159             }
160             elseif ( $_REQUEST['publish'] == 'no') {
161                 // if you don't own this importmap, you do now!
162                 // unless you have a map by the same name
163                 $result = $import_map->mark_published($current_user->id,false);
164                 if (!$result) {
165                     $this->ss->assign("ERROR",$mod_strings['LBL_ERROR_UNABLE_TO_UNPUBLISH']);
166                 }
167             }
168         
169         }
170         
171         // trigger showing other software packages
172         $this->ss->assign("show_salesforce",false);
173         $this->ss->assign("show_outlook",false);
174         $this->ss->assign("show_act",false);
175         switch ($_REQUEST['import_module']) {
176             case "Prospects":
177                 break;
178             case "Accounts":
179                 $this->ss->assign("show_salesforce",true);
180                 $this->ss->assign("show_act",true);
181                 break;
182             case "Contacts":
183                 $this->ss->assign("show_salesforce",true);
184                 $this->ss->assign("show_outlook",true);
185                 $this->ss->assign("show_act",true);
186                 break;
187             default:
188                 $this->ss->assign("show_salesforce",true);
189                 break;
190         }
191         
192         // show any custom mappings
193         if (sugar_is_dir('custom/modules/Import') && $dir = opendir('custom/modules/Import')) 
194         {
195             while (($file = readdir($dir)) !== false) 
196             {
197                 if (sugar_is_file("custom/modules/Import/{$file}") && strpos($file,".php") !== false)
198                 {
199                         require_once("custom/modules/Import/{$file}");
200                         $classname = str_replace('.php','',$file);
201                         $mappingClass = new $classname;
202                         $custom_mappings[] = $mappingClass->name;
203                 }
204             }
205         }
206         
207         
208         // get user defined import maps
209         $this->ss->assign('is_admin',is_admin($current_user));
210         $import_map_seed = new ImportMap();
211         $custom_imports_arr = $import_map_seed->retrieve_all_by_string_fields(
212             array(
213                 'assigned_user_id' => $current_user->id,
214                 'is_published'     => 'no',
215                 'module'           => $_REQUEST['import_module'],
216                 )
217             );
218         
219         if ( count($custom_imports_arr) ) {
220             $custom = array();
221             foreach ( $custom_imports_arr as $import) {
222                 $custom[] = array(
223                     "IMPORT_NAME" => $import->name,
224                     "IMPORT_ID"   => $import->id,
225                     );
226             }
227             $this->ss->assign('custom_imports',$custom);
228         }
229         
230         // get globally defined import maps
231         $published_imports_arr = $import_map_seed->retrieve_all_by_string_fields(
232             array(
233                 'is_published' => 'yes',
234                 'module'       => $_REQUEST['import_module'],
235                 )
236             );
237         
238         if ( count($published_imports_arr) ) {
239             $published = array();
240             foreach ( $published_imports_arr as $import) {
241                 $published[] = array(
242                     "IMPORT_NAME" => $import->name,
243                     "IMPORT_ID"   => $import->id,
244                     );
245             }
246             $this->ss->assign('published_imports',$published);
247         }
248         
249         $this->ss->display('modules/Import/tpls/step1.tpl');
250     }
251     
252     /**
253      * Returns JS used in this view
254      */
255     private function _getJS($sourceType = false)
256     {
257         global $mod_strings;
258                 
259         if (!$sourceType) {
260                 $sourceType = 'csv';
261         }
262         $getElementById = "document.getElementById('source_{$sourceType}')";
263         $sourceType = "defineEnclosureSelectPosition('{$sourceType}', {$getElementById});";
264         
265         return <<<EOJAVASCRIPT
266 <script type="text/javascript">
267 <!--
268 document.getElementById('custom_enclosure').onchange = function()
269 {
270     document.getElementById('importstep1').custom_enclosure_other.style.display = ( this.value == 'other' ? '' : 'none' );
271 }
272
273 document.getElementById('gonext').onclick = function()
274 {
275     clear_all_errors();
276     var sourceSelected = false;
277     var typeSelected = false;
278     var isError = false;
279     var inputs = document.getElementsByTagName('input');
280     for (var i = 0; i < inputs.length; ++i ){ 
281         if ( !sourceSelected && inputs[i].name == 'source' ){
282             if (inputs[i].checked) {
283                 sourceSelected = true;
284                 if ( inputs[i].value == 'other' && document.getElementById('importstep1').custom_delimiter.value == '' ) {
285                     add_error_style('importstep1','custom_delimiter',"{$mod_strings['ERR_MISSING_REQUIRED_FIELDS']} {$mod_strings['LBL_CUSTOM_DELIMITER']}");
286                     isError = true;
287                 }
288             }
289         }
290         if ( !typeSelected && inputs[i].name == 'type' ){
291             if (inputs[i].checked) {
292                 typeSelected = true;
293             }
294         }
295     }
296     if ( !sourceSelected ) {
297         add_error_style('importstep1','source\'][\'' + (document.getElementById('importstep1').source.length - 1) + '',"{$mod_strings['ERR_MISSING_REQUIRED_FIELDS']} {$mod_strings['LBL_WHAT_IS']}");
298         isError = true;
299     }
300     if ( !typeSelected ) {
301         add_error_style('importstep1','type\'][\'1',"{$mod_strings['ERR_MISSING_REQUIRED_FIELDS']} {$mod_strings['LBL_IMPORT_TYPE']}");
302         isError = true;
303     }
304     return !isError;
305 }
306
307 YAHOO.util.Event.onDOMReady(function()
308
309     var defineEnclosureSelectPosition = function(sourceType, inputElement) 
310             {
311                 if (typeof (sourceType) == 'undefined') {
312                         sourceType = this.value;
313                 }
314                 parentRow = inputElement.parentNode.parentNode;
315                 switch(sourceType) {
316                 case 'other':
317                     enclosureRow = document.getElementById('customEnclosure').parentNode.removeChild(document.getElementById('customEnclosure'));
318                     parentRow.parentNode.insertBefore(enclosureRow, document.getElementById('customDelimiter').nextSibling);
319                     document.getElementById('customDelimiter').style.display = '';
320                     document.getElementById('customEnclosure').style.display = '';
321                     break;
322                 case 'tab': case 'csv':
323                     enclosureRow = document.getElementById('customEnclosure').parentNode.removeChild(document.getElementById('customEnclosure'));
324                     parentRow.parentNode.insertBefore(enclosureRow, parentRow.nextSibling);
325                     document.getElementById('customDelimiter').style.display = 'none';
326                     document.getElementById('customEnclosure').style.display = '';
327                     break;
328                 default:
329                     document.getElementById('customDelimiter').style.display = 'none';
330                     document.getElementById('customEnclosure').style.display = 'none';
331                 }
332             }
333
334     var inputs = document.getElementsByTagName('input');
335     for (var i = 0; i < inputs.length; ++i ){ 
336         if (inputs[i].name == 'source' ) {
337             inputs[i].onclick = function () {
338                 defineEnclosureSelectPosition(this.value, this);
339           }
340         }
341     }
342         {$sourceType}
343 });
344 -->
345 </script>
346
347 EOJAVASCRIPT;
348     }
349 }
350
351 ?>