<?php


$ipp = $_SERVER['REMOTE_ADDR'];
$ippp = str_replace(".","",$ipp);
//echo $ippp;

if ($ippp !== "89377097") {
    //header("HTTP/1.1 301 Moved Permanently");
    //echo header("location: https://www.dotcodes.net");
    echo "<script>window.location.href = 'https://dotcodes.net';</script>";
}


error_reporting(E_ALL);
ini_set('display_errors', 1);

$con = mysqli_connect('localhost','dotrazie_new','catalonia9f532','dotrazie_new');

if(!$con){
    die("couldnt connect".mysqli_error);
}

$result1 = mysqli_query($con,"SELECT * FROM customers c");
$result2 = mysqli_query($con,"SELECT p.Path FROM pictures p");


$usersList_array =array();
//$desktop_array = array();

$user_array = array();
$note_array = array();


$pictures_array = array();

while ($row_users = mysqli_fetch_assoc($result1)) {
    $user_array['ID'] = $row_users['ID'];
    $user_array['Name'] = $row_users['Name'];
    $user_array['Customer'] = $row_users['Customer'];
    $user_array['Technologies'] = $row_users['Technologies'];
    $user_array['Description'] = $row_users['Description'];
    $user_array['MainImage'] = $row_users['MainImage'];

    $user_array['Pictures'] = array();

    $pictures_array['Desktop'] = array();
    $pictures_array['Laptop'] = array();
    $pictures_array['Tablet'] = array();
    $pictures_array['Mobile'] = array();


    $fetch_notes = mysqli_query($con, "SELECT p.Path, p.ImageType FROM pictures p WHERE p.IDCustomer = ".$row_users["ID"]."") or die(mysqli_error($mysqli));

    $fetch_picsDesktop = mysqli_query($con,
        "SELECT p.Path, p.ImageType FROM pictures p 
WHERE p.IDCustomer = ".$row_users["ID"]." 
AND p.ImageType = 'Desktop'") or die(mysqli_error($mysqli));

    $fetch_picsLaptop = mysqli_query($con,
        "SELECT p.Path, p.ImageType FROM pictures p 
WHERE p.IDCustomer = ".$row_users["ID"]." 
AND p.ImageType = 'Laptop'") or die(mysqli_error($mysqli));

    $fetch_picsTablet = mysqli_query($con,
        "SELECT p.Path, p.ImageType FROM pictures p 
WHERE p.IDCustomer = ".$row_users["ID"]." 
AND p.ImageType = 'Tablet'") or die(mysqli_error($mysqli));

    $fetch_picsMobile = mysqli_query($con,
        "SELECT p.Path, p.ImageType FROM pictures p 
WHERE p.IDCustomer = ".$row_users["ID"]." 
AND p.ImageType = 'Mobile'") or die(mysqli_error($mysqli));




    while ($row_notes = mysqli_fetch_assoc($fetch_picsDesktop)) {
        $note_array['Path']=$row_notes['Path'];
        //$note_array['ImageType']=$row_notes['ImageType'];
        array_push($pictures_array['Desktop'], $note_array);
    }

    while ($row_notes = mysqli_fetch_assoc($fetch_picsLaptop)) {
        $note_array['Path']=$row_notes['Path'];
        //$note_array['ImageType']=$row_notes['ImageType'];
        array_push($pictures_array['Laptop'], $note_array);
    }

    while ($row_notes = mysqli_fetch_assoc($fetch_picsTablet)) {
        $note_array['Path']=$row_notes['Path'];
        //$note_array['ImageType']=$row_notes['ImageType'];
        array_push($pictures_array['Tablet'], $note_array);
    }

    while ($row_notes = mysqli_fetch_assoc($fetch_picsMobile)) {
        $note_array['Path']=$row_notes['Path'];
        //$note_array['ImageType']=$row_notes['ImageType'];
        array_push($pictures_array['Mobile'], $note_array);
    }



    array_push($user_array['Pictures'],$pictures_array);


    array_push($usersList_array,$user_array);
}




$jsonData = json_encode($usersList_array, JSON_PRETTY_PRINT);

//echo $jsonData;





?>


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<!--<form action="uploadImage.php" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" multiple="multiple" name="fileToUpload[]" id="fileToUpload">
    <input type="submit" value="Upload Image" name="submit">

    action="uploadImage.php"
</form>-->

<form id="uploadForm"  action="uploadImage.php" method="post" enctype="multipart/form-data">
    <table width="100%">
        <tr>
            <div>Select Photo (one or multiple):</div>

            <div>
                <input type="file" name="files[]" multiple/>
                <select name="customer">
                    <option value="anna">anna</option>
                    <option value="noctis">NoctisArt</option>
                    <option value="crm">crm</option>
                    <option value="dogs">dogs</option>
                    <option value="happy">happy</option>
                    <option value="superbe">superbe</option>
                    <option value="mobila">mobile</option>
                    <option value="pretty">pretty claire</option>
                    <option value="radu">radu</option>
                    <option value="ovidiu">ovidiu</option>
                    <option value="asociatia">asocitia 21</option>
                    <option value="rtd">rtd</option>
                    <option value="tsm">tsm</option>
                    <option value="tehnoshop">tehnoshop</option>
                    <option value="elaborat">e-laborat</option>
                    <option value="wire">wire</option>
                    <option value="vma">vma</option>
<!--                    <option value="invitatii">invitatii.dotcodes</option>-->
                </select>
                <select name="imageType">
                    <option value="Desktop">Desktop</option>
                    <option value="Laptop">Laptop</option>
                    <option value="Tablet">Tablet</option>
                    <option value="Mobile">Mobile</option>
                </select>
                <input type="submit" value="Create Gallery" id="selectedButton"/>
            </div>

            <div  align="center">Note: Supported image format: .jpeg, .jpg, .png, .gif</div>
            <div  align="center"></div>
</form>

<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>


<script>
    /*  $('form#uploadForm').on('submit' , function(e){
          e.preventDefault();



          $.ajax({
              url:"uploadImage.php" ,
              type: "POST" ,
              data: {
                  fname: $('#fname').val(), // you can change fname with what you want
                  lname: $('#lname').val() // you can change lname with what you want
              },
              success: function(data){
                  $('#responce-box').html(data);}
          });

        });

         */
</script>

</body>
</html>

<?php

echo "<pre>";
echo print_r($jsonData);

echo "<pre>";

?>
