PageRenderTime 42ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

/trunk/rucrm/modules/Accounts/ListView.php

https://code.google.com/p/vtiger-ru-fork/
PHP | 356 lines | 267 code | 52 blank | 37 comment | 59 complexity | 7a6892a9c38a64e112630eb459189085 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 SugarCRM Public License Version 1.1.2
  4. * ("License"); You may not use this file except in compliance with the
  5. * License. You may obtain a copy of the License at http://www.sugarcrm.com/SPL
  6. * Software distributed under the License is distributed on an "AS IS" basis,
  7. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
  8. * the specific language governing rights and limitations under the License.
  9. * The Original Code is: SugarCRM Open Source
  10. * The Initial Developer of the Original Code is SugarCRM, Inc.
  11. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.;
  12. * All Rights Reserved.
  13. * Contributor(s): ______________________________________.
  14. ********************************************************************************/
  15. require_once('Smarty_setup.php');
  16. require_once("data/Tracker.php");
  17. require_once('modules/Accounts/Accounts.php');
  18. require_once('include/logging.php');
  19. require_once('include/ListView/ListView.php');
  20. require_once('include/utils/utils.php');
  21. require_once('modules/CustomView/CustomView.php');
  22. require_once('include/database/Postgres8.php');
  23. global $app_strings;
  24. global $list_max_entries_per_page;
  25. $log = LoggerManager::getLogger('account_list');
  26. global $currentModule;
  27. global $theme;
  28. $category = getParentTab();
  29. // focus_list is the means of passing data to a ListView.
  30. global $focus_list;
  31. if (!isset($where)) $where = "";
  32. $url_string = '';
  33. $focus = new Accounts();
  34. // Initialize sort by fields
  35. $focus->initSortbyField('Accounts');
  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 Change/Delete ".$errormsg." ".$currentModule);
  51. }else
  52. {
  53. $smarty->assign("ERROR","");
  54. }
  55. if(ListViewSession::hasViewChanged($currentModule,$viewid)) {
  56. $_SESSION['ACCOUNTS_ORDER_BY'] = '';
  57. }
  58. //<<<<<<< sort ordering >>>>>>>>>>>>>
  59. $sorder = $focus->getSortOrder();
  60. $order_by = $focus->getOrderBy();
  61. $_SESSION['ACCOUNTS_ORDER_BY'] = $order_by;
  62. $_SESSION['ACCOUNTS_SORT_ORDER'] = $sorder;
  63. //<<<<<<< sort ordering >>>>>>>>>>>>>
  64. //<<<<cutomview>>>>>>>
  65. $oCustomView = new CustomView($currentModule);
  66. $viewid = $oCustomView->getViewId($currentModule);
  67. $customviewcombo_html = $oCustomView->getCustomViewCombo($viewid);
  68. $viewnamedesc = $oCustomView->getCustomViewByCvid($viewid);
  69. //Added to handle approving or denying status-public by the admin in CustomView
  70. $statusdetails = $oCustomView->isPermittedChangeStatus($viewnamedesc['status']);
  71. $smarty->assign("CUSTOMVIEW_PERMISSION",$statusdetails);
  72. //To check if a user is able to edit/delete a customview
  73. $edit_permit = $oCustomView->isPermittedCustomView($viewid,'EditView',$currentModule);
  74. $delete_permit = $oCustomView->isPermittedCustomView($viewid,'Delete',$currentModule);
  75. $smarty->assign("CV_EDIT_PERMIT",$edit_permit);
  76. $smarty->assign("CV_DELETE_PERMIT",$delete_permit);
  77. //<<<<<customview>>>>>
  78. $smarty->assign("CHANGE_OWNER",getUserslist());
  79. $smarty->assign("CHANGE_GROUP_OWNER",getGroupslist());
  80. if($viewid != 0)
  81. {
  82. $CActionDtls = $oCustomView->getCustomActionDetails($viewid);
  83. }
  84. elseif($viewid ==0)
  85. {
  86. echo "<table border='0' cellpadding='5' cellspacing='0' width='100%' height='450px'><tr><td align='center'>";
  87. echo "<div style='border: 3px solid rgb(153, 153, 153); background-color: rgb(255, 255, 255); width: 55%; position: relative; z-index: 10000000;'>
  88. <table border='0' cellpadding='5' cellspacing='0' width='98%'>
  89. <tbody><tr>
  90. <td rowspan='2' width='11%'><img src= " . vtiger_imageurl('denied.gif', $theme) . " ></td>
  91. <td style='border-bottom: 1px solid rgb(204, 204, 204);' nowrap='nowrap' width='70%'>
  92. <span class='genHeaderSmall'>$app_strings[LBL_PERMISSION]</span></td>
  93. </tr>
  94. <tr>
  95. <td class='small' align='right' nowrap='nowrap'>
  96. <a href='javascript:window.history.back();'>$app_strings[LBL_GO_BACK]</a><br>
  97. </td>
  98. </tr>
  99. </tbody></table>
  100. </div>";
  101. echo "</td></tr></table>";
  102. exit;
  103. }
  104. if(isPermitted('Accounts','Delete','') == 'yes')
  105. {
  106. $other_text['del'] = $app_strings[LBL_MASS_DELETE];
  107. }
  108. if(isPermitted('Accounts','EditView','') == 'yes')
  109. {
  110. $other_text['mass_edit'] = $app_strings[LBL_MASS_EDIT];
  111. $other_text['c_owner'] = $app_strings[LBL_CHANGE_OWNER];
  112. }
  113. if(isPermitted('Emails','EditView','') == 'yes')
  114. {
  115. $other_text['s_mail'] = $app_strings[LBL_SEND_MAIL_BUTTON];
  116. }
  117. if(isset($CActionDtls))
  118. {
  119. $other_text['s_cmail'] = $app_strings[LBL_SEND_CUSTOM_MAIL_BUTTON];
  120. }
  121. // mailer export
  122. if(isPermitted('Accounts','Export','') == 'yes')
  123. {
  124. $other_text['mailer_exp'] = $mod_strings[LBL_MAILER_EXPORT];
  125. }
  126. // end of mailer export
  127. if($viewnamedesc['viewname'] == 'All')
  128. {
  129. $smarty->assign("ALL", 'All');
  130. }
  131. global $theme;
  132. $theme_path="themes/".$theme."/";
  133. $image_path=$theme_path."images/";
  134. $smarty->assign("MOD", $mod_strings);
  135. $smarty->assign("APP", $app_strings);
  136. $smarty->assign("THEME", $theme);
  137. $smarty->assign("IMAGE_PATH",$image_path);
  138. $smarty->assign("CUSTOMVIEW_OPTION",$customviewcombo_html);
  139. $smarty->assign("VIEWID", $viewid);
  140. $smarty->assign("BUTTONS",$other_text);
  141. $smarty->assign("MODULE",$currentModule);
  142. $smarty->assign("SINGLE_MOD",'Account');
  143. //Retreive the list from Database
  144. //<<<<<<<<<customview>>>>>>>>>
  145. global $current_user;
  146. $queryGenerator = new QueryGenerator($currentModule, $current_user);
  147. if ($viewid != "0") {
  148. $queryGenerator->initForCustomViewById($viewid);
  149. } else {
  150. $queryGenerator->initForDefaultCustomView();
  151. }
  152. //<<<<<<<<customview>>>>>>>>>
  153. // Enabling Module Search
  154. $url_string = '';
  155. if($_REQUEST['query'] == 'true') {
  156. $queryGenerator->addUserSearchConditions($_REQUEST);
  157. $ustring = getSearchURL($_REQUEST);
  158. $url_string .= "&query=true$ustring";
  159. $smarty->assign('SEARCH_URL', $url_string);
  160. }
  161. $query = $queryGenerator->getQuery();
  162. $where = $queryGenerator->getConditionalWhere();
  163. if(isset($where) && $where != '') {
  164. $_SESSION['export_where'] = $where;
  165. } else {
  166. unset($_SESSION['export_where']);
  167. }
  168. $view_script = "<script language='javascript'>
  169. function set_selected()
  170. {
  171. len=document.massdelete.viewname.length;
  172. for(i=0;i<len;i++)
  173. {
  174. if(document.massdelete.viewname[i].value == '$viewid')
  175. document.massdelete.viewname[i].selected = true;
  176. }
  177. }
  178. set_selected();
  179. </script>";
  180. // mailer_export
  181. if (isset($other_text['mailer_exp']))
  182. {
  183. $view_script .= "<script language='javascript'>
  184. function mailer_export()
  185. {
  186. document.massdelete.action.value=\"MailerExport\";
  187. document.massdelete.step.value=\"ask\";
  188. window.locate=\"index.php?module=Accounts&action=MailerExport&from=Accounts&step=ask\";
  189. }
  190. </script>";
  191. }
  192. // end of mailer export
  193. if(isset($order_by) && $order_by != '')
  194. {
  195. if($order_by == 'smownerid')
  196. {
  197. if( $adb->dbType == "pgsql")
  198. $query .= ' GROUP BY user_name';
  199. $query .= ' ORDER BY user_name '.$sorder;
  200. }
  201. else
  202. {
  203. $tablename = getTableNameForField('Accounts',$order_by);
  204. $tablename = (($tablename != '')?($tablename."."):'');
  205. if( $adb->dbType == "pgsql")
  206. $query .= ' GROUP BY '.$tablename.$order_by;
  207. $query .= ' ORDER BY '.$tablename.$order_by.' '.$sorder;
  208. }
  209. }
  210. //Postgres 8 fixes
  211. if( $adb->dbType == "pgsql")
  212. $query = fixPostgresQuery( $query, $log, 0);
  213. if(PerformancePrefs::getBoolean('LISTVIEW_COMPUTE_PAGE_COUNT', false) === true){
  214. $count_result = $adb->query( mkCountQuery( $query));
  215. $noofrows = $adb->query_result($count_result,0,"count");
  216. }else{
  217. $noofrows = null;
  218. }
  219. $queryMode = (isset($_REQUEST['query']) && $_REQUEST['query'] == 'true');
  220. $start = ListViewSession::getRequestCurrentPage($currentModule, $query, $viewid, $queryMode);
  221. $navigation_array = VT_getSimpleNavigationValues($start,$list_max_entries_per_page,$noofrows);
  222. $limit_start_rec = ($start-1) * $list_max_entries_per_page;
  223. if( $adb->dbType == "pgsql")
  224. $list_result = $adb->pquery($query. " OFFSET $limit_start_rec LIMIT $list_max_entries_per_page", array());
  225. else
  226. $list_result = $adb->pquery($query. " LIMIT $limit_start_rec, $list_max_entries_per_page", array());
  227. $recordListRangeMsg = getRecordRangeMessage($list_result, $limit_start_rec,$noofrows);
  228. $smarty->assign('recordListRange',$recordListRangeMsg);
  229. //mass merge for word templates -- *Raj*17/11
  230. while($row = $adb->fetch_array($list_result))
  231. {
  232. $ids[] = $row[$focus->table_index];
  233. }
  234. if(isset($ids))
  235. {
  236. $smarty->assign("ALLIDS", implode($ids,";"));
  237. }
  238. if(isPermitted("Accounts","Merge") == 'yes')
  239. {
  240. $wordTemplateResult = fetchWordTemplateList("Accounts");
  241. $tempCount = $adb->num_rows($wordTemplateResult);
  242. $tempVal = $adb->fetch_array($wordTemplateResult);
  243. for($templateCount=0;$templateCount<$tempCount;$templateCount++)
  244. {
  245. $optionString .="<option value=\"".$tempVal["templateid"]."\">" .$tempVal["filename"] ."</option>";
  246. $tempVal = $adb->fetch_array($wordTemplateResult);
  247. }
  248. if($tempCount > 0)
  249. {
  250. $smarty->assign("WORDTEMPLATEOPTIONS","<td>".$app_strings['LBL_SELECT_TEMPLATE_TO_MAIL_MERGE']."</td><td style=\"padding-left:5px;padding-right:5px\"><select class=\"small\" name=\"mergefile\">".$optionString."</select></td>");
  251. $smarty->assign("MERGEBUTTON","<td><input title=\"$app_strings[LBL_MERGE_BUTTON_TITLE]\" accessKey=\"$app_strings[LBL_MERGE_BUTTON_KEY]\" class=\"crmbutton small create\" onclick=\"return massMerge('Accounts')\" type=\"submit\" name=\"Merge\" value=\" $app_strings[LBL_MERGE_BUTTON_LABEL]\"></td>");
  252. }
  253. else
  254. {
  255. global $current_user;
  256. require("user_privileges/user_privileges_".$current_user->id.".php");
  257. if($is_admin == true)
  258. {
  259. $smarty->assign("MERGEBUTTON",'<td><a href=index.php?module=Settings&action=upload&tempModule='.$currentModule.'&parenttab=Settings>'. $app_strings["LBL_CREATE_MERGE_TEMPLATE"].'</td>');
  260. }
  261. }
  262. }
  263. //mass merge for word templates
  264. //Retreive the List View Table Header
  265. if($viewid !='')
  266. $url_string .= "&viewname=".$viewid;
  267. $controller = new ListViewController($adb, $current_user, $queryGenerator);
  268. $listview_header = $controller->getListViewHeader($focus,$currentModule,$url_string,$sorder,
  269. $order_by);
  270. $smarty->assign("LISTHEADER", $listview_header);
  271. $listview_header_search = $controller->getBasicSearchFieldInfoList();
  272. $smarty->assign("SEARCHLISTHEADER", $listview_header_search);
  273. $listview_entries = $controller->getListViewEntries($focus,$currentModule,$list_result,
  274. $navigation_array);
  275. $smarty->assign("LISTENTITY", $listview_entries);
  276. $smarty->assign("SELECT_SCRIPT", $view_script);
  277. $smarty->assign("CATEGORY",$category);
  278. $smarty->assign("AVALABLE_FIELDS", getMergeFields($currentModule,"available_fields"));
  279. $smarty->assign("FIELDS_TO_MERGE", getMergeFields($currentModule,"fileds_to_merge"));
  280. //Added to select Multiple records in multiple pages
  281. $smarty->assign("SELECTEDIDS", vtlib_purify($_REQUEST['selobjs']));
  282. $smarty->assign("ALLSELECTEDIDS", vtlib_purify($_REQUEST['allselobjs']));
  283. $smarty->assign("CURRENT_PAGE_BOXES", implode(array_keys($listview_entries),";"));
  284. $navigationOutput = getTableHeaderSimpleNavigation($navigation_array, $url_string,"Accounts","index",$viewid);
  285. $alphabetical = AlphabeticalSearch($currentModule,'index','accountname','true','basic',"","","","",$viewid);
  286. $fieldnames = $controller->getAdvancedSearchOptionString();
  287. $criteria = getcriteria_options();
  288. $smarty->assign("CRITERIA", $criteria);
  289. $smarty->assign("FIELDNAMES", $fieldnames);
  290. $smarty->assign("ALPHABETICAL", $alphabetical);
  291. $smarty->assign("NAVIGATION", $navigationOutput);
  292. $check_button = Button_Check($currentModule);
  293. $smarty->assign("CHECK", $check_button);
  294. ListViewSession::setSessionQuery($currentModule,$query,$viewid);
  295. // Gather the custom link information to display
  296. include_once('vtlib/Vtiger/Link.php');
  297. $customlink_params = Array('MODULE'=>$currentModule, 'ACTION'=>vtlib_purify($_REQUEST['action']), 'CATEGORY'=> $category);
  298. $smarty->assign('CUSTOM_LINKS', Vtiger_Link::getAllByType(getTabid($currentModule), Array('LISTVIEWBASIC','LISTVIEW'), $customlink_params));
  299. // END
  300. if(isset($_REQUEST['ajax']) && $_REQUEST['ajax'] != '')
  301. $smarty->display("ListViewEntries.tpl");
  302. else
  303. $smarty->display("ListView.tpl");
  304. ?>