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.
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($browserTitle = false)
93 global $mod_strings, $app_list_strings;
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>";
101 $returnArray[] = $app_list_strings['moduleList'][$_REQUEST['import_module']];
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'];
110 * @see SugarView::display()
112 public function display()
114 global $mod_strings, $app_strings, $current_user;
115 global $sugar_config;
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());
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']);
131 if (isset($_REQUEST['publish']) ) {
132 $import_map = new ImportMap();
135 $import_map = $import_map->retrieve($_REQUEST['import_map_id'], false);
137 if ($_REQUEST['publish'] == 'yes') {
138 $result = $import_map->mark_published($current_user->id,true);
140 $this->ss->assign("ERROR",$mod_strings['LBL_ERROR_UNABLE_TO_PUBLISH']);
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);
148 $this->ss->assign("ERROR",$mod_strings['LBL_ERROR_UNABLE_TO_UNPUBLISH']);
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']) {
162 $this->ss->assign("show_salesforce",true);
163 $this->ss->assign("show_act",true);
166 $this->ss->assign("show_salesforce",true);
167 $this->ss->assign("show_outlook",true);
168 $this->ss->assign("show_act",true);
171 $this->ss->assign("show_salesforce",true);
175 // show any custom mappings
176 if (sugar_is_dir('custom/modules/Import') && $dir = opendir('custom/modules/Import'))
178 while (($file = readdir($dir)) !== false)
180 if (sugar_is_file("custom/modules/Import/{$file}") && strpos($file,".php") !== false)
182 require_once("custom/modules/Import/{$file}");
183 $classname = str_replace('.php','',$file);
184 $mappingClass = new $classname;
185 $custom_mappings[] = $mappingClass->name;
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(
196 'assigned_user_id' => $current_user->id,
197 'is_published' => 'no',
198 'module' => $_REQUEST['import_module'],
202 if ( count($custom_imports_arr) ) {
204 foreach ( $custom_imports_arr as $import) {
206 "IMPORT_NAME" => $import->name,
207 "IMPORT_ID" => $import->id,
210 $this->ss->assign('custom_imports',$custom);
213 // get globally defined import maps
214 $published_imports_arr = $import_map_seed->retrieve_all_by_string_fields(
216 'is_published' => 'yes',
217 'module' => $_REQUEST['import_module'],
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,
229 $this->ss->assign('published_imports',$published);
232 $this->ss->display('modules/Import/tpls/step1.tpl');
236 * Returns JS used in this view
238 private function _getJS()
242 return <<<EOJAVASCRIPT
243 <script type="text/javascript">
245 document.getElementById('custom_enclosure').onchange = function()
247 document.getElementById('importstep1').custom_enclosure_other.style.display = ( this.value == 'other' ? '' : 'none' );
250 document.getElementById('gonext').onclick = function()
253 var sourceSelected = false;
254 var typeSelected = 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']}");
267 if ( !typeSelected && inputs[i].name == 'type' ){
268 if (inputs[i].checked) {
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']}");
277 if ( !typeSelected ) {
278 add_error_style('importstep1','type\'][\'1',"{$mod_strings['ERR_MISSING_REQUIRED_FIELDS']} {$mod_strings['LBL_IMPORT_TYPE']}");
284 YAHOO.util.Event.onDOMReady(function()
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()
291 parentRow = this.parentNode.parentNode;
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 = '';
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 = '';
306 document.getElementById('customDelimiter').style.display = 'none';
307 document.getElementById('customEnclosure').style.display = 'none';