/
ListView.php
240 lines (204 loc) · 9.41 KB
/
ListView.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
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
global $app_strings, $mod_strings, $current_language, $currentModule, $theme;
$list_max_entries_per_page = GlobalVariable::getVariable('Application_ListView_PageSize',20,$currentModule);
require_once('Smarty_setup.php');
require_once('include/ListView/ListView.php');
require_once('include/utils/utils.php');
require_once('modules/CustomView/CustomView.php');
require_once('modules/RecycleBin/RecycleBinUtils.php');
global $adb, $log, $current_user;
$theme_path="themes/".$theme."/";
$image_path=$theme_path."images/";
require_once('modules/Vtiger/layout_utils.php');
require("user_privileges/user_privileges_".$current_user->id.".php");
$smarty = new vtigerCRM_Smarty;
// Identify this module as custom module.
$smarty->assign('CUSTOM_MODULE', 'true');
// Data from the below modules will not be allowed to restore
$skip_modules = array('Webmails');
$skip_tab_ids = array();
for($i=0; $i<count($skip_modules); $i++) {
$tab_id = getTabid($skip_modules[$i]);
if ($tab_id != null && $tab_id != '') $skip_tab_ids[] = $tab_id;
}
$sql = 'SELECT tabid, name FROM vtiger_tab WHERE presence=0 AND isentitytype=1 ';
if (count($skip_tab_ids) > 0) {
$sql .= ' AND tabid NOT IN ('. generateQuestionMarks($skip_tab_ids) .')';
}
$sql .= ' ORDER BY name';
$result =$adb->pquery($sql, array($skip_tab_ids));
$noofrows = $adb->num_rows($result);
$module_name =Array();
$module_data =Array();
if($noofrows > 0) {
for($x=0,$y=0; $x<$noofrows;$x++) {
$tabid = $adb->query_result($result,$x,'tabid');
if($is_admin || $profileGlobalPermission[2]==0 || $profileGlobalPermission[1]==0 || $profileTabsPermission[$tabid]==0) {
$mod_name = $adb->query_result($result,$x,"name");
$module_name[$y] = $mod_name;
$y++;
}
}
}
if(isset($_REQUEST['selected_module']) && $_REQUEST['selected_module'] != '') {
$select_module = vtlib_purify($_REQUEST['selected_module']);
if (!in_array($select_module, $module_name)) {
show_error_msg();
}
} else {
if (count($module_name) > 0) {
$select_module = $module_name[0];
} else {
show_error_msg('no_permitted_modules');
}
}
$focus = CRMEntity::getInstance($select_module);
$sorder = $focus->getSortOrder();
$order_by = $focus->getOrderBy();
if(count($module_name) > 0)
{
$cur_mod_view = new CustomView($select_module);
$viewid = $cur_mod_view->getViewIdByName('All', $select_module);
$queryGenerator = new QueryGenerator($select_module, $current_user);
$queryGenerator->initForCustomViewById($viewid);
$rbfields = $queryGenerator->getFields();
if (!in_array('modifiedtime',$rbfields)) {
// Recycle Bin List view always shows modifiedtime
$rbfields[] = 'modifiedtime';
$queryGenerator->setFields($rbfields);
}
// Enabling Module Search
$url_string = '';
if(isset($_REQUEST['query']) and $_REQUEST['query'] == 'true') {
$queryGenerator->addUserSearchConditions($_REQUEST);
$ustring = getSearchURL($_REQUEST);
$url_string .= "&query=true$ustring";
$smarty->assign('SEARCH_URL', $url_string);
}
$list_query = $queryGenerator->getQuery();
$list_query = preg_replace("/vtiger_crmentity.deleted\s*=\s*0/i", 'vtiger_crmentity.deleted = 1', $list_query);
//Search criteria added to the list Query
if(isset($where) && $where != '')
{
$list_query .= ' AND '.$where;
}
$count_result = $adb->query( mkCountQuery($list_query));
$noofrows = $adb->query_result($count_result,0,"count");
$smarty->assign("NUMOFROWS", $noofrows);
$controller = new ListViewController($adb, $current_user, $queryGenerator);
$rb_listview_header = $controller->getListViewHeader($focus,$select_module,$url_string,$sorder,$order_by, true);
$listview_header_search = $controller->getBasicSearchFieldInfoList();
$smarty->assign("SEARCHLISTHEADER", $listview_header_search);
if(isset($_REQUEST['start']) && $_REQUEST['start'] != '')
$start = vtlib_purify($_REQUEST['start']);
else
$start = 1;
$navigation_array = getNavigationValues($start, $noofrows, $list_max_entries_per_page);
// Setting the record count string
$start_rec = $navigation_array['start'];
$end_rec = $navigation_array['end_val'];
//limiting the query
if ($start_rec ==0)
$limit_start_rec = 0;
else
$limit_start_rec = $start_rec -1;
$list_result = $adb->query($list_query. " LIMIT ".$limit_start_rec.",".$list_max_entries_per_page);
$record_string= $app_strings['LBL_SHOWING']." " .$start_rec." - ".$end_rec." " .$app_strings['LBL_LIST_OF'] ." ".$noofrows;
$navigationOutput = getTableHeaderNavigation($navigation_array, $url_string,"Recyclebin","index","");
$lvEntries = $controller->getListViewEntries($focus,$select_module,$list_result,$navigation_array, true);
}
$smarty->assign("NAVIGATION", $navigationOutput);
$smarty->assign("RECORD_COUNTS", $record_string);
$smarty->assign('MAX_RECORDS', $list_max_entries_per_page);
//to get the field name that mentions the module
$query = "SELECT fieldname,tablename FROM vtiger_entityname WHERE modulename =?";
$queryResult = $adb->pquery($query, array($select_module));
$moduleColumnName = $adb->query_result($queryResult,0,'fieldname');
$moduleTableName = $adb->query_result($queryResult,0,'tablename');
if(strpos($moduleColumnName,','))
{
$field_array = explode(',',$moduleColumnName);
$moduleColumnName = $field_array[0];
}
$query = "SELECT fieldname FROM vtiger_field WHERE tablename=? and columnname=?";
$rs = $adb->pquery($query, array($moduleTableName,$moduleColumnName));
$moduleFieldName = $adb->query_result($rs,0,'fieldname');
$indexField = $moduleFieldName;
$alphabetical = AlphabeticalSearch($currentModule,'index',$indexField,'true','basic',"","","","",$viewid);
$category = getParentTab();
$check_button = Button_Check($_REQUEST['module']);
$check_button['EditView'] = 'no';
$check_button['CreateView'] = 'no';
$check_button['Import'] = 'no';
$check_button['Export'] = 'no';
$check_button['Merge'] = 'no';
$check_button['DuplicatesHandling'] = 'no';
$smarty->assign("CHECK", $check_button);
$smarty->assign("ALPHABETICAL", $alphabetical);
$smarty->assign("NUMBER_MODULES",$noofrows);
uasort($module_name, function($a,$b) {return (strtolower(getTranslatedString($a,$a)) < strtolower(getTranslatedString($b,$b))) ? -1 : 1;});
$smarty->assign("MODULE_NAME",$module_name);
$smarty->assign("SELECTED_MODULE",$select_module);
$smarty->assign("MODULE_DATA",$rb_listview_header);
$smarty->assign("MOD", $mod_strings);
$smarty->assign("MODULE",$currentModule);
$smarty->assign("CATEGORY",$category);
$smarty->assign("THEME",$theme);
$smarty->assign("IMAGE_PATH",$image_path);
// Pass on the authenticated user language
$smarty->assign('LANGUAGE', $current_language);
$smarty->assign("APP", $app_strings);
$smarty->assign("CMOD", return_module_language($current_language,$select_module));
$smarty->assign("lvEntries", $lvEntries);
$smarty->assign('ALLSELECTEDIDS', (isset($_REQUEST['allselobjs']) ? vtlib_purify($_REQUEST['allselobjs']) : ''));
$smarty->assign("CURRENT_PAGE_BOXES", implode(array_keys($lvEntries),";"));
$smarty->assign("IS_ADMIN", $is_admin);
if(empty($_REQUEST['mode']) or $_REQUEST['mode'] != 'ajax') {
$smarty->display(vtlib_getModuleTemplate($currentModule,'RecycleBin.tpl'));
} else {
$smarty->display(vtlib_getModuleTemplate($currentModule,'RecycleBinContents.tpl'));
}
function show_error_msg($error_type='permission_denied') {
global $theme;
if ($error_type == 'permission_denied') {
echo "<link rel='stylesheet' type='text/css' href='themes/$theme/style.css'>";
echo "<table border='0' cellpadding='5' cellspacing='0' width='100%' height='450px'><tr><td align='center'>";
echo "<div style='border: 3px solid rgb(153, 153, 153); background-color: rgb(255, 255, 255); width: 55%; position: relative; z-index: 10000000;'>
<table border='0' cellpadding='5' cellspacing='0' width='98%'>
<tbody><tr>
<td rowspan='2' width='11%'><img src='" . vtiger_imageurl('denied.gif', $theme) . "' ></td>
<td style='border-bottom: 1px solid rgb(204, 204, 204);' nowrap='nowrap' width='70%'><span class='genHeaderSmall'>". getTranslatedString('LBL_PERMISSION') . "</span></td>
</tr>
<tr>
<td class='small' align='right' nowrap='nowrap'>
<a href='javascript:window.history.back();'>" . getTranslatedString('LBL_GO_BACK') . "</a><br>
</td>
</tr>
</tbody></table>
</div>
</td></tr></table>";
die();
} else if ($error_type == 'no_permitted_modules') {
echo "<link rel='stylesheet' type='text/css' href='themes/$theme/style.css'>";
echo "<table border='0' cellpadding='5' cellspacing='0' width='100%' height='450px'><tr><td align='center'>";
echo "<div style='border: 3px solid rgb(153, 153, 153); background-color: rgb(255, 255, 255); width: 55%; position: relative; z-index: 10000000;'>
<table border='0' cellpadding='5' cellspacing='0' width='98%'>
<tbody><tr>
<td rowspan='2' width='11%'><img src='" . vtiger_imageurl('empty.jpg', $theme) . "' ></td>
<td style='border-bottom: 1px solid rgb(204, 204, 204);' nowrap='nowrap' width='70%'><span class='genHeaderSmall'>". getTranslatedString('LBL_NO_PERMITTED_MODULES') . "</span></td>
</tr>
</tbody></table>
</div>
</td></tr></table>";
die();
}
}
?>