Esempio n. 1
0
 /** to get the realvalues for the given value
  * @param $tablename :: type string
  * @param $fieldname :: type string
  * @param $comparator :: type string
  * @param $value :: type string
  * @returns  $value as a string in the following format
  * 	  $tablename.$fieldname comparator
  */
 function getRealValues($tablename, $fieldname, $comparator, $value, $datatype)
 {
     //we have to add the fieldname/tablename.fieldname and the corresponding value (which we want) we can add here. So that when these LHS field comes then RHS value will be replaced for LHS in the where condition of the query
     $adb = PearDatabase::getInstance();
     $current_user = vglobal('current_user');
     $currentModule = vglobal('currentModule');
     $mod_strings = vglobal('mod_strings');
     //Added for proper check of contact name in advance filter
     if ($tablename == "vtiger_contactdetails" && $fieldname == "lastname") {
         $fieldname = "contactid";
     }
     $contactid = "vtiger_contactdetails.lastname";
     if ($currentModule != "Contacts" && $currentModule != "Leads" && $currentModule != 'Campaigns') {
         $contactid = getSqlForNameInDisplayFormat(array('lastname' => 'vtiger_contactdetails.lastname', 'firstname' => 'vtiger_contactdetails.firstname'), 'Contacts');
     }
     $change_table_field = array("product_id" => "vtiger_products.productname", "contactid" => 'trim(' . $contactid . ')', "contact_id" => 'trim(' . $contactid . ')', "accountid" => "", "account_id" => "", "vendorid" => "vtiger_vendor.vendorname", "vendor_id" => "vtiger_vendor.vendorname", "potentialid" => "vtiger_potential.potentialname", "vtiger_account.parentid" => "vtiger_account2.accountname", "quoteid" => "vtiger_quotes.subject", "salesorderid" => "vtiger_salesorder.subject", "campaignid" => "vtiger_campaign.campaignname", "vtiger_contactdetails.reportsto" => getSqlForNameInDisplayFormat(array('lastname' => 'vtiger_contactdetails2.lastname', 'firstname' => 'vtiger_contactdetails2.firstname'), 'Contacts'), "vtiger_pricebook.currency_id" => "vtiger_currency_info.currency_name");
     if ($fieldname == "smownerid" || $fieldname == 'modifiedby') {
         if ($fieldname == "smownerid") {
             $tableNameSuffix = '';
         } elseif ($fieldname == "modifiedby") {
             $tableNameSuffix = '2';
         }
         $userNameSql = getSqlForNameInDisplayFormat(array('first_name' => 'vtiger_users' . $tableNameSuffix . '.first_name', 'last_name' => 'vtiger_users' . $tableNameSuffix . '.last_name'), 'Users');
         $temp_value = '( trim(' . $userNameSql . ')' . $this->getAdvComparator($comparator, $value, $datatype);
         $temp_value .= " OR  vtiger_groups{$tableNameSuffix}.groupname" . $this->getAdvComparator($comparator, $value, $datatype) . ')';
         $value = $temp_value;
         // Hot fix: removed unbalanced closing bracket ")";
     } elseif ($fieldname == "inventorymanager") {
         $value = $tablename . "." . $fieldname . $this->getAdvComparator($comparator, getUserId_Ol($value), $datatype);
     } elseif ($change_table_field[$fieldname] != '') {
         //Added to handle special cases
         $value = $change_table_field[$fieldname] . $this->getAdvComparator($comparator, $value, $datatype);
     } elseif ($change_table_field[$tablename . "." . $fieldname] != '') {
         //Added to handle special cases
         $tmp_value = '';
         if (($comparator == 'e' || $comparator == 's' || $comparator == 'c') && trim($value) == '' || ($comparator == 'n' || $comparator == 'k') && trim($value) != '') {
             $tmp_value = $change_table_field[$tablename . "." . $fieldname] . ' IS NULL or ';
         }
         $value = $tmp_value . $change_table_field[$tablename . "." . $fieldname] . $this->getAdvComparator($comparator, $value, $datatype);
     } elseif ($fieldname == "crmid" && $tablename != 'vtiger_crmentity' || $fieldname == "parent_id" || $fieldname == 'parentid') {
         //For crmentity.crmid the control should not come here. This is only to get the related to modules
         $value = $this->getSalesRelatedName($comparator, $value, $datatype, $tablename, $fieldname);
     } else {
         //For checkbox type values, we have to convert yes/no as 1/0 to get the values
         $field_uitype = getUItype($this->customviewmodule, $fieldname);
         if ($field_uitype == 56) {
             if (strtolower($value) == 'yes') {
                 $value = 1;
             } elseif (strtolower($value) == 'no') {
                 $value = 0;
             }
         } else {
             if (is_uitype($field_uitype, '_picklist_')) {
                 /* Fix for tickets 4465 and 4629 */
                 // Get all the keys for the for the Picklist value
                 $mod_keys = array_keys($mod_strings, $value);
                 // 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) {
                         $value = $mod_key;
                         break;
                     }
                 }
             }
         }
         //added to fix the ticket
         if ($this->customviewmodule == "Calendar" && ($fieldname == "status" || $fieldname == "activitystatus")) {
             $value = " vtiger_activity.status " . $this->getAdvComparator($comparator, $value, $datatype);
         } elseif ($comparator == 'e' && (trim($value) == "NULL" || trim($value) == '')) {
             $value = '(' . $tablename . "." . $fieldname . ' IS NULL OR ' . $tablename . "." . $fieldname . ' = \'\')';
         } else {
             $value = $tablename . "." . $fieldname . $this->getAdvComparator($comparator, $value, $datatype);
         }
         //end
     }
     return $value;
 }
Esempio n. 2
0
 /** to get the realvalues for the given value   
  * @param $tablename :: type string 
  * @param $fieldname :: type string 
  * @param $comparator :: type string 
  * @param $value :: type string 
  * @returns  $value as a string in the following format
  *	  $tablename.$fieldname comparator
  */
 function getRealValues($tablename, $fieldname, $comparator, $value, $datatype)
 {
     //we have to add the fieldname/tablename.fieldname and the corresponding value (which we want) we can add here. So that when these LHS field comes then RHS value will be replaced for LHS in the where condition of the query
     global $adb, $mod_strings, $currentModule, $current_user;
     //Added for proper check of contact name in advance filter
     if ($tablename == "vtiger_contactdetails" && $fieldname == "lastname") {
         $fieldname = "contactid";
     }
     $contactid = "vtiger_contactdetails.lastname";
     if ($currentModule != "Contacts" && $currentModule != "Leads" && getFieldVisibilityPermission("Contacts", $current_user->id, 'firstname') == '0' && $currentModule != 'Campaigns') {
         $contactid = "concat(vtiger_contactdetails.lastname,' ',vtiger_contactdetails.firstname)";
     }
     $change_table_field = array("product_id" => "vtiger_products.productname", "contactid" => $contactid, "contact_id" => $contactid, "accountid" => "", "account_id" => "", "vendorid" => "vtiger_vendor.vendorname", "vendor_id" => "vtiger_vendor.vendorname", "potentialid" => "vtiger_potential.potentialname", "vtiger_account.parentid" => "vtiger_account2.accountname", "quoteid" => "vtiger_quotes.subject", "salesorderid" => "vtiger_salesorder.subject", "campaignid" => "vtiger_campaign.campaignname", "vtiger_contactdetails.reportsto" => "concat(vtiger_contactdetails2.lastname,' ',vtiger_contactdetails2.firstname)", "vtiger_pricebook.currency_id" => "vtiger_currency_info.currency_name");
     if ($fieldname == "smownerid") {
         $temp_value = "( vtiger_users.user_name" . $this->getAdvComparator($comparator, $value, $datatype);
         $temp_value .= " OR  vtiger_groups.groupname" . $this->getAdvComparator($comparator, $value, $datatype);
         $value = $temp_value . ")";
     } elseif ($fieldname == "inventorymanager") {
         $value = $tablename . "." . $fieldname . $this->getAdvComparator($comparator, getUserId_Ol($value), $datatype);
     } elseif ($change_table_field[$fieldname] != '') {
         $value = $change_table_field[$fieldname] . $this->getAdvComparator($comparator, $value, $datatype);
     } elseif ($change_table_field[$tablename . "." . $fieldname] != '') {
         $tmp_value = '';
         if (($comparator == 'e' || $comparator == 's' || $comparator == 'c') && trim($value) == '' || ($comparator == 'n' || $comparator == 'k') && trim($value) != '') {
             $tmp_value = $change_table_field[$tablename . "." . $fieldname] . ' IS NULL or ';
         }
         $value = $tmp_value . $change_table_field[$tablename . "." . $fieldname] . $this->getAdvComparator($comparator, $value, $datatype);
     } elseif ($fieldname == "handler") {
         $value = "vtiger_users.user_name" . $this->getAdvComparator($comparator, $value, $datatype);
     } elseif ($fieldname == "crmid" && $tablename != 'vtiger_crmentity' || $fieldname == "parent_id" || $fieldname == 'parentid') {
         //For crmentity.crmid the control should not come here. This is only to get the related to modules
         $value = $this->getSalesRelatedName($comparator, $value, $datatype, $tablename, $fieldname);
     } else {
         //For checkbox type values, we have to convert yes/no as 1/0 to get the values
         $field_uitype = getUItype($this->customviewmodule, $fieldname);
         if ($field_uitype == 56) {
             if (strtolower($value) == 'yes') {
                 $value = 1;
             } elseif (strtolower($value) == 'no') {
                 $value = 0;
             }
         } else {
             if (is_uitype($field_uitype, '_picklist_')) {
                 /* Fix for tickets 4465 and 4629 */
                 // Get all the keys for the for the Picklist value
                 $mod_keys = array_keys($mod_strings, $value);
                 // 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) {
                         $value = $mod_key;
                         break;
                     }
                 }
             }
         }
         //added to fix the ticket
         if ($this->customviewmodule == "Calendar" && ($fieldname == "status" || $fieldname == "taskstatus" || $fieldname == "eventstatus")) {
             if (getFieldVisibilityPermission("Calendar", $current_user->id, 'taskstatus') == '0') {
                 $value = " (case when (vtiger_activity.status not like '') then vtiger_activity.status else vtiger_activity.eventstatus end)" . $this->getAdvComparator($comparator, $value, $datatype);
             } else {
                 $value = " vtiger_activity.eventstatus " . $this->getAdvComparator($comparator, $value, $datatype);
             }
         } elseif ($comparator == 'e' && (trim($value) == "NULL" || trim($value) == '')) {
             $value = '(' . $tablename . "." . $fieldname . ' IS NULL OR ' . $tablename . "." . $fieldname . ' = \'\')';
         } else {
             $value = $tablename . "." . $fieldname . $this->getAdvComparator($comparator, $value, $datatype);
         }
         //end
     }
     return $value;
 }
Esempio n. 3
0
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;
}