File: /var/www/html/amberconcept/create_po.php
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
//include wp libriries and set timezone to HK
require_once('wp-load.php');
date_default_timezone_set("Asia/Hong_Kong");
$wpdb->insert('custom_po_master', array(
'po_number' => $_POST['po_number'],
'po_date' => $_POST['po_date'],
'vendor_name' => $_POST['vendor_name'],
'vendor_detail' => $_POST['vendor_detail'],
'ship_detail' => $_POST['ship_detail'],
'customer_ship_address' => $_POST['customer_ship_address'],
'customerName' => $_POST['customerName'],
'customerAddress' => $_POST['customerAddress'],
'customerPhone' => $_POST['customerPhone'],
'courierPayment' => $_POST['courierPayment'],
'order_id' => $_POST['order_id'],
'currency' => $_POST['currency'],
'po_amount' => $_POST['grand_total'],
'create_by' => get_current_user_id(),
'modify_by' => get_current_user_id()
));
$po_id = $wpdb->insert_id;
foreach($_POST['item_sequence'] as $idx=>$sequence_value) {
//if($sequence_value != "") {
$wpdb->insert('custom_po_detail', array(
'po_id' => $po_id,
'item_name' => stripslashes($_POST['item_name'][$idx]),
'item_qty' => $_POST['item_qty'][$idx],
'item_unit_price' => $_POST['item_unit_price'][$idx],
'item_total' => $_POST['item_total'][$idx],
'item_sequence' => $sequence_value,
'item_type' => $_POST['item_type'][$idx],
));
$key = str_replace("PO#","PO",$_POST['po_number'])."-".($idx+1);
//echo "<br>";
$directory = "/var/www/html/ossfs/amber/po/".$key;
//echo "<br>";
$permissions = 0777;
if (!is_dir($directory)) {
// echo "create directory";
// echo "<br>";
// Create the directory
if (mkdir($directory, $permissions, true)) { // 'true' enables recursive creation of parent dirs if needed
// echo "change file permission 1";
// echo "<br>";
chmod($directory, $permissions);
}
} else {
// echo "change file permission 2";
// echo "<br>";
chmod($directory, $permissions);
}
//}
}
//create folder in amber PO ftp
echo "<meta http-equiv='refresh' content='0;url=https://www.amberconcept.com/po-new?mode=edit&id=".$po_id."' />";