forked from vtiger-crm/vtigercrm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Popup.php
442 lines (406 loc) · 19.6 KB
/
Popup.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
<?php
/*********************************************************************************
* The contents of this file are subject to the SugarCRM Public License Version 1.1.2
* ("License"); You may not use this file except in compliance with the
* License. You may obtain a copy of the License at http://www.sugarcrm.com/SPL
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Original Code is: SugarCRM Open Source
* The Initial Developer of the Original Code is SugarCRM, Inc.
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.;
* All Rights Reserved.
* Contributor(s): ______________________________________.
********************************************************************************/
require_once('Smarty_setup.php');
require_once("data/Tracker.php");
require_once('include/logging.php');
require_once('include/ListView/ListView.php');
require_once('include/utils/utils.php');
global $app_strings, $default_charset;
global $currentModule, $current_user;
global $theme, $adb;
$url_string = '';
$smarty = new vtigerCRM_Smarty;
if (!isset($where)) $where = "";
$parent_tab=getParentTab();
$smarty->assign("CATEGORY",$parent_tab);
$url = '';
$popuptype = '';
$popuptype = vtlib_purify($_REQUEST["popuptype"]);
$theme_path="themes/".$theme."/";
$image_path=$theme_path."images/";
$smarty->assign("MOD", $mod_strings);
$smarty->assign("APP", $app_strings);
$smarty->assign("THEME", $theme);
$smarty->assign("THEME_PATH",$theme_path);
$smarty->assign("MODULE",$currentModule);
$form = vtlib_purify($_REQUEST['form']);
//added to get relatedto field value for todo, while selecting from the popup list, after done the alphabet or basic search.
if(isset($_REQUEST['maintab']) && $_REQUEST['maintab'] != '')
{
$act_tab = vtlib_purify($_REQUEST['maintab']);
$url = "&maintab=".$act_tab;
}
$smarty->assign("MAINTAB",$act_tab);
// This is added to support the type of popup and callback
if(isset($_REQUEST['popupmode']) && isset($_REQUEST['callback'])) {
$url = "&popupmode=".$_REQUEST['popupmode']."&callback=".$_REQUEST['callback'];
$smarty->assign("POPUPMODE", $_REQUEST['popupmode']);
$smarty->assign("CALLBACK", $_REQUEST['callback']);
}
switch($currentModule)
{
case 'Contacts':
require_once("modules/$currentModule/Contacts.php");
$focus = new Contacts();
$log = LoggerManager::getLogger('contact_list');
$smarty->assign("SINGLE_MOD",'Contact');
if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] !='')
$smarty->assign("RETURN_MODULE",vtlib_purify($_REQUEST['return_module']));
else
$smarty->assign("RETURN_MODULE",'Emails');
if (isset($_REQUEST['select'])) $smarty->assign("SELECT",'enable');
$alphabetical = AlphabeticalSearch($currentModule,'Popup','lastname','true','basic',$popuptype,"","",$url);
break;
case 'Campaigns':
require_once("modules/$currentModule/Campaigns.php");
$focus = new Campaigns();
$log = LoggerManager::getLogger('campaign_list');
$smarty->assign("SINGLE_MOD",'Campaign');
if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] !='')
$smarty->assign("RETURN_MODULE",vtlib_purify($_REQUEST['return_module']));
if (isset($_REQUEST['select'])) $smarty->assign("SELECT",'enable');
$alphabetical = AlphabeticalSearch($currentModule,'Popup','campaignname','true','basic',$popuptype,"","",$url);
break;
case 'Accounts':
require_once("modules/$currentModule/Accounts.php");
$focus = new Accounts();
$log = LoggerManager::getLogger('account_list');
if (isset($_REQUEST['select'])) $smarty->assign("SELECT",'enable');
$smarty->assign("SINGLE_MOD",'Account');
if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] !='')
$smarty->assign("RETURN_MODULE",vtlib_purify($_REQUEST['return_module']));
else
$smarty->assign("RETURN_MODULE",'Emails');
$alphabetical = AlphabeticalSearch($currentModule,'Popup','accountname','true','basic',$popuptype,"","",$url);
break;
case 'Leads':
require_once("modules/$currentModule/Leads.php");
$focus = new Leads();
$log = LoggerManager::getLogger('contact_list');
$smarty->assign("SINGLE_MOD",'Lead');
if (isset($_REQUEST['select'])) $smarty->assign("SELECT",'enable');
if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] !='')
$smarty->assign("RETURN_MODULE",vtlib_purify($_REQUEST['return_module']));
else
$smarty->assign("RETURN_MODULE",'Emails');
$alphabetical = AlphabeticalSearch($currentModule,'Popup','lastname','true','basic',$popuptype,"","",$url);
break;
case 'Potentials':
require_once("modules/$currentModule/Potentials.php");
$focus = new Potentials();
$log = LoggerManager::getLogger('potential_list');
if (isset($_REQUEST['select'])) $smarty->assign("SELECT",'enable');
$smarty->assign("SINGLE_MOD",'Opportunity');
if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] !='')
$smarty->assign("RETURN_MODULE",vtlib_purify($_REQUEST['return_module']));
$alphabetical = AlphabeticalSearch($currentModule,'Popup','potentialname','true','basic',$popuptype,"","",$url);
break;
case 'Quotes':
require_once("modules/$currentModule/Quotes.php");
$focus = new Quotes();
$log = LoggerManager::getLogger('quotes_list');
$smarty->assign("SINGLE_MOD",'Quote');
$alphabetical = AlphabeticalSearch($currentModule,'Popup','subject','true','basic',$popuptype,"","",$url);
break;
case 'Invoice':
require_once("modules/$currentModule/Invoice.php");
$focus = new Invoice();
$smarty->assign("SINGLE_MOD",'Invoice');
if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] !='')
$smarty->assign("RETURN_MODULE",vtlib_purify($_REQUEST['return_module']));
$alphabetical = AlphabeticalSearch($currentModule,'Popup','subject','true','basic',$popuptype,"","",$url);
break;
case 'Products':
require_once("modules/$currentModule/$currentModule.php");
$focus = new $currentModule();
$smarty->assign("SINGLE_MOD",getTranslatedString('SINGLE_'.$currentModule));
if(isset($_REQUEST['curr_row']))
{
$curr_row = vtlib_purify($_REQUEST['curr_row']);
$smarty->assign("CURR_ROW", $curr_row);
$url_string .="&curr_row=".vtlib_purify($_REQUEST['curr_row']);
}
if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] !='')
$smarty->assign("RETURN_MODULE",vtlib_purify($_REQUEST['return_module']));
if (isset($_REQUEST['select'])) $smarty->assign("SELECT",'enable');
$alphabetical = AlphabeticalSearch($currentModule,'Popup','productname','true','basic',$popuptype,"","",$url);
break;
case 'Vendors':
require_once("modules/$currentModule/Vendors.php");
$focus = new Vendors();
$smarty->assign("SINGLE_MOD",'Vendor');
$alphabetical = AlphabeticalSearch($currentModule,'Popup','vendorname','true','basic',$popuptype,"","",$url);
break;
case 'SalesOrder':
require_once("modules/$currentModule/SalesOrder.php");
$focus = new SalesOrder();
$smarty->assign("SINGLE_MOD",'SalesOrder');
if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] !='')
$smarty->assign("RETURN_MODULE",vtlib_purify($_REQUEST['return_module']));
$alphabetical = AlphabeticalSearch($currentModule,'Popup','subject','true','basic',$popuptype,"","",$url);
break;
case 'PurchaseOrder':
require_once("modules/$currentModule/PurchaseOrder.php");
$focus = new PurchaseOrder();
$smarty->assign("SINGLE_MOD",'PurchaseOrder');
if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] !='')
$smarty->assign("RETURN_MODULE",vtlib_purify($_REQUEST['return_module']));
$alphabetical = AlphabeticalSearch($currentModule,'Popup','subject','true','basic',$popuptype,"","",$url);
break;
case 'PriceBooks':
require_once("modules/$currentModule/PriceBooks.php");
$focus = new PriceBooks();
$smarty->assign("SINGLE_MOD",'PriceBook');
if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] !='')
$smarty->assign("RETURN_MODULE",vtlib_purify($_REQUEST['return_module']));
if(isset($_REQUEST['fldname']) && $_REQUEST['fldname'] !='')
{
$smarty->assign("FIELDNAME",vtlib_purify($_REQUEST['fldname']));
$url_string .="&fldname=".vtlib_purify($_REQUEST['fldname']);
}
if(isset($_REQUEST['productid']) && $_REQUEST['productid'] !='')
{
$smarty->assign("PRODUCTID",vtlib_purify($_REQUEST['productid']));
$url_string .="&productid=".vtlib_purify($_REQUEST['productid']);
}
$alphabetical = AlphabeticalSearch($currentModule,'Popup','bookname','true','basic',$popuptype,"","",$url);
break;
case 'Users':
require_once("modules/$currentModule/Users.php");
$focus = new Users();
$smarty->assign("SINGLE_MOD",'Users');
if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] !='')
$smarty->assign("RETURN_MODULE",vtlib_purify($_REQUEST['return_module']));
$alphabetical = AlphabeticalSearch($currentModule,'Popup','user_name','true','basic',$popuptype,"","",$url);
if (isset($_REQUEST['select'])) $smarty->assign("SELECT",'enable');
break;
case 'HelpDesk':
require_once("modules/$currentModule/HelpDesk.php");
$focus = new HelpDesk();
$smarty->assign("SINGLE_MOD",'HelpDesk');
if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] !='')
$smarty->assign("RETURN_MODULE",vtlib_purify($_REQUEST['return_module']));
$alphabetical = AlphabeticalSearch($currentModule,'Popup','ticket_title','true','basic',$popuptype,"","",$url);
if (isset($_REQUEST['select'])) $smarty->assign("SELECT",'enable');
break;
case 'Documents':
require_once("modules/$currentModule/Documents.php");
$focus = new Documents();
$smarty->assign("SINGLE_MOD",'Document');
if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] !='')
$smarty->assign("RETURN_MODULE",vtlib_purify($_REQUEST['return_module']));
else
$smarty->assign("RETURN_MODULE",'Emails');
if (isset($_REQUEST['select'])) $smarty->assign("SELECT",'enable');
$alphabetical = AlphabeticalSearch($currentModule,'Popup','notes_title','true','basic',$popuptype,"","",$url);
break;
// Special case handling (for curr_row value) for Services module
case 'Services':
if(isset($_REQUEST['curr_row']))
{
$curr_row = vtlib_purify($_REQUEST['curr_row']);
$smarty->assign("CURR_ROW", $curr_row);
$url_string .="&curr_row=".vtlib_purify($_REQUEST['curr_row']);
}
// vtlib customization: Generic hook for Popup selection
default:
require_once("modules/$currentModule/$currentModule.php");
$focus = new $currentModule();
$smarty->assign("SINGLE_MOD", $currentModule);
if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] !='')
$smarty->assign("RETURN_MODULE",vtlib_purify($_REQUEST['return_module']));
$alphabetical = AlphabeticalSearch($currentModule,'Popup',$focus->def_basicsearch_col,'true','basic',$popuptype,"","",$url);
if (isset($_REQUEST['select'])) $smarty->assign("SELECT",'enable');
break;
// END
}
// vtlib customization: Initialize focus to get generic popup
if($_REQUEST['form'] == 'vtlibPopupView') {
vtlib_setup_modulevars($currentModule, $focus);
}
// END
$smarty->assign("RETURN_ACTION",vtlib_purify($_REQUEST['return_action']));
//Retreive the list from Database
if($currentModule == 'PriceBooks')
{
$productid=$_REQUEST['productid'];
$currency_id=$_REQUEST['currencyid'];
if($currency_id == null) $currency_id = fetchCurrency($current_user->id);
$query = 'select vtiger_pricebook.*, vtiger_pricebookproductrel.productid, vtiger_pricebookproductrel.listprice, ' .
'vtiger_crmentity.crmid, vtiger_crmentity.smownerid, vtiger_crmentity.modifiedtime ' .
'from vtiger_pricebook inner join vtiger_pricebookproductrel on vtiger_pricebookproductrel.pricebookid = vtiger_pricebook.pricebookid ' .
'inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_pricebook.pricebookid ' .
'where vtiger_pricebookproductrel.productid='.$adb->sql_escape_string($productid).' and vtiger_crmentity.deleted=0 ' .
'and vtiger_pricebook.currency_id='.$adb->sql_escape_string($currency_id).' and vtiger_pricebook.active=1';
}
else
{
if(isset($_REQUEST['recordid']) && $_REQUEST['recordid'] != '')
{
$smarty->assign("RECORDID",vtlib_purify($_REQUEST['recordid']));
$url_string .='&recordid='.vtlib_purify($_REQUEST['recordid']);
$where_relquery = getRelCheckquery($currentModule,$_REQUEST['return_module'],$_REQUEST['recordid']);
}
if(isset($_REQUEST['relmod_id']) || isset($_REQUEST['fromPotential']))
{
if($_REQUEST['relmod_id'] !='')
{
$mod = vtlib_purify($_REQUEST['parent_module']);
$id = vtlib_purify($_REQUEST['relmod_id']);
}
else if($_REQUEST['fromPotential'] != '')
{
$mod = "Accounts";
$id= vtlib_purify($_REQUEST['acc_id']);
}
$smarty->assign("mod_var_name", "parent_module");
$smarty->assign("mod_var_value", $mod);
$smarty->assign("recid_var_name", "relmod_id");
$smarty->assign("recid_var_value",$id);
$where_relquery.= getPopupCheckquery($currentModule,$mod,$id);
}
else if(isset($_REQUEST['task_relmod_id']))
{
$smarty->assign("mod_var_name", "task_parent_module");
$smarty->assign("mod_var_value", vtlib_purify($_REQUEST['task_parent_module']));
$smarty->assign("recid_var_name", "task_relmod_id");
$smarty->assign("recid_var_value",vtlib_purify($_REQUEST['task_relmod_id']));
$where_relquery.= getPopupCheckquery($currentModule,$_REQUEST['task_parent_module'],$_REQUEST['task_relmod_id']);
}
if($currentModule == 'Products' && !$_REQUEST['record_id'] && ($popuptype == 'inventory_prod' || $popuptype == 'inventory_prod_po'))
$where_relquery .=" and vtiger_products.discontinued <> 0 AND (vtiger_products.productid NOT IN (SELECT crmid FROM vtiger_seproductsrel WHERE setype='Products'))";
elseif($currentModule == 'Products' && $_REQUEST['record_id'] && ($popuptype == 'inventory_prod' || $popuptype == 'inventory_prod_po'))
$where_relquery .=" and vtiger_products.discontinued <> 0 AND (vtiger_products.productid IN (SELECT crmid FROM vtiger_seproductsrel WHERE setype='Products' AND productid=".$adb->sql_escape_string($_REQUEST['record_id'])."))";
elseif($currentModule == 'Products' && $_REQUEST['return_module'] != 'Products')
$where_relquery .=" and vtiger_products.discontinued <> 0";
if($_REQUEST['return_module'] == 'Products' && $currentModule == 'Products' && $_REQUEST['recordid'])
$where_relquery .=" and vtiger_products.discontinued <> 0 AND (vtiger_crmentity.crmid NOT IN (".$adb->sql_escape_string($_REQUEST['recordid']).") AND vtiger_crmentity.crmid NOT IN (SELECT productid FROM vtiger_seproductsrel WHERE setype='Products') AND vtiger_crmentity.crmid NOT IN (SELECT crmid FROM vtiger_seproductsrel WHERE setype='Products' AND productid=".$adb->sql_escape_string($_REQUEST['recordid'])."))";
if($currentModule == 'Services' && $popuptype == 'inventory_service') {
$where_relquery .=" and vtiger_service.discontinued <> 0";
}
//Avoiding Current Record to show up in the popups When editing.
if($currentModule == 'Accounts' && $_REQUEST['recordid']!=''){
$where_relquery .=" and vtiger_account.accountid!=".$adb->sql_escape_string($_REQUEST['recordid']);
$smarty->assign("RECORDID",vtlib_purify($_REQUEST['recordid']));
}
if($currentModule == 'Contacts' && $_REQUEST['recordid']!=''){
$where_relquery .=" and vtiger_contactdetails.contactid!=".$adb->sql_escape_string($_REQUEST['recordid']);
$smarty->assign("RECORDID",vtlib_purify($_REQUEST['recordid']));
}
if($currentModule == 'Users' && $_REQUEST['recordid']!=''){
$where_relquery .=" and vtiger_users.id!=".$adb->sql_escape_string($_REQUEST['recordid']);
$smarty->assign("RECORDID",vtlib_purify($_REQUEST['recordid']));
}
$query = getListQuery($currentModule,$where_relquery);
}
if($currentModule == 'Products' && $_REQUEST['record_id'] && ($popuptype == 'inventory_prod' || $popuptype == 'inventory_prod_po'))
{
$product_name = getProductName($_REQUEST['record_id']);
$smarty->assign("PRODUCT_NAME", $product_name);
$smarty->assign("RECORD_ID", vtlib_purify($_REQUEST['record_id']));
}
$listview_header_search=getSearchListHeaderValues($focus,"$currentModule",$url_string,$sorder,$order_by);
$smarty->assign("SEARCHLISTHEADER", $listview_header_search);
$smarty->assign("ALPHABETICAL", $alphabetical);
if(isset($_REQUEST['query']) && $_REQUEST['query'] == 'true')
{
list($where, $ustring) = split("#@@#",getWhereCondition($currentModule));
$url_string .="&query=true".$ustring;
}
if(isset($where) && $where != '')
{
$query .= ' and '.$where;
}
//Added to fix the issue #2307
$order_by = $focus->getOrderBy();
$sorder = $focus->getSortOrder();
if(isset($order_by) && $order_by != '')
{
$query .= ' ORDER BY '.$order_by.' '.$sorder;
}
// vtlib customization: To override module specific popup query for a given field
$override_query = false;
if(method_exists($focus, 'getQueryByModuleField')) {
$override_query = $focus->getQueryByModuleField(vtlib_purify($_REQUEST['srcmodule']), vtlib_purify($_REQUEST['forfield']), vtlib_purify($_REQUEST['forrecord']), $query);
if($override_query) {
$query = $override_query;
}
}
// END
if(PerformancePrefs::getBoolean('LISTVIEW_COMPUTE_PAGE_COUNT', false) === true){
$count_result = $adb->query( mkCountQuery( $query));
$noofrows = $adb->query_result($count_result,0,"count");
}else{
$noofrows = null;
}
//Retreiving the start value from request
if(isset($_REQUEST['start']) && $_REQUEST['start'] != '') {
$start = vtlib_purify($_REQUEST['start']);
if($start == 'last'){
$count_result = $adb->query( mkCountQuery($query));
$noofrows = $adb->query_result($count_result,0,"count");
if($noofrows > 0){
$start = ceil($noofrows/$list_max_entries_per_page);
}
}
if(!is_numeric($start)){
$start = 1;
}elseif($start < 1){
$start = 1;
}
$start = ceil($start);
} else {
$start = 1;
}
$limstart=($start-1)*$list_max_entries_per_page;
$query.=" LIMIT $limstart,$list_max_entries_per_page";
$list_result = $adb->query($query);
//Retreive the Navigation array
$navigation_array = VT_getSimpleNavigationValues($start, $list_max_entries_per_page,$noofrows);
//Retreive the List View Table Header
$focus->initSortbyField($currentModule);
$focus->list_mode="search";
$focus->popup_type=$popuptype;
$url_string .='&popuptype='.$popuptype;
if(isset($_REQUEST['select']) && $_REQUEST['select'] == 'enable')
$url_string .='&select=enable';
if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] != '')
$url_string .='&return_module='.vtlib_purify($_REQUEST['return_module']);
if($popuptype == 'set_return_emails'){
$tabid = getTabid($currentModule);
$mail_arr = getMailFields($tabid);
if(!empty($mail_arr)){
$tablename = str_replace("vtiger_","",$mail_arr['tablename']);
$fieldname = $mail_arr['fieldname'];
$fieldlabel = $mail_arr['fieldlabel'];
$focus->search_fields[$fieldlabel] = Array($tablename=>$fieldname);
$focus->search_fields_name[$fieldlabel] = $fieldname;
}
}
$listview_header = getSearchListViewHeader($focus,"$currentModule",$url_string,$sorder,$order_by);
$smarty->assign("LISTHEADER", $listview_header);
$smarty->assign("HEADERCOUNT",count($listview_header)+1);
$listview_entries = getSearchListViewEntries($focus,"$currentModule",$list_result,$navigation_array,$form);
$smarty->assign("LISTENTITY", $listview_entries);
$navigationOutput = getTableHeaderSimpleNavigation($navigation_array, $url_string,$currentModule,"Popup");
$smarty->assign("NAVIGATION", $navigationOutput);
$smarty->assign("RECORD_COUNTS", $record_string);
$smarty->assign("POPUPTYPE", $popuptype);
$smarty->assign("PARENT_MODULE", vtlib_purify($_REQUEST['parent_module']));
if(isset($_REQUEST['ajax']) && $_REQUEST['ajax'] != '')
$smarty->display("PopupContents.tpl");
else
$smarty->display("Popup.tpl");
?>