<?php
define("_VALID_PHP", true);
require_once("../../init.php");
$page = basename($_SERVER["PHP_SELF"]);
$heder = "Lista";
$mali = " > za naručivanje";
$korisnik = $user->username;
$lokal = $user->fname;
$level = $user->userlevel;
$prezime = $user->lname;
$koje = $user->name;
//echo $koje;
$ip = $_SERVER['REMOTE_ADDR']; 
$kome = $user->sendto;
$id_user = $user->uid;
$dept = $user->todept;
$gdeje = "(".$dept.")";
//echo $gdeje;
$firma = $user->country;
$lokal = $_POST['lokal'];
$today = time();
$code = $id_user.$lokal.$today;
//echo $code;
//load the database configuration file
include 'dbConfig.php';
$query1 = $db->query("INSERT INTO orders (store,manager,code) VALUES ($lokal,$id_user,$code);");
//echo $lokal."<br>";
$answer = isset($_POST['quant']) ? $_POST['quant'] : "" ;
//$inputs = $_POST['quant'];
//var_dump($inputs);
if($query1){
foreach($answer as $key=>$value){
$query = $db->query("INSERT INTO odersdetail
 (productid,ordersid,quantity) VALUES ('$key','$code','$value')");
//echo $query;
//$questions->insertData($query,$con);
}
if($query){
echo '<script language="javascript">';
echo 'alert("Uspesno ste poslali porudzbinu");';
echo 'window.location.href = "http://service.poolteam.rs/";';
echo '</script>';
}
}
else
{
echo '<script language="javascript">';
echo 'alert("Proverite sve podatke, neuspesna porudzbenica");';
echo 'window.location.href = "http://service.poolteam.rs/";';
echo '</script>';	
}
?>