HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/molen.komma.pro/wwwroot/kms/bestelling_verzending_aanmaken.php
<?php

include_once('sendcloudApi.php');

if(isset($_POST['verzenden'])){
	$verzenden = true;
}

$order_id = $_GET['order_id'];
$order_id = checkData($order_id);

$filter = $_GET['filter'];
$filter = checkData($filter);

$maand = $_GET['maand'];
$maand = checkData($maand);


$q_order = "SELECT * FROM kms_orders WHERE kms_orders.order_id = '".$order_id."'";

$r_order = mysql_query($q_order);
$rec_order = mysql_fetch_assoc($r_order);


if($verzenden){
	
	if($rec_order['bezorgadresWijktAf'] == "no"){
	
		$naam = $rec_order['voornaam']." ";
		if(!empty($rec_order['tussenvoegsel'])){ $naam .= $rec_order['tussenvoegsel']." "; }
		$naam .= $rec_order['achternaam'];
		$naam = addslashes(html_entity_decode($naam));
	
		$bedrijfsnaam = addslashes(html_entity_decode($rec_order['bedrijfsnaam']));
		
		$adres = $rec_order['straatnaam']." ".$rec_order['huisnummer'];
		if(!empty($rec_order['toevoeging'])){ $adres .= "-".$rec_order['toevoeging']; }
		$adres = addslashes(html_entity_decode($adres));
			
		$postcode = addslashes(html_entity_decode($rec_order['postcode']));
		$woonplaats = addslashes(html_entity_decode($rec_order['woonplaats']));
		
		$land = addslashes(html_entity_decode($rec_order['land']));
		if($land == "Nederland"){ $landCode = "NL"; $shipment_id = 1; }else{ $landCode = "BE"; $shipment_id = 3; }

	}else{
		$naam = $rec_order['voornaamBezorg']." ";
		if(!empty($rec_order['tussenvoegselBezorg'])){ $naam .= $rec_order['tussenvoegselBezorg']." "; }
		$naam .= $rec_order['achternaamBezorg'];
		$naam = addslashes(html_entity_decode($naam));
		
		$bedrijfsnaam = addslashes(html_entity_decode($rec_order['bedrijfsnaamBezorg']));
		
		$adres = $rec_order['straatnaamBezorg']." ".$rec_order['huisnummerBezorg'];
		if(!empty($rec_order['toevoegingBezorg'])){ $adres .= "-".$rec_order['toevoegingBezorg']; }
		$adres = addslashes(html_entity_decode($adres));
				
		$postcode = addslashes(html_entity_decode($rec_order['postcodeBezorg']));
		$woonplaats = addslashes(html_entity_decode($rec_order['woonplaatsBezorg']));
		
		$land = addslashes(html_entity_decode($rec_order['landBezorg']));
		if($land == "Nederland"){ $landCode = "NL"; $shipment_id = 1; }else{ $landCode = "BE"; $shipment_id = 3; }
	}
	
	if($land == "Nederland"){ $aantal_zendingen = round($rec_order['verzendkosten'] / 6.9); }else{ $aantal_zendingen = round($rec_order['verzendkosten'] / 8.75); }
	
	$parcel_id = "";
						
	for($i=0;$i<$aantal_zendingen;$i++){
		
		$api = new SendcloudApi('live', 'jlp63pqdPXz3Ef5qXFXq','My4Tkw05JEWvjSb');
		$parcel = $api->parcels->create(
			array(
				'name'=> html_entity_decode($naam),
				'company_name' => html_entity_decode($bedrijfsnaam),
				'address' => html_entity_decode($adres),
				'city' => html_entity_decode($woonplaats),
				'postal_code' => html_entity_decode($postcode),
				'telephone' => $rec_order['telefoonnummer'],
				'requestShipment' => true, // set to true when you want to request a shipment
				'email' => $rec_order['emailadres'],
				'country' => $landCode,
				'shipment' => array(
					'id' => $shipment_id
				),
				'order_number' => $rec_order['ordernummer']
			
			)
		);
	
		$parcel_id .= $parcel['id'];
		
		if($i != ($aantal_zendingen-1)) $parcel_id .= ','; 
			
	}
		
	if(!empty($parcel_id)){ 
		$zending_aanmaken_succesvol = true; 
		
		$q_parcel_post = sprintf("UPDATE kms_orders SET parcel_id = '%s' WHERE kms_orders.order_id='%s'", $parcel_id, $order_id);
		$r_parcel_post = mysql_query($q_parcel_post);
			
	}else{ 
		$zending_aanmaken_succesvol = false; 
	}
		
	if($zending_aanmaken_succesvol){
		
		if($r_parcel_post){	
			echo("<h1>Verzending succesvol aangemaakt</h1><br />");
			echo("<p><strong>Aantal aangemaakte pakketten is: ".$aantal_zendingen."</strong></p><br />");
			echo("<p>De verzending is succesvol aangemaakt bij Sendcloud en PostNL. Wacht enkele seconden en print dan het verzendlabel via onderstaande knop.</p><br /><br />");

			echo("<a target=\"_blank\" class=\"submit_knop\" href=\"/kms/bestelling_label_printen.php?parcel_id=".$parcel_id."\" title=\"Labels printen\">Labels printen</a>");
			
			
		}else{
			echo("<h1>Verzending aanmaken mislukt</h1><br />");
			echo("<p>Het is mislukt om een verzending aan te maken.</p><br /><br />");
		}
	}else{
		echo("<h1>Verzending aanmaken mislukt</h1><br />");
		echo("<p>Het is mislukt om een verzending aan te maken.</p><br /><br />");
	}

	echo("<br /><br /><a class=\"submit_annuleren\" href=\"/kms/index.php?p=bestelling_info&amp;order_id=".$order_id."&amp;filter=".$filter."&amp;maand=".$maand."\" title=\"Terug naar overzicht\">Terug naar overzicht</a>");
	
}else{
?>

<h1>Zending aanmaken voor bestelling <?php echo(html_entity_decode($rec_order['ordernummer'])); ?></h1>

<?php if(!empty($rec_order['parcel_id'])){ ?>
	<p>Deze zending is al aangemaakt.<br /><br />
	<?php echo("<a target=\"_blank\" class=\"submit_knop\" href=\"/kms/bestelling_label_printen.php?parcel_id=".$rec_order['parcel_id']."\" title=\"Label printen\">Label printen</a>"); ?>
	<a class="submit_annuleren" href="index.php?p=bestelling_info&amp;order_id=<?php echo($order_id); ?>&amp;filter=<?php echo($filter);?>&amp;maand=<?php echo($maand); ?>" title="Terug">Terug</a>
<?php }else{ ?>


<p>Weet u zeker dat u een zending aan wil maken voor deze order?<br /><br />


<form action="<?php $_SERVER['PHP_SELF']; ?>" id="aanmelden" name="aanmelden" method="post">
	<div>    	    
        <input name="verzenden" type="submit" value="Zending aanmaken" class="submit" />
        <a class="submit_annuleren" href="index.php?p=bestelling_info&amp;order_id=<?php echo($order_id); ?>&amp;filter=<?php echo($filter);?>&amp;maand=<?php echo($maand); ?>" title="Annuleren">Annuleren</a>
	</div>
</form>

<?php
	}
}
?>