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-2013 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('modules/Import/views/ImportView.php');
45 require_once('modules/Import/ImportCacheFiles.php');
46 require_once('modules/Import/sources/ImportFile.php');
47 require_once('modules/Import/views/ImportListView.php');
48 require_once('include/ListView/ListViewFacade.php');
51 class ImportViewLast extends ImportView
53 protected $pageTitleKey = 'LBL_STEP_5_TITLE';
58 * @see SugarView::display()
60 public function display()
62 global $mod_strings, $app_strings, $current_user, $sugar_config, $current_language;
66 $this->ss->assign("IMPORT_MODULE", $_REQUEST['import_module']);
67 $this->ss->assign("TYPE", $_REQUEST['type']);
68 $this->ss->assign("HEADER", $app_strings['LBL_IMPORT']." ". $mod_strings['LBL_MODULE_NAME']);
69 $this->ss->assign("MODULE_TITLE", $this->getModuleTitle(false));
70 // lookup this module's $mod_strings to get the correct module name
72 return_module_language($current_language, $_REQUEST['import_module']);
73 $this->ss->assign("MODULENAME",$module_mod_strings['LBL_MODULE_NAME']);
75 // read status file to get totals for records imported, errors, and duplicates
81 $fp = sugar_fopen(ImportCacheFiles::getStatusFileName(), 'r');
83 // Read the data if we successfully opened file
86 // Read rows 1 by 1 and add the info
87 while ($row = fgetcsv($fp, 8192))
89 $count += (int) $row[0];
90 $errorCount += (int) $row[1];
91 $dupeCount += (int) $row[2];
92 $createdCount += (int) $row[3];
93 $updatedCount += (int) $row[4];
98 $this->ss->assign("showUndoButton",FALSE);
101 $this->ss->assign("showUndoButton",TRUE);
104 if ($errorCount > 0 && ($createdCount <= 0 && $updatedCount <= 0))
106 else if($dupeCount > 0 && ($createdCount <= 0 && $updatedCount <= 0))
111 $this->ss->assign("JAVASCRIPT", $this->_getJS($activeTab));
113 $this->ss->assign("errorCount", $errorCount);
114 $this->ss->assign("dupeCount", $dupeCount);
115 $this->ss->assign("createdCount", $createdCount);
116 $this->ss->assign("updatedCount", $updatedCount);
117 $this->ss->assign("errorFile", ImportCacheFiles::convertFileNameToUrl(ImportCacheFiles::getErrorFileName()));
118 $this->ss->assign("errorrecordsFile", ImportCacheFiles::convertFileNameToUrl(ImportCacheFiles::getErrorRecordsWithoutErrorFileName()));
119 $this->ss->assign("dupeFile", ImportCacheFiles::convertFileNameToUrl(ImportCacheFiles::getDuplicateFileName()));
121 if ( $this->bean->object_name == "Prospect" )
123 $this->ss->assign("PROSPECTLISTBUTTON", $this->_addToProspectListButton());
126 $this->ss->assign("PROSPECTLISTBUTTON","");
130 foreach ( UsersLastImport::getBeansByImport($_REQUEST['import_module']) as $beanname )
133 if ( !( $this->bean instanceof $beanname ) )
135 $this->bean = new $beanname;
137 $resultsTable .= $this->getListViewResults();
139 if(empty($resultsTable))
141 $resultsTable = $this->getListViewResults();
144 $this->ss->assign("RESULTS_TABLE", $resultsTable);
145 $this->ss->assign("ERROR_TABLE", $this->getListViewTableFromFile(ImportCacheFiles::getErrorRecordsFileName(), 'errors') );
146 $this->ss->assign("DUP_TABLE", $this->getListViewTableFromFile(ImportCacheFiles::getDuplicateFileDisplayName(), 'dup'));
147 $content = $this->ss->fetch('modules/Import/tpls/last.tpl');
148 $this->ss->assign("CONTENT",$content);
149 $this->ss->display('modules/Import/tpls/wizardWrapper.tpl');
152 protected function getListViewResults()
154 global $mod_strings, $current_language;
155 // build listview to show imported records
156 $lvf = !empty($this->lvf) ? $this->lvf : new ListViewFacade($this->bean, $this->bean->module_dir, 0);
159 if(!empty($_REQUEST['orderBy']))
161 $params['orderBy'] = $_REQUEST['orderBy'];
162 $params['overrideOrder'] = true;
163 if(!empty($_REQUEST['sortOrder'])) $params['sortOrder'] = $_REQUEST['sortOrder'];
165 $beanname = ($this->bean->object_name == 'Case' ? 'aCase' : $this->bean->object_name);
166 // add users_last_import joins so we only show records done in this import
167 $params['custom_from'] = ', users_last_import';
168 $params['custom_where'] = " AND users_last_import.assigned_user_id = '{$GLOBALS['current_user']->id}'
169 AND users_last_import.bean_type = '{$beanname}'
170 AND users_last_import.bean_id = {$this->bean->table_name}.id
171 AND users_last_import.deleted = 0
172 AND {$this->bean->table_name}.deleted = 0";
174 $lvf->lv->mergeduplicates = false;
175 $lvf->lv->showMassupdateFields = false;
176 if ( $lvf->type == 2 )
177 $lvf->template = 'include/ListView/ListViewNoMassUpdate.tpl';
179 $module_mod_strings = return_module_language($current_language, $this->bean->module_dir);
180 $lvf->setup('', '', $params, $module_mod_strings, 0, -1, '', strtoupper($beanname), array(), 'id');
181 global $app_list_strings;
182 return $lvf->display($app_list_strings['moduleList'][$this->bean->module_dir], 'main', TRUE);
186 protected function getListViewTableFromFile($fileName, $tableName)
188 $has_header = $_REQUEST['has_header'] == 'on' ? TRUE : FALSE;
189 $if = new ImportFile($fileName, ",", '"', FALSE, FALSE);
190 $if->setHeaderRow($has_header);
191 $lv = new ImportListView($if,array('offset'=> 0), $tableName);
192 return $lv->display(TRUE);
196 * Returns JS used in this view
198 private function _getJS($activeTab)
200 return <<<EOJAVASCRIPT
202 document.getElementById('importmore').onclick = function(){
203 document.getElementById('importlast').action.value = 'Step1';
207 document.getElementById('finished').onclick = function(){
208 document.getElementById('importlast').module.value = document.getElementById('importlast').import_module.value;
209 document.getElementById('importlast').action.value = 'index';
214 if ( typeof(SUGAR) == 'undefined' )
216 if ( typeof(SUGAR.IV) == 'undefined' )
221 getTable : function(tableID, offset) {
225 var tableKey = tableID + '_table';
226 document.getElementById(tableKey).innerHTML = o.responseText;
228 failure: function(o) {},
230 var has_header = document.getElementById('importlast').has_header.value
231 var url = 'index.php?action=RefreshTable&module=Import&offset=' + offset + '&tableID=' + tableID + '&has_header=' + has_header;
232 YAHOO.util.Connect.asyncRequest('GET', url, callback);
234 togglePages : function(activePage)
237 var pageId = 'pageNumIW_' + activePage;
238 activeDashboardPage = activePage;
239 activeTab = activePage;
241 //hide all pages first for display purposes
242 for(var i=0; i < num_tabs; i++)
244 var pageDivId = 'pageNumIW_'+i+'_div';
245 var pageDivElem = document.getElementById(pageDivId);
246 pageDivElem.style.display = 'none';
249 for(var i=0; i < num_tabs; i++)
251 var tabId = 'pageNumIW_'+i;
252 var anchorId = 'pageNumIW_'+i+'_anchor';
253 var pageDivId = 'pageNumIW_'+i+'_div';
255 var tabElem = document.getElementById(tabId);
256 var anchorElem = document.getElementById(anchorId);
257 var pageDivElem = document.getElementById(pageDivId);
261 tabElem.className = 'active';
262 anchorElem.className = 'current';
263 pageDivElem.style.display = '';
267 tabElem.className = '';
268 anchorElem.className = '';
274 SUGAR.IV.togglePages('$activeTab');
280 * Returns a button to add this list of prospects to a Target List
282 * @return string html code to display button
284 private function _addToProspectListButton()
286 global $app_strings, $sugar_version, $sugar_config, $current_user;
288 $query = "SELECT distinct prospects.id, prospects.assigned_user_id, prospects.first_name, prospects.last_name, prospects.phone_work, prospects.title,
289 email_addresses.email_address email1, users.user_name as assigned_user_name
290 FROM users_last_import,prospects
291 LEFT JOIN users ON prospects.assigned_user_id=users.id
292 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
293 LEFT JOIN email_addresses on email_addresses.id = email_addr_bean_rel.email_address_id
294 WHERE users_last_import.assigned_user_id = '{$current_user->id}' AND users_last_import.bean_type='Prospect' AND users_last_import.bean_id=prospects.id
295 AND users_last_import.deleted=0 AND prospects.deleted=0";
299 $res=$GLOBALS['db']->query($query);
300 while($row = $GLOBALS['db']->fetchByAssoc($res))
302 $prospect_id[]=$row['id'];
305 $popup_request_data = array(
306 'call_back_function' => 'set_return_and_save_background',
307 'form_name' => 'DetailView',
308 'field_to_name_array' => array(
309 'id' => 'prospect_list_id',
311 'passthru_data' => array(
312 'child_field' => 'notused',
313 'return_url' => 'notused',
314 'link_field_name' => 'notused',
315 'module_name' => 'notused',
317 'return_type'=>'addtoprospectlist',
318 'parent_module'=>'ProspectLists',
319 'parent_type'=>'ProspectList',
321 'link_attribute'=>'prospects',
322 'link_type'=>'default', //polymorphic or default
323 'prospect_ids'=>$prospect_id,
327 $json = getJSONobj();
328 $encoded_popup_request_data = $json->encode($popup_request_data);
331 <script type="text/javascript" src="include/SubPanel/SubPanelTiles.js?s={$sugar_version}&c={$sugar_config['js_custom_version']}"></script>
332 <input align=right" type="button" name="select_button" id="select_button" class="button"
333 title="{$app_strings['LBL_ADD_TO_PROSPECT_LIST_BUTTON_LABEL']}"
334 value="{$app_strings['LBL_ADD_TO_PROSPECT_LIST_BUTTON_LABEL']}"
335 onclick='open_popup("ProspectLists",600,400,"",true,true,$encoded_popup_request_data,"Single","true");' />