public static function render($userInputObject, $user) { global $list_max_entries_per_page; $adb = PearDatabase::getInstance(); $viewer = new Import_UI_Viewer(); $ownerId = $userInputObject->get('foruser'); $owner = new Users(); $owner->id = $ownerId; $owner->retrieve_entity_info($ownerId, 'Users'); if (!is_admin($user) && $user->id != $owner->id) { $viewer->display('OperationNotPermitted.tpl', 'Vtiger'); exit; } $userDBTableName = Import_Utils::getDbTableName($owner); $moduleName = $userInputObject->get('module'); $moduleMeta = self::getModuleMeta($moduleName, $user); $result = $adb->query('SELECT recordid FROM ' . $userDBTableName . ' WHERE status is NOT NULL AND recordid IS NOT NULL'); $noOfRecords = $adb->num_rows($result); $importedRecordIds = array(); for ($i = 0; $i < $noOfRecords; ++$i) { $importedRecordIds[] = $adb->query_result($result, $i, 'recordid'); } if (count($importedRecordIds) == 0) { $importedRecordIds[] = 0; } $focus = CRMEntity::getInstance($moduleName); $queryGenerator = new QueryGenerator($moduleName, $user); $customView = new CustomView($moduleName); $viewId = $customView->getViewIdByName('All', $moduleName); $queryGenerator->initForCustomViewById($viewId); $list_query = $queryGenerator->getQuery(); // Fetch only last imported records $list_query .= ' AND ' . $focus->table_name . '.' . $focus->table_index . ' IN (' . implode(',', $importedRecordIds) . ')'; if (PerformancePrefs::getBoolean('LISTVIEW_COMPUTE_PAGE_COUNT', false) === true) { $count_result = $adb->query(mkCountQuery($list_query)); $noofrows = $adb->query_result($count_result, 0, "count"); } else { $noofrows = null; } $start = ListViewSession::getRequestCurrentPage($moduleName, $list_query, $viewId, false); $navigation_array = VT_getSimpleNavigationValues($start, $list_max_entries_per_page, $noofrows); $limit_start_rec = ($start - 1) * $list_max_entries_per_page; $list_result = $adb->pquery($list_query . " LIMIT {$limit_start_rec}, {$list_max_entries_per_page}", array()); $recordListRangeMsg = getRecordRangeMessage($list_result, $limit_start_rec, $noofrows); $viewer->assign('recordListRange', $recordListRangeMsg); $controller = new ListViewController($adb, $user, $queryGenerator); $listview_header = $controller->getListViewHeader($focus, $moduleName, $url_string, $sorder, $order_by, true); $listview_entries = $controller->getListViewEntries($focus, $moduleName, $list_result, $navigation_array, true); $viewer->assign('CURRENT_PAGE', $start); $viewer->assign('LISTHEADER', $listview_header); $viewer->assign('LISTENTITY', $listview_entries); $viewer->assign('FOR_MODULE', $moduleName); $viewer->assign('FOR_USER', $ownerId); $isAjax = $userInputObject->get('ajax'); if (!empty($isAjax)) { echo $viewer->fetch('ListViewEntries.tpl'); } else { $viewer->display('ImportListView.tpl'); } }
$list_query .= ' ORDER BY ' . $tablename . $order_by . ' ' . $sorder; } } ///Postgres 8 fixes if ($adb->dbType == "pgsql") { $list_query = fixPostgresQuery($list_query, $log, 0); } if (PerformancePrefs::getBoolean('LISTVIEW_COMPUTE_PAGE_COUNT', false) === true) { $count_result = $adb->query(mkCountQuery($list_query)); $noofrows = $adb->query_result($count_result, 0, "count"); } else { $noofrows = null; } $queryMode = isset($_REQUEST['query']) && $_REQUEST['query'] == 'true'; $start = ListViewSession::getRequestCurrentPage($currentModule, $list_query, $viewid, $queryMode); $navigation_array = VT_getSimpleNavigationValues($start, $list_max_entries_per_page, $noofrows); $limit_start_rec = ($start - 1) * $list_max_entries_per_page; if ($adb->dbType == "pgsql") { $list_result = $adb->pquery($list_query . " OFFSET {$limit_start_rec} LIMIT {$list_max_entries_per_page}", array()); } else { $list_result = $adb->pquery($list_query . " LIMIT {$limit_start_rec}, {$list_max_entries_per_page}", array()); } $recordListRangeMsg = getRecordRangeMessage($list_result, $limit_start_rec); $smarty->assign('recordListRange', $recordListRangeMsg); //Retreive the List View Table Header if ($viewid != '') { $url_string .= "&viewname=" . $viewid; } $listview_header = getListViewHeader($focus, "SalesOrder", $url_string, $sorder, $order_by, "", $oCustomView); $smarty->assign("LISTHEADER", $listview_header); $listview_header_search = getSearchListHeaderValues($focus, "SalesOrder", $url_string, $sorder, $order_by, "", $oCustomView);
/** Function to display the Services which are related to the PriceBook * @param string $query - query to get the list of products which are related to the current PriceBook * @param object $focus - PriceBook object which contains all the information of the current PriceBook * @param string $returnset - return_module, return_action and return_id which are sequenced with & to pass to the URL which is optional * return array $return_data which will be formed like array('header'=>$header,'entries'=>$entries_list) where as $header contains all the header columns and $entries_list will contain all the Service entries */ function getPriceBookRelatedServices($query, $focus, $returnset = '') { global $log; $log->debug("Entering getPriceBookRelatedServices(" . $query . "," . get_class($focus) . "," . $returnset . ") method ..."); global $adb; global $app_strings; global $current_language, $current_user; $current_module_strings = return_module_language($current_language, 'Services'); global $list_max_entries_per_page; global $urlPrefix; global $theme; $pricebook_id = $_REQUEST['record']; $theme_path = "themes/" . $theme . "/"; $image_path = $theme_path . "images/"; $computeCount = $_REQUEST['withCount']; if (PerformancePrefs::getBoolean('LISTVIEW_COMPUTE_PAGE_COUNT', false) === true || (bool) $computeCount == true) { $noofrows = $adb->query_result($adb->query(mkCountQuery($query)), 0, 'count'); } else { $noofrows = null; } $module = 'PriceBooks'; $relatedmodule = 'Services'; if (!$_SESSION['rlvs'][$module][$relatedmodule]) { $modObj = new ListViewSession(); $modObj->sortby = $focus->default_order_by; $modObj->sorder = $focus->default_sort_order; $_SESSION['rlvs'][$module][$relatedmodule] = get_object_vars($modObj); } if (isset($_REQUEST['relmodule']) && $_REQUEST['relmodule'] != '' && $_REQUEST['relmodule'] == $relatedmodule) { $relmodule = vtlib_purify($_REQUEST['relmodule']); if ($_SESSION['rlvs'][$module][$relmodule]) { setSessionVar($_SESSION['rlvs'][$module][$relmodule], $noofrows, $list_max_entries_per_page, $module, $relmodule); } } global $relationId; $start = RelatedListViewSession::getRequestCurrentPage($relationId, $query); $navigation_array = VT_getSimpleNavigationValues($start, $list_max_entries_per_page, $noofrows); $limit_start_rec = ($start - 1) * $list_max_entries_per_page; if ($adb->dbType == "pgsql") { $list_result = $adb->pquery($query . " OFFSET {$limit_start_rec} LIMIT {$list_max_entries_per_page}", array()); } else { $list_result = $adb->pquery($query . " LIMIT {$limit_start_rec}, {$list_max_entries_per_page}", array()); } $header = array(); $header[] = $current_module_strings['LBL_LIST_SERVICE_NAME']; if (getFieldVisibilityPermission('Services', $current_user->id, 'unit_price') == '0') { $header[] = $current_module_strings['LBL_SERVICE_UNIT_PRICE']; } $header[] = $current_module_strings['LBL_PB_LIST_PRICE']; if (isPermitted("PriceBooks", "EditView", "") == 'yes' || isPermitted("PriceBooks", "Delete", "") == 'yes') { $header[] = $app_strings['LBL_ACTION']; } $currency_id = $focus->column_fields['currency_id']; $numRows = $adb->num_rows($list_result); for ($i = 0; $i < $numRows; $i++) { $entity_id = $adb->query_result($list_result, $i, "crmid"); $unit_price = $adb->query_result($list_result, $i, "unit_price"); if ($currency_id != null) { $prod_prices = getPricesForProducts($currency_id, array($entity_id), 'Services'); $unit_price = $prod_prices[$entity_id]; } $listprice = $adb->query_result($list_result, $i, "listprice"); $field_name = $entity_id . "_listprice"; $entries = array(); $entries[] = textlength_check($adb->query_result($list_result, $i, "servicename")); if (getFieldVisibilityPermission('Services', $current_user->id, 'unit_price') == '0') { $entries[] = CurrencyField::convertToUserFormat($unit_price, null, true); } $entries[] = CurrencyField::convertToUserFormat($listprice, null, true); $action = ""; if (isPermitted("PriceBooks", "EditView", "") == 'yes' && isPermitted('Services', 'EditView', $entity_id) == 'yes') { $action .= '<img style="cursor:pointer;" src="themes/images/editfield.gif" border="0" onClick="fnvshobj(this,\'editlistprice\'),editProductListPrice(\'' . $entity_id . '\',\'' . $pricebook_id . '\',\'' . $listprice . '\')" alt="' . $app_strings["LBL_EDIT_BUTTON"] . '" title="' . $app_strings["LBL_EDIT_BUTTON"] . '"/>'; } else { $action .= '<img src="' . vtiger_imageurl('blank.gif', $theme) . '" border="0" />'; } if (isPermitted("PriceBooks", "Delete", "") == 'yes' && isPermitted('Services', 'Delete', $entity_id) == 'yes') { if ($action != "") { $action .= ' | '; } $action .= '<img src="themes/images/delete.gif" onclick="if(confirm(\'' . $app_strings['ARE_YOU_SURE'] . '\')) deletePriceBookProductRel(' . $entity_id . ',' . $pricebook_id . ');" alt="' . $app_strings["LBL_DELETE"] . '" title="' . $app_strings["LBL_DELETE"] . '" style="cursor:pointer;" border="0">'; } if ($action != "") { $entries[] = $action; } $entries_list[] = $entries; } $navigationOutput[] = getRecordRangeMessage($list_result, $limit_start_rec, $noofrows); $navigationOutput[] = getRelatedTableHeaderNavigation($navigation_array, '', $module, $relatedmodule, $focus->id); $return_data = array('header' => $header, 'entries' => $entries_list, 'navigation' => $navigationOutput); $log->debug("Exiting getPriceBookRelatedServices method ..."); return $return_data; }
} if ($folder_id == $request_folderid) { $start[$folder_id] = 1; if (!empty($_REQUEST['start'])) { $start[$folder_id] = ListViewSession::getRequestStartPage(); if ($start[$folder_id] == 'last') { if ($num_records > 0) { $start[$folder_id] = ceil($num_records / $max_entries_per_page); } } if (!is_numeric($start[$folder_id])) { $start[$folder_id] = 1; } } } $navigation_array = VT_getSimpleNavigationValues($start[$folder_id], $max_entries_per_page, $num_records); if ($folder_id == $request_folderid) { if (!is_array($_SESSION['lvs'][$currentModule]['start'])) { $_SESSION['lvs'][$currentModule]['start'] = array(); } $_SESSION['lvs'][$currentModule]['start'][$folder_id] = $start[$folder_id]; } $limit_start_rec = ($start[$folder_id] - 1) * $max_entries_per_page; if ($adb->dbType == "pgsql") { $list_result = $adb->pquery($query . " OFFSET {$limit_start_rec} LIMIT {$max_entries_per_page}", array()); } else { $list_result = $adb->pquery($query . " LIMIT {$limit_start_rec}, {$max_entries_per_page}", array()); } //navigation end $folder_details = array(); $folderid = $adb->query_result($result, $i, "folderid");
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; }
/** * Function to get todos list scheduled between specified dates * @param array $calendar - collection of objects and strings * @param string $start_date - date string * @param string $end_date - date string * @param string $info - string 'listcnt' or empty string. if 'listcnt' means it returns no. of todos and no. of pending todos in array format else it returns todos list in array format * return array $Entries - todolists in array format */ function getTodoList(&$calendar, $start_date, $end_date, $info = '') { global $log, $app_strings, $theme; $Entries = array(); $category = getParentTab(); global $adb, $current_user, $mod_strings, $cal_log, $list_max_entries_per_page; $cal_log->debug("Entering getTodoList() method..."); require 'user_privileges/user_privileges_' . $current_user->id . '.php'; require 'user_privileges/sharing_privileges_' . $current_user->id . '.php'; $userNameSql = getSqlForNameInDisplayFormat(array('first_name' => 'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'), 'Users'); $query = "SELECT vtiger_groups.groupname, {$userNameSql} as user_name, vtiger_crmentity.crmid, vtiger_cntactivityrel.contactid,\n\t\t\t\tvtiger_activity.* FROM vtiger_activity\n INNER JOIN vtiger_crmentity\n\t\t\t\t\tON vtiger_crmentity.crmid = vtiger_activity.activityid\n LEFT JOIN vtiger_cntactivityrel\n\t\t\t\t\tON vtiger_cntactivityrel.activityid = vtiger_activity.activityid\n\t\t\t\tLEFT JOIN vtiger_groups\n\t\t\t\t\tON vtiger_groups.groupid = vtiger_crmentity.smownerid\n\t\t\t\tLEFT JOIN vtiger_users\n\t\t\t\t\tON vtiger_users.id = vtiger_crmentity.smownerid"; $query .= getNonAdminAccessControlQuery('Calendar', $current_user); $query .= "WHERE vtiger_crmentity.deleted = 0 AND vtiger_activity.activitytype = 'Task'" . " AND ((CAST(CONCAT(date_start,' ',time_start) AS DATETIME) >= ? AND CAST(CONCAT(date_start,' ',time_start) AS DATETIME) <= ?)\n\t\t\t\t\t\t\tOR\t(CAST(CONCAT(due_date,' ',time_end) AS DATETIME) >= ? AND CAST(CONCAT(due_date,' ',time_end) AS DATETIME) <= ? )\n\t\t\t\t\t\t\tOR\t(CAST(CONCAT(date_start,' ',time_start) AS DATETIME) <= ? AND CAST(CONCAT(due_date,' ',time_end) AS DATETIME) >= ?)\n\t\t\t\t\t\t)"; $list_query = $query . " AND vtiger_crmentity.smownerid = " . $current_user->id; $startDate = new DateTimeField($start_date . ' 00:00'); $endDate = new DateTimeField($end_date . ' 23:59'); $params = $info_params = array($startDate->getDBInsertDateTimeValue(), $endDate->getDBInsertDateTimeValue(), $startDate->getDBInsertDateTimeValue(), $endDate->getDBInsertDateTimeValue(), $startDate->getDBInsertDateTimeValue(), $endDate->getDBInsertDateTimeValue()); if ($info != '') { //added to fix #4816 $groupids = explode(",", fetchUserGroupids($current_user->id)); if (count($groupids) > 0 && !is_admin($current_user)) { $com_q = " AND (vtiger_crmentity.smownerid = ?\n\t\t\t\t\tOR vtiger_groups.groupid in (" . generateQuestionMarks($groupids) . "))"; array_push($info_params, $current_user->id); array_push($info_params, $groupids); } elseif (!is_admin($current_user)) { $com_q = " AND vtiger_crmentity.smownerid = ?"; array_push($info_params, $current_user->id); } //end $pending_query = $query . " AND (vtiger_activity.status != 'Completed')" . $com_q; $total_q = $query . "" . $com_q; $total_res = $adb->pquery($total_q, $info_params); $total = $adb->num_rows($total_res); $res = $adb->pquery($pending_query, $info_params); $pending_rows = $adb->num_rows($res); $cal_log->debug("Exiting getTodoList() method..."); return array('totaltodo' => $total, 'pendingtodo' => $pending_rows); } $group_cond = ''; $group_cond .= " ORDER BY vtiger_activity.date_start,vtiger_activity.time_start ASC"; if (isset($_REQUEST['start']) && $_REQUEST['start'] != '') { $start = vtlib_purify($_REQUEST['start']); } else { $start = 1; } //T6477 changes if (PerformancePrefs::getBoolean('LISTVIEW_COMPUTE_PAGE_COUNT', false) === true) { $count_res = $adb->pquery(mkCountQuery($query), $params); $total_rec_count = $adb->query_result($count_res, 0, 'count'); } else { $total_rec_count = null; } $navigation_array = VT_getSimpleNavigationValues($start, $list_max_entries_per_page, $total_rec_count); $start_rec = ($start - 1) * $list_max_entries_per_page; $end_rec = $navigation_array['end_val']; $list_query = $adb->convert2Sql($query, $params); $_SESSION['Calendar_listquery'] = $list_query; if ($start_rec < 0) { $start_rec = 0; } //ends $query .= $group_cond . " limit {$start_rec},{$list_max_entries_per_page}"; $result = $adb->pquery($query, $params); $rows = $adb->num_rows($result); $c = 0; if ($start > 1) { $c = ($start - 1) * $list_max_entries_per_page; } for ($i = 0; $i < $rows; $i++) { $element = array(); $contact_name = ''; $element['no'] = $c + 1; $more_link = ""; $start_time = $adb->query_result($result, $i, "time_start"); $date_start = $adb->query_result($result, $i, "date_start"); $due_date = $adb->query_result($result, $i, "due_date"); $date = new DateTimeField($date_start . ' ' . $start_time); $endDate = new DateTimeField($due_date); if (!empty($start_time)) { $start_time = $date->getDisplayTime(); } $format = $calendar['calendar']->hour_format; $value = getaddEventPopupTime($start_time, $start_time, $format); $element['starttime'] = $value['starthour'] . ':' . $value['startmin'] . '' . $value['startfmt']; $element['startdate'] = $date->getDisplayDate(); $element['duedate'] = $endDate->getDisplayDate(); $id = $adb->query_result($result, $i, "activityid"); $subject = $adb->query_result($result, $i, "subject"); $more_link = "<a href='index.php?action=DetailView&module=Calendar&record=" . $id . "&activity_mode=Task&viewtype=calendar&parenttab=" . $category . "' class='webMnu'>" . $subject . "</a>"; $element['tododetail'] = $more_link; if (getFieldVisibilityPermission('Calendar', $current_user->id, 'taskstatus') == '0') { $taskstatus = $adb->query_result($result, $i, "status"); if (!$is_admin && $taskstatus != '') { $roleid = $current_user->roleid; $roleids = array(); $subrole = getRoleSubordinates($roleid); if (count($subrole) > 0) { $roleids = $subrole; } array_push($roleids, $roleid); //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... $sql = "select * from vtiger_taskstatus where taskstatus=?"; $res = $adb->pquery($sql, array(decode_html($taskstatus))); $picklistvalueid = $adb->query_result($res, 0, 'picklist_valueid'); if ($picklistvalueid != null) { $pick_query = "select * from vtiger_role2picklist where picklistvalueid={$picklistvalueid} and roleid in (" . generateQuestionMarks($roleids) . ")"; $res_val = $adb->pquery($pick_query, array($roleids)); $num_val = $adb->num_rows($res_val); } if ($num_val > 0) { $element['status'] = getTranslatedString(decode_html($taskstatus)); } else { $element['status'] = "<font color='red'>" . $app_strings['LBL_NOT_ACCESSIBLE'] . "</font>"; } } else { $element['status'] = getTranslatedString(decode_html($taskstatus)); } } if (isPermitted("Calendar", "EditView") == "yes" || isPermitted("Calendar", "Delete") == "yes") { $element['action'] = "<img onClick='getcalAction(this,\"taskcalAction\"," . $id . ",\"" . $calendar['view'] . "\",\"" . $calendar['calendar']->date_time->hour . "\",\"" . $calendar['calendar']->date_time->get_DB_formatted_date() . "\",\"todo\");' src='" . vtiger_imageurl('cal_event.jpg', $theme) . "' border='0'>"; } $assignedto = $adb->query_result($result, $i, "user_name"); if (!empty($assignedto)) { $element['assignedto'] = $assignedto; } else { $element['assignedto'] = $adb->query_result($result, $i, "groupname"); } $c++; $Entries[] = $element; } $ret_arr[0] = $Entries; $ret_arr[1] = $navigation_array; $cal_log->debug("Exiting getTodoList() method..."); return $ret_arr; }
/** 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; }
/** 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; }