<?php
$display_comment='';
$display_block_call2='';
     $BHe='';
     $blink='';
      $section='';
      $num33A='';
      $j=20;
//        ${section.$j}='';

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'];
    $logged=$tok;
if (isset($this->request->get['button'])) {
			$this->data['phone5a'] = $this->request->get['button'];
		} else {
			$this->data['phone5a'] = 'no entry';
		}

 $phone5 =$this->data['phone5a'];

   $id_phone=$phone5;

  $phone = preg_replace("[^A-Za-z0-9]", "", $phone5 );
  $phone = str_replace(' ', '', $phone);
     $tool="baby";
  if($phone != $tool){

  if ($phone > 10000000){

   $phone2=substr($phone,0,-4);

   }else {

    $phone2=$phone;
   }
  $blank="";

   $sql33 ="SELECT * FROM $table_name36 WHERE telephone LIKE '$phone' or telephone LIKE '$phone2%' or customer_id='$id_phone' ";
  $result33 = @mysql_query($sql33,$connection) or die(mysql_error());
  $num33 = mysql_num_rows($result33);

  $num33A=$num33;

  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>";
    }

    If ($phone==$blink){
    $BHe="<font face = arial>No Telephone Search Requested. </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']);

    $company1="$first $last";
    $boris =strlen($company1);

    if ($boris>22){
      $company1=substr($company1,0,22);
    }



    $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'];
        }

     $sql35 ="SELECT * FROM .$table_name75 WHERE customer_id = '$id2' Order by create_date limit 5 ";
        $result225 = @mysql_query($sql35,$connection) or die(mysql_error());
         while ($row1225 = mysql_fetch_array($result225)) {
          $ag_id=  $row1225['map_id'];      //record
         $order_id2=  $row1225['app_id'];     //order
          $map_id=  $row1225['map_id'];
          $comment23=  $row1225['comments'];
          $cat23=  $row1225['category'];
          $commentdate=  $row1225['create_date'];

          $display_comment .="<tr> <td class=\"left\">$order_id2 </td><td class=\"left\">$commentdate</td><td>$cat23</td> <td class=\"left\">$comment23</td></tr> ";
          }

  //  ${section.$j}=$company1;

 $display_block_call2 .= "

 <h3 class=\"collapsible\" id=\"section$j\"> $id2  $company1<span></span><h3>
<div class=\"container\">
    <div class=\"content\">

    <table  class=\"list\">
<thead>
<tr>
 <td class=\"right\">Id</td>
<td class=\"left\"> Company</td>
<td class=\"right\"> Telephone</td>
		<td class=\"right\"> Fax</td>
		<td class=\"left\"> Email</td>
	   <td class=\"left\">Address</td>
	</tr> </thead>
    <tbody>
	<tr height=\"66\" style=\"height: 49.5pt\">
		<td class=\"right\">$id2</td>
		<td class=\"left\">$company1</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>
		</tr>   </tbody></table><br/>

        <table><tr><td><FORM  name=\"formcheck1\" target=\"GoTool\" METHOD=\"POST\" ACTION=\"GoTool/report/test_plain.php?token=$tok\">

			    <input type=\"hidden\" name=\"numID\" value=\"$id2\"  />
                 <input type=\"hidden\" name=\"telephone\" value=\"$id2\"  />

                <input type=\"hidden\" name=\"first\" value=\"$first\"  />
                <input type=\"hidden\" name=\"last\" value=\"$last\"  />

                <input type=\"hidden\" name=\"jedID2\" value=\"2\"  />
               <input type=\"submit\" value=\"Account\" name=\"B1\"></form></td>
               <td><FORM  name=\"formcheck1\" target=\"GoTool\" METHOD=\"POST\" ACTION=\"GoTool/report/test_plain.php?token=$tok\">

			    <input type=\"hidden\" name=\"numID\" value=\"$id2\"  />
                 <input type=\"hidden\" name=\"telephone\" value=\"$id2\"  />

                <input type=\"hidden\" name=\"first\" value=\"$first\"  />
                <input type=\"hidden\" name=\"last\" value=\"$last\"  />

                <input type=\"hidden\" name=\"jedID2\" value=\"1005\"  />
               <input type=\"submit\" value=\"History\" name=\"B1\"></form></td>
               <td><FORM  name=\"formcheck1\" target=\"GoTool\" METHOD=\"POST\" ACTION=\"GoTool/report/test_plain.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=\"4000\"  />
               <input type=\"submit\" value=\"Machines\" name=\"B1\"></form></td>
                <td>
                 <FORM  name=\"formcheck1\" target=\"GoTool\" METHOD=\"POST\" ACTION=\"GoTool/report/test_plain.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 type=\"submit\" value=\"Orders\" name=\"B1\"></form>
                </td>

               <td><FORM  name=\"formcheck1\" target=\"GoTool\" METHOD=\"POST\" ACTION=\"GoTool/report/test_plain.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=\"5000\"  />
               <input type=\"submit\" value=\"Folders\" name=\"B1\"></form></td>
               </tr></table>        <br/><br/>

        Last 5 Comments
                   <table  class=\"list\">
<thead>
<tr>
 <td class=\"left\"> Id</td>
 <td class=\"left\"> Date</td>
 <td class=\"left\"> Category</td>
 <td class=\"left\"> Comment</td>  </tr> </thead>
     $display_comment

     </table>

    </div>
</div>
                                                         ";

        $j=$j+1;

     }     }//end tool

     if ($num33A!=0){

     $display_block_call .="<div>$BHe<br/>$display_block_call2</div>";

     }else{
    $display_block_call .="<div>$BHe</div>";
     }
?>
