<? 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']
        );
        
        $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","registrant_id=:search1",$bind);
        $deresult =$results[0];
        
        $tbind = array(":search1"=>$deresult['table_id']);
        $tresults = $db->select("tbl_table","tbl_id=:search1",$tbind);
        $tresult = $tresults[0];
        
        
        $extra1 = $deresult['remarks'];
        $extra2 = "";
        
        //print_r($deresult);
        if ($deresult['registrant_salutation']=="Prof" || $deresult['registrant_salutation']=="A/Prof" || $deresult['registrant_salutation']=="HE")
			$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=ARTC2022-WEB";
        
        //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 = "Delegate No : ".$deresult['registrant_sn']."\nFull Name : ".$fullname."\nCompany : ".$deresult['registrant_company']."\nTable No. : $extra1\nDiet : ".$deresult['registrant_maincourse']."\nRemarks : ".$deresult['registrant_remarks'];
        //echo $output;
        
        echo "1";
    }


?>