]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Import/views/view.step1.php
Release 6.2.0
[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         /** 
110      * @see SugarView::display()
111      */
112         public function display()
113     {
114         global $mod_strings, $app_strings, $current_user;
115         global $sugar_config;
116         
117         $this->ss->assign("MODULE_TITLE", $this->getModuleTitle());
118         $this->ss->assign("DELETE_INLINE_PNG",  SugarThemeRegistry::current()->getImage('delete_inline','align="absmiddle" alt="'.$app_strings['LNK_DELETE'].'" border="0"'));
119         $this->ss->assign("PUBLISH_INLINE_PNG",  SugarThemeRegistry::current()->getImage('publish_inline','align="absmiddle" alt="'.$mod_strings['LBL_PUBLISH'].'" border="0"'));
120         $this->ss->assign("UNPUBLISH_INLINE_PNG",  SugarThemeRegistry::current()->getImage('unpublish_inline','align="absmiddle" alt="'.$mod_strings['LBL_UNPUBLISH'].'" border="0"'));
121         $this->ss->assign("IMPORT_MODULE", $_REQUEST['import_module']);
122         $this->ss->assign("JAVASCRIPT", $this->_getJS());
123         
124         
125         // handle publishing and deleting import maps
126         if (isset($_REQUEST['delete_map_id'])) {
127             $import_map = new ImportMap();
128             $import_map->mark_deleted($_REQUEST['delete_map_id']);
129         }
130         
131         if (isset($_REQUEST['publish']) ) {
132             $import_map = new ImportMap();
133             $result = 0;
134         
135             $import_map = $import_map->retrieve($_REQUEST['import_map_id'], false);
136         
137             if ($_REQUEST['publish'] == 'yes') {
138                 $result = $import_map->mark_published($current_user->id,true);
139                 if (!$result) {
140                     $this->ss->assign("ERROR",$mod_strings['LBL_ERROR_UNABLE_TO_PUBLISH']);
141                 }
142             }
143             elseif ( $_REQUEST['publish'] == 'no') {
144                 // if you don't own this importmap, you do now!
145                 // unless you have a map by the same name
146                 $result = $import_map->mark_published($current_user->id,false);
147                 if (!$result) {
148                     $this->ss->assign("ERROR",$mod_strings['LBL_ERROR_UNABLE_TO_UNPUBLISH']);
149                 }
150             }
151         
152         }
153         
154         // trigger showing other software packages
155         $this->ss->assign("show_salesforce",false);
156         $this->ss->assign("show_outlook",false);
157         $this->ss->assign("show_act",false);
158         switch ($_REQUEST['import_module']) {
159             case "Prospects":
160                 break;
161             case "Accounts":
162                 $this->ss->assign("show_salesforce",true);
163                 $this->ss->assign("show_act",true);
164                 break;
165             case "Contacts":
166                 $this->ss->assign("show_salesforce",true);
167                 $this->ss->assign("show_outlook",true);
168                 $this->ss->assign("show_act",true);
169                 break;
170             default:
171                 $this->ss->assign("show_salesforce",true);
172                 break;
173         }
174         
175         // show any custom mappings
176         if (sugar_is_dir('custom/modules/Import') && $dir = opendir('custom/modules/Import')) 
177         {
178             while (($file = readdir($dir)) !== false) 
179             {
180                 if (sugar_is_file("custom/modules/Import/{$file}") && strpos($file,".php") !== false)
181                 {
182                         require_once("custom/modules/Import/{$file}");
183                         $classname = str_replace('.php','',$file);
184                         $mappingClass = new $classname;
185                         $custom_mappings[] = $mappingClass->name;
186                 }
187             }
188         }
189         
190         
191         // get user defined import maps
192         $this->ss->assign('is_admin',is_admin($current_user));
193         $import_map_seed = new ImportMap();
194         $custom_imports_arr = $import_map_seed->retrieve_all_by_string_fields(
195             array(
196                 'assigned_user_id' => $current_user->id,
197                 'is_published'     => 'no',
198                 'module'           => $_REQUEST['import_module'],
199                 )
200             );
201         
202         if ( count($custom_imports_arr) ) {
203             $custom = array();
204             foreach ( $custom_imports_arr as $import) {
205                 $custom[] = array(
206                     "IMPORT_NAME" => $import->name,
207                     "IMPORT_ID"   => $import->id,
208                     );
209             }
210             $this->ss->assign('custom_imports',$custom);
211         }
212         
213         // get globally defined import maps
214         $published_imports_arr = $import_map_seed->retrieve_all_by_string_fields(
215             array(
216                 'is_published' => 'yes',
217                 'module'       => $_REQUEST['import_module'],
218                 )
219             );
220         
221         if ( count($published_imports_arr) ) {
222             $published = array();
223             foreach ( $published_imports_arr as $import) {
224                 $published[] = array(
225                     "IMPORT_NAME" => $import->name,
226                     "IMPORT_ID"   => $import->id,
227                     );
228             }
229             $this->ss->assign('published_imports',$published);
230         }
231         
232         $this->ss->display('modules/Import/tpls/step1.tpl');
233     }
234     
235     /**
236      * Returns JS used in this view
237      */
238     private function _getJS()
239     {
240         global $mod_strings;
241         
242         return <<<EOJAVASCRIPT
243 <script type="text/javascript">
244 <!--
245 document.getElementById('custom_enclosure').onchange = function()
246 {
247     document.getElementById('importstep1').custom_enclosure_other.style.display = ( this.value == 'other' ? '' : 'none' );
248 }
249
250 document.getElementById('gonext').onclick = function()
251 {
252     clear_all_errors();
253     var sourceSelected = false;
254     var typeSelected = false;
255     var isError = false;
256     var inputs = document.getElementsByTagName('input');
257     for (var i = 0; i < inputs.length; ++i ){ 
258         if ( !sourceSelected && inputs[i].name == 'source' ){
259             if (inputs[i].checked) {
260                 sourceSelected = true;
261                 if ( inputs[i].value == 'other' && document.getElementById('importstep1').custom_delimiter.value == '' ) {
262                     add_error_style('importstep1','custom_delimiter',"{$mod_strings['ERR_MISSING_REQUIRED_FIELDS']} {$mod_strings['LBL_CUSTOM_DELIMITER']}");
263                     isError = true;
264                 }
265             }
266         }
267         if ( !typeSelected && inputs[i].name == 'type' ){
268             if (inputs[i].checked) {
269                 typeSelected = true;
270             }
271         }
272     }
273     if ( !sourceSelected ) {
274         add_error_style('importstep1','source\'][\'' + (document.getElementById('importstep1').source.length - 1) + '',"{$mod_strings['ERR_MISSING_REQUIRED_FIELDS']} {$mod_strings['LBL_WHAT_IS']}");
275         isError = true;
276     }
277     if ( !typeSelected ) {
278         add_error_style('importstep1','type\'][\'1',"{$mod_strings['ERR_MISSING_REQUIRED_FIELDS']} {$mod_strings['LBL_IMPORT_TYPE']}");
279         isError = true;
280     }
281     return !isError;
282 }
283
284 YAHOO.util.Event.onDOMReady(function()
285
286     var inputs = document.getElementsByTagName('input');
287     for (var i = 0; i < inputs.length; ++i ){ 
288         if (inputs[i].name == 'source' ) {
289             inputs[i].onclick = function() 
290             {
291                 parentRow = this.parentNode.parentNode;
292                 switch(this.value) {
293                 case 'other':
294                     enclosureRow = document.getElementById('customEnclosure').parentNode.removeChild(document.getElementById('customEnclosure'));
295                     parentRow.parentNode.insertBefore(enclosureRow, document.getElementById('customDelimiter').nextSibling);
296                     document.getElementById('customDelimiter').style.display = '';
297                     document.getElementById('customEnclosure').style.display = '';
298                     break;
299                 case 'tab': case 'csv':
300                     enclosureRow = document.getElementById('customEnclosure').parentNode.removeChild(document.getElementById('customEnclosure'));
301                     parentRow.parentNode.insertBefore(enclosureRow, parentRow.nextSibling);
302                     document.getElementById('customDelimiter').style.display = 'none';
303                     document.getElementById('customEnclosure').style.display = '';
304                     break;
305                 default:
306                     document.getElementById('customDelimiter').style.display = 'none';
307                     document.getElementById('customEnclosure').style.display = 'none';
308                 }
309             }
310         }
311     }
312 });
313 -->
314 </script>
315
316 EOJAVASCRIPT;
317     }
318 }
319
320 ?>