]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Import/views/ImportView.php
Release 6.3.0beta2
[Github/sugarcrm.git] / modules / Import / views / ImportView.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 require_once('include/MVC/View/SugarView.php');
39
40
41 class ImportView extends SugarView
42 {
43     protected $currentStep;
44     protected $pageTitleKey;
45     protected $instruction;
46
47     public function __construct($bean = null, $view_object_map = array())
48     {
49         global $mod_strings;
50
51         parent::__construct($bean, $view_object_map);
52
53         if (isset($_REQUEST['button']) && trim($_REQUEST['button']) == htmlentities($mod_strings['LBL_BACK'])) {
54             // if the request comes from the "Back" button, decrease the step count
55             $this->currentStep = isset($_REQUEST['current_step']) ? ($_REQUEST['current_step'] - 1) : 1;
56         } else {
57             $this->currentStep = isset($_REQUEST['current_step']) ? ($_REQUEST['current_step'] + 1) : 1;
58         }
59         $this->importModule = isset($_REQUEST['import_module']) ? $_REQUEST['import_module'] : '';
60         
61         $this->options['show_header'] = false;
62         $this->options['show_footer'] = false;
63         $this->options['show_javascript'] = false;
64     }
65
66     /**
67      * @see SugarView::getMenu()
68      */
69     public function getMenu($module = null)
70     {
71         global $mod_strings, $current_language;
72
73         if ( empty($module) )
74             $module = $this->importModule;
75
76         $old_mod_strings = $mod_strings;
77         $mod_strings = return_module_language($current_language, $module);
78         $returnMenu = parent::getMenu($module);
79         $mod_strings = $old_mod_strings;
80
81         return $returnMenu;
82     }
83
84         /**
85      * @see SugarView::_getModuleTab()
86      */
87         protected function _getModuleTab()
88     {
89         global $app_list_strings, $moduleTabMap;
90
91                 // Need to figure out what tab this module belongs to, most modules have their own tabs, but there are exceptions.
92         if ( !empty($_REQUEST['module_tab']) )
93             return $_REQUEST['module_tab'];
94         elseif ( isset($moduleTabMap[$this->importModule]) )
95             return $moduleTabMap[$this->importModule];
96         // Default anonymous pages to be under Home
97         elseif ( !isset($app_list_strings['moduleList'][$this->importModule]) )
98             return 'Home';
99         else
100             return $this->importModule;
101         }
102
103     /**
104      * Send our output to the importer controller.
105      * 
106      * @param string $html
107      * @param string $submitContent
108      * @param string $script
109      * @param bool $encode
110      * @return void
111      */
112     protected function sendJsonOutput($html = "", $submitContent = "", $script = "", $encode = FALSE)
113     {
114         $title = $this->getModuleTitle(false);
115         $out = array(
116             'html'          => $html,
117             'submitContent' => $submitContent,
118             'title'         => $title,
119             'script'        => $script);
120
121         if($encode){
122             array_walk($out, create_function('&$val', '$val = htmlspecialchars($val,ENT_NOQUOTES);'));
123         }
124         echo json_encode($out);
125     }
126
127     /**
128          * @see SugarView::_getModuleTitleParams()
129          */
130         protected function _getModuleTitleParams($browserTitle = false)
131         {
132             global $mod_strings, $app_list_strings;
133
134             $returnArray = array();
135         $returnArray[] = $app_list_strings['moduleList'][$this->importModule];
136             $returnArray[] = $mod_strings['LBL_MODULE_NAME'];
137             $returnArray[] = string_format($mod_strings[$this->pageTitleKey], array($this->currentStep));
138
139             return $returnArray;
140     }
141
142     protected function getInstruction()
143     {
144         global $mod_strings;
145
146         $ins = '';
147         
148         if ($this->instruction) {
149             $ins_string = $mod_strings[$this->instruction];
150             $ins = '<div class="import_instruction">' . $ins_string . '</div>';
151         }
152
153         return $ins;
154     }
155
156      /**
157      * Displays the Smarty template for an error
158      *
159      * @param string $message error message to show
160      * @param string $module what module we were importing into
161      * @param string $action what page we should go back to
162      */
163     protected function _showImportError($message,$module,$action = 'Step1')
164     {
165         $ss = new Sugar_Smarty();
166         
167         global $mod_strings;
168
169                 $themeObject = SugarThemeRegistry::current();
170                 $css = $themeObject->getCSS();
171         $favicon = $themeObject->getImageURL('sugar_icon.ico',false);
172         $ss->assign('FAVICON_URL',getJSPath($favicon));
173         $ss->assign('SUGAR_CSS', $css);
174         $ss->assign('PAGETITLE', $mod_strings[$this->pageTitleKey]);
175         
176         
177
178         $ss->assign("MESSAGE",$message);
179         $ss->assign("ACTION",$action);
180         $ss->assign("IMPORT_MODULE",$module);
181         $ss->assign("MOD", $GLOBALS['mod_strings']);
182         $ss->assign("SOURCE","");
183         if ( isset($_REQUEST['source']) )
184             $ss->assign("SOURCE", $_REQUEST['source']);
185
186         $content = $this->ss->fetch('modules/Import/tpls/error.tpl');
187         $this->ss->assign("CONTENT",$content);
188         
189         ob_start();
190         $this->options['show_javascript'] = true;
191         $this->renderJavascript();
192         $this->options['show_javascript'] = false;
193         $script = ob_get_contents().$themeObject->getJS();
194         $ss->assign("SUGAR_JS",$script);
195         ob_end_clean();
196
197         echo json_encode(array(
198             'html'          => $content,
199             'submitContent' => "",
200             'title'         => $mod_strings[$this->pageTitleKey],
201             'script'        => $script,
202          ));
203     }
204 }