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 last step 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');
46 require_once('modules/Import/ImportCacheFiles.php');
49 class ImportViewLast extends SugarView
52 * @see SugarView::getMenu()
54 public function getMenu(
58 global $mod_strings, $current_language;
61 $module = $_REQUEST['import_module'];
63 $old_mod_strings = $mod_strings;
64 $mod_strings = return_module_language($current_language, $module);
65 $returnMenu = parent::getMenu($module);
66 $mod_strings = $old_mod_strings;
72 * @see SugarView::_getModuleTab()
74 protected function _getModuleTab()
76 global $app_list_strings, $moduleTabMap;
78 // Need to figure out what tab this module belongs to, most modules have their own tabs, but there are exceptions.
79 if ( !empty($_REQUEST['module_tab']) )
80 return $_REQUEST['module_tab'];
81 elseif ( isset($moduleTabMap[$_REQUEST['import_module']]) )
82 return $moduleTabMap[$_REQUEST['import_module']];
83 // Default anonymous pages to be under Home
84 elseif ( !isset($app_list_strings['moduleList'][$_REQUEST['import_module']]) )
87 return $_REQUEST['import_module'];
91 * @see SugarView::_getModuleTitleParams()
93 protected function _getModuleTitleParams($browserTitle = false)
95 global $mod_strings, $app_list_strings;
97 $iconPath = $this->getModuleTitleIconPath($this->module);
98 $returnArray = array();
99 if (!empty($iconPath) && !$browserTitle) {
100 $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>";
103 $returnArray[] = $app_list_strings['moduleList'][$_REQUEST['import_module']];
105 $returnArray[] = "<a href='index.php?module=Import&action=Step1&import_module={$_REQUEST['import_module']}'>".$mod_strings['LBL_MODULE_NAME']."</a>";
106 $returnArray[] = $mod_strings['LBL_RESULTS'];
112 * @see SugarView::display()
114 public function display()
116 global $mod_strings, $app_strings, $current_user, $sugar_config, $current_language;
118 $this->ss->assign("IMPORT_MODULE", $_REQUEST['import_module']);
119 $this->ss->assign("TYPE", $_REQUEST['type']);
120 $this->ss->assign("HEADER", $app_strings['LBL_IMPORT']." ". $mod_strings['LBL_MODULE_NAME']);
121 $this->ss->assign("MODULE_TITLE", $this->getModuleTitle());
122 // lookup this module's $mod_strings to get the correct module name
123 $module_mod_strings =
124 return_module_language($current_language, $_REQUEST['import_module']);
125 $this->ss->assign("MODULENAME",$module_mod_strings['LBL_MODULE_NAME']);
127 $this->ss->assign("JAVASCRIPT", $this->_getJS());
129 // read status file to get totals for records imported, errors, and duplicates
135 $fp = sugar_fopen(ImportCacheFiles::getStatusFileName(),'r');
136 while (( $row = fgetcsv($fp, 8192) ) !== FALSE) {
137 $count += (int) $row[0];
138 $errorCount += (int) $row[1];
139 $dupeCount += (int) $row[2];
140 $createdCount += (int) $row[3];
141 $updatedCount += (int) $row[4];
145 $this->ss->assign("noSuccess",FALSE);
146 if(($count == $errorCount) || ($dupeCount == $count)){
147 $this->ss->assign("noSuccess",TRUE);
150 $this->ss->assign("errorCount",$errorCount);
151 $this->ss->assign("dupeCount",$dupeCount);
152 $this->ss->assign("createdCount",$createdCount);
153 $this->ss->assign("updatedCount",$updatedCount);
154 $this->ss->assign("errorFile",ImportCacheFiles::getErrorFileName());
155 $this->ss->assign("errorrecordsFile",ImportCacheFiles::getErrorRecordsFileName());
156 $this->ss->assign("dupeFile",ImportCacheFiles::getDuplicateFileName());
158 if ( $this->bean->object_name == "Prospect" ) {
159 $this->ss->assign("PROSPECTLISTBUTTON",
160 $this->_addToProspectListButton());
163 $this->ss->assign("PROSPECTLISTBUTTON","");
166 $this->ss->display('modules/Import/tpls/last.tpl');
168 foreach ( UsersLastImport::getBeansByImport($_REQUEST['import_module']) as $beanname ) {
170 if ( !( $this->bean instanceof $beanname ) ) {
171 $this->bean = new $beanname;
173 // build listview to show imported records
174 require_once('include/ListView/ListViewFacade.php');
175 $lvf = new ListViewFacade($this->bean, $this->bean->module_dir, 0);
178 if(!empty($_REQUEST['orderBy'])) {
179 $params['orderBy'] = $_REQUEST['orderBy'];
180 $params['overrideOrder'] = true;
181 if(!empty($_REQUEST['sortOrder'])) $params['sortOrder'] = $_REQUEST['sortOrder'];
183 $beanname = ($this->bean->object_name == 'Case' ? 'aCase' : $this->bean->object_name);
184 // add users_last_import joins so we only show records done in this import
185 $params['custom_from'] = ', users_last_import';
186 $params['custom_where'] = " AND users_last_import.assigned_user_id = '{$GLOBALS['current_user']->id}'
187 AND users_last_import.bean_type = '{$beanname}'
188 AND users_last_import.bean_id = {$this->bean->table_name}.id
189 AND users_last_import.deleted = 0
190 AND {$this->bean->table_name}.deleted = 0";
191 $where = " {$this->bean->table_name}.id IN (
192 SELECT users_last_import.bean_id
193 FROM users_last_import
194 WHERE users_last_import.assigned_user_id = '{$GLOBALS['current_user']->id}'
195 AND users_last_import.bean_type = '{$beanname}'
196 AND users_last_import.deleted = 0 )";
198 $lbl_last_imported = $mod_strings['LBL_LAST_IMPORTED'];
199 $lvf->lv->mergeduplicates = false;
200 $lvf->lv->showMassupdateFields = false;
201 if ( $lvf->type == 2 ) {
202 $lvf->template = 'include/ListView/ListViewNoMassUpdate.tpl';
204 $module_mod_strings = return_module_language($current_language, $this->bean->module_dir);
205 $lvf->setup('', $where, $params, $module_mod_strings, 0, -1, '', strtoupper($beanname), array(), 'id');
206 $lvf->display($lbl_last_imported.": ".$module_mod_strings['LBL_MODULE_NAME']);
211 * Returns JS used in this view
213 private function _getJS()
215 return <<<EOJAVASCRIPT
216 <script type="text/javascript">
218 document.getElementById('importmore').onclick = function(){
219 document.getElementById('importlast').action.value = 'Step1';
223 document.getElementById('finished').onclick = function(){
224 document.getElementById('importlast').module.value = document.getElementById('importlast').import_module.value;
225 document.getElementById('importlast').action.value = 'index';
234 * Returns a button to add this list of prospects to a Target List
236 * @return string html code to display button
238 private function _addToProspectListButton()
240 global $app_strings, $sugar_version, $sugar_config, $current_user;
242 $query = "SELECT distinct
244 prospects.assigned_user_id,
245 prospects.first_name,
247 prospects.phone_work,
249 email_addresses.email_address email1,
250 users.user_name as assigned_user_name
251 FROM users_last_import,prospects
253 ON prospects.assigned_user_id=users.id
254 LEFT JOIN email_addr_bean_rel on prospects.id = email_addr_bean_rel.bean_id and email_addr_bean_rel.bean_module='Prospect' and email_addr_bean_rel.primary_address=1 and email_addr_bean_rel.deleted=0
255 LEFT JOIN email_addresses on email_addresses.id = email_addr_bean_rel.email_address_id
258 users_last_import.assigned_user_id=
259 '{$current_user->id}'
260 AND users_last_import.bean_type='Prospect'
261 AND users_last_import.bean_id=prospects.id
262 AND users_last_import.deleted=0
263 AND prospects.deleted=0
266 $popup_request_data = array(
267 'call_back_function' => 'set_return_and_save_background',
268 'form_name' => 'DetailView',
269 'field_to_name_array' => array(
270 'id' => 'subpanel_id',
272 'passthru_data' => array(
273 'child_field' => 'notused',
274 'return_url' => 'notused',
275 'link_field_name' => 'notused',
276 'module_name' => 'notused',
278 'return_type'=>'addtoprospectlist',
279 'parent_module'=>'ProspectLists',
280 'parent_type'=>'ProspectList',
282 'link_attribute'=>'prospects',
283 'link_type'=>'default', //polymorphic or default
287 $popup_request_data['passthru_data']['query'] = urlencode($query);
289 $json = getJSONobj();
290 $encoded_popup_request_data = $json->encode($popup_request_data);
293 <script type="text/javascript" src="include/SubPanel/SubPanelTiles.js?s={$sugar_version}&c={$sugar_config['js_custom_version']}"></script>
294 <input align=right" type="button" name="select_button" id="select_button" class="button"
295 title="{$app_strings['LBL_ADD_TO_PROSPECT_LIST_BUTTON_LABEL']}"
296 accesskey="{$app_strings['LBL_ADD_TO_PROSPECT_LIST_BUTTON_KEY']}"
297 value="{$app_strings['LBL_ADD_TO_PROSPECT_LIST_BUTTON_LABEL']}"
298 onclick='open_popup("ProspectLists",600,400,"",true,true,$encoded_popup_request_data,"Single","true");' />