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.
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.
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
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
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.
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.
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 ********************************************************************************/
38 /*********************************************************************************
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');
47 class ImportViewStep1 extends SugarView
50 * @see SugarView::getMenu()
52 public function getMenu(
56 global $mod_strings, $current_language;
59 $module = $_REQUEST['import_module'];
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;
70 * @see SugarView::_getModuleTab()
72 protected function _getModuleTab()
74 global $app_list_strings, $moduleTabMap;
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']]) )
85 return $_REQUEST['import_module'];
89 * @see SugarView::_getModuleTitleParams()
91 protected function _getModuleTitleParams()
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'],
103 * @see SugarView::display()
105 public function display()
107 global $mod_strings, $app_list_strings, $app_strings, $current_user;
108 global $sugar_config;
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());
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']);
126 if (isset($_REQUEST['publish']) ) {
127 $import_map = new ImportMap();
130 $import_map = $import_map->retrieve($_REQUEST['import_map_id'], false);
132 if ($_REQUEST['publish'] == 'yes') {
133 $result = $import_map->mark_published($current_user->id,true);
135 $this->ss->assign("ERROR",$mod_strings['LBL_ERROR_UNABLE_TO_PUBLISH']);
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);
143 $this->ss->assign("ERROR",$mod_strings['LBL_ERROR_UNABLE_TO_UNPUBLISH']);
150 $focus = loadImportBean($_REQUEST['import_module']);
152 showImportError($mod_strings['LBL_ERROR_IMPORTS_NOT_SET_UP'],$_REQUEST['import_module']);
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']) {
164 $this->ss->assign("show_salesforce",true);
165 $this->ss->assign("show_act",true);
168 $this->ss->assign("show_salesforce",true);
169 $this->ss->assign("show_outlook",true);
170 $this->ss->assign("show_act",true);
173 $this->ss->assign("show_salesforce",true);
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(
182 'assigned_user_id' => $current_user->id,
183 'is_published' => 'no',
184 'module' => $_REQUEST['import_module'],
188 if ( count($custom_imports_arr) ) {
190 foreach ( $custom_imports_arr as $import) {
192 "IMPORT_NAME" => $import->name,
193 "IMPORT_ID" => $import->id,
196 $this->ss->assign('custom_imports',$custom);
199 // get globally defined import maps
200 $published_imports_arr = $import_map_seed->retrieve_all_by_string_fields(
202 'is_published' => 'yes',
203 'module' => $_REQUEST['import_module'],
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,
215 $this->ss->assign('published_imports',$published);
218 $this->ss->display('modules/Import/tpls/step1.tpl');
222 * Returns JS used in this view
224 private function _getJS()
228 return <<<EOJAVASCRIPT
229 <script type="text/javascript">
231 document.getElementById('custom_enclosure').onchange = function()
233 document.getElementById('importstep1').custom_enclosure_other.style.display = ( this.value == 'other' ? '' : 'none' );
236 document.getElementById('gonext').onclick = function()
239 var sourceSelected = false;
240 var typeSelected = 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']}");
253 if ( !typeSelected && inputs[i].name == 'type' ){
254 if (inputs[i].checked) {
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']}");
263 if ( !typeSelected ) {
264 add_error_style('importstep1','type\'][\'1',"{$mod_strings['ERR_MISSING_REQUIRED_FIELDS']} {$mod_strings['LBL_IMPORT_TYPE']}");
270 YAHOO.util.Event.onDOMReady(function()
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()
277 parentRow = this.parentNode.parentNode;
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 = '';
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 = '';
292 document.getElementById('customDelimiter').style.display = 'none';
293 document.getElementById('customEnclosure').style.display = 'none';