PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/vtlib/ModuleDir/5.1.0/ListView.php

https://bitbucket.org/yousef_fadila/vtiger
PHP | 190 lines | 130 code | 39 blank | 21 comment | 28 complexity | f8ab68b4fd1d46189c0d0c7684d0a658 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.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. global $list_max_entries_per_page;
  12. require_once('Smarty_setup.php');
  13. require_once('include/ListView/ListView.php');
  14. require_once('modules/CustomView/CustomView.php');
  15. require_once('include/DatabaseUtil.php');
  16. checkFileAccess("modules/$currentModule/$currentModule.php");
  17. require_once("modules/$currentModule/$currentModule.php");
  18. $category = getParentTab();
  19. $url_string = '';
  20. $tool_buttons = Button_Check($currentModule);
  21. $list_buttons = Array();
  22. if(isPermitted($currentModule,'Delete','') == 'yes') $list_buttons['del'] = $app_strings[LBL_MASS_DELETE];
  23. if(isPermitted($currentModule,'EditView','') == 'yes') {
  24. $list_buttons['mass_edit'] = $app_strings[LBL_MASS_EDIT];
  25. // Mass Edit could be used to change the owner as well!
  26. //$list_buttons['c_owner'] = $app_strings[LBL_CHANGE_OWNER];
  27. }
  28. $focus = new $currentModule();
  29. $focus->initSortbyField($currentModule);
  30. $sorder = $focus->getSortOrder();
  31. $order_by = $focus->getOrderBy();
  32. $_SESSION[$currentModule."_Order_by"] = $order_by;
  33. $_SESSION[$currentModule."_Sort_Order"]=$sorder;
  34. $smarty = new vtigerCRM_Smarty();
  35. // Identify this module as custom module.
  36. $smarty->assign('CUSTOM_MODULE', true);
  37. $smarty->assign('MOD', $mod_strings);
  38. $smarty->assign('APP', $app_strings);
  39. $smarty->assign('MODULE', $currentModule);
  40. $smarty->assign('SINGLE_MOD', getTranslatedString('SINGLE_'.$currentModule));
  41. $smarty->assign('CATEGORY', $category);
  42. $smarty->assign('BUTTONS', $list_buttons);
  43. $smarty->assign('CHECK', $tool_buttons);
  44. $smarty->assign('THEME', $theme);
  45. $smarty->assign('IMAGE_PATH', "themes/$theme/images/");
  46. $smarty->assign('CHANGE_OWNER', getUserslist());
  47. $smarty->assign('CHANGE_GROUP_OWNER', getGroupslist());
  48. // Enabling Module Search
  49. $url_string = '';
  50. if($_REQUEST['query'] == 'true') {
  51. list($where, $ustring) = split('#@@#', getWhereCondition($currentModule));
  52. $url_string .= "&query=true$ustring";
  53. $smarty->assign('SEARCH_URL', $url_string);
  54. }
  55. // Custom View
  56. $customView = new CustomView($currentModule);
  57. $viewid = $customView->getViewId($currentModule);
  58. $customview_html = $customView->getCustomViewCombo($viewid);
  59. $viewinfo = $customView->getCustomViewByCvid($viewid);
  60. // Feature available from 5.1
  61. if(method_exists($customView, 'isPermittedChangeStatus')) {
  62. // Approving or Denying status-public by the admin in CustomView
  63. $statusdetails = $customView->isPermittedChangeStatus($viewinfo['status']);
  64. // To check if a user is able to edit/delete a CustomView
  65. $edit_permit = $customView->isPermittedCustomView($viewid,'EditView',$currentModule);
  66. $delete_permit = $customView->isPermittedCustomView($viewid,'Delete',$currentModule);
  67. $smarty->assign("CUSTOMVIEW_PERMISSION",$statusdetails);
  68. $smarty->assign("CV_EDIT_PERMIT",$edit_permit);
  69. $smarty->assign("CV_DELETE_PERMIT",$delete_permit);
  70. }
  71. // END
  72. $smarty->assign("VIEWID", $viewid);
  73. if($viewinfo['viewname'] == 'All') $smarty->assign('ALL', 'All');
  74. if($viewid ==0)
  75. {
  76. echo "<table border='0' cellpadding='5' cellspacing='0' width='100%' height='450px'><tr><td align='center'>";
  77. echo "<div style='border: 3px solid rgb(153, 153, 153); background-color: rgb(255, 255, 255); width: 55%; position: relative; z-index: 10000000;'>
  78. <table border='0' cellpadding='5' cellspacing='0' width='98%'>
  79. <tbody><tr>
  80. <td rowspan='2' width='11%'><img src='". vtiger_imageurl('denied.gif', $theme) ."' ></td>
  81. <td style='border-bottom: 1px solid rgb(204, 204, 204);' nowrap='nowrap' width='70%'><span clas
  82. s='genHeaderSmall'>$app_strings[LBL_PERMISSION]</span></td>
  83. </tr>
  84. <tr>
  85. <td class='small' align='right' nowrap='nowrap'>
  86. <a href='javascript:window.history.back();'>$app_strings[LBL_GO_BACK]</a><br>
  87. </td>
  88. </tr>
  89. </tbody></table>
  90. </div>";
  91. echo "</td></tr></table>";
  92. exit;
  93. }
  94. $listquery = getListQuery($currentModule);
  95. $list_query= $customView->getModifiedCvListQuery($viewid, $listquery, $currentModule);
  96. if($where != '') {
  97. $list_query = "$list_query AND $where";
  98. }
  99. // Sorting
  100. if(!empty($order_by)) {
  101. if($order_by == 'smownerid') $list_query .= ' ORDER BY user_name '.$sorder;
  102. else {
  103. $tablename = getTableNameForField($currentModule, $order_by);
  104. $tablename = ($tablename != '')? ($tablename . '.') : '';
  105. $list_query .= ' ORDER BY ' . $tablename . $order_by . ' ' . $sorder;
  106. }
  107. }
  108. //Postgres 8 fixes
  109. if( $adb->dbType == "pgsql")
  110. $list_query = fixPostgresQuery( $list_query, $log, 0);
  111. if(PerformancePrefs::getBoolean('LISTVIEW_COMPUTE_PAGE_COUNT', false) === true){
  112. $count_result = $adb->query( mkCountQuery( $list_query));
  113. $noofrows = $adb->query_result($count_result,0,"count");
  114. }else{
  115. $noofrows = null;
  116. }
  117. $queryMode = (isset($_REQUEST['query']) && $_REQUEST['query'] == 'true');
  118. $start = ListViewSession::getRequestCurrentPage($currentModule, $list_query, $viewid, $queryMode);
  119. $navigation_array = VT_getSimpleNavigationValues($start,$list_max_entries_per_page,$noofrows);
  120. $limit_start_rec = ($start-1) * $list_max_entries_per_page;
  121. if( $adb->dbType == "pgsql")
  122. $list_result = $adb->pquery($list_query. " OFFSET $limit_start_rec LIMIT $list_max_entries_per_page", array());
  123. else
  124. $list_result = $adb->pquery($list_query. " LIMIT $limit_start_rec, $list_max_entries_per_page", array());
  125. $recordListRangeMsg = getRecordRangeMessage($list_result, $limit_start_rec);
  126. $smarty->assign('recordListRange',$recordListRangeMsg);
  127. $smarty->assign("CUSTOMVIEW_OPTION",$customview_html);
  128. // Navigation
  129. $navigationOutput = getTableHeaderSimpleNavigation($navigation_array, $url_string, $currentModule, 'index', $viewid);
  130. $smarty->assign("NAVIGATION", $navigationOutput);
  131. $listview_header = getListViewHeader($focus,$currentModule,$url_string,$sorder,$order_by,'',$customView);
  132. $listview_entries = getListViewEntries($focus,$currentModule,$list_result,$navigation_array,'','','EditView','Delete',$customView);
  133. $listview_header_search = getSearchListHeaderValues($focus,$currentModule,$url_string,$sorder,$order_by,'',$customView);
  134. $smarty->assign('LISTHEADER', $listview_header);
  135. $smarty->assign('LISTENTITY', $listview_entries);
  136. $smarty->assign('SEARCHLISTHEADER',$listview_header_search);
  137. // Module Search
  138. $alphabetical = AlphabeticalSearch($currentModule,'index',$focus->def_basicsearch_col,'true','basic','','','','',$viewid);
  139. $fieldnames = getAdvSearchfields($currentModule);
  140. $criteria = getcriteria_options();
  141. $smarty->assign("ALPHABETICAL", $alphabetical);
  142. $smarty->assign("FIELDNAMES", $fieldnames);
  143. $smarty->assign("CRITERIA", $criteria);
  144. $smarty->assign("AVALABLE_FIELDS", getMergeFields($currentModule,"available_fields"));
  145. $smarty->assign("FIELDS_TO_MERGE", getMergeFields($currentModule,"fileds_to_merge"));
  146. $_SESSION[$currentModule.'_listquery'] = $list_query;
  147. if(isset($_REQUEST['ajax']) && $_REQUEST['ajax'] != '')
  148. $smarty->display("ListViewEntries.tpl");
  149. else
  150. $smarty->display('ListView.tpl');
  151. ?>