Jump to content

Search Code not working


garf3r

Recommended Posts

Hi there, new to the forum :)

 

Ok so i have a crm and i'm trying to add bits, been pretty succesful at most of it, however i've added a new field "status" and i want to be able to search this field, i've tried copying and changing the existing code, but it doesn't seem to be grabbing it.

 

So here's some exisiting code (that works and searches the field marked "Address"

            'address' => array(
                'title' => _l('Address:'),
                'field' => array(
                    'type' => 'text',
                    'name' => 'search[address]',
                    'value' => isset($search['address'])?$search['address']:'',
                    'size' => 15,
                )
            ),
            'status' => array(
                'title' => _l('Status:'),
                'field' => array(
                    'type' => 'text',
                    'name' => 'search[status]',
                    'value' => isset($search['status'])?$search['status']:'',
                    'size' => 15,
                )
            ),

I thought a simple name change like above would work, but it doesn't pull anything through, anyone got any ideas?

Link to comment
Share on other sites

Is this a custom CRM or a well known one?

 

The little snippet does not help much as all we see is a simple array.

If you changed those values and did not work is obviously more to this than just changing those words.

 

Some things to think about...

This could be part of a class or function that is using a prepared query with static values or expecting just what they coded it for.

What is now setting $search['status']?

 

A lot more information would be needed and code seen to determine what changes are needed.

Link to comment
Share on other sites

I'm just guessing here, i found this in the user.php

	public static function get_users($search=array(),$mysql=false){
		// limit based on customer id
		/*if(!isset($_REQUEST['customer_id']) || !(int)$_REQUEST['customer_id']){
			return array();
		}*/
		// build up a custom search sql query based on the provided search fields
		$sql = "SELECT *,u.user_id AS id ";
        $sql .= ", u.name AS name ";
        $from = " FROM `"._DB_PREFIX."user` u ";
		$where = " WHERE 1 ";
        $where .= " AND u.customer_id = 0 ";
		if(isset($search['generic']) && $search['generic']){
			$str = mysql_real_escape_string($search['generic']);
			$where .= " AND ( ";
			$where .= " u.name LIKE '%$str%' OR ";
			$where .= " u.email LIKE '%$str%' OR ";
			$where .= " u.phone LIKE '%$str%' OR ";
			$where .= " u.mobile LIKE '%$str%' ";
			$where .= ' ) ';
		}		
		if(isset($search['customer_id']) && $search['customer_id']){
			/*$str = mysql_real_escape_string($search['customer_id']);
			$where .= " AND u.customer_id = '$str'";
            $sql .= " , c.primary_user_id AS is_primary ";
            $from .= " LEFT JOIN `"._DB_PREFIX."customer` c ON u.customer_id = c.customer_id ";*/
            set_error('Bad usage of get_user() - please report this error.');
            return array();
		}
		if(isset($search['security_role_id']) && (int)$search['security_role_id']>0){
			$str = (int)$search['security_role_id'];
            $from .= " LEFT JOIN `"._DB_PREFIX."user_role` ur ON u.user_id = ur.user_id";
            $where .= " AND ur.security_role_id = $str";
		}
        foreach(array('email') as $key){
            if(isset($search[$key]) && $search[$key] !== ''&& $search[$key] !== false){
                $str = mysql_real_escape_string($search[$key]);
                $where .= " AND u.`$key` LIKE '$str'";
            }
        }

I'm guessing it may be something to do with that?

Link to comment
Share on other sites

This is my array

            'status' => array(
                'title' => _l('Status (do not use)'),
                'field' => array(
                    'type' => 'select',
                    'name' => 'search[status]',
                    'value' => isset($search['status'])?$search['status']:'',
                    'blank' => ' - Status - ',
                    'options' => array(
					    _Quote => _l('Quote'),
						_Application => _l('Application'),
						'On Risk' => _l('On Risk'),
						_Dead => _l('Dead'),
						_NTU => _l('NTU'),
						_Cancelled => _l('Cancelled'),
                        _TestLead => _l('Test Lead'),
                    ),
                ),
            ),

And this is my search string (which comes up blank)

		if(isset($search['status']) && trim($search['status'])){
			$str = (int)$search['status'];
			// search all the customer site addresses.
			$sql .= " LEFT JOIN `"._DB_PREFIX."customer` cur ON (c.customer_id = cur.status)";
			$where .= " AND (cur.status = '$str')";
		}

Any ideas?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.