]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Import/views/view.last.php
Release 6.2.0
[Github/sugarcrm.git] / modules / Import / views / view.last.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 /*********************************************************************************
39
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');
45
46 require_once('modules/Import/ImportCacheFiles.php');
47
48                 
49 class ImportViewLast extends SugarView 
50 {       
51     /**
52      * @see SugarView::getMenu()
53      */
54     public function getMenu(
55         $module = null
56         )
57     {
58         global $mod_strings, $current_language;
59         
60         if ( empty($module) )
61             $module = $_REQUEST['import_module'];
62         
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;
67         
68         return $returnMenu;
69     }
70     
71         /**
72      * @see SugarView::_getModuleTab()
73      */
74         protected function _getModuleTab()
75     {
76         global $app_list_strings, $moduleTabMap;
77         
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']]) )
85             return 'Home';
86         else
87             return $_REQUEST['import_module'];
88         }
89         
90         /**
91          * @see SugarView::_getModuleTitleParams()
92          */
93         protected function _getModuleTitleParams($browserTitle = false)
94         {
95             global $mod_strings, $app_list_strings;
96             
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>";
101         }
102         else {
103             $returnArray[] = $app_list_strings['moduleList'][$_REQUEST['import_module']];
104         }
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'];
107         
108             return $returnArray;
109     }
110     
111         /** 
112      * @see SugarView::display()
113      */
114         public function display()
115     {
116         global $mod_strings, $app_strings, $current_user, $sugar_config, $current_language;
117         
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']);
126         
127         $this->ss->assign("JAVASCRIPT", $this->_getJS());
128         
129         // read status file to get totals for records imported, errors, and duplicates
130         $count        = 0;
131         $errorCount   = 0;
132         $dupeCount    = 0;
133         $createdCount = 0;
134         $updatedCount = 0;
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];
142         }
143         fclose($fp);
144     
145         $this->ss->assign("noSuccess",FALSE);
146         if(($count == $errorCount) || ($dupeCount == $count)){
147                 $this->ss->assign("noSuccess",TRUE);            
148         }
149               
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());
157         
158         if ( $this->bean->object_name == "Prospect" ) {
159             $this->ss->assign("PROSPECTLISTBUTTON", 
160                 $this->_addToProspectListButton());
161         }
162         else {
163             $this->ss->assign("PROSPECTLISTBUTTON","");
164         }
165         
166         $this->ss->display('modules/Import/tpls/last.tpl');
167         
168         foreach ( UsersLastImport::getBeansByImport($_REQUEST['import_module']) as $beanname ) {
169             // load bean
170             if ( !( $this->bean instanceof $beanname ) ) {
171                 $this->bean = new $beanname;
172             }
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);
176         
177             $params = array();
178             if(!empty($_REQUEST['orderBy'])) {
179                 $params['orderBy'] = $_REQUEST['orderBy'];
180                 $params['overrideOrder'] = true;
181                 if(!empty($_REQUEST['sortOrder'])) $params['sortOrder'] = $_REQUEST['sortOrder'];
182             }
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 )";
197                 
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';
203             }
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']);
207         }
208     }
209
210     /**
211      * Returns JS used in this view
212      */
213     private function _getJS()
214     {
215         return <<<EOJAVASCRIPT
216 <script type="text/javascript">
217 <!--
218 document.getElementById('importmore').onclick = function(){
219     document.getElementById('importlast').action.value = 'Step1';
220     return true;
221 }
222
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';
226     return true;
227 }
228 -->
229 </script>
230
231 EOJAVASCRIPT;
232     }
233     /**
234      * Returns a button to add this list of prospects to a Target List
235      *
236      * @return string html code to display button
237      */
238     private function _addToProspectListButton() 
239     {
240         global $app_strings, $sugar_version, $sugar_config, $current_user;
241         
242         $query = "SELECT distinct
243                                 prospects.id,
244                                 prospects.assigned_user_id,
245                                 prospects.first_name,
246                                 prospects.last_name,
247                                 prospects.phone_work,
248                                 prospects.title,
249                                 email_addresses.email_address email1,
250                                 users.user_name as assigned_user_name
251                                 FROM users_last_import,prospects
252                                 LEFT JOIN users
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 
256                                                                                 
257                                 WHERE
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
264                         ";
265         
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',
271             ),
272             'passthru_data' => array(
273                 'child_field' => 'notused',
274                 'return_url' => 'notused',
275                 'link_field_name' => 'notused',
276                 'module_name' => 'notused',
277                 'refresh_page'=>'1',
278                 'return_type'=>'addtoprospectlist',
279                 'parent_module'=>'ProspectLists',
280                 'parent_type'=>'ProspectList',
281                 'child_id'=>'id',
282                 'link_attribute'=>'prospects',
283                 'link_type'=>'default',  //polymorphic or default
284             )                           
285         );
286     
287         $popup_request_data['passthru_data']['query'] = urlencode($query);
288     
289         $json = getJSONobj();
290         $encoded_popup_request_data = $json->encode($popup_request_data);       
291     
292         return <<<EOHTML
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");' />
299 EOHTML;
300     
301     }
302 }
303 ?>