PageRenderTime 71ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 2ms

/include/utils/ListViewUtils.php

https://bitbucket.org/jhunsinfotech/blue-blues
PHP | 4213 lines | 3625 code | 256 blank | 332 comment | 1600 complexity | 263bbd432896f7aae7962de7c1d1d4c4 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, LGPL-3.0

Large files files are truncated, but you can click here to view the full file

  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: /cvsroot/vtigercrm/vtiger_crm/include/utils/ListViewUtils.php,v 1.32 2006/02/03 06:53:08 mangai Exp $
  17. * Description: Includes generic helper functions used throughout the application.
  18. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  19. * All Rights Reserved.
  20. * Contributor(s): ______________________________________..
  21. ********************************************************************************/
  22. require_once('include/database/PearDatabase.php');
  23. require_once('include/ComboUtil.php'); //new
  24. require_once('include/utils/CommonUtils.php'); //new
  25. require_once('user_privileges/default_module_view.php'); //new
  26. require_once('include/utils/UserInfoUtil.php');
  27. require_once('include/Zend/Json.php');
  28. /* * This function is used to get the list view header values in a list view
  29. * Param $focus - module object
  30. * Param $module - module name
  31. * Param $sort_qry - sort by value
  32. * Param $sorder - sorting order (asc/desc)
  33. * Param $order_by - order by
  34. * Param $relatedlist - flag to check whether the header is for listvie or related list
  35. * Param $oCv - Custom view object
  36. * Returns the listview header values in an array
  37. */
  38. function getListViewHeader($focus, $module, $sort_qry = '', $sorder = '', $order_by = '', $relatedlist = '', $oCv = '', $relatedmodule = '', $skipActions = false) {
  39. global $log, $singlepane_view;
  40. $log->debug("Entering getListViewHeader(" . $module . "," . $sort_qry . "," . $sorder . "," . $order_by . "," . $relatedlist . "," . (is_object($oCv) ? get_class($oCv) : $oCv) . ") method ...");
  41. global $adb;
  42. global $theme;
  43. global $app_strings;
  44. global $mod_strings;
  45. global $counter;
  46. $arrow = '';
  47. $qry = getURLstring($focus);
  48. $theme_path = "themes/" . $theme . "/";
  49. $image_path = $theme_path . "images/";
  50. $list_header = Array();
  51. //Get the vtiger_tabid of the module
  52. $tabid = getTabid($module);
  53. $tabname = getParentTab();
  54. global $current_user;
  55. //added for vtiger_customview 27/5
  56. if ($oCv) {
  57. if (isset($oCv->list_fields)) {
  58. $focus->list_fields = $oCv->list_fields;
  59. }
  60. }
  61. // Remove fields which are made inactive
  62. $focus->filterInactiveFields($module);
  63. //Added to reduce the no. of queries logging for non-admin user -- by Minnie-start
  64. $field_list = array();
  65. $j = 0;
  66. require('user_privileges/user_privileges_' . $current_user->id . '.php');
  67. foreach ($focus->list_fields as $name => $tableinfo) {
  68. $fieldname = $focus->list_fields_name[$name];
  69. if ($oCv) {
  70. if (isset($oCv->list_fields_name)) {
  71. $fieldname = $oCv->list_fields_name[$name];
  72. }
  73. }
  74. if ($fieldname == 'accountname' && $module != 'Accounts') {
  75. $fieldname = 'account_id';
  76. }
  77. if ($fieldname == 'lastname' && ($module == 'SalesOrder' || $module == 'PurchaseOrder' || $module == 'Invoice' || $module == 'Quotes' || $module == 'Calendar' )) {
  78. $fieldname = 'contact_id';
  79. }
  80. if ($fieldname == 'productname' && $module != 'Products') {
  81. $fieldname = 'product_id';
  82. }
  83. array_push($field_list, $fieldname);
  84. $j++;
  85. }
  86. $field = Array();
  87. if ($is_admin == false) {
  88. if ($module == 'Emails') {
  89. $query = "SELECT fieldname FROM vtiger_field WHERE tabid = ? and vtiger_field.presence in (0,2)";
  90. $params = array($tabid);
  91. } else {
  92. $profileList = getCurrentUserProfileList();
  93. $params = array();
  94. $query = "SELECT DISTINCT vtiger_field.fieldname
  95. FROM vtiger_field
  96. INNER JOIN vtiger_profile2field
  97. ON vtiger_profile2field.fieldid = vtiger_field.fieldid
  98. INNER JOIN vtiger_def_org_field
  99. ON vtiger_def_org_field.fieldid = vtiger_field.fieldid";
  100. if ($module == "Calendar") {
  101. $query .=" WHERE vtiger_field.tabid in (9,16) and vtiger_field.presence in (0,2)";
  102. } else {
  103. $query .=" WHERE vtiger_field.tabid = ? and vtiger_field.presence in (0,2)";
  104. array_push($params, $tabid);
  105. }
  106. $query.=" AND vtiger_profile2field.visible = 0
  107. AND vtiger_def_org_field.visible = 0
  108. AND vtiger_profile2field.profileid IN (" . generateQuestionMarks($profileList) . ")
  109. AND vtiger_field.fieldname IN (" . generateQuestionMarks($field_list) . ")";
  110. array_push($params, $profileList, $field_list);
  111. }
  112. $result = $adb->pquery($query, $params);
  113. for ($k = 0; $k < $adb->num_rows($result); $k++) {
  114. $field[] = $adb->query_result($result, $k, "fieldname");
  115. }
  116. }
  117. //end
  118. //modified for vtiger_customview 27/5 - $app_strings change to $mod_strings
  119. foreach ($focus->list_fields as $name => $tableinfo) {
  120. //added for vtiger_customview 27/5
  121. if ($oCv) {
  122. if (isset($oCv->list_fields_name)) {
  123. $fieldname = $oCv->list_fields_name[$name];
  124. if ($fieldname == 'accountname' && $module != 'Accounts') {
  125. $fieldname = 'account_id';
  126. }
  127. if ($fieldname == 'lastname' && ($module == 'SalesOrder' || $module == 'PurchaseOrder' || $module == 'Invoice' || $module == 'Quotes' || $module == 'Calendar')) {
  128. $fieldname = 'contact_id';
  129. }
  130. if ($fieldname == 'productname' && $module != 'Products') {
  131. $fieldname = 'product_id';
  132. }
  133. } else {
  134. $fieldname = $focus->list_fields_name[$name];
  135. }
  136. } else {
  137. $fieldname = $focus->list_fields_name[$name];
  138. if ($fieldname == 'accountname' && $module != 'Accounts') {
  139. $fieldname = 'account_id';
  140. }
  141. if ($fieldname == 'lastname' && ($module == 'SalesOrder' || $module == 'PurchaseOrder' || $module == 'Invoice' || $module == 'Quotes' || $module == 'Calendar')) {
  142. $fieldname = 'contact_id';
  143. }
  144. if ($fieldname == 'productname' && $module != 'Products') {
  145. $fieldname = 'product_id';
  146. }
  147. }
  148. if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0 || in_array($fieldname, $field) || $fieldname == '' || ($name == 'Close' && $module == 'Calendar')) {
  149. if (isset($focus->sortby_fields) && $focus->sortby_fields != '') {
  150. //Added on 14-12-2005 to avoid if and else check for every list vtiger_field for arrow image and change order
  151. $change_sorder = array('ASC' => 'DESC', 'DESC' => 'ASC');
  152. $arrow_gif = array('ASC' => 'arrow_down.gif', 'DESC' => 'arrow_up.gif');
  153. foreach ($focus->list_fields[$name] as $tab => $col) {
  154. if (in_array($col, $focus->sortby_fields)) {
  155. if ($order_by == $col) {
  156. $temp_sorder = $change_sorder[$sorder];
  157. $arrow = "&nbsp;<img src ='" . vtiger_imageurl($arrow_gif[$sorder], $theme) . "' border='0'>";
  158. } else {
  159. $temp_sorder = 'ASC';
  160. }
  161. $lbl_name = getTranslatedString(decode_html($name), $module);
  162. //added to display vtiger_currency symbol in listview header
  163. if ($lbl_name == 'Amount') {
  164. $lbl_name .=' (' . $app_strings['LBL_IN'] . ' ' . $user_info['currency_symbol'] . ')';
  165. }
  166. if ($relatedlist != '' && $relatedlist != 'global') {
  167. $relationURL = '';
  168. if (!empty($_REQUEST['relation_id'])) {
  169. $relationURL = '&relation_id=' . vtlib_purify(
  170. $_REQUEST['relation_id']);
  171. }
  172. $actionsURL = '';
  173. if (!empty($_REQUEST['actions'])) {
  174. $actionsURL = '&actions=' . vtlib_purify($_REQUEST['actions']);
  175. }
  176. if (empty($_REQUEST['header'])) {
  177. $moduleLabel = getTranslatedString($module, $module);
  178. } else {
  179. $moduleLabel = $_REQUEST['header'];
  180. }
  181. $moduleLabel = str_replace(' ', '', $moduleLabel);
  182. $name = "<a href='javascript:void(0);' onClick='loadRelatedListBlock" .
  183. "(\"module=$relatedmodule&action=" . $relatedmodule . "Ajax&" .
  184. "file=DetailViewAjax&ajxaction=LOADRELATEDLIST&header=" . $moduleLabel .
  185. "&order_by=$col&record=$relatedlist&sorder=$temp_sorder$relationURL" .
  186. "$actionsURL\",\"tbl_" . $relatedmodule . "_$moduleLabel\"," .
  187. "\"$relatedmodule" . "_$moduleLabel\");' class='listFormHeaderLinks'>" . $lbl_name . "" . $arrow . "</a>";
  188. } elseif ($module == 'Users' && $name == 'User Name')
  189. $name = "<a href='javascript:;' onClick='getListViewEntries_js(\"" . $module . "\",\"parenttab=" . $tabname . "&order_by=" . $col . "&start=1&sorder=" . $temp_sorder . "" . $sort_qry . "\");' class='listFormHeaderLinks'>" . getTranslatedString('LBL_LIST_USER_NAME_ROLE', $module) . "" . $arrow . "</a>";
  190. elseif ($relatedlist == "global")
  191. $name = $lbl_name;
  192. else
  193. $name = "<a href='javascript:;' onClick='getListViewEntries_js(\"" . $module . "\",\"parenttab=" . $tabname . "&order_by=" . $col . "&start=1&sorder=" . $temp_sorder . "" . $sort_qry . "\");' class='listFormHeaderLinks'>" . $lbl_name . "" . $arrow . "</a>";
  194. $arrow = '';
  195. }
  196. else {
  197. if (stripos($col, 'cf_') === 0) {
  198. $tablenameArray = array_keys($tableinfo, $col);
  199. $tablename = $tablenameArray[0];
  200. $cf_columns = $adb->getColumnNames($tablename);
  201. if (array_search($col, $cf_columns) != null) {
  202. $pquery = "select fieldlabel,typeofdata from vtiger_field where tablename = ? and fieldname = ? and vtiger_field.presence in (0,2)";
  203. $cf_res = $adb->pquery($pquery, array($tablename, $col));
  204. if (count($cf_res) > 0) {
  205. $cf_fld_label = $adb->query_result($cf_res, 0, "fieldlabel");
  206. $typeofdata = explode("~", $adb->query_result($cf_res, 0, "typeofdata"));
  207. $new_field_label = $tablename . ":" . $col . ":" . $col . ":" . $module . "_" . str_replace(" ", "_", $cf_fld_label) . ":" . $typeofdata[0];
  208. $name = $cf_fld_label;
  209. // Update the existing field name in the database with new field name.
  210. $upd_query = "update vtiger_cvcolumnlist set columnname = ? where columnname like '" . $tablename . ":" . $col . ":" . $col . "%'";
  211. $upd_params = array($new_field_label);
  212. $adb->pquery($upd_query, $upd_params);
  213. }
  214. }
  215. } else {
  216. $name = getTranslatedString($name, $module);
  217. }
  218. }
  219. }
  220. }
  221. //added to display vtiger_currency symbol in related listview header
  222. if ($name == 'Amount' && $relatedlist != '') {
  223. $name .=' (' . $app_strings['LBL_IN'] . ' ' . $user_info['currency_symbol'] . ')';
  224. }
  225. if ($module == "Calendar" && $name == $app_strings['Close']) {
  226. if (isPermitted("Calendar", "EditView") == 'yes') {
  227. if ((getFieldVisibilityPermission('Events', $current_user->id, 'eventstatus') == '0') || (getFieldVisibilityPermission('Calendar', $current_user->id, 'taskstatus') == '0')) {
  228. array_push($list_header, $name);
  229. }
  230. }
  231. } else {
  232. $list_header[] = $name;
  233. }
  234. }
  235. }
  236. //Added for Action - edit and delete link header in listview
  237. if (!$skipActions && (isPermitted($module, "EditView", "") == 'yes' || isPermitted($module, "Delete", "") == 'yes'))
  238. $list_header[] = $app_strings["LBL_ACTION"];
  239. $log->debug("Exiting getListViewHeader method ...");
  240. return $list_header;
  241. }
  242. /* * This function is used to get the list view header in popup
  243. * Param $focus - module object
  244. * Param $module - module name
  245. * Param $sort_qry - sort by value
  246. * Param $sorder - sorting order (asc/desc)
  247. * Param $order_by - order by
  248. * Returns the listview header values in an array
  249. */
  250. function getSearchListViewHeader($focus, $module, $sort_qry = '', $sorder = '', $order_by = '') {
  251. global $log;
  252. $log->debug("Entering getSearchListViewHeader(" . get_class($focus) . "," . $module . "," . $sort_qry . "," . $sorder . "," . $order_by . ") method ...");
  253. global $adb;
  254. global $theme;
  255. global $app_strings;
  256. global $mod_strings, $current_user;
  257. $arrow = '';
  258. $list_header = Array();
  259. $tabid = getTabid($module);
  260. if (isset($_REQUEST['task_relmod_id'])) {
  261. $task_relmod_id = vtlib_purify($_REQUEST['task_relmod_id']);
  262. $pass_url .="&task_relmod_id=" . $task_relmod_id;
  263. }
  264. if (isset($_REQUEST['relmod_id'])) {
  265. $relmod_id = vtlib_purify($_REQUEST['relmod_id']);
  266. $pass_url .="&relmod_id=" . $relmod_id;
  267. }
  268. if (isset($_REQUEST['task_parent_module'])) {
  269. $task_parent_module = vtlib_purify($_REQUEST['task_parent_module']);
  270. $pass_url .="&task_parent_module=" . $task_parent_module;
  271. }
  272. if (isset($_REQUEST['parent_module'])) {
  273. $parent_module = vtlib_purify($_REQUEST['parent_module']);
  274. $pass_url .="&parent_module=" . $parent_module;
  275. }
  276. if (isset($_REQUEST['fromPotential']) && (isset($_REQUEST['acc_id']) && $_REQUEST['acc_id'] != '')) {
  277. $pass_url .="&parent_module=Accounts&relmod_id=" . vtlib_purify($_REQUEST['acc_id']);
  278. }
  279. // vtlib Customization : For uitype 10 popup during paging
  280. if ($_REQUEST['form'] == 'vtlibPopupView') {
  281. $pass_url .= '&form=vtlibPopupView&forfield=' . vtlib_purify($_REQUEST['forfield']) . '&srcmodule=' . vtlib_purify($_REQUEST['srcmodule']) . '&forrecord=' . vtlib_purify($_REQUEST['forrecord']);
  282. }
  283. // END
  284. //Added to reduce the no. of queries logging for non-admin user -- by Minnie-start
  285. $field_list = array();
  286. $j = 0;
  287. require('user_privileges/user_privileges_' . $current_user->id . '.php');
  288. foreach ($focus->search_fields as $name => $tableinfo) {
  289. $fieldname = $focus->search_fields_name[$name];
  290. array_push($field_list, $fieldname);
  291. $j++;
  292. }
  293. $field = Array();
  294. if ($is_admin == false && $module != 'Users') {
  295. if ($module == 'Emails') {
  296. $query = "SELECT fieldname FROM vtiger_field WHERE tabid = ? and vtiger_field.presence in (0,2)";
  297. $params = array($tabid);
  298. } else {
  299. $profileList = getCurrentUserProfileList();
  300. $query = "SELECT DISTINCT vtiger_field.fieldname
  301. FROM vtiger_field
  302. INNER JOIN vtiger_profile2field
  303. ON vtiger_profile2field.fieldid = vtiger_field.fieldid
  304. INNER JOIN vtiger_def_org_field
  305. ON vtiger_def_org_field.fieldid = vtiger_field.fieldid
  306. WHERE vtiger_field.tabid = ?
  307. AND vtiger_profile2field.visible=0
  308. AND vtiger_def_org_field.visible=0
  309. AND vtiger_profile2field.profileid IN (" . generateQuestionMarks($profileList) . ")
  310. AND vtiger_field.fieldname IN (" . generateQuestionMarks($field_list) . ") and vtiger_field.presence in (0,2)";
  311. $params = array($tabid, $profileList, $field_list);
  312. }
  313. $result = $adb->pquery($query, $params);
  314. for ($k = 0; $k < $adb->num_rows($result); $k++) {
  315. $field[] = $adb->query_result($result, $k, "fieldname");
  316. }
  317. }
  318. //end
  319. $theme_path = "themes/" . $theme . "/";
  320. $image_path = $theme_path . "images/";
  321. $focus->filterInactiveFields($module);
  322. foreach ($focus->search_fields as $name => $tableinfo) {
  323. $fieldname = $focus->search_fields_name[$name];
  324. $tabid = getTabid($module);
  325. global $current_user;
  326. require('user_privileges/user_privileges_' . $current_user->id . '.php');
  327. if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0 || in_array($fieldname, $field) || $module == 'Users') {
  328. if (isset($focus->sortby_fields) && $focus->sortby_fields != '') {
  329. foreach ($focus->search_fields[$name] as $tab => $col) {
  330. if (in_array($col, $focus->sortby_fields)) {
  331. if ($order_by == $col) {
  332. if ($sorder == 'ASC') {
  333. $sorder = "DESC";
  334. $arrow = "<img src ='" . vtiger_imageurl('arrow_down.gif', $theme) . "' border='0'>";
  335. } else {
  336. $sorder = 'ASC';
  337. $arrow = "<img src ='" . vtiger_imageurl('arrow_up.gif', $theme) . "' border='0'>";
  338. }
  339. }
  340. // vtlib customization: If translation is not available use the given name
  341. $tr_name = getTranslatedString($name, $module);
  342. $name = "<a href='javascript:;' onClick=\"getListViewSorted_js('" . $module . "','" . $sort_qry . $pass_url . "&order_by=" . $col . "&sorder=" . $sorder . "')\" class='listFormHeaderLinks'>" . $tr_name . "&nbsp;" . $arrow . "</a>";
  343. // END
  344. $arrow = '';
  345. } else {
  346. // vtlib customization: If translation is not available use the given name
  347. $tr_name = getTranslatedString($name, $module);
  348. $name = $tr_name;
  349. // END
  350. }
  351. }
  352. }
  353. $list_header[] = $name;
  354. }
  355. }
  356. $log->debug("Exiting getSearchListViewHeader method ...");
  357. return $list_header;
  358. }
  359. /* * This function generates the navigation array in a listview
  360. * Param $display - start value of the navigation
  361. * Param $noofrows - no of records
  362. * Param $limit - no of entries per page
  363. * Returns an array type
  364. */
  365. //code contributed by raju for improved pagination
  366. function getNavigationValues($display, $noofrows, $limit) {
  367. global $log;
  368. $log->debug("Entering getNavigationValues(" . $display . "," . $noofrows . "," . $limit . ") method ...");
  369. $navigation_array = Array();
  370. global $limitpage_navigation;
  371. if (isset($_REQUEST['allflag']) && $_REQUEST['allflag'] == 'All') {
  372. $navigation_array['start'] = 1;
  373. $navigation_array['first'] = 1;
  374. $navigation_array['end'] = 1;
  375. $navigation_array['prev'] = 0;
  376. $navigation_array['next'] = 0;
  377. $navigation_array['end_val'] = $noofrows;
  378. $navigation_array['current'] = 1;
  379. $navigation_array['allflag'] = 'Normal';
  380. $navigation_array['verylast'] = 1;
  381. $log->debug("Exiting getNavigationValues method ...");
  382. return $navigation_array;
  383. }
  384. if ($noofrows != 0) {
  385. if (((($display * $limit) - $limit) + 1) > $noofrows) {
  386. $display = floor($noofrows / $limit);
  387. }
  388. $start = ((($display * $limit) - $limit) + 1);
  389. } else {
  390. $start = 0;
  391. }
  392. $end = $start + ($limit - 1);
  393. if ($end > $noofrows) {
  394. $end = $noofrows;
  395. }
  396. $paging = ceil($noofrows / $limit);
  397. // Display the navigation
  398. if ($display > 1) {
  399. $previous = $display - 1;
  400. } else {
  401. $previous = 0;
  402. }
  403. if ($noofrows < $limit) {
  404. $first = '';
  405. } elseif ($noofrows != $limit) {
  406. $last = $paging;
  407. $first = 1;
  408. if ($paging > $limitpage_navigation) {
  409. $first = $display - floor(($limitpage_navigation / 2));
  410. if ($first < 1)
  411. $first = 1;
  412. $last = ($limitpage_navigation - 1) + $first;
  413. }
  414. if ($last > $paging) {
  415. $first = $paging - ($limitpage_navigation - 1);
  416. $last = $paging;
  417. }
  418. }
  419. if ($display < $paging) {
  420. $next = $display + 1;
  421. } else {
  422. $next = 0;
  423. }
  424. $navigation_array['start'] = $start;
  425. $navigation_array['first'] = $first;
  426. $navigation_array['end'] = $last;
  427. $navigation_array['prev'] = $previous;
  428. $navigation_array['next'] = $next;
  429. $navigation_array['end_val'] = $end;
  430. $navigation_array['current'] = $display;
  431. $navigation_array['allflag'] = 'All';
  432. $navigation_array['verylast'] = $paging;
  433. $log->debug("Exiting getNavigationValues method ...");
  434. return $navigation_array;
  435. }
  436. //End of code contributed by raju for improved pagination
  437. /* * This function generates the List view entries in a list view
  438. * Param $focus - module object
  439. * Param $list_result - resultset of a listview query
  440. * Param $navigation_array - navigation values in an array
  441. * Param $relatedlist - check for related list flag
  442. * Param $returnset - list query parameters in url string
  443. * Param $edit_action - Edit action value
  444. * Param $del_action - delete action value
  445. * Param $oCv - vtiger_customview object
  446. * Returns an array type
  447. */
  448. //parameter added for vtiger_customview $oCv 27/5
  449. function getListViewEntries($focus, $module, $list_result, $navigation_array, $relatedlist = '', $returnset = '', $edit_action = 'EditView', $del_action = 'Delete', $oCv = '', $page = '', $selectedfields = '', $contRelatedfields = '', $skipActions = false) {
  450. global $log;
  451. global $mod_strings;
  452. $log->debug("Entering getListViewEntries(" . get_class($focus) . "," . $module . "," . $list_result . "," . $navigation_array . "," . $relatedlist . "," . $returnset . "," . $edit_action . "," . $del_action . "," . (is_object($oCv) ? get_class($oCv) : $oCv) . ") method ...");
  453. $tabname = getParentTab();
  454. global $adb, $current_user;
  455. global $app_strings;
  456. $noofrows = $adb->num_rows($list_result);
  457. $list_block = Array();
  458. global $theme;
  459. $evt_status = '';
  460. $theme_path = "themes/" . $theme . "/";
  461. $image_path = $theme_path . "images/";
  462. //getting the vtiger_fieldtable entries from database
  463. $tabid = getTabid($module);
  464. //added for vtiger_customview 27/5
  465. if ($oCv) {
  466. if (isset($oCv->list_fields)) {
  467. $focus->list_fields = $oCv->list_fields;
  468. }
  469. }
  470. if (is_array($selectedfields) && $selectedfields != '') {
  471. $focus->list_fields = $selectedfields;
  472. }
  473. // Remove fields which are made inactive
  474. $focus->filterInactiveFields($module);
  475. //Added to reduce the no. of queries logging for non-admin user -- by minnie-start
  476. $field_list = array();
  477. $j = 0;
  478. require('user_privileges/user_privileges_' . $current_user->id . '.php');
  479. foreach ($focus->list_fields as $name => $tableinfo) {
  480. $fieldname = $focus->list_fields_name[$name];
  481. if ($oCv) {
  482. if (isset($oCv->list_fields_name)) {
  483. $fieldname = $oCv->list_fields_name[$name];
  484. }
  485. }
  486. if ($fieldname == 'accountname' && $module != 'Accounts') {
  487. $fieldname = 'account_id';
  488. }
  489. if ($fieldname == 'lastname' && ($module == 'SalesOrder' || $module == 'PurchaseOrder' || $module == 'Invoice' || $module == 'Quotes' || $module == 'Calendar'))
  490. $fieldname = 'contact_id';
  491. if ($fieldname == 'productname' && $module != 'Products') {
  492. $fieldname = 'product_id';
  493. }
  494. array_push($field_list, $fieldname);
  495. $j++;
  496. }
  497. $field = Array();
  498. if ($is_admin == false) {
  499. if ($module == 'Emails') {
  500. $query = "SELECT fieldname FROM vtiger_field WHERE tabid = ? and vtiger_field.presence in (0,2)";
  501. $params = array($tabid);
  502. } else {
  503. $profileList = getCurrentUserProfileList();
  504. $params = array();
  505. $query = "SELECT DISTINCT vtiger_field.fieldname
  506. FROM vtiger_field
  507. INNER JOIN vtiger_profile2field
  508. ON vtiger_profile2field.fieldid = vtiger_field.fieldid
  509. INNER JOIN vtiger_def_org_field
  510. ON vtiger_def_org_field.fieldid = vtiger_field.fieldid";
  511. if ($module == "Calendar")
  512. $query .=" WHERE vtiger_field.tabid in (9,16) and vtiger_field.presence in (0,2)";
  513. else {
  514. $query .=" WHERE vtiger_field.tabid = ? and vtiger_field.presence in (0,2)";
  515. array_push($params, $tabid);
  516. }
  517. $query .=" AND vtiger_profile2field.visible = 0
  518. AND vtiger_profile2field.visible = 0
  519. AND vtiger_def_org_field.visible = 0
  520. AND vtiger_profile2field.profileid IN (" . generateQuestionMarks($profileList) . ")
  521. AND vtiger_field.fieldname IN (" . generateQuestionMarks($field_list) . ")";
  522. array_push($params, $profileList, $field_list);
  523. }
  524. $result = $adb->pquery($query, $params);
  525. for ($k = 0; $k < $adb->num_rows($result); $k++) {
  526. $field[] = $adb->query_result($result, $k, "fieldname");
  527. }
  528. }
  529. //constructing the uitype and columnname array
  530. $ui_col_array = Array();
  531. $params = array();
  532. $query = "SELECT uitype, columnname, fieldname FROM vtiger_field ";
  533. if ($module == "Calendar")
  534. $query .=" WHERE vtiger_field.tabid in (9,16) and vtiger_field.presence in (0,2)";
  535. else {
  536. $query .=" WHERE vtiger_field.tabid = ? and vtiger_field.presence in (0,2)";
  537. array_push($params, $tabid);
  538. }
  539. $query .= " AND fieldname IN (" . generateQuestionMarks($field_list) . ") ";
  540. array_push($params, $field_list);
  541. $result = $adb->pquery($query, $params);
  542. $num_rows = $adb->num_rows($result);
  543. for ($i = 0; $i < $num_rows; $i++) {
  544. $tempArr = array();
  545. $uitype = $adb->query_result($result, $i, 'uitype');
  546. $columnname = $adb->query_result($result, $i, 'columnname');
  547. $field_name = $adb->query_result($result, $i, 'fieldname');
  548. $tempArr[$uitype] = $columnname;
  549. $ui_col_array[$field_name] = $tempArr;
  550. }
  551. //end
  552. if ($navigation_array['start'] != 0)
  553. for ($i = 1; $i <= $noofrows; $i++) {
  554. $list_header = Array();
  555. //Getting the entityid
  556. if ($module != 'Users') {
  557. $entity_id = $adb->query_result($list_result, $i - 1, "crmid");
  558. $owner_id = $adb->query_result($list_result, $i - 1, "smownerid");
  559. } else {
  560. $entity_id = $adb->query_result($list_result, $i - 1, "id");
  561. }
  562. // Fredy Klammsteiner, 4.8.2005: changes from 4.0.1 migrated to 4.2
  563. // begin: Armando Lüscher 05.07.2005 -> §priority
  564. // Code contri buted by fredy Desc: Set Priority color
  565. $priority = $adb->query_result($list_result, $i - 1, "priority");
  566. $font_color_high = "color:#00DD00;";
  567. $font_color_medium = "color:#DD00DD;";
  568. $P_FONT_COLOR = "";
  569. switch ($priority) {
  570. case 'High':
  571. $P_FONT_COLOR = $font_color_high;
  572. break;
  573. case 'Medium':
  574. $P_FONT_COLOR = $font_color_medium;
  575. break;
  576. default:
  577. $P_FONT_COLOR = "";
  578. }
  579. //end: Armando Lüscher 05.07.2005 -> §priority
  580. foreach ($focus->list_fields as $name => $tableinfo) {
  581. $fieldname = $focus->list_fields_name[$name];
  582. //added for vtiger_customview 27/5
  583. if ($oCv) {
  584. if (isset($oCv->list_fields_name)) {
  585. $fieldname = $oCv->list_fields_name[$name];
  586. if ($fieldname == 'accountname' && $module != 'Accounts') {
  587. $fieldname = 'account_id';
  588. }
  589. if ($fieldname == 'lastname' && ($module == 'SalesOrder' || $module == 'PurchaseOrder' || $module == 'Invoice' || $module == 'Quotes' || $module == 'Calendar' )) {
  590. $fieldname = 'contact_id';
  591. }
  592. if ($fieldname == 'productname' && $module != 'Products') {
  593. $fieldname = 'product_id';
  594. }
  595. } else {
  596. $fieldname = $focus->list_fields_name[$name];
  597. }
  598. } else {
  599. $fieldname = $focus->list_fields_name[$name];
  600. if ($fieldname == 'accountname' && $module != 'Accounts') {
  601. $fieldname = 'account_id';
  602. }
  603. if ($fieldname == 'lastname' && ($module == 'SalesOrder' || $module == 'PurchaseOrder' || $module == 'Invoice' || $module == 'Quotes' || $module == 'Calendar')) {
  604. $fieldname = 'contact_id';
  605. }
  606. if ($fieldname == 'productname' && $module != 'Products') {
  607. $fieldname = 'product_id';
  608. }
  609. }
  610. if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0 || in_array($fieldname, $field) || $fieldname == '' || ($name == 'Close' && $module == 'Calendar')) {
  611. if ($fieldname == '') {
  612. $table_name = '';
  613. $column_name = '';
  614. foreach ($tableinfo as $tablename => $colname) {
  615. $table_name = $tablename;
  616. $column_name = $colname;
  617. }
  618. $value = $adb->query_result($list_result, $i - 1, $colname);
  619. } else {
  620. if ($module == 'Calendar') {
  621. $act_id = $adb->query_result($list_result, $i - 1, "activityid");
  622. $activitytype = $adb->query_result($list_result, $i - 1, 'activitytype');
  623. if (empty($activitytype)) {
  624. $cal_sql = "select activitytype from vtiger_activity where activityid=?";
  625. $cal_res = $adb->pquery($cal_sql, array($act_id));
  626. if ($adb->num_rows($cal_res) >= 0)
  627. $activitytype = $adb->query_result($cal_res, 0, "activitytype");
  628. }
  629. }
  630. if (($module == 'Calendar' || $module == 'Emails' || $module == 'HelpDesk' || $module == 'Invoice' || $module == 'Leads' || $module == 'Contacts') && (($fieldname == 'parent_id') || ($name == 'Contact Name') || ($name == 'Close') || ($fieldname == 'firstname'))) {
  631. if ($module == 'Calendar') {
  632. if ($fieldname == 'status') {
  633. if ($activitytype == 'Task') {
  634. $fieldname = 'taskstatus';
  635. } else {
  636. $fieldname = 'eventstatus';
  637. }
  638. }
  639. if ($activitytype == 'Task') {
  640. if (getFieldVisibilityPermission('Calendar', $current_user->id, $fieldname) == '0') {
  641. $has_permission = 'yes';
  642. } else {
  643. $has_permission = 'no';
  644. }
  645. } else {
  646. if (getFieldVisibilityPermission('Events', $current_user->id, $fieldname) == '0') {
  647. $has_permission = 'yes';
  648. } else {
  649. $has_permission = 'no';
  650. }
  651. }
  652. }
  653. if ($module != 'Calendar' || ($module == 'Calendar' && $has_permission == 'yes')) {
  654. if ($fieldname == 'parent_id') {
  655. $value = getRelatedTo($module, $list_result, $i - 1);
  656. }
  657. if ($name == 'Contact Name') {
  658. $contact_id = $adb->query_result($list_result, $i - 1, "contactid");
  659. $contact_name = getFullNameFromQResult($list_result, $i - 1, "Contacts");
  660. $value = "";
  661. //Added to get the contactname for activities custom view - t=2190
  662. if ($contact_id != '' && !empty($contact_name)) {
  663. $displayValueArray = getEntityName('Contacts', $contact_id);
  664. if (!empty($displayValueArray)) {
  665. foreach ($displayValueArray as $key => $field_value) {
  666. $contact_name = $field_value;
  667. }
  668. }
  669. }
  670. if (($contact_name != "") && ($contact_id != 'NULL')) {
  671. // Fredy Klammsteiner, 4.8.2005: changes from 4.0.1 migrated to 4.2
  672. $value = "<a href='index.php?module=Contacts&action=DetailView&parenttab=" . $tabname . "&record=" . $contact_id . "' style='" . $P_FONT_COLOR . "'>" . textlength_check($contact_name) . "</a>"; // Armando Lüscher 05.07.2005 -> §priority -> Desc: inserted style="$P_FONT_COLOR"
  673. }
  674. }
  675. if ($fieldname == "firstname") {
  676. $first_name = textlength_check($adb->query_result($list_result, $i - 1, "firstname"));
  677. $value = '<a href="index.php?action=DetailView&module=' . $module . '&parenttab=' . $tabname . '&record=' . $entity_id . '">' . $first_name . '</a>';
  678. }
  679. if ($name == 'Close') {
  680. $status = $adb->query_result($list_result, $i - 1, "status");
  681. $activityid = $adb->query_result($list_result, $i - 1, "activityid");
  682. if (empty($activityid)) {
  683. $activityid = $adb->query_result($list_result, $i - 1, "tmp_activity_id");
  684. }
  685. if ($activitytype != 'Task' && $activitytype != 'Emails') {
  686. $eventstatus = $adb->query_result($list_result, $i - 1, "eventstatus");
  687. if (isset($eventstatus)) {
  688. $status = $eventstatus;
  689. }
  690. }
  691. if ($status == 'Deferred' || $status == 'Completed' || $status == 'Held' || $status == '') {
  692. $value = "";
  693. } else {
  694. if ($activitytype == 'Task')
  695. $evt_status = '&status=Completed';
  696. else
  697. $evt_status = '&eventstatus=Held';
  698. if (isPermitted("Calendar", 'EditView', $activityid) == 'yes') {
  699. if ($returnset == '') {
  700. $returnset = '&return_module=Calendar&return_action=ListView&return_id=' . $activityid . '&return_viewname=' . $oCv->setdefaultviewid;
  701. }
  702. // Fredy Klammsteiner, 4.8.2005: changes from 4.0.1 migrated to 4.2
  703. $value = "<a href='index.php?action=Save&module=Calendar&record=" . $activityid . "&parenttab=" . $tabname . "&change_status=true" . $returnset . $evt_status . "&start=" . $navigation_array['current'] . "' style='" . $P_FONT_COLOR . "'>X</a>"; // Armando Lüscher 05.07.2005 -> §priority -> Desc: inserted style="$P_FONT_COLOR"
  704. } else {
  705. $value = "";
  706. }
  707. }
  708. }
  709. } else {
  710. $value = "";
  711. }
  712. } elseif ($module == "Documents" && ($fieldname == 'filelocationtype' || $fieldname == 'filename' || $fieldname == 'filesize' || $fieldname == 'filestatus' || $fieldname == 'filetype')) {
  713. $value = $adb->query_result($list_result, $i - 1, $fieldname);
  714. if ($fieldname == 'filelocationtype') {
  715. if ($value == 'I')
  716. $value = getTranslatedString('LBL_INTERNAL', $module);
  717. elseif ($value == 'E')
  718. $value = getTranslatedString('LBL_EXTERNAL', $module);
  719. else
  720. $value = ' --';
  721. }
  722. if ($fieldname == 'filename') {
  723. $downloadtype = $adb->query_result($list_result, $i - 1, 'filelocationtype');
  724. if ($downloadtype == 'I') {
  725. $fld_value = $value;
  726. $ext_pos = strrpos($fld_value, ".");
  727. $ext = substr($fld_value, $ext_pos + 1);
  728. $ext = strtolower($ext);
  729. if ($value != '') {
  730. if ($ext == 'bin' || $ext == 'exe' || $ext == 'rpm')
  731. $fileicon = "<img src='" . vtiger_imageurl('fExeBin.gif', $theme) . "' hspace='3' align='absmiddle' border='0'>";
  732. elseif ($ext == 'jpg' || $ext == 'gif' || $ext == 'bmp')
  733. $fileicon = "<img src='" . vtiger_imageurl('fbImageFile.gif', $theme) . "' hspace='3' align='absmiddle' border='0'>";
  734. elseif ($ext == 'txt' || $ext == 'doc' || $ext == 'xls')
  735. $fileicon = "<img src='" . vtiger_imageurl('fbTextFile.gif', $theme) . "' hspace='3' align='absmiddle' border='0'>";
  736. elseif ($ext == 'zip' || $ext == 'gz' || $ext == 'rar')
  737. $fileicon = "<img src='" . vtiger_imageurl('fbZipFile.gif', $theme) . "' hspace='3' align='absmiddle' border='0'>";
  738. else
  739. $fileicon = "<img src='" . vtiger_imageurl('fbUnknownFile.gif', $theme) . "' hspace='3' align='absmiddle' border='0'>";
  740. }
  741. } elseif ($downloadtype == 'E') {
  742. if (trim($value) != '') {
  743. $fld_value = $value;
  744. $fileicon = "<img src='" . vtiger_imageurl('fbLink.gif', $theme) . "' alt='" . getTranslatedString('LBL_EXTERNAL_LNK', $module) . "' title='" . getTranslatedString('LBL_EXTERNAL_LNK', $module) . "' hspace='3' align='absmiddle' border='0'>";
  745. } else {
  746. $fld_value = '--';
  747. $fileicon = '';
  748. }
  749. } else {
  750. $fld_value = ' --';
  751. $fileicon = '';
  752. }
  753. $file_name = $adb->query_result($list_result, $i - 1, 'filename');
  754. $notes_id = $adb->query_result($list_result, $i - 1, 'crmid');
  755. $folder_id = $adb->query_result($list_result, $i - 1, 'folderid');
  756. $download_type = $adb->query_result($list_result, $i - 1, 'filelocationtype');
  757. $file_status = $adb->query_result($list_result, $i - 1, 'filestatus');
  758. $fileidQuery = "select attachmentsid from vtiger_seattachmentsrel where crmid=?";
  759. $fileidres = $adb->pquery($fileidQuery, array($notes_id));
  760. $fileid = $adb->query_result($fileidres, 0, 'attachmentsid');
  761. if ($file_name != '' && $file_status == 1) {
  762. if ($download_type == 'I') {
  763. $fld_value = "<a href='index.php?module=uploads&action=downloadfile&entityid=$notes_id&fileid=$fileid' title='" . getTranslatedString("LBL_DOWNLOAD_FILE", $module) . "' onclick='javascript:dldCntIncrease($notes_id);'>" . textlength_check($fld_value) . "</a>";
  764. } elseif ($download_type == 'E') {
  765. $fld_value = "<a target='_blank' href='$file_name' onclick='javascript:dldCntIncrease($notes_id);' title='" . getTranslatedString("LBL_DOWNLOAD_FILE", $module) . "'>" . textlength_check($fld_value) . "</a>";
  766. } else {
  767. $fld_value = ' --';
  768. }
  769. }
  770. $value = $fileicon . $fld_value;
  771. }
  772. if ($fieldname == 'filesize') {
  773. $downloadtype = $adb->query_result($list_result, $i - 1, 'filelocationtype');
  774. if ($downloadtype == 'I') {
  775. $filesize = $value;
  776. if ($filesize < 1024)
  777. $value = $filesize . ' B';
  778. elseif ($filesize > 1024 && $filesize < 1048576)
  779. $value = round($filesize / 1024, 2) . ' KB';
  780. else if ($filesize > 1048576)
  781. $value = round($filesize / (1024 * 1024), 2) . ' MB';
  782. } else {
  783. $value = ' --';
  784. }
  785. }
  786. if ($fieldname == 'filestatus') {
  787. $filestatus = $value;
  788. if ($filestatus == 1)
  789. $value = getTranslatedString('yes', $module);
  790. elseif ($filestatus == 0)
  791. $value = getTranslatedString('no', $module);
  792. else
  793. $value = ' --';
  794. }
  795. if ($fieldname == 'filetype') {
  796. $downloadtype = $adb->query_result($list_result, $i - 1, 'filelocationtype');
  797. $filetype = $adb->query_result($list_result, $i - 1, 'filetype');
  798. if ($downloadtype == 'E' || $downloadtype != 'I') {
  799. $value = ' --';
  800. } else
  801. $value = $filetype;
  802. }
  803. if ($fieldname == 'notecontent') {
  804. $value = decode_html($value);
  805. $value = textlength_check($value);
  806. }
  807. } elseif ($module == "Products" && $name == "Related to") {
  808. $value = getRelatedTo($module, $list_result, $i - 1);
  809. $value = textlength_check($value);
  810. } elseif ($name == 'Contact Name' && ($module == 'SalesOrder' || $module == 'Quotes' || $module == 'PurchaseOrder')) {
  811. if ($name == 'Contact Name') {
  812. $contact_id = $adb->query_result($list_result, $i - 1, "contactid");
  813. $contact_name = getFullNameFromQResult($list_result, $i - 1, "Contacts");
  814. $value = "";
  815. if (($contact_name != "") && ($contact_id != 'NULL'))
  816. $value = "<a href='index.php?module=Contacts&action=DetailView&parenttab=" . $tabname . "&record=" . $contact_id . "' style='" . $P_FONT_COLOR . "'>" . textlength_check($contact_name) . "</a>";
  817. }
  818. } elseif ($name == 'Product') {
  819. $product_id = textlength_check($adb->query_result($list_result, $i - 1, "productname"));
  820. $value = $product_id;
  821. } elseif ($name == 'Account Name') {
  822. //modified for vtiger_customview 27/5
  823. if ($module == 'Accounts') {
  824. $account_id = $adb->query_result($list_result, $i - 1, "crmid");
  825. //$account_name = getAccountName($account_id);
  826. $account_name = textlength_check($adb->query_result($list_result, $i - 1, "accountname"));
  827. // Fredy Klammsteiner, 4.8.2005: changes from 4.0.1 migrated to 4.2
  828. $value = '<a href="index.php?module=Accounts&action=DetailView&record=' . $account_id . '&parenttab=' . $tabname . '" style="' . $P_FONT_COLOR . '">' . $account_name . '</a>'; // Armando Lüscher 05.07.2005 -> §priority -> Desc: inserted style="$P_FONT_COLOR"
  829. } elseif ($module == 'Potentials' || $module == 'Contacts' || $module == 'Invoice' || $module == 'SalesOrder' || $module == 'Quotes') { //Potential,Contacts,Invoice,SalesOrder & Quotes records sort by Account Name
  830. $accountname = textlength_check($adb->query_result($list_result, $i - 1, "accountname"));
  831. $accountid = $adb->query_result($list_result, $i - 1, "accountid");
  832. if (empty($accountname))
  833. $accountname = getAccountName($accountid);
  834. $value = '<a href="index.php?module=Accounts&action=DetailView&record=' . $accountid . '&parenttab=' . $tabname . '" style="' . $P_FONT_COLOR . '">' . $accountname . '</a>';
  835. } else {
  836. $account_id = $adb->query_result($list_result, $i - 1, "accountid");
  837. $account_name = getAccountName($account_id);
  838. $acc_name = textlength_check($account_name);
  839. // Fredy Klammsteiner, 4.8.2005: changes from 4.0.1 migrated to 4.2
  840. $value = '<a href="index.php?module=Accounts&action=DetailView&record=' . $account_id . '&parenttab=' . $tabname . '" style="' . $P_FONT_COLOR . '">' . $acc_name . '</a>'; // Armando Lüscher 05.07.2005 -> §priority -> Desc: inserted style="$P_FONT_COLOR"
  841. }
  842. } elseif (( $module == 'HelpDesk' || $module == 'PriceBook' || $module == 'Quotes' || $module == 'PurchaseOrder' || $module == 'Faq') && $name == 'Product Name') {
  843. if ($module == 'HelpDesk' || $module == 'Faq')
  844. $product_id = $adb->query_result($list_result, $i - 1, "product_id");
  845. else
  846. $product_id = $adb->query_result($list_result, $i - 1, "productid");
  847. if ($product_id != '')
  848. $product_name = getProductName($product_id);
  849. else
  850. $product_name = '';
  851. $value = '<a href="index.php?module=Products&action=DetailView&parenttab=' . $tabname . '&record=' . $product_id . '">' . textlength_check($product_name) . '</a>';
  852. } elseif (($module == 'Quotes' && $name == 'Potential Name') || ($module == 'SalesOrder' && $name == 'Potential Name')) {
  853. $potential_id = $adb->query_result($list_result, $i - 1, "potentialid");
  854. $potential_name = getPotentialName($potential_id);
  855. $value = '<a href="index.php?module=Potentials&action=DetailView&parenttab=' . $tabname . '&record=' . $potential_id . '">' . textlength_check($potential_name) . '</a>';
  856. } elseif ($module == 'Emails' && $relatedlist != '' && ($name == 'Subject' || $name == 'Date Sent' || $name == 'To')) {
  857. $list_result_count = $i - 1;
  858. $tmp_value = getValue($ui_col_array, $list_result, $fieldname, $focus, $module, $entity_id, $list_result_count, "list", "", $returnset, $oCv->setdefaultviewid);
  859. $value = '<a href="javascript:;" onClick="ShowEmail(\'' . $entity_id . '\');">' . textlength_check($tmp_value) . '</a>';
  860. if ($name == 'Date Sent') {
  861. $sql = "select email_flag from vtiger_emaildetails where emailid=?";
  862. $result = $adb->pquery($sql, array($entity_id));
  863. $email_flag = $adb->query_result($result, 0, "email_flag");
  864. if ($email_flag != 'SAVED')
  865. $value = getValue($ui_col_array, $list_result, $fieldname, $focus, $module, $entity_id, $list_result_count, "list", "", $returnset, $oCv->setdefaultviewid);
  866. else
  867. $value = '';
  868. }
  869. } elseif ($module == 'Calendar' && ($fieldname != 'taskstatus' && $fieldname != 'eventstatus')) {
  870. if ($activitytype == 'Task') {
  871. if (getFieldVisibilityPermission('Calendar', $current_user->id, $fieldname) == '0') {
  872. $list_result_count = $i - 1;
  873. $value = getValue($ui_col_array, $list_result, $fieldname, $focus, $module, $entity_id, $list_result_count, "list", "", $returnset, $oCv->setdefaultviewid);
  874. } else {
  875. $value = '';
  876. }
  877. } else {
  878. if (getFieldVisibilityPermission('Events', $current_user->id, $fieldname) == '0') {
  879. $list_result_count = $i - 1;
  880. $value = getValue($ui_col_array, $list_result, $fieldname, $focus, $module, $entity_id, $list_result_count, "list", "", $returnset, $oCv->setdefaultviewid);
  881. } else {
  882. $value = '';
  883. }
  884. }
  885. } else {
  886. $list_result_count = $i - 1;
  887. $value = getValue($ui_col_array, $list_result, $fieldname, $focus, $module, $entity_id, $list_result_count, "list", "", $returnset, $oCv->setdefaultviewid);
  888. }
  889. }
  890. // vtlib customization: For listview javascript triggers
  891. $value = "$value <span type='vtlib_metainfo' vtrecordid='{$entity_id}' vtfieldname='{$fieldname}' vtmodule='$module' style='display:none;'></span>";
  892. // END
  893. if ($module == "Calendar" && $name == $app_strings['Close']) {
  894. if (isPermitted("Calendar", "EditView") == 'yes') {
  895. if ((getFieldVisibilityPermission('Events', $current_user->id, 'eventstatus') == '0') || (getFieldVisibilityPermission('Calendar', $current_user->id, 'taskstatus') == '0')) {
  896. array_push($list_header, $value);
  897. }
  898. }
  899. }
  900. else
  901. $list_header[] = $value;
  902. }
  903. }
  904. $varreturnset = '';
  905. if ($returnset == '')
  906. $varreturnset = '&return_module=' . $module . '&return_action=index';
  907. else
  908. $varreturnset = $returnset;
  909. if ($module == 'Calendar') {
  910. $actvity_type = $adb->query_result($list_result, $list_result_count, 'activitytype');
  911. if ($actvity_type == 'Task')
  912. $varreturnset .= '&activity_mode=Task';
  913. else
  914. $varreturnset .= '&activity_mode=Events';
  915. }
  916. //Added for Actions ie., edit and delete links in listview
  917. $links_info = "";
  918. if (!(is_array($selectedfields) && $selectedfields != '')) {
  919. if (isPermitted($module, "EditView", "") == 'yes') {
  920. $edit_link = getListViewEditLink($module, $entity_id, $relatedlist, $varreturnset, $list_result, $list_result_count);
  921. if (isset($_REQUEST['start']) && $_REQUEST['start'] > 1 && $module != 'Emails')
  922. $links_info .= "<a href=\"$edit_link&start=" . vtlib_purify($_REQUEST['start']) . "\">" . $app_strings["LNK_EDIT"] . "</a> ";
  923. else
  924. $links_info .= "<a href=\"$edit_link\">" . $app_strings["LNK_EDIT"] . "</a> ";
  925. }
  926. if (isPermitted($module, "Delete", "") == 'yes') {
  927. $del_link = getListViewDeleteLink($module, $entity_id, $relatedlist, $varreturnset);
  928. if ($links_info != "" && $del_link != "")
  929. $links_info .= " | ";
  930. if ($del_link != "")
  931. $links_info .= "<a href='javascript:confirmdelete(\"" . addslashes(urlencode($del_link)) . "\")'>" . $app_strings["LNK_DELETE"] . "</a>";
  932. }
  933. }
  934. // Record Change Notification
  935. if (method_exists($focus, 'isViewed') && PerformancePrefs::getBoolean('LISTVIEW_RECORD_CHANGE_INDICATOR', true)) {
  936. if (!$focus->isViewed($entity_id)) {
  937. $links_info .= " | <img src='" . vtiger_imageurl('important1.gif', $theme) . "' border=0>";
  938. }
  939. }
  940. // END
  941. if ($links_info != "" && !$skipActions)
  942. $list_header[] = $links_info;
  943. $list_block[$entity_id] = $list_header;
  944. }
  945. $log->debug("Exiting getListViewEntries method ...");
  946. return $list_block;
  947. }
  948. /* * This function generates the List view entries in a popup list view
  949. * Param $focus - module object
  950. * Param $list_result - resultset of a listview query
  951. * Param $navigation_array - navigation values in an array
  952. * Param $relatedlist - check for related list flag
  953. * Param $returnset - list query parameters in url string
  954. * Param $edit_action - Edit action value
  955. * Param $del_action - delete action value
  956. * Param $oCv - vtiger_customview object
  957. * Returns an array type
  958. */
  959. function getSearchListViewEntries($focus, $module, $list_result, $navigation_array, $form = '') {
  960. global $log;
  961. $log->debug("Entering getSearchListViewEntries(" . get_class($focus) . "," . $module . "," . $list_result . "," . $navigation_array . ") method ...");
  962. global $adb, $app_strings, $theme, $current_user, $list_max_entries_per_page;
  963. $noofrows = $adb->num_rows($list_result);
  964. $list_header = '';
  965. $theme_path = "themes/" . $theme . "/";
  966. $image_path = $theme_path . "images/";
  967. $list_block = Array();
  968. //getting the vtiger_fieldtable entries from database
  969. $tabid = getTabid($module);
  970. require('user_privileges/user_privileges_' . $current_user->id . '.php');
  971. //Added to reduce the no. of queries logging for non-admin user -- by Minnie-start
  972. $field_list = array();
  973. $j = 0;
  974. foreach ($focus->search_fields as $name => $tableinfo) {
  975. $fieldname = $focus->search_fields_name[$name];
  976. array_push($field_list, $fieldname);
  977. $j++;
  978. }
  979. $field = Array();
  980. if ($is_admin == false && $module != 'Users') {
  981. if ($module == 'Emails') {
  982. $query = "SELECT fieldname FROM vtiger_field WHERE tabid = ? and vtiger_field.presence in (0,2)";
  983. $params = array($tabid);
  984. } else {
  985. $profileList = getCurrentUserProfileList();
  986. $query = "SELECT DISTINCT vtiger_field.fieldname
  987. FROM vtiger_field
  988. INNER JOIN vtiger_profile2field
  989. ON vtiger_profile2field.fieldid = vtiger_field.fieldid
  990. INNER JOIN vtiger_def_org_field
  991. ON vtiger_def_org_field.fieldid = vtiger_field.fieldid
  992. WHERE vtiger_field.tabid = ?
  993. AND vtiger_profile2field.visible = 0
  994. AND vtiger_def_org_field.visible = 0
  995. AND vtiger_profile2field.profileid IN (" . generateQuestionMarks($profileList) . ")
  996. AND vtiger_field.fieldname IN (" . generateQuestionMarks($field_list) . ") and vtiger_field.presence in (0,2)";
  997. $params = array($tabid, $profileList, $field_list);
  998. }
  999. $result = $adb->pquery($query, $params);
  1000. for ($k = 0; $k < $adb->num_rows($result); $k++) {
  1001. $field[] = $adb->query_result($result, $k, "fieldname");
  1002. }
  1003. }
  1004. //constructing the uitype and columnname array
  1005. $ui_col_array = Array();
  1006. $query = "SELECT uitype, columnname, fieldname
  1007. FROM vtiger_field
  1008. WHERE tabid=?
  1009. AND fieldname IN (" . generateQuestionMarks($field_list) . ") and vtiger_field.presence in (0,2)";
  1010. $result = $adb->pquery($query, array($tabid, $field_list));
  1011. $num_rows = $adb->num_rows($result);
  1012. for ($i = 0; $i < $num_rows; $i++) {
  1013. $tempArr = array();
  1014. $uitype = $adb->query_result($result, $i, 'uitype');
  1015. $columnname = $adb->query_result($result, $i, 'columnname');
  1016. $field_name = $adb->query_result($result, $i, 'fieldname');
  1017. $tempArr[$uitype] = $columnname;
  1018. $ui_col_array[$field_name] = $tempArr;
  1019. }
  1020. //end
  1021. if ($navigation_array['end_val'] > 0) {
  1022. for ($i = 1; $i <= $noofrows; $i++) {
  1023. //Getting the entityid
  1024. if ($module != 'Users') {
  1025. $entity_id = $adb->query_result($list_result, $i - 1, "crmid");
  1026. } else {
  1027. $entity_id = $adb->query_result($list_result, $i - 1, "id");
  1028. }
  1029. $list_header = Array();
  1030. foreach ($focus->search_fields as $name => $tableinfo) {
  1031. $fieldname = $focus->search_fields_name[$name];
  1032. if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0 || in_array($fieldname, $field) || $module == 'Users') {
  1033. if ($fieldname == '') {
  1034. $table_name = '';
  1035. $column_name = '';
  1036. foreach ($tableinfo as $tablename => $colname) {
  1037. $table_name = $tablename;
  1038. $column_name = $colname;
  1039. }
  1040. $value = $adb->query_result($list_result, $i - 1, $colname);
  1041. } else {
  1042. if (($module == 'Calls' || $module == 'Tasks' || $module == 'Meetings' || $module == 'Emails') && (($name == 'Related to') || ($name == 'Contact Name') || ($name == 'Vendor Name'))) {
  1043. if ($name == 'Related to')
  1044. $value = getRelatedTo($module, $list_result, $i - 1);
  1045. if ($name == 'Contact Name') {
  1046. $contact_id = $adb->query_result($list_result, $i - 1, "contactid");
  1047. $contact_name = getFullNameFromQResult($list_result, $i - 1, "Contacts");
  1048. $value = "";
  1049. if (($contact_name != "") && ($contact_id != 'NULL'))
  1050. $value = "<a href='index.php?module=Contacts&action=DetailView&record=" . $contact_id . "'>" . $contact_name . "</a>";
  1051. }
  1052. }
  1053. elseif (($module == 'Faq' || $module == 'Documents') && $name == 'Related to') {
  1054. $value = getRelatedToEntity($module, $list_result, $i -

Large files files are truncated, but you can click here to view the full file