]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Import/views/view.last.php
Release 6.1.4
[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 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()
94         {
95             global $mod_strings;
96             
97         return array(
98            "<a href='index.php?module={$_REQUEST['import_module']}&action=index'><img src='".SugarThemeRegistry::current()->getImageURL('icon_'.$_REQUEST['import_module'].'_32.png')."' alt='".$_REQUEST['import_module']."' title='".$_REQUEST['import_module']."' align='absmiddle'></a>",
99            "<a href='index.php?module=Import&action=Step1&import_module={$_REQUEST['import_module']}'>".$mod_strings['LBL_MODULE_NAME']."</a>",
100            $mod_strings['LBL_RESULTS'],
101            );
102     }
103     
104         /** 
105      * @see SugarView::display()
106      */
107         public function display()
108     {
109         global $mod_strings, $app_strings, $current_user, $sugar_config, $current_language;
110         
111         $this->ss->assign("MOD", $mod_strings);
112         $this->ss->assign("APP", $app_strings);
113         $this->ss->assign("IMPORT_MODULE", $_REQUEST['import_module']);
114         $this->ss->assign("TYPE", $_REQUEST['type']);
115         $this->ss->assign("HEADER", $app_strings['LBL_IMPORT']." ". $mod_strings['LBL_MODULE_NAME']);
116         $this->ss->assign("MODULE_TITLE", $this->getModuleTitle());
117         // lookup this module's $mod_strings to get the correct module name
118         $language = (isset($current_language)) ? ($current_language) : ($sugar_config['default_language']);
119         $module_mod_strings = 
120             return_module_language($current_language, $_REQUEST['import_module']);
121         $this->ss->assign("MODULENAME",$module_mod_strings['LBL_MODULE_NAME']);
122         
123         $this->ss->assign("JAVASCRIPT", $this->_getJS());
124         
125         // read status file to get totals for records imported, errors, and duplicates
126         $count        = 0;
127         $errorCount   = 0;
128         $dupeCount    = 0;
129         $createdCount = 0;
130         $updatedCount = 0;
131         $fp = sugar_fopen(ImportCacheFiles::getStatusFileName(),'r');
132         while (( $row = fgetcsv($fp, 8192) ) !== FALSE) {
133             $count         += (int) $row[0];
134             $errorCount    += (int) $row[1];
135             $dupeCount     += (int) $row[2];
136             $createdCount  += (int) $row[3];
137             $updatedCount  += (int) $row[4];
138         }
139         fclose($fp);
140     
141         $this->ss->assign("noSuccess",FALSE);
142         if(($count == $errorCount) || ($dupeCount == $count)){
143                 $this->ss->assign("noSuccess",TRUE);            
144         }
145               
146         $this->ss->assign("errorCount",$errorCount);
147         $this->ss->assign("dupeCount",$dupeCount);
148         $this->ss->assign("createdCount",$createdCount);
149         $this->ss->assign("updatedCount",$updatedCount);
150         $this->ss->assign("errorFile",ImportCacheFiles::getErrorFileName());
151         $this->ss->assign("errorrecordsFile",ImportCacheFiles::getErrorRecordsFileName());
152         $this->ss->assign("dupeFile",ImportCacheFiles::getDuplicateFileName());
153         
154         // load bean
155         $focus = loadImportBean($_REQUEST['import_module']);
156         if ( !$focus ) {
157             showImportError($mod_strings['LBL_ERROR_IMPORTS_NOT_SET_UP'],$_REQUEST['import_module']);
158             return;
159         }
160         
161         if ( $focus->object_name == "Prospect" ) {
162             $this->ss->assign("PROSPECTLISTBUTTON", 
163                 $this->_addToProspectListButton());
164         }
165         else {
166             $this->ss->assign("PROSPECTLISTBUTTON","");
167         }
168         
169         $this->ss->display('modules/Import/tpls/last.tpl');
170         
171         foreach ( UsersLastImport::getBeansByImport($_REQUEST['import_module']) as $beanname ) {
172             // load bean
173             if ( !( $focus instanceof $beanname ) ) {
174                 require_once($GLOBALS['beanFiles'][$beanname]);
175                 $focus = new $beanname;
176             }
177             // build listview to show imported records
178             require_once('include/ListView/ListViewFacade.php');
179             $lvf = new ListViewFacade($focus, $focus->module_dir, 0);
180         
181             $params = array();
182             if(!empty($_REQUEST['orderBy'])) {
183                 $params['orderBy'] = $_REQUEST['orderBy'];
184                 $params['overrideOrder'] = true;
185                 if(!empty($_REQUEST['sortOrder'])) $params['sortOrder'] = $_REQUEST['sortOrder'];
186             }
187             $beanname = ($focus->object_name == 'Case' ? 'aCase' : $focus->object_name);
188             // add users_last_import joins so we only show records done in this import
189             $params['custom_from']  = ', users_last_import';
190             $params['custom_where'] = " AND users_last_import.assigned_user_id = '{$GLOBALS['current_user']->id}' 
191                 AND users_last_import.bean_type = '{$beanname}' 
192                 AND users_last_import.bean_id = {$focus->table_name}.id 
193                 AND users_last_import.deleted = 0 
194                 AND {$focus->table_name}.deleted = 0";
195             $where = " {$focus->table_name}.id IN ( 
196                         SELECT users_last_import.bean_id
197                             FROM users_last_import
198                             WHERE users_last_import.assigned_user_id = '{$GLOBALS['current_user']->id}' 
199                                 AND users_last_import.bean_type = '{$beanname}' 
200                                 AND users_last_import.deleted = 0 )";
201                 
202             $lbl_last_imported = $mod_strings['LBL_LAST_IMPORTED'];
203             $lvf->lv->mergeduplicates = false;
204             $module_mod_strings = return_module_language($current_language, $focus->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 ?>