/
listdata_related.php
executable file
·147 lines (130 loc) · 4.98 KB
/
listdata_related.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
<?php
// Copyright SQCRM. For licensing, reuse, modification and distribution see license.txt
/**
* Used for loading the data using the jquery datatable server side proceesing modal
* Gets the module name as a GET and gets the list query for the module
* The fileds information is stored in the memmber array list_view_field_information of the object
* @see view/related_listview.php
* @author Abhik Chakraborty
*/
include_once("config.php") ;
$m = $_GET["m"];
$related_method = $_GET["related_method"];
$object = '' ;
$mid = $_SESSION["do_module"]->get_idmodule_by_name($m,$_SESSION["do_module"]);
//Get the module from which the request is comming and use this object to other operation
$module = $_GET["module"];
$sqcrmid = (int)$_GET["sqcrmid"];
$do_crm_list_view = new CRMListView();
$related_object = $do_crm_list_view->get_list_view_object($m,"related");
$entity_table_name = $related_object->getTable() ;
$fields_info = $related_object->list_view_field_information ;
$primary_key = $related_object->primary_key;
$object = new $module();
$object->$related_method($sqcrmid);
/**
* FIXME
* For some reason when the array index starts with 0 the text box search works well but the asc/desc on the header does not
* So $aColumns array is used for text search and adding a new array $ahColumns for header sort
*/
$aColumns = array();
$col_count = 0 ;
foreach ($fields_info as $field_name=>$info) {
$aColumns[$col_count++] = $field_name ;
}
$ahColumns = array();
$hcol_count = 1 ;
foreach ($fields_info as $field_name=>$info) {
$ahColumns[$hcol_count++] = $field_name ;
}
$do_data_display = new DataDisplay();
if (isset($_GET["iDisplayStart"]) && $_GET["iDisplayLength"] != '-1') {
$do_data_display->set_ds_sql_start($_GET["iDisplayStart"]);
$do_data_display->set_ds_sql_max($_GET["iDisplayLength"]);
}
$sOrder = "";
if (isset( $_GET['iSortCol_0'])) {
$sOrder = "ORDER BY ";
for ($i=0 ; $i<intval( $_GET['iSortingCols'] ) ; $i++) {
if ($_GET[ 'bSortable_'.intval($_GET['iSortCol_'.$i]) ] == "true") {
$sort_order = (strtolower($_GET['sSortDir_'.$i]) == 'desc' ? 'desc' : 'asc');
if ($fields_info[$ahColumns[ intval( $_GET['iSortCol_'.$i] )]]["field_type"] == 131) {
if ($mid == 6) {
$sOrder .= " organization_member_of ".$sort_order .", ";
} else {
$sOrder .= " organization_name ".$sort_order .", ";
}
} elseif ($fields_info[$ahColumns[ intval( $_GET['iSortCol_'.$i] )]]["field_type"] == 130) {
if ($mid == 4) {
$sOrder .= " contact_report_to ".$sort_order .", ";
} else {
$sOrder .= " contact_name ".$sort_order .", ";
}
} elseif ($fields_info[$ahColumns[ intval( $_GET['iSortCol_'.$i] )]]["field_type"] == 150) {
$sOrder .= " related_to_value ".$sort_order .", ";
} else {
$sOrder .= $ahColumns[ intval( $_GET['iSortCol_'.$i] ) ]." ".$sort_order .", ";
}
}
}
$sOrder = substr_replace( $sOrder, "", -2 );
if ($sOrder == "ORDER BY") {
$sOrder = "";
}
}
if ($sOrder == "") {
$sOrder = " ORDER BY ". $related_object->get_default_order_by();
}
$do_data_display->set_ds_order_by($sOrder);
// Get the security parameter for the user and add to the where condition
$security_where = "";
$security_where = $_SESSION["do_crm_action_permission"]->get_user_where_condition($entity_table_name,$mid);
$do_data_display->set_ds_list_security($security_where);
/* Filtering - NOTE this does not match the built-in DataTables filtering which does it
* word by word on any field. It's possible to do here, but concerned about efficiency
* on very large tables, and MySQL's regex functionality is very limited
*/
$sWhere = "";
$search_param = array() ;
if ($_GET['sSearch'] != "") {
$sWhere .= " AND (";
for ($i=0;$i<count($aColumns);$i++) {
if ($i == (count($aColumns)-1)) {
if ($fields_info[$aColumns[$i]]["field_type"] == 15) { // assigned_to
$sWhere .= " `user`.`user_name` LIKE ? OR `group`.`group_name` LIKE ? )";
$search_param[] = '%'.$_GET['sSearch'].'%';
$search_param[] = '%'.$_GET['sSearch'].'%';
}
} else {
if ($fields_info[$aColumns[$i]]["field_type"] == 15) { // assigned_to
$sWhere .= " `user`.`user_name` LIKE ? OR `group`.`group_name` LIKE ? OR ";
$search_param[] = '%'.$_GET['sSearch'].'%';
$search_param[] = '%'.$_GET['sSearch'].'%';
} else {
$sWhere .= " ".$fields_info[$aColumns[$i]]["table"].".".$aColumns[$i]." LIKE ? OR ";
$search_param[] = '%'.$_GET['sSearch'].'%';
}
}
}
}
for ($i=0 ; $i<$_GET['iColumns'] ; $i++) {
if ($_GET['sSearch_'.$i] != ''){
if ($sWhere != "" ) {
$sWhere .= " AND ";
} else {
$sWhere .= "WHERE ";
}
}
}
//echo $sWhere;exit;
$do_data_display->set_ds_where_cond($sWhere);
$do_data_display->set_ds_search_params($search_param);
$do_data_display->set_ds_fields_info($fields_info);
$do_data_display->set_ds_show_record_selector(false);
$do_data_display->set_ds_object($object);
//-- while showing the related values do not use group by in Products
if($module == 'Products'){
$object->list_query_group_by = '';
}
$do_data_display->display_data($mid,false,$primary_key);
?>