PageRenderTime 25ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/modules/Calendar/ListView.php

https://bitbucket.org/jhunsinfotech/blue-blues
PHP | 296 lines | 208 code | 49 blank | 39 comment | 53 complexity | 43fba9adecf15ee420eec2ac47798502 MD5 | raw file
Possible License(s): LGPL-2.1, 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. /*********************************************************************************
  16. * $Header: /advent/projects/wesat/vtiger_crm/sugarcrm/modules/Activities/ListView.php,v 1.14 2005/03/26 09:45:00 samk Exp $
  17. * Description: TODO: To be written.
  18. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  19. * All Rights Reserved.
  20. * Contributor(s): ______________________________________..
  21. ********************************************************************************/
  22. require_once('Smarty_setup.php');
  23. require_once("data/Tracker.php");
  24. require_once('modules/Calendar/Activity.php');
  25. require_once('include/logging.php');
  26. require_once('include/ListView/ListView.php');
  27. require_once('include/utils/utils.php');
  28. require_once('modules/CustomView/CustomView.php');
  29. require_once('modules/Calendar/CalendarCommon.php');
  30. global $app_strings;
  31. global $list_max_entries_per_page;
  32. $log = LoggerManager::getLogger('task_list');
  33. global $currentModule,$image_path,$theme,$adb;
  34. if (isset($_REQUEST['current_user_only'])) $current_user_only = vtlib_purify($_REQUEST['current_user_only']);
  35. $focus = new Activity();
  36. // Initialize sort by fields
  37. $focus->initSortbyField('Calendar');
  38. // END
  39. $smarty = new vtigerCRM_Smarty;
  40. $other_text = Array();
  41. if(!$_SESSION['lvs'][$currentModule])
  42. {
  43. unset($_SESSION['lvs']);
  44. $modObj = new ListViewSession();
  45. $modObj->sorder = $sorder;
  46. $modObj->sortby = $order_by;
  47. $_SESSION['lvs'][$currentModule] = get_object_vars($modObj);
  48. }
  49. if($_REQUEST['errormsg'] != '')
  50. {
  51. $errormsg = vtlib_purify($_REQUEST['errormsg']);
  52. $smarty->assign("ERROR",$mod_strings["SHARED_EVENT_DEL_MSG"]);
  53. }else
  54. {
  55. $smarty->assign("ERROR","");
  56. }
  57. if(ListViewSession::hasViewChanged($currentModule,$viewid)) {
  58. $_SESSION['ACTIVITIES_ORDER_BY'] = '';
  59. }
  60. //<<<<<<< sort ordering >>>>>>>>>>>>>
  61. $sorder = $focus->getSortOrder();
  62. $order_by = $focus->getOrderBy();
  63. $_SESSION['ACTIVITIES_ORDER_BY'] = $order_by;
  64. $_SESSION['ACTIVITIES_SORT_ORDER'] = $sorder;
  65. //<<<<<<< sort ordering >>>>>>>>>>>>>
  66. //<<<<cutomview>>>>>>>
  67. $oCustomView = new CustomView($currentModule);
  68. $viewid = $oCustomView->getViewId($currentModule);
  69. $customviewcombo_html = $oCustomView->getCustomViewCombo($viewid);
  70. $viewnamedesc = $oCustomView->getCustomViewByCvid($viewid);
  71. //Added to handle approving or denying status-public by the admin in CustomView
  72. $statusdetails = $oCustomView->isPermittedChangeStatus($viewnamedesc['status']);
  73. $smarty->assign("CUSTOMVIEW_PERMISSION",$statusdetails);
  74. //To check if a user is able to edit/delete a customview
  75. $edit_permit = $oCustomView->isPermittedCustomView($viewid,'EditView',$currentModule);
  76. $delete_permit = $oCustomView->isPermittedCustomView($viewid,'Delete',$currentModule);
  77. $smarty->assign("CV_EDIT_PERMIT",$edit_permit);
  78. $smarty->assign("CV_DELETE_PERMIT",$delete_permit);
  79. //<<<<<customview>>>>>
  80. if($viewid == 0 )
  81. {
  82. echo "<table border='0' cellpadding='5' cellspacing='0' width='100%' height='450px'><tr><td align='center'>";
  83. echo "<div style='border: 3px solid rgb(153, 153, 153); background-color: rgb(255, 255, 255); width: 55%; position: relative; z-index: 10000000;'>
  84. <table border='0' cellpadding='5' cellspacing='0' width='98%'>
  85. <tbody><tr>
  86. <td rowspan='2' width='11%'><img src='<?php echo vtiger_imageurl('close.gif', $theme) ?>'></td>
  87. <td style='border-bottom: 1px solid rgb(204, 204, 204);' nowrap='nowrap' width='70%'>
  88. <span class='genHeaderSmall'>$app_strings[LBL_PERMISSION]</span></td>
  89. </tr>
  90. <tr>
  91. <td class='small' align='right' nowrap='nowrap'>
  92. <a href='javascript:window.history.back();'>$app_strings[LBL_GO_BACK]</a><br>
  93. </td>
  94. </tr>
  95. </tbody></table>
  96. </div>";
  97. echo "</td></tr></table>";
  98. exit;
  99. }
  100. $changeOwner = getAssignedTo(16);
  101. $userList = $changeOwner[0];
  102. $groupList = $changeOwner[1];
  103. $smarty->assign("CHANGE_USER",$userList);
  104. $smarty->assign("CHANGE_GROUP",$groupList);
  105. $smarty->assign("CHANGE_OWNER",getUserslist());
  106. $smarty->assign("CHANGE_GROUP_OWNER",getGroupslist());
  107. $smarty->assign('MAX_RECORDS', $list_max_entries_per_page);
  108. $where = "";
  109. $url_string = ''; // assigning http url string
  110. if(isset($_REQUEST['query']) && $_REQUEST['query'] == 'true')
  111. {
  112. list($where, $ustring) = split("#@@#",getWhereCondition($currentModule));
  113. // we have a query
  114. $url_string .="&query=true".$ustring;
  115. $log->info("Here is the where clause for the list view: $where");
  116. $smarty->assign("SEARCH_URL",$url_string);
  117. }
  118. if($viewnamedesc['viewname'] == 'All')
  119. {
  120. $smarty->assign("ALL", 'All');
  121. }
  122. if(isPermitted("Calendar","Delete",$_REQUEST['record']) == 'yes')
  123. {
  124. $other_text['del'] = $app_strings[LBL_MASS_DELETE];
  125. }
  126. if(isPermitted('Calendar','EditView','') == 'yes')
  127. {
  128. $other_text['c_owner'] = $app_strings[LBL_CHANGE_OWNER];
  129. }
  130. global $task_title;
  131. $title_display = $current_module_strings['LBL_LIST_FORM_TITLE'];
  132. if ($task_title) $title_display= $task_title;
  133. //Retreive the list from Database
  134. //<<<<<<<<<customview>>>>>>>>>
  135. if($viewid != "0")
  136. {
  137. $listquery = getListQuery("Calendar");
  138. $list_query = $oCustomView->getModifiedCvListQuery($viewid,$listquery,"Calendar");
  139. }else
  140. {
  141. $list_query = getListQuery("Calendar");
  142. }
  143. //<<<<<<<<customview>>>>>>>>>
  144. if(isset($where) && $where != '')
  145. {
  146. if(isset($_REQUEST['from_homepagedb']) && $_REQUEST['from_homepagedb'] == 'true')
  147. $list_query .= " and ((vtiger_activity.status!='Completed' and vtiger_activity.status!='Deferred') or vtiger_activity.status is null) and ((vtiger_activity.eventstatus!='Held' and vtiger_activity.eventstatus!='Not Held') or vtiger_activity.eventstatus is null) AND ".$where;
  148. else
  149. $list_query .= " AND " .$where;
  150. }
  151. if (isset($_REQUEST['from_homepage'])) {
  152. $dbStartDateTime = new DateTimeField(date('Y-m-d H:i:s'));
  153. $userStartDate = $dbStartDateTime->getDisplayDate();
  154. $userStartDateTime = new DateTimeField($userStartDate.' 00:00:00');
  155. $startDateTime = $userStartDateTime->getDBInsertDateTimeValue();
  156. $userEndDateTime = new DateTimeField($userStartDate.' 23:59:00');
  157. $endDateTime = $userEndDateTime->getDBInsertDateTimeValue();
  158. if ($_REQUEST['from_homepage'] == 'upcoming_activities')
  159. $list_query .= " AND (vtiger_activity.status is NULL OR vtiger_activity.status not in ('Completed','Deferred')) and (vtiger_activity.eventstatus is NULL OR vtiger_activity.eventstatus not in ('Held','Not Held')) AND (CAST((CONCAT(date_start,' ',time_start)) AS DATETIME) >= '$startDateTime' OR CAST((CONCAT(vtiger_recurringevents.recurringdate,' ',time_start)) AS DATETIME) >= '$startDateTime')";
  160. elseif ($_REQUEST['from_homepage'] == 'pending_activities')
  161. $list_query .= " AND (vtiger_activity.status is NULL OR vtiger_activity.status not in ('Completed','Deferred')) and (vtiger_activity.eventstatus is NULL OR vtiger_activity.eventstatus not in ('Held','Not Held')) AND (CAST((CONCAT(due_date,' ',time_end)) AS DATETIME) <= '$endDateTime' OR CAST((CONCAT(vtiger_recurringevents.recurringdate,' ',time_start)) AS DATETIME) <= '$endDateTime')";
  162. }
  163. if(isset($order_by) && $order_by != '') {
  164. if($order_by == 'smownerid') {
  165. $list_query .= ' ORDER BY user_name '.$sorder;
  166. } else {
  167. $tablename = getTableNameForField('Calendar',$order_by);
  168. $tablename = (($tablename != '')?($tablename."."):'');
  169. if($order_by == 'lastname')
  170. $list_query .= ' ORDER BY vtiger_contactdetails.lastname '.$sorder;
  171. else
  172. $list_query .= ' ORDER BY '.$tablename.$order_by.' '.$sorder;
  173. }
  174. }
  175. //Constructing the list view
  176. $smarty->assign("CUSTOMVIEW_OPTION",$customviewcombo_html);
  177. $smarty->assign("VIEWID", $viewid);
  178. $smarty->assign("MOD", $mod_strings);
  179. $smarty->assign("APP", $app_strings);
  180. $smarty->assign("THEME", $theme);
  181. $smarty->assign("IMAGE_PATH",$image_path);
  182. $smarty->assign("MODULE",$currentModule);
  183. $smarty->assign("SINGLE_MOD",getTranslatedString('SINGLE_'.$currentModule, $currentModule));
  184. $smarty->assign("BUTTONS",$other_text);
  185. $smarty->assign("NEW_EVENT",$app_strings['LNK_NEW_EVENT']);
  186. $smarty->assign("NEW_TASK",$app_strings['LNK_NEW_TASK']);
  187. //Postgres 8 fixes
  188. if( $adb->dbType == "pgsql")
  189. $list_query = fixPostgresQuery( $list_query, $log, 0);
  190. if(PerformancePrefs::getBoolean('LISTVIEW_COMPUTE_PAGE_COUNT', false) === true){
  191. $count_result = $adb->query( mkCountQuery( $list_query));
  192. $noofrows = $adb->query_result($count_result,0,"count");
  193. }else{
  194. $noofrows = null;
  195. }
  196. $queryMode = (isset($_REQUEST['query']) && $_REQUEST['query'] == 'true');
  197. $start = ListViewSession::getRequestCurrentPage($currentModule, $list_query, $viewid, $queryMode);
  198. $navigation_array = VT_getSimpleNavigationValues($start,$list_max_entries_per_page,$noofrows);
  199. $limit_start_rec = ($start-1) * $list_max_entries_per_page;
  200. if( $adb->dbType == "pgsql")
  201. $list_result = $adb->pquery($list_query. " OFFSET $limit_start_rec LIMIT $list_max_entries_per_page", array());
  202. else
  203. $list_result = $adb->pquery($list_query. " LIMIT $limit_start_rec, $list_max_entries_per_page", array());
  204. $recordListRangeMsg = getRecordRangeMessage($list_result, $limit_start_rec,$noofrows);
  205. $smarty->assign('recordListRange',$recordListRangeMsg);
  206. //Retreive the List View Table Header
  207. if($viewid !='')
  208. $url_string .="&viewname=".$viewid;
  209. //Cambiado code to add close button in custom vtiger_field
  210. if (($viewid!=0)&&($viewid!="")){
  211. if (!isset($oCustomView->list_fields['Close'])) $oCustomView->list_fields['Close']=array ( 'vtiger_activity' => 'eventstatus' );
  212. if (!isset($oCustomView->list_fields_name['Close'])) $oCustomView->list_fields_name['Close']='eventstatus';
  213. }
  214. $listview_header = getListViewHeader($focus,"Calendar",$url_string,$sorder,$order_by,"",$oCustomView);
  215. $smarty->assign("LISTHEADER", $listview_header);
  216. $listview_header_search=getSearchListHeaderValues($focus,"Calendar",$url_string,$sorder,$order_by,"",$oCustomView);
  217. $smarty->assign("SEARCHLISTHEADER", $listview_header_search);
  218. $listview_entries = getListViewEntries($focus,"Calendar",$list_result,$navigation_array,"","","EditView","Delete",$oCustomView);
  219. $smarty->assign("LISTENTITY", $listview_entries);
  220. $smarty->assign("SELECT_SCRIPT", $view_script);
  221. //Added to select Multiple records in multiple pages
  222. $smarty->assign("SELECTEDIDS", vtlib_purify($_REQUEST['selobjs']));
  223. $smarty->assign("ALLSELECTEDIDS", vtlib_purify($_REQUEST['allselobjs']));
  224. $smarty->assign("CURRENT_PAGE_BOXES", implode(array_keys($listview_entries),";"));
  225. $navigationOutput = getTableHeaderSimpleNavigation($navigation_array,$url_string,"Calendar","ListView",$viewid);
  226. $alphabetical = AlphabeticalSearch($currentModule,'ListView','subject','true','basic',"","","","",$viewid);
  227. $fieldnames = getAdvSearchfields($module);
  228. $criteria = getcriteria_options();
  229. $smarty->assign("CRITERIA", $criteria);
  230. $smarty->assign("FIELDNAMES", $fieldnames);
  231. $smarty->assign("ALPHABETICAL", $alphabetical);
  232. $smarty->assign("NAVIGATION", $navigationOutput);
  233. $category = getParentTab();
  234. $smarty->assign("CATEGORY",$category);
  235. $check_button = Button_Check($module);
  236. $smarty->assign("CHECK", $check_button);
  237. $_SESSION[$currentModule.'_listquery'] = $list_query;
  238. // Gather the custom link information to display
  239. include_once('vtlib/Vtiger/Link.php');
  240. $customlink_params = Array('MODULE'=>$currentModule, 'ACTION'=>vtlib_purify($_REQUEST['action']), 'CATEGORY'=> $category);
  241. $smarty->assign('CUSTOM_LINKS', Vtiger_Link::getAllByType(getTabid($currentModule), Array('LISTVIEWBASIC','LISTVIEW'), $customlink_params));
  242. // END
  243. if(isset($_REQUEST['ajax']) && $_REQUEST['ajax'] != '')
  244. $smarty->display("ListViewEntries.tpl");
  245. else
  246. $smarty->display("ActivityListView.tpl");
  247. ?>