-
Notifications
You must be signed in to change notification settings - Fork 14
/
Popup.php
781 lines (738 loc) · 32.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
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
<?php
/*************************************
* SPDX-FileCopyrightText: 2009-2020 Vtenext S.r.l. <[email protected]>
* SPDX-License-Identifier: AGPL-3.0-only
************************************/
require_once("data/Tracker.php");
require_once('include/logging.php');
require_once('include/ListView/ListView.php');
require_once('include/database/PearDatabase.php');
require_once('include/ComboUtil.php');
require_once('include/utils/utils.php');
global $app_strings,$app_list_strings; //DS-CR VlMe 10.4.2008 - add $app_list_strings
global $currentModule;
global $theme;
global $table_prefix;
$url_string = '';
if (VteSession::isEmpty('authenticated_user_id')) die('Unauthorized!'); // crmv@37463
$LVU = ListViewUtils::getInstance();
$smarty = new VteSmarty();
if (!isset($where)) $where = "";
if(isset($_REQUEST['parenttab']) && $_REQUEST['parenttab']){
$parent_tab=$_REQUEST['parenttab'];
$smarty->assign("CATEGORY",$parent_tab);}
$url = '';
$popuptype = '';
$popuptype = $_REQUEST["popuptype"];
//crmv@137077
require_once('include/utils/ModuleHomeView.php');
$MHW = ModuleHomeView::getInstance($currentModule, $current_user->id);
$MHW->setModHomeListId();
//crmv@137077e
//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 = $_REQUEST['maintab'];
$url = "&maintab=".$act_tab;
}
$smarty->assign("MAINTAB",$act_tab);
switch($currentModule)
{
case 'Contacts':
$focus = CRMEntity::getInstance($currentModule);
$log = LoggerManager::getLogger('contact_list');
$smarty->assign("SINGLE_MOD",'Contact');
if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] !='')
$smarty->assign("RETURN_MODULE",$_REQUEST['return_module']);
else
$smarty->assign("RETURN_MODULE",'Emails');
if (isset($_REQUEST['select'])) $smarty->assign("SELECT",'enable');
if (isset($_REQUEST['form'])) $smarty->assign("FORM",$_REQUEST['form']); //crmv@138218
$alphabetical = $LVU->AlphabeticalSearch($currentModule,'Popup','lastname','true','basic',$popuptype,"","",$url);
break;
case 'Campaigns':
$focus = CRMEntity::getInstance($currentModule);
$log = LoggerManager::getLogger('campaign_list');
$smarty->assign("SINGLE_MOD",'Campaign');
if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] !='')
$smarty->assign("RETURN_MODULE",$_REQUEST['return_module']);
if (isset($_REQUEST['select'])) $smarty->assign("SELECT",'enable');
$alphabetical = $LVU->AlphabeticalSearch($currentModule,'Popup','campaignname','true','basic',$popuptype,"","",$url);
break;
case 'Accounts':
$focus = CRMEntity::getInstance($currentModule);
$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",$_REQUEST['return_module']);
else
$smarty->assign("RETURN_MODULE",'Emails');
$alphabetical = $LVU->AlphabeticalSearch($currentModule,'Popup','accountname','true','basic',$popuptype,"","",$url);
break;
case 'Leads':
$focus = CRMEntity::getInstance($currentModule);
$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",$_REQUEST['return_module']);
else
$smarty->assign("RETURN_MODULE",'Emails');
$alphabetical = $LVU->AlphabeticalSearch($currentModule,'Popup','lastname','true','basic',$popuptype,"","",$url);
break;
case 'Potentials':
$focus = CRMEntity::getInstance($currentModule);
$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",$_REQUEST['return_module']);
$alphabetical = $LVU->AlphabeticalSearch($currentModule,'Popup','potentialname','true','basic',$popuptype,"","",$url);
break;
case 'Quotes':
$focus = CRMEntity::getInstance($currentModule);
$log = LoggerManager::getLogger('quotes_list');
$smarty->assign("SINGLE_MOD",'Quote');
//crmv@14492
if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] !='')
$smarty->assign("RETURN_MODULE",$_REQUEST['return_module']);
//crmv@14492 end
$alphabetical = $LVU->AlphabeticalSearch($currentModule,'Popup','subject','true','basic',$popuptype,"","",$url);
break;
case 'Invoice':
$focus = CRMEntity::getInstance($currentModule);
$smarty->assign("SINGLE_MOD",'Invoice');
if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] !='')
$smarty->assign("RETURN_MODULE",$_REQUEST['return_module']);
$alphabetical = $LVU->AlphabeticalSearch($currentModule,'Popup','subject','true','basic',$popuptype,"","",$url);
break;
case 'Products':
$focus = CRMEntity::getInstance($currentModule);
$smarty->assign("SINGLE_MOD",'Product');
if(isset($_REQUEST['curr_row']))
{
$curr_row = $_REQUEST['curr_row'];
$smarty->assign("CURR_ROW", $curr_row);
$url_string .="&curr_row=".$_REQUEST['curr_row'];
}
if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] !='')
$smarty->assign("RETURN_MODULE",$_REQUEST['return_module']);
if (isset($_REQUEST['select'])) $smarty->assign("SELECT",'enable');
$alphabetical = $LVU->AlphabeticalSearch($currentModule,'Popup','productname','true','basic',$popuptype,"","",$url);
break;
case 'Vendors':
$focus = CRMEntity::getInstance($currentModule);
$smarty->assign("SINGLE_MOD",'Vendor');
//denis - senza le related dei fornitori non lasciano selezionare nulla
if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] !='')
$smarty->assign("RETURN_MODULE",$_REQUEST['return_module']);
//denis e
if (isset($_REQUEST['select'])) $smarty->assign("SELECT",'enable');//crmv@22366
$alphabetical = $LVU->AlphabeticalSearch($currentModule,'Popup','vendorname','true','basic',$popuptype,"","",$url);
break;
case 'SalesOrder':
$focus = CRMEntity::getInstance($currentModule);
$smarty->assign("SINGLE_MOD",'SalesOrder');
if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] !='')
$smarty->assign("RETURN_MODULE",$_REQUEST['return_module']);
$alphabetical = $LVU->AlphabeticalSearch($currentModule,'Popup','subject','true','basic',$popuptype,"","",$url);
break;
case 'PurchaseOrder':
$focus = CRMEntity::getInstance($currentModule);
$smarty->assign("SINGLE_MOD",'PurchaseOrder');
if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] !='')
$smarty->assign("RETURN_MODULE",$_REQUEST['return_module']);
$alphabetical = $LVU->AlphabeticalSearch($currentModule,'Popup','subject','true','basic',$popuptype,"","",$url);
break;
case 'PriceBooks':
$focus = CRMEntity::getInstance($currentModule);
$smarty->assign("SINGLE_MOD",'PriceBook');
if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] !='')
$smarty->assign("RETURN_MODULE",$_REQUEST['return_module']);
if(isset($_REQUEST['fldname']) && $_REQUEST['fldname'] !='')
{
$smarty->assign("FIELDNAME",$_REQUEST['fldname']);
$url_string .="&fldname=".$_REQUEST['fldname'];
}
if(isset($_REQUEST['productid']) && $_REQUEST['productid'] !='')
{
$smarty->assign("PRODUCTID",$_REQUEST['productid']);
$url_string .="&productid=".$_REQUEST['productid'];
}
$alphabetical = $LVU->AlphabeticalSearch($currentModule,'Popup','bookname','true','basic',$popuptype,"","",$url);
break;
case 'Users':
require_once("modules/$currentModule/Users.php");
$focus = CRMEntity::getInstance('Users');
$smarty->assign("SINGLE_MOD",'Users');
if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] !='')
$smarty->assign("RETURN_MODULE",$_REQUEST['return_module']);
$alphabetical = $LVU->AlphabeticalSearch($currentModule,'Popup','user_name','true','basic',$popuptype,"","",$url);
if (isset($_REQUEST['select'])) $smarty->assign("SELECT",'enable');
break;
case 'HelpDesk':
$focus = CRMEntity::getInstance($currentModule);
$smarty->assign("SINGLE_MOD",'HelpDesk');
if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] !='')
$smarty->assign("RETURN_MODULE",$_REQUEST['return_module']);
$alphabetical = $LVU->AlphabeticalSearch($currentModule,'Popup','ticket_title','true','basic',$popuptype,"","",$url);
if (isset($_REQUEST['select'])) $smarty->assign("SELECT",'enable');
break;
case 'Documents':
$focus = CRMEntity::getInstance($currentModule);
$smarty->assign("SINGLE_MOD",'Note');
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 = $LVU->AlphabeticalSearch($currentModule,'Popup','notes_title','true','basic',$popuptype,"","",$url);
break;
case 'Workflow':
$focus = CRMEntity::getInstance($currentModule);
$smarty->assign("SINGLE_MOD",'Workflow');
if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] !='')
$smarty->assign("RETURN_MODULE",$_REQUEST['return_module']);
$alphabetical = $LVU->AlphabeticalSearch($currentModule,'Popup','phrase','true','basic',$popuptype,"","","");
if (isset($_REQUEST['select'])) $smarty->assign("SELECT",'enable');
break;
//ds@26
case 'Visitreport':
$focus = CRMEntity::getInstance($currentModule);
$smarty->assign("SINGLE_MOD",'Visitreport');
if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] !='')
$smarty->assign("RETURN_MODULE",$_REQUEST['return_module']);
$alphabetical = $LVU->AlphabeticalSearch($currentModule,'Popup','crmid','true','basic',$popuptype,"","","");
if (isset($_REQUEST['select'])) $smarty->assign("SELECT",'enable');
break;
//ds@26e
// 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']);
}
//crmv@26265
case 'Calendar';
$result = $adb->query("SELECT cvid FROM ".$table_prefix."_customview WHERE entitytype = 'Calendar' AND viewname = 'Tasks' AND status = 0");
if ($result && $adb->num_rows($result)) {
$smarty->assign("CVID_TASKS",$adb->query_result($result,0,'cvid'));
}
//crmv@26265e
// vtlib customization: Generic hook for Popup selection
default:
$focus = CRMEntity::getInstance($currentModule);
$smarty->assign("SINGLE_MOD", $currentModule);
if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] !='')
$smarty->assign("RETURN_MODULE",vtlib_purify($_REQUEST['return_module']));
$alphabetical = $LVU->AlphabeticalSearch($currentModule,'Popup',$focus->def_basicsearch_col,'true','basic',$popuptype,"","",$url); //crmv@21249
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",$_REQUEST['return_action']);
$theme_path="themes/".$theme."/";
$image_path=$theme_path."images/";
$smarty->assign("MOD", $mod_strings);
$smarty->assign("APP", $app_strings);
$smarty->assign("APPLIST", $app_list_strings["moduleList"]); //DS-CR VlMe 10.4.2008
$smarty->assign("IMAGE_PATH",$image_path);
$smarty->assign("THEME_PATH",$theme_path);
$smarty->assign("MODULE",$currentModule);
//Retreive the list from Database
if($currentModule == 'PriceBooks')
{
// crmv@37463
$productid=intval($_REQUEST['productid']);
$currency_id=intval($_REQUEST['currencyid']);
// crmv@37463e
if($currency_id == null) $currency_id = fetchCurrency($current_user->id);
$query = 'select '.$table_prefix.'_pricebook.*, '.$table_prefix.'_pricebookproductrel.productid, '.$table_prefix.'_pricebookproductrel.listprice, ' .
''.$table_prefix.'_crmentity.crmid, '.$table_prefix.'_crmentity.smownerid, '.$table_prefix.'_crmentity.modifiedtime ' .
'from '.$table_prefix.'_pricebook inner join '.$table_prefix.'_pricebookproductrel on '.$table_prefix.'_pricebookproductrel.pricebookid = '.$table_prefix.'_pricebook.pricebookid ' .
'inner join '.$table_prefix.'_crmentity on '.$table_prefix.'_crmentity.crmid = '.$table_prefix.'_pricebook.pricebookid ' .
'where '.$table_prefix.'_pricebookproductrel.productid='.$adb->sql_escape_string($productid).' and '.$table_prefix.'_crmentity.deleted=0 ' .
'and '.$table_prefix.'_pricebook.currency_id='.$adb->sql_escape_string($currency_id).' and '.$table_prefix.'_pricebook.active=1';
//crmv@21387
if($productid != '') {
$construct_query=false;
} else {
$construct_query=true;
}
//crmv@21387e
}
else
{
// crmv@37463
$recordid = intval($_REQUEST['recordid']);
$recordidAlt = intval($_REQUEST['record_id']);
$construct_query=true;
if($recordid > 0)
{
$smarty->assign("RECORDID",$recordid);
$url_string .='&recordid='.$recordid;
$where_relquery = $LVU->getRelCheckquery($currentModule,$_REQUEST['return_module'],$recordid);
}
// crmv@37463e
if ($_REQUEST['autocomplete'] != 'yes') { //crmv@29190
if(isset($_REQUEST['relmod_id']) || isset($_REQUEST['fromPotential']))
{
if($_REQUEST['relmod_id'] !='')
{
$mod = $_REQUEST['parent_module'];
$id = $_REQUEST['relmod_id'];
}
else if($_REQUEST['fromPotential'] != '')
{
$mod = "Accounts";
$id= $_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.= $LVU->getPopupCheckquery($currentModule,$mod,$id);
}
else if(isset($_REQUEST['task_relmod_id']))
{
$smarty->assign("mod_var_name", "task_parent_module");
$smarty->assign("mod_var_value", $_REQUEST['task_parent_module']);
$smarty->assign("recid_var_name", "task_relmod_id");
$smarty->assign("recid_var_value",$_REQUEST['task_relmod_id']);
$where_relquery.= $LVU->getPopupCheckquery($currentModule,$_REQUEST['task_parent_module'],$_REQUEST['task_relmod_id']);
}
} //crmv@29190
//sk@2
if($currentModule == 'HelpDesk' && trim($_REQUEST['stopids'],":")!=''){
$where_relquery .= " and ".$table_prefix."_troubletickets.ticketid not in (".str_replace(":",",",trim($_REQUEST['stopids'],":")).")";
}
//sk@2e
if($currentModule == 'Products' && !$_REQUEST['record_id'] && ($popuptype == 'inventory_prod' || $popuptype == 'inventory_prod_po'))
$where_relquery .=" and ".$table_prefix."_products.discontinued <> 0 AND (".$table_prefix."_products.productid NOT IN (SELECT crmid FROM ".$table_prefix."_seproductsrel WHERE setype='Products'))";
elseif($currentModule == 'Products' && $_REQUEST['record_id'] && ($popuptype == 'inventory_prod' || $popuptype == 'inventory_prod_po'))
$where_relquery .=" and ".$table_prefix."_products.discontinued <> 0 AND (".$table_prefix."_products.productid IN (SELECT crmid FROM ".$table_prefix."_seproductsrel WHERE setype='Products' AND productid=".$adb->sql_escape_string($_REQUEST['record_id'])."))";
elseif($currentModule == 'Products' && $_REQUEST['return_module'] != 'Products')
$where_relquery .=" and ".$table_prefix."_products.discontinued <> 0";
if($_REQUEST['return_module'] == 'Products' && $currentModule == 'Products' && $_REQUEST['recordid'])
$where_relquery .=" and ".$table_prefix."_products.discontinued <> 0 AND (".$table_prefix."_crmentity.crmid NOT IN (".$adb->sql_escape_string($_REQUEST['recordid']).") AND ".$table_prefix."_crmentity.crmid NOT IN (SELECT productid FROM ".$table_prefix."_seproductsrel WHERE setype='Products') AND ".$table_prefix."_crmentity.crmid NOT IN (SELECT crmid FROM ".$table_prefix."_seproductsrel WHERE setype='Products' AND productid=".$adb->sql_escape_string($_REQUEST['recordid'])."))";
if($currentModule == 'Services' && $popuptype == 'inventory_service') {
$where_relquery .=" and ".$table_prefix."_service.discontinued <> 0";
}
//Avoiding Current Record to show up in the popups When editing.
if($currentModule == 'Accounts' && $_REQUEST['recordid']!=''){
$where_relquery .=" and ".$table_prefix."_account.accountid!=".$adb->sql_escape_string($_REQUEST['recordid']);
$smarty->assign("RECORDID",vtlib_purify($_REQUEST['recordid']));
}
if($currentModule == 'Contacts' && $_REQUEST['recordid']!=''){
$where_relquery .=" and ".$table_prefix."_contactdetails.contactid!=".$adb->sql_escape_string($_REQUEST['recordid']);
$smarty->assign("RECORDID",vtlib_purify($_REQUEST['recordid']));
}
if($currentModule == 'Users' && $_REQUEST['recordid']!=''){
$where_relquery .=" and ".$table_prefix."_users.id!=".$adb->sql_escape_string($_REQUEST['recordid']);
$smarty->assign("RECORDID",vtlib_purify($_REQUEST['recordid']));
}
}
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']));
}
//crmv@24577
if(isset($_REQUEST['query']) && $_REQUEST['reset_query'] != 'true'){
//crmv@24577e
list($where, $ustring) = explode("#@@#",getWhereCondition($currentModule));
$url_string .="&query=true".$ustring;
}
if ($construct_query){
if(isset($where) && $where != '')
{
$where_relquery .= ' and '.$where;
}
$query = $LVU->getListQuery($currentModule,$where_relquery);
$query_count = $LVU->getListQuery($currentModule,$where_relquery);
}
else {
if(isset($where) && $where != '')
{
$where_relquery .= ' and '.$where;
}
$query .= $where_relquery;
$query_count = $query.$where_relquery;
}
// 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
//crmv@sdk-24186 //crmv@26265
$sdk_show_all_button = false;
$sdk_view_all = false;
if ($_REQUEST['sdk_view_all'] != '') {
$sdk_view_all = true;
}
if (!$sdk_view_all) {
$sdk_file = SDK::getPopupQuery('field',vtlib_purify($_REQUEST['srcmodule']),vtlib_purify($_REQUEST['forfield']));
if ($sdk_file != '' && Vtecrm_Utils::checkFileAccess($sdk_file)) {//crmv@198038
include($sdk_file);
//crmv@26920
$sdk_params = SDK::getPopupHiddenElements(vtlib_purify($_REQUEST['srcmodule']), vtlib_purify($_REQUEST['forfield']), true);
$smarty->assign('SDK_POPUP_PARAMS', $sdk_params);
//crmv@26920e
}
$sdk_file = SDK::getPopupQuery('related',vtlib_purify($_REQUEST['return_module']),vtlib_purify($_REQUEST['module']));
if ($sdk_file != '' && Vtecrm_Utils::checkFileAccess($sdk_file)) {//crmv@198038
include($sdk_file);
}
}
$smarty->assign('sdk_show_all_button', $sdk_show_all_button);
$smarty->assign('sdk_view_all', $sdk_view_all);
//crmv@sdk-24186e //crmv@26265e
//crmv@11597
//------------------------------------------------------------------------------------------------------------------------------------------
//crmv@popup customview
// Enabling Module Search
$url_string = '';
//crmv@24577
if($_REQUEST['query'] == 'true' && $_REQUEST['reset_query']!= 'true') {
//crmv@24577e
list($where, $ustring, $add_join) = explode('#@@#', getWhereCondition($currentModule)); //crmv@131239
$url_string .= "&query=true$ustring";
$smarty->assign('SEARCH_URL', $url_string);
}
// Custom View
$customView = CRMEntity::getInstance('CustomView',$currentModule);
$viewid = $customView->getViewId($currentModule);
$customview_html = $customView->getCustomViewCombo($viewid);
$viewnamedesc = $customView->getCustomViewByCvid($viewid);
// Feature available from 5.1
if(method_exists($customView, 'isPermittedChangeStatus')) {
// Approving or Denying status-public by the admin in CustomView
$statusdetails = $customView->isPermittedChangeStatus($viewnamedesc['status']);
// To check if a user is able to edit/delete a CustomView
$edit_permit = $customView->isPermittedCustomView($viewid,'EditView',$currentModule);
$delete_permit = $customView->isPermittedCustomView($viewid,'Delete',$currentModule);
$smarty->assign("CUSTOMVIEW_PERMISSION",$statusdetails);
$smarty->assign("CV_EDIT_PERMIT",$edit_permit);
$smarty->assign("CV_DELETE_PERMIT",$delete_permit);
}
// END
$smarty->assign("VIEWID", $viewid);
if($viewnamedesc['viewname'] == 'All') $smarty->assign('ALL', 'All');
if($viewid != "0" && trim($viewid) != '')
{
$stdfiltersql = $customView->getCVStdFilterSQL($viewid);
$advfiltersql = $customView->getCVAdvFilterSQL($viewid);
if(isset($stdfiltersql) && $stdfiltersql != '')
{
$list_where .= ' and '.$stdfiltersql;
}
if(isset($advfiltersql) && $advfiltersql != '')
{
$list_where .= ' and '.$advfiltersql;
}
$list_query = $customView->getModifiedCvListQuery($viewid,$query,$currentModule,$popuptype);
//crmv@25193
list($focus->customview_order_by,$focus->customview_sort_order) = $customView->getOrderByFilterSQL($viewid);
$sorder = $focus->getSortOrder();
$order_by = $focus->getOrderBy();
if(!empty($order_by) && $order_by != '' && $order_by != null) {
if($order_by == 'smownerid') $list_query .= ' ORDER BY user_name '.$sorder;
else {
$tablename = getTableNameForField($currentModule, $order_by);
$tablename = ($tablename != '')? ($tablename . '.') : '';
$list_query .= ' ORDER BY ' . $tablename . $order_by . ' ' . $sorder;
}
}
//crmv@25193e
}
else {
$list_query = $query;
}
if (!empty($add_join)) $list_query = str_ireplace(' where ',$add_join.' where ',$list_query); //crmv@131239
$smarty->assign("CUSTOMVIEW_OPTION",$customview_html);
//crmv@popup customview end
//------------------------------------------------------------------------------------------------------------------------------------------
//crmv@sdk-18508
$sdk_files = SDK::getViews($module,'popup_query');
if (!empty($sdk_files)) {
foreach($sdk_files as $sdk_file) {
include($sdk_file['src']);
}
}
//crmv@sdk-18508e
//crmv@29190 crmv@37463 crmv@146187
if ($_REQUEST['autocomplete'] == 'yes') {
// crmv@131921
$hasCategory = false; // crmv@198024
// use the All filter for the autocomplete
if ($module != 'Users' && !$override_query) { // crmv@157201
$queryGenerator = QueryGenerator::getInstance($module, $current_user);
$queryGenerator->initForAllCustomView();
$queryGenerator->addFieldAlias('id', 'crmid');
// add fields for popups
// TODO: move this shit in the module class!
if ($popuptype == 'inventory_prod' || $popuptype == 'inventory_prod_po' || $popuptype == 'inventory_service'){
$queryGenerator->addField('description');
if ($module == 'Products') {
$queryGenerator->addCondition('discontinued', 1, 'e');
// crmv@198024
if (vtlib_isModuleActive('ConfProducts')) {
$confprod = CRMEntity::getInstance('ConfProducts');
$queryGenerator->addField('confprodid');
$queryGenerator->addJoin($confprod->table_name, $confprod->table_index, $table_prefix.'_products', 'confproductid', 'LEFT', 'confprod');
$queryGenerator->appendRawSelect('COALESCE(confprod.productname, \'\') as category, '.$table_prefix.'_products.confprodinfo');
$hasCategory = true;
}
// crmv@198024e
}
}
$query = $queryGenerator->getQuery();
}
// crmv@131921e
$sdk_file = SDK::getPopupQuery('field',vtlib_purify($_REQUEST['srcmodule']),vtlib_purify($_REQUEST['forfield']));
if ($sdk_file != '' && Vtecrm_Utils::checkFileAccess($sdk_file)) {//crmv@198038
include($sdk_file);
}
$autoselect = vtlib_purify($_REQUEST['autocomplete_select']);
$autoselect = str_ireplace(array('--', '#', ';', '*', ' from '), '', $autoselect);
$query = 'select '.$autoselect.','.substr(trim($query),7);
if(strripos($query,'ORDER BY') > 0) {
$query = substr($query, 0, strripos($query,'ORDER BY'));
}
// create the query here, not in autocomplete.php
$autowhere = vtlib_purify($_REQUEST['autocomplete_where']);
$autowhereSql = ' and 0=1';
if (is_array($autowhere) && count($autowhere) > 0) {
$list = array();
foreach ($autowhere as $cond) {
$s = explode('###', $cond);
if (count($s) == 2 && strlen($s[1]) > 2) {
$colname = preg_replace('/[^a-z0-9_.]/i', '', $s[0]);
//crmv@94308
$s[1] = html_entity_decode($s[1]); // crmv@175498
if($adb->isMysql()){
$list[] = "$colname like '".formatForSqlLike($s[1])."'"; // crmv@198024
} else {
$list[] = "$colname like '%".$s[1]."%'";
}
//crmv@94308e
// crmv@198024
if ($module == 'Products' && $hasCategory) {
$list[] = "confprod.productname like '".formatForSqlLike($s[1])."'";
}
// crmv@198024e
}
}
if (count($list) > 0) {
$autowhereSql = ' and ('.implode(' or ', $list).')';
}
}
$query .= $autowhereSql;
$list_query = $query;
// crmv@198024
if ($module == 'Products' && $hasCategory) {
// order by category, nulls last
$list_query .= ' ORDER BY COALESCE(confprod.productname, \'ZZZ\') ASC';
}
// crmv@198024e
// crmv@198024
} else {
if ($module == 'Products' && vtlib_isModuleActive('ConfProducts')) {
$list_query = preg_replace("/ FROM {$table_prefix}_products /", ", {$table_prefix}_products.confprodinfo FROM {$table_prefix}_products ", $list_query);
}
}
//crmv@29190e crmv@37463e crmv@146187e crmv@198024e
// crmv@184368
// an ugly patch for that terrible calendar (mysql only)!
if ($currentModule == 'Calendar' && $adb->isMysql()) {
// limit to the 1st contact (it's N-N, but there's a field! WTF?!! )
$list_query = preg_replace(
"/JOIN {$table_prefix}_cntactivityrel.*?LEFT JOIN/i",
"JOIN {$table_prefix}_cntactivityrel ON {$table_prefix}_activity.activityid = (
SELECT car.contactid FROM {$table_prefix}_cntactivityrel car
WHERE car.activityid = {$table_prefix}_activity.activityid
ORDER BY contactid
LIMIT 1
)
LEFT JOIN",
$list_query
);
}
// crmv@184368e
$smarty->assign("CUSTOMCOUNTS_OPTION", $LVU->get_selection_options($currentModule, $noofrows));
$list_max_entries_per_page = $LVU->get_selection_options($currentModule, $noofrows, 'list');
if ($_REQUEST['calc_nav'] == 'true'){
//Retreive the List View Table Header
if($viewid !='')
$url_string .= "&viewname=".$viewid;
echo '&#&#&#';
echo get_navigation_values($list_query,$url_string,$currentModule,'',false,$viewid);
die();
}
if ($_REQUEST['ajax'] == 'true'
&& $_REQUEST['search']!= 'true'
&& $_REQUEST['changecount']!= 'true'
&& $_REQUEST['changecustomview']!= 'true')
{
if ($_REQUEST['noofrows'] != '')
$noofrows = $_REQUEST['noofrows'];
else {
$lvs_noofrows = getLVSDetails($currentModule,$viewid,'noofrows');
if ($lvs_noofrows != '') $noofrows = $lvs_noofrows;
}
if ($noofrows > 0){
$list_max_entries_per_page = $LVU->get_selection_options($currentModule, $noofrows, 'list');
$queryMode = (isset($_REQUEST['query']) && $_REQUEST['query'] == 'true');
$start = ListViewSession::getRequestCurrentPage($currentModule, $list_query, $viewid, $queryMode);
$navigation_array = VT_getSimpleNavigationValues($start,$list_max_entries_per_page,$noofrows);
$limit_start_rec = ($start-1) * $list_max_entries_per_page;
$record_string = getRecordRangeMessage($list_max_entries_per_page, $limit_start_rec,$noofrows);
$navigationOutput = $LVU->getTableHeaderSimpleNavigation($navigation_array, $url_string,$currentModule,$type,$viewid);
$smarty->assign("RECORD_COUNTS", $record_string);
$smarty->assign("NAVIGATION", $navigationOutput);
$smarty->assign("AJAX", 'true');
}
}
else {
$queryMode = (isset($_REQUEST['query']) && $_REQUEST['query'] == 'true');
//crmv@29190
if ($_REQUEST['autocomplete'] == 'yes')
$start = 2;
else
$start = ListViewSession::getRequestCurrentPage($currentModule, $list_query, $viewid, $queryMode);
//crmv@29190e
$limit_start_rec = ($start-1) * $list_max_entries_per_page;
if ($limit_start_rec >= $list_max_entries_per_page){
$start -= 1;
$limit_start_rec = ($start-1) * $list_max_entries_per_page;
setLVSDetails($currentModule,$viewid,$start,'start');
}
$navigation_array['current'] = $start;
$navigation_array['start'] = $start;
}
$list_result = $adb->limitQuery($list_query,$limit_start_rec,$list_max_entries_per_page); //crmv@33997
//crmv@11597 e
//Retreive the List View Table Header
$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='.$_REQUEST['return_module'];
//crmv@29190
if ($_REQUEST['autocomplete'] != 'yes') {
//crmv@29190e
$listview_header_search=getSearchListHeaderValues($focus,"$currentModule",$url_string,$sorder,$order_by,$relatedlist,$customView);
$smarty->assign("SEARCHLISTHEADER", $listview_header_search);
$listview_header = $LVU->getSearchListViewHeader($focus,"$currentModule",$url_string,$sorder,$order_by,$customView);
$smarty->assign("LISTHEADER", $listview_header);
$smarty->assign("HEADERCOUNT",count($listview_header)+1);
$smarty->assign('FROM_CALENDAR', $_REQUEST['fromCalendar']);//crmv@26807
$smarty->assign('MASS_LINK', $_REQUEST['mass_link']);//crmv@26510
//crmv@29190
}
//crmv@29190e
// crmv@126696
if (isset($_REQUEST['override_fn'])) {
$LVU->overrideReturnFunction($_REQUEST['override_fn']);
}
// crmv@126696e
$listview_entries = $LVU->getSearchListViewEntries($focus,"$currentModule",$list_result,$navigation_array,'',$customView);
//crmv@33997
if ($_REQUEST['autocomplete'] == 'yes') {
global $autocomplete_return_function;
if ($list_result) {
$list_result->MoveFirst(); //porto il resultset alla prima riga
while($row=$adb->fetchByAssoc($list_result,-1,false)) {
if($module == 'Calendar') {
$entity_id = 'activityid';
} elseif ($module == 'Users') {
$entity_id = 'id';
} else {
$entity_id = 'crmid';
}
// crmv@198024
$entry = array(
'id'=>$row[$entity_id],
'label'=>$row['displayname'],
'return_function'=>html_entity_decode($autocomplete_return_function[$row[$entity_id]],null,'UTF-8'), //crmv@34792
'return_function_file'=>"modules/$module/$module.js",
);
if ($hasCategory) {
$entry['category'] = $row['category'];
}
$autocomplete_return[] = $entry;
// crmv@198024e
}
}
die(Zend_Json::encode($autocomplete_return));
}
//crmv@33997e
$smarty->assign("LISTENTITY", $listview_entries);
$smarty->assign("DATEFORMAT",$current_user->date_format);
$smarty->assign("RECORD_COUNTS", $record_string);
$smarty->assign("POPUPTYPE", $popuptype);
//crmv@17997
$queryGenerator = QueryGenerator::getInstance($currentModule, $current_user);
$controller = ListViewController::getInstance($adb, $current_user, $queryGenerator);
$alphabetical = $LVU->AlphabeticalSearch($currentModule,'index',$focus->search_base_field,'true','basic',"","","","",$viewid);
$fieldnames = $controller->getAdvancedSearchOptionString(true);
//crmv@17997 end
$criteria = getcriteria_options();
$smarty->assign("CRITERIA", $criteria);
$smarty->assign("FIELDNAMES", $fieldnames);
$smarty->assign("ALPHABETICAL", $alphabetical);
if (isset($_REQUEST["selected_ids"]))
{
$smarty->assign("SELECTED_IDS_ARRAY", explode(";",$_REQUEST["selected_ids"]));
$smarty->assign("SELECTED_IDS", $_REQUEST["selected_ids"]);
}
if (isset($_REQUEST["all_ids"]))
{
$smarty->assign("ALL_IDS", $_REQUEST["all_ids"]);
}
// QuickCreatePopup
$qcreate_array = QuickCreate($currentModule);
if (!empty($qcreate_array['data'])) $smarty->assign('QUICKCREATE','permitted');
//crmv@sdk-18501
include_once('vtlib/Vtecrm/Link.php');
$hdrcustomlink_params = Array('MODULE'=>$currentModule);
$COMMONHDRLINKS = Vtecrm_Link::getAllByType(Vtecrm_Link::IGNORE_MODULE, Array('HEADERLINK','HEADERSCRIPT', 'HEADERCSS'), $hdrcustomlink_params);//crmv@198038
$smarty->assign('HEADERLINKS', $COMMONHDRLINKS['HEADERLINK']);
$smarty->assign('HEADERSCRIPTS', $COMMONHDRLINKS['HEADERSCRIPT']);
$smarty->assign('HEADERCSS', $COMMONHDRLINKS['HEADERCSS']);
//crmv@sdk-18501 e
// crmv@42024 - pass global JS vars to template
$JSGlobals = ( function_exists('getJSGlobalVars') ? getJSGlobalVars() : array() );
$smarty->assign('JS_GLOBAL_VARS',Zend_Json::encode($JSGlobals));
// crmv@42024e
// crmv@113400
$smarty_ajax_template = 'PopupContents.tpl';
$smarty_template = 'Popup.tpl';
$sdk_custom_file = 'PopupCustomisations';
if (isModuleInstalled('SDK')) {
$tmp_sdk_custom_file = SDK::getFile($currentModule,$sdk_custom_file);
if (!empty($tmp_sdk_custom_file)) {
$sdk_custom_file = $tmp_sdk_custom_file;
}
}
@include("modules/$currentModule/$sdk_custom_file.php");
if(isset($_REQUEST['ajax']) && $_REQUEST['ajax'] != '')
$smarty->display($smarty_ajax_template);
else
$smarty->display($smarty_template);
// crmv@113400e