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