<?php
include ('../../config.inc.php');
require_once("../fpdf/fpdf.php"); // FIXME this needs to be part of configuration file
require_once("../fpdf/cl_pdfcard.php");
Session::Start();
define('RELATIVE_PATH','../fpdf/');
define('FPDF_FONTPATH','../fpdf/font/');
include_once ("../configuration/".$_SESSION['gatewayType'].".attr");
$oreon=$_SESSION['oreon'];
$dateFormat=$oreon->phpmyprepaid['display_date_format'];
$octet_type=$oreon->phpmyprepaid['octet_type'];
$pdfprint=$oreon->pdfprint;
if (isset($_POST['type']))
$type=$_POST['type'];
if (isset($_POST['attr'])) {
$attrr=$_POST['attr'];
$attr="Attribute='".$_POST['attr']."'";
}
if (isset($_POST['db']))
$db=$_POST['db'];
if (isset($_POST['div']))
$div=$_POST['div'];
if (isset($_POST['exp']))
$exp=$_POST['exp'];
$accountab=split(',',$_POST['id']);
//set up the display format .. This will change
/*-------------------------------------------------
To create the object, 2 possibilities:
either pass a custom format via an array
or use a built-in AVERY name
-------------------------------------------------*/
// Example of custom format; we start at the second column
//$pdf = new PDF_Label(array('name'=>'5163', 'paper-size'=>'A4', 'marginLeft'=>1, 'marginTop'=>1, 'NX'=>100, 'NY'=>100, 'SpaceX'=>0, 'SpaceY'=>0, 'width'=>120, 'height'=>20, 'metric'=>'mm', 'font-size'=>16), 1, 2);
// Standard format
if ($pdfprint['avery_name']=="None") {
$margin_left=$pdfprint['margin_left'];
$margin_top=$pdfprint['margin_top'];
$x_space=$pdfprint['x_space'];
$y_space=$pdfprint['y_space'];
$x_number=$pdfprint['x_number'];
$y_number=$pdfprint['y_number'];
$width=$pdfprint['width'];
$height=$pdfprint['height'];
$paper_size=$pdfprint['paper_size'];
$metric=$pdfprint['metric'];
$pdf = new PDF_card(array('name'=>'5163', 'paper-size'=>''.$paper_size.'', 'marginLeft'=>$margin_left, 'marginTop'=>$margin_top, 'NX'=>$x_number, 'NY'=>$y_number, 'SpaceX'=>$x_space, 'SpaceY'=>$y_space, 'width'=>$width, 'height'=>$height, 'metric'=>''.$metric.'', 'font-size'=>16), 1, 1);
}
else
$pdf = new PDF_card($pdfprint['avery_name']);
$pdf->_Set_Char_Size($pdfprint['char_size']);
$pdf->_Set_FontColor($pdfprint['font_color']);
$pdf->_Set_FontStyle(substr($pdfprint['font_style'],0,1));
$pdf->_Set_Font($pdfprint['font_name']);
$pdf->_Apply_Font_Attr();
$pdf->_Set_Point($pdfprint['print_point']);
$pdf->_Set_Cross($pdfprint['print_cross']);
if ($pdfprint['background_image']!="")
$pdf->_Set_BackgroundImage("../../".$pdfprint['background_image']);
if ($pdfprint['logo_image']!="")
$pdf->_Set_LogoImage("../../".$pdfprint['logo_image']);
$pdf->Open();
$pdf->AddPage();
for($i=0;$i<sizeof($accountab);$i++){
$username=$accountab[$i];
$q = "SELECT * FROM userinfo WHERE Username='$username' "; // get all the timed cards
$result = $_SESSION["oreon"]->database->database->query($q);
$row=$oreon->database->database->fetch_object($result);
$tp=$row->BillingPlan;
$activeDate=$row->activeDate;
$tp2=$row->Type;
$q2 = "SELECT Value FROM radcheck WHERE Attribute ='User-Password' and UserName='$username' "; // get all the timed cards
$result1 = $_SESSION["oreon"]->database->database->query($q2);
$row1=$oreon->database->database->fetch_array($result1);
$pass=$row1['Value'];
$pBp=get_plan_price($tp);
$nBp=get_plan_device($tp);
$q3 = "SELECT Value FROM $db WHERE $attr and UserName='$username' "; // get all the timed cards
if ($pBp=="") $pBp="none";
$result2=$oreon->database->database->query($q3) or die("Query database error !");
$result2 = $_SESSION["oreon"]->database->database->query($q3);
$row2=$oreon->database->database->fetch_array($result2);
$detail=$row2['Value'];
if ($tp2=="Subscription Expiration" or $tp2=="Expiration" ) {
$detail=date($dateFormat,strtotime($detail));
}
if ($tp2=="Subscription Expiration" or $tp2=="Expiration")
$val=date($dateFormat,strtotime($detail));
else if ($tp2 == "Hourly" or $tp2 == "Subscription Time")
$val = time2str ($detail );
else if ($tp2 == "Octets" or $tp2 == "Subscription Octets")
$val = octets2str ($detail);
//echo " PDF ".trim($pdfprint['format_text'])."<br>";
$res2="\n%s %s %s %s";
$res3="".$pdfprint['format_text']."";
$locname=$_SESSION['LocName'];
$pdf->Add_PDF_card(sprintf(str_replace('\n',"\n",$pdfprint['format_text']),$pdfprint['card_type_text'], $pdfprint['login_text'].$username,$pdfprint['passwd_text'].$pass,$pdfprint['validity_text'].$val,$pdfprint['location_text'].$locname),$pdfprint['header_text'],$pdfprint['footer_text']);
//$pdf->Add_PDF_card(sprintf($res2,$pdfprint['card_type_text'], $pdfprint['login_text'].$username,$pdfprint['passwd_text'].$pass,$pdfprint['validity_text'].$res));
}
$pdf->Output();
exit();
?>