<? include("settings.php"); ?>
<?

	function url_get_contents ($Url) {
		if (!function_exists('curl_init')){ 
			die('CURL is not installed!');
		}
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $Url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		$output = curl_exec($ch);
		curl_close($ch);
		return $output;
	}


    if ($_REQUEST['submission_type']=="New"){
        $insert = array(
            "topic_id" => $_REQUEST['session'],
			"topic_others" => $_REQUEST['topic_others'],
            "abstract_op" => $_REQUEST['abssub'],
            "abstract_title" =>  $_REQUEST['topic_title'],
            "registrant_salutation" => $_REQUEST['registrant_salutation'],
            "registrant_lastname" => $_REQUEST['registrant_lastname'],
            "registrant_firstname" => $_REQUEST['registrant_firstname'],
            "registrant_organisation" => $_REQUEST['registrant_organisation'],
			"registrant_designation" => $_REQUEST['registrant_designation'],
            "registrant_email" => $_REQUEST['registrant_email'],
			"registrant_mobilecc" => $_REQUEST['registrant_mobilecc'],
			"registrant_mobile" => $_REQUEST['registrant_mobile'],
            "registrant_mailing1" => $_REQUEST['registrant_mailing1'],
			"registrant_mailing2" => $_REQUEST['registrant_mailing2'],
            "registrant_city" => $_REQUEST['registrant_city'],
			"registrant_state" => $_REQUEST['registrant_state'],
            "registrant_postal" => $_REQUEST['registrant_postal'],
            "registrant_country" => $_REQUEST['registrant_country'],
			"registrant_presenting" => $_REQUEST['registrant_presenting'],
			"registrant_student" => $_REQUEST['registrant_student'],
			"registrant_salutation1" => $_REQUEST['registrant_salutation1'],
            "registrant_lastname1" => $_REQUEST['registrant_lastname1'],
            "registrant_firstname1" => $_REQUEST['registrant_firstname1'],
            "registrant_organisation1" => $_REQUEST['registrant_organisation1'],
			"registrant_designation1" => $_REQUEST['registrant_designation1'],
            "registrant_email1" => $_REQUEST['registrant_email1'],
			"registrant_country1" => $_REQUEST['registrant_country1'],
			"registrant_presenting1" => $_REQUEST['registrant_presenting1'],
			"registrant_salutation2" => $_REQUEST['registrant_salutation2'],
            "registrant_lastname2" => $_REQUEST['registrant_lastname2'],
            "registrant_firstname2" => $_REQUEST['registrant_firstname2'],
            "registrant_organisation2" => $_REQUEST['registrant_organisation2'],
			"registrant_designation2" => $_REQUEST['registrant_designation2'],
            "registrant_email2" => $_REQUEST['registrant_email2'],
			"registrant_country2" => $_REQUEST['registrant_country2'],
			"registrant_presenting2" => $_REQUEST['registrant_presenting2'],
			"registrant_salutation3" => $_REQUEST['registrant_salutation3'],
            "registrant_lastname3" => $_REQUEST['registrant_lastname3'],
            "registrant_firstname3" => $_REQUEST['registrant_firstname3'],
            "registrant_organisation3" => $_REQUEST['registrant_organisation3'],
			"registrant_designation3" => $_REQUEST['registrant_designation3'],
            "registrant_email3" => $_REQUEST['registrant_email3'],
			"registrant_country3" => $_REQUEST['registrant_country3'],
			"registrant_presenting3" => $_REQUEST['registrant_presenting3'],
			"registrant_salutation4" => $_REQUEST['registrant_salutation4'],
            "registrant_lastname4" => $_REQUEST['registrant_lastname4'],
            "registrant_firstname4" => $_REQUEST['registrant_firstname4'],
            "registrant_organisation4" => $_REQUEST['registrant_organisation4'],
			"registrant_designation4" => $_REQUEST['registrant_designation4'],
            "registrant_email4" => $_REQUEST['registrant_email4'],
			"registrant_country4" => $_REQUEST['registrant_country4'],
			"registrant_presenting4" => $_REQUEST['registrant_presenting4'],
			"registrant_salutation5" => $_REQUEST['registrant_salutation5'],
            "registrant_lastname5" => $_REQUEST['registrant_lastname5'],
            "registrant_firstname5" => $_REQUEST['registrant_firstname5'],
            "registrant_organisation5" => $_REQUEST['registrant_organisation5'],
			"registrant_designation5" => $_REQUEST['registrant_designation5'],
			"registrant_presenting5" => $_REQUEST['registrant_presenting5'],
            "registrant_email5" => $_REQUEST['registrant_email5'],
			"registrant_country5" => $_REQUEST['registrant_country5'],
			"registrant_salutation6" => $_REQUEST['registrant_salutation6'],
            "registrant_lastname6" => $_REQUEST['registrant_lastname6'],
            "registrant_firstname6" => $_REQUEST['registrant_firstname6'],
            "registrant_organisation6" => $_REQUEST['registrant_organisation6'],
			"registrant_designation6" => $_REQUEST['registrant_designation6'],
            "registrant_email6" => $_REQUEST['registrant_email6'],
			"registrant_country6" => $_REQUEST['registrant_country6'],
			"registrant_presenting6" => $_REQUEST['registrant_presenting6'],
			"registrant_salutation7" => $_REQUEST['registrant_salutation7'],
            "registrant_lastname7" => $_REQUEST['registrant_lastname7'],
            "registrant_firstname7" => $_REQUEST['registrant_firstname7'],
            "registrant_organisation7" => $_REQUEST['registrant_organisation7'],
			"registrant_designation7" => $_REQUEST['registrant_designation7'],
            "registrant_email7" => $_REQUEST['registrant_email7'],
			"registrant_country7" => $_REQUEST['registrant_country7'],
			"registrant_presenting7" => $_REQUEST['registrant_presenting7'],
			"registrant_salutation8" => $_REQUEST['registrant_salutation8'],
            "registrant_lastname8" => $_REQUEST['registrant_lastname8'],
            "registrant_firstname8" => $_REQUEST['registrant_firstname8'],
            "registrant_organisation8" => $_REQUEST['registrant_organisation8'],
			"registrant_designation8" => $_REQUEST['registrant_designation8'],
            "registrant_email8" => $_REQUEST['registrant_email8'],
			"registrant_country8" => $_REQUEST['registrant_country8'],
			"registrant_presenting8" => $_REQUEST['registrant_presenting8'],
			"registrant_salutation9" => $_REQUEST['registrant_salutation9'],
            "registrant_lastname9" => $_REQUEST['registrant_lastname9'],
            "registrant_firstname9" => $_REQUEST['registrant_firstname9'],
            "registrant_organisation9" => $_REQUEST['registrant_organisation9'],
			"registrant_designation9" => $_REQUEST['registrant_designation9'],
            "registrant_email9" => $_REQUEST['registrant_email9'],
			"registrant_country9" => $_REQUEST['registrant_country9'],
			"registrant_presenting9" => $_REQUEST['registrant_presenting9'],
			"registrant_salutation10" => $_REQUEST['registrant_salutation10'],
            "registrant_lastname10" => $_REQUEST['registrant_lastname10'],
            "registrant_firstname10" => $_REQUEST['registrant_firstname10'],
            "registrant_organisation10" => $_REQUEST['registrant_organisation10'],
			"registrant_designation10" => $_REQUEST['registrant_designation10'],
            "registrant_email10" => $_REQUEST['registrant_email10'],
			"registrant_country10" => $_REQUEST['registrant_country10'],
			"registrant_presenting10" => $_REQUEST['registrant_presenting10'],
            "abstract_mode" => $_REQUEST['abstract_mode']
        );
		print_r($insert);
        $db->insert("tbl_abstract", $insert);

        $abstract_idarr = $db->run("SELECT LAST_INSERT_ID() as id;");
        $abstract_id = $abstract_idarr[0]['id'];
		
        $topic_id = str_pad($_REQUEST['session'],2,"0",STR_PAD_LEFT);
        
        $abstract_type = "Authors";
        
		if ($_REQUEST['abssub']=="O")
			$abstract_number = "O-".$topic_id."-".str_pad($abstract_id,4,"0",STR_PAD_LEFT);
		else
			$abstract_number = "P-".$topic_id."-".str_pad($abstract_id,4,"0",STR_PAD_LEFT);
			
        $update = array(
            "abstract_number" => $abstract_number
        );
        $bind = array(
            ":search1" => $abstract_id
        );
        $db->update("tbl_abstract", $update, "abstract_id = :search1", $bind);
        // Saving Abstract
        if (isset($_FILES['newabssub']) && $_FILES['newabssub']['name']!=""){
            $ext = substr(strrchr($_FILES['newabssub']['name'],'.'),1);
            $filename1 = $abstract_number.".".$ext;
            move_uploaded_file($_FILES['newabssub']['tmp_name'], $_SERVER['DOCUMENT_ROOT']."/Nanoman2024/abstract_documents/".$filename1);
            $update = array(
                "abstract_path" => $filename1
            );
            $db->update("tbl_abstract", $update, "abstract_id = :search1", $bind);
        }

        $paper_number = $abstract_number;
        $topic = $_REQUEST['topic_title'];
        if ($_REQUEST['abssub']=="O")
            $paper_type = "Oral";
        else
            $paper_type = "Poster";
        $name = $_REQUEST['registrant_firstname']." ".$_REQUEST['registrant_lastname'];

        $message = "
						Thank you for your submission.<br/><br/>

						Below is a record of your submission details.<br/><br/>

						Abstract / Paper Number: $paper_number<br/>
						Title: $topic<br/>
						Category: $paper_type<br/>
						Paper submitted by: $name<br/><br/>

						Please note that only ONE (1) revision is allowed via the portal from now to 31 June 2024. <br/><br/> 
						
						If you have questions, please contact our event secretariat, Ms Nicole May at secretariat@nanoman2024.com.<br/><br/> 
						
						Alternatively, you may visit our website for the latest updates and information on the event.";
						$contents = url_get_contents('https://www.events-sp.com/ACFS2023/sendemail.php?paper_number='.$paper_number."&submission_type=New&registrant_email=".$_REQUEST['registrant_email']);
						//echo $contents;
    }else if ($_REQUEST['submission_type']=="Revision"){
		// Need to check if it has already been accepted
		$bind = array(":search1"=>$_REQUEST['paper_number'], ":search2"=>$_REQUEST['email']);
		$results = $db->select("tbl_abstract","abstract_number = :search1 AND registrant_email = :search2",$bind);
		if (count($results)==0){
			$message = "Sorry, no such paper found!";
		}else{
			$result = $results[0];
			if ($result['abstract_status']!=1){
				$message = "Sorry, You cannot submit a revision as your submission has either been already accepted or rejected.";
			}else{
				if ($result['abstract_revision']==1)
					$message = "Sorry, You cannot submit another revision. <br/><br/>Please contact Ms India Wan at secretariat@iiw2020.com.";
				else{
					if (isset($_FILES['reabssub']) && $_FILES['reabssub']['name']!=""){
						$ext = substr(strrchr($_FILES['reabssub']['name'],'.'),1);
						$filename1 = $result['abstract_number']."-R.".$ext;
						move_uploaded_file($_FILES['reabssub']['tmp_name'], $_SERVER['DOCUMENT_ROOT']."/ACFS2023/abstract_documents/".$filename1);
						$update = array(
							"abstract_revision_path" => $filename1,
							"abstract_revision"=>1,
							"abstract_re_datetime"=>date("Y-m-d H:i:s")
						);
						$db->update("tbl_abstract", $update, "abstract_number = :search1 AND registrant_email = :search2", $bind);
						
						
						$paper_number = $result['abstract_number'];
						$topic = $result['abstract_title'];
						if ($result['abstract_op']=="OR")
							$paper_type = "Oral";
						else
							$paper_type = "Poster";
						$name = $result['registrant_firstname']." ".$result['registrant_lastname'];
						
						$message = "<b>ACKNOWLEDGEMENT OF REVISED ABSTRACT SUBMISSION</b><br/><br/>
                        

						Dear $name,<br/><br/>

						We have successfully received your revised abstract.<br/><br/>

						Abstract / Paper Number: $paper_number<br/>
						Title: $topic<br/>
						Category: $paper_type<br/>
						Paper submitted by: $name<br/><br/>

						Please do not delete this email because you require your Abstract /Paper Number to submit your full paper, and to complete your registration.<br/><br/>

						If you have questions, please contact our conference secretariat Ms Nelly Ang at secretariat@ncafm2023.org.  Alternatively, you may visit our website for the latest updates and information on the event.<br/><br/>
						";
						$contents = file_get_contents('https://www.events-sp.com/NCAFM2023/sendemail.php?paper_number='.$paper_number."&submission_type=Revision&registrant_email=".$result['registrant_email']);
						//echo $contents;
					}
				}
			}
		}
	}else if ($_REQUEST['submission_type']=="Full"){
		// Need to check if it has already been accepted
		$bind = array(":search1"=>$_REQUEST['paper_number'], ":search2"=>$_REQUEST['email']);
		$results = $db->select("tbl_abstract","abstract_number = :search1 AND registrant_email = :search2",$bind);
		if (count($results)==0){
			$message = "Sorry, no such paper found!";
		}else{
			$result = $results[0];
			if ($result['abstract_status']==4){
				$message = "Sorry, You cannot submit another full paper as your full submission has already been accepted.";
			}else{
				if ($result['abstract_full']==1)
					$message = "Sorry, You cannot submit another full paper.";
				else{
					if (isset($_FILES['papersub']) && $_FILES['papersub']['name']!=""){
						$ext = substr(strrchr($_FILES['papersub']['name'],'.'),1);
						$filename1 = $result['abstract_number']."-F.".$ext;
						move_uploaded_file($_FILES['papersub']['tmp_name'], $_SERVER['DOCUMENT_ROOT']."/ACFS2023/abstract_documents/".$filename1);
						$update = array(
							"abstract_full_path" => $filename1,
							"abstract_full"=>1,
							"abstract_full_datetime"=>date("Y-m-d H:i:s")
						);
						$db->update("tbl_abstract", $update, "abstract_number = :search1 AND registrant_email = :search2", $bind);
						
						
						$paper_number = $result['abstract_number'];
						$topic = $result['abstract_title'];
						if ($result['abstract_op']=="OR")
							$paper_type = "Oral";
						else
							$paper_type = "Poster";
						$name = $result['registrant_firstname']." ".$result['registrant_lastname'];
						
						$message = "<b>ACKNOWLEDGEMENT OF FULL PAPER SUBMISSION</b><br/><br/>
                        

						Dear $name,<br/><br/>

						We have successfully received your full paper.<br/><br/>
						
						Below is a record of your full paper submission details:<br/><br/>

						Abstract / Paper Number: $paper_number<br/>
						Title: $topic<br/>
						Category: $paper_type<br/>
						Paper submitted by: $name<br/><br/>
						
						If you have questions, please contact our conference secretariat Ms Nelly Ang at secretariat@ncafm2023.org.  Alternatively, you may visit our website for the latest updates and information on the event.
						";
						$contents = file_get_contents('https://www.events-sp.com/NCAFM2023/sendemail.php?paper_number='.$paper_number."&submission_type=Full&registrant_email=".$result['registrant_email']);

					}
				}
			}
		}
	}
    
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    
    <title>Nanoman 2024</title>
    
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Bootstrap -->
    <link href="css/bootstrap.css" rel="stylesheet">
      <link href="css/bootstrap-theme.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
      
        
  </head>
  <body>
<div class="well">
<div class="content" bgcolor="#FFFFD0">
  <div class="col-12 feature">
      <form class="form-horizontal" method="post" action="process.php">
          <center>
              <img src="nm24masthead.jpg" width="800"></img>
          </center>
          <br/><br/>
          <div class="form-group">
              <div class="col-lg-2">&nbsp;</div>
                <div class="col-lg-8">
                    <?=$message;?>
                </div>
              <div class="col-lg-2">&nbsp;</div>
          </div>
          
                
             
             
        
        </form>
    </div>


    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="js/jquery-1.11.2.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>
    <script>
        
    </script>
  </div>
</div>
</body>
</html>