<?php
    require '../vendor/autoload.php';
    require '../app/init.php';
    require '../app/config.php';
    
    $db_name = $config["db"]["name"];
    $db_user = $config["db"]["user"];
    $db_pass = $config["db"]["pass"];
    $db_host = $config["db"]["host"];
    $db = new mysqli( $db_host, $db_name, $db_user, $db_pass);
    if ($db->connect_errno) die ($db->connect_error);
    $table=$db->prepare("SHOW TABLE STATUS FROM $db_name");
    $table->execute();
    $sonuc = $table->get_result();
    while ($satir=$sonuc->fetch_assoc()){
        if ($satir["Name"]== "orders"){
            $ai[$satir["Name"]]=$satir["Auto_increment"];
        }
    }
    $LastAutoIncrement=$ai["orders"];
    
    
    
   
   
    if ( $settings["fake_order"] == 2 ) {
   $ospmin=$settings['fake_order_min'];
$creatifying= $settings['fake_order_min'];
$id=rand($ospmin,$creatifying);
}
else {
 $id=$settings["fake_order_fix"];
}

   

        
   

    
    //$id=$settings["fake_order_fix"]+ $LastAutoIncrement;
    
    


    $osp=$LastAutoIncrement+$id;
    $fake_order="osp";
    $conn->beginTransaction();
     $insert = $conn->prepare("INSERT INTO orders SET order_start=:count, order_error=:error,order_id=:osp,order_status=:order_status, client_id=:c_id, api_orderid=:order_id, service_id=:s_id, order_quantity=:quantity, order_charge=:price,
                order_url=:url,
                order_create=:create, order_extras=:extra, last_check=:last_check, order_api=:api, api_serviceid=:api_serviceid, dripfeed=:drip, dripfeed_totalcharges=:totalcharges, dripfeed_runs=:runs,
                dripfeed_interval=:interval, dripfeed_totalquantity=:totalquantity, dripfeed_delivery=:delivery
                ");
              $insert = $insert-> execute(array("count"=>$fake_order,"c_id"=>$fake_order,"error"=>"-","order_status"=>"osp","s_id"=>$fake_order["service_id"],"quantity"=>$fake_order,"price"=>$fake_order,"osp"=>$osp,"url"=>$fake_order,
                "create"=>date("Y.m.d H:i:s"),"extra"=>$fake_order,"order_id"=>0,"last_check"=>date("Y.m.d H:i:s"),"api"=>$fake_order,
                "api_serviceid"=>$fake_order["api_service"],"drip"=>$fake_order,"totalcharges"=>$fake_order,"runs"=>$runs,
                "interval"=>$fake_order,"totalquantity"=>$fake_order,"delivery"=>1
              ));
              
               $update = $conn->prepare("UPDATE settings SET panel_order=:osp WHERE id=:id");
            $update = $update->execute(array("id" =>1, "osp" =>$osp  ));
            
            $delete = $conn->prepare("DELETE FROM orders WHERE order_id=:id ");
              $delete->execute(array("id"=>$osp));
              
              $error  = 0;
                $conn->commit();

?>