function vtws_getSearchResults($query, $search_onlyin, $restrictionids, $user) { global $adb, $log, $current_user; $res = array(); // security restrictions if (empty($query) or empty($restrictionids) or !is_array($restrictionids)) { return serialize($res); } if (empty($restrictionids['userId']) or empty($restrictionids['accountId']) or empty($restrictionids['contactId'])) { return serialize($res); } list($void, $accountId) = explode('x', $restrictionids['accountId']); list($void, $contactId) = explode('x', $restrictionids['contactId']); list($void, $userId) = explode('x', $restrictionids['userId']); $current_user->retrieveCurrentUserInfoFromFile($userId); // if connected user does not have admin privileges > user must be the connected user if ($user->is_admin != 'on' and $user->id != $userId) { return serialize($res); } // connected user must have access to account and contact > this will be restricted by the coreBOS system and the rest of the code // start work require_once 'modules/CustomView/CustomView.php'; require_once 'include/utils/utils.php'; // Was the search limited by user for specific modules? $search_onlyin = empty($search_onlyin) ? array() : explode(',', $search_onlyin); $object_array = getSearchModules($search_onlyin); $total_record_count = 0; $i = 0; $j = 0; $moduleRecordCount = array(); foreach ($object_array as $module => $object_name) { $listquery = getListQuery($module); $oCustomView = new CustomView($module); //Instead of getting current customview id, use cvid of All so that all entities will be found $cv_res = $adb->pquery("select cvid from vtiger_customview where viewname='All' and entitytype=?", array($module)); $viewid = $adb->query_result($cv_res, 0, 'cvid'); $listquery = $oCustomView->getModifiedCvListQuery($viewid, $listquery, $module); if (!empty($accountId) and !empty($contactId)) { switch ($module) { case 'Products': // FIXME: add inner join on relations to accounts and contacts break; case 'Services': // FIXME: add inner join on relations to accounts and contacts break; case 'Documents': $listquery = str_replace(' WHERE ', " inner join vtiger_senotesrel on vtiger_senotesrel.notesid=vtiger_notes.notesid and (vtiger_senotesrel.crmid={$accountId} or vtiger_senotesrel.crmid={$contactId}) WHERE ", $listquery); break; } } $where = getUnifiedWhere($listquery, $module, $query); if ($where != '') { $listquery .= ' and (' . $where . ')'; } if (!empty($accountId) and !empty($contactId)) { $cond = evvt_PortalModuleRestrictions($module, $accountId, $contactId); if ($cond != '') { $listquery .= ' and (' . $cond . ')'; } } $count_result = $adb->query($listquery); $noofrows = $adb->num_rows($count_result); $moduleRecordCount[$module]['count'] = $noofrows; $navigation_array = VT_getSimpleNavigationValues(1, 100, $noofrows); $list_result = $adb->query($listquery); $focus = CRMEntity::getInstance($module); $listview_entries = getSearchingListViewEntries($focus, $module, $list_result, $navigation_array, "", "", "", "", $oCustomView, "", "", "", true); $total_record_count = $total_record_count + $noofrows; if (!empty($listview_entries)) { foreach ($listview_entries as $key => $element) { $res[$j] = $element; $j++; } } $i++; } $result = serialize($res); return $result; }
if (isset($query_string) && $query_string != '') { // Was the search limited by user for specific modules? $search_onlyin = $_REQUEST['search_onlyin']; if (!empty($search_onlyin) && $search_onlyin != '--USESELECTED--') { $search_onlyin = explode(',', $search_onlyin); } else { if ($search_onlyin == '--USESELECTED--') { $search_onlyin = $_SESSION['__UnifiedSearch_SelectedModules__']; } else { $search_onlyin = array(); } } // Save the selection for futur use (UnifiedSearchModules.php) $_SESSION['__UnifiedSearch_SelectedModules__'] = $search_onlyin; // END $object_array = getSearchModules($search_onlyin); global $adb; global $current_user; global $theme; $theme_path = "themes/" . $theme . "/"; $image_path = $theme_path . "images/"; $search_val = $query_string; $search_module = $_REQUEST['search_module']; if ($curModule == 'Home') { getSearchModulesComboList($search_module); } $i = 0; $moduleRecordCount = array(); foreach ($object_array as $module => $object_name) { if ($curModule == 'Home' || $curModule == $module && !empty($_REQUEST['ajax'])) { $focus = CRMEntity::getInstance($module);
/** END */ function process(Mobile_API_Request $request) { global $current_user, $current_language, $displayed_modules; global $adb, $theme; $wsResponse = parent::process($request); $response = false; if ($wsResponse->hasError()) { $response = $wsResponse; } else { $current_user = $this->getActiveUser(); $response = false; $total_record_count = 0; $query_string = trim($_REQUEST['query_string']); $curModule = 'Home'; $search_tag = vtlib_purify($_REQUEST['search_tag']); //get language $current_user = $this->getActiveUser(); $CRM_Version = Mobile::config('crm_version'); if ($CRM_Version != '5.2.1') { //for v5.3.0 use User's Settings include 'user_privileges/user_privileges_' . $current_user->id . '.php'; if (isset($user_info['language'])) { $this->activeUser->column_fields['language'] = $user_info['language']; } else { $this->activeUser->column_fields['language'] = 'en_us'; } } else { //for v5.2.1 use default language global $adb; $queryResult = $adb->pquery("SELECT prefix FROM vtiger_language WHERE isdefault =1", array()); $this->activeUser->column_fields['language'] = $adb->query_result($queryResult, 0, 'prefix'); } $current_language = $this->activeUser->column_fields['language']; include dirname(__FILE__) . '/../language/' . $current_language . '.lang.php'; function getSearchModules($filter = array()) { global $adb; // vtlib customization: Ignore disabled modules. //$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)'; $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) and vtiger_tab.presence != 1 and vtiger_field.presence in (0,2)'; // END $result = $adb->pquery($sql, array()); while ($module_result = $adb->fetch_array($result)) { $modulename = $module_result['name']; // Do we need to filter the module selection? if (!empty($filter) && is_array($filter) && !in_array($modulename, $filter)) { continue; } // END if ($modulename != 'Calendar') { $return_arr[$modulename] = $modulename; } else { $return_arr[$modulename] = 'Activity'; } } return $return_arr; } if (isset($query_string) && $query_string != '') { // limit search to modules enabled for mobile $search_onlyin = vtlib_purify($_REQUEST['search_onlyin']); if (!empty($search_onlyin)) { $search_onlyin = explode(',', $search_onlyin); //prevent manipulations if (array_values($search_onlyin) != array_values($displayed_modules)) { //do standard search $search_onlyin = $displayed_modules; } } else { $search_onlyin = $displayed_modules; } // Save the selection for future use (UnifiedSearchModules.php) $_SESSION['__UnifiedSearch_SelectedModules__'] = $search_onlyin; // END $object_array = getSearchModules($search_onlyin); $search_val = $query_string; $search_module = $_REQUEST['search_module']; $i = 0; $moduleRecordCount = array(); foreach ($object_array as $module => $object_name) { if ($curModule == 'Home' || $curModule == $module && !empty($_REQUEST['ajax'])) { $focus = CRMEntity::getInstance($module); if (isPermitted($module, "index") == "yes") { $listquery = getListQuery($module); $oCustomView = ''; $oCustomView = new CustomView($module); //Instead of getting current customview id, use cvid of All so that all entities will be found //$viewid = $oCustomView->getViewId($module); $cv_res = $adb->pquery("select cvid from vtiger_customview where viewname='All' and entitytype=?", array($module)); $viewid = $adb->query_result($cv_res, 0, 'cvid'); $listquery = $oCustomView->getModifiedCvListQuery($viewid, $listquery, $module); if ($module == "Calendar") { if (!isset($oCustomView->list_fields['Close'])) { $oCustomView->list_fields['Close'] = array('activity' => 'status'); } if (!isset($oCustomView->list_fields_name['Close'])) { $oCustomView->list_fields_name['Close'] = 'status'; } } if ($search_module != '' || $search_tag != '') { //This is for Tag search $where = getTagWhere($search_val, $current_user->id); $search_msg = $app_strings['LBL_TAG_SEARCH']; $search_msg .= "<b>" . to_html($search_val) . "</b>"; } else { //This is for Global search $where = getUnifiedWhere($listquery, $module, $search_val); $search_msg = $app_strings['LBL_SEARCH_RESULTS_FOR']; $search_msg .= "<b>" . htmlentities($search_val, ENT_QUOTES, $default_charset) . "</b>"; } if ($where != '') { $listquery .= ' and (' . $where . ')'; } if (!(isset($_REQUEST['ajax']) && $_REQUEST['ajax'] != '')) { $count_result = $adb->query($listquery); $noofrows = $adb->num_rows($count_result); } else { $noofrows = vtlib_purify($_REQUEST['recordCount']); } $moduleRecordCount[$module]['count'] = $noofrows; global $list_max_entries_per_page; if (!empty($_REQUEST['start'])) { $start = $_REQUEST['start']; if ($start == 'last') { $count_result = $adb->query(mkCountQuery($listquery)); $noofrows = $adb->query_result($count_result, 0, "count"); if ($noofrows > 0) { $start = ceil($noofrows / $list_max_entries_per_page); } } if (!is_numeric($start)) { $start = 1; } elseif ($start < 0) { $start = 1; } $start = ceil($start); } else { $start = 1; } $navigation_array = VT_getSimpleNavigationValues($start, $list_max_entries_per_page, $noofrows); $limitStartRecord = ($navigation_array['start'] - 1) * $list_max_entries_per_page; if ($adb->dbType == "pgsql") { $listquery = $listquery . " OFFSET {$limitStartRecord} LIMIT {$list_max_entries_per_page}"; } else { $listquery = $listquery . " LIMIT {$limitStartRecord}, {$list_max_entries_per_page}"; } $list_result = $adb->query($listquery); $listview_entries = $adb->pquery($listquery, array()); $entity = "select id from vtiger_ws_entity where ismodule=1 and name =?"; $ws_entity = $adb->pquery($entity, array($module)); $ws_entity2 = $adb->query_result($ws_entity, 0, 'id'); $filde = "select fieldname,entityidfield from vtiger_entityname where modulename =?"; $ws_entity1 = $adb->pquery($filde, array($module)); $fieldname = $adb->query_result($ws_entity1, 0, 'fieldname'); $entityidfield = $adb->query_result($ws_entity1, 0, 'entityidfield'); $firstname = explode(',', $fieldname); $noofrows = $adb->num_rows($listview_entries); //for new GUI for ($i = 0; $i < $noofrows; $i++) { $lstcontent[$module][$i]['firstname'] = $adb->query_result($listview_entries, $i, $firstname[0]); $lstcontent[$module][$i]['lastname'] = $adb->query_result($listview_entries, $i, $firstname[1]); if ($module == 'Calendar') { $eventtask = $adb->query_result($listview_entries, $i, 'activitytype'); if ($acttype != 'Task') { $ws_entity2 = 18; } else { $ws_entity2 = 1; } } $lstcontent[$module][$i]['id'] = $ws_entity2 . "x" . $adb->query_result($listview_entries, $i, 'crmid'); } //get translated module name $modullabel[$module] = $this->cachedModule($module)->label(); $i++; } } } //Added to display the Total record count } //end search $viewer = new Mobile_UI_Viewer(); $viewer->assign("MOD", $mod_strings); $viewer->assign("MODULE", $module); $viewer->assign("TAG_SEARCH", $search_tag); $viewer->assign("SEARCH_MODULE", vtlib_purify($_REQUEST['search_module'])); $viewer->assign("SINGLE_MOD", $module); $viewer->assign("SEARCH_STRING", htmlentities($search_val, ENT_QUOTES, $default_charset)); $viewer->assign('_MODULES', $modules); $viewer->assign('LISTHEADER', $listview_header); $viewer->assign('LISTENTITY', $lstcontent); $viewer->assign('MODLABEL', $modullabel); $viewer->assign('HEADERCOUNT', count($listview_header)); $viewer->assign("SEARCH_CRITERIA", "( {$noofrows} )" . $search_msg); $response = $viewer->process('generic/GlobalSearch.tpl'); } return $response; }
********************************************************************************/ require_once 'include/logging.php'; //require_once('modules/Home/language/en_us.lang.php'); require_once 'include/database/PearDatabase.php'; require_once 'modules/CustomView/CustomView.php'; require_once 'include/DatabaseUtil.php'; require_once 'include/CRMSmarty.php'; global $mod_strings; global $list_max_entries_per_page; $total_record_count = 0; $query_string = trim($_REQUEST['query_string']); //var_dump($query_string); //exit(); if (isset($query_string) && $query_string != '') { //module => object $object_array = getSearchModules(); foreach ($object_array as $curr_module => $curr_object) { if (is_file("modules/{$curr_module}/{$curr_object}.php")) { require_once "modules/{$curr_module}/{$curr_object}.php"; } else { unset($object_array[$curr_module]); } } global $adb; global $current_user; global $current_language; if (empty($current_language)) { $current_language = "zh_cn"; } global $theme; $theme_path = "themes/" . $theme . "/";
/** END */ function process(Mobile_API_Request $request) { $wsResponse = parent::process($request); $response = false; if ($wsResponse->hasError()) { $response = $wsResponse; } else { $wsResponseResult = $wsResponse->getResult(); $tabid = getTabid($wsResponseResult['module']); $CATEGORY = getParentTabFromModule($wsResponseResult['module']); //serch $total_record_count = 0; $query_string = trim($_REQUEST['query_string']); $curModule = 'Home'; $search_tag = vtlib_purify($_REQUEST['search_tag']); function getSearchModules($filter = array()) { global $adb; // vtlib customization: Ignore disabled modules. //$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)'; $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) and vtiger_tab.presence != 1 and vtiger_field.presence in (0,2)'; // END $result = $adb->pquery($sql, array()); while ($module_result = $adb->fetch_array($result)) { $modulename = $module_result['name']; // Do we need to filter the module selection? if (!empty($filter) && is_array($filter) && !in_array($modulename, $filter)) { continue; } // END if ($modulename != 'Calendar') { $return_arr[$modulename] = $modulename; } else { $return_arr[$modulename] = 'Activity'; } } return $return_arr; } if (isset($query_string) && $query_string != '') { // Was the search limited by user for specific modules? $search_onlyin = $_REQUEST['search_onlyin']; if (!empty($search_onlyin) && $search_onlyin != '--USESELECTED--') { $search_onlyin = explode(',', $search_onlyin); } else { if ($search_onlyin == '--USESELECTED--') { $search_onlyin = $_SESSION['__UnifiedSearch_SelectedModules__']; } else { $search_onlyin = array(); } } // Save the selection for futur use (UnifiedSearchModules.php) $_SESSION['__UnifiedSearch_SelectedModules__'] = $search_onlyin; // END $object_array = getSearchModules($search_onlyin); global $adb; global $current_user; global $theme; $theme_path = "themes/" . $theme . "/"; $image_path = $theme_path . "images/"; $search_val = $query_string; $search_module = $_REQUEST['search_module']; $i = 0; $moduleRecordCount = array(); foreach ($object_array as $module => $object_name) { if ($curModule == 'Home' || $curModule == $module && !empty($_REQUEST['ajax'])) { $focus = CRMEntity::getInstance($module); if (isPermitted($module, "index") == "yes") { $smarty = new vtigerCRM_Smarty(); global $mod_strings; global $app_strings; $smarty->assign("MOD", $mod_strings); $smarty->assign("APP", $app_strings); $smarty->assign("THEME", $theme); $smarty->assign("IMAGE_PATH", $image_path); $smarty->assign("MODULE", $module); $smarty->assign("TAG_SEARCH", $search_tag); $smarty->assign("SEARCH_MODULE", vtlib_purify($_REQUEST['search_module'])); $smarty->assign("SINGLE_MOD", $module); $smarty->assign("SEARCH_STRING", htmlentities($search_val, ENT_QUOTES, $default_charset)); $listquery = getListQuery($module); $oCustomView = ''; $oCustomView = new CustomView($module); //Instead of getting current customview id, use cvid of All so that all entities will be found //$viewid = $oCustomView->getViewId($module); $cv_res = $adb->pquery("select cvid from vtiger_customview where viewname='All' and entitytype=?", array($module)); $viewid = $adb->query_result($cv_res, 0, 'cvid'); $listquery = $oCustomView->getModifiedCvListQuery($viewid, $listquery, $module); if ($module == "Calendar") { if (!isset($oCustomView->list_fields['Close'])) { $oCustomView->list_fields['Close'] = array('activity' => 'status'); } if (!isset($oCustomView->list_fields_name['Close'])) { $oCustomView->list_fields_name['Close'] = 'status'; } } if ($search_module != '' || $search_tag != '') { //This is for Tag search $where = getTagWhere($search_val, $current_user->id); $search_msg = $app_strings['LBL_TAG_SEARCH']; $search_msg .= "<b>" . to_html($search_val) . "</b>"; } else { //This is for Global search $where = getUnifiedWhere($listquery, $module, $search_val); $search_msg = $app_strings['LBL_SEARCH_RESULTS_FOR']; $search_msg .= "<b>" . htmlentities($search_val, ENT_QUOTES, $default_charset) . "</b>"; } if ($where != '') { $listquery .= ' and (' . $where . ')'; } if (!(isset($_REQUEST['ajax']) && $_REQUEST['ajax'] != '')) { $count_result = $adb->query($listquery); $noofrows = $adb->num_rows($count_result); } else { $noofrows = vtlib_purify($_REQUEST['recordCount']); } $moduleRecordCount[$module]['count'] = $noofrows; global $list_max_entries_per_page; if (!empty($_REQUEST['start'])) { $start = $_REQUEST['start']; if ($start == 'last') { $count_result = $adb->query(mkCountQuery($listquery)); $noofrows = $adb->query_result($count_result, 0, "count"); if ($noofrows > 0) { $start = ceil($noofrows / $list_max_entries_per_page); } } if (!is_numeric($start)) { $start = 1; } elseif ($start < 0) { $start = 1; } $start = ceil($start); } else { $start = 1; } $navigation_array = VT_getSimpleNavigationValues($start, $list_max_entries_per_page, $noofrows); $limitStartRecord = ($navigation_array['start'] - 1) * $list_max_entries_per_page; if ($adb->dbType == "pgsql") { $listquery = $listquery . " OFFSET {$limitStartRecord} LIMIT {$list_max_entries_per_page}"; } else { $listquery = $listquery . " LIMIT {$limitStartRecord}, {$list_max_entries_per_page}"; } $list_result = $adb->query($listquery); $listview_entries = $adb->pquery($listquery, array()); $entity = "select id from vtiger_ws_entity where ismodule=1 and name =?"; $ws_entity = $adb->pquery($entity, array($module)); $ws_entity2 = $adb->query_result($ws_entity, 0, 'id'); $filde = "select fieldname,entityidfield from vtiger_entityname where modulename =?"; $ws_entity1 = $adb->pquery($filde, array($module)); $fieldname = $adb->query_result($ws_entity1, 0, 'fieldname'); $entityidfield = $adb->query_result($ws_entity1, 0, 'entityidfield'); $firstname = explode(',', $fieldname); $noofrows = $adb->num_rows($listview_entries); $lstresult = array(); for ($i = 0; $i < $noofrows; $i++) { $lstresult[$i]['firstname'] = $adb->query_result($listview_entries, $i, $firstname[0]); $lstresult[$i]['lastname'] = $adb->query_result($listview_entries, $i, $firstname[1]); $lstresult[$i]['id'] = $ws_entity2 . "x" . $adb->query_result($listview_entries, $i, 'crmid'); } //Do not display the Header if there are no entires in listview_entries if (count($listview_entries) > 0) { $display_header = 1; } else { $display_header = 0; } $smarty->assign("LISTHEADER", $listview_header); $smarty->assign("LISTENTITY", $lstresult); $smarty->assign("DISPLAYHEADER", $display_header); $smarty->assign("HEADERCOUNT", count($listview_header)); $smarty->assign("searchstring", $query_string); $smarty->assign("SEARCH_CRITERIA", "( {$noofrows} )" . $search_msg); $smarty->display("UnifiedSearchAjax1.tpl"); unset($_SESSION['lvs'][$module]); $i++; } } } //Added to display the Total record count } //end search $viewer = new Mobile_UI_Viewer(); $viewer->assign('_MODULE', $this->cachedModule($wsResponseResult['module'])); $viewer->assign('_RECORDS', Mobile_UI_ModuleRecordModel::buildModelsFromResponse($wsResponseResult['records'])); } return $response; }