]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Import/views/view.step1.php
Release 6.2.0beta4
[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($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             while (($file = readdir('custom/modules/Import')) !== false) {
178                 if ($file == ".." 
179                         || $file == "."
180                         || $file == ".svn"
181                         || $file == "CVS" 
182                         || $file == "Attic"
183                         || !sugar_is_dir("./$dirPath".$file)
184                         || sugar_is_file("modules/Import/{$file}")
185                         )
186                     continue;
187                 require_once("custom/modules/Import/{$file}");
188                 $classname = str_replace('.php','',$file);
189                 $mappingClass = new $classname;
190                 $custom_mappings[] = $mappingClass->name;
191             }
192         }
193         
194         
195         // get user defined import maps
196         $this->ss->assign('is_admin',is_admin($current_user));
197         $import_map_seed = new ImportMap();
198         $custom_imports_arr = $import_map_seed->retrieve_all_by_string_fields(
199             array(
200                 'assigned_user_id' => $current_user->id,
201                 'is_published'     => 'no',
202                 'module'           => $_REQUEST['import_module'],
203                 )
204             );
205         
206         if ( count($custom_imports_arr) ) {
207             $custom = array();
208             foreach ( $custom_imports_arr as $import) {
209                 $custom[] = array(
210                     "IMPORT_NAME" => $import->name,
211                     "IMPORT_ID"   => $import->id,
212                     );
213             }
214             $this->ss->assign('custom_imports',$custom);
215         }
216         
217         // get globally defined import maps
218         $published_imports_arr = $import_map_seed->retrieve_all_by_string_fields(
219             array(
220                 'is_published' => 'yes',
221                 'module'       => $_REQUEST['import_module'],
222                 )
223             );
224         
225         if ( count($published_imports_arr) ) {
226             $published = array();
227             foreach ( $published_imports_arr as $import) {
228                 $published[] = array(
229                     "IMPORT_NAME" => $import->name,
230                     "IMPORT_ID"   => $import->id,
231                     );
232             }
233             $this->ss->assign('published_imports',$published);
234         }
235         
236         $this->ss->display('modules/Import/tpls/step1.tpl');
237     }
238     
239     /**
240      * Returns JS used in this view
241      */
242     private function _getJS()
243     {
244         global $mod_strings;
245         
246         return <<<EOJAVASCRIPT
247 <script type="text/javascript">
248 <!--
249 document.getElementById('custom_enclosure').onchange = function()
250 {
251     document.getElementById('importstep1').custom_enclosure_other.style.display = ( this.value == 'other' ? '' : 'none' );
252 }
253
254 document.getElementById('gonext').onclick = function()
255 {
256     clear_all_errors();
257     var sourceSelected = false;
258     var typeSelected = false;
259     var isError = false;
260     var inputs = document.getElementsByTagName('input');
261     for (var i = 0; i < inputs.length; ++i ){ 
262         if ( !sourceSelected && inputs[i].name == 'source' ){
263             if (inputs[i].checked) {
264                 sourceSelected = true;
265                 if ( inputs[i].value == 'other' && document.getElementById('importstep1').custom_delimiter.value == '' ) {
266                     add_error_style('importstep1','custom_delimiter',"{$mod_strings['ERR_MISSING_REQUIRED_FIELDS']} {$mod_strings['LBL_CUSTOM_DELIMITER']}");
267                     isError = true;
268                 }
269             }
270         }
271         if ( !typeSelected && inputs[i].name == 'type' ){
272             if (inputs[i].checked) {
273                 typeSelected = true;
274             }
275         }
276     }
277     if ( !sourceSelected ) {
278         add_error_style('importstep1','source\'][\'' + (document.getElementById('importstep1').source.length - 1) + '',"{$mod_strings['ERR_MISSING_REQUIRED_FIELDS']} {$mod_strings['LBL_WHAT_IS']}");
279         isError = true;
280     }
281     if ( !typeSelected ) {
282         add_error_style('importstep1','type\'][\'1',"{$mod_strings['ERR_MISSING_REQUIRED_FIELDS']} {$mod_strings['LBL_IMPORT_TYPE']}");
283         isError = true;
284     }
285     return !isError;
286 }
287
288 YAHOO.util.Event.onDOMReady(function()
289
290     var inputs = document.getElementsByTagName('input');
291     for (var i = 0; i < inputs.length; ++i ){ 
292         if (inputs[i].name == 'source' ) {
293             inputs[i].onclick = function() 
294             {
295                 parentRow = this.parentNode.parentNode;
296                 switch(this.value) {
297                 case 'other':
298                     enclosureRow = document.getElementById('customEnclosure').parentNode.removeChild(document.getElementById('customEnclosure'));
299                     parentRow.parentNode.insertBefore(enclosureRow, document.getElementById('customDelimiter').nextSibling);
300                     document.getElementById('customDelimiter').style.display = '';
301                     document.getElementById('customEnclosure').style.display = '';
302                     break;
303                 case 'tab': case 'csv':
304                     enclosureRow = document.getElementById('customEnclosure').parentNode.removeChild(document.getElementById('customEnclosure'));
305                     parentRow.parentNode.insertBefore(enclosureRow, parentRow.nextSibling);
306                     document.getElementById('customDelimiter').style.display = 'none';
307                     document.getElementById('customEnclosure').style.display = '';
308                     break;
309                 default:
310                     document.getElementById('customDelimiter').style.display = 'none';
311                     document.getElementById('customEnclosure').style.display = 'none';
312                 }
313             }
314         }
315     }
316 });
317 -->
318 </script>
319
320 EOJAVASCRIPT;
321     }
322 }
323
324 ?>