PageRenderTime 64ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 1ms

/modules/RecycleBin/ListView.php

https://bitbucket.org/jhunsinfotech/blue-blues
PHP | 232 lines | 178 code | 38 blank | 16 comment | 40 complexity | f11a58e532a05067a64d07b54f5d7c5b MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, LGPL-3.0
  1. <?php
  2. /*+**********************************************************************************
  3. * The contents of this file are subject to the vtiger CRM Public License Version 1.0
  4. * ("License"); You may not use this file except in compliance with the License
  5. * The Original Code is: vtiger CRM Open Source
  6. * The Initial Developer of the Original Code is vtiger.
  7. * Portions created by vtiger are Copyright (C) vtiger.
  8. * All Rights Reserved.
  9. ************************************************************************************/
  10. global $app_strings, $mod_strings, $current_language, $currentModule, $theme;
  11. require_once('Smarty_setup.php');
  12. require_once('include/ListView/ListView.php');
  13. require_once('include/utils/utils.php');
  14. require_once('modules/CustomView/CustomView.php');
  15. require_once('modules/RecycleBin/RecycleBinUtils.php');
  16. global $adb, $log, $list_max_entries_per_page;
  17. $theme_path="themes/".$theme."/";
  18. $image_path=$theme_path."images/";
  19. require_once('modules/Vtiger/layout_utils.php');
  20. require("user_privileges/user_privileges_".$current_user->id.".php");
  21. $smarty = new vtigerCRM_Smarty;
  22. // Data from the below modules will not be allowed to restore
  23. $skip_modules = array('Webmails');
  24. $skip_tab_ids = array();
  25. for($i=0; $i<count($skip_modules); $i++) {
  26. $tab_id = getTabid($skip_modules[$i]);
  27. if ($tab_id != null && $tab_id != '') $skip_tab_ids[] = $tab_id;
  28. }
  29. $sql = 'SELECT tabid, name FROM vtiger_tab WHERE presence=0 AND isentitytype=1 ';
  30. if (count($skip_tab_ids) > 0) {
  31. $sql .= ' AND tabid NOT IN ('. generateQuestionMarks($skip_tab_ids) .')';
  32. }
  33. $sql .= ' ORDER BY name';
  34. $result =$adb->pquery($sql, array($skip_tab_ids));
  35. $noofrows = $adb->num_rows($result);
  36. $module_name =Array();
  37. $module_data =Array();
  38. if($noofrows > 0) {
  39. for($x=0,$y=0; $x<$noofrows;$x++) {
  40. $tabid = $adb->query_result($result,$x,'tabid');
  41. if($is_admin || $profileGlobalPermission[2]==0 || $profileGlobalPermission[1]==0 || $profileTabsPermission[$tabid]==0) {
  42. $mod_name = $adb->query_result($result,$x,"name");
  43. $module_name[$y] = $mod_name;
  44. $y++;
  45. }
  46. }
  47. }
  48. if(isset($_REQUEST['selected_module']) && $_REQUEST['selected_module'] != '') {
  49. $select_module = vtlib_purify($_REQUEST['selected_module']);
  50. if (!in_array($select_module, $module_name)) {
  51. show_error_msg();
  52. }
  53. } else {
  54. if (count($module_name) > 0) {
  55. $select_module = $module_name[0];
  56. } else {
  57. show_error_msg('no_permitted_modules');
  58. }
  59. }
  60. $focus = CRMEntity::getInstance($select_module);
  61. if(count($module_name) > 0)
  62. {
  63. $cur_mod_view = new CustomView($select_module);
  64. $viewid = $cur_mod_view->getViewIdByName('All', $select_module);
  65. global $current_user;
  66. $queryGenerator = new QueryGenerator($select_module, $current_user);
  67. $queryGenerator->initForCustomViewById($viewid);
  68. // Enabling Module Search
  69. $url_string = '';
  70. if($_REQUEST['query'] == 'true') {
  71. $queryGenerator->addUserSearchConditions($_REQUEST);
  72. $ustring = getSearchURL($_REQUEST);
  73. $url_string .= "&query=true$ustring";
  74. $smarty->assign('SEARCH_URL', $url_string);
  75. }
  76. $list_query = $queryGenerator->getQuery();
  77. $list_query = preg_replace("/vtiger_crmentity.deleted\s*=\s*0/i", 'vtiger_crmentity.deleted = 1', $list_query);
  78. //Search criteria added to the list Query
  79. if(isset($where) && $where != '')
  80. {
  81. $list_query .= ' AND '.$where;
  82. }
  83. $count_result = $adb->query( mkCountQuery($list_query));
  84. $noofrows = $adb->query_result($count_result,0,"count");
  85. $smarty->assign("NUMOFROWS", $noofrows);
  86. $controller = new ListViewController($adb, $current_user, $queryGenerator);
  87. $rb_listview_header = $controller->getListViewHeader($focus,$select_module,$url_string,$sorder,
  88. $order_by, true);
  89. $listview_header_search = $controller->getBasicSearchFieldInfoList();
  90. $smarty->assign("SEARCHLISTHEADER", $listview_header_search);
  91. if(isset($_REQUEST['start']) && $_REQUEST['start'] != '')
  92. $start = vtlib_purify($_REQUEST['start']);
  93. else
  94. $start = 1;
  95. $navigation_array = getNavigationValues($start, $noofrows, $list_max_entries_per_page);
  96. // Setting the record count string
  97. //modified by rdhital
  98. $start_rec = $navigation_array['start'];
  99. $end_rec = $navigation_array['end_val'];
  100. //By Raju Ends
  101. //limiting the query
  102. if ($start_rec ==0)
  103. $limit_start_rec = 0;
  104. else
  105. $limit_start_rec = $start_rec -1;
  106. if( $adb->dbType == "pgsql")
  107. $list_result = $adb->query($list_query. " OFFSET ".$limit_start_rec." LIMIT ".$list_max_entries_per_page);
  108. else
  109. $list_result = $adb->query($list_query. " LIMIT ".$limit_start_rec.",".$list_max_entries_per_page);
  110. $record_string= $app_strings[LBL_SHOWING]." " .$start_rec." - ".$end_rec." " .$app_strings[LBL_LIST_OF] ." ".$noofrows;
  111. $navigationOutput = getTableHeaderNavigation($navigation_array, $url_string,"Recyclebin","index","");
  112. $lvEntries = $controller->getListViewEntries($focus,$select_module,$list_result,
  113. $navigation_array, true);
  114. }
  115. $smarty->assign("NAVIGATION", $navigationOutput);
  116. $smarty->assign("RECORD_COUNTS", $record_string);
  117. $smarty->assign('MAX_RECORDS', $list_max_entries_per_page);
  118. //to get the field name that mentions the module
  119. $query = "SELECT fieldname,tablename FROM vtiger_entityname WHERE modulename =?";
  120. $queryResult = $adb->pquery($query, array($select_module));
  121. $moduleColumnName = $adb->query_result($queryResult,0,'fieldname');
  122. $moduleTableName = $adb->query_result($queryResult,0,'tablename');
  123. if(strpos($moduleColumnName,','))
  124. {
  125. $field_array = explode(',',$moduleColumnName);
  126. $moduleColumnName = $field_array[0];
  127. }
  128. $query = "SELECT fieldname FROM vtiger_field WHERE tablename=? and columnname=?";
  129. $moduleFieldName = $adb->query_result($adb->pquery($query, array($moduleTableName,$moduleColumnName)),0,'fieldname');
  130. $indexField = $moduleFieldName;
  131. $alphabetical = AlphabeticalSearch($currentModule,'index',$indexField,'true','basic',"","","","",$viewid);
  132. $category = getParentTab();;
  133. $check_button = Button_Check($_REQUEST['module']);
  134. $check_button['EditView'] = 'no';
  135. $smarty->assign("CHECK", $check_button);
  136. $smarty->assign("ALPHABETICAL", $alphabetical);
  137. $smarty->assign("NUMBER_MODULES",$noofrows);
  138. $smarty->assign("MODULE_NAME",$module_name);
  139. $smarty->assign("SELECTED_MODULE",$select_module);
  140. $smarty->assign("MODULE_DATA",$rb_listview_header);
  141. $smarty->assign("MOD", $mod_strings);
  142. $smarty->assign("MODULE",$currentModule);
  143. $smarty->assign("CATEGORY",$category);
  144. $smarty->assign("THEME",$theme);
  145. $smarty->assign("IMAGE_PATH",$image_path);
  146. $smarty->assign("APP", $app_strings);
  147. $smarty->assign("CMOD", return_module_language($current_language,$select_module));
  148. $smarty->assign("lvEntries", $lvEntries);
  149. $smarty->assign("ALLSELECTEDIDS", vtlib_purify($_REQUEST['allselobjs']));
  150. $smarty->assign("CURRENT_PAGE_BOXES", implode(array_keys($lvEntries),";"));
  151. $smarty->assign("IS_ADMIN", $is_admin);
  152. if($_REQUEST['mode'] != 'ajax') {
  153. $smarty->display(vtlib_getModuleTemplate($currentModule,'RecycleBin.tpl'));
  154. } else {
  155. $smarty->display(vtlib_getModuleTemplate($currentModule,'RecycleBinContents.tpl'));
  156. }
  157. function show_error_msg($error_type='permission_denied') {
  158. global $theme;
  159. if ($error_type == 'permission_denied') {
  160. echo "<link rel='stylesheet' type='text/css' href='themes/$theme/style.css'>";
  161. echo "<table border='0' cellpadding='5' cellspacing='0' width='100%' height='450px'><tr><td align='center'>";
  162. echo "<div style='border: 3px solid rgb(153, 153, 153); background-color: rgb(255, 255, 255); width: 55%; position: relative; z-index: 10000000;'>
  163. <table border='0' cellpadding='5' cellspacing='0' width='98%'>
  164. <tbody><tr>
  165. <td rowspan='2' width='11%'><img src='" . vtiger_imageurl('denied.gif', $theme) . "' ></td>
  166. <td style='border-bottom: 1px solid rgb(204, 204, 204);' nowrap='nowrap' width='70%'><span class='genHeaderSmall'>"
  167. . getTranslatedString('LBL_PERMISSION') . "</span></td>
  168. </tr>
  169. <tr>
  170. <td class='small' align='right' nowrap='nowrap'>
  171. <a href='javascript:window.history.back();'>" . getTranslatedString('LBL_GO_BACK') . "</a><br>
  172. </td>
  173. </tr>
  174. </tbody></table>
  175. </div>";
  176. echo "</td></tr></table>";
  177. die();
  178. } else if ($error_type == 'no_permitted_modules') {
  179. echo "<link rel='stylesheet' type='text/css' href='themes/$theme/style.css'>";
  180. echo "<table border='0' cellpadding='5' cellspacing='0' width='100%' height='450px'><tr><td align='center'>";
  181. echo "<div style='border: 3px solid rgb(153, 153, 153); background-color: rgb(255, 255, 255); width: 55%; position: relative; z-index: 10000000;'>
  182. <table border='0' cellpadding='5' cellspacing='0' width='98%'>
  183. <tbody><tr>
  184. <td rowspan='2' width='11%'><img src='" . vtiger_imageurl('empty.jpg', $theme) . "' ></td>
  185. <td style='border-bottom: 1px solid rgb(204, 204, 204);' nowrap='nowrap' width='70%'><span class='genHeaderSmall'>"
  186. . getTranslatedString('LBL_NO_PERMITTED_MODULES') . "</span></td>
  187. </tr>
  188. </tbody></table>
  189. </div>";
  190. echo "</td></tr></table>";
  191. die();
  192. }
  193. }
  194. ?>