PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/vtlib/ModuleDir/5.0.4/ListView.php

https://bitbucket.org/yousef_fadila/vtiger
PHP | 154 lines | 103 code | 32 blank | 19 comment | 28 complexity | 6124ccfa33abcbce9cbdab6dde49620a 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. require_once("modules/$currentModule/$currentModule.php");
  17. $category = getParentTab();
  18. $url_string = '';
  19. $tool_buttons = Button_Check($currentModule);
  20. $list_buttons = Array();
  21. if(isPermitted($currentModule,'Delete','') == 'yes') $list_buttons['del'] = $app_strings[LBL_MASS_DELETE];
  22. if(isPermitted($currentModule,'EditView','') == 'yes') {
  23. $list_buttons['mass_edit'] = $app_strings[LBL_MASS_EDIT];
  24. // Mass Edit could be used to change the owner as well!
  25. //$list_buttons['c_owner'] = $app_strings[LBL_CHANGE_OWNER];
  26. }
  27. $focus = new $currentModule();
  28. $sorder = $focus->getSortOrder();
  29. $order_by = $focus->getOrderBy();
  30. $_SESSION[$currentModule."_Order_by"] = $order_by;
  31. $_SESSION[$currentModule."_Sort_Order"]=$sorder;
  32. $smarty = new vtigerCRM_Smarty();
  33. // Identify this module as custom module.
  34. $smarty->assign('CUSTOM_MODULE', true);
  35. $smarty->assign('MOD', $mod_strings);
  36. $smarty->assign('APP', $app_strings);
  37. $smarty->assign('MODULE', $currentModule);
  38. $smarty->assign('SINGLE_MOD', $currentModule);
  39. $smarty->assign('CATEGORY', $category);
  40. $smarty->assign('BUTTONS', $list_buttons);
  41. $smarty->assign('CHECK', $tool_buttons);
  42. $smarty->assign("THEME", $theme);
  43. $smarty->assign('IMAGE_PATH', "themes/$theme/images/");
  44. $smarty->assign('CHANGE_OWNER', getUserslist());
  45. $smarty->assign('CHANGE_GROUP_OWNER', getGroupslist());
  46. // Enabling Module Search
  47. $url_string = '';
  48. if($_REQUEST['query'] == 'true') {
  49. list($where, $ustring) = split('#@@#', getWhereCondition($currentModule));
  50. $url_string .= "&query=true$ustring";
  51. $smarty->assign('SEARCH_URL', $url_string);
  52. }
  53. // Custom View
  54. $customView = new CustomView($currentModule);
  55. $viewid = $customView->getViewId($currentModule);
  56. $customview_html = $customView->getCustomViewCombo($viewid);
  57. $viewinfo = $customView->getCustomViewByCvid($viewid);
  58. $smarty->assign("VIEWID", $viewid);
  59. if($viewinfo['viewname'] == 'All') $smarty->assign('ALL', 'All');
  60. if($viewid != '0') {
  61. $listquery = getListQuery($currentModule);
  62. $list_query= $customView->getModifiedCvListQuery($viewid, $listquery, $currentModule);
  63. } else {
  64. $list_query= getListQuery($currentModule);
  65. }
  66. if($where != '') {
  67. $list_query = "$list_query AND $where";
  68. }
  69. // Sorting
  70. if($order_by) {
  71. if($order_by == 'smownerid') $list_query .= ' ORDER BY user_name '.$sorder;
  72. else {
  73. $tablename = getTableNameForField($currentModule, $order_by);
  74. $tablename = ($tablename != '')? ($tablename . '.') : '';
  75. $list_query .= ' ORDER BY ' . $tablename . $order_by . ' ' . $sorder;
  76. }
  77. }
  78. $countQuery = $adb->query( mkCountQuery($list_query) );
  79. $recordCount= $adb->query_result($countQuery,0,'count');
  80. // Set paging start value.
  81. $start = 1;
  82. if(isset($_REQUEST['start'])) { $start = $_REQUEST['start']; }
  83. else { $start = $_SESSION['lvs'][$currentModule]['start']; }
  84. // Total records is less than a page now.
  85. if($recordCount <= $list_max_entries_per_page) $start = 1;
  86. // Save in session
  87. if(empty($start)) $start = 1; // Reset to proper state
  88. $_SESSION['lvs'][$currentModule]['start'] = $start;
  89. $navigation_array = getNavigationValues($start, $recordCount, $list_max_entries_per_page);
  90. $start_rec = $navigation_array['start'];
  91. $end_rec = $navigation_array['end_val'];
  92. $_SESSION['nav_start']=$start_rec;
  93. $_SESSION['nav_end']=$end_rec;
  94. if ($start_rec ==0) $limit_start_rec = 0;
  95. else $limit_start_rec = $start_rec -1;
  96. $list_result = $adb->query( $list_query . " LIMIT $limit_start_rec, $list_max_entries_per_page" );
  97. $record_string= $app_strings['LBL_SHOWING']." $start_rec - $end_rec " . $app_strings['LBL_LIST_OF'] ." ".$recordCount;
  98. $smarty->assign('RECORD_COUNTS', $record_string);
  99. $smarty->assign("CUSTOMVIEW_OPTION",$customview_html);
  100. // Navigation
  101. $start = $_SESSION['lvs'][$currentModule]['start'];
  102. $navigation_array = getNavigationValues($start, $recordCount, $list_max_entries_per_page);
  103. $navigationOutput = getTableHeaderNavigation($navigation_array, $url_string, $currentModule, 'index', $viewid);
  104. $smarty->assign("NAVIGATION", $navigationOutput);
  105. $listview_header = getListViewHeader($focus,$currentModule,$url_string,$sorder,$order_by,'',$customView);
  106. $listview_entries = getListViewEntries($focus,$currentModule,$list_result,$navigation_array,'','','EditView','Delete',$customView);
  107. $listview_header_search = getSearchListHeaderValues($focus,$currentModule,$url_string,$sorder,$order_by,'',$customView);
  108. $smarty->assign('LISTHEADER', $listview_header);
  109. $smarty->assign('LISTENTITY', $listview_entries);
  110. $smarty->assign('SEARCHLISTHEADER',$listview_header_search);
  111. // Module Search
  112. $alphabetical = AlphabeticalSearch($currentModule,'index',$focus->def_basicsearch_col,'true','basic','','','','',$viewid);
  113. $fieldnames = getAdvSearchfields($currentModule);
  114. $criteria = getcriteria_options();
  115. $smarty->assign("ALPHABETICAL", $alphabetical);
  116. $smarty->assign("FIELDNAMES", $fieldnames);
  117. $smarty->assign("CRITERIA", $criteria);
  118. if(isset($_REQUEST['ajax']) && $_REQUEST['ajax'] != '')
  119. $smarty->display("ListViewEntries.tpl");
  120. else
  121. $smarty->display('ListView.tpl');
  122. ?>