<?php
require($vqmod->modCheck('admin/GoTool/cat.inc'));

$display_block='';

function format_phone($telephone)
    {
    $phone = preg_replace("/[^0-9]/", "", $telephone);

    if(strlen($telephone) == 7)
    return preg_replace("/([0-9]{3})([0-9]{4})/", "$1-$2", $telephone);
    elseif(strlen($telephone) == 10)
    return preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "($1) $2-$3", $telephone);
    else
    return $telephone;
    }



    $tok=$_GET['token'];
if (isset($this->request->get['button'])) {
			$this->data['phone5a'] = $this->request->get['button'];
		} else {
			$this->data['phone5a'] = 'no entry';
		}

 $phone5 =$this->data['phone5a'];

  $phone = ereg_replace("[^A-Za-z0-9]", "", $phone5 );
  $phone = str_replace(' ', '', $phone);
   $phone2=substr($phone,0,-4);
  $blank="";

   $sql33 ="SELECT * FROM $table_name36 WHERE telephone LIKE '$phone' or telephone LIKE '$phone2%' ";
  $result33 = @mysql_query($sql33,$connection) or die(mysql_error());
  $num33 = mysql_num_rows($result33);

  if ($num33 >0 )  {
     $BHe="<font face = arial>The Following Customers Were Located for $phone or $phone2:</font>";
    }Else{
    $BHe="<font face = arial>No Records Were Located. </font>";
    }


    $result33 = @mysql_query($sql33,$connection) or die(mysql_error());
$num33 = mysql_num_rows($result33);

$result222 = @mysql_query($sql33,$connection) or die(mysql_error());
while ($row1 = mysql_fetch_array($result222)) {
 	$first = stripslashes($row1['firstname']);
    $last =stripslashes($row1['lastname']);
    $id2=  $row1['customer_id'];
    $login2 =$row1['store_id'];
    $address_id =$row1['address_id'];
  //  $company=  $row1['company'];
    $email=  $row1['email'];
    $telephone=  $row1['telephone'];

 $telephone= format_phone($telephone) ;


    $fax=  $row1['fax'];
     $fax= format_phone($fax) ;

       $sql34 ="SELECT * FROM $table_name40 WHERE address_id = '$address_id' ";
        $result224 = @mysql_query($sql34,$connection) or die(mysql_error());
        $row14 =mysql_fetch_array($result224,MYSQL_ASSOC);
        if ($address_id == $row14['address_id'])
        {
         $company=  $row14['company'];
     $address_1 =$row14['address_1'];
    $address_2 =$row14['address_2'];
    $city =$row14['city'];
    $postcode =$row14['postcode'];
    $country_id =$row14['country_id'];
    $zone_id =$row14['zone_id'];
        }

        $sql35 ="SELECT * FROM $table_name45 WHERE country_id = '$country_id' ";
        $result225 = @mysql_query($sql35,$connection) or die(mysql_error());
        $row15 =mysql_fetch_array($result225,MYSQL_ASSOC);
        if ($country_id == $row15['country_id'])
        {
         $country=  $row15['name'];
        }



        $sql36 ="SELECT * FROM $table_name46 WHERE country_id = '$country_id' AND zone_id = '$zone_id' ";
        $result226 = @mysql_query($sql36,$connection) or die(mysql_error());
        $row16 =mysql_fetch_array($result226,MYSQL_ASSOC);

     if (($zone_id == $row16['zone_id']) || ($country_id==$row16['country_id']))
        {
         $zone=  $row16['name'];
        }


 $display_block .= "<table  class=\"list\">
<thead>
<tr>
 <td class=\"right\"> Customer Id</td>
<td class=\"left\"> First Name</td>
<td class=\"left\"> Last Name</td>
<td class=\"right\"> Telephone</td>
		<td class=\"right\"> Fax</td>
		<td class=\"left\"> Email</td>
	   <td class=\"left\">Address</td>
		<td class=\"left\">View Orders</td>
		<td class=\"left\">View Folder</td>
	</tr> </thead>
    <tbody>
	<tr height=\"66\" style=\"height: 49.5pt\">
		<td class=\"right\">$id2</td>
		<td class=\"left\">$first</td>
		<td class=\"left\">$last</td>
		<td class=\"right\">$telephone</td>
		<td class=\"right\">$fax</td>
		<td class=\"left\">$email</td>
		<td class=\"left\">$company <br/>$address_1<br/>$city, $zone, $country <br/> $postcode</td>
		<td class=\"left\">
        <FORM  name=\"formcheck1\"  METHOD=\"POST\" ACTION=\"GoTool/report/test.php?token=$tok\">

			    <input type=\"hidden\" name=\"numID\" value=\"$id2\"  />


                <input type=\"hidden\" name=\"first\" value=\"$first\"  />
                <input type=\"hidden\" name=\"last\" value=\"$last\"  />

                <input type=\"hidden\" name=\"jedID2\" value=\"4\"  />
				<input name=\"button name0\" type=\"image\" src=\"GoTool/image/orderscopy.png\" align=\"center\" /></form>


        </td>
		<td class=\"left\">
        <FORM  name=\"formcheck1\"  METHOD=\"POST\" ACTION=\"../upload/customer/customer.php\">

				<input type=\"hidden\" name=\"numID\" value=\"$id2\"  />

                <input type=\"hidden\" name=\"first\" value=\"$first\"  />
                <input type=\"hidden\" name=\"last\" value=\"$last\"  />

                <input type=\"hidden\" name=\"jedID2\" value=\"3\"  />
				<input name=\"button name0\" type=\"image\" src=\"GoTool/image/fold33.png\" align=\"center\" />
                </form></td></tr><tr><td colspan=\"9\" >&nbsp;</td></tr>   </tbody></table><br/><br/>";

     }




  $hi3="This can have buttons, sub menus, etc.";
//  $this->config->get('user_id');
//$this->customer->getCustomerGroupId();
// $text_account2 = sprintf($this->customer->getCustomerGroupId());
//$this->customer->getId(); 	  
 //$text_account2 = sprintf($this->customer->getId());
 $this->user->getId();
   $hi2 = sprintf($this->user->getId());
 
$this->load->model('user/user');
$user_group_id = $this->model_user_user->getUser($this->user->getId());
$user_gid = $user_group_id['user_group_id'];

$hi1=$user_gid;
  $hi="$hi3<br/> User ID: $hi2<br />Group:$hi1 <br /> User Info: $phone5 <br /> Records: $BHe <br/><br/> $display_block <br/><br/>";
?>



<?php echo $header; ?>
<div id="content">
  <div class="breadcrumb">
    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
    <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
    <?php } ?>
  </div>
  <?php if ($error_install) { ?>
  <div class="warning"><?php echo $error_install; ?></div>
  <?php } ?>
  <?php if ($error_image) { ?>
  <div class="warning"><?php echo $error_image; ?></div>
  <?php } ?>
  <?php if ($error_image_cache) { ?>
  <div class="warning"><?php echo $error_image_cache; ?></div>
  <?php } ?>
  <?php if ($error_cache) { ?>
  <div class="warning"><?php echo $error_cache; ?></div>
  <?php } ?>
  <?php if ($error_download) { ?>
  <div class="warning"><?php echo $error_download; ?></div>
  <?php } ?>
  <?php if ($error_logs) { ?>
  <div class="warning"><?php echo $error_logs; ?></div>
  <?php } ?>
  <div class="box">
    <div class="heading">
      <h1><img src="view/image/home.png" alt="" /> <?php echo $heading_title; ?></h1>
    </div>
    <div class="content">  </br><b>Note: </b> <i>This view can be customized. <?php echo $hi; ?></i> <br/> <br/><br/>
      <div class="overview">
        <div class="dashboard-heading"><?php echo $text_overview; ?></div>
        <div class="dashboard-content">
          <table>
            <tr>
              <td><?php echo $text_total_sale; ?></td>
              <td><?php echo $total_sale; ?></td>
            </tr>
            <tr>
              <td><?php echo $text_total_sale_year; ?></td>
              <td><?php echo $total_sale_year; ?></td>
            </tr>
            <tr>
              <td><?php echo $text_total_order; ?></td>
              <td><?php echo $total_order; ?></td>
            </tr>
            <tr>
              <td><?php echo $text_total_customer; ?></td>
              <td><?php echo $total_customer; ?></td>
            </tr>
            <tr>
              <td><?php echo $text_total_customer_approval; ?></td>
              <td><?php echo $total_customer_approval; ?></td>
            </tr>
            <tr>
              <td><?php echo $text_total_review_approval; ?></td>
              <td><?php echo $total_review_approval; ?></td>
            </tr>
            <tr>
              <td><?php echo $text_total_affiliate; ?></td>
              <td><?php echo $total_affiliate; ?></td>
            </tr>
            <tr>
              <td><?php echo $text_total_affiliate_approval; ?></td>
              <td><?php echo $total_affiliate_approval; ?></td>
            </tr>
          </table>
        </div>
      </div>
      <div class="statistic">
        <div class="range"><?php echo $entry_range; ?>
          <select id="range" onchange="getSalesChart(this.value)">
            <option value="day"><?php echo $text_day; ?></option>
            <option value="week"><?php echo $text_week; ?></option>
            <option value="month"><?php echo $text_month; ?></option>
            <option value="year"><?php echo $text_year; ?></option>
          </select>
        </div>
        <div class="dashboard-heading"><?php echo $text_statistics; ?></div>
        <div class="dashboard-content">
          <div id="report" style="width: 390px; height: 170px; margin: auto;"></div>
        </div>
      </div>
      <div class="latest">
        <div class="dashboard-heading"><?php echo $text_latest_10_orders; ?></div>
        <div class="dashboard-content">
          <table class="list">
            <thead>
              <tr>
                <td class="right"><?php echo $column_order; ?></td>
                <td class="left"><?php echo $column_customer; ?></td>
                <td class="left"><?php echo $column_status; ?></td>
                <td class="left"><?php echo $column_date_added; ?></td>
                <td class="right"><?php echo $column_total; ?></td>
                <td class="right"><?php echo $column_action; ?></td>
              </tr>
            </thead>
            <tbody>
              <?php if ($orders) { ?>
              <?php foreach ($orders as $order) { ?>
              <tr>
                <td class="right"><?php echo $order['order_id']; ?></td>
                <td class="left"><?php echo $order['customer']; ?></td>
                <td class="left"><?php echo $order['status']; ?></td>
                <td class="left"><?php echo $order['date_added']; ?></td>
                <td class="right"><?php echo $order['total']; ?></td>
                <td class="right"><?php foreach ($order['action'] as $action) { ?>
                  [ <a href="<?php echo $action['href']; ?>"><?php echo $action['text']; ?></a> ]
                  <?php } ?></td>
              </tr>
              <?php } ?>
              <?php } else { ?>
              <tr>
                <td class="center" colspan="6"><?php echo $text_no_results; ?></td>
              </tr>
              <?php } ?>
            </tbody>
          </table>
        </div>
      </div>
    </div>
  </div>
</div>
<!--[if IE]>
<script type="text/javascript" src="view/javascript/jquery/flot/excanvas.js"></script>
<![endif]--> 
<script type="text/javascript" src="view/javascript/jquery/flot/jquery.flot.js"></script> 
<script type="text/javascript"><!--
function getSalesChart(range) {
	$.ajax({
		type: 'GET',
		url: 'index.php?route=common/home/chart&token=<?php echo $token; ?>&range=' + range,
		dataType: 'json',
		async: false,
		success: function(json) {
			var option = {	
				shadowSize: 0,
				lines: { 
					show: true,
					fill: true,
					lineWidth: 1
				},
				grid: {
					backgroundColor: '#FFFFFF'
				},	
				xaxis: {
            		ticks: json.xaxis
				}
			}

			$.plot($('#report'), [json.order, json.customer], option);
		}
	});
}

getSalesChart($('#range').val());
//--></script> 
<?php echo $footer; ?>
