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

/trunk/rucrm/modules/Faq/ListView.php

https://code.google.com/p/vtiger-ru-fork/
PHP | 270 lines | 201 code | 43 blank | 26 comment | 46 complexity | a598264f4e22bf5fdcae3767bd3c6e3e 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 $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. if(ListViewSession::hasViewChanged($currentModule,$viewid)) {
  71. $_SESSION['FAQ_ORDER_BY'] = '';
  72. }
  73. //<<<<<<<<<<<<<<<<<<< sorting - stored in session >>>>>>>>>>>>>>>>>>>>
  74. if($_REQUEST['order_by'] != '')
  75. $order_by = $adb->sql_escape_string($_REQUEST['order_by']);
  76. else
  77. $order_by = (($_SESSION['FAQ_ORDER_BY'] != '')?($_SESSION['FAQ_ORDER_BY']):($focus->default_order_by));
  78. if($_REQUEST['sorder'] != '')
  79. $sorder = $adb->sql_escape_string($_REQUEST['sorder']);
  80. else
  81. $sorder = (($_SESSION['FAQ_SORT_ORDER'] != '')?($_SESSION['FAQ_SORT_ORDER']):($focus->default_sort_order));
  82. $_SESSION['FAQ_ORDER_BY'] = $order_by;
  83. $_SESSION['FAQ_SORT_ORDER'] = $sorder;
  84. //<<<<<<<<<<<<<<<<<<< sorting - stored in session >>>>>>>>>>>>>>>>>>>>
  85. if($viewid != 0)
  86. {
  87. $CActionDtls = $oCustomView->getCustomActionDetails($viewid);
  88. }
  89. elseif($viewid ==0)
  90. {
  91. echo "<table border='0' cellpadding='5' cellspacing='0' width='100%' height='450px'><tr><td align='center'>";
  92. echo "<div style='border: 3px solid rgb(153, 153, 153); background-color: rgb(255, 255, 255); width: 55%; position: relative; z-index: 10000000;'>
  93. <table border='0' cellpadding='5' cellspacing='0' width='98%'>
  94. <tbody><tr>
  95. <td rowspan='2' width='11%'><img src='". vtiger_imageurl('denied.gif', $theme)."' ></td>
  96. <td style='border-bottom: 1px solid rgb(204, 204, 204);' nowrap='nowrap' width='70%'><span clas
  97. s='genHeaderSmall'>$app_strings[LBL_PERMISSION]</span></td>
  98. </tr>
  99. <tr>
  100. <td class='small' align='right' nowrap='nowrap'>
  101. <a href='javascript:window.history.back();'>$app_strings[LBL_GO_BACK]</a><br>
  102. </td>
  103. </tr>
  104. </tbody></table>
  105. </div>";
  106. echo "</td></tr></table>";
  107. exit;
  108. }
  109. if(isPermitted('Faq','Delete','') == 'yes')
  110. $other_text ['del'] = $app_strings[LBL_MASS_DELETE];
  111. //Retreive the list from Database
  112. //Retreive the list from Database
  113. //<<<<<<<<<customview>>>>>>>>>
  114. global $current_user;
  115. $queryGenerator = new QueryGenerator($currentModule, $current_user);
  116. if ($viewid != "0") {
  117. $queryGenerator->initForCustomViewById($viewid);
  118. } else {
  119. $queryGenerator->initForDefaultCustomView();
  120. }
  121. if(isset($_REQUEST['query']) && $_REQUEST['query'] == 'true')
  122. {
  123. $queryGenerator->addUserSearchConditions($_REQUEST);
  124. $ustring = getSearchURL($_REQUEST);
  125. // we have a query
  126. $url_string .="&query=true".$ustring;
  127. $smarty->assign("SEARCH_URL",$url_string);
  128. }
  129. $list_query = $queryGenerator->getQuery();
  130. $view_script = "<script language='javascript'>
  131. function set_selected()
  132. {
  133. len=document.massdelete.viewname.length;
  134. for(i=0;i<len;i++)
  135. {
  136. if(document.massdelete.viewname[i].value == '$viewid')
  137. document.massdelete.viewname[i].selected = true;
  138. }
  139. }
  140. set_selected();
  141. </script>";
  142. if(isset($order_by) && $order_by != '')
  143. {
  144. $tablename = getTableNameForField('Faq',$order_by);
  145. $tablename = (($tablename != '')?($tablename."."):'');
  146. if( $adb->dbType == "pgsql")
  147. $list_query .= ' GROUP BY '.$tablename.$order_by;
  148. $list_query .= ' ORDER BY '.$tablename.$order_by.' '.$sorder;
  149. }
  150. //Constructing the list view
  151. $smarty->assign("MOD", $mod_strings);
  152. $smarty->assign("APP", $app_strings);
  153. $smarty->assign("THEME", $theme);
  154. $smarty->assign("IMAGE_PATH",$image_path);
  155. $smarty->assign("MODULE",$currentModule);
  156. $smarty->assign("BUTTONS",$other_text);
  157. $smarty->assign("CATEGORY",$category);
  158. $smarty->assign("SINGLE_MOD",'Document');
  159. if($viewnamedesc['viewname'] == 'All')
  160. {
  161. $smarty->assign("ALL", 'All');
  162. }
  163. //Postgres 8 fixes
  164. if( $adb->dbType == "pgsql")
  165. $list_query = fixPostgresQuery( $list_query, $log, 0);
  166. if(PerformancePrefs::getBoolean('LISTVIEW_COMPUTE_PAGE_COUNT', false) === true){
  167. $count_result = $adb->query( mkCountQuery( $list_query));
  168. $noofrows = $adb->query_result($count_result,0,"count");
  169. }else{
  170. $noofrows = null;
  171. }
  172. $queryMode = (isset($_REQUEST['query']) && $_REQUEST['query'] == 'true');
  173. $start = ListViewSession::getRequestCurrentPage($currentModule, $list_query, $viewid, $queryMode);
  174. $navigation_array = VT_getSimpleNavigationValues($start,$list_max_entries_per_page,$noofrows);
  175. $limit_start_rec = ($start-1) * $list_max_entries_per_page;
  176. if( $adb->dbType == "pgsql")
  177. $list_result = $adb->pquery($list_query. " OFFSET $limit_start_rec LIMIT $list_max_entries_per_page", array());
  178. else
  179. $list_result = $adb->pquery($list_query. " LIMIT $limit_start_rec, $list_max_entries_per_page", array());
  180. $recordListRangeMsg = getRecordRangeMessage($list_result, $limit_start_rec,$noofrows);
  181. $smarty->assign('recordListRange',$recordListRangeMsg);
  182. if($viewid !='')
  183. $url_string .= "&viewname=".$viewid;
  184. //Retreive the List View Table Header
  185. $controller = new ListViewController($adb, $current_user, $queryGenerator);
  186. $listview_header = $controller->getListViewHeader($focus,$currentModule,$url_string,$sorder,
  187. $order_by);
  188. $smarty->assign("LISTHEADER", $listview_header);
  189. $listview_header_search = $controller->getBasicSearchFieldInfoList();
  190. $smarty->assign("SEARCHLISTHEADER",$listview_header_search);
  191. $listview_entries = $controller->getListViewEntries($focus,$currentModule,$list_result,
  192. $navigation_array);
  193. $smarty->assign("LISTHEADER", $listview_header);
  194. $smarty->assign("LISTENTITY", $listview_entries);
  195. $smarty->assign("SELECT_SCRIPT", $view_script);
  196. //Added to select Multiple records in multiple pages
  197. $smarty->assign("SELECTEDIDS", vtlib_purify($_REQUEST['selobjs']));
  198. $smarty->assign("ALLSELECTEDIDS", vtlib_purify($_REQUEST['allselobjs']));
  199. $smarty->assign("CURRENT_PAGE_BOXES", implode(array_keys($listview_entries),";"));
  200. $navigationOutput = getTableHeaderSimpleNavigation($navigation_array, $url_string,"Faq","index",$viewid);
  201. $alphabetical = AlphabeticalSearch($currentModule,'index','question','true','basic',"","","","",$viewid);
  202. $fieldnames = $controller->getAdvancedSearchOptionString();
  203. $criteria = getcriteria_options();
  204. $smarty->assign("CRITERIA", $criteria);
  205. $smarty->assign("FIELDNAMES", $fieldnames);
  206. $smarty->assign("ALPHABETICAL", $alphabetical);
  207. $smarty->assign("NAVIGATION", $navigationOutput);
  208. $smarty->assign("CUSTOMVIEW_OPTION",$customviewcombo_html);
  209. $smarty->assign("VIEWID", $viewid);
  210. $smarty->assign("SINGLE_MOD" ,'Faq');
  211. if(isPermitted('Faq','EditView','') == 'yes') {
  212. $other_text['mass_edit'] = $app_strings[LBL_MASS_EDIT];
  213. }
  214. $smarty->assign("BUTTONS",$other_text);
  215. $check_button = Button_Check($module);
  216. $smarty->assign("CHECK", $check_button);
  217. ListViewSession::setSessionQuery($currentModule,$list_query,$viewid);
  218. // Gather the custom link information to display
  219. include_once('vtlib/Vtiger/Link.php');
  220. $customlink_params = Array('MODULE'=>$currentModule, 'ACTION'=>vtlib_purify($_REQUEST['action']), 'CATEGORY'=> $category);
  221. $smarty->assign('CUSTOM_LINKS', Vtiger_Link::getAllByType(getTabid($currentModule), Array('LISTVIEWBASIC','LISTVIEW'), $customlink_params));
  222. // END
  223. if(isset($_REQUEST['ajax']) && $_REQUEST['ajax'] != '')
  224. $smarty->display("ListViewEntries.tpl");
  225. else
  226. $smarty->display("ListView.tpl");
  227. ?>