PageRenderTime 50ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/rucrm/modules/ServiceContracts/ListView.php

https://code.google.com/p/vtiger-ru-fork/
PHP | 215 lines | 152 code | 40 blank | 23 comment | 34 complexity | 34b648f465a2bdbdd333b38647a0f6ee MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception, 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. 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. if(ListViewSession::hasViewChanged($currentModule,$viewid)) {
  31. $_SESSION[$currentModule."_Order_By"] = '';
  32. }
  33. $sorder = $focus->getSortOrder();
  34. $order_by = $focus->getOrderBy();
  35. $_SESSION[$currentModule."_Order_By"] = $order_by;
  36. $_SESSION[$currentModule."_Sort_Order"]=$sorder;
  37. $smarty = new vtigerCRM_Smarty();
  38. // Identify this module as custom module.
  39. $smarty->assign('CUSTOM_MODULE', true);
  40. $smarty->assign('MOD', $mod_strings);
  41. $smarty->assign('APP', $app_strings);
  42. $smarty->assign('MODULE', $currentModule);
  43. $smarty->assign('SINGLE_MOD', getTranslatedString('SINGLE_'.$currentModule));
  44. $smarty->assign('CATEGORY', $category);
  45. $smarty->assign('BUTTONS', $list_buttons);
  46. $smarty->assign('CHECK', $tool_buttons);
  47. $smarty->assign("THEME", $theme);
  48. $smarty->assign('IMAGE_PATH', "themes/$theme/images/");
  49. $smarty->assign('CHANGE_OWNER', getUserslist());
  50. $smarty->assign('CHANGE_GROUP_OWNER', getGroupslist());
  51. // Custom View
  52. $customView = new CustomView($currentModule);
  53. $viewid = $customView->getViewId($currentModule);
  54. $customview_html = $customView->getCustomViewCombo($viewid);
  55. $viewinfo = $customView->getCustomViewByCvid($viewid);
  56. // Feature available from 5.1
  57. if(method_exists($customView, 'isPermittedChangeStatus')) {
  58. // Approving or Denying status-public by the admin in CustomView
  59. $statusdetails = $customView->isPermittedChangeStatus($viewinfo['status']);
  60. // To check if a user is able to edit/delete a CustomView
  61. $edit_permit = $customView->isPermittedCustomView($viewid,'EditView',$currentModule);
  62. $delete_permit = $customView->isPermittedCustomView($viewid,'Delete',$currentModule);
  63. $smarty->assign("CUSTOMVIEW_PERMISSION",$statusdetails);
  64. $smarty->assign("CV_EDIT_PERMIT",$edit_permit);
  65. $smarty->assign("CV_DELETE_PERMIT",$delete_permit);
  66. }
  67. // END
  68. $smarty->assign("VIEWID", $viewid);
  69. if($viewinfo['viewname'] == 'All') $smarty->assign('ALL', 'All');
  70. if($viewid ==0)
  71. {
  72. echo "<table border='0' cellpadding='5' cellspacing='0' width='100%' height='450px'><tr><td align='center'>";
  73. echo "<div style='border: 3px solid rgb(153, 153, 153); background-color: rgb(255, 255, 255); width: 55%; position: relative; z-index: 10000000;'>
  74. <table border='0' cellpadding='5' cellspacing='0' width='98%'>
  75. <tbody><tr>
  76. <td rowspan='2' width='11%'><img src='". vtiger_imageurl('denied.gif', $theme) ."' ></td>
  77. <td style='border-bottom: 1px solid rgb(204, 204, 204);' nowrap='nowrap' width='70%'><span clas
  78. s='genHeaderSmall'>$app_strings[LBL_PERMISSION]</span></td>
  79. </tr>
  80. <tr>
  81. <td class='small' align='right' nowrap='nowrap'>
  82. <a href='javascript:window.history.back();'>$app_strings[LBL_GO_BACK]</a><br>
  83. </td>
  84. </tr>
  85. </tbody></table>
  86. </div>";
  87. echo "</td></tr></table>";
  88. exit;
  89. }
  90. global $current_user;
  91. $queryGenerator = new QueryGenerator($currentModule, $current_user);
  92. if ($viewid != "0") {
  93. $queryGenerator->initForCustomViewById($viewid);
  94. } else {
  95. $queryGenerator->initForDefaultCustomView();
  96. }
  97. // Enabling Module Search
  98. $url_string = '';
  99. if($_REQUEST['query'] == 'true') {
  100. $queryGenerator->addUserSearchConditions($_REQUEST);
  101. $ustring = getSearchURL($_REQUEST);
  102. $url_string .= "&query=true$ustring";
  103. $smarty->assign('SEARCH_URL', $url_string);
  104. }
  105. $list_query = $queryGenerator->getQuery();
  106. $where = $queryGenerator->getConditionalWhere();
  107. if(isset($where) && $where != '') {
  108. $_SESSION['export_where'] = $where;
  109. } else {
  110. unset($_SESSION['export_where']);
  111. }
  112. // Sorting
  113. if(!empty($order_by)) {
  114. if($order_by == 'smownerid') $list_query .= ' ORDER BY user_name '.$sorder;
  115. else {
  116. $tablename = getTableNameForField($currentModule, $order_by);
  117. $tablename = ($tablename != '')? ($tablename . '.') : '';
  118. $list_query .= ' ORDER BY ' . $tablename . $order_by . ' ' . $sorder;
  119. }
  120. }
  121. //Postgres 8 fixes
  122. if( $adb->dbType == "pgsql")
  123. $list_query = fixPostgresQuery( $list_query, $log, 0);
  124. if(PerformancePrefs::getBoolean('LISTVIEW_COMPUTE_PAGE_COUNT', false) === true){
  125. $count_result = $adb->query( mkCountQuery( $list_query));
  126. $noofrows = $adb->query_result($count_result,0,"count");
  127. }else{
  128. $noofrows = null;
  129. }
  130. $queryMode = (isset($_REQUEST['query']) && $_REQUEST['query'] == 'true');
  131. $start = ListViewSession::getRequestCurrentPage($currentModule, $list_query, $viewid, $queryMode);
  132. $navigation_array = VT_getSimpleNavigationValues($start,$list_max_entries_per_page,$noofrows);
  133. $limit_start_rec = ($start-1) * $list_max_entries_per_page;
  134. if( $adb->dbType == "pgsql")
  135. $list_result = $adb->pquery($list_query. " OFFSET $limit_start_rec LIMIT $list_max_entries_per_page", array());
  136. else
  137. $list_result = $adb->pquery($list_query. " LIMIT $limit_start_rec, $list_max_entries_per_page", array());
  138. $recordListRangeMsg = getRecordRangeMessage($list_result, $limit_start_rec,$noofrows);
  139. $smarty->assign('recordListRange',$recordListRangeMsg);
  140. $smarty->assign("CUSTOMVIEW_OPTION",$customview_html);
  141. $navigationOutput = getTableHeaderSimpleNavigation($navigation_array, $url_string, $currentModule, 'index', $viewid);
  142. $smarty->assign("NAVIGATION", $navigationOutput);
  143. $controller = new ListViewController($adb, $current_user, $queryGenerator);
  144. $listview_header = $controller->getListViewHeader($focus,$currentModule,$url_string,$sorder,
  145. $order_by);
  146. $listview_entries = $controller->getListViewEntries($focus,$currentModule,$list_result,
  147. $navigation_array);
  148. $listview_header_search = $controller->getBasicSearchFieldInfoList();
  149. $smarty->assign('LISTHEADER', $listview_header);
  150. $smarty->assign('LISTENTITY', $listview_entries);
  151. $smarty->assign('SEARCHLISTHEADER',$listview_header_search);
  152. // Module Search
  153. $alphabetical = AlphabeticalSearch($currentModule,'index',$focus->def_basicsearch_col,'true','basic','','','','',$viewid);
  154. $fieldnames = $controller->getAdvancedSearchOptionString();
  155. $criteria = getcriteria_options();
  156. $smarty->assign("ALPHABETICAL", $alphabetical);
  157. $smarty->assign("FIELDNAMES", $fieldnames);
  158. $smarty->assign("CRITERIA", $criteria);
  159. $smarty->assign("AVALABLE_FIELDS", getMergeFields($currentModule,"available_fields"));
  160. $smarty->assign("FIELDS_TO_MERGE", getMergeFields($currentModule,"fileds_to_merge"));
  161. //Added to select Multiple records in multiple pages
  162. $smarty->assign("SELECTEDIDS", vtlib_purify($_REQUEST['selobjs']));
  163. $smarty->assign("ALLSELECTEDIDS", vtlib_purify($_REQUEST['allselobjs']));
  164. $smarty->assign("CURRENT_PAGE_BOXES", implode(array_keys($listview_entries),";"));
  165. ListViewSession::setSessionQuery($currentModule,$list_query,$viewid);
  166. // Gather the custom link information to display
  167. include_once('vtlib/Vtiger/Link.php');
  168. $customlink_params = Array('MODULE'=>$currentModule, 'ACTION'=>vtlib_purify($_REQUEST['action']), 'CATEGORY'=> $category);
  169. $smarty->assign('CUSTOM_LINKS', Vtiger_Link::getAllByType(getTabid($currentModule), Array('LISTVIEWBASIC','LISTVIEW'), $customlink_params));
  170. // END
  171. if(isset($_REQUEST['ajax']) && $_REQUEST['ajax'] != '')
  172. $smarty->display("ListViewEntries.tpl");
  173. else
  174. $smarty->display('ListView.tpl');
  175. ?>