PageRenderTime 78ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/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
  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 - 1);
  1055. } elseif ($name == 'Account Name' && ($module == 'Potentials' || $module == 'SalesOrder' || $module == 'Quotes')) {
  1056. $account_id = $adb->query_result($list_result, $i - 1, "accountid");
  1057. $account_name = getAccountName($account_id);
  1058. $value = textlength_check($account_name);
  1059. } elseif ($name == 'Quote Name' && $module == 'SalesOrder') {
  1060. $quote_id = $adb->query_result($list_result, $i - 1, "quoteid");
  1061. $quotename = getQuoteName($quote_id);
  1062. $value = textlength_check($quotename);
  1063. } elseif ($name == 'Account Name' && $module == 'Contacts') {
  1064. $account_id = $adb->query_result($list_result, $i - 1, "accountid");
  1065. $account_name = getAccountName($account_id);
  1066. $value = textlength_check($account_name);
  1067. }
  1068. // vtlib customization: Generic popup handling
  1069. elseif (isset($focus->popup_fields) && in_array($fieldname, $focus->popup_fields)) {
  1070. global $default_charset;
  1071. $forfield = htmlspecialchars($_REQUEST['forfield'], ENT_QUOTES, $default_charset);
  1072. $list_result_count = $i - 1;
  1073. $value = getValue($ui_col_array, $list_result, $fieldname, $focus, $module, $entity_id, $list_result_count, "search", $focus->popup_type);
  1074. if (isset($forfield) && $forfield != '' && $focus->popup_type != 'detailview') {
  1075. $value1 = strip_tags($value);
  1076. $value = htmlspecialchars(addslashes(html_entity_decode(strip_tags($value), ENT_QUOTES, $default_charset)), ENT_QUOTES, $default_charset); // Remove any previous html conversion
  1077. $count = counterValue();
  1078. $value = "<a href='javascript:window.close();' onclick='return vtlib_setvalue_from_popup($entity_id, \"$value\", \"$forfield\")' id =$count >$value1</a>";
  1079. }
  1080. }
  1081. // END
  1082. else {
  1083. $list_result_count = $i - 1;
  1084. $value = getValue($ui_col_array, $list_result, $fieldname, $focus, $module, $entity_id, $list_result_count, "search", $focus->popup_type, $form);
  1085. }
  1086. }
  1087. $list_header[] = $value;
  1088. }
  1089. }
  1090. if ($module == 'Products' && ($focus->popup_type == 'inventory_prod' || $focus->popup_type == 'inventory_prod_po')) {
  1091. global $default_charset;
  1092. require('user_privileges/user_privileges_' . $current_user->id . '.php');
  1093. $row_id = $_REQUEST['curr_row'];
  1094. //To get all the tax types and values and pass it to product details
  1095. $tax_str = '';
  1096. $tax_details = getAllTaxes();
  1097. for ($tax_count = 0; $tax_count < count($tax_details); $tax_count++) {
  1098. $tax_str .= $tax_details[$tax_count]['taxname'] . '=' . $tax_details[$tax_count]['percentage'] . ',';
  1099. }
  1100. $tax_str = trim($tax_str, ',');
  1101. $rate = $user_info['conv_rate'];
  1102. if (getFieldVisibilityPermission($module, $current_user->id, 'unit_price') == '0') {
  1103. $unitprice = $adb->query_result($list_result, $list_result_count, 'unit_price');
  1104. if ($_REQUEST['currencyid'] != null) {
  1105. $prod_prices = getPricesForProducts($_REQUEST['currencyid'], array($entity_id));
  1106. $unitprice = $prod_prices[$entity_id];
  1107. }
  1108. } else {
  1109. $unitprice = '';
  1110. }
  1111. $sub_products = '';
  1112. $sub_prod = '';
  1113. $sub_prod_query = $adb->pquery("SELECT vtiger_products.productid,vtiger_products.productname from vtiger_products INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid=vtiger_products.productid INNER JOIN vtiger_seproductsrel on vtiger_seproductsrel.crmid=vtiger_products.productid WHERE vtiger_seproductsrel.productid=? and vtiger_seproductsrel.setype='Products'", array($entity_id));
  1114. for ($k = 0; $k < $adb->num_rows($sub_prod_query); $k++) {
  1115. //$sub_prod=array();
  1116. $id = $adb->query_result($sub_prod_query, $k, "productid");
  1117. $str_sep = '';
  1118. if ($k > 0)
  1119. $str_sep = ":";
  1120. $sub_products .= $str_sep . $id;
  1121. $sub_prod .= $str_sep . " - " . $adb->query_result($sub_prod_query, $k, "productname");
  1122. }
  1123. $sub_det = $sub_products . "::" . str_replace(":", "<br>", $sub_prod);
  1124. $qty_stock = $adb->query_result($list_result, $list_result_count, 'qtyinstock');
  1125. $slashes_temp_val = popup_from_html(getProductName($entity_id));
  1126. $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
  1127. $description = $adb->query_result($list_result, $list_result_count, 'description');
  1128. $slashes_desc = htmlspecialchars($description, ENT_QUOTES, $default_charset);
  1129. $sub_products_link = '<a href="index.php?module=Products&action=Popup&html=Popup_picker&return_module=' . vtlib_purify($_REQUEST['return_module']) . '&record_id=' . vtlib_purify($entity_id) . '&form=HelpDeskEditView&select=enable&popuptype=' . $focus->popup_type . '&curr_row=' . vtlib_purify($row_id) . '&currencyid=' . vtlib_purify($_REQUEST['currencyid']) . '" > Sub Products</a>';
  1130. if (!isset($_REQUEST['record_id'])) {
  1131. $sub_products_query = $adb->pquery("SELECT * from vtiger_seproductsrel WHERE productid=? AND setype='Products'", array($entity_id));
  1132. if ($adb->num_rows($sub_products_query) > 0)
  1133. $list_header[] = $sub_products_link;
  1134. else
  1135. $list_header[] = $app_strings['LBL_NO_SUB_PRODUCTS'];
  1136. }
  1137. }
  1138. if ($module == 'Services' && $focus->popup_type == 'inventory_service') {
  1139. global $default_charset;
  1140. require('user_privileges/user_privileges_' . $current_user->id . '.php');
  1141. $row_id = $_REQUEST['curr_row'];
  1142. //To get all the tax types and values and pass it to product details
  1143. $tax_str = '';
  1144. $tax_details = getAllTaxes();
  1145. for ($tax_count = 0; $tax_count < count($tax_details); $tax_count++) {
  1146. $tax_str .= $tax_details[$tax_count]['taxname'] . '=' . $tax_details[$tax_count]['percentage'] . ',';
  1147. }
  1148. $tax_str = trim($tax_str, ',');
  1149. $rate = $user_info['conv_rate'];
  1150. if (getFieldVisibilityPermission($module, $current_user->id, 'unit_price') == '0') {
  1151. $unitprice = $adb->query_result($list_result, $list_result_count, 'unit_price');
  1152. if ($_REQUEST['currencyid'] != null) {
  1153. $prod_prices = getPricesForProducts($_REQUEST['currencyid'], array($entity_id), $module);
  1154. $unitprice = $prod_prices[$entity_id];
  1155. }
  1156. } else {
  1157. $unitprice = '';
  1158. }
  1159. $slashes_temp_val = popup_from_html($adb->query_result($list_result, $list_result_count, 'servicename'));
  1160. $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
  1161. $description = $adb->query_result($list_result, $list_result_count, 'description');
  1162. $slashes_desc = htmlspecialchars($description, ENT_QUOTES, $default_charset);
  1163. }
  1164. $list_block[$entity_id] = $list_header;
  1165. }
  1166. }
  1167. $list = $list_block;
  1168. $log->debug("Exiting getSearchListViewEntries method ...");
  1169. return $list;
  1170. }
  1171. /* * This function generates the value for a given vtiger_field namee
  1172. * Param $field_result - vtiger_field result in array
  1173. * Param $list_result - resultset of a listview query
  1174. * Param $fieldname - vtiger_field name
  1175. * Param $focus - module object
  1176. * Param $module - module name
  1177. * Param $entity_id - entity id
  1178. * Param $list_result_count - list result count
  1179. * Param $mode - mode type
  1180. * Param $popuptype - popup type
  1181. * Param $returnset - list query parameters in url string
  1182. * Param $viewid - custom view id
  1183. * Returns an string value
  1184. */
  1185. function getValue($field_result, $list_result, $fieldname, $focus, $module, $entity_id, $list_result_count, $mode, $popuptype, $returnset = '', $viewid = '') {
  1186. global $log, $listview_max_textlength, $app_strings, $current_language, $currentModule;
  1187. $log->debug("Entering getValue(" . $field_result . "," . $list_result . "," . $fieldname . "," . get_class($focus) . "," . $module . "," . $entity_id . "," . $list_result_count . "," . $mode . "," . $popuptype . "," . $returnset . "," . $viewid . ") method ...");
  1188. global $adb, $current_user, $default_charset;
  1189. require('user_privileges/user_privileges_' . $current_user->id . '.php');
  1190. $tabname = getParentTab();
  1191. $tabid = getTabid($module);
  1192. $current_module_strings = return_module_language($current_language, $module);
  1193. $uicolarr = $field_result[$fieldname];
  1194. foreach ($uicolarr as $key => $value) {
  1195. $uitype = $key;
  1196. $colname = $value;
  1197. }
  1198. //added for getting event status in Custom view - Jaguar
  1199. if ($module == 'Calendar' && ($colname == "status" || $colname == "eventstatus")) {
  1200. $colname = "activitystatus";
  1201. }
  1202. //Ends
  1203. $field_val = $adb->query_result($list_result, $list_result_count, $colname);
  1204. if ($uitype != 8) {
  1205. $temp_val = html_entity_decode($field_val, ENT_QUOTES, $default_charset);
  1206. } else {
  1207. $temp_val = $field_val;
  1208. }
  1209. // vtlib customization: New uitype to handle relation between modules
  1210. if ($uitype == '10') {
  1211. $parent_id = $field_val;
  1212. if (!empty($parent_id)) {
  1213. $parent_module = getSalesEntityType($parent_id);
  1214. $valueTitle = $parent_module;
  1215. if ($app_strings[$valueTitle])
  1216. $valueTitle = $app_strings[$valueTitle];
  1217. $displayValueArray = getEntityName($parent_module, $parent_id);
  1218. if (!empty($displayValueArray)) {
  1219. foreach ($displayValueArray as $key => $value) {
  1220. $value = $value;
  1221. }
  1222. }
  1223. $value = "<a href='index.php?module=$parent_module&action=DetailView&record=$parent_id' title='$valueTitle'>" . textlength_check($value) . "</a>";
  1224. } else {
  1225. $value = '';
  1226. }
  1227. } // END
  1228. else if ($uitype == 53) {
  1229. $value = $adb->query_result($list_result, $list_result_count, 'user_name');
  1230. // When Assigned To field is used in Popup window
  1231. if ($value == '') {
  1232. $user_id = $adb->query_result($list_result, $list_result_count, 'smownerid');
  1233. if ($user_id != null && $user_id != '') {
  1234. $value = getOwnerName($user_id);
  1235. $value = textlength_check($value);
  1236. }
  1237. }
  1238. } elseif ($uitype == 52) {
  1239. $value = getOwnerName($adb->query_result($list_result, $list_result_count, $colname));
  1240. $value = textlength_check($value);
  1241. } elseif ($uitype == 51) {//Accounts - Member Of
  1242. $parentid = $adb->query_result($list_result, $list_result_count, "parentid");
  1243. if ($module == 'Accounts')
  1244. $entity_name = textlength_check(getAccountName($parentid));
  1245. elseif ($module == 'Products')
  1246. $entity_name = textlength_check(getProductName($parentid));
  1247. $value = '<a href="index.php?module=' . $module . '&action=DetailView&record=' . $parentid . '&parenttab=' . $tabname . '" style="' . $P_FONT_COLOR . '">' . $entity_name . '</a>';
  1248. }
  1249. elseif ($uitype == 77) {
  1250. $value = getOwnerName($adb->query_result($list_result, $list_result_count, 'inventorymanager'));
  1251. $value = textlength_check($value);
  1252. } elseif ($uitype == 5 || $uitype == 6 || $uitype == 23 || $uitype == 70) {
  1253. $temp_val = trim($temp_val);
  1254. $timeField = 'time_start';
  1255. if ($fieldname == 'due_date') {
  1256. $timeField = 'time_end';
  1257. }
  1258. if ($temp_val != '' && $module == 'Calendar' && ($uitype == 23 || $uitype == 6) &&
  1259. $timeField != '' && ($fieldname == 'date_start' || $fieldname == 'due_date' )) {
  1260. $time = $adb->query_result($list_result, $list_result_count, $timeField);
  1261. if (empty($time)) {
  1262. $time = getSingleFieldValue('vtiger_activity', $timeField, 'activityid', $entity_id);
  1263. }
  1264. }
  1265. if ($temp_val == '0000-00-00' || empty($temp_val)) {
  1266. $value = '';
  1267. } else {
  1268. if (empty($time) && strpos($temp_val, ' ') == false) {
  1269. $value = DateTimeField::convertToUserFormat($temp_val);
  1270. } else {
  1271. if (!empty($time)) {
  1272. $date = new DateTimeField($temp_val . ' ' . $time);
  1273. $value = $date->getDisplayDate();
  1274. } else {
  1275. $date = new DateTimeField($temp_val);
  1276. $value = $date->getDisplayDateTimeValue();
  1277. }
  1278. }
  1279. }
  1280. } elseif ($uitype == 15 || ($uitype == 55 && $fieldname == "salutationtype")) {
  1281. $temp_val = decode_html($adb->query_result($list_result, $list_result_count, $colname));
  1282. if (($is_admin == false && $profileGlobalPermission[1] == 1 && $profileGlobalPermission[2] == 1) && $temp_val != '') {
  1283. $temp_acttype = $adb->query_result($list_result, $list_result_count, 'activitytype');
  1284. if (($temp_acttype != 'Task') && $fieldname == "taskstatus")
  1285. $temptable = "eventstatus";
  1286. else
  1287. $temptable = $fieldname;
  1288. $roleid = $current_user->roleid;
  1289. $roleids = Array();
  1290. $subrole = getRoleSubordinates($roleid);
  1291. if (count($subrole) > 0)
  1292. $roleids = $subrole;
  1293. array_push($roleids, $roleid);
  1294. //here we are checking wheather the table contains the sortorder column .If sortorder is present in the main picklist table, then the role2picklist will be applicable for this table...
  1295. $sql = "select * from vtiger_$temptable where $temptable=?";
  1296. $res = $adb->pquery($sql, array(decode_html($temp_val)));
  1297. $picklistvalueid = $adb->query_result($res, 0, 'picklist_valueid');
  1298. if ($picklistvalueid != null) {
  1299. $pick_query = "select * from vtiger_role2picklist where picklistvalueid=$picklistvalueid and roleid in (" . generateQuestionMarks($roleids) . ")";
  1300. $res_val = $adb->pquery($pick_query, array($roleids));
  1301. $num_val = $adb->num_rows($res_val);
  1302. }
  1303. if ($num_val > 0 || ($temp_acttype == 'Task' && $fieldname == 'activitytype'))
  1304. $temp_val = $temp_val;
  1305. else
  1306. $temp_val = "<font color='red'>" . $app_strings['LBL_NOT_ACCESSIBLE'] . "</font>";
  1307. }
  1308. $value = ($current_module_strings[$temp_val] != '') ? $current_module_strings[$temp_val] : (($app_strings[$temp_val] != '') ? ($app_strings[$temp_val]) : $temp_val);
  1309. if ($value != "<font color='red'>" . $app_strings['LBL_NOT_ACCESSIBLE'] . "</font>") {
  1310. $value = textlength_check($value);
  1311. }
  1312. } elseif ($uitype == 16) {
  1313. $value = getTranslatedString($temp_val, $currentModule);
  1314. $value = textlength_check($value);
  1315. } elseif ($uitype == 71 || $uitype == 72) {
  1316. if ($temp_val != '') {
  1317. // Some of the currency fields like Unit Price, Total, Sub-total etc of Inventory modules, do not need currency conversion
  1318. if ($uitype == 72) {
  1319. if ($fieldname == 'unit_price') {
  1320. $currency_id = getProductBaseCurrency($entity_id, $module);
  1321. $cursym_convrate = getCurrencySymbolandCRate($currency_id);
  1322. $currency_symbol = $cursym_convrate['symbol'];
  1323. } else {
  1324. $currency_info = getInventoryCurrencyInfo($module, $entity_id);
  1325. $currency_symbol = $currency_info['currency_symbol'];
  1326. }
  1327. $currencyValue = CurrencyField::convertToUserFormat($temp_val, null, true);
  1328. $value = CurrencyField::appendCurrencySymbol($currencyValue, $currency_symbol);
  1329. } else {
  1330. //changes made to remove vtiger_currency symbol infront of each vtiger_potential amount
  1331. if ($temp_val != 0)
  1332. $value = CurrencyField::convertToUserFormat($temp_val);
  1333. else
  1334. $value = $temp_val;
  1335. }
  1336. }
  1337. else {
  1338. $value = '';
  1339. }
  1340. } elseif ($uitype == 17) {
  1341. $matchPattern = "^[\w]+:\/\/^";
  1342. preg_match($matchPattern, $field_val, $matches);
  1343. if (!empty($matches[0])) {
  1344. $value = '<a href="' . $field_val . '" target="_blank">' . textlength_check($temp_val) . '</a>';
  1345. } else {
  1346. $value = '<a href="http://' . $field_val . '" target="_blank">' . textlength_check($temp_val) . '</a>';
  1347. }
  1348. } elseif ($uitype == 13 || $uitype == 104 && ($_REQUEST['action'] != 'Popup' && $_REQUEST['file'] != 'Popup')) {
  1349. if ($_SESSION['internal_mailer'] == 1) {
  1350. //check added for email link in user detailview
  1351. if ($module == 'Calendar') {
  1352. if (getActivityType($entity_id) == 'Task') {
  1353. $tabid = 9;
  1354. } else {
  1355. $tabid = 16;
  1356. }
  1357. } else {
  1358. $tabid = getTabid($module);
  1359. }
  1360. $fieldid = getFieldid($tabid, $fieldname);
  1361. if (empty($popuptype)) {
  1362. $value = '<a href="javascript:InternalMailer(' . $entity_id . ',' . $fieldid . ',\'' . $fieldname . '\',\'' . $module . '\',\'record_id\');">' . textlength_check($temp_val) . '</a>';
  1363. } else {
  1364. $value = $temp_val;
  1365. $value = textlength_check($value);
  1366. }
  1367. }
  1368. else
  1369. $value = '<a href="mailto:' . $field_val . '">' . textlength_check($temp_val) . '</a>';
  1370. }
  1371. elseif ($uitype == 56) {
  1372. if ($temp_val == 1) {
  1373. $value = $app_strings['yes'];
  1374. } elseif ($temp_val == 0) {
  1375. $value = $app_strings['no'];
  1376. } else {
  1377. $value = '';
  1378. }
  1379. } elseif ($uitype == 57) {
  1380. if ($temp_val != '') {
  1381. $sql = "SELECT * FROM vtiger_contactdetails WHERE contactid=?";
  1382. $result = $adb->pquery($sql, array($temp_val));
  1383. $value = '';
  1384. if ($adb->num_rows($result)) {
  1385. $name = getFullNameFromQResult($result, 0, "Contacts");
  1386. $value = '<a href=index.php?module=Contacts&action=DetailView&record=' . $temp_val . '>' . textlength_check($name) . '</a>';
  1387. }
  1388. }
  1389. else
  1390. $value = '';
  1391. }
  1392. //Added by Minnie to get Campaign Source
  1393. elseif ($uitype == 58) {
  1394. if ($temp_val != '') {
  1395. $sql = "SELECT * FROM vtiger_campaign WHERE campaignid=?";
  1396. $result = $adb->pquery($sql, array($temp_val));
  1397. $campaignname = $adb->query_result($result, 0, "campaignname");
  1398. $value = '<a href=index.php?module=Campaigns&action=DetailView&record=' . $temp_val . '>' . textlength_check($campaignname) . '</a>';
  1399. }
  1400. else
  1401. $value = '';
  1402. }
  1403. //End
  1404. //Added By *Raj* for the Issue ProductName not displayed in CustomView of HelpDesk
  1405. elseif ($uitype == 59) {
  1406. if ($temp_val != '') {
  1407. $value = getProductName($temp_val);
  1408. } else {
  1409. $value = '';
  1410. }
  1411. }
  1412. //End
  1413. elseif ($uitype == 61) {
  1414. $attachmentid = $adb->query_result($adb->pquery("SELECT * FROM vtiger_seattachmentsrel WHERE crmid = ?", array($entity_id)), 0, 'attachmentsid');
  1415. $value = '<a href = "index.php?module=uploads&action=downloadfile&return_module=' . $module . '&fileid=' . $attachmentid . '&filename=' . $temp_val . '">' . textlength_check($temp_val) . '</a>';
  1416. } elseif ($uitype == 62) {
  1417. $parentid = $adb->query_result($list_result, $list_result_count, "parent_id");
  1418. $parenttype = $adb->query_result($list_result, $list_result_count, "parent_type");
  1419. if ($parenttype == "Leads") {
  1420. $tablename = "vtiger_leaddetails";
  1421. $fieldname = "lastname";
  1422. $idname = "leadid";
  1423. }
  1424. if ($parenttype == "Accounts") {
  1425. $tablename = "vtiger_account";
  1426. $fieldname = "accountname";
  1427. $idname = "accountid";
  1428. }
  1429. if ($parenttype == "Products") {
  1430. $tablename = "vtiger_products";
  1431. $fieldname = "productname";
  1432. $idname = "productid";
  1433. }
  1434. if ($parenttype == "HelpDesk") {
  1435. $tablename = "vtiger_troubletickets";
  1436. $fieldname = "title";
  1437. $idname = "ticketid";
  1438. }
  1439. if ($parenttype == "Invoice") {
  1440. $tablename = "vtiger_invoice";
  1441. $fieldname = "subject";
  1442. $idname = "invoiceid";
  1443. }
  1444. if ($parentid != '') {
  1445. $sql = "SELECT * FROM $tablename WHERE $idname = ?";
  1446. $fieldvalue = $adb->query_result($adb->pquery($sql, array($parentid)), 0, $fieldname);
  1447. $value = '<a href=index.php?module=' . $parenttype . '&action=DetailView&record=' . $parentid . '&parenttab=' . urlencode($tabname) . '>' . textlength_check($fieldvalue) . '</a>';
  1448. }
  1449. else
  1450. $value = '';
  1451. }
  1452. elseif ($uitype == 66) {
  1453. $parentid = $adb->query_result($list_result, $list_result_count, "parent_id");
  1454. $parenttype = $adb->query_result($list_result, $list_result_count, "parent_type");
  1455. if ($parenttype == "Leads") {
  1456. $tablename = "vtiger_leaddetails";
  1457. $fieldname = "lastname";
  1458. $idname = "leadid";
  1459. }
  1460. if ($parenttype == "Accounts") {
  1461. $tablename = "vtiger_account";
  1462. $fieldname = "accountname";
  1463. $idname = "accountid";
  1464. }
  1465. if ($parenttype == "HelpDesk") {
  1466. $tablename = "vtiger_troubletickets";
  1467. $fieldname = "title";
  1468. $idname = "ticketid";
  1469. }
  1470. if ($parentid != '') {
  1471. $sql = "SELECT * FROM $tablename WHERE $idname = ?";
  1472. $fieldvalue = $adb->query_result($adb->pquery($sql, array($parentid)), 0, $fieldname);
  1473. $value = '<a href=index.php?module=' . $parenttype . '&action=DetailView&record=' . $parentid . '&parenttab=' . urlencode($tabname) . '>' . textlength_check($fieldvalue) . '</a>';
  1474. }
  1475. else
  1476. $value = '';
  1477. }
  1478. elseif ($uitype == 67) {
  1479. $parentid = $adb->query_result($list_result, $list_result_count, "parent_id");
  1480. $parenttype = $adb->query_result($list_result, $list_result_count, "parent_type");
  1481. if ($parenttype == "Leads") {
  1482. $tablename = "vtiger_leaddetails";
  1483. $fieldname = "lastname";
  1484. $idname = "leadid";
  1485. }
  1486. if ($parenttype == "Contacts") {
  1487. $tablename = "vtiger_contactdetails";
  1488. $fieldname = "contactname";
  1489. $idname = "contactid";
  1490. }
  1491. if ($parentid != '') {
  1492. $sql = "SELECT * FROM $tablename WHERE $idname = ?";
  1493. $fieldvalue = $adb->query_result($adb->pquery($sql, array($parentid)), 0, $fieldname);
  1494. $value = '<a href=index.php?module=' . $parenttype . '&action=DetailView&record=' . $parentid . '&parenttab=' . urlencode($tabname) . '>' . textlength_check($fieldvalue) . '</a>';
  1495. }
  1496. else
  1497. $value = '';
  1498. }
  1499. elseif ($uitype == 68) {
  1500. $parentid = $adb->query_result($list_result, $list_result_count, "parent_id");
  1501. $parenttype = $adb->query_result($list_result, $list_result_count, "parent_type");
  1502. if ($parenttype == '' && $parentid != '')
  1503. $parenttype = getSalesEntityType($parentid);
  1504. if ($parenttype == "Contacts") {
  1505. $tablename = "vtiger_contactdetails";
  1506. $fieldname = "contactname";
  1507. $idname = "contactid";
  1508. }
  1509. if ($parenttype == "Accounts") {
  1510. $tablename = "vtiger_account";
  1511. $fieldname = "accountname";
  1512. $idname = "accountid";
  1513. }
  1514. if ($parentid != '') {
  1515. $sql = "SELECT * FROM $tablename WHERE $idname = ?";
  1516. $fieldvalue = $adb->query_result($adb->pquery($sql, array($parentid)), 0, $fieldname);
  1517. $value = '<a href=index.php?module=' . $parenttype . '&action=DetailView&record=' . $parentid . '&parenttab=' . urlencode($tabname) . '>' . textlength_check($fieldvalue) . '</a>';
  1518. }
  1519. else
  1520. $value = '';
  1521. }
  1522. elseif ($uitype == 78) {
  1523. if ($temp_val != '') {
  1524. $quote_name = getQuoteName($temp_val);
  1525. $value = '<a href=index.php?module=Quotes&action=DetailView&record=' . $temp_val . '&parenttab=' . urlencode($tabname) . '>' . textlength_check($quote_name) . '</a>';
  1526. }
  1527. else
  1528. $value = '';
  1529. }
  1530. elseif ($uitype == 79) {
  1531. if ($temp_val != '') {
  1532. $purchaseorder_name = getPoName($temp_val);
  1533. $value = '<a href=index.php?module=PurchaseOrder&action=DetailView&record=' . $temp_val . '&parenttab=' . urlencode($tabname) . '>' . textlength_check($purchaseorder_name) . '</a>';
  1534. }
  1535. else
  1536. $value = '';
  1537. }
  1538. elseif ($uitype == 80) {
  1539. if ($temp_val != '') {
  1540. $salesorder_name = getSoName($temp_val);
  1541. $value = "<a href=index.php?module=SalesOrder&action=DetailView&record=$temp_val&parenttab=" . urlencode($tabname) . ">" . textlength_check($salesorder_name) . '</a>';
  1542. }
  1543. else
  1544. $value = '';
  1545. }
  1546. elseif ($uitype == 75 || $uitype == 81) {
  1547. if ($temp_val != '') {
  1548. $vendor_name = getVendorName($temp_val);
  1549. $value = '<a href=index.php?module=Vendors&action=DetailView&record=' . $temp_val . '&parenttab=' . urlencode($tabname) . '>' . textlength_check($vendor_name) . '</a>';
  1550. }
  1551. else
  1552. $value = '';
  1553. }
  1554. elseif ($uitype == 98) {
  1555. $value = '<a href="index.php?action=RoleDetailView&module=Settings&parenttab=Settings&roleid=' . $temp_val . '">' . textlength_check(getRoleName($temp_val)) . '</a>';
  1556. } elseif ($uitype == 33) {
  1557. $value = ($temp_val != "") ? str_ireplace(' |##| ', ', ', $temp_val) : "";
  1558. if (!$is_admin && $value != '') {
  1559. $value = ($field_val != "") ? str_ireplace(' |##| ', ', ', $field_val) : "";
  1560. if ($value != '') {
  1561. $value_arr = explode(',', trim($value));
  1562. $roleid = $current_user->roleid;
  1563. $subrole = getRoleSubordinates($roleid);
  1564. if (count($subrole) > 0) {
  1565. $roleids = $subrole;
  1566. array_push($roleids, $roleid);
  1567. } else {
  1568. $roleids = $roleid;
  1569. }
  1570. if (count($roleids) > 0) {
  1571. $pick_query = "select distinct $fieldname from vtiger_$fieldname inner join vtiger_role2picklist on vtiger_role2picklist.picklistvalueid = vtiger_$fieldname.picklist_valueid where roleid in (" . generateQuestionMarks($roleids) . ") and picklistid in (select picklistid from vtiger_$fieldname) order by $fieldname asc";
  1572. $params = array($roleids);
  1573. } else {
  1574. $pick_query = "select distinct $fieldname from vtiger_$fieldname inner join vtiger_role2picklist on vtiger_role2picklist.picklistvalueid = vtiger_$fieldname.picklist_valueid where picklistid in (select picklistid from vtiger_$fieldname) order by $fieldname asc";
  1575. $params = array();
  1576. }
  1577. $pickListResult = $adb->pquery($pick_query, $params);
  1578. $picklistval = Array();
  1579. for ($i = 0; $i < $adb->num_rows($pickListResult); $i++) {
  1580. $picklistarr[] = $adb->query_result($pickListResult, $i, $fieldname);
  1581. }
  1582. $value_temp = Array();
  1583. $string_temp = '';
  1584. $str_c = 0;
  1585. foreach ($value_arr as $ind => $val) {
  1586. $notaccess = '<font color="red">' . $app_strings['LBL_NOT_ACCESSIBLE'] . "</font>";
  1587. if (!$listview_max_textlength || !(strlen(preg_replace("/(<\/?)(\w+)([^>]*>)/i", "", $string_temp)) > $listview_max_textlength)) {
  1588. $value_temp1 = (in_array(trim($val), $picklistarr)) ? $val : $notaccess;
  1589. if ($str_c != 0)
  1590. $string_temp .= ' , ';
  1591. $string_temp .= $value_temp1;
  1592. $str_c++;
  1593. }
  1594. else
  1595. $string_temp .='...';
  1596. }
  1597. $value = $string_temp;
  1598. }
  1599. }
  1600. }
  1601. elseif ($uitype == 85) {
  1602. $value = ($temp_val != "") ? "<a href='skype:{$temp_val}?call'>{$temp_val}</a>" : "";
  1603. } elseif ($uitype == 116) {
  1604. $value = ($temp_val != "") ? getCurrencyName($temp_val) : "";
  1605. } elseif ($uitype == 117) {
  1606. // NOTE: Without symbol the value could be used for filtering/lookup hence avoiding the translation
  1607. $value = ($temp_val != "") ? getCurrencyName($temp_val, false) : "";
  1608. } elseif ($uitype == 26) {
  1609. $sql = "select foldername from vtiger_attachmentsfolder where folderid = ?";
  1610. $res = $adb->pquery($sql, array($temp_val));
  1611. $foldername = $adb->query_result($res, 0, 'foldername');
  1612. $value = $foldername;
  1613. }
  1614. //added for asterisk integration
  1615. elseif ($uitype == 11) {
  1616. // Fix added for Trac Id: 6139
  1617. if (vtlib_isModuleActive('PBXManager')) {
  1618. $value = "<a href='javascript:;' onclick='startCall(&quot;$temp_val&quot;, &quot;$entity_id&quot;)'>" . textlength_check($temp_val) . "</a>";
  1619. } else {
  1620. $value = $temp_val;
  1621. }
  1622. }
  1623. //asterisk changes end here
  1624. //Added for email status tracking
  1625. elseif ($uitype == 25) {
  1626. $contactid = $_REQUEST['record'];
  1627. $emailid = $adb->query_result($list_result, $list_result_count, "activityid");
  1628. $result = $adb->pquery("SELECT access_count FROM vtiger_email_track WHERE crmid=? AND mailid=?", array($contactid, $emailid));
  1629. $value = $adb->query_result($result, 0, "access_count");
  1630. if (!$value) {
  1631. $value = 0;
  1632. }
  1633. } elseif ($uitype == 8) {
  1634. if (!empty($temp_val)) {
  1635. $temp_val = html_entity_decode($temp_val, ENT_QUOTES, $default_charset);
  1636. $json = new Zend_Json();
  1637. $value = vt_suppressHTMLTags(implode(',', $json->decode($temp_val)));
  1638. }
  1639. }
  1640. //end email status tracking
  1641. else {
  1642. if ($fieldname == $focus->list_link_field) {
  1643. if ($mode == "search") {
  1644. if ($popuptype == "specific" || $popuptype == "toDospecific") {
  1645. // Added for get the first name of contact in Popup window
  1646. if ($colname == "lastname" && $module == 'Contacts') {
  1647. $temp_val = getFullNameFromQResult($list_result, $list_result_count, "Contacts");
  1648. }
  1649. $slashes_temp_val = popup_from_html($temp_val);
  1650. $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
  1651. //Added to avoid the error when select SO from Invoice through AjaxEdit
  1652. if ($module == 'SalesOrder') {
  1653. $count = counterValue();
  1654. $value = '<a href="javascript:window.close();" onclick=\'set_return_specific("' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '","' . $_REQUEST['form'] . '");\' id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
  1655. } elseif ($module == 'Contacts') {
  1656. require_once('modules/Contacts/Contacts.php');
  1657. $cntct_focus = new Contacts();
  1658. $cntct_focus->retrieve_entity_info($entity_id, "Contacts");
  1659. $slashes_temp_val = popup_from_html($temp_val);
  1660. //ADDED TO CHECK THE FIELD PERMISSIONS FOR
  1661. $xyz = array('mailingstreet', 'mailingcity', 'mailingzip', 'mailingpobox', 'mailingcountry', 'mailingstate', 'otherstreet', 'othercity', 'otherzip', 'otherpobox', 'othercountry', 'otherstate');
  1662. for ($i = 0; $i < 12; $i++) {
  1663. if (getFieldVisibilityPermission($module, $current_user->id, $xyz[$i]) == '0') {
  1664. $cntct_focus->column_fields[$xyz[$i]] = $cntct_focus->column_fields[$xyz[$i]];
  1665. }
  1666. else
  1667. $cntct_focus->column_fields[$xyz[$i]] = '';
  1668. }
  1669. // For ToDo creation the underlying form is not named as EditView
  1670. $form = !empty($_REQUEST['form']) ? $_REQUEST['form'] : '';
  1671. if (!empty($form))
  1672. $form = htmlspecialchars($form, ENT_QUOTES, $default_charset);
  1673. $count = counterValue();
  1674. $value = '<a href="javascript:window.close();" onclick=\'set_return_contact_address("' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '", "' . popup_decode_html($cntct_focus->column_fields['mailingstreet']) . '", "' . popup_decode_html($cntct_focus->column_fields['otherstreet']) . '", "' . popup_decode_html($cntct_focus->column_fields['mailingcity']) . '", "' . popup_decode_html($cntct_focus->column_fields['othercity']) . '", "' . popup_decode_html($cntct_focus->column_fields['mailingstate']) . '", "' . popup_decode_html($cntct_focus->column_fields['otherstate']) . '", "' . popup_decode_html($cntct_focus->column_fields['mailingzip']) . '", "' . popup_decode_html($cntct_focus->column_fields['otherzip']) . '", "' . popup_decode_html($cntct_focus->column_fields['mailingcountry']) . '", "' . popup_decode_html($cntct_focus->column_fields['othercountry']) . '","' . popup_decode_html($cntct_focus->column_fields['mailingpobox']) . '", "' . popup_decode_html($cntct_focus->column_fields['otherpobox']) . '","' . $form . '");\'id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
  1675. }
  1676. else
  1677. if ($popuptype == 'toDospecific') {
  1678. $count = counterValue();
  1679. $value = '<a href="javascript:window.close();" onclick=\'set_return_toDospecific("' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '");\'id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
  1680. } else {
  1681. $count = counterValue();
  1682. $value = '<a href="javascript:window.close();" onclick=\'set_return_specific("' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '");\'id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
  1683. }
  1684. } elseif ($popuptype == "detailview") {
  1685. if ($colname == "lastname" && ($module == 'Contacts' || $module == 'Leads')) {
  1686. $temp_val = getFullNameFromQResult($list_result, $list_result_count, $module);
  1687. }
  1688. $slashes_temp_val = popup_from_html($temp_val);
  1689. $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
  1690. $focus->record_id = $_REQUEST['recordid'];
  1691. $popupMode = $_REQUEST['popupmode'];
  1692. $callBack = $_REQUEST['callback'];
  1693. if ($_REQUEST['return_module'] == "Calendar") {
  1694. $count = counterValue();
  1695. $value = '<a href="javascript:window.close();" id="calendarCont' . $entity_id . '" LANGUAGE=javascript onclick=\'add_data_to_relatedlist_incal("' . $entity_id . '","' . decode_html($slashes_temp_val) . '");\'id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
  1696. } else {
  1697. $count = counterValue();
  1698. if (empty($callBack)) {
  1699. $value = '<a style="cursor:pointer;" onclick=\'add_data_to_relatedlist("' . $entity_id . '","' . $focus->record_id . '","' . $module . '","' . $popupMode . '");\'>' . textlength_check($temp_val) . '</a>';
  1700. } else {
  1701. $value = '<a style="cursor:pointer;" onclick=\'add_data_to_relatedlist("' . $entity_id . '","' . $focus->record_id . '","' . $module . '","' . $popupMode . '",' . $callBack . ');\'>' . textlength_check($temp_val) . '</a>';
  1702. }
  1703. }
  1704. } elseif ($popuptype == "formname_specific") {
  1705. $slashes_temp_val = popup_from_html($temp_val);
  1706. $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
  1707. $count = counterValue();
  1708. $value = '<a href="javascript:window.close();" onclick=\'set_return_formname_specific("' . $_REQUEST['form'] . '", "' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '");\'id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
  1709. } elseif ($popuptype == "inventory_prod") {
  1710. $row_id = $_REQUEST['curr_row'];
  1711. //To get all the tax types and values and pass it to product details
  1712. $tax_str = '';
  1713. $tax_details = getAllTaxes();
  1714. for ($tax_count = 0; $tax_count < count($tax_details); $tax_count++) {
  1715. $tax_str .= $tax_details[$tax_count]['taxname'] . '=' . $tax_details[$tax_count]['percentage'] . ',';
  1716. }
  1717. $tax_str = trim($tax_str, ',');
  1718. $rate = $user_info['conv_rate'];
  1719. if (getFieldVisibilityPermission('Products', $current_user->id, 'unit_price') == '0') {
  1720. $unitprice = $adb->query_result($list_result, $list_result_count, 'unit_price');
  1721. if ($_REQUEST['currencyid'] != null) {
  1722. $prod_prices = getPricesForProducts($_REQUEST['currencyid'], array($entity_id));
  1723. $unitprice = $prod_prices[$entity_id];
  1724. }
  1725. } else {
  1726. $unitprice = '';
  1727. }
  1728. $sub_products = '';
  1729. $sub_prod = '';
  1730. $sub_prod_query = $adb->pquery("SELECT vtiger_products.productid,vtiger_products.productname,vtiger_products.qtyinstock,vtiger_crmentity.description from vtiger_products INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid=vtiger_products.productid INNER JOIN vtiger_seproductsrel on vtiger_seproductsrel.crmid=vtiger_products.productid WHERE vtiger_seproductsrel.productid=? and vtiger_seproductsrel.setype='Products'", array($entity_id));
  1731. for ($i = 0; $i < $adb->num_rows($sub_prod_query); $i++) {
  1732. //$sub_prod=array();
  1733. $id = $adb->query_result($sub_prod_query, $i, "productid");
  1734. $str_sep = '';
  1735. if ($i > 0)
  1736. $str_sep = ":";
  1737. $sub_products .= $str_sep . $id;
  1738. $sub_prod .= $str_sep . " - " . $adb->query_result($sub_prod_query, $i, "productname");
  1739. }
  1740. $sub_det = $sub_products . "::" . str_replace(":", "<br>", $sub_prod);
  1741. $qty_stock = $adb->query_result($list_result, $list_result_count, 'qtyinstock');
  1742. //fix for T6943
  1743. $slashes_temp_val = popup_from_html($field_val);
  1744. $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
  1745. $description = popup_from_html($adb->query_result($list_result, $list_result_count, 'description'));
  1746. $slashes_temp_desc = decode_html(htmlspecialchars($description, ENT_QUOTES, $default_charset));
  1747. $slashes_desc = str_replace(array("\r", "\n"), array('\r', '\n'), $slashes_temp_desc);
  1748. $tmp_arr = array("entityid" => $entity_id, "prodname" => "" . stripslashes(decode_html(nl2br($slashes_temp_val))) . "", "unitprice" => "$unitprice", "qtyinstk" => "$qty_stock", "taxstring" => "$tax_str", "rowid" => "$row_id", "desc" => "$slashes_desc", "subprod_ids" => "$sub_det");
  1749. require_once('include/Zend/Json.php');
  1750. $prod_arr = Zend_Json::encode($tmp_arr);
  1751. $value = '<a href="javascript:window.close();" id=\'popup_product_' . $entity_id . '\' onclick=\'set_return_inventory("' . $entity_id . '", "' . decode_html(nl2br($slashes_temp_val)) . '", "' . $unitprice . '", "' . $qty_stock . '","' . $tax_str . '","' . $row_id . '","' . $slashes_desc . '","' . $sub_det . '");\' vt_prod_arr=\'' . $prod_arr . '\' >' . textlength_check($temp_val) . '</a>';
  1752. }
  1753. elseif ($popuptype == "inventory_prod_po") {
  1754. $row_id = $_REQUEST['curr_row'];
  1755. //To get all the tax types and values and pass it to product details
  1756. $tax_str = '';
  1757. $tax_details = getAllTaxes();
  1758. for ($tax_count = 0; $tax_count < count($tax_details); $tax_count++) {
  1759. $tax_str .= $tax_details[$tax_count]['taxname'] . '=' . $tax_details[$tax_count]['percentage'] . ',';
  1760. }
  1761. $tax_str = trim($tax_str, ',');
  1762. $rate = $user_info['conv_rate'];
  1763. if (getFieldVisibilityPermission($module, $current_user->id, 'unit_price') == '0') {
  1764. $unitprice = $adb->query_result($list_result, $list_result_count, 'unit_price');
  1765. if ($_REQUEST['currencyid'] != null) {
  1766. $prod_prices = getPricesForProducts($_REQUEST['currencyid'], array($entity_id), $module);
  1767. $unitprice = $prod_prices[$entity_id];
  1768. }
  1769. } else {
  1770. $unitprice = '';
  1771. }
  1772. $sub_products = '';
  1773. $sub_prod = '';
  1774. $sub_prod_query = $adb->pquery("SELECT vtiger_products.productid,vtiger_products.productname,vtiger_products.qtyinstock,vtiger_crmentity.description from vtiger_products INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid=vtiger_products.productid INNER JOIN vtiger_seproductsrel on vtiger_seproductsrel.crmid=vtiger_products.productid WHERE vtiger_seproductsrel.productid=? and vtiger_seproductsrel.setype='Products'", array($entity_id));
  1775. for ($i = 0; $i < $adb->num_rows($sub_prod_query); $i++) {
  1776. //$sub_prod=array();
  1777. $id = $adb->query_result($sub_prod_query, $i, "productid");
  1778. $str_sep = '';
  1779. if ($i > 0)
  1780. $str_sep = ":";
  1781. $sub_products .= $str_sep . $id;
  1782. $sub_prod .= $str_sep . " - $id." . $adb->query_result($sub_prod_query, $i, "productname");
  1783. }
  1784. $sub_det = $sub_products . "::" . str_replace(":", "<br>", $sub_prod);
  1785. $slashes_temp_val = popup_from_html($field_val);
  1786. $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
  1787. $description = popup_from_html($adb->query_result($list_result, $list_result_count, 'description'));
  1788. $slashes_temp_desc = decode_html(htmlspecialchars($description, ENT_QUOTES, $default_charset));
  1789. $slashes_desc = str_replace(array("\r", "\n"), array('\r', '\n'), $slashes_temp_desc);
  1790. $tmp_arr = array("entityid" => $entity_id, "prodname" => "" . stripslashes(decode_html(nl2br($slashes_temp_val))) . "", "unitprice" => "$unitprice", "qtyinstk" => "$qty_stock", "taxstring" => "$tax_str", "rowid" => "$row_id", "desc" => "$slashes_desc", "subprod_ids" => "$sub_det");
  1791. require_once('include/Zend/Json.php');
  1792. $prod_arr = Zend_Json::encode($tmp_arr);
  1793. $value = '<a href="javascript:window.close();" id=\'popup_product_' . $entity_id . '\' onclick=\'set_return_inventory_po("' . $entity_id . '", "' . decode_html(nl2br($slashes_temp_val)) . '", "' . $unitprice . '", "' . $tax_str . '","' . $row_id . '","' . $slashes_desc . '","' . $sub_det . '"); \' vt_prod_arr=\'' . $prod_arr . '\' >' . textlength_check($temp_val) . '</a>';
  1794. }
  1795. elseif ($popuptype == "inventory_service") {
  1796. $row_id = $_REQUEST['curr_row'];
  1797. //To get all the tax types and values and pass it to product details
  1798. $tax_str = '';
  1799. $tax_details = getAllTaxes();
  1800. for ($tax_count = 0; $tax_count < count($tax_details); $tax_count++) {
  1801. $tax_str .= $tax_details[$tax_count]['taxname'] . '=' . $tax_details[$tax_count]['percentage'] . ',';
  1802. }
  1803. $tax_str = trim($tax_str, ',');
  1804. $rate = $user_info['conv_rate'];
  1805. if (getFieldVisibilityPermission('Services', $current_user->id, 'unit_price') == '0') {
  1806. $unitprice = $adb->query_result($list_result, $list_result_count, 'unit_price');
  1807. if ($_REQUEST['currencyid'] != null) {
  1808. $prod_prices = getPricesForProducts($_REQUEST['currencyid'], array($entity_id), $module);
  1809. $unitprice = $prod_prices[$entity_id];
  1810. }
  1811. } else {
  1812. $unitprice = '';
  1813. }
  1814. $slashes_temp_val = popup_from_html($field_val);
  1815. $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
  1816. $description = popup_from_html($adb->query_result($list_result, $list_result_count, 'description'));
  1817. $slashes_temp_desc = decode_html(htmlspecialchars($description, ENT_QUOTES, $default_charset));
  1818. $slashes_desc = str_replace(array("\r", "\n"), array('\r', '\n'), $slashes_temp_desc);
  1819. $tmp_arr = array("entityid" => $entity_id, "prodname" => "" . stripslashes(decode_html(nl2br($slashes_temp_val))) . "", "unitprice" => "$unitprice", "taxstring" => "$tax_str", "rowid" => "$row_id", "desc" => "$slashes_desc");
  1820. require_once('include/Zend/Json.php');
  1821. $prod_arr = Zend_Json::encode($tmp_arr);
  1822. $value = '<a href="javascript:window.close();" id=\'popup_product_' . $entity_id . '\' onclick=\'set_return_inventory("' . $entity_id . '", "' . decode_html(nl2br($slashes_temp_val)) . '", "' . $unitprice . '", "' . $tax_str . '","' . $row_id . '","' . $slashes_desc . '");\' vt_prod_arr=\'' . $prod_arr . '\' >' . textlength_check($temp_val) . '</a>';
  1823. } elseif ($popuptype == "inventory_pb") {
  1824. $prod_id = $_REQUEST['productid'];
  1825. $flname = $_REQUEST['fldname'];
  1826. $listprice = getListPrice($prod_id, $entity_id);
  1827. $temp_val = popup_from_html($temp_val);
  1828. $count = counterValue();
  1829. $value = '<a href="javascript:window.close();" onclick=\'set_return_inventory_pb("' . $listprice . '", "' . $flname . '"); \'id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
  1830. } elseif ($popuptype == "specific_account_address") {
  1831. require_once('modules/Accounts/Accounts.php');
  1832. $acct_focus = new Accounts();
  1833. $acct_focus->retrieve_entity_info($entity_id, "Accounts");
  1834. $slashes_temp_val = popup_from_html($temp_val);
  1835. $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
  1836. $xyz = array('bill_street', 'bill_city', 'bill_code', 'bill_pobox', 'bill_country', 'bill_state', 'ship_street', 'ship_city', 'ship_code', 'ship_pobox', 'ship_country', 'ship_state');
  1837. for ($i = 0; $i < 12; $i++) {
  1838. if (getFieldVisibilityPermission($module, $current_user->id, $xyz[$i]) == '0') {
  1839. $acct_focus->column_fields[$xyz[$i]] = $acct_focus->column_fields[$xyz[$i]];
  1840. }
  1841. else
  1842. $acct_focus->column_fields[$xyz[$i]] = '';
  1843. }
  1844. $bill_street = str_replace(array("\r", "\n"), array('\r', '\n'), popup_decode_html($acct_focus->column_fields['bill_street']));
  1845. $ship_street = str_replace(array("\r", "\n"), array('\r', '\n'), popup_decode_html($acct_focus->column_fields['ship_street']));
  1846. $count = counterValue();
  1847. $value = '<a href="javascript:window.close();" onclick=\'set_return_address("' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '", "' . $bill_street . '", "' . $ship_street . '", "' . popup_decode_html($acct_focus->column_fields['bill_city']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_city']) . '", "' . popup_decode_html($acct_focus->column_fields['bill_state']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_state']) . '", "' . popup_decode_html($acct_focus->column_fields['bill_code']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_code']) . '", "' . popup_decode_html($acct_focus->column_fields['bill_country']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_country']) . '","' . popup_decode_html($acct_focus->column_fields['bill_pobox']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_pobox']) . '");\'id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
  1848. }
  1849. elseif ($popuptype == "specific_contact_account_address") {
  1850. require_once('modules/Accounts/Accounts.php');
  1851. $acct_focus = new Accounts();
  1852. $acct_focus->retrieve_entity_info($entity_id, "Accounts");
  1853. $slashes_temp_val = popup_from_html($temp_val);
  1854. $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
  1855. $bill_street = str_replace(array("\r", "\n"), array('\r', '\n'), popup_decode_html($acct_focus->column_fields['bill_street']));
  1856. $ship_street = str_replace(array("\r", "\n"), array('\r', '\n'), popup_decode_html($acct_focus->column_fields['ship_street']));
  1857. $count = counterValue();
  1858. $value = '<a href="javascript:window.close();" onclick=\'set_return_contact_address("' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '", "' . $bill_street . '", "' . $ship_street . '", "' . popup_decode_html($acct_focus->column_fields['bill_city']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_city']) . '", "' . popup_decode_html($acct_focus->column_fields['bill_state']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_state']) . '", "' . popup_decode_html($acct_focus->column_fields['bill_code']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_code']) . '", "' . popup_decode_html($acct_focus->column_fields['bill_country']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_country']) . '","' . popup_decode_html($acct_focus->column_fields['bill_pobox']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_pobox']) . '");\'id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
  1859. } elseif ($popuptype == "specific_potential_account_address") {
  1860. $slashes_temp_val = popup_from_html($temp_val);
  1861. $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
  1862. // For B2C support, Potential was enabled to be linked to Contacts also.
  1863. // Hence we need case handling for it.
  1864. $relatedid = $adb->query_result($list_result, $list_result_count, "related_to");
  1865. $relatedentity = getSalesEntityType($relatedid);
  1866. if ($relatedentity == 'Accounts') {
  1867. require_once('modules/Accounts/Accounts.php');
  1868. $acct_focus = new Accounts();
  1869. $acct_focus->retrieve_entity_info($relatedid, "Accounts");
  1870. $account_name = getAccountName($relatedid);
  1871. $slashes_account_name = popup_from_html($account_name);
  1872. $slashes_account_name = htmlspecialchars($slashes_account_name, ENT_QUOTES, $default_charset);
  1873. $xyz = array('bill_street', 'bill_city', 'bill_code', 'bill_pobox', 'bill_country', 'bill_state', 'ship_street', 'ship_city', 'ship_code', 'ship_pobox', 'ship_country', 'ship_state');
  1874. for ($i = 0; $i < 12; $i++) {
  1875. if (getFieldVisibilityPermission('Accounts', $current_user->id, $xyz[$i]) == '0') {
  1876. $acct_focus->column_fields[$xyz[$i]] = $acct_focus->column_fields[$xyz[$i]];
  1877. }
  1878. else
  1879. $acct_focus->column_fields[$xyz[$i]] = '';
  1880. }
  1881. $bill_street = str_replace(array("\r", "\n"), array('\r', '\n'), popup_decode_html($acct_focus->column_fields['bill_street']));
  1882. $ship_street = str_replace(array("\r", "\n"), array('\r', '\n'), popup_decode_html($acct_focus->column_fields['ship_street']));
  1883. $count = counterValue();
  1884. $value = '<a href="javascript:window.close();" onclick=\'set_return_address("' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '", "' . $relatedid . '", "' . nl2br(decode_html($slashes_account_name)) . '", "' . $bill_street . '", "' . $ship_street . '", "' . popup_decode_html($acct_focus->column_fields['bill_city']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_city']) . '", "' . popup_decode_html($acct_focus->column_fields['bill_state']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_state']) . '", "' . popup_decode_html($acct_focus->column_fields['bill_code']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_code']) . '", "' . popup_decode_html($acct_focus->column_fields['bill_country']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_country']) . '","' . popup_decode_html($acct_focus->column_fields['bill_pobox']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_pobox']) . '");\'id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
  1885. } else if ($relatedentity == 'Contacts') {
  1886. require_once('modules/Contacts/Contacts.php');
  1887. $displayValueArray = getEntityName('Contacts', $relatedid);
  1888. if (!empty($displayValueArray)) {
  1889. foreach ($displayValueArray as $key => $field_value) {
  1890. $contact_name = $field_value;
  1891. }
  1892. } else {
  1893. $contact_name = '';
  1894. }
  1895. $slashes_contact_name = popup_from_html($contact_name);
  1896. $slashes_contact_name = htmlspecialchars($slashes_contact_name, ENT_QUOTES, $default_charset);
  1897. $count = counterValue();
  1898. $value = '<a href="javascript:window.close();" onclick=\'set_return_contact("' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '", "' . $relatedid . '", "' . nl2br(decode_html($slashes_contact_name)) . '");\'id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
  1899. } else {
  1900. $value = $temp_val;
  1901. }
  1902. }
  1903. //added by rdhital/Raju for better emails
  1904. elseif ($popuptype == "set_return_emails") {
  1905. if ($module == 'Accounts') {
  1906. $name = $adb->query_result($list_result, $list_result_count, 'accountname');
  1907. $accid = $adb->query_result($list_result, $list_result_count, 'accountid');
  1908. if (CheckFieldPermission('email1', $module) == "true") {
  1909. $emailaddress = $adb->query_result($list_result, $list_result_count, "email1");
  1910. $email_check = 1;
  1911. }
  1912. else
  1913. $email_check = 0;
  1914. if ($emailaddress == '') {
  1915. if (CheckFieldPermission('email2', $module) == 'true') {
  1916. $emailaddress2 = $adb->query_result($list_result, $list_result_count, "email2");
  1917. $email_check = 2;
  1918. } else {
  1919. if ($email_check == 1)
  1920. $email_check = 4;
  1921. else
  1922. $email_check = 3;
  1923. }
  1924. }
  1925. $querystr = "SELECT fieldid,fieldlabel,columnname FROM vtiger_field WHERE tabid=? and uitype=13 and vtiger_field.presence in (0,2)";
  1926. $queryres = $adb->pquery($querystr, array(getTabid($module)));
  1927. //Change this index 0 - to get the vtiger_fieldid based on email1 or email2
  1928. $fieldid = $adb->query_result($queryres, 0, 'fieldid');
  1929. $slashes_name = popup_from_html($name);
  1930. $slashes_name = htmlspecialchars($slashes_name, ENT_QUOTES, $default_charset);
  1931. $count = counterValue();
  1932. $value = '<a href="javascript:window.close();" onclick=\'return set_return_emails(' . $entity_id . ',' . $fieldid . ',"' . decode_html($slashes_name) . '","' . $emailaddress . '","' . $emailaddress2 . '","' . $email_check . '"); \'id = ' . $count . '>' . textlength_check($name) . '</a>';
  1933. }elseif ($module == 'Vendors') {
  1934. $name = $adb->query_result($list_result, $list_result_count, 'vendorname');
  1935. $venid = $adb->query_result($list_result, $list_result_count, 'vendorid');
  1936. if (CheckFieldPermission('email', $module) == "true") {
  1937. $emailaddress = $adb->query_result($list_result, $list_result_count, "email");
  1938. $email_check = 1;
  1939. }
  1940. else
  1941. $email_check = 0;
  1942. $querystr = "SELECT fieldid,fieldlabel,columnname FROM vtiger_field WHERE tabid=? and uitype=13 and vtiger_field.presence in (0,2)";
  1943. $queryres = $adb->pquery($querystr, array(getTabid($module)));
  1944. //Change this index 0 - to get the vtiger_fieldid based on email1 or email2
  1945. $fieldid = $adb->query_result($queryres, 0, 'fieldid');
  1946. $slashes_name = popup_from_html($name);
  1947. $slashes_name = htmlspecialchars($slashes_name, ENT_QUOTES, $default_charset);
  1948. $count = counterValue();
  1949. $value = '<a href="javascript:window.close();" onclick=\'return set_return_emails(' . $entity_id . ',' . $fieldid . ',"' . decode_html($slashes_name) . '","' . $emailaddress . '","' . $emailaddress2 . '","' . $email_check . '"); \'id = ' . $count . '>' . textlength_check($name) . '</a>';
  1950. }elseif ($module == 'Contacts' || $module == 'Leads') {
  1951. $name = getFullNameFromQResult($list_result, $list_result_count, $module);
  1952. if (CheckFieldPermission('email', $module) == "true") {
  1953. $emailaddress = $adb->query_result($list_result, $list_result_count, "email");
  1954. $email_check = 1;
  1955. }
  1956. else
  1957. $email_check = 0;
  1958. if ($emailaddress == '') {
  1959. if (CheckFieldPermission('secondaryemail', $module) == 'true') {
  1960. $emailaddress2 = $adb->query_result($list_result, $list_result_count, "secondaryemail");
  1961. $email_check = 2;
  1962. } else {
  1963. if ($email_check == 1)
  1964. $email_check = 4;
  1965. else
  1966. $email_check = 3;
  1967. }
  1968. }
  1969. $querystr = "SELECT fieldid,fieldlabel,columnname FROM vtiger_field WHERE tabid=? and uitype=13 and vtiger_field.presence in (0,2)";
  1970. $queryres = $adb->pquery($querystr, array(getTabid($module)));
  1971. //Change this index 0 - to get the vtiger_fieldid based on email or secondaryemail
  1972. $fieldid = $adb->query_result($queryres, 0, 'fieldid');
  1973. $slashes_name = popup_from_html($name);
  1974. $slashes_name = htmlspecialchars($slashes_name, ENT_QUOTES, $default_charset);
  1975. $count = counterValue();
  1976. $value = '<a href="javascript:window.close();" onclick=\'return set_return_emails(' . $entity_id . ',' . $fieldid . ',"' . decode_html($slashes_name) . '","' . $emailaddress . '","' . $emailaddress2 . '","' . $email_check . '"); \'id = ' . $count . '>' . $name . '</a>';
  1977. }else {
  1978. $name = getFullNameFromQResult($list_result, $list_result_count, $module);
  1979. $emailaddress = $adb->query_result($list_result, $list_result_count, "email1");
  1980. $slashes_name = popup_from_html($name);
  1981. $slashes_name = htmlspecialchars($slashes_name, ENT_QUOTES, $default_charset);
  1982. $email_check = 1;
  1983. $count = counterValue();
  1984. $value = '<a href="javascript:window.close();" onclick=\'return set_return_emails(' . $entity_id . ',-1,"' . decode_html($slashes_name) . '","' . $emailaddress . '","' . $emailaddress2 . '","' . $email_check . '"); \'id = ' . $count . '>' . textlength_check($name) . '</a>';
  1985. }
  1986. } elseif ($popuptype == "specific_vendor_address") {
  1987. require_once('modules/Vendors/Vendors.php');
  1988. $acct_focus = new Vendors();
  1989. $acct_focus->retrieve_entity_info($entity_id, "Vendors");
  1990. $slashes_temp_val = popup_from_html($temp_val);
  1991. $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
  1992. $xyz = array('street', 'city', 'postalcode', 'pobox', 'country', 'state');
  1993. for ($i = 0; $i < 6; $i++) {
  1994. if (getFieldVisibilityPermission($module, $current_user->id, $xyz[$i]) == '0') {
  1995. $acct_focus->column_fields[$xyz[$i]] = $acct_focus->column_fields[$xyz[$i]];
  1996. }
  1997. else
  1998. $acct_focus->column_fields[$xyz[$i]] = '';
  1999. }
  2000. $bill_street = str_replace(array("\r", "\n"), array('\r', '\n'), popup_decode_html($acct_focus->column_fields['street']));
  2001. $count = counterValue();
  2002. $value = '<a href="javascript:window.close();" onclick=\'set_return_address("' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '", "' . $bill_street . '", "' . popup_decode_html($acct_focus->column_fields['city']) . '", "' . popup_decode_html($acct_focus->column_fields['state']) . '", "' . popup_decode_html($acct_focus->column_fields['postalcode']) . '", "' . popup_decode_html($acct_focus->column_fields['country']) . '","' . popup_decode_html($acct_focus->column_fields['pobox']) . '");\'id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
  2003. }
  2004. elseif ($popuptype == "specific_campaign") {
  2005. $slashes_temp_val = popup_from_html($temp_val);
  2006. $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
  2007. $count = counterValue();
  2008. $value = '<a href="javascript:window.close();" onclick=\'set_return_specific_campaign("' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '");\'id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
  2009. } else {
  2010. if ($colname == "lastname") {
  2011. $temp_val = getFullNameFromQResult($list_result, $list_result_count, $module);
  2012. } elseif ($module == 'Users' && $fieldname == 'last_name') {
  2013. $temp_val = getFullNameFromQResult($list_result, $list_result_count, $module);
  2014. }
  2015. $slashes_temp_val = popup_from_html($temp_val);
  2016. $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
  2017. $log->debug("Exiting getValue method ...");
  2018. if ($_REQUEST['maintab'] == 'Calendar') {
  2019. $count = counterValue();
  2020. $value = '<a href="javascript:window.close();" onclick=\'set_return_todo("' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '");\'id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
  2021. } else {
  2022. $value = '<a href="javascript:window.close();" onclick=\'set_return("' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '");\'';
  2023. if (empty($_REQUEST['forfield']) && $focus->popup_type != 'detailview') {
  2024. $count = counterValue();
  2025. $value .= " id='$count' ";
  2026. }
  2027. $value .= '>' . textlength_check($temp_val) . '</a>';
  2028. }
  2029. }
  2030. } else {
  2031. if (($module == "Leads" && $colname == "lastname") || ($module == "Contacts" && $colname == "lastname")) {
  2032. $count = counterValue();
  2033. $value = '<a href="index.php?action=DetailView&module=' . $module . '&record=' . $entity_id . '&parenttab=' . $tabname . '" id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
  2034. } elseif ($module == "Calendar") {
  2035. $actvity_type = $adb->query_result($list_result, $list_result_count, 'activitytype');
  2036. $actvity_type = ($actvity_type != '') ? $actvity_type : $adb->query_result($list_result, $list_result_count, 'type');
  2037. if ($actvity_type == "Task") {
  2038. $count = counterValue();
  2039. $value = '<a href="index.php?action=DetailView&module=' . $module . '&record=' . $entity_id . '&activity_mode=Task&parenttab=' . $tabname . '" id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
  2040. } else {
  2041. $count = counterValue();
  2042. $value = '<a href="index.php?action=DetailView&module=' . $module . '&record=' . $entity_id . '&activity_mode=Events&parenttab=' . $tabname . '" id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
  2043. }
  2044. } elseif ($module == "Vendors") {
  2045. $count = counterValue();
  2046. $value = '<a href="index.php?action=DetailView&module=Vendors&record=' . $entity_id . '&parenttab=' . $tabname . '" id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
  2047. } elseif ($module == "PriceBooks") {
  2048. $count = counterValue();
  2049. $value = '<a href="index.php?action=DetailView&module=PriceBooks&record=' . $entity_id . '&parenttab=' . $tabname . '" id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
  2050. } elseif ($module == "SalesOrder") {
  2051. $count = counterValue();
  2052. $value = '<a href="index.php?action=DetailView&module=SalesOrder&record=' . $entity_id . '&parenttab=' . $tabname . '" id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
  2053. } elseif ($module == 'Emails') {
  2054. $value = $temp_val;
  2055. } elseif (($module == "Users" && $colname == "last_name")) {
  2056. $temp_val = getFullNameFromQResult($list_result, $list_result_count, $module);
  2057. $value = '<a href="index.php?action=DetailView&module=' . $module . '&record=' . $entity_id . '&parenttab=' . $tabname . '">' . textlength_check($temp_val) . '</a>';
  2058. } else {
  2059. $count = counterValue();
  2060. $value = '<a href="index.php?action=DetailView&module=' . $module . '&record=' . $entity_id . '&parenttab=' . $tabname . '" id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
  2061. }
  2062. }
  2063. } elseif ($module == 'Calendar' && ($fieldname == 'time_start' ||
  2064. $fieldname == 'time_end')) {
  2065. $dateField = 'date_start';
  2066. if ($fieldname == 'time_end') {
  2067. $dateField = 'due_date';
  2068. }
  2069. $type = $adb->query_result($list_result, $list_result_count, 'activitytype');
  2070. if (empty($type)) {
  2071. $type = $adb->query_result($list_result, $list_result_count, 'type');
  2072. }
  2073. if ($type == 'Task' && $fieldname == 'time_end') {
  2074. $value = '--';
  2075. } else {
  2076. $date_val = $adb->query_result($list_result, $list_result_count, $dateField);
  2077. $date = new DateTimeField($date_val . ' ' . $temp_val);
  2078. $value = $date->getDisplayTime();
  2079. $value = textlength_check($value);
  2080. }
  2081. } else {
  2082. $value = $temp_val;
  2083. $value = textlength_check($value);
  2084. }
  2085. }
  2086. // Mike Crowe Mod --------------------------------------------------------Make right justified and vtiger_currency value
  2087. if (in_array($uitype, array(71, 72, 7, 9, 90))) {
  2088. $value = '<span align="right">' . $value . '</div>';
  2089. }
  2090. $log->debug("Exiting getValue method ...");
  2091. return $value;
  2092. }
  2093. /** Function to get the list query for a module
  2094. * @param $module -- module name:: Type string
  2095. * @param $where -- where:: Type string
  2096. * @returns $query -- query:: Type query
  2097. */
  2098. function getListQuery($module, $where = '') {
  2099. global $log;
  2100. $log->debug("Entering getListQuery(" . $module . "," . $where . ") method ...");
  2101. global $current_user;
  2102. require('user_privileges/user_privileges_' . $current_user->id . '.php');
  2103. require('user_privileges/sharing_privileges_' . $current_user->id . '.php');
  2104. $tab_id = getTabid($module);
  2105. $userNameSql = getSqlForNameInDisplayFormat(array('first_name' => 'vtiger_users.first_name', 'last_name' =>
  2106. 'vtiger_users.last_name'), 'Users');
  2107. switch ($module) {
  2108. Case "HelpDesk":
  2109. $query = "SELECT vtiger_crmentity.crmid, vtiger_crmentity.smownerid,
  2110. vtiger_troubletickets.title, vtiger_troubletickets.status,
  2111. vtiger_troubletickets.priority, vtiger_troubletickets.parent_id,
  2112. vtiger_contactdetails.contactid, vtiger_contactdetails.firstname,
  2113. vtiger_contactdetails.lastname, vtiger_account.accountid,
  2114. vtiger_account.accountname, vtiger_ticketcf.*, vtiger_troubletickets.ticket_no
  2115. FROM vtiger_troubletickets
  2116. INNER JOIN vtiger_ticketcf
  2117. ON vtiger_ticketcf.ticketid = vtiger_troubletickets.ticketid
  2118. INNER JOIN vtiger_crmentity
  2119. ON vtiger_crmentity.crmid = vtiger_troubletickets.ticketid
  2120. LEFT JOIN vtiger_groups
  2121. ON vtiger_groups.groupid = vtiger_crmentity.smownerid
  2122. LEFT JOIN vtiger_contactdetails
  2123. ON vtiger_troubletickets.parent_id = vtiger_contactdetails.contactid
  2124. LEFT JOIN vtiger_account
  2125. ON vtiger_account.accountid = vtiger_troubletickets.parent_id
  2126. LEFT JOIN vtiger_users
  2127. ON vtiger_crmentity.smownerid = vtiger_users.id
  2128. LEFT JOIN vtiger_products
  2129. ON vtiger_products.productid = vtiger_troubletickets.product_id";
  2130. $query .= ' ' . getNonAdminAccessControlQuery($module, $current_user);
  2131. $query .= "WHERE vtiger_crmentity.deleted = 0 " . $where;
  2132. break;
  2133. Case "Accounts":
  2134. //Query modified to sort by assigned to
  2135. $query = "SELECT vtiger_crmentity.crmid, vtiger_crmentity.smownerid,
  2136. vtiger_account.accountname, vtiger_account.email1,
  2137. vtiger_account.email2, vtiger_account.website, vtiger_account.phone,
  2138. vtiger_accountbillads.bill_city,
  2139. vtiger_accountscf.*
  2140. FROM vtiger_account
  2141. INNER JOIN vtiger_crmentity
  2142. ON vtiger_crmentity.crmid = vtiger_account.accountid
  2143. INNER JOIN vtiger_accountbillads
  2144. ON vtiger_account.accountid = vtiger_accountbillads.accountaddressid
  2145. INNER JOIN vtiger_accountshipads
  2146. ON vtiger_account.accountid = vtiger_accountshipads.accountaddressid
  2147. INNER JOIN vtiger_accountscf
  2148. ON vtiger_account.accountid = vtiger_accountscf.accountid
  2149. LEFT JOIN vtiger_groups
  2150. ON vtiger_groups.groupid = vtiger_crmentity.smownerid
  2151. LEFT JOIN vtiger_users
  2152. ON vtiger_users.id = vtiger_crmentity.smownerid
  2153. LEFT JOIN vtiger_account vtiger_account2
  2154. ON vtiger_account.parentid = vtiger_account2.accountid";
  2155. $query .= getNonAdminAccessControlQuery($module, $current_user);
  2156. $query .= "WHERE vtiger_crmentity.deleted = 0 " . $where;
  2157. break;
  2158. Case "Potentials":
  2159. //Query modified to sort by assigned to
  2160. $query = "SELECT vtiger_crmentity.crmid, vtiger_crmentity.smownerid,
  2161. vtiger_account.accountname,
  2162. vtiger_potential.related_to, vtiger_potential.potentialname,
  2163. vtiger_potential.sales_stage, vtiger_potential.amount,
  2164. vtiger_potential.currency, vtiger_potential.closingdate,
  2165. vtiger_potential.typeofrevenue,
  2166. vtiger_potentialscf.*
  2167. FROM vtiger_potential
  2168. INNER JOIN vtiger_crmentity
  2169. ON vtiger_crmentity.crmid = vtiger_potential.potentialid
  2170. INNER JOIN vtiger_potentialscf
  2171. ON vtiger_potentialscf.potentialid = vtiger_potential.potentialid
  2172. LEFT JOIN vtiger_account
  2173. ON vtiger_potential.related_to = vtiger_account.accountid
  2174. LEFT JOIN vtiger_contactdetails
  2175. ON vtiger_potential.related_to = vtiger_contactdetails.contactid
  2176. LEFT JOIN vtiger_campaign
  2177. ON vtiger_campaign.campaignid = vtiger_potential.campaignid
  2178. LEFT JOIN vtiger_groups
  2179. ON vtiger_groups.groupid = vtiger_crmentity.smownerid
  2180. LEFT JOIN vtiger_users
  2181. ON vtiger_users.id = vtiger_crmentity.smownerid";
  2182. $query .= getNonAdminAccessControlQuery($module, $current_user);
  2183. $query .= "WHERE vtiger_crmentity.deleted = 0 " . $where;
  2184. break;
  2185. Case "Leads":
  2186. $query = "SELECT vtiger_crmentity.crmid, vtiger_crmentity.smownerid,
  2187. vtiger_leaddetails.firstname, vtiger_leaddetails.lastname,
  2188. vtiger_leaddetails.company, vtiger_leadaddress.phone,
  2189. vtiger_leadsubdetails.website, vtiger_leaddetails.email,
  2190. vtiger_leadscf.*
  2191. FROM vtiger_leaddetails
  2192. INNER JOIN vtiger_crmentity
  2193. ON vtiger_crmentity.crmid = vtiger_leaddetails.leadid
  2194. INNER JOIN vtiger_leadsubdetails
  2195. ON vtiger_leadsubdetails.leadsubscriptionid = vtiger_leaddetails.leadid
  2196. INNER JOIN vtiger_leadaddress
  2197. ON vtiger_leadaddress.leadaddressid = vtiger_leadsubdetails.leadsubscriptionid
  2198. INNER JOIN vtiger_leadscf
  2199. ON vtiger_leaddetails.leadid = vtiger_leadscf.leadid
  2200. LEFT JOIN vtiger_groups
  2201. ON vtiger_groups.groupid = vtiger_crmentity.smownerid
  2202. LEFT JOIN vtiger_users
  2203. ON vtiger_users.id = vtiger_crmentity.smownerid";
  2204. $query .= getNonAdminAccessControlQuery($module, $current_user);
  2205. $query .= "WHERE vtiger_crmentity.deleted = 0 AND vtiger_leaddetails.converted = 0 " . $where;
  2206. break;
  2207. Case "Products":
  2208. $query = "SELECT vtiger_crmentity.crmid, vtiger_crmentity.smownerid, vtiger_crmentity.description, vtiger_products.*, vtiger_productcf.*
  2209. FROM vtiger_products
  2210. INNER JOIN vtiger_crmentity
  2211. ON vtiger_crmentity.crmid = vtiger_products.productid
  2212. INNER JOIN vtiger_productcf
  2213. ON vtiger_products.productid = vtiger_productcf.productid
  2214. LEFT JOIN vtiger_vendor
  2215. ON vtiger_vendor.vendorid = vtiger_products.vendor_id
  2216. LEFT JOIN vtiger_groups
  2217. ON vtiger_groups.groupid = vtiger_crmentity.smownerid
  2218. LEFT JOIN vtiger_users
  2219. ON vtiger_users.id = vtiger_crmentity.smownerid";
  2220. if ((isset($_REQUEST["from_dashboard"]) && $_REQUEST["from_dashboard"] == true) && (isset($_REQUEST["type"]) && $_REQUEST["type"] == "dbrd"))
  2221. $query .= " INNER JOIN vtiger_inventoryproductrel on vtiger_inventoryproductrel.productid = vtiger_products.productid";
  2222. $query .= getNonAdminAccessControlQuery($module, $current_user);
  2223. $query .= " WHERE vtiger_crmentity.deleted = 0 " . $where;
  2224. break;
  2225. Case "Documents":
  2226. $query = "SELECT case when (vtiger_users.user_name not like '') then $userNameSql else vtiger_groups.groupname end as user_name,vtiger_crmentity.crmid, vtiger_crmentity.modifiedtime,
  2227. vtiger_crmentity.smownerid,vtiger_attachmentsfolder.*,vtiger_notes.*
  2228. FROM vtiger_notes
  2229. INNER JOIN vtiger_crmentity
  2230. ON vtiger_crmentity.crmid = vtiger_notes.notesid
  2231. LEFT JOIN vtiger_groups
  2232. ON vtiger_groups.groupid = vtiger_crmentity.smownerid
  2233. LEFT JOIN vtiger_users
  2234. ON vtiger_users.id = vtiger_crmentity.smownerid
  2235. LEFT JOIN vtiger_attachmentsfolder
  2236. ON vtiger_notes.folderid = vtiger_attachmentsfolder.folderid";
  2237. $query .= getNonAdminAccessControlQuery($module, $current_user);
  2238. $query .= "WHERE vtiger_crmentity.deleted = 0 " . $where;
  2239. break;
  2240. Case "Contacts":
  2241. //Query modified to sort by assigned to
  2242. $query = "SELECT vtiger_contactdetails.firstname, vtiger_contactdetails.lastname,
  2243. vtiger_contactdetails.title, vtiger_contactdetails.accountid,
  2244. vtiger_contactdetails.email, vtiger_contactdetails.phone,
  2245. vtiger_crmentity.smownerid, vtiger_crmentity.crmid
  2246. FROM vtiger_contactdetails
  2247. INNER JOIN vtiger_crmentity
  2248. ON vtiger_crmentity.crmid = vtiger_contactdetails.contactid
  2249. INNER JOIN vtiger_contactaddress
  2250. ON vtiger_contactaddress.contactaddressid = vtiger_contactdetails.contactid
  2251. INNER JOIN vtiger_contactsubdetails
  2252. ON vtiger_contactsubdetails.contactsubscriptionid = vtiger_contactdetails.contactid
  2253. INNER JOIN vtiger_contactscf
  2254. ON vtiger_contactscf.contactid = vtiger_contactdetails.contactid
  2255. LEFT JOIN vtiger_account
  2256. ON vtiger_account.accountid = vtiger_contactdetails.accountid
  2257. LEFT JOIN vtiger_groups
  2258. ON vtiger_groups.groupid = vtiger_crmentity.smownerid
  2259. LEFT JOIN vtiger_users
  2260. ON vtiger_users.id = vtiger_crmentity.smownerid
  2261. LEFT JOIN vtiger_contactdetails vtiger_contactdetails2
  2262. ON vtiger_contactdetails.reportsto = vtiger_contactdetails2.contactid
  2263. LEFT JOIN vtiger_customerdetails
  2264. ON vtiger_customerdetails.customerid = vtiger_contactdetails.contactid";
  2265. if ((isset($_REQUEST["from_dashboard"]) && $_REQUEST["from_dashboard"] == true) &&
  2266. (isset($_REQUEST["type"]) && $_REQUEST["type"] == "dbrd")) {
  2267. $query .= " INNER JOIN vtiger_campaigncontrel on vtiger_campaigncontrel.contactid = " .
  2268. "vtiger_contactdetails.contactid";
  2269. }
  2270. $query .= getNonAdminAccessControlQuery($module, $current_user);
  2271. $query .= "WHERE vtiger_crmentity.deleted = 0 " . $where;
  2272. break;
  2273. Case "Calendar":
  2274. $query = "SELECT vtiger_activity.activityid as act_id,vtiger_crmentity.crmid, vtiger_crmentity.smownerid, vtiger_crmentity.setype,
  2275. vtiger_activity.*,
  2276. vtiger_contactdetails.lastname, vtiger_contactdetails.firstname,
  2277. vtiger_contactdetails.contactid,
  2278. vtiger_account.accountid, vtiger_account.accountname
  2279. FROM vtiger_activity
  2280. LEFT JOIN vtiger_activitycf
  2281. ON vtiger_activitycf.activityid = vtiger_activity.activityid
  2282. LEFT JOIN vtiger_cntactivityrel
  2283. ON vtiger_cntactivityrel.activityid = vtiger_activity.activityid
  2284. LEFT JOIN vtiger_contactdetails
  2285. ON vtiger_contactdetails.contactid = vtiger_cntactivityrel.contactid
  2286. LEFT JOIN vtiger_seactivityrel
  2287. ON vtiger_seactivityrel.activityid = vtiger_activity.activityid
  2288. LEFT OUTER JOIN vtiger_activity_reminder
  2289. ON vtiger_activity_reminder.activity_id = vtiger_activity.activityid
  2290. LEFT JOIN vtiger_crmentity
  2291. ON vtiger_crmentity.crmid = vtiger_activity.activityid
  2292. LEFT JOIN vtiger_users
  2293. ON vtiger_users.id = vtiger_crmentity.smownerid
  2294. LEFT JOIN vtiger_groups
  2295. ON vtiger_groups.groupid = vtiger_crmentity.smownerid
  2296. LEFT JOIN vtiger_users vtiger_users2
  2297. ON vtiger_crmentity.modifiedby = vtiger_users2.id
  2298. LEFT JOIN vtiger_groups vtiger_groups2
  2299. ON vtiger_crmentity.modifiedby = vtiger_groups2.groupid
  2300. LEFT OUTER JOIN vtiger_account
  2301. ON vtiger_account.accountid = vtiger_contactdetails.accountid
  2302. LEFT OUTER JOIN vtiger_leaddetails
  2303. ON vtiger_leaddetails.leadid = vtiger_seactivityrel.crmid
  2304. LEFT OUTER JOIN vtiger_account vtiger_account2
  2305. ON vtiger_account2.accountid = vtiger_seactivityrel.crmid
  2306. LEFT OUTER JOIN vtiger_potential
  2307. ON vtiger_potential.potentialid = vtiger_seactivityrel.crmid
  2308. LEFT OUTER JOIN vtiger_troubletickets
  2309. ON vtiger_troubletickets.ticketid = vtiger_seactivityrel.crmid
  2310. LEFT OUTER JOIN vtiger_salesorder
  2311. ON vtiger_salesorder.salesorderid = vtiger_seactivityrel.crmid
  2312. LEFT OUTER JOIN vtiger_purchaseorder
  2313. ON vtiger_purchaseorder.purchaseorderid = vtiger_seactivityrel.crmid
  2314. LEFT OUTER JOIN vtiger_quotes
  2315. ON vtiger_quotes.quoteid = vtiger_seactivityrel.crmid
  2316. LEFT OUTER JOIN vtiger_invoice
  2317. ON vtiger_invoice.invoiceid = vtiger_seactivityrel.crmid
  2318. LEFT OUTER JOIN vtiger_campaign
  2319. ON vtiger_campaign.campaignid = vtiger_seactivityrel.crmid";
  2320. //added to fix #5135
  2321. if (isset($_REQUEST['from_homepage']) && ($_REQUEST['from_homepage'] ==
  2322. "upcoming_activities" || $_REQUEST['from_homepage'] == "pending_activities")) {
  2323. $query.=" LEFT OUTER JOIN vtiger_recurringevents
  2324. ON vtiger_recurringevents.activityid=vtiger_activity.activityid";
  2325. }
  2326. //end
  2327. $query .= getNonAdminAccessControlQuery($module, $current_user);
  2328. $query.=" WHERE vtiger_crmentity.deleted = 0 AND activitytype != 'Emails' " . $where;
  2329. break;
  2330. Case "Emails":
  2331. $query = "SELECT DISTINCT vtiger_crmentity.crmid, vtiger_crmentity.smownerid,
  2332. vtiger_activity.activityid, vtiger_activity.subject,
  2333. vtiger_activity.date_start,
  2334. vtiger_contactdetails.lastname, vtiger_contactdetails.firstname,
  2335. vtiger_contactdetails.contactid
  2336. FROM vtiger_activity
  2337. INNER JOIN vtiger_crmentity
  2338. ON vtiger_crmentity.crmid = vtiger_activity.activityid
  2339. LEFT JOIN vtiger_users
  2340. ON vtiger_users.id = vtiger_crmentity.smownerid
  2341. LEFT JOIN vtiger_seactivityrel
  2342. ON vtiger_seactivityrel.activityid = vtiger_activity.activityid
  2343. LEFT JOIN vtiger_contactdetails
  2344. ON vtiger_contactdetails.contactid = vtiger_seactivityrel.crmid
  2345. LEFT JOIN vtiger_cntactivityrel
  2346. ON vtiger_cntactivityrel.activityid = vtiger_activity.activityid
  2347. AND vtiger_cntactivityrel.contactid = vtiger_cntactivityrel.contactid
  2348. LEFT JOIN vtiger_groups
  2349. ON vtiger_groups.groupid = vtiger_crmentity.smownerid
  2350. LEFT JOIN vtiger_salesmanactivityrel
  2351. ON vtiger_salesmanactivityrel.activityid = vtiger_activity.activityid
  2352. LEFT JOIN vtiger_emaildetails
  2353. ON vtiger_emaildetails.emailid = vtiger_activity.activityid
  2354. WHERE vtiger_activity.activitytype = 'Emails'";
  2355. $query .= getNonAdminAccessControlQuery($module, $current_user);
  2356. $query .= "AND vtiger_crmentity.deleted = 0 " . $where;
  2357. break;
  2358. Case "Faq":
  2359. $query = "SELECT vtiger_crmentity.crmid, vtiger_crmentity.createdtime, vtiger_crmentity.modifiedtime,
  2360. vtiger_faq.*
  2361. FROM vtiger_faq
  2362. INNER JOIN vtiger_crmentity
  2363. ON vtiger_crmentity.crmid = vtiger_faq.id
  2364. LEFT JOIN vtiger_products
  2365. ON vtiger_faq.product_id = vtiger_products.productid";
  2366. $query .= getNonAdminAccessControlQuery($module, $current_user);
  2367. $query .= "WHERE vtiger_crmentity.deleted = 0 " . $where;
  2368. break;
  2369. Case "Vendors":
  2370. $query = "SELECT vtiger_crmentity.crmid, vtiger_vendor.*
  2371. FROM vtiger_vendor
  2372. INNER JOIN vtiger_crmentity
  2373. ON vtiger_crmentity.crmid = vtiger_vendor.vendorid
  2374. INNER JOIN vtiger_vendorcf
  2375. ON vtiger_vendor.vendorid = vtiger_vendorcf.vendorid
  2376. WHERE vtiger_crmentity.deleted = 0 " . $where;
  2377. break;
  2378. Case "PriceBooks":
  2379. $query = "SELECT vtiger_crmentity.crmid, vtiger_pricebook.*, vtiger_currency_info.currency_name
  2380. FROM vtiger_pricebook
  2381. INNER JOIN vtiger_crmentity
  2382. ON vtiger_crmentity.crmid = vtiger_pricebook.pricebookid
  2383. INNER JOIN vtiger_pricebookcf
  2384. ON vtiger_pricebook.pricebookid = vtiger_pricebookcf.pricebookid
  2385. LEFT JOIN vtiger_currency_info
  2386. ON vtiger_pricebook.currency_id = vtiger_currency_info.id
  2387. WHERE vtiger_crmentity.deleted = 0 " . $where;
  2388. break;
  2389. Case "Quotes":
  2390. //Query modified to sort by assigned to
  2391. $query = "SELECT vtiger_crmentity.*,
  2392. vtiger_quotes.*,
  2393. vtiger_quotesbillads.*,
  2394. vtiger_quotesshipads.*,
  2395. vtiger_potential.potentialname,
  2396. vtiger_account.accountname,
  2397. vtiger_currency_info.currency_name
  2398. FROM vtiger_quotes
  2399. INNER JOIN vtiger_crmentity
  2400. ON vtiger_crmentity.crmid = vtiger_quotes.quoteid
  2401. INNER JOIN vtiger_quotesbillads
  2402. ON vtiger_quotes.quoteid = vtiger_quotesbillads.quotebilladdressid
  2403. INNER JOIN vtiger_quotesshipads
  2404. ON vtiger_quotes.quoteid = vtiger_quotesshipads.quoteshipaddressid
  2405. LEFT JOIN vtiger_quotescf
  2406. ON vtiger_quotes.quoteid = vtiger_quotescf.quoteid
  2407. LEFT JOIN vtiger_currency_info
  2408. ON vtiger_quotes.currency_id = vtiger_currency_info.id
  2409. LEFT OUTER JOIN vtiger_account
  2410. ON vtiger_account.accountid = vtiger_quotes.accountid
  2411. LEFT OUTER JOIN vtiger_potential
  2412. ON vtiger_potential.potentialid = vtiger_quotes.potentialid
  2413. LEFT JOIN vtiger_contactdetails
  2414. ON vtiger_contactdetails.contactid = vtiger_quotes.contactid
  2415. LEFT JOIN vtiger_groups
  2416. ON vtiger_groups.groupid = vtiger_crmentity.smownerid
  2417. LEFT JOIN vtiger_users
  2418. ON vtiger_users.id = vtiger_crmentity.smownerid
  2419. LEFT JOIN vtiger_users as vtiger_usersQuotes
  2420. ON vtiger_usersQuotes.id = vtiger_quotes.inventorymanager";
  2421. $query .= getNonAdminAccessControlQuery($module, $current_user);
  2422. $query .= "WHERE vtiger_crmentity.deleted = 0 " . $where;
  2423. break;
  2424. Case "PurchaseOrder":
  2425. //Query modified to sort by assigned to
  2426. $query = "SELECT vtiger_crmentity.*,
  2427. vtiger_purchaseorder.*,
  2428. vtiger_pobillads.*,
  2429. vtiger_poshipads.*,
  2430. vtiger_vendor.vendorname,
  2431. vtiger_currency_info.currency_name
  2432. FROM vtiger_purchaseorder
  2433. INNER JOIN vtiger_crmentity
  2434. ON vtiger_crmentity.crmid = vtiger_purchaseorder.purchaseorderid
  2435. LEFT OUTER JOIN vtiger_vendor
  2436. ON vtiger_purchaseorder.vendorid = vtiger_vendor.vendorid
  2437. LEFT JOIN vtiger_contactdetails
  2438. ON vtiger_purchaseorder.contactid = vtiger_contactdetails.contactid
  2439. INNER JOIN vtiger_pobillads
  2440. ON vtiger_purchaseorder.purchaseorderid = vtiger_pobillads.pobilladdressid
  2441. INNER JOIN vtiger_poshipads
  2442. ON vtiger_purchaseorder.purchaseorderid = vtiger_poshipads.poshipaddressid
  2443. LEFT JOIN vtiger_purchaseordercf
  2444. ON vtiger_purchaseordercf.purchaseorderid = vtiger_purchaseorder.purchaseorderid
  2445. LEFT JOIN vtiger_currency_info
  2446. ON vtiger_purchaseorder.currency_id = vtiger_currency_info.id
  2447. LEFT JOIN vtiger_groups
  2448. ON vtiger_groups.groupid = vtiger_crmentity.smownerid
  2449. LEFT JOIN vtiger_users
  2450. ON vtiger_users.id = vtiger_crmentity.smownerid";
  2451. $query .= getNonAdminAccessControlQuery($module, $current_user);
  2452. $query .= "WHERE vtiger_crmentity.deleted = 0 " . $where;
  2453. break;
  2454. Case "SalesOrder":
  2455. //Query modified to sort by assigned to
  2456. $query = "SELECT vtiger_crmentity.*,
  2457. vtiger_salesorder.*,
  2458. vtiger_sobillads.*,
  2459. vtiger_soshipads.*,
  2460. vtiger_quotes.subject AS quotename,
  2461. vtiger_account.accountname,
  2462. vtiger_currency_info.currency_name
  2463. FROM vtiger_salesorder
  2464. INNER JOIN vtiger_crmentity
  2465. ON vtiger_crmentity.crmid = vtiger_salesorder.salesorderid
  2466. INNER JOIN vtiger_sobillads
  2467. ON vtiger_salesorder.salesorderid = vtiger_sobillads.sobilladdressid
  2468. INNER JOIN vtiger_soshipads
  2469. ON vtiger_salesorder.salesorderid = vtiger_soshipads.soshipaddressid
  2470. LEFT JOIN vtiger_salesordercf
  2471. ON vtiger_salesordercf.salesorderid = vtiger_salesorder.salesorderid
  2472. LEFT JOIN vtiger_currency_info
  2473. ON vtiger_salesorder.currency_id = vtiger_currency_info.id
  2474. LEFT OUTER JOIN vtiger_quotes
  2475. ON vtiger_quotes.quoteid = vtiger_salesorder.quoteid
  2476. LEFT OUTER JOIN vtiger_account
  2477. ON vtiger_account.accountid = vtiger_salesorder.accountid
  2478. LEFT JOIN vtiger_contactdetails
  2479. ON vtiger_salesorder.contactid = vtiger_contactdetails.contactid
  2480. LEFT JOIN vtiger_potential
  2481. ON vtiger_potential.potentialid = vtiger_salesorder.potentialid
  2482. LEFT JOIN vtiger_invoice_recurring_info
  2483. ON vtiger_invoice_recurring_info.salesorderid = vtiger_salesorder.salesorderid
  2484. LEFT JOIN vtiger_groups
  2485. ON vtiger_groups.groupid = vtiger_crmentity.smownerid
  2486. LEFT JOIN vtiger_users
  2487. ON vtiger_users.id = vtiger_crmentity.smownerid";
  2488. $query .= getNonAdminAccessControlQuery($module, $current_user);
  2489. $query .= "WHERE vtiger_crmentity.deleted = 0 " . $where;
  2490. break;
  2491. Case "Invoice":
  2492. //Query modified to sort by assigned to
  2493. //query modified -Code contribute by Geoff(http://forums.vtiger.com/viewtopic.php?t=3376)
  2494. $query = "SELECT vtiger_crmentity.*,
  2495. vtiger_invoice.*,
  2496. vtiger_invoicebillads.*,
  2497. vtiger_invoiceshipads.*,
  2498. vtiger_salesorder.subject AS salessubject,
  2499. vtiger_account.accountname,
  2500. vtiger_currency_info.currency_name
  2501. FROM vtiger_invoice
  2502. INNER JOIN vtiger_crmentity
  2503. ON vtiger_crmentity.crmid = vtiger_invoice.invoiceid
  2504. INNER JOIN vtiger_invoicebillads
  2505. ON vtiger_invoice.invoiceid = vtiger_invoicebillads.invoicebilladdressid
  2506. INNER JOIN vtiger_invoiceshipads
  2507. ON vtiger_invoice.invoiceid = vtiger_invoiceshipads.invoiceshipaddressid
  2508. LEFT JOIN vtiger_currency_info
  2509. ON vtiger_invoice.currency_id = vtiger_currency_info.id
  2510. LEFT OUTER JOIN vtiger_salesorder
  2511. ON vtiger_salesorder.salesorderid = vtiger_invoice.salesorderid
  2512. LEFT OUTER JOIN vtiger_account
  2513. ON vtiger_account.accountid = vtiger_invoice.accountid
  2514. LEFT JOIN vtiger_contactdetails
  2515. ON vtiger_contactdetails.contactid = vtiger_invoice.contactid
  2516. INNER JOIN vtiger_invoicecf
  2517. ON vtiger_invoice.invoiceid = vtiger_invoicecf.invoiceid
  2518. LEFT JOIN vtiger_groups
  2519. ON vtiger_groups.groupid = vtiger_crmentity.smownerid
  2520. LEFT JOIN vtiger_users
  2521. ON vtiger_users.id = vtiger_crmentity.smownerid";
  2522. $query .= getNonAdminAccessControlQuery($module, $current_user);
  2523. $query .= "WHERE vtiger_crmentity.deleted = 0 " . $where;
  2524. break;
  2525. Case "Campaigns":
  2526. //Query modified to sort by assigned to
  2527. //query modified -Code contribute by Geoff(http://forums.vtiger.com/viewtopic.php?t=3376)
  2528. $query = "SELECT vtiger_crmentity.*,
  2529. vtiger_campaign.*
  2530. FROM vtiger_campaign
  2531. INNER JOIN vtiger_crmentity
  2532. ON vtiger_crmentity.crmid = vtiger_campaign.campaignid
  2533. INNER JOIN vtiger_campaignscf
  2534. ON vtiger_campaign.campaignid = vtiger_campaignscf.campaignid
  2535. LEFT JOIN vtiger_groups
  2536. ON vtiger_groups.groupid = vtiger_crmentity.smownerid
  2537. LEFT JOIN vtiger_users
  2538. ON vtiger_users.id = vtiger_crmentity.smownerid
  2539. LEFT JOIN vtiger_products
  2540. ON vtiger_products.productid = vtiger_campaign.product_id";
  2541. $query .= getNonAdminAccessControlQuery($module, $current_user);
  2542. $query .= "WHERE vtiger_crmentity.deleted = 0 " . $where;
  2543. break;
  2544. Case "Users":
  2545. $query = "SELECT id,user_name,first_name,last_name,email1,phone_mobile,phone_work,is_admin,status,email2,
  2546. vtiger_user2role.roleid as roleid,vtiger_role.depth as depth
  2547. FROM vtiger_users
  2548. INNER JOIN vtiger_user2role ON vtiger_users.id = vtiger_user2role.userid
  2549. INNER JOIN vtiger_role ON vtiger_user2role.roleid = vtiger_role.roleid
  2550. WHERE deleted=0 " . $where;
  2551. break;
  2552. default:
  2553. // vtlib customization: Include the module file
  2554. $focus = CRMEntity::getInstance($module);
  2555. $query = $focus->getListQuery($module, $where);
  2556. // END
  2557. }
  2558. if ($module != 'Users') {
  2559. $query = listQueryNonAdminChange($query, $module);
  2560. }
  2561. $log->debug("Exiting getListQuery method ...");
  2562. return $query;
  2563. }
  2564. /* * Function returns the list of records which an user is entiled to view
  2565. * Param $module - module name
  2566. * Returns a database query - type string
  2567. */
  2568. function getReadEntityIds($module) {
  2569. global $log;
  2570. $log->debug("Entering getReadEntityIds(" . $module . ") method ...");
  2571. global $current_user;
  2572. require('user_privileges/user_privileges_' . $current_user->id . '.php');
  2573. require('user_privileges/sharing_privileges_' . $current_user->id . '.php');
  2574. $tab_id = getTabid($module);
  2575. if ($module == "Leads") {
  2576. $query = "SELECT vtiger_crmentity.crmid
  2577. FROM vtiger_leaddetails
  2578. INNER JOIN vtiger_crmentity
  2579. ON vtiger_crmentity.crmid = vtiger_leaddetails.leadid
  2580. LEFT JOIN vtiger_groups
  2581. ON vtiger_groups.groupid = vtiger_crmentity.smownerid";
  2582. $query .= getNonAdminAccessControlQuery($module, $current_user);
  2583. $query .= "WHERE vtiger_crmentity.deleted = 0
  2584. AND vtiger_leaddetails.converted = 0 ";
  2585. } elseif ($module == "Accounts") {
  2586. //Query modified to sort by assigned to
  2587. $query = "SELECT vtiger_crmentity.crmid
  2588. FROM vtiger_account
  2589. INNER JOIN vtiger_crmentity
  2590. ON vtiger_crmentity.crmid = vtiger_account.accountid
  2591. LEFT JOIN vtiger_groups
  2592. ON vtiger_groups.groupid = vtiger_crmentity.smownerid";
  2593. $query .= getNonAdminAccessControlQuery($module, $current_user);
  2594. $query .= "WHERE vtiger_crmentity.deleted = 0 ";
  2595. } elseif ($module == "Potentials") {
  2596. //Query modified to sort by assigned to
  2597. $query = "SELECT vtiger_crmentity.crmid
  2598. FROM vtiger_potential
  2599. INNER JOIN vtiger_crmentity
  2600. ON vtiger_crmentity.crmid = vtiger_potential.potentialid
  2601. LEFT JOIN vtiger_groups
  2602. ON vtiger_groups.groupid = vtiger_crmentity.smownerid";
  2603. $query .= getNonAdminAccessControlQuery($module, $current_user);
  2604. $query .= "WHERE vtiger_crmentity.deleted = 0 ";
  2605. } elseif ($module == "Contacts") {
  2606. //Query modified to sort by assigned to
  2607. $query = "SELECT vtiger_crmentity.crmid
  2608. FROM vtiger_contactdetails
  2609. INNER JOIN vtiger_crmentity
  2610. ON vtiger_crmentity.crmid = vtiger_contactdetails.contactid
  2611. LEFT JOIN vtiger_groups
  2612. ON vtiger_groups.groupid = vtiger_crmentity.smownerid";
  2613. $query .= getNonAdminAccessControlQuery($module, $current_user);
  2614. $query .= "WHERE vtiger_crmentity.deleted = 0 ";
  2615. } elseif ($module == "Products") {
  2616. $query = "SELECT DISTINCT vtiger_crmentity.crmid
  2617. FROM vtiger_products
  2618. INNER JOIN vtiger_crmentity
  2619. ON vtiger_crmentity.crmid = vtiger_products.productid
  2620. LEFT JOIN vtiger_seproductsrel
  2621. ON vtiger_seproductsrel.productid = vtiger_products.productid
  2622. WHERE vtiger_crmentity.deleted = 0
  2623. AND (vtiger_seproductsrel.crmid IS NULL
  2624. OR vtiger_seproductsrel.crmid IN (" . getReadEntityIds('Leads') . ")
  2625. OR vtiger_seproductsrel.crmid IN (" . getReadEntityIds('Accounts') . ")
  2626. OR vtiger_seproductsrel.crmid IN (" . getReadEntityIds('Potentials') . ")
  2627. OR vtiger_seproductsrel.crmid IN (" . getReadEntityIds('Contacts') . ")) ";
  2628. } elseif ($module == "PurchaseOrder") {
  2629. //Query modified to sort by assigned to
  2630. $query = "SELECT vtiger_crmentity.crmid
  2631. FROM vtiger_purchaseorder
  2632. INNER JOIN vtiger_crmentity
  2633. ON vtiger_crmentity.crmid = vtiger_purchaseorder.purchaseorderid
  2634. LEFT JOIN vtiger_groups
  2635. ON vtiger_groups.groupid = vtiger_crmentity.smownerid";
  2636. $query .= getNonAdminAccessControlQuery($module, $current_user);
  2637. $query .= "WHERE vtiger_crmentity.deleted = 0 ";
  2638. } elseif ($module == "SalesOrder") {
  2639. //Query modified to sort by assigned to
  2640. $query = "SELECT vtiger_crmentity.crmid
  2641. FROM vtiger_salesorder
  2642. INNER JOIN vtiger_crmentity
  2643. ON vtiger_crmentity.crmid = vtiger_salesorder.salesorderid
  2644. LEFT JOIN vtiger_groups
  2645. ON vtiger_groups.groupid = vtiger_crmentity.smownerid";
  2646. $query .= getNonAdminAccessControlQuery($module, $current_user);
  2647. $query .= "WHERE vtiger_crmentity.deleted = 0 ";
  2648. } elseif ($module == "Invoice") {
  2649. $query = "SELECT vtiger_crmentity.crmid
  2650. FROM vtiger_invoice
  2651. INNER JOIN vtiger_crmentity
  2652. ON vtiger_crmentity.crmid = vtiger_invoice.invoiceid
  2653. LEFT JOIN vtiger_groups
  2654. ON vtiger_groups.groupid = vtiger_crmentity.smownerid";
  2655. $query .= getNonAdminAccessControlQuery($module, $current_user);
  2656. $query .= "WHERE vtiger_crmentity.deleted = 0 ";
  2657. } elseif ($module == "Quotes") {
  2658. $query = "SELECT vtiger_crmentity.crmid
  2659. FROM vtiger_quotes
  2660. INNER JOIN vtiger_crmentity
  2661. ON vtiger_crmentity.crmid = vtiger_quotes.quoteid
  2662. LEFT JOIN vtiger_groups
  2663. ON vtiger_groups.groupid = vtiger_crmentity.smownerid";
  2664. $query .= getNonAdminAccessControlQuery($module, $current_user);
  2665. $query .= "WHERE vtiger_crmentity.deleted = 0 ";
  2666. } elseif ($module == "HelpDesk") {
  2667. $query = "SELECT vtiger_crmentity.crmid
  2668. FROM vtiger_troubletickets
  2669. INNER JOIN vtiger_crmentity
  2670. ON vtiger_crmentity.crmid = vtiger_troubletickets.ticketid
  2671. LEFT JOIN vtiger_groups
  2672. ON vtiger_groups.groupid = vtiger_crmentity.smownerid";
  2673. $query .= getNonAdminAccessControlQuery($module, $current_user);
  2674. $query .= "WHERE vtiger_crmentity.deleted = 0 ";
  2675. }
  2676. $log->debug("Exiting getReadEntityIds method ...");
  2677. return $query;
  2678. }
  2679. /** Function to get alphabetical search links
  2680. * Param $module - module name
  2681. * Param $action - action
  2682. * Param $fieldname - vtiger_field name
  2683. * Param $query - query
  2684. * Param $type - search type
  2685. * Param $popuptype - popup type
  2686. * Param $recordid - record id
  2687. * Param $return_module - return module
  2688. * Param $append_url - url string to be appended
  2689. * Param $viewid - custom view id
  2690. * Param $groupid - group id
  2691. * Returns an string value
  2692. */
  2693. function AlphabeticalSearch($module, $action, $fieldname, $query, $type, $popuptype = '', $recordid = '', $return_module = '', $append_url = '', $viewid = '', $groupid = '') {
  2694. global $log;
  2695. $log->debug("Entering AlphabeticalSearch(" . $module . "," . $action . "," . $fieldname . "," . $query . "," . $type . "," . $popuptype . "," . $recordid . "," . $return_module . "," . $append_url . "," . $viewid . "," . $groupid . ") method ...");
  2696. if ($type == 'advanced')
  2697. $flag = '&advanced=true';
  2698. if ($popuptype != '')
  2699. $popuptypevalue = "&popuptype=" . $popuptype;
  2700. if ($recordid != '')
  2701. $returnvalue = '&recordid=' . $recordid;
  2702. if ($return_module != '')
  2703. $returnvalue .= '&return_module=' . $return_module;
  2704. // vtlib Customization : For uitype 10 popup during paging
  2705. if ($_REQUEST['form'] == 'vtlibPopupView') {
  2706. $returnvalue .= '&form=vtlibPopupView&forfield=' . vtlib_purify($_REQUEST['forfield']) . '&srcmodule=' . vtlib_purify($_REQUEST['srcmodule']) . '&forrecord=' . vtlib_purify($_REQUEST['forrecord']);
  2707. }
  2708. // END
  2709. for ($var = 'A', $i = 1; $i <= 26; $i++, $var++)
  2710. // Mike Crowe Mod --------------------------------------------------------added groupid to url
  2711. $list .= '<td class="searchAlph" id="alpha_' . $i . '" align="center" onClick=\'alphabetic("' . $module . '","gname=' . $groupid . '&query=' . $query . '&search_field=' . $fieldname . '&searchtype=BasicSearch&operator=s&type=alpbt&search_text=' . $var . $flag . $popuptypevalue . $returnvalue . $append_url . '","alpha_' . $i . '")\'>' . $var . '</td>';
  2712. $log->debug("Exiting AlphabeticalSearch method ...");
  2713. return $list;
  2714. }
  2715. /* * Function to get parent name for a given parent id
  2716. * Param $module - module name
  2717. * Param $list_result- result set
  2718. * Param $rset - result set index
  2719. * Returns an string value
  2720. */
  2721. function getRelatedToEntity($module, $list_result, $rset) {
  2722. global $log;
  2723. $log->debug("Entering getRelatedToEntity(" . $module . "," . $list_result . "," . $rset . ") method ...");
  2724. global $adb;
  2725. $seid = $adb->query_result($list_result, $rset, "relatedto");
  2726. $action = "DetailView";
  2727. if (isset($seid) && $seid != '') {
  2728. $parent_module = $parent_module = getSalesEntityType($seid);
  2729. if ($parent_module == 'Accounts') {
  2730. $numrows = $adb->num_rows($evt_result);
  2731. $parent_module = $adb->query_result($evt_result, 0, 'setype');
  2732. $parent_id = $adb->query_result($evt_result, 0, 'crmid');
  2733. if ($numrows > 1) {
  2734. $parent_module = 'Multiple';
  2735. $parent_name = $app_strings['LBL_MULTIPLE'];
  2736. }
  2737. //Raju -- Ends
  2738. $parent_query = "SELECT accountname FROM vtiger_account WHERE accountid=?";
  2739. $parent_result = $adb->pquery($parent_query, array($seid));
  2740. $parent_name = $adb->query_result($parent_result, 0, "accountname");
  2741. }
  2742. if ($parent_module == 'Leads') {
  2743. $parent_query = "SELECT firstname,lastname FROM vtiger_leaddetails WHERE leadid=?";
  2744. $parent_result = $adb->pquery($parent_query, array($seid));
  2745. $parent_name = getFullNameFromQResult($parent_result, 0, "Leads");
  2746. }
  2747. if ($parent_module == 'Potentials') {
  2748. $parent_query = "SELECT potentialname FROM vtiger_potential WHERE potentialid=?";
  2749. $parent_result = $adb->pquery($parent_query, array($seid));
  2750. $parent_name = $adb->query_result($parent_result, 0, "potentialname");
  2751. }
  2752. if ($parent_module == 'Products') {
  2753. $parent_query = "SELECT productname FROM vtiger_products WHERE productid=?";
  2754. $parent_result = $adb->pquery($parent_query, array($seid));
  2755. $parent_name = $adb->query_result($parent_result, 0, "productname");
  2756. }
  2757. if ($parent_module == 'PurchaseOrder') {
  2758. $parent_query = "SELECT subject FROM vtiger_purchaseorder WHERE purchaseorderid=?";
  2759. $parent_result = $adb->pquery($parent_query, array($seid));
  2760. $parent_name = $adb->query_result($parent_result, 0, "subject");
  2761. }
  2762. if ($parent_module == 'SalesOrder') {
  2763. $parent_query = "SELECT subject FROM vtiger_salesorder WHERE salesorderid=?";
  2764. $parent_result = $adb->pquery($parent_query, array($seid));
  2765. $parent_name = $adb->query_result($parent_result, 0, "subject");
  2766. }
  2767. if ($parent_module == 'Invoice') {
  2768. $parent_query = "SELECT subject FROM vtiger_invoice WHERE invoiceid=?";
  2769. $parent_result = $adb->pquery($parent_query, array($seid));
  2770. $parent_name = $adb->query_result($parent_result, 0, "subject");
  2771. }
  2772. $parent_value = "<a href='index.php?module=" . $parent_module . "&action=" . $action . "&record=" . $seid . "'>" . $parent_name . "</a>";
  2773. } else {
  2774. $parent_value = '';
  2775. }
  2776. $log->debug("Exiting getRelatedToEntity method ...");
  2777. return $parent_value;
  2778. }
  2779. /* * Function to get parent name for a given parent id
  2780. * Param $module - module name
  2781. * Param $list_result- result set
  2782. * Param $rset - result set index
  2783. * Returns an string value
  2784. */
  2785. //used in home page listTop vtiger_files
  2786. function getRelatedTo($module, $list_result, $rset) {
  2787. global $adb, $log, $app_strings;
  2788. $tabname = getParentTab();
  2789. if ($module == "Documents") {
  2790. $notesid = $adb->query_result($list_result, $rset, "notesid");
  2791. $action = "DetailView";
  2792. $evt_query = "SELECT vtiger_senotesrel.crmid, vtiger_crmentity.setype
  2793. FROM vtiger_senotesrel
  2794. INNER JOIN vtiger_crmentity
  2795. ON vtiger_senotesrel.crmid = vtiger_crmentity.crmid
  2796. WHERE vtiger_senotesrel.notesid = ?";
  2797. $params = array($notesid);
  2798. } else if ($module == "Products") {
  2799. $productid = $adb->query_result($list_result, $rset, "productid");
  2800. $action = "DetailView";
  2801. $evt_query = "SELECT vtiger_seproductsrel.crmid, vtiger_crmentity.setype
  2802. FROM vtiger_seproductsrel
  2803. INNER JOIN vtiger_crmentity
  2804. ON vtiger_seproductsrel.crmid = vtiger_crmentity.crmid
  2805. WHERE vtiger_seproductsrel.productid =?";
  2806. $params = array($productid);
  2807. } else {
  2808. $activity_id = $adb->query_result($list_result, $rset, "activityid");
  2809. $action = "DetailView";
  2810. $evt_query = "SELECT vtiger_seactivityrel.crmid, vtiger_crmentity.setype
  2811. FROM vtiger_seactivityrel
  2812. INNER JOIN vtiger_crmentity
  2813. ON vtiger_seactivityrel.crmid = vtiger_crmentity.crmid
  2814. WHERE vtiger_seactivityrel.activityid=?";
  2815. $params = array($activity_id);
  2816. if ($module == 'HelpDesk') {
  2817. $activity_id = $adb->query_result($list_result, $rset, "parent_id");
  2818. if ($activity_id != '') {
  2819. $evt_query = "SELECT crmid, setype FROM vtiger_crmentity WHERE crmid=?";
  2820. $params = array($activity_id);
  2821. }
  2822. }
  2823. }
  2824. //added by raju to change the related to in emails inot multiple if email is for more than one contact
  2825. $evt_result = $adb->pquery($evt_query, $params);
  2826. $numrows = $adb->num_rows($evt_result);
  2827. $parent_module = $adb->query_result($evt_result, 0, 'setype');
  2828. $parent_id = $adb->query_result($evt_result, 0, 'crmid');
  2829. if ($numrows > 1) {
  2830. $parent_module = 'Multiple';
  2831. $parent_name = $app_strings['LBL_MULTIPLE'];
  2832. }
  2833. //Raju -- Ends
  2834. if ($module == 'HelpDesk' && ($parent_module == 'Accounts' || $parent_module == 'Contacts')) {
  2835. global $theme;
  2836. $module_icon = '<img src="themes/images/' . $parent_module . '.gif" alt="' . $app_strings[$parent_module] . '" title="' . $app_strings[$parent_module] . '" border=0 align=center> ';
  2837. }
  2838. $action = "DetailView";
  2839. if ($parent_module == 'Accounts') {
  2840. $parent_query = "SELECT accountname FROM vtiger_account WHERE accountid=?";
  2841. $parent_result = $adb->pquery($parent_query, array($parent_id));
  2842. $parent_name = textlength_check($adb->query_result($parent_result, 0, "accountname"));
  2843. }
  2844. if ($parent_module == 'Leads') {
  2845. $parent_query = "SELECT firstname,lastname FROM vtiger_leaddetails WHERE leadid=?";
  2846. $parent_result = $adb->pquery($parent_query, array($parent_id));
  2847. $parent_name = getFullNameFromQResult($parent_result, 0, "Leads");
  2848. }
  2849. if ($parent_module == 'Potentials') {
  2850. $parent_query = "SELECT potentialname FROM vtiger_potential WHERE potentialid=?";
  2851. $parent_result = $adb->pquery($parent_query, array($parent_id));
  2852. $parent_name = textlength_check($adb->query_result($parent_result, 0, "potentialname"));
  2853. }
  2854. if ($parent_module == 'Products') {
  2855. $parent_query = "SELECT productname FROM vtiger_products WHERE productid=?";
  2856. $parent_result = $adb->pquery($parent_query, array($parent_id));
  2857. $parent_name = $adb->query_result($parent_result, 0, "productname");
  2858. }
  2859. if ($parent_module == 'Quotes') {
  2860. $parent_query = "SELECT subject FROM vtiger_quotes WHERE quoteid=?";
  2861. $parent_result = $adb->pquery($parent_query, array($parent_id));
  2862. $parent_name = $adb->query_result($parent_result, 0, "subject");
  2863. }
  2864. if ($parent_module == 'PurchaseOrder') {
  2865. $parent_query = "SELECT subject FROM vtiger_purchaseorder WHERE purchaseorderid=?";
  2866. $parent_result = $adb->pquery($parent_query, array($parent_id));
  2867. $parent_name = $adb->query_result($parent_result, 0, "subject");
  2868. }
  2869. if ($parent_module == 'Invoice') {
  2870. $parent_query = "SELECT subject FROM vtiger_invoice WHERE invoiceid=?";
  2871. $parent_result = $adb->pquery($parent_query, array($parent_id));
  2872. $parent_name = $adb->query_result($parent_result, 0, "subject");
  2873. }
  2874. if ($parent_module == 'SalesOrder') {
  2875. $parent_query = "SELECT subject FROM vtiger_salesorder WHERE salesorderid=?";
  2876. $parent_result = $adb->pquery($parent_query, array($parent_id));
  2877. $parent_name = $adb->query_result($parent_result, 0, "subject");
  2878. }
  2879. if ($parent_module == 'Contacts' && ($module == 'Emails' || $module == 'HelpDesk')) {
  2880. $parent_query = "SELECT firstname,lastname FROM vtiger_contactdetails WHERE contactid=?";
  2881. $parent_result = $adb->pquery($parent_query, array($parent_id));
  2882. $parent_name = getFullNameFromQResult($parent_result, 0, "Contacts");
  2883. }
  2884. if ($parent_module == 'Vendors' && ($module == 'Emails')) {
  2885. $parent_query = "SELECT vendorname FROM vtiger_vendor WHERE vendorid=?";
  2886. $parent_result = $adb->pquery($parent_query, array($parent_id));
  2887. $parent_name = $adb->query_result($parent_result, 0, "vendorname");
  2888. }
  2889. if ($parent_module == 'HelpDesk') {
  2890. $parent_query = "SELECT title FROM vtiger_troubletickets WHERE ticketid=?";
  2891. $parent_result = $adb->pquery($parent_query, array($parent_id));
  2892. $parent_name = $adb->query_result($parent_result, 0, "title");
  2893. //if(strlen($parent_name) > 25)
  2894. //{
  2895. $parent_name = textlength_check($parent_name);
  2896. //}
  2897. }
  2898. if ($parent_module == 'Campaigns') {
  2899. $parent_query = "SELECT campaignname FROM vtiger_campaign WHERE campaignid=?";
  2900. $parent_result = $adb->pquery($parent_query, array($parent_id));
  2901. $parent_name = $adb->query_result($parent_result, 0, "campaignname");
  2902. //if(strlen($parent_name) > 25)
  2903. //{
  2904. $parent_name = textlength_check($parent_name);
  2905. //}
  2906. }
  2907. //added by rdhital for better emails - Raju
  2908. if ($parent_module == 'Multiple') {
  2909. $parent_value = $parent_name;
  2910. } else {
  2911. $parent_value = $module_icon . "<a href='index.php?module=" . $parent_module . "&action=" . $action . "&record=" . $parent_id . "&parenttab=" . $tabname . "'>" . textlength_check($parent_name) . "</a>";
  2912. }
  2913. //code added by raju ends
  2914. $log->debug("Exiting getRelatedTo method ...");
  2915. return $parent_value;
  2916. }
  2917. /* * Function to get the table headers for a listview
  2918. * Param $navigation_arrray - navigation values in array
  2919. * Param $url_qry - url string
  2920. * Param $module - module name
  2921. * Param $action- action file name
  2922. * Param $viewid - view id
  2923. * Returns an string value
  2924. */
  2925. function getTableHeaderNavigation($navigation_array, $url_qry, $module = '', $action_val = 'index', $viewid = '') {
  2926. global $log, $app_strings;
  2927. $log->debug("Entering getTableHeaderNavigation(" . $navigation_array . "," . $url_qry . "," . $module . "," . $action_val . "," . $viewid . ") method ...");
  2928. global $theme, $current_user;
  2929. $theme_path = "themes/" . $theme . "/";
  2930. $image_path = $theme_path . "images/";
  2931. if ($module == 'Documents') {
  2932. $output = '<td class="mailSubHeader" width="100%" align="center">';
  2933. } else {
  2934. $output = '<td align="right" style="padding: 5px;">';
  2935. }
  2936. $tabname = getParentTab();
  2937. $url_string = '';
  2938. // vtlib Customization : For uitype 10 popup during paging
  2939. if ($_REQUEST['form'] == 'vtlibPopupView') {
  2940. $url_string .= '&form=vtlibPopupView&forfield=' . vtlib_purify($_REQUEST['forfield']) . '&srcmodule=' . vtlib_purify($_REQUEST['srcmodule']) . '&forrecord=' . vtlib_purify($_REQUEST['forrecord']);
  2941. }
  2942. // END
  2943. if ($module == 'Calendar' && $action_val == 'index') {
  2944. if ($_REQUEST['view'] == '') {
  2945. if ($current_user->activity_view == "This Year") {
  2946. $mysel = 'year';
  2947. } else if ($current_user->activity_view == "This Month") {
  2948. $mysel = 'month';
  2949. } else if ($current_user->activity_view == "This Week") {
  2950. $mysel = 'week';
  2951. } else {
  2952. $mysel = 'day';
  2953. }
  2954. }
  2955. $data_value = date('Y-m-d H:i:s');
  2956. preg_match('/(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/', $data_value, $value);
  2957. $date_data = Array(
  2958. 'day' => $value[3],
  2959. 'month' => $value[2],
  2960. 'year' => $value[1],
  2961. 'hour' => $value[4],
  2962. 'min' => $value[5],
  2963. );
  2964. $tab_type = ($_REQUEST['subtab'] == '') ? 'event' : vtlib_purify($_REQUEST['subtab']);
  2965. $url_string .= isset($_REQUEST['view']) ? "&view=" . vtlib_purify($_REQUEST['view']) : "&view=" . $mysel;
  2966. $url_string .= isset($_REQUEST['subtab']) ? "&subtab=" . vtlib_purify($_REQUEST['subtab']) : '';
  2967. $url_string .= isset($_REQUEST['viewOption']) ? "&viewOption=" . vtlib_purify($_REQUEST['viewOption']) : '&viewOption=listview';
  2968. $url_string .= isset($_REQUEST['day']) ? "&day=" . vtlib_purify($_REQUEST['day']) : '&day=' . $date_data['day'];
  2969. $url_string .= isset($_REQUEST['week']) ? "&week=" . vtlib_purify($_REQUEST['week']) : '';
  2970. $url_string .= isset($_REQUEST['month']) ? "&month=" . vtlib_purify($_REQUEST['month']) : '&month=' . $date_data['month'];
  2971. $url_string .= isset($_REQUEST['year']) ? "&year=" . vtlib_purify($_REQUEST['year']) : "&year=" . $date_data['year'];
  2972. $url_string .= isset($_REQUEST['n_type']) ? "&n_type=" . vtlib_purify($_REQUEST['n_type']) : '';
  2973. $url_string .= isset($_REQUEST['search_option']) ? "&search_option=" . vtlib_purify($_REQUEST['search_option']) : '';
  2974. }
  2975. if ($module == 'Calendar' && $action_val != 'index') //added for the All link from the homepage -- ticket 5211
  2976. $url_string .= isset($_REQUEST['from_homepage']) ? "&from_homepage=" . vtlib_purify($_REQUEST['from_homepage']) : '';
  2977. if (($navigation_array['prev']) != 0) {
  2978. if ($module == 'Calendar' && $action_val == 'index') {
  2979. //$output .= '<a href="index.php?module=Calendar&action=index&start=1'.$url_string.'" alt="'.$app_strings['LBL_FIRST'].'" title="'.$app_strings['LBL_FIRST'].'"><img src="themes/images/start.gif" border="0" align="absmiddle"></a>&nbsp;';
  2980. $output .= '<a href="javascript:;" onClick="cal_navigation(\'' . $tab_type . '\',\'' . $url_string . '\',\'&start=1\');" alt="' . $app_strings['LBL_FIRST'] . '" title="' . $app_strings['LBL_FIRST'] . '"><img src="' . vtiger_imageurl('start.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  2981. //$output .= '<a href="index.php?module=Calendar&action=index&start='.$navigation_array['prev'].$url_string.'" alt="'.$app_strings['LNK_LIST_PREVIOUS'].'"title="'.$app_strings['LNK_LIST_PREVIOUS'].'"><img src="themes/images/previous.gif" border="0" align="absmiddle"></a>&nbsp;';
  2982. $output .= '<a href="javascript:;" onClick="cal_navigation(\'' . $tab_type . '\',\'' . $url_string . '\',\'&start=' . $navigation_array['prev'] . '\');" alt="' . $app_strings['LBL_FIRST'] . '" title="' . $app_strings['LBL_FIRST'] . '"><img src="' . vtiger_imageurl('start.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  2983. } else if ($action_val == "FindDuplicate") {
  2984. $output .= '<a href="javascript:;" onClick="getDuplicateListViewEntries_js(\'' . $module . '\',\'parenttab=' . $tabname . '&start=1' . $url_string . '\');" alt="' . $app_strings['LBL_FIRST'] . '" title="' . $app_strings['LBL_FIRST'] . '"><img src="' . vtiger_imageurl('start.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  2985. $output .= '<a href="javascript:;" onClick="getDuplicateListViewEntries_js(\'' . $module . '\',\'parenttab=' . $tabname . '&start=' . $navigation_array['prev'] . $url_string . '\');" alt="' . $app_strings['LNK_LIST_PREVIOUS'] . '"title="' . $app_strings['LNK_LIST_PREVIOUS'] . '"><img src="' . vtiger_imageurl('previous.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  2986. } elseif ($action_val == 'UnifiedSearch') {
  2987. $output .= '<a href="javascript:;" onClick="getUnifiedSearchEntries_js(\'' . $search_tag . '\',\'' . $module . '\',\'parenttab=' . $tabname . '&start=1' . $url_string . '\');" alt="' . $app_strings['LBL_FIRST'] . '" title="' . $app_strings['LBL_FIRST'] . '"><img src="' . vtiger_imageurl('start.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  2988. $output .= '<a href="javascript:;" onClick="getUnifiedSearchEntries_js(\'' . $search_tag . '\',\'' . $module . '\',\'parenttab=' . $tabname . '&start=' . $navigation_array['prev'] . $url_string . '\');" alt="' . $app_strings['LNK_LIST_PREVIOUS'] . '"title="' . $app_strings['LNK_LIST_PREVIOUS'] . '"><img src="' . vtiger_imageurl('previous.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  2989. } elseif ($module == 'Documents') {
  2990. $output .= '<a href="javascript:;" onClick="getListViewEntries_js(\'' . $module . '\',\'parenttab=' . $tabname . '&start=1' . $url_string . '\');" alt="' . $app_strings['LBL_FIRST'] . '" title="' . $app_strings['LBL_FIRST'] . '"><img src="' . vtiger_imageurl('start.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  2991. $output .= '<a href="javascript:;" onClick="getListViewEntries_js(\'' . $module . '\',\'parenttab=' . $tabname . '&start=' . $navigation_array['prev'] . $url_string . '&folderid=' . $action_val . '\');" alt="' . $app_strings['LNK_LIST_PREVIOUS'] . '"title="' . $app_strings['LNK_LIST_PREVIOUS'] . '"><img src="' . vtiger_imageurl('previous.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  2992. } else {
  2993. $output .= '<a href="javascript:;" onClick="getListViewEntries_js(\'' . $module . '\',\'parenttab=' . $tabname . '&start=1' . $url_string . '\');" alt="' . $app_strings['LBL_FIRST'] . '" title="' . $app_strings['LBL_FIRST'] . '"><img src="' . vtiger_imageurl('start.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  2994. $output .= '<a href="javascript:;" onClick="getListViewEntries_js(\'' . $module . '\',\'parenttab=' . $tabname . '&start=' . $navigation_array['prev'] . $url_string . '\');" alt="' . $app_strings['LNK_LIST_PREVIOUS'] . '"title="' . $app_strings['LNK_LIST_PREVIOUS'] . '"><img src="' . vtiger_imageurl('previous.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  2995. }
  2996. } else {
  2997. $output .= '<img src="' . vtiger_imageurl('start_disabled.gif', $theme) . '" border="0" align="absmiddle">&nbsp;';
  2998. $output .= '<img src="' . vtiger_imageurl('previous_disabled.gif', $theme) . '" border="0" align="absmiddle">&nbsp;';
  2999. }
  3000. if ($module == 'Calendar' && $action_val == 'index') {
  3001. $jsNavigate = "cal_navigation('$tab_type','$url_string','&start='+this.value);";
  3002. } else if ($action_val == "FindDuplicate") {
  3003. $jsNavigate = "getDuplicateListViewEntries_js('$module','parenttab=$tabname&start='+this.value+'$url_string');";
  3004. } elseif ($action_val == 'UnifiedSearch') {
  3005. $jsNavigate = "getUnifiedSearchEntries_js('$module','parenttab=$tabname&start='+this.value+'$url_string');";
  3006. } elseif ($module == 'Documents') {
  3007. $jsNavigate = "getListViewEntries_js('$module','parenttab=$tabname&start='+this.value+'$url_string&folderid=$action_val');";
  3008. } else {
  3009. $jsNavigate = "getListViewEntries_js('$module','parenttab=$tabname&start='+this.value+'$url_string');";
  3010. }
  3011. if ($module == 'Documents') {
  3012. $url = '&folderid=' . $action_val;
  3013. } else {
  3014. $url = '';
  3015. }
  3016. $jsHandler = "return VT_disableFormSubmit(event);";
  3017. $output .= "<input class='small' name='pagenum' type='text' value='{$navigation_array['current']}'
  3018. style='width: 3em;margin-right: 0.7em;' onchange=\"$jsNavigate\"
  3019. onkeypress=\"$jsHandler\">";
  3020. $output .= "<span name='" . $module . "_listViewCountContainerName' class='small' style='white-space: nowrap;'>";
  3021. $output .= $app_strings['LBL_LIST_OF'] . ' ' . $navigation_array['verylast'] . '</span>';
  3022. if (($navigation_array['next']) != 0) {
  3023. if ($module == 'Calendar' && $action_val == 'index') {
  3024. //$output .= '<a href="index.php?module=Calendar&action=index&start='.$navigation_array['next'].$url_string.'" alt="'.$app_strings['LNK_LIST_NEXT'].'" title="'.$app_strings['LNK_LIST_NEXT'].'"><img src="themes/images/next.gif" border="0" align="absmiddle"></a>&nbsp;';
  3025. $output .= '<a href="javascript:;" onClick="cal_navigation(\'' . $tab_type . '\',\'' . $url_string . '\',\'&start=' . $navigation_array['next'] . '\');" alt="' . $app_strings['LNK_LIST_NEXT'] . '" title="' . $app_strings['LNK_LIST_NEXT'] . '"><img src="' . vtiger_imageurl('next.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  3026. //$output .= '<a href="index.php?module=Calendar&action=index&start='.$navigation_array['verylast'].$url_string.'" alt="'.$app_strings['LBL_LAST'].'" title="'.$app_strings['LBL_LAST'].'"><img src="themes/images/end.gif" border="0" align="absmiddle"></a>&nbsp;';
  3027. $output .= '<a href="javascript:;" onClick="cal_navigation(\'' . $tab_type . '\',\'' . $url_string . '\',\'&start=' . $navigation_array['verylast'] . '\');" alt="' . $app_strings['LBL_LAST'] . '" title="' . $app_strings['LBL_LAST'] . '"><img src="' . vtiger_imageurl('end.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  3028. } else if ($action_val == "FindDuplicate") {
  3029. $output .= '<a href="javascript:;" onClick="getDuplicateListViewEntries_js(\'' . $module . '\',\'parenttab=' . $tabname . '&start=' . $navigation_array['next'] . $url_string . '\');" alt="' . $app_strings['LNK_LIST_NEXT'] . '" title="' . $app_strings['LNK_LIST_NEXT'] . '"><img src="' . vtiger_imageurl('next.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  3030. $output .= '<a href="javascript:;" onClick="getDuplicateListViewEntries_js(\'' . $module . '\',\'parenttab=' . $tabname . '&start=' . $navigation_array['verylast'] . $url_string . '\');" alt="' . $app_strings['LBL_LAST'] . '" title="' . $app_strings['LBL_LAST'] . '"><img src="' . vtiger_imageurl('end.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  3031. } elseif ($action_val == 'UnifiedSearch') {
  3032. $output .= '<a href="javascript:;" onClick="getUnifiedSearchEntries_js(\'' . $search_tag . '\',\'' . $module . '\',\'parenttab=' . $tabname . '&start=' . $navigation_array['next'] . $url_string . '\');" alt="' . $app_strings['LNK_LIST_NEXT'] . '" title="' . $app_strings['LNK_LIST_NEXT'] . '"><img src="' . vtiger_imageurl('next.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  3033. $output .= '<a href="javascript:;" onClick="getUnifiedSearchEntries_js(\'' . $search_tag . '\',\'' . $module . '\',\'parenttab=' . $tabname . '&start=' . $navigation_array['verylast'] . $url_string . '\');" alt="' . $app_strings['LBL_LAST'] . '" title="' . $app_strings['LBL_LAST'] . '"><img src="themes/images/end.gif" border="0" align="absmiddle"></a>&nbsp;';
  3034. } elseif ($module == 'Documents') {
  3035. $output .= '<a href="javascript:;" onClick="getListViewEntries_js(\'' . $module . '\',\'parenttab=' . $tabname . '&start=' . $navigation_array['next'] . $url_string . '&folderid=' . $action_val . '\');" alt="' . $app_strings['LNK_LIST_NEXT'] . '" title="' . $app_strings['LNK_LIST_NEXT'] . '"><img src="' . vtiger_imageurl('next.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  3036. $output .= '<a href="javascript:;" onClick="getListViewEntries_js(\'' . $module . '\',\'parenttab=' . $tabname . '&start=' . $navigation_array['verylast'] . $url_string . '&folderid=' . $action_val . '\');" alt="' . $app_strings['LBL_LAST'] . '" title="' . $app_strings['LBL_LAST'] . '"><img src="' . vtiger_imageurl('end.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  3037. } else {
  3038. $output .= '<a href="javascript:;" onClick="getListViewEntries_js(\'' . $module . '\',\'parenttab=' . $tabname . '&start=' . $navigation_array['next'] . $url_string . '\');" alt="' . $app_strings['LNK_LIST_NEXT'] . '" title="' . $app_strings['LNK_LIST_NEXT'] . '"><img src="' . vtiger_imageurl('next.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  3039. $output .= '<a href="javascript:;" onClick="getListViewEntries_js(\'' . $module . '\',\'parenttab=' . $tabname . '&start=' . $navigation_array['verylast'] . $url_string . '\');" alt="' . $app_strings['LBL_LAST'] . '" title="' . $app_strings['LBL_LAST'] . '"><img src="' . vtiger_imageurl('end.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  3040. }
  3041. } else {
  3042. $output .= '<img src="' . vtiger_imageurl('next_disabled.gif', $theme) . '" border="0" align="absmiddle">&nbsp;';
  3043. $output .= '<img src="' . vtiger_imageurl('end_disabled.gif', $theme) . '" border="0" align="absmiddle">&nbsp;';
  3044. }
  3045. $output .= '</td>';
  3046. $log->debug("Exiting getTableHeaderNavigation method ...");
  3047. if ($navigation_array['first'] == '')
  3048. return;
  3049. else
  3050. return $output;
  3051. }
  3052. function getPopupCheckquery($current_module, $relmodule, $relmod_recordid) {
  3053. global $log, $adb;
  3054. $log->debug("Entering getPopupCheckquery(" . $current_module . "," . $relmodule . "," . $relmod_recordid . ") method ...");
  3055. if ($current_module == "Contacts") {
  3056. if ($relmodule == "Accounts" && $relmod_recordid != '')
  3057. $condition = "and vtiger_account.accountid= " . $relmod_recordid;
  3058. elseif ($relmodule == "Potentials") {
  3059. $query = "select contactid from vtiger_contpotentialrel where potentialid=?";
  3060. $result = $adb->pquery($query, array($relmod_recordid));
  3061. $contact_id = $adb->query_result($result, 0, "contactid");
  3062. if ($contact_id != '' && $contact_id != 0)
  3063. $condition = "and vtiger_contactdetails.contactid= " . $contact_id;
  3064. else {
  3065. $query = "select related_to from vtiger_potential where potentialid=?";
  3066. $result = $adb->pquery($query, array($relmod_recordid));
  3067. $acc_id = $adb->query_result($result, 0, "related_to");
  3068. if ($acc_id != '') {
  3069. $condition = "and vtiger_contactdetails.accountid= " . $acc_id;
  3070. }
  3071. }
  3072. } elseif ($relmodule == "Quotes") {
  3073. $query = "select accountid,contactid from vtiger_quotes where quoteid=?";
  3074. $result = $adb->pquery($query, array($relmod_recordid));
  3075. $contactid = $adb->query_result($result, 0, "contactid");
  3076. if ($contactid != '' && $contactid != 0)
  3077. $condition = "and vtiger_contactdetails.contactid= " . $contactid;
  3078. else {
  3079. $account_id = $adb->query_result($result, 0, "accountid");
  3080. if ($account_id != '')
  3081. $condition = "and vtiger_contactdetails.accountid= " . $account_id;
  3082. }
  3083. }
  3084. elseif ($relmodule == "PurchaseOrder") {
  3085. $query = "select contactid from vtiger_purchaseorder where purchaseorderid=?";
  3086. $result = $adb->pquery($query, array($relmod_recordid));
  3087. $contact_id = $adb->query_result($result, 0, "contactid");
  3088. if ($contact_id != '')
  3089. $condition = "and vtiger_contactdetails.contactid= " . $contact_id;
  3090. else
  3091. $condition = "and vtiger_contactdetails.contactid= 0";
  3092. }
  3093. elseif ($relmodule == "SalesOrder") {
  3094. $query = "select accountid,contactid from vtiger_salesorder where salesorderid=?";
  3095. $result = $adb->pquery($query, array($relmod_recordid));
  3096. $contact_id = $adb->query_result($result, 0, "contactid");
  3097. if ($contact_id != 0 && $contact_id != '')
  3098. $condition = "and vtiger_contactdetails.contactid=" . $contact_id;
  3099. else {
  3100. $account_id = $adb->query_result($result, 0, "accountid");
  3101. if ($account_id != '')
  3102. $condition = "and vtiger_contactdetails.accountid= " . $account_id;
  3103. }
  3104. }
  3105. elseif ($relmodule == "Invoice") {
  3106. $query = "select accountid,contactid from vtiger_invoice where invoiceid=?";
  3107. $result = $adb->pquery($query, array($relmod_recordid));
  3108. $contact_id = $adb->query_result($result, 0, "contactid");
  3109. if ($contact_id != '' && $contact_id != 0)
  3110. $condition = " and vtiger_contactdetails.contactid=" . $contact_id;
  3111. else {
  3112. $account_id = $adb->query_result($result, 0, "accountid");
  3113. if ($account_id != '')
  3114. $condition = " and vtiger_contactdetails.accountid=" . $account_id;
  3115. }
  3116. }
  3117. elseif ($relmodule == "Campaigns") {
  3118. $query = "select contactid from vtiger_campaigncontrel where campaignid =?";
  3119. $result = $adb->pquery($query, array($relmod_recordid));
  3120. $rows = $adb->num_rows($result);
  3121. if ($rows != 0) {
  3122. $j = 0;
  3123. $contactid_comma = "(";
  3124. for ($k = 0; $k < $rows; $k++) {
  3125. $contactid = $adb->query_result($result, $k, 'contactid');
  3126. $contactid_comma.=$contactid;
  3127. if ($k < ($rows - 1))
  3128. $contactid_comma.=', ';
  3129. }
  3130. $contactid_comma.= ")";
  3131. }
  3132. else
  3133. $contactid_comma = "(0)";
  3134. $condition = "and vtiger_contactdetails.contactid in " . $contactid_comma;
  3135. }
  3136. elseif ($relmodule == "Products") {
  3137. $query = "select crmid from vtiger_seproductsrel where productid=? and setype=?";
  3138. $result = $adb->pquery($query, array($relmod_recordid, "Contacts"));
  3139. $rows = $adb->num_rows($result);
  3140. if ($rows != 0) {
  3141. $j = 0;
  3142. $contactid_comma = "(";
  3143. for ($k = 0; $k < $rows; $k++) {
  3144. $contactid = $adb->query_result($result, $k, 'crmid');
  3145. $contactid_comma.=$contactid;
  3146. if ($k < ($rows - 1))
  3147. $contactid_comma.=', ';
  3148. }
  3149. $contactid_comma.= ")";
  3150. }
  3151. else
  3152. $contactid_comma = "(0)";
  3153. $condition = "and vtiger_contactdetails.contactid in " . $contactid_comma;
  3154. }
  3155. elseif ($relmodule == "HelpDesk" || $relmodule == "Trouble Tickets") {
  3156. $query = "select parent_id from vtiger_troubletickets where ticketid =?";
  3157. $result = $adb->pquery($query, array($relmod_recordid));
  3158. $parent_id = $adb->query_result($result, 0, "parent_id");
  3159. if ($parent_id != "") {
  3160. $crmquery = "select setype from vtiger_crmentity where crmid=?";
  3161. $parentmodule_id = $adb->pquery($crmquery, array($parent_id));
  3162. $parent_modname = $adb->query_result($parentmodule_id, 0, "setype");
  3163. if ($parent_modname == "Accounts")
  3164. $condition = "and vtiger_contactdetails.accountid= " . $parent_id;
  3165. if ($parent_modname == "Contacts")
  3166. $condition = "and vtiger_contactdetails.contactid= " . $parent_id;
  3167. }
  3168. else
  3169. $condition = " and vtiger_contactdetails.contactid=0";
  3170. }
  3171. }
  3172. elseif ($current_module == "Potentials") {
  3173. if ($relmodule == 'Accounts' || $relmodule == 'Contacts') {
  3174. if ($relmodule == 'Contacts') {
  3175. $pot_query = "select vtiger_crmentity.crmid,vtiger_contactdetails.contactid,vtiger_potential.potentialid from vtiger_potential inner join vtiger_contactdetails on vtiger_contactdetails.contactid=vtiger_potential.related_to inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_contactdetails.contactid where vtiger_crmentity.deleted=0 and vtiger_potential.related_to=?";
  3176. } else {
  3177. $pot_query = "select vtiger_crmentity.crmid,vtiger_account.accountid,vtiger_potential.potentialid from vtiger_potential inner join vtiger_account on vtiger_account.accountid=vtiger_potential.related_to inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_account.accountid where vtiger_crmentity.deleted=0 and vtiger_potential.related_to=?";
  3178. }
  3179. $pot_result = $result = $adb->pquery($pot_query, array($relmod_recordid));
  3180. $rows = $adb->num_rows($pot_result);
  3181. $potids_comma = "";
  3182. if ($rows != 0) {
  3183. $j = 0;
  3184. $potids_comma .= "(";
  3185. for ($k = 0; $k < $rows; $k++) {
  3186. $potential_ids = $adb->query_result($pot_result, $k, 'potentialid');
  3187. $potids_comma.=$potential_ids;
  3188. if ($k < ($rows - 1))
  3189. $potids_comma.=',';
  3190. }
  3191. $potids_comma.= ")";
  3192. }
  3193. else
  3194. $potids_comma = "(0)";
  3195. $condition = "and vtiger_potential.potentialid in " . $potids_comma;
  3196. }
  3197. }
  3198. else if ($current_module == "Products") {
  3199. if ($relmodule == 'Accounts') {
  3200. $pro_query = "select productid from vtiger_seproductsrel where setype='Accounts' and crmid=?";
  3201. $pro_result = $result = $adb->pquery($pro_query, array($relmod_recordid));
  3202. $rows = $adb->num_rows($pro_result);
  3203. if ($rows != 0) {
  3204. $proids_comma = "(";
  3205. for ($k = 0; $k < $rows; $k++) {
  3206. $product_ids = $adb->query_result($pro_result, $k, 'productid');
  3207. $proids_comma .= $product_ids;
  3208. if ($k < ($rows - 1))
  3209. $proids_comma.=',';
  3210. }
  3211. $proids_comma.= ")";
  3212. }
  3213. else
  3214. $proids_comma = "(0)";
  3215. $condition = "and vtiger_products.productid in " . $proids_comma;
  3216. }
  3217. if ($relmodule == 'Vendor' && $relmod_recordid != '')
  3218. $condition = "and vtiger_vendor.vendorid= " . $relmod_recordid;
  3219. }
  3220. else if ($current_module == 'Quotes') {
  3221. if ($relmodule == 'Accounts') {
  3222. $quote_query = "select quoteid from vtiger_quotes where accountid=?";
  3223. $quote_result = $result = $adb->pquery($quote_query, array($relmod_recordid));
  3224. $rows = $adb->num_rows($quote_result);
  3225. if ($rows != 0) {
  3226. $j = 0;
  3227. $qtids_comma = "(";
  3228. for ($k = 0; $k < $rows; $k++) {
  3229. $quote_ids = $adb->query_result($quote_result, $k, 'quoteid');
  3230. $qtids_comma.=$quote_ids;
  3231. if ($k < ($rows - 1))
  3232. $qtids_comma.=',';
  3233. }
  3234. $qtids_comma.= ")";
  3235. }
  3236. else
  3237. $qtids_comma = "(0)";
  3238. $condition = "and vtiger_quotes.quoteid in " . $qtids_comma;
  3239. }
  3240. }
  3241. else if ($current_module == 'SalesOrder') {
  3242. if ($relmodule == 'Accounts') {
  3243. $SO_query = "select salesorderid from vtiger_salesorder where accountid=?";
  3244. $SO_result = $result = $adb->pquery($SO_query, array($relmod_recordid));
  3245. $rows = $adb->num_rows($SO_result);
  3246. if ($rows != 0) {
  3247. $SOids_comma = "(";
  3248. for ($k = 0; $k < $rows; $k++) {
  3249. $SO_ids = $adb->query_result($SO_result, $k, 'salesorderid');
  3250. $SOids_comma.=$SO_ids;
  3251. if ($k < ($rows - 1))
  3252. $SOids_comma.=',';
  3253. }
  3254. $SOids_comma.= ")";
  3255. }
  3256. else
  3257. $SOids_comma = "(0)";
  3258. $condition = "and vtiger_salesorder.salesorderid in " . $SOids_comma;
  3259. }
  3260. }
  3261. else
  3262. $condition = '';
  3263. $where = $condition;
  3264. $log->debug("Exiting getPopupCheckquery method ...");
  3265. return $where;
  3266. }
  3267. /* * This function return the entity ids that need to be excluded in popup listview for a given record
  3268. Param $currentmodule - modulename of the entity to be selected
  3269. Param $returnmodule - modulename for which the entity is assingned
  3270. Param $recordid - the record id for which the entity is assigned
  3271. Return type string.
  3272. */
  3273. function getRelCheckquery($currentmodule, $returnmodule, $recordid) {
  3274. global $log, $adb;
  3275. $log->debug("Entering getRelCheckquery(" . $currentmodule . "," . $returnmodule . "," . $recordid . ") method ...");
  3276. $skip_id = Array();
  3277. $where_relquery = "";
  3278. $params = array();
  3279. if ($currentmodule == "Contacts" && $returnmodule == "Potentials") {
  3280. $reltable = 'vtiger_contpotentialrel';
  3281. $condition = 'WHERE potentialid = ?';
  3282. array_push($params, $recordid);
  3283. $field = $selectfield = 'contactid';
  3284. $table = 'vtiger_contactdetails';
  3285. } elseif ($currentmodule == "Contacts" && $returnmodule == "Vendors") {
  3286. $reltable = 'vtiger_vendorcontactrel';
  3287. $condition = 'WHERE vendorid = ?';
  3288. array_push($params, $recordid);
  3289. $field = $selectfield = 'contactid';
  3290. $table = 'vtiger_contactdetails';
  3291. } elseif ($currentmodule == "Contacts" && $returnmodule == "Campaigns") {
  3292. $reltable = 'vtiger_campaigncontrel';
  3293. $condition = 'WHERE campaignid = ?';
  3294. array_push($params, $recordid);
  3295. $field = $selectfield = 'contactid';
  3296. $table = 'vtiger_contactdetails';
  3297. } elseif ($currentmodule == "Contacts" && $returnmodule == "Calendar") {
  3298. $reltable = 'vtiger_cntactivityrel';
  3299. $condition = 'WHERE activityid = ?';
  3300. array_push($params, $recordid);
  3301. $field = $selectfield = 'contactid';
  3302. $table = 'vtiger_contactdetails';
  3303. } elseif ($currentmodule == "Leads" && $returnmodule == "Campaigns") {
  3304. $reltable = 'vtiger_campaignleadrel';
  3305. $condition = 'WHERE campaignid = ?';
  3306. array_push($params, $recordid);
  3307. $field = $selectfield = 'leadid';
  3308. $table = 'vtiger_leaddetails';
  3309. } elseif ($currentmodule == "Users" && $returnmodule == "Calendar") {
  3310. $reltable = 'vtiger_salesmanactivityrel';
  3311. $condition = 'WHERE activityid = ?';
  3312. array_push($params, $recordid);
  3313. $selectfield = 'smid';
  3314. $field = 'id';
  3315. $table = 'vtiger_users';
  3316. } elseif ($currentmodule == "Campaigns" && $returnmodule == "Leads") {
  3317. $reltable = 'vtiger_campaignleadrel';
  3318. $condition = 'WHERE leadid = ?';
  3319. array_push($params, $recordid);
  3320. $field = $selectfield = 'campaignid';
  3321. $table = 'vtiger_campaign';
  3322. } elseif ($currentmodule == "Campaigns" && $returnmodule == "Contacts") {
  3323. $reltable = 'vtiger_campaigncontrel';
  3324. $condition = 'WHERE contactid = ?';
  3325. array_push($params, $recordid);
  3326. $field = $selectfield = 'campaignid';
  3327. $table = 'vtiger_campaign';
  3328. } elseif ($currentmodule == "Products" && ($returnmodule == "Potentials" || $returnmodule == "Accounts" || $returnmodule == "Contacts" || $returnmodule == "Leads")) {
  3329. $reltable = 'vtiger_seproductsrel';
  3330. $condition = 'WHERE crmid = ? and setype = ?';
  3331. array_push($params, $recordid, $returnmodule);
  3332. $field = $selectfield = 'productid';
  3333. $table = 'vtiger_products';
  3334. } elseif (($currentmodule == "Leads" || $currentmodule == "Accounts" || $currentmodule == "Potentials" || $currentmodule == "Contacts") && $returnmodule == "Products") {//added to fix the issues(ticket 4001,4002 and 4003)
  3335. $reltable = 'vtiger_seproductsrel';
  3336. $condition = 'WHERE productid = ? and setype = ?';
  3337. array_push($params, $recordid, $currentmodule);
  3338. $selectfield = 'crmid';
  3339. if ($currentmodule == "Leads") {
  3340. $field = 'leadid';
  3341. $table = 'vtiger_leaddetails';
  3342. } elseif ($currentmodule == "Accounts") {
  3343. $field = 'accountid';
  3344. $table = 'vtiger_account';
  3345. } elseif ($currentmodule == "Contacts") {
  3346. $field = 'contactid';
  3347. $table = 'vtiger_contactdetails';
  3348. } elseif ($currentmodule == "Potentials") {
  3349. $field = 'potentialid';
  3350. $table = 'vtiger_potential';
  3351. }
  3352. } elseif ($currentmodule == "Products" && $returnmodule == "Vendors") {
  3353. $reltable = 'vtiger_products';
  3354. $condition = 'WHERE vendor_id = ?';
  3355. array_push($params, $recordid);
  3356. $field = $selectfield = 'productid';
  3357. $table = 'vtiger_products';
  3358. } elseif ($currentmodule == "Documents") {
  3359. $reltable = "vtiger_senotesrel";
  3360. $selectfield = "notesid";
  3361. $condition = "where crmid = ?";
  3362. array_push($params, $recordid);
  3363. $table = "vtiger_notes";
  3364. $field = "notesid";
  3365. }
  3366. //end
  3367. if ($reltable != null) {
  3368. $query = "SELECT " . $selectfield . " FROM " . $reltable . " " . $condition;
  3369. } elseif ($currentmodule != $returnmodule && $returnmodule != "") { // If none of the above relation matches, then the relation is assumed to be stored in vtiger_crmentityrel
  3370. $query = "SELECT relcrmid AS relatedid FROM vtiger_crmentityrel WHERE crmid = ? and module = ? and relmodule = ?
  3371. UNION SELECT crmid AS relatedid FROM vtiger_crmentityrel WHERE relcrmid = ? and relmodule = ? and module = ?";
  3372. array_push($params, $recordid, $returnmodule, $currentmodule, $recordid, $returnmodule, $currentmodule);
  3373. $focus_obj = CRMEntity::getInstance($currentmodule);
  3374. $field = $focus_obj->table_index;
  3375. $table = $focus_obj->table_name;
  3376. $selectfield = 'relatedid';
  3377. }
  3378. if ($query != '') {
  3379. $result = $adb->pquery($query, $params);
  3380. if ($adb->num_rows($result) != 0) {
  3381. for ($k = 0; $k < $adb->num_rows($result); $k++) {
  3382. $skip_id[] = $adb->query_result($result, $k, $selectfield);
  3383. }
  3384. $skipids = implode(",", constructList($skip_id, 'INTEGER'));
  3385. if (count($skipids) > 0) {
  3386. $where_relquery = "and " . $table . "." . $field . " not in (" . $skipids . ")";
  3387. }
  3388. }
  3389. }
  3390. $log->debug("Exiting getRelCheckquery method ...");
  3391. return $where_relquery;
  3392. }
  3393. /* * This function stores the variables in session sent in list view url string.
  3394. * Param $lv_array - list view session array
  3395. * Param $noofrows - no of rows
  3396. * Param $max_ent - maximum entires
  3397. * Param $module - module name
  3398. * Param $related - related module
  3399. * Return type void.
  3400. */
  3401. function setSessionVar($lv_array, $noofrows, $max_ent, $module = '', $related = '') {
  3402. $start = '';
  3403. if ($noofrows >= 1) {
  3404. $lv_array['start'] = 1;
  3405. $start = 1;
  3406. } elseif ($related != '' && $noofrows == 0) {
  3407. $lv_array['start'] = 1;
  3408. $start = 1;
  3409. } else {
  3410. $lv_array['start'] = 0;
  3411. $start = 0;
  3412. }
  3413. if (isset($_REQUEST['start']) && $_REQUEST['start'] != '') {
  3414. $lv_array['start'] = ListViewSession::getRequestStartPage();
  3415. $start = ListViewSession::getRequestStartPage();
  3416. } elseif ($_SESSION['rlvs'][$module][$related]['start'] != '') {
  3417. if ($related != '') {
  3418. $lv_array['start'] = $_SESSION['rlvs'][$module][$related]['start'];
  3419. $start = $_SESSION['rlvs'][$module][$related]['start'];
  3420. }
  3421. }
  3422. if (isset($_REQUEST['viewname']) && $_REQUEST['viewname'] != '')
  3423. $lv_array['viewname'] = vtlib_purify($_REQUEST['viewname']);
  3424. if ($related == '')
  3425. $_SESSION['lvs'][$_REQUEST['module']] = $lv_array;
  3426. else
  3427. $_SESSION['rlvs'][$module][$related] = $lv_array;
  3428. if ($start < ceil($noofrows / $max_ent) && $start != '') {
  3429. $start = ceil($noofrows / $max_ent);
  3430. if ($related == '')
  3431. $_SESSION['lvs'][$currentModule]['start'] = $start;
  3432. }
  3433. }
  3434. /* * Function to get the table headers for related listview
  3435. * Param $navigation_arrray - navigation values in array
  3436. * Param $url_qry - url string
  3437. * Param $module - module name
  3438. * Param $action- action file name
  3439. * Param $viewid - view id
  3440. * Returns an string value
  3441. */
  3442. function getRelatedTableHeaderNavigation($navigation_array, $url_qry, $module, $related_module, $recordid) {
  3443. global $log, $app_strings, $adb;
  3444. $log->debug("Entering getTableHeaderNavigation(" . $navigation_array . "," . $url_qry . "," . $module . "," . $action_val . "," . $viewid . ") method ...");
  3445. global $theme;
  3446. $relatedTabId = getTabid($related_module);
  3447. $tabid = getTabid($module);
  3448. $relatedListResult = $adb->pquery('SELECT * FROM vtiger_relatedlists WHERE tabid=? AND
  3449. related_tabid=?', array($tabid, $relatedTabId));
  3450. if (empty($relatedListResult))
  3451. return;
  3452. $relatedListRow = $adb->fetch_row($relatedListResult);
  3453. $header = $relatedListRow['label'];
  3454. $actions = $relatedListRow['actions'];
  3455. $functionName = $relatedListRow['name'];
  3456. $urldata = "module=$module&action={$module}Ajax&file=DetailViewAjax&record={$recordid}&" .
  3457. "ajxaction=LOADRELATEDLIST&header={$header}&relation_id={$relatedListRow['relation_id']}" .
  3458. "&actions={$actions}&{$url_qry}";
  3459. $formattedHeader = str_replace(' ', '', $header);
  3460. $target = 'tbl_' . $module . '_' . $formattedHeader;
  3461. $imagesuffix = $module . '_' . $formattedHeader;
  3462. $output = '<td align="right" style="padding="5px;">';
  3463. if (($navigation_array['prev']) != 0) {
  3464. $output .= '<a href="javascript:;" onClick="loadRelatedListBlock(\'' . $urldata . '&start=1\',\'' . $target . '\',\'' . $imagesuffix . '\');" alt="' . $app_strings['LBL_FIRST'] . '" title="' . $app_strings['LBL_FIRST'] . '"><img src="' . vtiger_imageurl('start.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  3465. $output .= '<a href="javascript:;" onClick="loadRelatedListBlock(\'' . $urldata . '&start=' . $navigation_array['prev'] . '\',\'' . $target . '\',\'' . $imagesuffix . '\');" alt="' . $app_strings['LNK_LIST_PREVIOUS'] . '"title="' . $app_strings['LNK_LIST_PREVIOUS'] . '"><img src="' . vtiger_imageurl('previous.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  3466. } else {
  3467. $output .= '<img src="' . vtiger_imageurl('start_disabled.gif', $theme) . '" border="0" align="absmiddle">&nbsp;';
  3468. $output .= '<img src="' . vtiger_imageurl('previous_disabled.gif', $theme) . '" border="0" align="absmiddle">&nbsp;';
  3469. }
  3470. $jsHandler = "return VT_disableFormSubmit(event);";
  3471. $output .= "<input class='small' name='pagenum' type='text' value='{$navigation_array['current']}'
  3472. style='width: 3em;margin-right: 0.7em;' onchange=\"loadRelatedListBlock('{$urldata}&start='+this.value+'','{$target}','{$imagesuffix}');\"
  3473. onkeypress=\"$jsHandler\">";
  3474. $output .= "<span name='listViewCountContainerName' class='small' style='white-space: nowrap;'>";
  3475. $computeCount = $_REQUEST['withCount'];
  3476. if (PerformancePrefs::getBoolean('LISTVIEW_COMPUTE_PAGE_COUNT', false) === true
  3477. || ((boolean) $computeCount) == true) {
  3478. $output .= $app_strings['LBL_LIST_OF'] . ' ' . $navigation_array['verylast'];
  3479. } else {
  3480. $output .= "<img src='" . vtiger_imageurl('windowRefresh.gif', $theme) . "' alt='" . $app_strings['LBL_HOME_COUNT'] . "'
  3481. onclick=\"loadRelatedListBlock('{$urldata}&withCount=true&start={$navigation_array['current']}','{$target}','{$imagesuffix}');\"
  3482. align='absmiddle' name='" . $module . "_listViewCountRefreshIcon'/>
  3483. <img name='" . $module . "_listViewCountContainerBusy' src='" . vtiger_imageurl('vtbusy.gif', $theme) . "' style='display: none;'
  3484. align='absmiddle' alt='" . $app_strings['LBL_LOADING'] . "'>";
  3485. }
  3486. $output .= '</span>';
  3487. if (($navigation_array['next']) != 0) {
  3488. $output .= '<a href="javascript:;" onClick="loadRelatedListBlock(\'' . $urldata . '&start=' . $navigation_array['next'] . '\',\'' . $target . '\',\'' . $imagesuffix . '\');"><img src="' . vtiger_imageurl('next.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  3489. $output .= '<a href="javascript:;" onClick="loadRelatedListBlock(\'' . $urldata . '&start=' . $navigation_array['verylast'] . '\',\'' . $target . '\',\'' . $imagesuffix . '\');"><img src="' . vtiger_imageurl('end.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  3490. } else {
  3491. $output .= '<img src="' . vtiger_imageurl('next_disabled.gif', $theme) . '" border="0" align="absmiddle">&nbsp;';
  3492. $output .= '<img src="' . vtiger_imageurl('end_disabled.gif', $theme) . '" border="0" align="absmiddle">&nbsp;';
  3493. }
  3494. $output .= '</td>';
  3495. $log->debug("Exiting getTableHeaderNavigation method ...");
  3496. if ($navigation_array['first'] == '')
  3497. return;
  3498. else
  3499. return $output;
  3500. }
  3501. /** Function to get the Edit link details for ListView and RelatedListView
  3502. * @param string $module - module name
  3503. * @param int $entity_id - record id
  3504. * @param string $relatedlist - string "relatedlist" or may be empty. if empty means ListView else relatedlist
  3505. * @param string $returnset - may be empty in case of ListView. For relatedlists, return_module, return_action and return_id values will be passed like &return_module=Accounts&return_action=CallRelatedList&return_id=10
  3506. * return string $edit_link - url string which cotains the editlink details (module, action, record, etc.,) like index.php?module=Accounts&action=EditView&record=10
  3507. */
  3508. function getListViewEditLink($module, $entity_id, $relatedlist, $returnset, $result, $count) {
  3509. global $adb;
  3510. $return_action = "index";
  3511. $edit_link = "index.php?module=$module&action=EditView&record=$entity_id";
  3512. $tabname = getParentTab();
  3513. //Added to fix 4600
  3514. $url = getBasic_Advance_SearchURL();
  3515. //This is relatedlist listview
  3516. if ($relatedlist == 'relatedlist') {
  3517. $edit_link .= $returnset;
  3518. } else {
  3519. if ($module == 'Calendar') {
  3520. $return_action = "ListView";
  3521. $actvity_type = $adb->query_result($result, $count, 'type');
  3522. if ($actvity_type == 'Task')
  3523. $edit_link .= '&activity_mode=Task';
  3524. else
  3525. $edit_link .= '&activity_mode=Events';
  3526. }
  3527. $edit_link .= "&return_module=$module&return_action=$return_action";
  3528. }
  3529. $edit_link .= "&parenttab=" . $tabname . $url;
  3530. //Appending view name while editing from ListView
  3531. $edit_link .= "&return_viewname=" . $_SESSION['lvs'][$module]["viewname"];
  3532. if ($module == 'Emails')
  3533. $edit_link = 'javascript:;" onclick="OpenCompose(\'' . $entity_id . '\',\'edit\');';
  3534. return $edit_link;
  3535. }
  3536. /** Function to get the Del link details for ListView and RelatedListView
  3537. * @param string $module - module name
  3538. * @param int $entity_id - record id
  3539. * @param string $relatedlist - string "relatedlist" or may be empty. if empty means ListView else relatedlist
  3540. * @param string $returnset - may be empty in case of ListView. For relatedlists, return_module, return_action and return_id values will be passed like &return_module=Accounts&return_action=CallRelatedList&return_id=10
  3541. * return string $del_link - url string which cotains the editlink details (module, action, record, etc.,) like index.php?module=Accounts&action=Delete&record=10
  3542. */
  3543. function getListViewDeleteLink($module, $entity_id, $relatedlist, $returnset) {
  3544. $tabname = getParentTab();
  3545. $current_module = vtlib_purify($_REQUEST['module']);
  3546. $viewname = $_SESSION['lvs'][$current_module]['viewname'];
  3547. //Added to fix 4600
  3548. $url = getBasic_Advance_SearchURL();
  3549. if ($module == "Calendar")
  3550. $return_action = "ListView";
  3551. else
  3552. $return_action = "index";
  3553. //This is added to avoid the del link in Product related list for the following modules
  3554. $avoid_del_links = Array("PurchaseOrder", "SalesOrder", "Quotes", "Invoice");
  3555. if (($current_module == 'Products' || $current_module == 'Services') && in_array($module, $avoid_del_links)) {
  3556. return '';
  3557. }
  3558. $del_link = "index.php?module=$module&action=Delete&record=$entity_id";
  3559. //This is added for relatedlist listview
  3560. if ($relatedlist == 'relatedlist') {
  3561. $del_link .= $returnset;
  3562. } else {
  3563. $del_link .= "&return_module=$module&return_action=$return_action";
  3564. }
  3565. $del_link .= "&parenttab=" . $tabname . "&return_viewname=" . $viewname . $url;
  3566. // vtlib customization: override default delete link for custom modules
  3567. $requestModule = vtlib_purify($_REQUEST['module']);
  3568. $requestRecord = vtlib_purify($_REQUEST['record']);
  3569. $requestAction = vtlib_purify($_REQUEST['action']);
  3570. $parenttab = vtlib_purify($_REQUEST['parenttab']);
  3571. $isCustomModule = vtlib_isCustomModule($requestModule);
  3572. if ($requestAction == $requestModule . "Ajax") {
  3573. $requestAction = vtlib_purify($_REQUEST['file']);
  3574. }
  3575. if ($isCustomModule && !in_array($requestAction, Array('index', 'ListView'))) {
  3576. $del_link = "index.php?module=$requestModule&action=updateRelations&parentid=$requestRecord";
  3577. $del_link .= "&destination_module=$module&idlist=$entity_id&mode=delete&parenttab=$parenttab";
  3578. }
  3579. // END
  3580. return $del_link;
  3581. }
  3582. /* Function to get the Entity Id of a given Entity Name */
  3583. function getEntityId($module, $entityName) {
  3584. global $log, $adb;
  3585. $log->info("in getEntityId " . $entityName);
  3586. $query = "select fieldname,tablename,entityidfield from vtiger_entityname where modulename = ?";
  3587. $result = $adb->pquery($query, array($module));
  3588. $fieldsname = $adb->query_result($result, 0, 'fieldname');
  3589. $tablename = $adb->query_result($result, 0, 'tablename');
  3590. $entityidfield = $adb->query_result($result, 0, 'entityidfield');
  3591. if (!(strpos($fieldsname, ',') === false)) {
  3592. $fieldlists = explode(',', $fieldsname);
  3593. $fieldsname = "concat(";
  3594. $fieldsname = $fieldsname . implode(",' ',", $fieldlists);
  3595. $fieldsname = $fieldsname . ")";
  3596. }
  3597. if ($entityName != '') {
  3598. $sql = "select $entityidfield from $tablename INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = $tablename.$entityidfield " .
  3599. " WHERE vtiger_crmentity.deleted = 0 and $fieldsname=?";
  3600. $result = $adb->pquery($sql, array($entityName));
  3601. if ($adb->num_rows($result) > 0) {
  3602. $entityId = $adb->query_result($result, 0, $entityidfield);
  3603. }
  3604. }
  3605. if (!empty($entityId))
  3606. return $entityId;
  3607. else
  3608. return 0;
  3609. }
  3610. /** function used to get the parent id for the given input parent name --Pavani * */
  3611. function getParentId($parent_name) {
  3612. global $adb;
  3613. if ($parent_name == '' || $parent_name == NULL)
  3614. $parent_id = 0;
  3615. //For now it have conditions only for accounts and contacts, if needed can add more
  3616. $relatedTo = explode(':', $parent_name);
  3617. $parent_module = $relatedTo[0];
  3618. $parent_module = trim($parent_module, " ");
  3619. $parent_name = $relatedTo[3];
  3620. $parent_name = trim($parent_name, " ");
  3621. $num_rows = 0;
  3622. if ($parent_module == 'Contacts') {
  3623. $query = "select crmid from vtiger_contactdetails, vtiger_crmentity WHERE concat(lastname,' ',firstname)=? and vtiger_crmentity.crmid =vtiger_contactdetails.contactid and vtiger_crmentity.deleted=0";
  3624. $result = $adb->pquery($query, array($parent_name));
  3625. $num_rows = $adb->num_rows($result);
  3626. } else if ($parent_module == 'Accounts') {
  3627. $query = "select crmid from vtiger_account, vtiger_crmentity WHERE accountname=? and vtiger_crmentity.crmid =vtiger_account.accountid and vtiger_crmentity.deleted=0";
  3628. $result = $adb->pquery($query, array($parent_name));
  3629. $num_rows = $adb->num_rows($result);
  3630. }
  3631. else
  3632. $num_rows = 0;
  3633. if ($num_rows == 0)
  3634. $parent_id = 0;
  3635. else
  3636. $parent_id = $adb->query_result($result, 0, "crmid");
  3637. return $parent_id;
  3638. }
  3639. function decode_html($str) {
  3640. global $default_charset;
  3641. // Direct Popup action or Ajax Popup action should be treated the same.
  3642. if ($_REQUEST['action'] == 'Popup' || $_REQUEST['file'] == 'Popup')
  3643. return html_entity_decode($str);
  3644. else
  3645. return html_entity_decode($str, ENT_QUOTES, $default_charset);
  3646. }
  3647. /**
  3648. * Alternative decoding function which coverts irrespective of $_REQUEST values.
  3649. * Useful incase of Popup (Listview etc...) where if decode_html will not work as expected
  3650. */
  3651. function decode_html_force($str) {
  3652. global $default_charset;
  3653. return html_entity_decode($str, ENT_QUOTES, $default_charset);
  3654. }
  3655. function popup_decode_html($str) {
  3656. global $default_charset;
  3657. $slashes_str = popup_from_html($str);
  3658. $slashes_str = htmlspecialchars($slashes_str, ENT_QUOTES, $default_charset);
  3659. return decode_html(br2nl($slashes_str));
  3660. }
  3661. //function added to check the text length in the listview.
  3662. function textlength_check($field_val) {
  3663. global $listview_max_textlength, $default_charset;
  3664. if ($listview_max_textlength && $listview_max_textlength > 0) {
  3665. $temp_val = preg_replace("/(<\/?)(\w+)([^>]*>)/i", "", $field_val);
  3666. if (function_exists('mb_strlen')) {
  3667. if (mb_strlen($temp_val) > $listview_max_textlength) {
  3668. $temp_val = mb_substr(preg_replace("/(<\/?)(\w+)([^>]*>)/i", "", $field_val), 0, $listview_max_textlength, $default_charset) . '...';
  3669. }
  3670. } elseif (strlen($field_val) > $listview_max_textlength) {
  3671. $temp_val = substr(preg_replace("/(<\/?)(\w+)([^>]*>)/i", "", $field_val), 0, $listview_max_textlength) . '...';
  3672. }
  3673. } else {
  3674. $temp_val = $field_val;
  3675. }
  3676. return $temp_val;
  3677. }
  3678. /** Function to get permitted fields of current user of a particular module to find duplicate records --Pavani */
  3679. function getMergeFields($module, $str) {
  3680. global $adb, $current_user;
  3681. $tabid = getTabid($module);
  3682. if ($str == "available_fields") {
  3683. $result = getFieldsResultForMerge($tabid);
  3684. } else { //if($str == fileds_to_merge)
  3685. $sql = "select * from vtiger_user2mergefields where tabid=? and userid=? and visible=1";
  3686. $result = $adb->pquery($sql, array($tabid, $current_user->id));
  3687. }
  3688. $num_rows = $adb->num_rows($result);
  3689. $user_profileid = fetchUserProfileId($current_user->id);
  3690. $permitted_list = getProfile2FieldPermissionList($module, $user_profileid);
  3691. $sql_def_org = "select fieldid from vtiger_def_org_field where tabid=? and visible=0";
  3692. $result_def_org = $adb->pquery($sql_def_org, array($tabid));
  3693. $num_rows_org = $adb->num_rows($result_def_org);
  3694. $permitted_org_list = Array();
  3695. for ($i = 0; $i < $num_rows_org; $i++)
  3696. $permitted_org_list[$i] = $adb->query_result($result_def_org, $i, "fieldid");
  3697. require('user_privileges/user_privileges_' . $current_user->id . '.php');
  3698. for ($i = 0; $i < $num_rows; $i++) {
  3699. $field_id = $adb->query_result($result, $i, "fieldid");
  3700. foreach ($permitted_list as $field => $data)
  3701. if ($data[4] == $field_id and $data[1] == 0) {
  3702. if ($is_admin == 'true' || (in_array($field_id, $permitted_org_list))) {
  3703. $field = "<option value=\"" . $field_id . "\">" . getTranslatedString($data[0], $module) . "</option>";
  3704. $fields.=$field;
  3705. break;
  3706. }
  3707. }
  3708. }
  3709. return $fields;
  3710. }
  3711. /**
  3712. * this function accepts a modulename and a fieldname and returns the first related module for it
  3713. * it expects the uitype of the field to be 10
  3714. * @param string $module - the modulename
  3715. * @param string $fieldname - the field name
  3716. * @return string $data - the first related module
  3717. */
  3718. function getFirstModule($module, $fieldname) {
  3719. global $adb;
  3720. $sql = "select fieldid, uitype from vtiger_field where tabid=? and fieldname=?";
  3721. $result = $adb->pquery($sql, array(getTabid($module), $fieldname));
  3722. if ($adb->num_rows($result) > 0) {
  3723. $uitype = $adb->query_result($result, 0, "uitype");
  3724. if ($uitype == 10) {
  3725. $fieldid = $adb->query_result($result, 0, "fieldid");
  3726. $sql = "select * from vtiger_fieldmodulerel where fieldid=?";
  3727. $result = $adb->pquery($sql, array($fieldid));
  3728. $count = $adb->num_rows($result);
  3729. if ($count > 0) {
  3730. $data = $adb->query_result($result, 0, "relmodule");
  3731. }
  3732. }
  3733. }
  3734. return $data;
  3735. }
  3736. function VT_getSimpleNavigationValues($start, $size, $total) {
  3737. $prev = $start - 1;
  3738. if ($prev < 0) {
  3739. $prev = 0;
  3740. }
  3741. if ($total === null) {
  3742. return array('start' => $start, 'first' => $start, 'current' => $start, 'end' => $start, 'end_val' => $size, 'allflag' => 'All',
  3743. 'prev' => $prev, 'next' => $start + 1, 'verylast' => 'last');
  3744. }
  3745. if (empty($total)) {
  3746. $lastPage = 1;
  3747. } else {
  3748. $lastPage = ceil($total / $size);
  3749. }
  3750. $next = $start + 1;
  3751. if ($next > $lastPage) {
  3752. $next = 0;
  3753. }
  3754. return array('start' => $start, 'first' => $start, 'current' => $start, 'end' => $start, 'end_val' => $size, 'allflag' => 'All',
  3755. 'prev' => $prev, 'next' => $next, 'verylast' => $lastPage);
  3756. }
  3757. /* * Function to get the simplified table headers for a listview
  3758. * Param $navigation_arrray - navigation values in array
  3759. * Param $url_qry - url string
  3760. * Param $module - module name
  3761. * Param $action- action file name
  3762. * Param $viewid - view id
  3763. * Returns an string value
  3764. */
  3765. function getTableHeaderSimpleNavigation($navigation_array, $url_qry, $module = '', $action_val = 'index', $viewid = '') {
  3766. global $log, $app_strings;
  3767. global $theme, $current_user;
  3768. $theme_path = "themes/" . $theme . "/";
  3769. $image_path = $theme_path . "images/";
  3770. if ($module == 'Documents') {
  3771. $output = '<td class="mailSubHeader" width="40%" align="right">';
  3772. } else {
  3773. $output = '<td align="right" style="padding: 5px;">';
  3774. }
  3775. $tabname = getParentTab();
  3776. $search_tag = $_REQUEST['search_tag'];
  3777. $url_string = '';
  3778. // vtlib Customization : For uitype 10 popup during paging
  3779. if ($_REQUEST['form'] == 'vtlibPopupView') {
  3780. $url_string .= '&form=vtlibPopupView&forfield=' . vtlib_purify($_REQUEST['forfield']) . '&srcmodule=' . vtlib_purify($_REQUEST['srcmodule']) . '&forrecord=' . vtlib_purify($_REQUEST['forrecord']);
  3781. }
  3782. // END
  3783. if ($module == 'Calendar' && $action_val == 'index') {
  3784. if ($_REQUEST['view'] == '') {
  3785. if ($current_user->activity_view == "This Year") {
  3786. $mysel = 'year';
  3787. } else if ($current_user->activity_view == "This Month") {
  3788. $mysel = 'month';
  3789. } else if ($current_user->activity_view == "This Week") {
  3790. $mysel = 'week';
  3791. } else {
  3792. $mysel = 'day';
  3793. }
  3794. }
  3795. $data_value = date('Y-m-d H:i:s');
  3796. preg_match('/(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/', $data_value, $value);
  3797. $date_data = Array(
  3798. 'day' => $value[3],
  3799. 'month' => $value[2],
  3800. 'year' => $value[1],
  3801. 'hour' => $value[4],
  3802. 'min' => $value[5],
  3803. );
  3804. $tab_type = ($_REQUEST['subtab'] == '') ? 'event' : vtlib_purify($_REQUEST['subtab']);
  3805. $url_string .= isset($_REQUEST['view']) ? "&view=" . vtlib_purify($_REQUEST['view']) : "&view=" . $mysel;
  3806. $url_string .= isset($_REQUEST['subtab']) ? "&subtab=" . vtlib_purify($_REQUEST['subtab']) : '';
  3807. $url_string .= isset($_REQUEST['viewOption']) ? "&viewOption=" . vtlib_purify($_REQUEST['viewOption']) : '&viewOption=listview';
  3808. $url_string .= isset($_REQUEST['day']) ? "&day=" . vtlib_purify($_REQUEST['day']) : '&day=' . $date_data['day'];
  3809. $url_string .= isset($_REQUEST['week']) ? "&week=" . vtlib_purify($_REQUEST['week']) : '';
  3810. $url_string .= isset($_REQUEST['month']) ? "&month=" . vtlib_purify($_REQUEST['month']) : '&month=' . $date_data['month'];
  3811. $url_string .= isset($_REQUEST['year']) ? "&year=" . vtlib_purify($_REQUEST['year']) : "&year=" . $date_data['year'];
  3812. $url_string .= isset($_REQUEST['n_type']) ? "&n_type=" . vtlib_purify($_REQUEST['n_type']) : '';
  3813. $url_string .= isset($_REQUEST['search_option']) ? "&search_option=" . vtlib_purify($_REQUEST['search_option']) : '';
  3814. }
  3815. if ($module == 'Calendar' && $action_val != 'index') //added for the All link from the homepage -- ticket 5211
  3816. $url_string .= isset($_REQUEST['from_homepage']) ? "&from_homepage=" . vtlib_purify($_REQUEST['from_homepage']) : '';
  3817. if (($navigation_array['prev']) != 0) {
  3818. if ($module == 'Calendar' && $action_val == 'index') {
  3819. $output .= '<a href="javascript:;" onClick="cal_navigation(\'' . $tab_type . '\',\'' . $url_string . '\',\'&start=1\');" alt="' . $app_strings['LBL_FIRST'] . '" title="' . $app_strings['LBL_FIRST'] . '"><img src="' . vtiger_imageurl('start.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  3820. $output .= '<a href="javascript:;" onClick="cal_navigation(\'' . $tab_type . '\',\'' . $url_string . '\',\'&start=' . $navigation_array['prev'] . '\');" alt="' . $app_strings['LBL_FIRST'] . '" title="' . $app_strings['LBL_FIRST'] . '"><img src="' . vtiger_imageurl('start.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  3821. } else if ($action_val == "FindDuplicate") {
  3822. $output .= '<a href="javascript:;" onClick="getDuplicateListViewEntries_js(\'' . $module . '\',\'parenttab=' . $tabname . '&start=1' . $url_string . '\');" alt="' . $app_strings['LBL_FIRST'] . '" title="' . $app_strings['LBL_FIRST'] . '"><img src="' . vtiger_imageurl('start.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  3823. $output .= '<a href="javascript:;" onClick="getDuplicateListViewEntries_js(\'' . $module . '\',\'parenttab=' . $tabname . '&start=' . $navigation_array['prev'] . $url_string . '\');" alt="' . $app_strings['LNK_LIST_PREVIOUS'] . '"title="' . $app_strings['LNK_LIST_PREVIOUS'] . '"><img src="' . vtiger_imageurl('previous.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  3824. } elseif ($action_val == 'UnifiedSearch') {
  3825. $output .= '<a href="javascript:;" onClick="getUnifiedSearchEntries_js(\'' . $search_tag . '\',\'' . $module . '\',\'parenttab=' . $tabname . '&start=1' . $url_string . '\');" alt="' . $app_strings['LBL_FIRST'] . '" title="' . $app_strings['LBL_FIRST'] . '"><img src="' . vtiger_imageurl('start.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  3826. $output .= '<a href="javascript:;" onClick="getUnifiedSearchEntries_js(\'' . $search_tag . '\',\'' . $module . '\',\'parenttab=' . $tabname . '&start=' . $navigation_array['prev'] . $url_string . '\');" alt="' . $app_strings['LNK_LIST_PREVIOUS'] . '"title="' . $app_strings['LNK_LIST_PREVIOUS'] . '"><img src="' . vtiger_imageurl('previous.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  3827. } elseif ($module == 'Documents') {
  3828. $output .= '<a href="javascript:;" onClick="getListViewEntries_js(\'' . $module . '\',\'parenttab=' . $tabname . '&start=1' . $url_string . '\');" alt="' . $app_strings['LBL_FIRST'] . '" title="' . $app_strings['LBL_FIRST'] . '"><img src="' . vtiger_imageurl('start.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  3829. $output .= '<a href="javascript:;" onClick="getListViewEntries_js(\'' . $module . '\',\'parenttab=' . $tabname . '&start=' . $navigation_array['prev'] . $url_string . '&folderid=' . $action_val . '\');" alt="' . $app_strings['LNK_LIST_PREVIOUS'] . '"title="' . $app_strings['LNK_LIST_PREVIOUS'] . '"><img src="' . vtiger_imageurl('previous.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  3830. } else {
  3831. $output .= '<a href="javascript:;" onClick="getListViewEntries_js(\'' . $module . '\',\'parenttab=' . $tabname . '&start=1' . $url_string . '\');" alt="' . $app_strings['LBL_FIRST'] . '" title="' . $app_strings['LBL_FIRST'] . '"><img src="' . vtiger_imageurl('start.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  3832. $output .= '<a href="javascript:;" onClick="getListViewEntries_js(\'' . $module . '\',\'parenttab=' . $tabname . '&start=' . $navigation_array['prev'] . $url_string . '\');" alt="' . $app_strings['LNK_LIST_PREVIOUS'] . '"title="' . $app_strings['LNK_LIST_PREVIOUS'] . '"><img src="' . vtiger_imageurl('previous.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  3833. }
  3834. } else {
  3835. $output .= '<img src="' . vtiger_imageurl('start_disabled.gif', $theme) . '" border="0" align="absmiddle">&nbsp;';
  3836. $output .= '<img src="' . vtiger_imageurl('previous_disabled.gif', $theme) . '" border="0" align="absmiddle">&nbsp;';
  3837. }
  3838. if ($module == 'Calendar' && $action_val == 'index') {
  3839. $jsNavigate = "cal_navigation('$tab_type','$url_string','&start='+this.value);";
  3840. } else if ($action_val == "FindDuplicate") {
  3841. $jsNavigate = "getDuplicateListViewEntries_js('$module','parenttab=$tabname&start='+this.value+'$url_string');";
  3842. } elseif ($action_val == 'UnifiedSearch') {
  3843. $jsNavigate = "getUnifiedSearchEntries_js('$search_tag','$module','parenttab=$tabname&start='+this.value+'$url_string');";
  3844. } elseif ($module == 'Documents') {
  3845. $jsNavigate = "getListViewEntries_js('$module','parenttab=$tabname&start='+this.value+'$url_string&folderid=$action_val');";
  3846. } else {
  3847. $jsNavigate = "getListViewEntries_js('$module','parenttab=$tabname&start='+this.value+'$url_string');";
  3848. }
  3849. if ($module == 'Documents' && $action_val != 'UnifiedSearch') {
  3850. $url = '&folderid=' . $action_val;
  3851. } else {
  3852. $url = '';
  3853. }
  3854. $jsHandler = "return VT_disableFormSubmit(event);";
  3855. $output .= "<input class='small' name='pagenum' type='text' value='{$navigation_array['current']}'
  3856. style='width: 3em;margin-right: 0.7em;' onchange=\"$jsNavigate\"
  3857. onkeypress=\"$jsHandler\">";
  3858. $output .= "<span name='" . $module . "_listViewCountContainerName' class='small' style='white-space: nowrap;'>";
  3859. if (PerformancePrefs::getBoolean('LISTVIEW_COMPUTE_PAGE_COUNT', false) === true) {
  3860. $output .= $app_strings['LBL_LIST_OF'] . ' ' . $navigation_array['verylast'];
  3861. } else {
  3862. $output .= "<img src='" . vtiger_imageurl('windowRefresh.gif', $theme) . "' alt='" . $app_strings['LBL_HOME_COUNT'] . "'
  3863. onclick='getListViewCount(\"" . $module . "\",this,this.parentNode,\"" . $url . "\")'
  3864. align='absmiddle' name='" . $module . "_listViewCountRefreshIcon'/>
  3865. <img name='" . $module . "_listViewCountContainerBusy' src='" . vtiger_imageurl('vtbusy.gif', $theme) . "' style='display: none;'
  3866. align='absmiddle' alt='" . $app_strings['LBL_LOADING'] . "'>";
  3867. }
  3868. $output .='</span>';
  3869. if (($navigation_array['next']) != 0) {
  3870. if ($module == 'Calendar' && $action_val == 'index') {
  3871. $output .= '<a href="javascript:;" onClick="cal_navigation(\'' . $tab_type . '\',\'' . $url_string . '\',\'&start=' . $navigation_array['next'] . '\');" alt="' . $app_strings['LNK_LIST_NEXT'] . '" title="' . $app_strings['LNK_LIST_NEXT'] . '"><img src="' . vtiger_imageurl('next.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  3872. $output .= '<a href="javascript:;" onClick="cal_navigation(\'' . $tab_type . '\',\'' . $url_string . '\',\'&start=' . $navigation_array['verylast'] . '\');" alt="' . $app_strings['LBL_LAST'] . '" title="' . $app_strings['LBL_LAST'] . '"><img src="' . vtiger_imageurl('end.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  3873. } else if ($action_val == "FindDuplicate") {
  3874. $output .= '<a href="javascript:;" onClick="getDuplicateListViewEntries_js(\'' . $module . '\',\'parenttab=' . $tabname . '&start=' . $navigation_array['next'] . $url_string . '\');" alt="' . $app_strings['LNK_LIST_NEXT'] . '" title="' . $app_strings['LNK_LIST_NEXT'] . '"><img src="' . vtiger_imageurl('next.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  3875. $output .= '<a href="javascript:;" onClick="getDuplicateListViewEntries_js(\'' . $module . '\',\'parenttab=' . $tabname . '&start=' . $navigation_array['verylast'] . $url_string . '\');" alt="' . $app_strings['LBL_LAST'] . '" title="' . $app_strings['LBL_LAST'] . '"><img src="' . vtiger_imageurl('end.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  3876. } elseif ($action_val == 'UnifiedSearch') {
  3877. $output .= '<a href="javascript:;" onClick="getUnifiedSearchEntries_js(\'' . $search_tag . '\',\'' . $module . '\',\'parenttab=' . $tabname . '&start=' . $navigation_array['next'] . $url_string . '\');" alt="' . $app_strings['LNK_LIST_NEXT'] . '" title="' . $app_strings['LNK_LIST_NEXT'] . '"><img src="' . vtiger_imageurl('next.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  3878. $output .= '<a href="javascript:;" onClick="getUnifiedSearchEntries_js(\'' . $search_tag . '\',\'' . $module . '\',\'parenttab=' . $tabname . '&start=' . $navigation_array['verylast'] . $url_string . '\');" alt="' . $app_strings['LBL_LAST'] . '" title="' . $app_strings['LBL_LAST'] . '"><img src="themes/images/end.gif" border="0" align="absmiddle"></a>&nbsp;';
  3879. } elseif ($module == 'Documents') {
  3880. $output .= '<a href="javascript:;" onClick="getListViewEntries_js(\'' . $module . '\',\'parenttab=' . $tabname . '&start=' . $navigation_array['next'] . $url_string . '&folderid=' . $action_val . '\');" alt="' . $app_strings['LNK_LIST_NEXT'] . '" title="' . $app_strings['LNK_LIST_NEXT'] . '"><img src="' . vtiger_imageurl('next.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  3881. $output .= '<a href="javascript:;" onClick="getListViewEntries_js(\'' . $module . '\',\'parenttab=' . $tabname . '&start=' . $navigation_array['verylast'] . $url_string . '&folderid=' . $action_val . '\');" alt="' . $app_strings['LBL_LAST'] . '" title="' . $app_strings['LBL_LAST'] . '"><img src="' . vtiger_imageurl('end.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  3882. } else {
  3883. $output .= '<a href="javascript:;" onClick="getListViewEntries_js(\'' . $module . '\',\'parenttab=' . $tabname . '&start=' . $navigation_array['next'] . $url_string . '\');" alt="' . $app_strings['LNK_LIST_NEXT'] . '" title="' . $app_strings['LNK_LIST_NEXT'] . '"><img src="' . vtiger_imageurl('next.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  3884. $output .= '<a href="javascript:;" onClick="getListViewEntries_js(\'' . $module . '\',\'parenttab=' . $tabname . '&start=' . $navigation_array['verylast'] . $url_string . '\');" alt="' . $app_strings['LBL_LAST'] . '" title="' . $app_strings['LBL_LAST'] . '"><img src="' . vtiger_imageurl('end.gif', $theme) . '" border="0" align="absmiddle"></a>&nbsp;';
  3885. }
  3886. } else {
  3887. $output .= '<img src="' . vtiger_imageurl('next_disabled.gif', $theme) . '" border="0" align="absmiddle">&nbsp;';
  3888. $output .= '<img src="' . vtiger_imageurl('end_disabled.gif', $theme) . '" border="0" align="absmiddle">&nbsp;';
  3889. }
  3890. $output .= '</td>';
  3891. if ($navigation_array['first'] == '')
  3892. return;
  3893. else
  3894. return $output;
  3895. }
  3896. function getRecordRangeMessage($listResult, $limitStartRecord, $totalRows = '') {
  3897. global $adb, $app_strings;
  3898. $numRows = $adb->num_rows($listResult);
  3899. $recordListRangeMsg = '';
  3900. if ($numRows > 0) {
  3901. $recordListRangeMsg = $app_strings['LBL_SHOWING'] . ' ' . $app_strings['LBL_RECORDS'] .
  3902. ' ' . ($limitStartRecord + 1) . ' - ' . ($limitStartRecord + $numRows);
  3903. if (PerformancePrefs::getBoolean('LISTVIEW_COMPUTE_PAGE_COUNT', false) === true) {
  3904. $recordListRangeMsg .= ' ' . $app_strings['LBL_LIST_OF'] . " $totalRows";
  3905. }
  3906. }
  3907. return $recordListRangeMsg;
  3908. }
  3909. function listQueryNonAdminChange($query, $module, $scope = '') {
  3910. $instance = CRMEntity::getInstance($module);
  3911. return $instance->listQueryNonAdminChange($query, $scope);
  3912. }
  3913. function html_strlen($str) {
  3914. $chars = preg_split('/(&[^;\s]+;)|/', $str, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
  3915. return count($chars);
  3916. }
  3917. function html_substr($str, $start, $length = NULL) {
  3918. if ($length === 0)
  3919. return "";
  3920. //check if we can simply use the built-in functions
  3921. if (strpos($str, '&') === false) { //No entities. Use built-in functions
  3922. if ($length === NULL)
  3923. return substr($str, $start);
  3924. else
  3925. return substr($str, $start, $length);
  3926. }
  3927. // create our array of characters and html entities
  3928. $chars = preg_split('/(&[^;\s]+;)|/', $str, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE);
  3929. $html_length = count($chars);
  3930. // check if we can predict the return value and save some processing time
  3931. if (($html_length === 0) or ($start >= $html_length) or (isset($length) and ($length <= -$html_length)))
  3932. return "";
  3933. //calculate start position
  3934. if ($start >= 0) {
  3935. $real_start = $chars[$start][1];
  3936. } else { //start'th character from the end of string
  3937. $start = max($start, -$html_length);
  3938. $real_start = $chars[$html_length + $start][1];
  3939. }
  3940. if (!isset($length)) // no $length argument passed, return all remaining characters
  3941. return substr($str, $real_start);
  3942. else if ($length > 0) { // copy $length chars
  3943. if ($start + $length >= $html_length) { // return all remaining characters
  3944. return substr($str, $real_start);
  3945. } else { //return $length characters
  3946. return substr($str, $real_start, $chars[max($start, 0) + $length][1] - $real_start);
  3947. }
  3948. } else { //negative $length. Omit $length characters from end
  3949. return substr($str, $real_start, $chars[$html_length + $length][1] - $real_start);
  3950. }
  3951. }
  3952. function counterValue() {
  3953. static $counter = 0;
  3954. $counter = $counter + 1;
  3955. return $counter;
  3956. }
  3957. ?>