function getWhereCondition($currentModule, $input = '') { global $log, $default_charset, $adb; global $column_array, $table_col_array, $mod_strings, $current_user; $log->debug("Entering getWhereCondition(" . $currentModule . ") method ..."); if (empty($input)) { $input = $_REQUEST; } if ($input['searchtype'] == 'advance') { $json = new Zend_Json(); $advft_criteria = $input['advft_criteria']; if (!empty($advft_criteria)) { $advft_criteria_decoded = $json->decode($advft_criteria); } $advft_criteria_groups = $input['advft_criteria_groups']; if (!empty($advft_criteria_groups)) { $advft_criteria_groups_decoded = $json->decode($advft_criteria_groups); } $advfilterlist = getAdvancedSearchCriteriaList($advft_criteria_decoded, $advft_criteria_groups_decoded, $currentModule); $adv_string = generateAdvancedSearchSql($advfilterlist); if (!empty($adv_string)) { $adv_string = '(' . $adv_string . ')'; } $where = $adv_string . '#@@#' . '&advft_criteria=' . $advft_criteria . '&advft_criteria_groups=' . $advft_criteria_groups . '&searchtype=advance'; } elseif ($input['type'] == 'dbrd') { $where = getdashboardcondition($input); } else { $where = Search($currentModule, $input); } $log->debug("Exiting getWhereCondition method ..."); return $where; }
function getWhereCondition($currentModule) { global $log, $default_charset, $adb; global $column_array, $table_col_array, $mod_strings, $current_user; $log->debug("Entering getWhereCondition(" . $currentModule . ") method ..."); if ($_REQUEST['searchtype'] == 'advance') { $adv_string = ''; $url_string = ''; if (isset($_REQUEST['search_cnt'])) { $tot_no_criteria = vtlib_purify($_REQUEST['search_cnt']); } if ($_REQUEST['matchtype'] == 'all') { $matchtype = "and"; } else { $matchtype = "or"; } for ($i = 0; $i < $tot_no_criteria; $i++) { if ($i == $tot_no_criteria - 1) { $matchtype = ""; } $table_colname = 'Fields' . $i; $search_condition = 'Condition' . $i; $search_value = 'Srch_value' . $i; list($tab_col_val, $typeofdata) = split("::::", $_REQUEST[$table_colname]); $tab_col = str_replace('\'', '', stripslashes($tab_col_val)); $srch_cond = str_replace('\'', '', stripslashes($_REQUEST[$search_condition])); $srch_val = $_REQUEST[$search_value]; $srch_val = function_exists(iconv) ? @iconv("UTF-8", $default_charset, $srch_val) : $srch_val; $url_string .= "&Fields" . $i . "=" . $tab_col . "&Condition" . $i . "=" . $srch_cond . "&Srch_value" . $i . "=" . urlencode($srch_val); $srch_val = $adb->sql_escape_string($srch_val); list($tab_name, $column_name) = split("[.]", $tab_col); $uitype = getUItype($currentModule, $column_name); //added to allow search in check box type fields(ex: product active. it will contain 0 or 1) using yes or no instead of 0 or 1 if ($uitype == 56) { if (strtolower($srch_val) == 'yes') { $adv_string .= " " . getSearch_criteria($srch_cond, "1", $tab_name . '.' . $column_name) . " " . $matchtype; } elseif (strtolower($srch_val) == 'no') { $adv_string .= " " . getSearch_criteria($srch_cond, "0", $tab_name . '.' . $column_name) . " " . $matchtype; } else { $adv_string .= " " . getSearch_criteria($srch_cond, "-1", $tab_name . '.' . $column_name) . " " . $matchtype; } } elseif ($uitype == 15 || $uitype == 16) { if (is_uitype($uitype, '_picklist_')) { // Get all the keys for the for the Picklist value $mod_keys = array_keys($mod_strings, $srch_val); if (sizeof($mod_keys) >= 1) { // Iterate on the keys, to get the first key which doesn't start with LBL_ (assuming it is not used in PickList) foreach ($mod_keys as $mod_idx => $mod_key) { $stridx = strpos($mod_key, 'LBL_'); // Use strict type comparision, refer strpos for more details if ($stridx !== 0) { $srch_val = $mod_key; if (getFieldVisibilityPermission("Calendar", $current_user->id, 'taskstatus') == '0' && ($tab_col == "vtiger_activity.status" || $tab_col == "vtiger_activity.eventstatus")) { if ($srch_cond == 'dcts' || $srch_cond == 'isn' || $srch_cond == 'is') { $re_cond = "and"; } else { $re_cond = "or"; } if ($srch_cond == 'is' && $srch_val != '') { $re_cond = "or"; } $adv_string .= " (" . getSearch_criteria($srch_cond, $srch_val, 'vtiger_activity.status') . " " . $re_cond; $adv_string .= " " . getSearch_criteria($srch_cond, $srch_val, 'vtiger_activity.eventstatus') . " )" . $matchtype; } else { $adv_string .= " " . getSearch_criteria($srch_cond, $srch_val, $tab_name . '.' . $column_name) . " " . $matchtype; } break; } else { //if the key contains the LBL, then return the original srch_val. $adv_string .= " " . getSearch_criteria($srch_cond, $srch_val, $tab_name . '.' . $column_name) . " " . $matchtype; } } } else { if (getFieldVisibilityPermission("Calendar", $current_user->id, 'taskstatus') == '0' && ($tab_col == "vtiger_activity.status" || $tab_col == "vtiger_activity.eventstatus")) { if ($srch_cond == 'dcts' || $srch_cond == 'isn' || $srch_cond == 'is') { $re_cond = "and"; } else { $re_cond = "or"; } if ($srch_cond == 'is' && $srch_val != '') { $re_cond = "or"; } $adv_string .= " (" . getSearch_criteria($srch_cond, $srch_val, 'vtiger_activity.status') . " " . $re_cond; $adv_string .= " " . getSearch_criteria($srch_cond, $srch_val, 'vtiger_activity.eventstatus') . " )" . $matchtype; } else { $adv_string .= " " . getSearch_criteria($srch_cond, $srch_val, $tab_col) . " " . $matchtype; } } } } elseif ($tab_col == "vtiger_crmentity.smownerid") { $adv_string .= " (" . getSearch_criteria($srch_cond, $srch_val, 'vtiger_users.user_name') . " or"; $adv_string .= " " . getSearch_criteria($srch_cond, $srch_val, 'vtiger_groups.groupname') . " )" . $matchtype; } elseif ($tab_col == "vtiger_cntactivityrel.contactid") { $adv_string .= " (" . getSearch_criteria($srch_cond, $srch_val, 'vtiger_contactdetails.firstname') . " or"; $adv_string .= " " . getSearch_criteria($srch_cond, $srch_val, 'vtiger_contactdetails.lastname') . " )" . $matchtype; } elseif (in_array($column_name, $column_array)) { $adv_string .= " " . getValuesforColumns($column_name, $srch_val, $srch_cond) . " " . $matchtype; } else { $adv_string .= " " . getSearch_criteria($srch_cond, $srch_val, $tab_col) . " " . $matchtype; } } $where = "(" . $adv_string . ")#@@#" . $url_string . "&searchtype=advance&search_cnt=" . $tot_no_criteria . "&matchtype=" . vtlib_purify($_REQUEST['matchtype']); } elseif ($_REQUEST['type'] == 'dbrd') { $where = getdashboardcondition(); } else { $where = Search($currentModule); } $log->debug("Exiting getWhereCondition method ..."); return $where; }