[ Index ] |
|
Code source de vtiger CRM 5.0.2 |
1 <?php 2 /********************************************************************************* 3 * The contents of this file are subject to the SugarCRM Public License Version 1.1.2 4 * ("License"); You may not use this file except in compliance with the 5 * License. You may obtain a copy of the License at http://www.sugarcrm.com/SPL 6 * Software distributed under the License is distributed on an "AS IS" basis, 7 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for 8 * the specific language governing rights and limitations under the License. 9 * The Original Code is: SugarCRM Open Source 10 * The Initial Developer of the Original Code is SugarCRM, Inc. 11 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.; 12 * All Rights Reserved. 13 * Contributor(s): ______________________________________. 14 ********************************************************************************/ 15 /********************************************************************************* 16 * $Header: /advent/projects/wesat/vtiger_crm/sugarcrm/modules/Home/UnifiedSearch.php,v 1.4 2005/02/21 07:02:49 jack Exp $ 17 * Description: TODO: To be written. 18 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. 19 * All Rights Reserved. 20 * Contributor(s): ______________________________________.. 21 ********************************************************************************/ 22 23 require_once ('include/logging.php'); 24 require_once ('modules/Home/language/en_us.lang.php'); 25 require_once ('include/database/PearDatabase.php'); 26 require_once ('modules/CustomView/CustomView.php'); 27 28 require_once ('Smarty_setup.php'); 29 global $mod_strings; 30 31 $total_record_count = 0; 32 33 $query_string = trim($_REQUEST['query_string']); 34 if(isset($query_string) && $query_string != '')//preg_match("/[\w]/", $_REQUEST['query_string'])) 35 { 36 37 //module => object 38 $object_array = getSearchModules(); 39 foreach($object_array as $curr_module=>$curr_object) 40 { 41 require_once("modules/$curr_module/$curr_object.php"); 42 } 43 44 global $adb; 45 global $current_user; 46 global $theme; 47 $theme_path="themes/".$theme."/"; 48 $image_path=$theme_path."images/"; 49 50 $search_val = $query_string; 51 $search_module = $_REQUEST['search_module']; 52 53 getSearchModulesComboList($search_module); 54 55 foreach($object_array as $module => $object_name) 56 { 57 if(isPermitted($module,"index") == "yes") 58 { 59 $focus = new $object_name(); 60 61 $smarty = new vtigerCRM_Smarty; 62 63 require_once("modules/$module/language/en_us.lang.php"); 64 global $mod_strings; 65 global $app_strings; 66 67 $smarty->assign("MOD", $mod_strings); 68 $smarty->assign("APP", $app_strings); 69 $smarty->assign("IMAGE_PATH",$image_path); 70 $smarty->assign("MODULE",$module); 71 $smarty->assign("SEARCH_MODULE",$_REQUEST['search_module']); 72 $smarty->assign("SINGLE_MOD",$module); 73 74 75 $listquery = getListQuery($module); 76 $oCustomView = ''; 77 78 $oCustomView = new CustomView($module); 79 80 if($search_module != '')//This is for Tag search 81 { 82 83 $where = getTagWhere($search_val,$current_user->id); 84 $search_msg = $app_strings['LBL_TAG_SEARCH']; 85 $search_msg .= "<b>".$search_val."</b>"; 86 } 87 else //This is for Global search 88 { 89 $where = getUnifiedWhere($listquery,$module,$search_val); 90 $search_msg = $app_strings['LBL_SEARCH_RESULTS_FOR']; 91 $search_msg .= "<b>".$search_val."</b>"; 92 } 93 94 if($where != '') 95 $listquery .= ' and ('.$where.')'; 96 97 $list_result = $adb->query($listquery); 98 $noofrows = $adb->num_rows($list_result); 99 100 if($noofrows >= 1) 101 $list_max_entries_per_page = $noofrows; 102 //Here we can change the max list entries per page per module 103 $navigation_array = getNavigationValues(1, $noofrows, $list_max_entries_per_page); 104 105 $listview_header = getListViewHeader($focus,$module,"","","","global",$oCustomView); 106 $listview_entries = getListViewEntries($focus,$module,$list_result,$navigation_array,"","","","",$oCustomView); 107 108 //Do not display the Header if there are no entires in listview_entries 109 if(count($listview_entries) > 0) 110 { 111 $display_header = 1; 112 } 113 else 114 { 115 $display_header = 0; 116 } 117 118 $smarty->assign("LISTHEADER", $listview_header); 119 $smarty->assign("LISTENTITY", $listview_entries); 120 $smarty->assign("DISPLAYHEADER", $display_header); 121 $smarty->assign("HEADERCOUNT", count($listview_header)); 122 123 $total_record_count = $total_record_count + $noofrows; 124 125 $smarty->assign("SEARCH_CRITERIA","( $noofrows )".$search_msg); 126 $smarty->assign("MODULES_LIST", $object_array); 127 128 $smarty->display("GlobalListView.tpl"); 129 unset($_SESSION['lvs'][$module]); 130 } 131 } 132 133 //Added to display the Total record count 134 ?> 135 <script> 136 document.getElementById("global_search_total_count").innerHTML = " <? echo $app_strings['LBL_TOTAL_RECORDS_FOUND'] ?><b><?php echo $total_record_count; ?></b>"; 137 </script> 138 <?php 139 140 } 141 else { 142 echo "<br><br> <em>".$mod_strings['ERR_ONE_CHAR']."</em>"; 143 } 144 145 /** Function to get the where condition for a module based on the field table entries 146 * @param string $listquery -- ListView query for the module 147 * @param string $module -- module name 148 * @param string $search_val -- entered search string value 149 * @return string $where -- where condition for the module based on field table entries 150 */ 151 function getUnifiedWhere($listquery,$module,$search_val) 152 { 153 global $adb; 154 155 $query = "SELECT columnname, tablename FROM vtiger_field WHERE tabid = ".getTabid($module); 156 $result = $adb->query($query); 157 $noofrows = $adb->num_rows($result); 158 159 $where = ''; 160 for($i=0;$i<$noofrows;$i++) 161 { 162 $columnname = $adb->query_result($result,$i,'columnname'); 163 $tablename = $adb->query_result($result,$i,'tablename'); 164 165 //Before form the where condition, check whether the table for the field has been added in the listview query 166 if(strstr($listquery,$tablename)) 167 { 168 if($where != '') 169 $where .= " OR "; 170 $where .= $tablename.".".$columnname." LIKE ".$adb->quote("%$search_val%"); 171 } 172 } 173 174 return $where; 175 } 176 177 /** Function to get the Tags where condition 178 * @param string $search_val -- entered search string value 179 * @param string $current_user_id -- current user id 180 * @return string $where -- where condition with the list of crmids, will like vtiger_crmentity.crmid in (1,3,4,etc.,) 181 */ 182 function getTagWhere($search_val,$current_user_id) 183 { 184 require_once ('include/freetag/freetag.class.php'); 185 186 $freetag_obj = new freetag(); 187 188 $crmid_array = $freetag_obj->get_objects_with_tag_all($search_val,$current_user_id); 189 190 $where = ''; 191 if(count($crmid_array) > 0) 192 { 193 $where = " vtiger_crmentity.crmid IN ("; 194 foreach($crmid_array as $index => $crmid) 195 { 196 $where .= $crmid.','; 197 } 198 $where = trim($where,',').')'; 199 } 200 201 return $where; 202 } 203 204 205 /** Function to get the the List of Searchable Modules as a combo list which will be displayed in right corner under the Header 206 * @param string $search_module -- search module, this module result will be shown defaultly 207 */ 208 function getSearchModulesComboList($search_module) 209 { 210 global $object_array; 211 global $app_strings; 212 global $mod_strings; 213 214 ?> 215 <script language="JavaScript" type="text/javascript" src="include/js/general.js"></script> 216 <script> 217 function displayModuleList(selectmodule_view) 218 { 219 <?php 220 foreach($object_array as $module => $object_name) 221 { 222 ?> 223 mod = "global_list_"+"<?php echo $module; ?>"; 224 if(selectmodule_view.options[selectmodule_view.options.selectedIndex].value == "All") 225 show(mod); 226 else 227 hide(mod); 228 <?php 229 } 230 ?> 231 232 if(selectmodule_view.options[selectmodule_view.options.selectedIndex].value != "All") 233 { 234 selectedmodule="global_list_"+selectmodule_view.options[selectmodule_view.options.selectedIndex].value; 235 show(selectedmodule); 236 } 237 } 238 </script> 239 <table border=0 cellspacing=0 cellpadding=0 width=98% align=center> 240 <tr> 241 <td colspan="3" id="global_search_total_count" style="padding-left:30px"> </td> 242 <td nowrap align="right"><? echo $app_strings['LBL_SHOW_RESULTS'] ?> 243 <select id="global_search_module" name="global_search_module" onChange="displayModuleList(this);"> 244 <option value="All"><? echo $app_strings['COMBO_ALL'] ?></option> 245 <?php 246 foreach($object_array as $module => $object_name) 247 { 248 $selected = ''; 249 if($search_module != '' && $module == $search_module) 250 $selected = 'selected'; 251 if($search_module == '' && $module == 'All') 252 $selected = 'selected'; 253 ?> 254 <option value="<?php echo $module; ?>" <?php echo $selected; ?> ><?php echo $app_strings[$module]; ?></option> 255 <?php 256 } 257 ?> 258 </select> 259 </td> 260 </tr> 261 </table> 262 <?php 263 } 264 265 /*To get the modules allowed for global search this function returns all the 266 * modules which supports global search as an array in the following structure 267 * array($module_name1=>$object_name1,$module_name2=>$object_name2,$module_name3=>$object_name3,$module_name4=>$object_name4,-----); 268 */ 269 function getSearchModules() 270 { 271 global $adb; 272 $sql = 'select distinct vtiger_field.tabid,name from vtiger_field inner join vtiger_tab on vtiger_tab.tabid=vtiger_field.tabid where vtiger_tab.tabid not in (16,29)'; 273 $result = $adb->query($sql); 274 while($module_result = $adb->fetch_array($result)) 275 { 276 $modulename = $module_result['name']; 277 if($modulename != 'Calendar') 278 { 279 $return_arr[$modulename] = $modulename; 280 }else 281 { 282 $return_arr[$modulename] = 'Activity'; 283 } 284 } 285 return $return_arr; 286 } 287 288 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 10:22:19 2007 | par Balluche grâce à PHPXref 0.7 |