function queryFilterone_of(&$layout_def)
 {
     foreach ($layout_def['input_name0'] as $key => $value) {
         $layout_def['input_name0'][$key] = PearDatabase::quote($value);
     }
     return $this->_get_column_select($layout_def) . " IN ('" . implode("','", $layout_def['input_name0']) . "')\n";
 }
 function add_create_assigned_user_name()
 {
     // global is defined in UsersLastImport.php
     global $imported_ids;
     global $current_user;
     if (empty($this->assigned_user_name)) {
         return;
     }
     $user_name = $this->assigned_user_name;
     // check if it already exists
     $focus = new User();
     $query = "select * from {$focus->table_name} WHERE user_name='{$user_name}'";
     $GLOBALS['log']->info($query);
     $result = $this->db->query($query) or sugar_die("Error selecting sugarbean: ");
     $row = $this->db->fetchByAssoc($result, -1, false);
     // we found a row with that id
     if (isset($row['id']) && $row['id'] != -1) {
         // if it exists but was deleted, just remove it entirely
         if (isset($row['deleted']) && $row['deleted'] == 1) {
             $query2 = "delete from {$focus->table_name} WHERE id='" . PearDatabase::quote($row['id']) . "'";
             $GLOBALS['log']->info($query2);
             $result2 = $this->db->query($query2) or sugar_die("Error deleting existing sugarbean: ");
         } else {
             $focus->id = $row['id'];
         }
     }
     // now just link the account
     $this->assigned_user_id = $focus->id;
     $this->modified_user_id = $focus->id;
 }
 function queryFilterone_of(&$layout_def)
 {
     $arr = array();
     foreach ($layout_def['input_name0'] as $value) {
         array_push($arr, "'" . PearDatabase::quote($value) . "'");
     }
     $str = implode(",", $arr);
     return $this->_get_column_select($layout_def) . " IN (" . $str . ")\n";
 }
Esempio n. 4
0
 /**
 	builds a generic search based on the query string using or
 	do not include any $this-> because this is called on without having the class instantiated
 */
 function build_generic_where_clause($the_query_string)
 {
     $where_clauses = array();
     $the_query_string = PearDatabase::quote(from_html($the_query_string));
     array_push($where_clauses, "leads.last_name like '{$the_query_string}%'");
     array_push($where_clauses, "leads.account_name like '{$the_query_string}%'");
     array_push($where_clauses, "leads.first_name like '{$the_query_string}%'");
     array_push($where_clauses, "leads.email1 like '{$the_query_string}%'");
     array_push($where_clauses, "leads.email2 like '{$the_query_string}%'");
     if (is_numeric($the_query_string)) {
         array_push($where_clauses, "leads.phone_home like '%{$the_query_string}%'");
         array_push($where_clauses, "leads.phone_mobile like '%{$the_query_string}%'");
         array_push($where_clauses, "leads.phone_work like '%{$the_query_string}%'");
         array_push($where_clauses, "leads.phone_other like '%{$the_query_string}%'");
         array_push($where_clauses, "leads.phone_fax like '%{$the_query_string}%'");
     }
     $the_where = "";
     foreach ($where_clauses as $clause) {
         if ($the_where != "") {
             $the_where .= " or ";
         }
         $the_where .= $clause;
     }
     return $the_where;
 }
Esempio n. 5
0
 /**
  *
  */
 function build_generic_where_clause($the_query_string)
 {
     $where_clauses = array();
     $the_query_string = PearDatabase::quote(from_html($the_query_string));
     array_push($where_clauses, "ink.name LIKE '%{$the_query_string}%'");
     $the_where = '';
     foreach ($where_clauses as $clause) {
         if ($the_where != '') {
             $the_where .= " OR ";
         }
         $the_where .= $clause;
     }
     return $the_where;
 }
Esempio n. 6
0
 /**
 	builds a generic search based on the query string using or
 	do not include any $this-> because this is called on without having the class instantiated
 */
 function build_generic_where_clause($the_query_string)
 {
     $where_clauses = array();
     $the_query_string = PearDatabase::quote(from_html($the_query_string));
     array_push($where_clauses, "cases.name like '{$the_query_string}%'");
     array_push($where_clauses, "accounts.name like '{$the_query_string}%'");
     if (is_numeric($the_query_string)) {
         array_push($where_clauses, "cases.case_number like '{$the_query_string}%'");
     }
     $the_where = "";
     foreach ($where_clauses as $clause) {
         if ($the_where != "") {
             $the_where .= " or ";
         }
         $the_where .= $clause;
     }
     if ($the_where != "") {
         $the_where = "(" . $the_where . ")";
     }
     return $the_where;
 }
     $current_user_only = $_REQUEST['current_user_only'];
 }
 if (isset($_REQUEST['assigned_user_id'])) {
     $assigned_user_id = $_REQUEST['assigned_user_id'];
 }
 //if (isset($_REQUEST['spec'])) $spec = $_REQUEST['spec'];
 //if (isset($_REQUEST['subordinate_only'])) $subordinate_only = $_REQUEST['subordinate_only'];
 $where_clauses = array();
 if (isset($name) && $name != "") {
     array_push($where_clauses, "products.name like '%" . PearDatabase::quote($name) . "%'");
 }
 if (isset($pnum) && $pnum != "") {
     array_push($where_clauses, "products.pnum like '%" . PearDatabase::quote($pnum) . "%'");
 }
 if (isset($category) && $category != "") {
     array_push($where_clauses, "products.category like '%" . PearDatabase::quote($category) . "%'");
 }
 //if(isset($type) && $type != "") array_push($where_clauses, "products.type like '%".PearDatabase::quote($type)."%'");
 if (isset($current_user_only) && $current_user_only != "") {
     array_push($where_clauses, "products.assigned_user_id='{$current_user->id}'");
 }
 /*
 	//search by modified date.
 	$date_period = '';
 	if (isset($_REQUEST['date_period'])) $date_period = $_REQUEST['date_period'];
 	if($date_period == "cust"){
 		if (isset($_REQUEST['date_from'])) $date_from = $_REQUEST['date_from'];
 		if (isset($_REQUEST['date_to'])) $date_to = $_REQUEST['date_to'];
 		
 	}else{
 		$date_from = get_date_from($date_period);
require_once 'modules/MySettings/StoreQuery.php';
$storeQuery = new StoreQuery();
if ($_REQUEST['action'] == 'index') {
    if (!isset($_REQUEST['query'])) {
        $storeQuery->loadQuery($currentModule);
        $storeQuery->populateRequest();
    } else {
        $storeQuery->saveFromGet($currentModule);
    }
}
if (isset($_REQUEST['query'])) {
    // we have a query
    $searchForm->populateFromRequest();
    if (!empty($_REQUEST['date_closed']) && !empty($_REQUEST['date_start'])) {
        // this is to handle dashboard queries
        $whereAdditional = "opportunities.date_closed >= '" . PearDatabase::quote($_REQUEST['date_start']) . "' and opportunities.date_closed <= '" . PearDatabase::quote($_REQUEST['date_closed']) . "'";
        if (isset($searchForm->searchFields['date_closed'])) {
            unset($searchForm->searchFields['date_closed']);
        }
    }
    $where_clauses = $searchForm->generateSearchWhere($_REQUEST, true, "Opportunities");
    // First change the query string value for sales_stage
    $position = array_search("opportunities.sales_stage = 'Other'", $where_clauses);
    if ($position !== false) {
        $where_clauses[$position] = "opportunities.sales_stage not in ('Closed Won', 'Closed Lost')";
        // Same as: ("SELECT DISTINCT sales_stage from opportunities where sales_stage not in ('Closed Won', 'Closed Lost')")
    }
    if (isset($whereAdditional)) {
        array_push($where_clauses, $whereAdditional);
    }
    $where = "";
 function add_create_assigned_user_name()
 {
     // global is defined in UsersLastImport.php
     global $imported_ids;
     global $current_user;
     if (empty($this->assigned_real_user_name)) {
         return;
     }
     $arr = array();
     $name_arr = preg_split('/\\s+/', $this->assigned_real_user_name);
     if (count($name_arr) == 1) {
         $first_name = $this->assigned_real_user_name;
     } else {
         $first_name = array_shift($name_arr);
         $last_name = join(' ', $name_arr);
     }
     if (empty($last_name)) {
         $user_name = strtolower($first_name);
     } else {
         $user_name = strtolower($first_name . '_' . $last_name);
     }
     $user_name = preg_replace('/[^A-Za-z_]+/', '_', $user_name);
     $arr = array();
     // check if it already exists
     $focus = new User();
     $query = "select * from {$focus->table_name} WHERE (first_name='" . PearDatabase::quote($first_name) . "' AND last_name='" . PearDatabase::quote($last_name) . "') OR user_name='{$user_name}'";
     $GLOBALS['log']->info($query);
     $result = $this->db->query($query) or sugar_die("Error selecting sugarbean: ");
     $row = $this->db->fetchByAssoc($result, -1, false);
     // we found a row with that id
     if (isset($row['id']) && $row['id'] != -1) {
         // if it exists but was deleted, just remove it entirely
         if (isset($row['deleted']) && $row['deleted'] == 1) {
             $query2 = "delete from {$focus->table_name} WHERE id='" . PearDatabase::quote($row['id']) . "'";
             $GLOBALS['log']->info($query2);
             $result2 = $this->db->query($query2) or sugar_die("Error deleting existing sugarbean: ");
         } else {
             $focus->id = $row['id'];
         }
     }
     // now just link the account
     $this->assigned_user_id = $focus->id;
     $this->modified_user_id = $focus->id;
 }
Esempio n. 10
0
 /**
 	builds a generic search based on the query string using or
 	do not include any $this-> because this is called on without having the class instantiated
 */
 function build_generic_where_clause($the_query_string)
 {
     $where_clauses = array();
     $the_query_string = PearDatabase::quote(from_html($the_query_string));
     array_push($where_clauses, "name like '{$the_query_string}%'");
     $the_where = "";
     foreach ($where_clauses as $clause) {
         if ($the_where != "") {
             $the_where .= " or ";
         }
         $the_where .= $clause;
     }
     return $the_where;
 }
Esempio n. 11
0
    if (!isset($_REQUEST['query'])) {
        $storeQuery->loadQuery($currentModule);
        $storeQuery->populateRequest();
    } else {
        $storeQuery->saveFromGet($currentModule);
    }
}
$seedRole = new Role();
if (isset($_REQUEST['query'])) {
    // we have a query
    if (isset($_REQUEST['name'])) {
        $name = $_REQUEST['name'];
    }
    $where_clauses = array();
    if (isset($name) && $name != "") {
        array_push($where_clauses, "roles.name like '" . PearDatabase::quote($name) . "%'");
    }
    $seedRole->custom_fields->setWhereClauses($where_clauses);
    $where = "";
    foreach ($where_clauses as $clause) {
        if ($where != "") {
            $where .= " and ";
        }
        $where .= $clause;
    }
    $GLOBALS['log']->info("Here is the where clause for the list view: {$where}");
}
if (!isset($_REQUEST['search_form']) || $_REQUEST['search_form'] != 'false') {
    // Stick the form header out there.
    $search_form = new XTemplate('modules/Roles/SearchForm.html');
    $search_form->assign("MOD", $current_module_strings);
Esempio n. 12
0
 }
 if (isset($_REQUEST['assigned_user_id'])) {
     $assigned_user_id = $_REQUEST['assigned_user_id'];
 }
 if (isset($_REQUEST['list_type'])) {
     $list_type = $_REQUEST['list_type'];
 }
 $where_clauses = array();
 if (isset($name) && $name != "") {
     array_push($where_clauses, "prospect_lists.name like '" . PearDatabase::quote($name) . "%'");
 }
 if (isset($current_user_only) && $current_user_only != "") {
     array_push($where_clauses, "prospect_lists.assigned_user_id='{$current_user->id}'");
 }
 if (!empty($list_type)) {
     array_push($where_clauses, "prospect_lists.list_type like '" . PearDatabase::quote($list_type) . "%'");
 }
 $seedProspectLists->custom_fields->setWhereClauses($where_clauses);
 $where = "";
 foreach ($where_clauses as $clause) {
     if ($where != "") {
         $where .= " and ";
     }
     $where .= $clause;
 }
 if (isset($assigned_user_id) && is_array($assigned_user_id)) {
     $count = count($assigned_user_id);
     if ($count > 0) {
         if (!empty($where)) {
             $where .= " AND ";
         }
 function setWhereClauses(&$where_clauses)
 {
     if (!array_key_exists($this->module, $this->modules)) {
         return false;
     }
     foreach ($this->avail_fields as $name => $value) {
         if (!empty($_REQUEST[$name])) {
             array_push($where_clauses, $this->bean->table_name . "_cstm.{$name} LIKE '" . PearDatabase::quote($_REQUEST[$name]) . "%'");
         }
     }
 }
 function queryFilterBetween_Dates(&$layout_def)
 {
     global $timedate;
     if ($this->getAssignedUser()) {
         $begin = $timedate->handle_offset($layout_def['input_name0'], $timedate->dbDayFormat, false, $this->assigned_user);
         $end = $timedate->handle_offset($layout_def['input_name1'], $timedate->dbDayFormat, false, $this->assigned_user);
     } else {
         $begin = $layout_def['input_name0'];
         $end = $layout_def['input_name1'];
     }
     return "(" . $this->_get_column_select($layout_def) . ">='" . PearDatabase::quote($begin) . "' AND \n" . $this->_get_column_select($layout_def) . "<='" . PearDatabase::quote($end) . "')\n";
 }
 function queryFilterBetween(&$layout_def)
 {
     return $this->_get_column_select($layout_def) . " BETWEEN '" . PearDatabase::quote($layout_def['input_name0']) . "' AND '" . PearDatabase::quote($layout_def['input_name1']) . "'\n";
 }
Esempio n. 16
0
 /**
 	builds a generic search based on the query string using or
 	do not include any $this-> because this is called on without having the class instantiated
 */
 function build_generic_where_clause($the_query_string)
 {
     $where_clauses = array();
     $the_query_string = PearDatabase::quote(from_html($the_query_string));
     array_push($where_clauses, "suppliers.name like '{$the_query_string}%'");
     if (is_numeric($the_query_string)) {
         array_push($where_clauses, "suppliers.phone_alternate like '%{$the_query_string}%'");
         array_push($where_clauses, "suppliers.phone_fax like '%{$the_query_string}%'");
         array_push($where_clauses, "suppliers.phone_office like '%{$the_query_string}%'");
     }
     $the_where = "";
     foreach ($where_clauses as $clause) {
         if (!empty($the_where)) {
             $the_where .= " or ";
         }
         $the_where .= $clause;
     }
     return $the_where;
 }
 function queryFilterBetween(&$layout_def)
 {
     $global_currency_obj = get_currency();
     return $this->_get_column_select($layout_def) . " > " . PearDatabase::quote(round($global_currency_obj->convertToDollar($layout_def['input_name0']))) . " AND " . $this->_get_column_select($layout_def) . " < " . PearDatabase::quote(round($global_currency_obj->convertToDollar($layout_def['input_name1']))) . "\n";
 }
Esempio n. 18
0
 }
 $where_clauses = array();
 if (isset($supplynum) && $supplynum != "") {
     array_push($where_clauses, "supplies.supplynum like '%" . PearDatabase::quote($supplynum) . "%'");
 }
 if (isset($delivery_date) && $delivery_date != "") {
     array_push($where_clauses, "supplies.delivery_date like '%" . PearDatabase::quote($delivery_date) . "%'");
 }
 if (isset($purchaseorder_num) && $purchaseorder_num != "") {
     array_push($where_clauses, "supplies.purchaseorder_num like '%" . PearDatabase::quote($purchaseorder_num) . "%'");
 }
 if (isset($category) && $category != "") {
     array_push($where_clauses, "supplies.category like '%" . PearDatabase::quote($category) . "%'");
 }
 if (isset($status) && $status != "") {
     array_push($where_clauses, "supplies.status like '%" . PearDatabase::quote($status) . "%'");
 }
 if (isset($current_user_only) && $current_user_only != "") {
     array_push($where_clauses, "supplies.assigned_user_id='{$current_user->id}'");
 }
 /*
 //search by modified date.
 $date_period = '';
 if (isset($_REQUEST['date_period'])) $date_period = $_REQUEST['date_period'];
 if($date_period == "cust"){
 	if (isset($_REQUEST['date_from'])) $date_from = $_REQUEST['date_from'];
 	if (isset($_REQUEST['date_to'])) $date_to = $_REQUEST['date_to'];
 	
 }else{
 	$date_from = get_date_from($date_period);
 	$date_to = get_date_to($date_period);
function portal_get_entry_list_filter($session, $module_name, $order_by, $select_fields, $row_offset, $limit, $filter)
{
    global $beanList, $beanFiles, $portal_modules;
    $error = new SoapError();
    if (!portal_validate_authenticated($session)) {
        $error->set_error('invalid_session');
        return array('result_count' => -1, 'entry_list' => array(), 'error' => $error->get_soap_array());
    }
    if ($_SESSION['type'] == 'lead') {
        $error->set_error('no_access');
        return array('result_count' => -1, 'entry_list' => array(), 'error' => $error->get_soap_array());
    }
    if (empty($beanList[$module_name])) {
        $error->set_error('no_module');
        return array('result_count' => -1, 'entry_list' => array(), 'error' => $error->get_soap_array());
    }
    //build the where clause
    $sugar = null;
    if ($module_name == 'Cases') {
        $sugar = new aCase();
    } else {
        if ($module_name == 'Contacts') {
            $sugar = new Contact();
        } else {
            if ($module_name == 'Accounts') {
                $sugar = new Account();
            } else {
                if ($module_name == 'Bugs') {
                    $sugar = new Bug();
                } else {
                    $error->set_error('no_module_support');
                    return array('result_count' => -1, 'entry_list' => array(), 'error' => $error->get_soap_array());
                }
            }
        }
    }
    if ($sugar != null) {
        if (isset($filter) && is_array($filter)) {
            $where = "";
            foreach ($filter as $nvOp) {
                $name = $nvOp['name'];
                $value = $nvOp['value'];
                $value_array = $nvOp['value_array'];
                $operator = $nvOp['operator'];
                //do nothing if all three values are not set
                if (isset($name) && (isset($value) || isset($value_array)) && isset($operator)) {
                    if (!empty($where)) {
                        $where .= ' AND ';
                    }
                    if (isset($sugar->field_defs[$name])) {
                        $where .= "{$sugar->table_name}.{$name} {$operator} ";
                        if ($sugar->field_defs['name']['type'] == 'datetime') {
                            $where .= db_convert("'{$value}'", 'datetime');
                        } else {
                            if (empty($value)) {
                                $tmp = array();
                                foreach ($value_array as $v) {
                                    $tmp[] = PearDatabase::quote(from_html($v));
                                }
                                $where .= "('" . implode("', '", $tmp) . "')";
                            } else {
                                $where .= "'" . PearDatabase::quote(from_html($value)) . "'";
                            }
                        }
                    }
                }
            }
        }
        $GLOBALS['log']->debug("Portal where clause: " . $where);
        return portal_get_entry_list_limited($session, $module_name, $where, $order_by, $select_fields, $row_offset, $limit);
    } else {
        $error->set_error('no_module_support');
        return array('result_count' => -1, 'entry_list' => array(), 'error' => $error->get_soap_array());
    }
}
Esempio n. 20
0
$list_form->assign("APP", $app_strings);
$list_form->assign("THEME", $theme);
$list_form->assign("IMAGE_PATH", $image_path);
$list_form->assign("MODULE_NAME", $currentModule);
$where = "";
if (isset($_REQUEST['query'])) {
    // we have a query
    if (isset($_REQUEST['name'])) {
        $name = $_REQUEST['name'];
    }
    if (isset($_REQUEST['contact_name'])) {
        $contact_name = $_REQUEST['contact_name'];
    }
    $where_clauses = array();
    if (isset($name) && $name != '') {
        array_push($where_clauses, "email_templates.name like '" . PearDatabase::quote($name) . "%'");
    }
    $seedEmailTemplate->custom_fields->setWhereClauses($where_clauses);
    $where = "";
    if (isset($where_clauses)) {
        foreach ($where_clauses as $clause) {
            if ($where != "") {
                $where .= " and ";
            }
            $where .= $clause;
        }
    }
    $GLOBALS['log']->info("Here is the where clause for the list view: {$where}");
}
global $title;
$display_title = $mod_strings['LBL_LIST_FORM_TITLE'];
 function queryFilterIs(&$layout_def)
 {
     return $this->_get_column_select($layout_def) . "='" . PearDatabase::quote($layout_def['input_name0']) . "'\n";
 }
Esempio n. 22
0
 /**
  * @return -- returns a list of all users in the system.
  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc..
  * All Rights Reserved..
  * Contributor(s): ______________________________________..
  */
 function verify_data($ieVerified = true)
 {
     global $mod_strings, $current_user;
     $verified = TRUE;
     if (!empty($this->id)) {
         // Make sure the user doesn't report to themselves.
         $reports_to_self = 0;
         $check_user = $this->reports_to_id;
         $already_seen_list = array();
         while (!empty($check_user)) {
             if (isset($already_seen_list[$check_user])) {
                 // This user doesn't actually report to themselves
                 // But someone above them does.
                 $reports_to_self = 1;
                 break;
             }
             if ($check_user == $this->id) {
                 $reports_to_self = 1;
                 break;
             }
             $already_seen_list[$check_user] = 1;
             $query = "SELECT reports_to_id FROM users WHERE id='" . PearDatabase::quote($check_user) . "'";
             $result = $this->db->query($query, true, "Error checking for reporting-loop");
             $row = $this->db->fetchByAssoc($result);
             echo "fetched: " . $row['reports_to_id'] . " from " . $check_user . "<br>";
             $check_user = $row['reports_to_id'];
         }
         if ($reports_to_self == 1) {
             $this->error_string .= $mod_strings['ERR_REPORT_LOOP'];
             $verified = FALSE;
         }
     }
     $query = "SELECT user_name from users where user_name='{$this->user_name}' AND deleted=0";
     if (!empty($this->id)) {
         $query .= " AND id<>'{$this->id}'";
     }
     $result = $this->db->query($query, true, "Error selecting possible duplicate users: ");
     $dup_users = $this->db->fetchByAssoc($result);
     if (!empty($dup_users)) {
         $this->error_string .= $mod_strings['ERR_USER_NAME_EXISTS_1'] . $this->user_name . $mod_strings['ERR_USER_NAME_EXISTS_2'];
         $verified = FALSE;
     }
     if ($current_user->is_admin == "on") {
         if ($this->db->dbType == 'mssql') {
             $query = "SELECT user_name from users where is_admin = 1 AND deleted=0";
         } else {
             $query = "SELECT user_name from users where is_admin = 'on' AND deleted=0";
         }
         $result = $this->db->query($query, true, "Error selecting possible duplicate users: ");
         $remaining_admins = $this->db->getRowCount($result);
         if ($remaining_admins <= 1 && $this->is_admin != "on" && $this->id == $current_user->id) {
             $GLOBALS['log']->debug("Number of remaining administrator accounts: {$remaining_admins}");
             $this->error_string .= $mod_strings['ERR_LAST_ADMIN_1'] . $this->user_name . $mod_strings['ERR_LAST_ADMIN_2'];
             $verified = FALSE;
         }
     }
     ///////////////////////////////////////////////////////////////////////
     ////	InboundEmail verification failure
     if (!$ieVerified) {
         $verified = false;
         $this->error_string .= '<br />' . $mod_strings['ERR_EMAIL_NO_OPTS'];
     }
     return $verified;
 }
Esempio n. 23
0
/**
 * Creates an array of where restrictions.  These are used to construct a where SQL statement on the query
 * It looks for the variable in the $_REQUEST array.  If it is set and is not "" it will create a where clause out of it.
 * @param &$where_clauses - The array to append the clause to
 * @param $variable_name - The name of the variable to look for an add to the where clause if found
 * @param $SQL_name - [Optional] If specified, this is the SQL column name that is used.  If not specified, the $variable_name is used as the SQL_name.
 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
 * All Rights Reserved.
 * Contributor(s): ______________________________________..
 */
function append_where_clause(&$where_clauses, $variable_name, $SQL_name = null)
{
    if ($SQL_name == null) {
        $SQL_name = $variable_name;
    }
    if (isset($_REQUEST[$variable_name]) && $_REQUEST[$variable_name] != "") {
        array_push($where_clauses, "{$SQL_name} like '" . PearDatabase::quote($_REQUEST[$variable_name]) . "%'");
    }
}
Esempio n. 24
0
    }
    if (isset($_REQUEST['to_name'])) {
        $to_name = $_REQUEST['to_name'];
    }
    if (isset($_REQUEST['to_email'])) {
        $to_email = $_REQUEST['to_email'];
    }
    $where_clauses = array();
    if (isset($campaign_name) && $campaign_name != '') {
        array_push($where_clauses, " campaigns.name like '" . PearDatabase::quote($campaign_name) . "%' ");
    }
    if (isset($to_name) && $to_name != '') {
        array_push($where_clauses, " (contacts.first_name like '" . PearDatabase::quote($to_name) . "%' OR contacts.last_name like '" . PearDatabase::quote($to_name) . "%' or leads.first_name like '" . PearDatabase::quote($to_name) . "%' OR leads.last_name like '" . PearDatabase::quote($to_name) . "%' or prospects.first_name like '" . PearDatabase::quote($to_name) . "%' OR prospects.last_name like '" . PearDatabase::quote($to_name) . "%') ");
    }
    if (isset($to_email) && $to_email != '') {
        array_push($where_clauses, " (contacts.email1 like '" . PearDatabase::quote($to_email) . "%'  or leads.email1 like '" . PearDatabase::quote($to_email) . "%' OR prospects.email1 like '" . PearDatabase::quote($to_email) . "%') ");
    }
    $seed->custom_fields->setWhereClauses($where_clauses);
    $where = "";
    if (isset($where_clauses)) {
        foreach ($where_clauses as $clause) {
            if ($where != "") {
                $where .= " and ";
            }
            $where .= $clause;
        }
    }
    $GLOBALS['log']->info("Here is the where clause for the list view: {$where}");
}
$display_title = $mod_strings['LBL_LIST_FORM_TITLE'];
/*cn: necessary to inline this form because MassUpdate form wraps this and the listview rows
    if (isset($email_type) && $email_type != "") {
        $whereClauses['emails.type'] = "emails.type = '" . PearDatabase::quote($email_type) . "'";
    }
    if (isset($assigned_to) && $assigned_to != "") {
        $whereClauses['emails.assigned_user_id'] = "emails.assigned_user_id = '" . PearDatabase::quote($assigned_to) . "'";
    }
    if (isset($status) && $status != "") {
        $whereClauses['emails.status'] = "emails.status = '" . PearDatabase::quote($status) . "'";
    }
    if (isset($name) && $name != "") {
        $whereClauses['emails.name'] = "emails.name like '" . PearDatabase::quote($name) . "%'";
    }
    if (isset($contact_name) && $contact_name != '') {
        $contact_names = explode(" ", $contact_name);
        foreach ($contact_names as $name) {
            $whereClauses['contacts.name'] = "(contacts.first_name like '" . PearDatabase::quote($name) . "%' OR contacts.last_name like '" . PearDatabase::quote($name) . "%')";
        }
    }
    $focus->custom_fields->setWhereClauses($whereClauses);
    $GLOBALS['log']->info("Here is the where clause for the list view: {$where}");
}
// end isset($_REQUEST['query'])
////	OUTPUT GENERATION
if (!isset($_REQUEST['search_form']) || $_REQUEST['search_form'] != 'false') {
    // ASSIGNMENTS pre-processing
    $email_type_sel = '';
    $assigned_to_sel = '';
    $status_sel = '';
    if (isset($_REQUEST['email_type'])) {
        $email_type_sel = $_REQUEST['email_type'];
    }
function construct_where(&$query_obj, $table = '')
{
    if (!empty($table)) {
        $table .= ".";
    }
    $cond_arr = array();
    if (!is_array($query_obj['conditions'])) {
        $query_obj['conditions'] = array();
    }
    foreach ($query_obj['conditions'] as $condition) {
        if ($condition['op'] == 'contains') {
            array_push($cond_arr, PearDatabase::quote($table . $condition['name']) . " like '%" . PearDatabase::quote($condition['value']) . "%'");
        }
        if ($condition['op'] == 'like_custom') {
            $like = '';
            if (!empty($condition['begin'])) {
                $like .= PearDatabase::quote($condition['begin']);
            }
            $like .= PearDatabase::quote($condition['value']);
            if (!empty($condition['end'])) {
                $like .= PearDatabase::quote($condition['end']);
            }
            array_push($cond_arr, PearDatabase::quote($table . $condition['name']) . " like '{$like}'");
        } else {
            // starts_with
            array_push($cond_arr, PearDatabase::quote($table . $condition['name']) . " like '" . PearDatabase::quote($condition['value']) . "%'");
        }
    }
    if ($table == 'users.') {
        array_push($cond_arr, $table . "status='Active'");
    }
    return implode(" {$query_obj['group']} ", $cond_arr);
}
 function search()
 {
     if (!file_exists('cache/modules/unified_search_modules.php')) {
         $this->buildCache();
     }
     include 'cache/modules/unified_search_modules.php';
     require_once 'include/ListView/ListViewSmarty.php';
     require_once 'include/utils.php';
     global $modListHeader, $beanList, $beanFiles, $current_language, $app_strings, $current_user, $mod_strings;
     $home_mod_strings = return_module_language($current_language, 'Home');
     $overlib = true;
     $_REQUEST['query_string'] = PearDatabase::quote(from_html(clean_string($_REQUEST['query_string'], 'UNIFIED_SEARCH')));
     if (!empty($_REQUEST['advanced']) && $_REQUEST['advanced'] != 'false') {
         $modules_to_search = array();
         foreach ($_REQUEST as $param => $value) {
             if (preg_match('/^search_mod_(.*)$/', $param, $match)) {
                 $modules_to_search[$match[1]] = $beanList[$match[1]];
             }
         }
         $current_user->setPreference('globalSearch', $modules_to_search, 0, 'search');
         // save selections to user preference
     } else {
         $users_modules = $current_user->getPreference('globalSearch', 'search');
         if (isset($users_modules)) {
             // use user's previous selections
             $modules_to_search = $users_modules;
         } else {
             // select all the modules (ie first time user has used global search)
             foreach ($unified_search_modules as $module => $data) {
                 $modules_to_search[$module] = $beanList[$module];
             }
             $current_user->setPreference('globalSearch', $modules_to_search, 'search');
         }
     }
     echo $this->getDropDownDiv('modules/Home/UnifiedSearchAdvancedForm.tpl');
     $module_results = array();
     $module_counts = array();
     $has_results = false;
     if (!empty($_REQUEST['query_string'])) {
         foreach ($modules_to_search as $name => $beanName) {
             if (array_key_exists($name, $modListHeader)) {
                 $where_clauses_array = array();
                 foreach ($unified_search_modules[$name]['fields'] as $field => $def) {
                     $clause = '';
                     if (isset($def['table'])) {
                         // if field is from joining table
                         $clause = "{$def['table']}.{$def['rname']} ";
                     } else {
                         $clause = "{$unified_search_modules[$name]['table']}.{$field} ";
                     }
                     switch ($def['type']) {
                         case 'int':
                             if (is_numeric($_REQUEST['query_string'])) {
                                 $clause .= "in ('{$_REQUEST['query_string']}')";
                             } else {
                                 $clause .= "in ('-1')";
                             }
                             break;
                         default:
                             $clause .= "LIKE '{$_REQUEST['query_string']}%'";
                             break;
                     }
                     array_push($where_clauses_array, $clause);
                 }
                 $where = implode(' or ', $where_clauses_array);
                 require_once $beanFiles[$beanName];
                 $seed = new $beanName();
                 $lv = new ListViewSmarty();
                 $lv->lvd->additionalDetails = false;
                 $mod_strings = return_module_language($current_language, $seed->module_dir);
                 if (file_exists('custom/modules/' . $seed->module_dir . '/metadata/listviewdefs.php')) {
                     require_once 'custom/modules/' . $seed->module_dir . '/metadata/listviewdefs.php';
                 } else {
                     require_once 'modules/' . $seed->module_dir . '/metadata/listviewdefs.php';
                 }
                 $displayColumns = array();
                 foreach ($listViewDefs[$seed->module_dir] as $colName => $param) {
                     if (!empty($param['default']) && $param['default'] == true) {
                         $displayColumns[$colName] = $param;
                     }
                 }
                 if (count($displayColumns) > 0) {
                     $lv->displayColumns = $displayColumns;
                 } else {
                     $lv->displayColumns = $listViewDefs[$seed->module_dir];
                 }
                 $lv->export = false;
                 $lv->mergeduplicates = false;
                 $lv->multiSelect = false;
                 if ($overlib) {
                     $lv->overlib = true;
                     $overlib = false;
                 } else {
                     $lv->overlib = false;
                 }
                 $lv->setup($seed, 'include/ListView/ListViewGeneric.tpl', $where, 0, 10);
                 $module_results[$name] = '<br /><br />' . get_form_header($GLOBALS['app_list_strings']['moduleList'][$seed->module_dir] . ' (' . $lv->data['pageData']['offsets']['total'] . ')', '', false);
                 $module_counts[$name] = $lv->data['pageData']['offsets']['total'];
                 if ($lv->data['pageData']['offsets']['total'] == 0) {
                     $module_results[$name] .= '<h2>' . $home_mod_strings['LBL_NO_RESULTS_IN_MODULE'] . '</h2>';
                 } else {
                     $has_results = true;
                     $module_results[$name] .= $lv->display(false, false);
                 }
             }
         }
     }
     if ($has_results) {
         arsort($module_counts);
         foreach ($module_counts as $name => $value) {
             echo $module_results[$name];
         }
     } else {
         echo '<br>';
         echo $home_mod_strings['LBL_NO_RESULTS'];
         echo $home_mod_strings['LBL_NO_RESULTS_TIPS'];
     }
 }
 function set_relationship($table, $relate_values, $check_duplicates = true, $do_update = false, $data_values = null)
 {
     $where = '';
     // make sure there is a date modified
     $date_modified = db_convert("'" . gmdate("Y-m-d H:i:s") . "'", 'datetime');
     $row = null;
     if ($check_duplicates) {
         $query = "SELECT * FROM {$table} ";
         $where = "WHERE deleted = '0'  ";
         foreach ($relate_values as $name => $value) {
             $where .= " AND {$name} = '{$value}' ";
         }
         $query .= $where;
         $result = $this->db->query($query, false, "Looking For Duplicate Relationship:" . $query);
         $row = $this->db->fetchByAssoc($result);
     }
     if (!$check_duplicates || empty($row)) {
         unset($relate_values['id']);
         if (isset($data_values)) {
             $relate_values = array_merge($relate_values, $data_values);
         }
         $query = "INSERT INTO {$table} (id, " . implode(',', array_keys($relate_values)) . ", date_modified) VALUES ('" . create_guid() . "', " . "'" . implode("', '", $relate_values) . "', " . $date_modified . ")";
         $this->db->query($query, false, "Creating Relationship:" . $query);
     } else {
         if ($do_update) {
             $conds = array();
             foreach ($data_values as $key => $value) {
                 array_push($conds, $key . "='" . PearDatabase::quote(from_html($value)) . "'");
             }
             $query = "UPDATE {$table} SET " . implode(',', $conds) . ",date_modified=" . $date_modified . " " . $where;
             $this->db->query($query, false, "Updating Relationship:" . $query);
         }
     }
 }
 function add_member_of_name()
 {
     // global is defined in UsersLastImport.php
     global $imported_ids;
     global $current_user;
     if ((!isset($this->account_name) || $this->account_name == '') && (!isset($this->parent_id) || $this->parent_id == '')) {
         return;
     }
     $arr = array();
     // check if it already exists
     $focus = new Account();
     $query = '';
     // if user is defining the account id to be associated with this contact..
     if (isset($this->parent_id) && $this->parent_id != '') {
         $this->parent_id = convert_id($this->parent_id);
         $query = "select * from {$focus->table_name} WHERE id='" . PearDatabase::quote($this->parent_id) . "'";
     } else {
         $query = "select * from {$focus->table_name} WHERE name='" . PearDatabase::quote($this->account_name) . "'";
     }
     $GLOBALS['log']->info($query);
     $result = $this->db->query($query) or sugar_die("Error selecting sugarbean: ");
     $row = $this->db->fetchByAssoc($result, -1, false);
     // we found a row with that id
     if (isset($row['id']) && $row['id'] != -1) {
         // if it exists but was deleted, just remove it entirely
         if (isset($row['deleted']) && $row['deleted'] == 1) {
             $query2 = "delete from {$focus->table_name} WHERE id='" . PearDatabase::quote($row['id']) . "'";
             $GLOBALS['log']->info($query2);
             $result2 = $this->db->query($query2) or sugar_die("Error deleting existing sugarbean: ");
         } else {
             $focus->id = $row['id'];
         }
     }
     // if we didnt find the account, so create it
     if (!isset($focus->id) || $focus->id == '') {
         $focus->name = $this->account_name;
         if (isset($this->parent_id)) {
             $focus->parent_id = $this->parent_id;
         } else {
             $focus->parent_id = $current_user->id;
         }
         if (isset($this->modified_date)) {
             $focus->modified_date = $this->modified_date;
         }
         // if we are providing the account id:
         if (isset($this->parent_id) && $this->parent_id != '') {
             $focus->new_with_id = true;
             $focus->id = $this->account_id;
         }
         $focus->save();
         // avoid duplicate mappings:
         if (!isset($imported_ids[$focus->id])) {
             // save the new account as a users_last_import
             $last_import = new UsersLastImport();
             $last_import->assigned_user_id = $current_user->id;
             $last_import->bean_type = "Accounts";
             $last_import->bean_id = $focus->id;
             $last_import->save();
             $imported_ids[$focus->id] = 1;
         }
     }
     // now just link the account
     $this->parent_id = $focus->id;
 }
Esempio n. 30
0
if (!isset($_REQUEST['query'])) {
    $storeQuery->loadQuery($currentModule);
    $storeQuery->populateRequest();
} else {
    $storeQuery->saveFromGet($currentModule);
}
if (isset($_REQUEST['current_user_only']) && $_REQUEST['current_user_only'] != "") {
    $seedFeed->my_favorites = true;
}
// we have a query
if (isset($_REQUEST['title'])) {
    $title = $_REQUEST['title'];
}
$where_clauses = array();
if (isset($_REQUEST['title']) && $_REQUEST['title'] != "") {
    array_push($where_clauses, "feeds.title like '%" . PearDatabase::quote($_REQUEST['title']) . "%'");
}
if (isset($_REQUEST['current_user_only']) && $_REQUEST['current_user_only'] != "") {
    array_push($where_clauses, " users_feeds.user_id='{$current_user->id}' ");
}
$where = "";
foreach ($where_clauses as $clause) {
    if ($where != "") {
        $where .= " and ";
    }
    $where .= $clause;
}
$GLOBALS['log']->info("Here is the where clause for the list view: {$where}");
if (!isset($_REQUEST['search_form']) || $_REQUEST['search_form'] != 'false') {
    echo get_form_header($current_module_strings['LBL_SEARCH_FORM_TITLE'], '', false);
    // Stick the form header out there.