<?php 
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 

include("../lib/ado/adodb.inc.php");
include("../lib/generic.inc.php");
include("taxspl1.inc.php");

$fu=(int)@$_REQUEST['FUNC'];

switch ($fu)
{
case 1:
   export_license($db);
   break;
}

$db->Close();
//--------------------------------------
// Function area
//--------------------------------------
function export_license(&$db)
{
   $f1='data.lic';
   
   if (empty($_REQUEST['RAW'])) {
      header("Content-Type: application/octet-stream");
      header("Content-Disposition: attachment; filename=$f1");
   }
   
   do {
      $query="SELECT COUNT(*) FROM ser_einv_mac WHERE ei_mac=?";
      $data=array($_REQUEST['MAC']);
      if (!$db->Execute($query,$data)) {
         $s1=$db->ErrorMsg();
         break;
      }
      
      $ar1=array();
      for ($i=0;$i<6;$i++) {
         $ar1[] = substr($_REQUEST['MAC'], $i*2, 2);
      }
      $s1 = "[".implode('-', $ar1)."]\nIFORM.4.DESIGNER=1\nIFORM.4.BARCODE=1\nIFORM.4.INDEXER=0\nIFORM.5.DESIGNER=1\nIFORM.5.BARCODE=1\nIFORM.5.INDEXER=0\nCUSTOMER=AB VASSILOPOULOS\n";
      
   } while (false);
   
	$key40=sha1($s1);
	$ar20=array(); // 20 bytes
	for ($i=0;$i<40;$i+=2) {
		sscanf(substr($key40,$i,2),"%x",$x);
		$ar20[]=$x;
	}
   
   if (!empty($_REQUEST['RAW'])) {
      echo "<pre>$s1</pre>$key40";
      return;
   }

   $s2='';
	$l=strlen($s1);
	for ($i=0,$j=0; $i<$l; $i++) {
		$x = ord($s1{$i}) ^ $ar20[$j];
      echo chr($x);
		if (++$j >= 20) $j=0;
	}
	
   for ($i=0;$i<20;$i++) {
      echo chr($ar20[$i]);
   }
}
//--------------------------------------   