<? include ("../settings.php"); ?>
<? include ("session.php"); ?>
<?
    if (isset($_REQUEST['registrant_id']) && $_REQUEST['registrant_id']>0){

        $insert = array(
            "registrant_id" => $_REQUEST['registrant_id'],
            "session_id" => $_REQUEST['session_id'],
			"user_id"=>$_SESSION['user_id']
        );
        
        $bind = array(":search1"=>$registrant_id);
        $exists = $db->select("tbl_registrant_attendance","registrant_id = :search1",$bind);
        if (count($exists)==0)
            $db->insert("tbl_registrant_attendance", $insert);
        
        //$db->delete("tbl_registrant", "registrant_id = :search1", $bind);
        
        
        // Sending to Print DB
        $bind = array (":search1"=>$_REQUEST['registrant_id']);
        $results = $db->select("tbl_registrant as a, tbl_role as b","registrant_id=:search1 AND a.role_id=b.role_id",$bind);
        $deresult =$results[0];
        
        $extra1 = $deresult['remarks'];
        $extra2 = "";

        if ($deresult['registrant_salutation']=="Prof" || $deresult['registrant_salutation']=="AProf" || $deresult['registrant_salutation']=="Dr" || $deresult['registrant_salutation']=="A/Prof")
			$fullname = $deresult['registrant_salutation']." ".$deresult['registrant_fullname'];        
        else
        	$fullname = $deresult['registrant_fullname'];
        $var = "user_name=sp&user_password=spspsp&name=".urlencode($fullname)."&sn=".urlencode($deresult['registrant_sn'])."&company=".urlencode($deresult['registrant_organisation'])."&extra1=".urlencode($extra1)."&extra2=N.A.&printer=".urlencode($_SESSION['user_printer'])."&event=APCOT2024";

        //echo $var;
        $contents = file_get_contents('https://www.events-sp.com/PRINT/insert.php?'.$var);
        //$contents = file_get_contents('https://www.events-sp.com/PRINT/insert.php?'.$var);
		//echo "<script>alert('Delegate attendance taken.');parent.thickBoxDone();</script>";       
		$output = "Registration Type : ".$deresult['registrant_type']."\nDelegate Number : ".$deresult['registrant_sn']."\nName : ".$fullname."\nOrganisation : ".$deresult['registrant_organisation']."\nBadge Colour : ".$deresult['registrant_badgecolour']."\nPayment Status : ".$deresult['registrant_paid']."\nRemarks : ".$deresult['remarks']."\n\n";  		
        echo $output;
        
    }


?>