]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Import/views/view.step2.php
Release 6.4.0
[Github/sugarcrm.git] / modules / Import / views / view.step2.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 2 of the import process
41  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42  * All Rights Reserved.
43  ********************************************************************************/
44
45 require_once('modules/Import/views/ImportView.php');
46
47
48 class ImportViewStep2 extends ImportView
49 {
50         protected $pageTitleKey = 'LBL_STEP_2_TITLE';
51
52
53         /**
54      * @see SugarView::display()
55      */
56         public function display()
57     {
58         global $mod_strings, $app_list_strings, $app_strings, $current_user, $import_bean_map;
59         global $import_mod_strings;
60
61         $this->instruction = 'LBL_SELECT_UPLOAD_INSTRUCTION';
62         $this->ss->assign('INSTRUCTION', $this->getInstruction());
63
64         $this->ss->assign("MODULE_TITLE", $this->getModuleTitle(false));
65         $this->ss->assign("IMP", $import_mod_strings);
66         $this->ss->assign("CURRENT_STEP", $this->currentStep);
67         $this->ss->assign("TYPE",( !empty($_REQUEST['type']) ? $_REQUEST['type'] : "import" ));
68         $this->ss->assign("CUSTOM_DELIMITER", ( !empty($_REQUEST['custom_delimiter']) ? $_REQUEST['custom_delimiter'] : "," ));
69         $this->ss->assign("CUSTOM_ENCLOSURE",htmlentities(
70             ( !empty($_REQUEST['custom_enclosure']) && $_REQUEST['custom_enclosure'] != 'other'
71                 ? $_REQUEST['custom_enclosure'] :
72                 ( !empty($_REQUEST['custom_enclosure_other'])
73                     ? $_REQUEST['custom_enclosure_other'] : "" ) )));
74
75         $this->ss->assign("IMPORT_MODULE", $_REQUEST['import_module']);
76         $this->ss->assign("HEADER", $app_strings['LBL_IMPORT']." ". $mod_strings['LBL_MODULE_NAME']);
77         $this->ss->assign("JAVASCRIPT", $this->_getJS());
78         $this->ss->assign("SAMPLE_URL", "<a href=\"javascript: void(0);\" onclick=\"window.location.href='index.php?entryPoint=export&module=".$_REQUEST['import_module']."&action=index&all=true&sample=true'\" >".$mod_strings['LBL_EXAMPLE_FILE']."</a>");
79
80         $displayBackBttn = isset($_REQUEST['action']) && $_REQUEST['action'] != 'index'? TRUE : FALSE;
81         $this->ss->assign("displayBackBttn", $displayBackBttn);
82
83         $importSource = isset($_REQUEST['source']) ? $_REQUEST['source'] : 'csv' ;
84         //Start custom mapping
85         // show any custom mappings
86         if (sugar_is_dir('custom/modules/Import') && $dir = opendir('custom/modules/Import'))
87         {
88             while (($file = readdir($dir)) !== false)
89             {
90                 if (sugar_is_file("custom/modules/Import/{$file}") && strpos($file,".php") !== false)
91                 {
92                         require_once("custom/modules/Import/{$file}");
93                         $classname = str_replace('.php','',$file);
94                         $mappingClass = new $classname;
95                         $custom_mappings[] = $mappingClass->name;
96                 }
97             }
98         }
99         // get user defined import maps
100         $is_admin = is_admin($current_user);
101         if($is_admin)
102             $savedMappingHelpText = $mod_strings['LBL_MY_SAVED_ADMIN_HELP'];
103         else
104             $savedMappingHelpText = $mod_strings['LBL_MY_SAVED_HELP'];
105
106         $this->ss->assign('savedMappingHelpText',$savedMappingHelpText);
107         $this->ss->assign('is_admin',$is_admin);
108
109         $import_map_seed = new ImportMap();
110         $custom_imports_arr = $import_map_seed->retrieve_all_by_string_fields( array('assigned_user_id' => $current_user->id, 'is_published' => 'no','module' => $_REQUEST['import_module']));
111
112         if( count($custom_imports_arr) )
113         {
114             $custom = array();
115             foreach ( $custom_imports_arr as $import)
116             {
117                 $custom[] = array( "IMPORT_NAME" => $import->name,"IMPORT_ID"   => $import->id);
118             }
119             $this->ss->assign('custom_imports',$custom);
120         }
121
122         // get globally defined import maps
123         $published_imports_arr = $import_map_seed->retrieve_all_by_string_fields(array('is_published' => 'yes', 'module' => $_REQUEST['import_module'],) );
124         if ( count($published_imports_arr) )
125         {
126             $published = array();
127             foreach ( $published_imports_arr as $import)
128             {
129                 $published[] = array("IMPORT_NAME" => $import->name, "IMPORT_ID"   => $import->id);
130             }
131             $this->ss->assign('published_imports',$published);
132         }
133         //End custom mapping
134
135         // add instructions for anything other than custom_delimited
136         $instructions = array();
137         $lang_key = "CUSTOM";
138
139         for ($i = 1; isset($mod_strings["LBL_{$lang_key}_NUM_$i"]);$i++)
140         {
141             $instructions[] = array(
142                 "STEP_NUM"         => $mod_strings["LBL_NUM_$i"],
143                 "INSTRUCTION_STEP" => $mod_strings["LBL_{$lang_key}_NUM_$i"],
144             );
145         }
146         $this->ss->assign("INSTRUCTIONS_TITLE",$mod_strings["LBL_IMPORT_{$lang_key}_TITLE"]);
147         $this->ss->assign("instructions",$instructions);
148
149         $content = $this->ss->fetch('modules/Import/tpls/step2.tpl');
150         $this->ss->assign("CONTENT",$content);
151         $this->ss->display('modules/Import/tpls/wizardWrapper.tpl');
152     }
153
154     /**
155      * Returns JS used in this view
156      */
157     private function _getJS()
158     {
159         global $mod_strings;
160
161         return <<<EOJAVASCRIPT
162
163 if( document.getElementById('goback') )
164 {
165     document.getElementById('goback').onclick = function()
166     {
167         document.getElementById('importstep2').action.value = 'Step1';
168         return true;
169     }
170 }
171
172 document.getElementById('gonext').onclick = function(){
173     // warning message that tells user that updates can not be undone
174     if(document.getElementById('import_update').checked)
175     {
176         ret = confirm(SUGAR.language.get("Import", 'LBL_CONFIRM_IMPORT'));
177         if (!ret) {
178             return false;
179         }
180     }
181     clear_all_errors();
182     var isError = false;
183     // be sure we specify a file to upload
184     if (document.getElementById('importstep2').userfile.value == "") {
185         add_error_style(document.getElementById('importstep2').name,'userfile',"{$mod_strings['ERR_MISSING_REQUIRED_FIELDS']} {$mod_strings['ERR_SELECT_FILE']}");
186         isError = true;
187     }
188
189     return !isError;
190
191 }
192
193 function publishMapping(elem, publish, mappingId)
194 {
195     if( typeof(elem.publish) != 'undefined' )
196         publish = elem.publish;
197
198     var url = 'index.php?action=mapping&module=Import&publish=' + publish + '&import_map_id=' + mappingId;
199     var callback = {
200                         success: function(o)
201                         {
202                             var r = YAHOO.lang.JSON.parse(o.responseText);
203                             if( r.message != '')
204                                 alert(r.message);
205                         },
206                         failure: function(o) {}
207                    };
208     YAHOO.util.Connect.asyncRequest('GET', url, callback);
209     //Toggle the button title
210     if(publish == 'yes')
211     {
212         var newTitle = SUGAR.language.get('Import','LBL_UNPUBLISH');
213         var newPublish = 'no';
214     }
215     else
216     {
217         var newTitle = SUGAR.language.get('Import','LBL_PUBLISH');
218         var newPublish = 'yes';
219     }
220
221     elem.value = newTitle;
222     elem.publish = newPublish;
223
224 }
225 function deleteMapping(elemId, mappingId )
226 {
227     var elem = document.getElementById(elemId);
228     var table = elem.parentNode;
229     table.deleteRow(elem.rowIndex);
230
231     var url = 'index.php?action=mapping&module=Import&delete_map_id=' + mappingId;
232     var callback = {
233                         success: function(o)
234                         {
235                             var r = YAHOO.lang.JSON.parse(o.responseText);
236                             if( r.message != '')
237                                 alert(r.message);
238                         },
239                         failure: function(o) {}
240                    };
241     YAHOO.util.Connect.asyncRequest('GET', url, callback);
242 }
243 var deselectEl = document.getElementById('deselect');
244 if(deselectEl)
245 {
246     deselectEl.onclick = function() {
247         var els = document.getElementsByName('source');
248         for(i=0;i<els.length;i++)
249         {
250             els[i].checked = false;
251         }
252     }
253 }
254
255 EOJAVASCRIPT;
256     }
257 }
258
259