PageRenderTime 53ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/vtigerCRM/modules/Faq/ListView.php

https://github.com/hitchby/PLEXUS
PHP | 267 lines | 198 code | 43 blank | 26 comment | 45 complexity | c079470e6dde24198f6eae256c8f59a1 MD5 | raw file
  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 $theme;
  11. $theme_path="themes/".$theme."/";
  12. $image_path=$theme_path."images/";
  13. global $mod_strings;
  14. require_once('modules/Faq/Faq.php');
  15. require_once('Smarty_setup.php');
  16. require_once('include/utils/utils.php');
  17. require_once('include/ListView/ListView.php');
  18. require_once('modules/Faq/Faq.php');
  19. require_once('modules/CustomView/CustomView.php');
  20. require_once('include/database/Postgres8.php');
  21. global $app_strings,$theme;
  22. $current_module_strings = return_module_language($current_language, 'Faq');
  23. global $currentModule, $adb;
  24. require_once($theme_path.'layout_utils.php');
  25. if(isset($_REQUEST['category']) && $_REQUEST['category'] !='')
  26. {
  27. $category = vtlib_purify($_REQUEST['category']);
  28. }
  29. else
  30. {
  31. $category = getParentTabFromModule($currentModule);
  32. }
  33. $focus = new Faq();
  34. // Initialize sort by fields
  35. $focus->initSortbyField('Faq');
  36. // END
  37. $smarty = new vtigerCRM_Smarty;
  38. $other_text = Array();
  39. if(!$_SESSION['lvs'][$currentModule])
  40. {
  41. unset($_SESSION['lvs']);
  42. $modObj = new ListViewSession();
  43. $modObj->sorder = $sorder;
  44. $modObj->sortby = $order_by;
  45. $_SESSION['lvs'][$currentModule] = get_object_vars($modObj);
  46. }
  47. if($_REQUEST['errormsg'] != '')
  48. {
  49. $errormsg = vtlib_purify($_REQUEST['errormsg']);
  50. $smarty->assign("ERROR","The User does not have permission to delete ".$errormsg." ".$currentModule);
  51. }else
  52. {
  53. $smarty->assign("ERROR","");
  54. }
  55. $url_string = '';
  56. //<<<<cutomview>>>>>>>
  57. $oCustomView = new CustomView("Faq");
  58. $viewid = $oCustomView->getViewId($currentModule);
  59. $customviewcombo_html = $oCustomView->getCustomViewCombo($viewid);
  60. $viewnamedesc = $oCustomView->getCustomViewByCvid($viewid);
  61. //Added to handle approving or denying status-public by the admin in CustomView
  62. $statusdetails = $oCustomView->isPermittedChangeStatus($viewnamedesc['status']);
  63. $smarty->assign("CUSTOMVIEW_PERMISSION",$statusdetails);
  64. //To check if a user is able to edit/delete a customview
  65. $edit_permit = $oCustomView->isPermittedCustomView($viewid,'EditView',$currentModule);
  66. $delete_permit = $oCustomView->isPermittedCustomView($viewid,'Delete',$currentModule);
  67. $smarty->assign("CV_EDIT_PERMIT",$edit_permit);
  68. $smarty->assign("CV_DELETE_PERMIT",$delete_permit);
  69. //<<<<<customview>>>>>
  70. //<<<<<<<<<<<<<<<<<<< sorting - stored in session >>>>>>>>>>>>>>>>>>>>
  71. if($_REQUEST['order_by'] != '')
  72. $order_by = $adb->sql_escape_string($_REQUEST['order_by']);
  73. else
  74. $order_by = (($_SESSION['FAQ_ORDER_BY'] != '')?($_SESSION['FAQ_ORDER_BY']):($focus->default_order_by));
  75. if($_REQUEST['sorder'] != '')
  76. $sorder = $adb->sql_escape_string($_REQUEST['sorder']);
  77. else
  78. $sorder = (($_SESSION['FAQ_SORT_ORDER'] != '')?($_SESSION['FAQ_SORT_ORDER']):($focus->default_sort_order));
  79. $_SESSION['FAQ_ORDER_BY'] = $order_by;
  80. $_SESSION['FAQ_SORT_ORDER'] = $sorder;
  81. //<<<<<<<<<<<<<<<<<<< sorting - stored in session >>>>>>>>>>>>>>>>>>>>
  82. if($viewid != 0)
  83. {
  84. $CActionDtls = $oCustomView->getCustomActionDetails($viewid);
  85. }
  86. elseif($viewid ==0)
  87. {
  88. echo "<table border='0' cellpadding='5' cellspacing='0' width='100%' height='450px'><tr><td align='center'>";
  89. echo "<div style='border: 3px solid rgb(153, 153, 153); background-color: rgb(255, 255, 255); width: 55%; position: relative; z-index: 10000000;'>
  90. <table border='0' cellpadding='5' cellspacing='0' width='98%'>
  91. <tbody><tr>
  92. <td rowspan='2' width='11%'><img src='". vtiger_imageurl('denied.gif', $theme)."' ></td>
  93. <td style='border-bottom: 1px solid rgb(204, 204, 204);' nowrap='nowrap' width='70%'><span clas
  94. s='genHeaderSmall'>$app_strings[LBL_PERMISSION]</span></td>
  95. </tr>
  96. <tr>
  97. <td class='small' align='right' nowrap='nowrap'>
  98. <a href='javascript:window.history.back();'>$app_strings[LBL_GO_BACK]</a><br>
  99. </td>
  100. </tr>
  101. </tbody></table>
  102. </div>";
  103. echo "</td></tr></table>";
  104. exit;
  105. }
  106. if(isPermitted('Faq','Delete','') == 'yes')
  107. $other_text ['del'] = $app_strings[LBL_MASS_DELETE];
  108. //Retreive the list from Database
  109. //Retreive the list from Database
  110. //<<<<<<<<<customview>>>>>>>>>
  111. global $current_user;
  112. $queryGenerator = new QueryGenerator($currentModule, $current_user);
  113. if ($viewid != "0") {
  114. $queryGenerator->initForCustomViewById($viewid);
  115. } else {
  116. $queryGenerator->initForDefaultCustomView();
  117. }
  118. if(isset($_REQUEST['query']) && $_REQUEST['query'] == 'true')
  119. {
  120. $queryGenerator->addUserSearchConditions($_REQUEST);
  121. $ustring = getSearchURL($_REQUEST);
  122. // we have a query
  123. $url_string .="&query=true".$ustring;
  124. $smarty->assign("SEARCH_URL",$url_string);
  125. }
  126. $list_query = $queryGenerator->getQuery();
  127. $view_script = "<script language='javascript'>
  128. function set_selected()
  129. {
  130. len=document.massdelete.viewname.length;
  131. for(i=0;i<len;i++)
  132. {
  133. if(document.massdelete.viewname[i].value == '$viewid')
  134. document.massdelete.viewname[i].selected = true;
  135. }
  136. }
  137. set_selected();
  138. </script>";
  139. if(isset($order_by) && $order_by != '')
  140. {
  141. $tablename = getTableNameForField('Faq',$order_by);
  142. $tablename = (($tablename != '')?($tablename."."):'');
  143. if( $adb->dbType == "pgsql")
  144. $list_query .= ' GROUP BY '.$tablename.$order_by;
  145. $list_query .= ' ORDER BY '.$tablename.$order_by.' '.$sorder;
  146. }
  147. //Constructing the list view
  148. $smarty->assign("MOD", $mod_strings);
  149. $smarty->assign("APP", $app_strings);
  150. $smarty->assign("THEME", $theme);
  151. $smarty->assign("IMAGE_PATH",$image_path);
  152. $smarty->assign("MODULE",$currentModule);
  153. $smarty->assign("BUTTONS",$other_text);
  154. $smarty->assign("CATEGORY",$category);
  155. $smarty->assign("SINGLE_MOD",'Document');
  156. if($viewnamedesc['viewname'] == 'All')
  157. {
  158. $smarty->assign("ALL", 'All');
  159. }
  160. //Postgres 8 fixes
  161. if( $adb->dbType == "pgsql")
  162. $list_query = fixPostgresQuery( $list_query, $log, 0);
  163. if(PerformancePrefs::getBoolean('LISTVIEW_COMPUTE_PAGE_COUNT', false) === true){
  164. $count_result = $adb->query( mkCountQuery( $list_query));
  165. $noofrows = $adb->query_result($count_result,0,"count");
  166. }else{
  167. $noofrows = null;
  168. }
  169. $queryMode = (isset($_REQUEST['query']) && $_REQUEST['query'] == 'true');
  170. $start = ListViewSession::getRequestCurrentPage($currentModule, $list_query, $viewid, $queryMode);
  171. $navigation_array = VT_getSimpleNavigationValues($start,$list_max_entries_per_page,$noofrows);
  172. $limit_start_rec = ($start-1) * $list_max_entries_per_page;
  173. if( $adb->dbType == "pgsql")
  174. $list_result = $adb->pquery($list_query. " OFFSET $limit_start_rec LIMIT $list_max_entries_per_page", array());
  175. else
  176. $list_result = $adb->pquery($list_query. " LIMIT $limit_start_rec, $list_max_entries_per_page", array());
  177. $recordListRangeMsg = getRecordRangeMessage($list_result, $limit_start_rec,$noofrows);
  178. $smarty->assign('recordListRange',$recordListRangeMsg);
  179. if($viewid !='')
  180. $url_string .= "&viewname=".$viewid;
  181. //Retreive the List View Table Header
  182. $controller = new ListViewController($adb, $current_user, $queryGenerator);
  183. $listview_header = $controller->getListViewHeader($focus,$currentModule,$url_string,$sorder,
  184. $order_by);
  185. $smarty->assign("LISTHEADER", $listview_header);
  186. $listview_header_search = $controller->getBasicSearchFieldInfoList();
  187. $smarty->assign("SEARCHLISTHEADER",$listview_header_search);
  188. $listview_entries = $controller->getListViewEntries($focus,$currentModule,$list_result,
  189. $navigation_array);
  190. $smarty->assign("LISTHEADER", $listview_header);
  191. $smarty->assign("LISTENTITY", $listview_entries);
  192. $smarty->assign("SELECT_SCRIPT", $view_script);
  193. //Added to select Multiple records in multiple pages
  194. $smarty->assign("SELECTEDIDS", vtlib_purify($_REQUEST['selobjs']));
  195. $smarty->assign("ALLSELECTEDIDS", vtlib_purify($_REQUEST['allselobjs']));
  196. $smarty->assign("CURRENT_PAGE_BOXES", implode(array_keys($listview_entries),";"));
  197. $navigationOutput = getTableHeaderSimpleNavigation($navigation_array, $url_string,"Faq","index",$viewid);
  198. $alphabetical = AlphabeticalSearch($currentModule,'index','question','true','basic',"","","","",$viewid);
  199. $fieldnames = $controller->getAdvancedSearchOptionString();
  200. $criteria = getcriteria_options();
  201. $smarty->assign("CRITERIA", $criteria);
  202. $smarty->assign("FIELDNAMES", $fieldnames);
  203. $smarty->assign("ALPHABETICAL", $alphabetical);
  204. $smarty->assign("NAVIGATION", $navigationOutput);
  205. $smarty->assign("CUSTOMVIEW_OPTION",$customviewcombo_html);
  206. $smarty->assign("VIEWID", $viewid);
  207. $smarty->assign("SINGLE_MOD" ,'Faq');
  208. if(isPermitted('Faq','EditView','') == 'yes') {
  209. $other_text['mass_edit'] = $app_strings[LBL_MASS_EDIT];
  210. }
  211. $smarty->assign("BUTTONS",$other_text);
  212. $check_button = Button_Check($module);
  213. $smarty->assign("CHECK", $check_button);
  214. ListViewSession::setSessionQuery($currentModule,$list_query,$viewid);
  215. // Gather the custom link information to display
  216. include_once('vtlib/Vtiger/Link.php');
  217. $customlink_params = Array('MODULE'=>$currentModule, 'ACTION'=>vtlib_purify($_REQUEST['action']), 'CATEGORY'=> $category);
  218. $smarty->assign('CUSTOM_LINKS', Vtiger_Link::getAllByType(getTabid($currentModule), Array('LISTVIEWBASIC','LISTVIEW'), $customlink_params));
  219. // END
  220. if(isset($_REQUEST['ajax']) && $_REQUEST['ajax'] != '')
  221. $smarty->display("ListViewEntries.tpl");
  222. else
  223. $smarty->display("ListView.tpl");
  224. ?>