<?
$rez=include("setup.php");
if (! $rez) //if can't find setup.php or not chmod'ed 
 {
  echo "<font color=red>Check Your setup.php file !</font>";
	exit;
 }

$dir='admin';
checkauth($dir);

include "menu.htm";

//-------------- ADD new dir ---------------------
if (isset($insertme))		
{
       if( check_if_exist($nameofcompanyzz_nes,"garant","NameOfCompany"))
       {
	print "This warranty service company exists";
       }
       else
       {	
       $result=mysql_query("
              insert into garant(
  ID,
  NameOfCompany,
  Tel,
  Cell,
  Fax,
  Address,
  ContactPerson
  ) 
  values (null, 
         '$nameofcompanyzz_nes',
         '$telofcompanyzz',
         '$cellofcompanyzz',
         '$faxofcompanyzz',
         '$addresscompanyzz_nes',
         '$contactpersonzz' )") or die (mysql_error(). " : ".mysql_errno());
       }
}
//----------------------- and insert new ----------------

//------delete dirs-categories --------------
   if (($deleteme="delete") && isset($cremove[0]))
     {	
	$result=0;
        $i=0;  
        $flag=1; //we need it to check if warranty company has products to service
                 //1 if does not service
     while($elements = each ($cremove))
     {
        $whois=$elements["value"];	
       if( check_if_exist($elements["value"],"product","GarantID")>=1)
       {
	 echo "This warranty service company has products.Can't be deleted<br>";
         $flag=0;
       }
       else
       {
        $query="delete from garant where ID=$whois";
        $result=$result . mysql_query($query)or die (mysql_error(). " : ".mysql_errno());     
        $i++;
       }
     }
	if ($result==$i && $flag)
          print "Operation succeeded<br><br>";


     }

//----------- end remove dirs-categories--------

// ------------- remove -------------------
print "<br><br><br><br>"; 	//---------------  vse dir v nyneshey dir  -----------------

print "<form action=$PHP_SELF method=post name=allgarants>
       <input type=hidden name=deleteme value=delete>";
$result=mysql_query("select * from garant order by NameOfCompany") or die (mysql_error(). " : ".mysql_errno());
print "<table border=0  cellpadding=3 cellspacing=0 width=400>";

       print "<tr><td width=20%>Remove</td><td>Name of company</td></tr><tr>";

while($row=mysql_fetch_object($result))
{
       print "<td><input type=checkbox name=cremove[] value=$row->ID></td> ";
       print "<td><a href=\"javascript:showuserdata('one_garant.php','$row->ID')\" title=\"Show about $row->NameOfCompany\">$row->NameOfCompany</a></td>";
       print "</tr>";
}
print "</table>";
print "<br><input type=reset name=reset value='Reset'> ";
print "<input type=submit value=Delete onclick='return del()'></form>";

//------------------ remove --------------------------

?>
<br>
<hr>
<form action=<?=$PHP_SELF?> method=post name=garantadd>
<input type="hidden" name=insertme><BR>
<table>
<tr>
       <td>*Name of company </td>
       <td><input type=text name=nameofcompanyzz_nes></td>
<tr>
       <td>Tel of company </td>
       <td><input type=text name=telofcompanyzz></td>
</tr>
<tr>
       <td>Cell of company </td>
       <td><input type=text name=cellofcompanyzz></td>
</tr>
<tr>
       <td>Fax of company </td>
       <td><input type=text name=faxofcompanyzz></td>
</tr>
<tr>
       <td>*Address of company </td>
       <td><input type=text name=addresscompanyzz_nes></td>
</tr>
<tr>
       <td>Contact person</td>
       <td><input type=text name=contactpersonzz></td>
</tr>
<tr>
        <td align=center><br><input type=reset value=Reset></td>
	<td align=center><br><input type=submit name=submit value=Submit onclick="return validate_form_no_email('garantadd ')"></td>
</tr>
</table>
</form>
