PageRenderTime 61ms CodeModel.GetById 34ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/Users/getListOfRecords.php

https://bitbucket.org/yousef_fadila/vtiger
PHP | 125 lines | 103 code | 12 blank | 10 comment | 19 complexity | f6fae58e093455f844d2e2bd9c15300f MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. <?php
  2. /*+*******************************************************************************
  3. * The contents of this file are subject to the vtiger CRM Public License Version 1.0
  4. * ("License"); You may not use this file except in compliance with the License
  5. * The Original Code is: vtiger CRM Open Source
  6. * The Initial Developer of the Original Code is vtiger.
  7. * Portions created by vtiger are Copyright (C) vtiger.
  8. * All Rights Reserved.
  9. ********************************************************************************/
  10. session_start();
  11. require_once('include/CustomFieldUtil.php');
  12. require_once('Smarty_setup.php');
  13. require_once('include/database/PearDatabase.php');
  14. require_once 'include/utils/ListViewUtils.php';
  15. require_once('modules/CustomView/CustomView.php');
  16. global $mod_strings,$app_strings,$app_list_strings,$theme,$adb,$current_user;
  17. global $list_max_entries_per_page;
  18. $theme_path="themes/".$theme."/";
  19. require_once('modules/Vtiger/layout_utils.php');
  20. $iCurRecord = vtlib_purify($_REQUEST['CurRecordId']);
  21. $sModule = vtlib_purify($_REQUEST['CurModule']);
  22. require_once('data/CRMEntity.php');
  23. $foc_obj = CRMEntity::getInstance($sModule);
  24. $query = $adb->pquery("SELECT tablename,entityidfield, fieldname from vtiger_entityname WHERE modulename = ?",array($sModule));
  25. $table_name = $adb->query_result($query,0,'tablename');
  26. $field_name = $adb->query_result($query,0,'fieldname');
  27. $id_field = $adb->query_result($query,0,'entityidfield');
  28. $fieldname = split(",",$field_name);
  29. $fields_array = array($sModule=>$fieldname);
  30. $id_array = array($sModule=>$id_field);
  31. $tables_array = array($sModule=>$table_name);
  32. $permittedFieldNameList = array();
  33. foreach ($fieldname as $fieldName) {
  34. $checkForFieldAccess = $fieldName;
  35. // Handling case where fieldname in vtiger_entityname mismatches fieldname in vtiger_field
  36. if($sModule == 'HelpDesk' && $checkForFieldAccess == 'title') {
  37. $checkForFieldAccess = 'ticket_title';
  38. } else if($sModule == 'Documents' && $checkForFieldAccess == 'title') {
  39. $checkForFieldAccess = 'notes_title';
  40. }
  41. // END
  42. if(getFieldVisibilityPermission($sModule,$current_user->id, $checkForFieldAccess) == '0'){
  43. $permittedFieldNameList[] = $fieldName;
  44. }
  45. }
  46. $cv = new CustomView();
  47. $viewId = $cv->getViewId($sModule);
  48. if(!empty($_SESSION[$sModule.'_DetailView_Navigation'.$viewId])){
  49. $recordNavigationInfo = Zend_Json::decode($_SESSION[$sModule.'_DetailView_Navigation'.$viewId]);
  50. $recordList = array();
  51. $recordIndex = null;
  52. $recordPageMapping = array();
  53. foreach ($recordNavigationInfo as $start=>$recordIdList){
  54. foreach ($recordIdList as $index=>$recordId) {
  55. if(!isRecordExists($recordId)) continue;
  56. $recordList[] = $recordId;
  57. $recordPageMapping[$recordId] = $start;
  58. if($recordId == $iCurRecord){
  59. $recordIndex = count($recordList)-1;
  60. }
  61. }
  62. }
  63. }else{
  64. $recordList = array();
  65. }
  66. $output = '<table width="100%" border="0" cellpadding="5" cellspacing="0" class="layerHeadingULine">
  67. <tr><td width="60%" align="left" style="font-size:12px;font-weight:bold;">Jump to '.$app_strings[$sModule].':</td>
  68. <td width="5%" align="right"><a href="javascript:fninvsh(\'lstRecordLayout\');"><img src="'. vtiger_imageurl('close.gif', $theme).'" border="0" align="absmiddle" /></a></td>
  69. </tr>
  70. </table><table border=0 cellspacing=0 cellpadding=0 width=100% align=center>
  71. <tr>
  72. <td class=small >
  73. <table border=0 celspacing=0 cellpadding=0 width=100% align=center >
  74. <tr><td>';
  75. $output .= '<div style="height:270px;overflow-y:auto;">';
  76. $output .= '<table cellpadding="2">';
  77. if(count($recordList) > 0){
  78. $displayRecordCount = 10;
  79. $count = count($recordList);
  80. $idListEndIndex = ($count < ($recordIndex+$displayRecordCount))? ($count+1) : ($recordIndex+$displayRecordCount+1);
  81. $idListStartIndex = $recordIndex-$displayRecordCount;
  82. if($idListStartIndex < 0){
  83. $idListStartIndex = 0;
  84. }
  85. $idsArray = array_slice($recordList,$idListStartIndex,($idListEndIndex - $idListStartIndex));
  86. $selectColString = implode(',',$permittedFieldNameList).', '.$id_array[$sModule];
  87. $fieldQuery = "SELECT $selectColString from ".$tables_array[$sModule]." WHERE ".$id_array[$sModule]." IN (". generateQuestionMarks($idsArray) .")";
  88. $fieldResult = $adb->pquery($fieldQuery,$idsArray);
  89. $numOfRows = $adb->num_rows($fieldResult);
  90. $recordNameMapping = array();
  91. for($i=0; $i<$numOfRows; ++$i) {
  92. $recordId = $adb->query_result($fieldResult,$i,$id_array[$sModule]);
  93. $fieldValue = '';
  94. foreach ($permittedFieldNameList as $fieldName) {
  95. $fieldValue .= " ".$adb->query_result($fieldResult,$i,$fieldName);
  96. }
  97. $fieldValue = textlength_check($fieldValue);
  98. $recordNameMapping[$recordId] = $fieldValue;
  99. }
  100. foreach ($idsArray as $id) {
  101. if($id===$iCurRecord){
  102. $output .= '<tr><td style="text-align:left;font-weight:bold;">'.$recordNameMapping[$id].'</td></tr>';
  103. }else{
  104. $output .= '<tr><td style="text-align:left;"><a href="index.php?module='.$sModule.
  105. '&action=DetailView&parenttab='.vtlib_purify($_REQUEST['CurParentTab']).'&record='.$id.
  106. '&start='.$recordPageMapping[$id].'">'.$recordNameMapping[$id].'</a></td></tr>';
  107. }
  108. }
  109. }
  110. $output .= '</table>';
  111. $output .= '</div></td></tr></table></td></tr></table>';
  112. echo $output;
  113. ?>