Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Searching in Admin by customers first name OR last name


viper2626

Recommended Posts

Hi All,

 

I was wondering if anyone was aware of how to run a typical OR search in the admin on the customers.php page. Basically if I wanted to search for the name Jon Smith and actually have it show me everyone who has the first name Jon and the last name Smith. Right now if I search for Jon Smith it will give me 0 results which makes sense but I instead need it to give me many results not only the person names JJon Smith but also anyone in the DB with the first name Jon and the last name Smith.

 

On line 541 of my customers.php file I have:

 

<?php
    $search = '';
    if (isset($HTTP_GET_VARS['search']) && tep_not_null($HTTP_GET_VARS['search'])) {
      $keywords = tep_db_input(tep_db_prepare_input($HTTP_GET_VARS['search']));
      $search = "where c.customers_lastname like '%" . $keywords . "%' or c.customers_firstname like '%" . $keywords . "%' or c.customers_email_address like '%" . $keywords . "%'";
    }
    $customers_query_raw = "select c.customers_id, c.customers_lastname, c.customers_firstname, c.customers_email_address, a.entry_country_id from " . TABLE_CUSTOMERS . " c left join " . TABLE_ADDRESS_BOOK . " a on c.customers_id = a.customers_id and c.customers_default_address_id = a.address_book_id " . $search . " order by c.customers_lastname, c.customers_firstname";
    $customers_split = new splitPageResults($HTTP_GET_VARS['page'], MAX_DISPLAY_SEARCH_RESULTS, $customers_query_raw, $customers_query_numrows);
    $customers_query = tep_db_query($customers_query_raw);
    while ($customers = tep_db_fetch_array($customers_query)) {
      $info_query = tep_db_query("select customers_info_date_account_created as date_account_created, customers_info_date_account_last_modified as date_account_last_modified, customers_info_date_of_last_logon as date_last_logon, customers_info_number_of_logons as number_of_logons from " . TABLE_CUSTOMERS_INFO . " where customers_info_id = '" . $customers['customers_id'] . "'");
      $info = tep_db_fetch_array($info_query);
 
......
 
 
I hope that make sense and any help would be greatly appreciated.
 
Thank You!
 
Link to comment
Share on other sites

Hello

 

here you go - try something like this:

    $search = '';
    if (isset($HTTP_GET_VARS['search']) && tep_not_null($HTTP_GET_VARS['search'])) {		
      $keywords = tep_db_input(tep_db_prepare_input($HTTP_GET_VARS['search']));
	  //new code - check for a space in the input
	     if (strpos($keywords, ' ') !== false) {
             // Space found so split the input by spaces into an array
			   $pieces=explode(' ',$keywords); 
			 // setup parts of the $search string
			   $search .= "where ";
			   $or = " ";
			 // run the new array and build $ search
			    foreach ($pieces as $key=>$value){   
			    	$search .= $or ." c.customers_lastname like '%" . $value . "%' 
					             or c.customers_firstname like '%" . $value . "%' 
								 or c.customers_email_address like '%" . $value . "%'";	
					$or=" or "; // we do not need or on the first instance but we do now
								 
				}
               
			 
			 }// end strpos
	  else{//original query
		      $search = "where c.customers_lastname like '%" . $keywords . "%' or c.customers_firstname like '%" . $keywords . "%' or c.customers_email_address like '%" . $keywords . "%'";
	  }
	  

    }//end if (isset($HTTP_GET_VARS['search']) && tep_not_null($HTTP_GET_VARS['search']))
Link to comment
Share on other sites

That worked like a charm! Thanks! Now I just need to figure out how to export those results to a csv file, the search function itself worked perfectly though!

 

The main purpose of this search is to be able to work with customer groups so when I search for multiple customer group names I can actually export those and modify them as needed.

 

Thanks Again!

Link to comment
Share on other sites

 

I wanted to search for the name Jon Smith and actually have it show me everyone who has the first name Jon and the last name Smith. Right now if I search for Jon Smith it will give me 0 results which makes sense but I instead need it to give me many results not only the person names Jon Smith but also anyone in the DB with the first name Jon and the last name Smith.

 

 

What are you actually looking for? If the data is stored as separate first and last names (given and family names), if you want to find "John Smith" wouldn't you ask for firstName = 'John' AND lastName = 'Smith'? If you ask for OR instead of AND, you would get back anyone with first name John. as well as anyone with last name Smith. I suspect that's not what you intend.

Link to comment
Share on other sites

Hi MrPhil,

 

The intention actually has nothing to do with the name but rather a group I have set 15 different groups of customers which are actually being assigned in the customers.php file... my actual search code now looks like this, thanks to Bob Terveuren

 

I basically need the groups to be picked out which works well now however if I wanted to export all the data from group1, group2, group3, group7 then the purpose would be to search for those groups using the search box and then export the search results to a CSV.

 

The name itself was irrelevant and I have no interest of using the name but rather felt that it was the best way to describe my request and the first part works great now! Thanks Bob Terveuren!!

 

    $search = '';
    if (isset($HTTP_GET_VARS['search']) && tep_not_null($HTTP_GET_VARS['search'])) {
      $keywords = tep_db_input(tep_db_prepare_input($HTTP_GET_VARS['search']));
 //new code - check for a space in the input
    if (strpos($keywords, ' ') !== false) {
             // Space found so split the input by spaces into an array
  $pieces=explode(' ',$keywords); 
// setup parts of the $search string
  $search .= "where ";
  $or = " ";
// run the new array and build $ search
   foreach ($pieces as $key=>$value){   
    $search .= $or ." c.customers_lastname like '%" . $value . "%' 
            or c.customers_firstname like '%" . $value . "%' 
                                 or c.group1 like '%" . $value . "%' 
  or c.group2 like '%" . $value . "%' 
or c.group3 like '%" . $value . "%' 
or c.group4 like '%" . $value . "%' 
or c.group5 like '%" . $value . "%' 
or c.group6 like '%" . $value . "%' 
or c.group7 like '%" . $value . "%' 
or c.group8 like '%" . $value . "%' 
or c.group9 like '%" . $value . "%' 
or c.group10 like '%" . $value . "%' 
or c.group11 like '%" . $value . "%' 
or c.group12 like '%" . $value . "%' 
or c.group13 like '%" . $value . "%' 
or c.group14 like '%" . $value . "%'
or c.group15 like '%" . $value . "%'
or c.customers_email_address like '%" . $value . "%'";
$or=" or "; // we do not need or on the first instance but we do now
 
}
 
}// end strpos
Link to comment
Share on other sites

Hi

 

Try this - I've hacked down some code that was to create a csv for orders/tax/stuff and it had two lines per order and a load of other geegaws  that I have pulled out so it may well not work without some error checking

 

Use this after the result of using $sql - $XXXXXX need to match your return string.

 

The original creates a single $csv and then writes it in one go to the filename - if you are likely to have a vast number of results then it may be better to write the csv a line or two at a time if the script times out - it should then email the csv to the store owner and then delete the file

<?php



if(tep_db_num_rows($XXXXX_query) == 0){exit("No records found for inclusion");}// or whatever you want


		  

// write header row for the csv if you want one - obviously yours will differ
// if you do not want a header then comment out the line below

#################################################################
 $csv = "Code(M),Currency,Date(M),(Period(M),Number(M),GL Account,Rel/Cost Centre(O),Prj/FA(O),Amount(M),debit/credit(M),Description(O),Invoice Number,VAT Code(M) \n";
###################################################################



//database query result handled here
while ($result1 = tep_db_fetch_array($XXXXXX_query)) {


//first row show full data
$csv.=",".//A
$result1['field'].",".//B
$result1['field2'].",".//C
",".//D
$the_number.",".//E
$gl_account.",".//F
",".//G
",".//H
$result1['field3'].",".//I
"debit,".//K
$result1['etc'].",".//L
$result1['etc'].",".//M
"\n"; 

//second row if needed here

}

// write the file


   $store_folder='';//admin sub folder if you want it
 


$filename = 'somename.csv';//filename 
$csv_handler = fopen ($filename,'w');
fwrite ($csv_handler,$csv);
fclose ($csv_handler);

 // email to store owner
  
    tep_mail_attach('', STORE_OWNER_EMAIL_ADDRESS, 'csv from '.STORE_NAME,  'VAT for orders '.$first_day.' to '.$last_day.' inclusive', STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS,$filename,$filename,'application/csv');

  $record.='<br /><br />Click <a href="'.$filename2.'" target="_blank"><u>here</u></a> to download the checksum file';
  
//delete file
  unlink ($filename);
}  
//end 

  function tep_mail_attach($to_name, $to_email_address, $email_subject, $email_text, $from_email_name, $from_email_address, $file, $filename, $filetype) {

   if (SEND_EMAILS != 'true') return false;

   $message = new email(array('X-Mailer: osCommerce'));

   $text = strip_tags($email_text);

         $message->add_text($text);
  

   $attachment = file_get_contents($file);
   $message->add_attachment($attachment, $filename, $filetype);
   
   $message->build_message();
   $message->send($to_name, $to_email_address, $from_email_name, $from_email_address, $email_subject);

 }


?>
Link to comment
Share on other sites

That didn't work for me however if this helps here is my code, I stripped some of it down but anything important is there.

<?php

  require('includes/application_top.php');

  $action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');

  $error = false;
  $processed = false;

  if (tep_not_null($action)) {
    switch ($action) {
      case 'update':
        $customers_id = tep_db_prepare_input($HTTP_GET_VARS['cID']);
        $customers_firstname = tep_db_prepare_input($HTTP_POST_VARS['customers_firstname']);
        $customers_lastname = tep_db_prepare_input($HTTP_POST_VARS['customers_lastname']);
        $customers_email_address = tep_db_prepare_input($HTTP_POST_VARS['customers_email_address']);
        $customers_telephone = tep_db_prepare_input($HTTP_POST_VARS['customers_telephone']);
        $customers_fax = tep_db_prepare_input($HTTP_POST_VARS['customers_fax']);
        $customers_newsletter = tep_db_prepare_input($HTTP_POST_VARS['customers_newsletter']);
        $initiative1 = tep_db_prepare_input($HTTP_POST_VARS['initiative1']);
        $initiative2 = tep_db_prepare_input($HTTP_POST_VARS['initiative2']);
        $initiative3 = tep_db_prepare_input($HTTP_POST_VARS['initiative3']);
        $initiative4 = tep_db_prepare_input($HTTP_POST_VARS['initiative4']);
        $initiative5 = tep_db_prepare_input($HTTP_POST_VARS['initiative5']);
        $initiative6 = tep_db_prepare_input($HTTP_POST_VARS['initiative6']);
        $initiative7 = tep_db_prepare_input($HTTP_POST_VARS['initiative7']);
        $initiative8 = tep_db_prepare_input($HTTP_POST_VARS['initiative8']);
        $initiative9 = tep_db_prepare_input($HTTP_POST_VARS['initiative9']);
        $initiative10 = tep_db_prepare_input($HTTP_POST_VARS['initiative10']);
        $initiative11 = tep_db_prepare_input($HTTP_POST_VARS['initiative11']);
        $initiative12 = tep_db_prepare_input($HTTP_POST_VARS['initiative12']);
        $initiative13 = tep_db_prepare_input($HTTP_POST_VARS['initiative13']);
        $initiative14 = tep_db_prepare_input($HTTP_POST_VARS['initiative14']);
        $initiative15 = tep_db_prepare_input($HTTP_POST_VARS['initiative15']);
        $initiative16 = tep_db_prepare_input($HTTP_POST_VARS['initiative16']);
        $initiative17 = tep_db_prepare_input($HTTP_POST_VARS['initiative17']);
        $initiative18 = tep_db_prepare_input($HTTP_POST_VARS['initiative18']);
        $initiative19 = tep_db_prepare_input($HTTP_POST_VARS['initiative19']);
        $initiative20 = tep_db_prepare_input($HTTP_POST_VARS['initiative20']);

        $prefix = tep_db_prepare_input($HTTP_POST_VARS['prefix']);
        $title = tep_db_prepare_input($HTTP_POST_VARS['title']);
        $organization = tep_db_prepare_input($HTTP_POST_VARS['organization']);
        $notes = tep_db_prepare_input($HTTP_POST_VARS['notes']);
        $default_address_id = tep_db_prepare_input($HTTP_POST_VARS['default_address_id']);
        $address1 = tep_db_prepare_input($HTTP_POST_VARS['address1']);
        $address2 = tep_db_prepare_input($HTTP_POST_VARS['address2']);
        $postal = tep_db_prepare_input($HTTP_POST_VARS['postal']);
        $city = tep_db_prepare_input($HTTP_POST_VARS['city']);
        $country = tep_db_prepare_input($HTTP_POST_VARS['country']);
        $entry_company = tep_db_prepare_input($HTTP_POST_VARS['entry_company']);
        $province = tep_db_prepare_input($HTTP_POST_VARS['province']);
 
       if (isset($HTTP_POST_VARS['entry_zone_id'])) $entry_zone_id = tep_db_prepare_input($HTTP_POST_VARS['entry_zone_id']);

          $entry_email_address_error = false;

          $entry_email_address_check_error = false;

        $entry_telephone_error = false;

        $entry_email_address_exists = false;

      if ($error == false) {

        $sql_data_array = array('customers_firstname' => $customers_firstname,
                                'customers_lastname' => $customers_lastname,
                                'address1' => $address1,
                                'address2' => $address2,
                                'city' => $city,
                                'province' => $province,
                                'postal' => $postal,
                                'country' => $country,
                                'customers_email_address' => $customers_email_address,
                                'customers_telephone' => $customers_telephone,
                                'customers_fax' => $customers_fax,
                                'initiative1' => $initiative1,
                                'initiative2' => $initiative2,
                                'initiative3' => $initiative3,
                                'initiative4' => $initiative4,
                                'initiative5' => $initiative5,
                                'initiative6' => $initiative6,
                                'initiative7' => $initiative7,
                                'initiative8' => $initiative8,
                                'initiative9' => $initiative9,
                                'initiative10' => $initiative10,
                                'initiative11' => $initiative11,
                                'initiative12' => $initiative12,
                                'initiative13' => $initiative13,
                                'initiative14' => $initiative14,
                                'initiative15' => $initiative15,
                                'initiative16' => $initiative16,
                                'initiative17' => $initiative17,
                                'initiative18' => $initiative18,
                                'initiative19' => $initiative19,
                                'initiative20' => $initiative20,
                                'customers_newsletter' => $customers_newsletter,
                                'prefix' => $prefix,
                                'title' => $title,
                                'organization' => $organization,
                                'notes' => $notes);

        tep_db_perform(TABLE_CUSTOMERS, $sql_data_array, 'update', "customers_id = '" . (int)$customers_id . "'");
   
        tep_redirect(tep_href_link(FILENAME_DEFAULT, tep_get_all_get_params(array('cID', 'action')) . 'cID=' . $customers_id));

        } else if ($error == true) {
          $cInfo = new objectInfo($HTTP_POST_VARS);
          $processed = true;
        }

        break;
      case 'deleteconfirm':
        $customers_id = tep_db_prepare_input($HTTP_GET_VARS['cID']);

        tep_db_query("delete from " . TABLE_CUSTOMERS . " where customers_id = '" . (int)$customers_id . "'");
        tep_db_query("delete from " . TABLE_CUSTOMERS_INFO . " where customers_info_id = '" . (int)$customers_id . "'");
        tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customers_id . "'");
        tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customers_id . "'");
        tep_db_query("delete from " . TABLE_WHOS_ONLINE . " where customer_id = '" . (int)$customers_id . "'");

        tep_redirect(tep_href_link(FILENAME_DEFAULT, tep_get_all_get_params(array('cID', 'action'))));
        break;
      default:
        $customers_query = tep_db_query("select * from " . TABLE_CUSTOMERS . " c where c.customers_id = '" . (int)$HTTP_GET_VARS['cID'] . "'");
        $customers = tep_db_fetch_array($customers_query);
        $cInfo = new objectInfo($customers);
    }
  }

  require(DIR_WS_INCLUDES . 'template_top.php');

  if ($action == 'edit' || $action == 'update') {
?>
<script type="text/javascript"><!--

function check_form() {
  var error = 0;
  var error_message = "<?php echo JS_ERROR; ?>";

  var customers_firstname = document.customers.customers_firstname.value;
  var customers_lastname = document.customers.customers_lastname.value;
<?php if (ACCOUNT_COMPANY == 'true') echo 'var entry_company = document.customers.entry_company.value;' . "\n"; ?>
<?php if (ACCOUNT_DOB == 'true') echo 'var customers_dob = document.customers.customers_dob.value;' . "\n"; ?>
  var customers_email_address = document.customers.customers_email_address.value;
  var entry_street_address = document.customers.entry_street_address.value;
  var entry_postcode = document.customers.entry_postcode.value;
  var entry_city = document.customers.entry_city.value;
  var customers_telephone = document.customers.customers_telephone.value;

<?php if (ACCOUNT_GENDER == 'true') { ?>
  if (document.customers.customers_gender[0].checked || document.customers.customers_gender[1].checked) {
  } else {
    error_message = error_message + "<?php echo JS_GENDER; ?>";
    error = 1;
  }
<?php } ?>

  if (customers_firstname.length < <?php echo ENTRY_FIRST_NAME_MIN_LENGTH; ?>) {
    error_message = error_message + "<?php echo JS_FIRST_NAME; ?>";
    error = 1;
  }

  if (customers_lastname.length < <?php echo ENTRY_LAST_NAME_MIN_LENGTH; ?>) {
    error_message = error_message + "<?php echo JS_LAST_NAME; ?>";
    error = 1;
  }

<?php if (ACCOUNT_DOB == 'true') { ?>
  if (customers_dob.length < <?php echo ENTRY_DOB_MIN_LENGTH; ?>) {
    error_message = error_message + "<?php echo JS_DOB; ?>";
    error = 1;
  }
<?php } ?>

  if (customers_email_address.length < <?php echo ENTRY_EMAIL_ADDRESS_MIN_LENGTH; ?>) {
    error_message = error_message + "<?php echo JS_EMAIL_ADDRESS; ?>";
    error = 1;
  }

  }

  if (customers_telephone.length < <?php echo ENTRY_TELEPHONE_MIN_LENGTH; ?>) {
    error_message = error_message + "<?php echo JS_TELEPHONE; ?>";
    error = 1;
  }

  if (error == 1) {
    alert(error_message);
    return false;
  } else {
    return true;
  }
}
//--></script>
<?php
  }
?>

    <table border="0" width="100%" cellspacing="0" cellpadding="2">
<?php
  if ($action == 'edit' || $action == 'update') {
    $newsletter_array = array(array('id' => '1', 'text' => ENTRY_NEWSLETTER_YES),
                              array('id' => '0', 'text' => ENTRY_NEWSLETTER_NO));
$initiative1_array = array(array('id' => '1', 'text' => Yes),
                              array('id' => '0', 'text' => No)); 
$initiative2_array = array(array('id' => '2', 'text' => Yes),
                              array('id' => '0', 'text' => No)); 
$initiative3_array = array(array('id' => '3', 'text' => Yes),
                              array('id' => '0', 'text' => No)); 
$initiative4_array = array(array('id' => '4', 'text' => Yes),
                              array('id' => '0', 'text' => No)); 
$initiative5_array = array(array('id' => '5', 'text' => Yes),
                              array('id' => '0', 'text' => No)); 
$initiative6_array = array(array('id' => '6', 'text' => Yes),
                              array('id' => '0', 'text' => No)); 
$initiative7_array = array(array('id' => '7', 'text' => Yes),
                              array('id' => '0', 'text' => No)); 
$initiative8_array = array(array('id' => '8', 'text' => Yes),
                              array('id' => '0', 'text' => No)); 
$initiative9_array = array(array('id' => '9', 'text' => Yes),
                              array('id' => '0', 'text' => No)); 
$initiative10_array = array(array('id' => '10', 'text' => Yes),
                              array('id' => '0', 'text' => No)); 
$initiative11_array = array(array('id' => '11', 'text' => Yes),
                              array('id' => '0', 'text' => No)); 
$initiative12_array = array(array('id' => '12', 'text' => Yes),
                              array('id' => '0', 'text' => No)); 
$initiative13_array = array(array('id' => '1', 'text' => Yes),
                              array('id' => '0', 'text' => No)); 
$initiative14_array = array(array('id' => '1', 'text' => Yes),
                              array('id' => '0', 'text' => No)); 
$initiative15_array = array(array('id' => '1', 'text' => Yes),
                              array('id' => '0', 'text' => No)); 
$initiative16_array = array(array('id' => '1', 'text' => Yes),
                              array('id' => '0', 'text' => No)); 
$initiative17_array = array(array('id' => '1', 'text' => Yes),
                              array('id' => '0', 'text' => No)); 
$initiative18_array = array(array('id' => '1', 'text' => Yes),
                              array('id' => '0', 'text' => No)); 
$initiative19_array = array(array('id' => '1', 'text' => Yes),
                              array('id' => '0', 'text' => No)); 
$initiative20_array = array(array('id' => '1', 'text' => Yes),
                              array('id' => '0', 'text' => No)); 
?>
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
            <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr><?php echo tep_draw_form('customers', FILENAME_DEFAULT, tep_get_all_get_params(array('action')) . 'action=update', 'post', 'onsubmit="return check_form();"') . tep_draw_hidden_field('default_address_id', $cInfo->customers_default_address_id); ?>
        <td class="formAreaTitle"><?php echo CATEGORY_PERSONAL; ?></td>
      </tr>
      <tr>
        <td class="formArea"><table border="0" cellspacing="2" cellpadding="2">

          <tr>
            <td class="main">Prefix: </td>
            <td class="main"><?php echo tep_draw_input_field('prefix', $cInfo->prefix, 'size="52"'); ?></td>
          </tr>
          <tr>
            <td class="main">First Name: </td>
            <td class="main"><?php echo tep_draw_input_field('customers_firstname', $cInfo->customers_firstname, 'size="52"');?></td>
          </tr>
          <tr>
            <td class="main">Last Name: </td>
            <td class="main"><?php echo tep_draw_input_field('customers_lastname', $cInfo->customers_lastname, 'size="52"');?></td>
          </tr>
          <tr>
            <td class="main">Title: </td>
            <td class="main"><?php echo tep_draw_input_field('title', $cInfo->title, 'size="52"'); ?></td>
          </tr>
          <tr>
            <td class="main">Organization: </td>
            <td class="main"><?php echo tep_draw_input_field('organization', $cInfo->organization, 'size="52"'); ?></td> 
          </tr>
          <tr>
            <td class="main">Notes: </td>
            <td class="main"><?php echo tep_draw_textarea_field('notes', 'soft', 50, 15, $cInfo->notes); ?></td>
          </tr>

        </table></td>
      </tr>


<?php
    if (ACCOUNT_COMPANY == 'true') {
?>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr>
        <td class="formAreaTitle"><?php echo CATEGORY_COMPANY; ?></td>
      </tr>
      <tr>
        <td class="formArea"><table border="0" cellspacing="2" cellpadding="2">
          <tr>
            <td class="main"><?php echo ENTRY_COMPANY; ?></td>
            <td class="main">
<?php
    if ($error == true) {
      echo $cInfo->entry_company . tep_draw_hidden_field('entry_company');
    } else {
      echo tep_draw_input_field('entry_company', $cInfo->entry_company, 'maxlength="32"');
    }
?></td>
          </tr>
        </table></td>
      </tr>
<?php
    }
?>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr>
        <td class="formAreaTitle"><?php echo CATEGORY_ADDRESS; ?></td>
      </tr>
      <tr>
        <td class="formArea"><table border="0" cellspacing="2" cellpadding="2">
          <tr>
            <td class="main"><?php echo ENTRY_STREET_ADDRESS; ?></td>
            <td class="main"><?php echo tep_draw_input_field('address1', $cInfo->address1, 'maxlength="64"'); ?></td>
          </tr>
          <tr>
            <td class="main">Address Line 2:</td>
            <td class="main"><?php echo tep_draw_input_field('address2', $cInfo->address2, 'maxlength="32"'); ?></td>
          </tr>

          <tr>
            <td class="main"><?php echo ENTRY_CITY; ?></td>
            <td class="main"><?php echo tep_draw_input_field('city', $cInfo->city, 'maxlength="32"'); ?></td>
          </tr>
          <tr>
            <td class="main">Province / State</td>
            <td class="main"><?php echo tep_draw_input_field('province', $cInfo->province, 'maxlength="200"'); ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo ENTRY_POST_CODE; ?></td>
            <td class="main"><?php echo tep_draw_input_field('postal', $cInfo->postal, 'maxlength="8"'); ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo ENTRY_COUNTRY; ?></td>
           <td class="main"><?php echo tep_draw_input_field('country', $cInfo->country, 'maxlength="200"'); ?></td>
  
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr>
        <td class="formAreaTitle"><?php echo CATEGORY_CONTACT; ?></td>
      </tr>
      <tr>
        <td class="formArea"><table border="0" cellspacing="2" cellpadding="2">
          <tr>
            <td class="main">Email Address: </td>
            <td class="main"><?php echo tep_draw_input_field('customers_email_address', $cInfo->customers_email_address, 'size="52"'); ?></td>
          </tr>
          <tr>
            <td class="main">Phone Number: </td>
            <td class="main"><?php echo tep_draw_input_field('customers_telephone', $cInfo->customers_telephone, 'size="52"'); ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo ENTRY_FAX_NUMBER; ?></td>
            <td class="main"><?php echo tep_draw_input_field('customers_fax', $cInfo->customers_fax, 'size="52"');?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr>
        <td class="formAreaTitle">Initiatives / Organizations</td>
      </tr>
      <tr>
        <td class="formArea"><table border="0" cellspacing="2" cellpadding="2">
	<tr>
            <td class="main">1
	<?php
  		if ($processed == true) {
    		if ($cInfo->initiative1 == '1') {
     		 echo Yes;
    		} else {
    		  echo No;
    		}
   		 echo tep_draw_hidden_field('initiative1');
  		} else {
  		  echo tep_draw_pull_down_menu('initiative1', $initiative1_array, (($cInfo->initiative1 == '1') ? '1' : '0'));
  		}
	?></td>
          </tr>

	<tr>
            <td class="main">2
	<?php
  		if ($processed == true) {
    		if ($cInfo->initiative2 == '2') {
     		 echo Yes;
    		} else {
    		  echo No;
    		}
   		 echo tep_draw_hidden_field('initiative2');
  		} else {
  		  echo tep_draw_pull_down_menu('initiative2', $initiative2_array, (($cInfo->initiative2 == '2') ? '2' : '0'));
  		}
	?></td>
          </tr>

	<tr>
            <td class="main">3
	<?php
  		if ($processed == true) {
    		if ($cInfo->initiative3 == '3') {
     		 echo Yes;
    		} else {
    		  echo No;
    		}
   		 echo tep_draw_hidden_field('initiative3');
  		} else {
  		  echo tep_draw_pull_down_menu('initiative3', $initiative3_array, (($cInfo->initiative3 == '3') ? '3' : '0'));
  		}
	?></td>
          </tr>

	<tr>
            <td class="main">4
	<?php
  		if ($processed == true) {
    		if ($cInfo->initiative4 == '4') {
     		 echo Yes;
    		} else {
    		  echo No;
    		}
   		 echo tep_draw_hidden_field('initiative4');
  		} else {
  		  echo tep_draw_pull_down_menu('initiative4', $initiative4_array, (($cInfo->initiative4 == '4') ? '4' : '0'));
  		}
	?></td>
          </tr>

	<tr>
            <td class="main">5
	<?php
  		if ($processed == true) {
    		if ($cInfo->initiative5 == '5') {
     		 echo Yes;
    		} else {
    		  echo No;
    		}
   		 echo tep_draw_hidden_field('initiative5');
  		} else {
  		  echo tep_draw_pull_down_menu('initiative5', $initiative5_array, (($cInfo->initiative5 == '5') ? '5' : '0'));
  		}
	?></td>
          </tr>

        </table></td>
      </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr>
        <td align="right" class="smallText"><?php echo tep_draw_button(IMAGE_SAVE, 'disk', null, 'primary') . tep_draw_button(IMAGE_CANCEL, 'close', tep_href_link(FILENAME_DEFAULT, tep_get_all_get_params(array('action')))); ?></td>
      </tr></form>
<?php
  } else {
?>
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading">Results</td>
            <td class="pageHeading" align="right">Export List</td>
            <td class="smallText" align="center" width="900"> 

	<form name="form1">
       <input type="checkbox" name="checkboxname" value="1">1  |  
       <input type="checkbox" name="checkboxname" value="2">2  |  
       <input type="checkbox" name="checkboxname" value="3">3  |  
       <input type="checkbox" name="checkboxname" value="4">4<br>
       <input type="checkbox" name="checkboxname" value="5">5  |  
    </form>
</td><td>
    <form name="form2">
		Search: <?php echo tep_draw_input_field('search', '', 'size="90"'); ?>
    </form>

<script src="clickforsearch.js"></script>

</td>

          <?php echo tep_hide_session_id(); ?></form></tr>
        </table></td>
      </tr>
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr class="dataTableHeadingRow">
                <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_FIRSTNAME; ?></td>
                <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_LASTNAME; ?></td>
                <td class="dataTableHeadingContent">E-Mail Address</td>
                <td class="dataTableHeadingContent">Initiatives</td>
              </tr>

<?php


//    $search = '';
//    if (isset($HTTP_GET_VARS['search']) && tep_not_null($HTTP_GET_VARS['search'])) {
//      $keywords = tep_db_input(tep_db_prepare_input($HTTP_GET_VARS['search']));
//
//      $search = "where c.customers_lastname like '%" . $keywords . "%' or c.customers_firstname like '%" . $keywords . "%' or c.initiative1 like '%" . $keywords . "%' or c.initiative2 like '%" . $keywords . "%' or c.initiative3 like '%" . $keywords . "%' or c.initiative4 like '%" . $keywords . "%' or c.initiative5 like '%" . $keywords . "%' or c.initiative6 like '%" . $keywords . "%' or c.initiative7 like '%" . $keywords . "%' or c.initiative8 like '%" . $keywords . "%' or c.initiative9 like '%" . $keywords . "%' or c.initiative10 like '%" . $keywords . "%' or c.initiative11 like '%" . $keywords . "%' or c.initiative12 like '%" . $keywords . "%' or c.initiative13 like '%" . $keywords . "%' or c.initiative14 like '%" . $keywords . "%' or c.initiative15 like '%" . $keywords . "%' or c.initiative16 like '%" . $keywords . "%' or c.initiative17 like '%" . $keywords . "%' or c.initiative18 like '%" . $keywords . "%' or c.initiative19 like '%" . $keywords . "%' or c.initiative20 like '%" . $keywords . "%' or c.customers_email_address like '%" . $keywords . "%'";
//    }


    $search = '';
    if (isset($HTTP_GET_VARS['search']) && tep_not_null($HTTP_GET_VARS['search'])) {		
      $keywords = tep_db_input(tep_db_prepare_input($HTTP_GET_VARS['search']));
	  //new code - check for a space in the input
	     if (strpos($keywords, ' ') !== false) {
             // Space found so split the input by spaces into an array
			   $pieces=explode(' ',$keywords); 
			 // setup parts of the $search string
			   $search .= "where ";
			   $or = " ";
			 // run the new array and build $ search
			    foreach ($pieces as $key=>$value){   
			    	$search .= $or ." c.customers_lastname like '%" . $value . "%' 
					             or c.customers_firstname like '%" . $value . "%' 
                                 or c.initiative1 like '%" . $value . "%' 
 								 or c.initiative2 like '%" . $value . "%' 
								 or c.initiative3 like '%" . $value . "%' 
								 or c.initiative4 like '%" . $value . "%' 
								 or c.initiative5 like '%" . $value . "%' 
								 or c.initiative6 like '%" . $value . "%' 
								 or c.initiative7 like '%" . $value . "%' 
								 or c.initiative8 like '%" . $value . "%' 
								 or c.initiative9 like '%" . $value . "%' 
								 or c.initiative10 like '%" . $value . "%' 
								 or c.initiative11 like '%" . $value . "%' 
								 or c.initiative12 like '%" . $value . "%' 
								 or c.initiative13 like '%" . $value . "%' 
								 or c.initiative14 like '%" . $value . "%'
								 or c.initiative15 like '%" . $value . "%'
								 or c.initiative16 like '%" . $value . "%'
								 or c.initiative17 like '%" . $value . "%'
								 or c.initiative18 like '%" . $value . "%'
								 or c.initiative19 like '%" . $value . "%'
								 or c.initiative20 like '%" . $value . "%'
								 or c.customers_email_address like '%" . $value . "%'";	
					$or=" or "; // we do not need or on the first instance but we do now
								 
				}
               
			 
			 }// end strpos
	  else{//original query
//		      $search = "where c.customers_lastname like '%" . $keywords . "%' or c.customers_firstname like '%" . $keywords . "%' or c.customers_email_address like '%" . $keywords . "%'";
      $search = "where c.customers_lastname like '%" . $keywords . "%' or c.customers_firstname like '%" . $keywords . "%' or c.initiative1 like '%" . $keywords . "%' or c.initiative2 like '%" . $keywords . "%' or c.initiative3 like '%" . $keywords . "%' or c.initiative4 like '%" . $keywords . "%' or c.initiative5 like '%" . $keywords . "%' or c.initiative6 like '%" . $keywords . "%' or c.initiative7 like '%" . $keywords . "%' or c.initiative8 like '%" . $keywords . "%' or c.initiative9 like '%" . $keywords . "%' or c.initiative10 like '%" . $keywords . "%' or c.initiative11 like '%" . $keywords . "%' or c.initiative12 like '%" . $keywords . "%' or c.initiative13 like '%" . $keywords . "%' or c.initiative14 like '%" . $keywords . "%' or c.initiative15 like '%" . $keywords . "%' or c.initiative16 like '%" . $keywords . "%' or c.initiative17 like '%" . $keywords . "%' or c.initiative18 like '%" . $keywords . "%' or c.initiative19 like '%" . $keywords . "%' or c.initiative20 like '%" . $keywords . "%' or c.customers_email_address like '%" . $keywords . "%'";
	  }
	  

    }//end if (isset($HTTP_GET_VARS['search']) && tep_not_null($HTTP_GET_VARS['search']))


    $customers_query_raw = "select * from " . TABLE_CUSTOMERS . " c " . $search . " order by c.customers_lastname, c.customers_firstname";
    $customers_split = new splitPageResults($HTTP_GET_VARS['page'], MAX_DISPLAY_SEARCH_RESULTS, $customers_query_raw, $customers_query_numrows);
    $customers_query = tep_db_query($customers_query_raw);
    while ($customers = tep_db_fetch_array($customers_query)) {
      $info_query = tep_db_query("select customers_info_date_account_created as date_account_created, customers_info_date_account_last_modified as date_account_last_modified, customers_info_date_of_last_logon as date_last_logon, customers_info_number_of_logons as number_of_logons from " . TABLE_CUSTOMERS_INFO . " where customers_info_id = '" . $customers['customers_id'] . "'");
      $info = tep_db_fetch_array($info_query);

      if ((!isset($HTTP_GET_VARS['cID']) || (isset($HTTP_GET_VARS['cID']) && ($HTTP_GET_VARS['cID'] == $customers['customers_id']))) && !isset($cInfo)) {
        $country_query = tep_db_query("select countries_name from " . TABLE_COUNTRIES . " where countries_id = '" . (int)$customers['entry_country_id'] . "'");
        $country = tep_db_fetch_array($country_query);

$customer_info = array_merge((array)$country, (array)$info);
$cInfo_array = array_merge((array)$customers, (array)$customer_info);

        $cInfo = new objectInfo($cInfo_array);
      }

      if (isset($cInfo) && is_object($cInfo) && ($customers['customers_id'] == $cInfo->customers_id)) {
        echo '          <tr id="defaultSelected" class="dataTableRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_DEFAULT, tep_get_all_get_params(array('cID', 'action')) . 'cID=' . $cInfo->customers_id . '&action=edit') . '\'">' . "\n";
      } else {
        echo '          <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_DEFAULT, tep_get_all_get_params(array('cID')) . 'cID=' . $customers['customers_id']) . '\'">' . "\n";
      }
?>
                <td class="dataTableContent"><?php echo $customers['customers_firstname']; ?></td>
                <td class="dataTableContent"><?php echo $customers['customers_lastname']; ?></td>
                <td class="dataTableContent"><?php echo $customers['customers_email_address']; ?></td>
                <td class="dataTableContent">
<?php if ($customers['initiative1'] != NULL) { ?><img src="icon1.png"><?php } ?>
<?php if ($customers['initiative2'] != NULL) { ?><img src="icon2.png"><?php } ?>
<?php if ($customers['initiative3'] != NULL) { ?><img src="icon3.png"><?php } ?>
<?php if ($customers['initiative4'] != NULL) { ?><img src="icon4.png"><?php } ?>
<?php if ($customers['initiative5'] != NULL) { ?><img src="icon5.png"><?php } ?>
<?php if ($customers['initiative6'] != NULL) { ?><img src="icon6.png"><?php } ?>
<?php if ($customers['initiative7'] != NULL) { ?><img src="icon7.png"><?php } ?>
<?php if ($customers['initiative8'] != NULL) { ?><img src="icon8.png"><?php } ?>
<?php if ($customers['initiative9'] != NULL) { ?><img src="icon9.png"><?php } ?>
<?php if ($customers['initiative10'] != NULL) { ?><img src="icon10.png"><?php } ?>
<?php if ($customers['initiative11'] != NULL) { ?><img src="icon11.png"><?php } ?>
<?php if ($customers['initiative12'] != NULL) { ?><img src="icon12.png"><?php } ?>
<?php if ($customers['initiative13'] != NULL) { ?><img src="icon13.png"><?php } ?>
</td>
              </tr>
<?php
    }
?>
              <tr>
                <td colspan="4"><table border="0" width="100%" cellspacing="0" cellpadding="2">
                  <tr>
                    <td class="smallText" align="right"><?php echo $customers_split->display_links($customers_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, MAX_DISPLAY_PAGE_LINKS, $HTTP_GET_VARS['page'], tep_get_all_get_params(array('page', 'info', 'x', 'y', 'cID'))); ?></td>
                  </tr>
<?php
    if (isset($HTTP_GET_VARS['search']) && tep_not_null($HTTP_GET_VARS['search'])) {
?>
                  <tr>
                    <td class="smallText" align="right" colspan="2"><?php echo tep_draw_button(IMAGE_RESET, 'arrowrefresh-1-w', tep_href_link(FILENAME_DEFAULT)); ?></td>
                  </tr>
<?php
    }
?>
                </table></td>
              </tr>
            </table></td>
<?php
  $heading = array();
  $contents = array();

  switch ($action) {
    case 'confirm':
      $heading[] = array('text' => '<strong>' . TEXT_INFO_HEADING_DELETE_CUSTOMER . '</strong>');

      $contents = array('form' => tep_draw_form('customers', FILENAME_DEFAULT, tep_get_all_get_params(array('cID', 'action')) . 'cID=' . $cInfo->customers_id . '&action=deleteconfirm'));
      $contents[] = array('text' => TEXT_DELETE_INTRO . '<br /><br /><strong>' . $cInfo->customers_firstname . ' ' . $cInfo->customers_lastname . '</strong>');
      $contents[] = array('align' => 'center', 'text' => '<br />' . tep_draw_button(IMAGE_DELETE, 'trash', null, 'primary') . tep_draw_button(IMAGE_CANCEL, 'close', tep_href_link(FILENAME_DEFAULT, tep_get_all_get_params(array('cID', 'action')) . 'cID=' . $cInfo->customers_id)));
      break;
    default:
      if (isset($cInfo) && is_object($cInfo)) {
        $heading[] = array('text' => '<strong>' . $cInfo->customers_firstname . ' ' . $cInfo->customers_lastname . '</strong>');

        $contents[] = array('align' => 'center', 'text' => tep_draw_button(IMAGE_EDIT, 'document', tep_href_link(FILENAME_DEFAULT, tep_get_all_get_params(array('cID', 'action')) . 'cID=' . $cInfo->customers_id . '&action=edit')) . tep_draw_button(IMAGE_DELETE, 'trash', tep_href_link(FILENAME_DEFAULT, tep_get_all_get_params(array('cID', 'action')) . 'cID=' . $cInfo->customers_id . '&action=confirm')));
        $contents[] = array('text' => '<br />' . $cInfo->prefix . ' ' . $cInfo->customers_firstname . ' ' . $cInfo->customers_lastname . '<br>' . $cInfo->address1 . ' ' . $cInfo->address2 . '<br>' . $cInfo->city . ' ' . $cInfo->province . ' ' . $cInfo->postal . '<br>' .  $cInfo->country . '<br><br>E-Mail: <a href="mailto:' . $cInfo->customers_email_address . '"><font color="blue"><u>' . $cInfo->customers_email_address . '</u></font></a><br><br>Phone: ' .  $cInfo->customers_telephone . '');
      }
      break;
  }

  if ( (tep_not_null($heading)) && (tep_not_null($contents)) ) {
    echo '            <td width="25%" valign="top">' . "\n";

    $box = new box;
    echo $box->infoBox($heading, $contents);

    echo '            </td>' . "\n";
  }
?>
          </tr>
        </table></td>
      </tr>
<?php
  }
?>
    </table>

<?php
  require(DIR_WS_INCLUDES . 'template_bottom.php');
  require(DIR_WS_INCLUDES . 'application_bottom.php');
?>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...