 <?php

        $con = new mysqli("localhost","root","toor","museam_db");
        mysqli_set_charset($con, 'utf8');

        // Check connection
        if (mysqli_connect_errno())
          {
          echo "Failed to connect to MySQL: " . mysqli_connect_error();
          }

            if(!isset($_SESSION))
            session_start();
     //   foreach ($_SESSION as $key=>$val)
     //   echo $key. ": ".$val. "<br>";

        $syntir_msg ="";
        
        include_once("/includes/errorcheck.php");


        if (isset($_POST['save']) and $_POST['save']=="syntir"){


            if(!isset($_POST['syntir_syntiritis']))  
                $syntir_msg .= 'Δεν βρέθηκε διαθέσιμος συντηρητής. Παρακαλώ προχωρήστε στην καταχώρηση κάποιου στην καρτέλα ->Υπάλληλοι.<br/>';

            if(!isset($_POST['syntir_manager']))  
                $syntir_msg .= 'Δεν βρέθηκε διαθέσιμος διοικητικός. Παρακαλώ προχωρήστε στην καταχώρηση κάποιου στην καρτέλα ->Υπάλληλοι.<br/>';

            if(!isset($_POST['syntir_arc']))  
                $syntir_msg .= 'Δεν βρέθηκε διαθέσιμος αρχαιολόγς. Παρακαλώ προχωρήστε στην καταχώρηση κάποιου στην καρτέλα ->Υπάλληλοι.<br/>';

            if(!preg_match($strin_num_exp,$_POST['syntir_code']) || strlen($_POST['syntir_code'])<3)  
                $syntir_msg .= 'Ο Κωδικός δεν είναι έγκυρος ή ειναι κάτω των τριών χαρακτήρων.<br/>';

            if(strlen($_POST['syntir_budget'])<1)  
                $syntir_msg .= 'Ο Προυπολογισμός δεν είναι έγκυρος.<br/>';

            if(!isset($_SESSION['aithousa']))
                $syntir_msg .= 'Δέν έχετε επιλέξει κάποια αίθουσα. <br/>';

            if (!strlen($syntir_msg) and isset($_SESSION['type']) and ($_SESSION['type']=='syntiriseis_up') && isset($_SESSION['mouseio']) && isset($_SESSION['aithousa'])){

                $result = $con->query("UPDATE syntiriseis SET kwdikos='".$_POST['syntir_code']."',budget='".$_POST['syntir_budget']."',start_date='".$_POST['syntir_start_date']."',end_date='".$_POST['syntir_end_date']."',syntiritis_id='".$_POST['syntir_syntiritis']."',manager_id='".$_POST['syntir_manager']."',archaeologist_id='".$_POST['syntir_arc']."',museam_id='".$_SESSION['mouseio']."',room_id='".$_SESSION['aithousa']."' WHERE id=".$_SESSION['id'].";");
                $syntir_msg .= 'Η Εγγραφή ενημερώθηκε επιτυχώς στην βάση.<br/>';
                if(isset($_SESSION))
                session_destroy();
            }

            if (!strlen($syntir_msg) and !isset($_SESSION['type']) and isset($_SESSION['mouseio']) and isset($_SESSION['aithousa'])){

            $query = "INSERT INTO syntiriseis (kwdikos,budget,start_date,end_date,syntiritis_id,manager_id,archaeologist_id,museam_id,room_id) VALUES ('".$_POST['syntir_code']."','".$_POST['syntir_budget']."','".$_POST['syntir_start_date']."','".($_POST['syntir_end_date'])."','".$_POST['syntir_syntiritis']."','".$_POST['syntir_manager']."','".$_POST['syntir_arc']."','".$_SESSION['mouseio']."','".$_SESSION['aithousa']."')";
                $result=mysqli_query($con,$query);
                $syntir_msg .= 'Η Εγγραφή προστέθηκε επιτυχώς στην βάση.<br/>';
            }
            header("Refresh:3;url=http://127.0.0.1/museam/suntiriseis.php");
    }
    ?>


<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>About - Business Casual - Start Bootstrap Theme</title>

    <!-- Bootstrap Core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="css/business-casual.css" rel="stylesheet">
    <link href="css/flow.css" rel="stylesheet">
    <script type='text/javascript' src='js/function/common.js'></script>


    <!-- Fonts -->
    <link href="http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800" rel="stylesheet" type="text/css">
    <link href="http://fonts.googleapis.com/css?family=Josefin+Slab:100,300,400,600,700,100italic,300italic,400italic,600italic,700italic" rel="stylesheet" type="text/css">

    <script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
    <script type='text/javascript' src='js/flow.js'></script>

    <!-- Custom CSS -->
    <link href="css/freelancer.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <link href="http://fonts.googleapis.com/css?family=Montserrat:400,700" rel="stylesheet" type="text/css">
    <link href="http://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic" rel="stylesheet" type="text/css">

    <!-- MetisMenu CSS -->
    <link href="css/metisMenu.min.css" rel="stylesheet">

    <!-- DataTables CSS -->
    <link href="css/dataTables.bootstrap.css" rel="stylesheet">

</head>

<body id="page-top" class="index">

 <!-- Navigation -->
    <nav class="navbar_fixed_top">
        <div class="container">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header page-scroll">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="#page-top">Start Bootstrap</a>
            </div>

             <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav navbar-left">
                <li class="page-scroll">
                        <img class="main_image_bar" id="proswpa"src="images/icons_black/sintiriseis.png">
                        </li>
                    <li class="page-scroll">
                       <a href="suntiriseis.php"><i class="fa fa-star-half"></i>ΣΥΝΤΗΡΗΣΕΙΣ</a>
                    </li>
                
                </ul>
            </div>
            <!-- /.navbar-collapse -->
        </div>
        <!-- /.container-fluid -->
    </nav>

 <!--create-flow-menu-->
 <?php
  include_once("/includes/flowmenu.php");
 ?>
 <!-- /.create-flow-menu -->     

    <section class="top_pad" id="sun">
        <div class="container"> 

            <div class="row">
                <div class="col-lg-12 text-center">
                    <hr class="star-primary">
                    <h2 class="intro-text text-center">ΠΡΟΣΘΗΚΗ
                            <strong>ΣΥΝΤΗΡΗΣΗΣ</strong>
                    </h2>
                    <hr class="star-primary2">
                </div>
            </div>

              <div class="row">
                <div class="col-lg-12 text-center">
                    <p class="main_img_text2"> 
                    <?=$syntir_msg?> </p>
                </div>
            </div>
                
            <div class="row">       
                <div class="box">
                    <div class="col-md-6">  

                        <table class="main_table">
                            <tr>

                            <td>
                            <figure class="cap-left">
                                       <img class="img_inside_box" src="images/images_inside_box/sintiriseis/sintiriseis.jpg" alt="">
                                        <figcaption>Κλασικός Ναός Απόλλωνα | Πελοπόννησος.</figcaption>
                                    </figure>
                            </td>
                            <td rowspan="2">
                            <form  method="post" action="">
                                <div class="main_div1">

                                         <label>Κωδικός:</label>
                                        <div class="form-group input-group">
                                            <span class="input-group-addon"> <i class="fa fa-barcode"> </i> </span>
                                            <input name="syntir_code" value="<?=((isset($_SESSION['kwdikos']) and ($_SESSION['type']=='syntiriseis_up')) ? $_SESSION['kwdikos'] : '')?>" type="text" class="form-control" placeholder="Δώστε ένα κωδ. επισκευής.">
                                        </div>

                                         <label>Προϋπολογισμός:</label>
                                        <div class="form-group input-group">
                                            <span class="input-group-addon"> <i class="fa fa-euro"> </i> </span>
                                            <input name="syntir_budget" value="<?=((isset($_SESSION['budget']) and ($_SESSION['type']=='syntiriseis_up')) ? $_SESSION['budget'] : '')?>" type="text" class="form-control" placeholder="Δώστε ένα προϋπ. επισκευής.">
                                        </div>

                                         <label>Ημερομηνία Έναρξης:</label>
                                        <div class="form-group input-group">
                                            <span class="input-group-addon"> <i class="fa fa-calendar"> </i> </span>
                                            <input name="syntir_start_date" value="<?=((isset($_SESSION['start_date']) and ($_SESSION['type']=='syntiriseis_up')) ? $_SESSION['start_date'] : date('Y-m-d'))?>" type="date" class="form-control">
                                        </div>

                                        <label>Ημερομηνία Λήξης:</label>
                                        <div class="form-group input-group">
                                            <span class="input-group-addon"> <i class="fa fa-calendar"> </i> </span>
                                            <input name="syntir_end_date" value="<?=((isset($_SESSION['end_date']) and ($_SESSION['type']=='syntiriseis_up')) ? $_SESSION['end_date'] : date('Y-m-d'))?>" type="date" class="form-control">
                                        </div>

                                        <label>Επιλέξτε Συντηρητή:</label>
                                        <div class="form-group input-group">
                                        <span class="input-group-addon"> <i class="fa fa-user"> </i> </span>
                                        <select name="syntir_syntiritis" class="form-control">
                                            <?php
                                                $query = "SELECT id,full_name FROM preservatives ORDER BY full_name ASC;";
                                                 $result=mysqli_query($con, $query);  
                                                    if($result)
                                                        while(($row=$result->fetch_assoc())!= null){
                                                        ?><option value="<?=$row['id']?>"<?=((isset($_SESSION['syntiritis_id']) and ($row['id']==$_SESSION['syntiritis_id']) and ($_SESSION['type']=='syntiriseis_up'))  ? 'SELECTED' : '')?>><?=$row['full_name']?> </option><?php
                                                    }
                                             ?>
                                        </select>
                                        </div>
                            </td>
                            <td rowspan="2">
                               <div class="main_div1">

                                    <label>Επιλέξτε Υπεύθυνο Προϋπολογισμού:</label>
                                    <div class="form-group input-group">
                                    <span class="input-group-addon"> <i class="fa fa-user"> </i> </span>
                                    <select name="syntir_manager" class="form-control">
                                        <?php
                                            $query = "SELECT id,full_name FROM managers ORDER BY full_name ASC;";
                                             $result=mysqli_query($con, $query);  
                                                if($result)
                                                    while(($row=$result->fetch_assoc())!= null){
                                                    ?><option value="<?=$row['id']?>"<?=((isset($_SESSION['manager_id']) and ($row['id']==$_SESSION['manager_id']) and ($_SESSION['type']=='syntiriseis_up'))  ? 'SELECTED' : '')?>><?=$row['full_name']?> </option><?php
                                                }
                                         ?>
                                    </select>
                                    </div>

                                    <label>Επιλέξτε Υπεύθυνο Επίβλεψης:</label>
                                    <div class="form-group input-group">
                                    <span class="input-group-addon"> <i class="fa fa-user"> </i> </span>
                                    <select name="syntir_arc" class="form-control">
                                        <?php
                                            $query = "SELECT id,full_name FROM archaeologist ORDER BY full_name ASC;";
                                             $result=mysqli_query($con, $query);  
                                                if($result)
                                                    while(($row=$result->fetch_assoc())!= null){
                                                    ?><option value="<?=$row['id']?>"<?=((isset($_SESSION['archaeologist_id']) and ($row['id']==$_SESSION['archaeologist_id']) and ($_SESSION['type']=='syntiriseis_up'))  ? 'SELECTED' : '')?>><?=$row['full_name']?> </option><?php
                                                }
                                         ?>
                                    </select>
                                    </div>

                                    <label>Επιλέξτε Μουσείο:</label>
                                        <div class="form-group input-group">
                                        <span class="input-group-addon"> <i class="fa fa-bank"> </i> </span>
                                        <select name="agalm_mus" class="form-control" onchange="bring_who('room',this.value)">
                                           <?php
                                                $query = "SELECT id,full_name FROM museam ORDER BY full_name ASC;";
                                                 $result=mysqli_query($con, $query);  
                                                    if($result)
                                                        while(($row=$result->fetch_assoc())!= null){
                                                        ?><option value="<?=$row['id']?>"><?=$row['full_name']?> </option><?php
                                                    }
                                             ?>
                                             <option value="" disabled="" selected="">-----Μουσείο-----</option>
                                        </select>
                                        </div>

                                        <label>Επιλέξτε Αίθουσα:</label>
                                        <div class="form-group input-group">
                                            <span class="input-group-addon"> <i class="fa fa-bank"> </i> </span>
                                            <div id="name-room">
                                                <select name="agalm_room"  class="form-control">
                                                <option></option>
                                                </select>
                                            </div>
                                        </div>

                                    <label>Για καταχώρηση πατήστε εδώ:</label>
                                    <div class="form-group input-group">
                                            <input type="hidden" name="save" value="syntir">
                                            <input type="submit"  onclick="this.form.submit();" class="btn btn-success"></submit>
                                    </div>
                                    <div class="form-group input-group">
                                        <?=('<a href="" class="btn btn-warning" onclick="close_data(\'null\', \''.'0'.'\')">'.'<i class="fa fa-eraser">'.'</i>'.'</a>') ?>             
                                    </div>
                                </div>
                            </td>
                            </form>

                            </tr>
                            <tr>
                                <td>
                                    <div id="info_box">           
                                        <p id="info_p"> <strong> <i class="fa fa-user"> </i> Όνομα: </strong> Ναός Απόλλωνα</p>
                                        <p id="info_p"> <strong> <i class="fa fa-map-marker"> </i> Διεύθυνση: </strong> Πελοπόννησος </p>
                                        <p id="info_p"> <strong> <i class="fa fa-history"> </i> Χρ.Περίοδος: </strong> 420-410 π.Χ. </p>
                                    </div> 
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </section>

      <section class="top_pad" id="edit">
        <div class="container"> 

            <div class="row">
                <div class="col-lg-12 text-center">
                    <hr class="star-primary">
                    <h2 class="intro-text text-center">ΔΙΑΧΕΙΡΙΣΗ
                            <strong>ΣΥΝΤΗΡΗΣΕΩΝ</strong>
                    </h2>
                    <hr class="star-primary2">
                </div>
            </div>
                
            <div class="row">       
                <div class="box"> 
                    <div id="wrapper">
                        <div class="panel-body">
                            <div class="dataTable_wrapper">
                                <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                    <thead>
                                        <tr>
                                            <th>Κωδικός</th>
                                            <th>Προϋπ.</th>
                                            <th>Ημερ.Έναρξης:</th>
                                            <th>Ημερ.Λήξης:</th>
                                            <th>Συντηρητής</th>
                                            <th>Υπεύθ.Προϋπ.</th>
                                            <th>Υπεύθ.Επίβλ.</th>
                                            <th>Αίθουσα</th>
                                            <th>Del/Edit</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php

                                        $query = "SELECT syntiriseis.id, syntiriseis.kwdikos, syntiriseis.budget, syntiriseis.start_date, syntiriseis.end_date, syntiriseis.museam_id, syntiriseis.room_id, (SELECT full_name FROM preservatives WHERE preservatives.id=syntiriseis.syntiritis_id) AS presername,  (SELECT full_name FROM managers WHERE managers.id=syntiriseis.manager_id) AS managername,  (SELECT full_name FROM archaeologist WHERE archaeologist.id=syntiriseis.archaeologist_id) AS archaeologistname FROM syntiriseis WHERE 1; ";
                                        $result=mysqli_query($con, $query);  
                                        if($result)
                                        while(($row=$result->fetch_assoc())!= null){


                                          if (isset($row['room_id'])){
                                            $query2 = "SELECT full_name as roomname FROM room WHERE museam_id=".$row['museam_id']." AND id=".$row['room_id']." ;";
                                            $result2=mysqli_query($con, $query2);
                                            $row2=$result2->fetch_assoc();
                                            }  
                                                  
                                        ?>
                                        <tr class="">
                                        <td><?=$row['kwdikos']?></td>
                                        <td><?=$row['budget']?></td>
                                        <td><?=$row['start_date']?></td>
                                        <td><?=$row['end_date']?></td>
                                        <td><?=$row['presername']?></td>
                                        <td><?=$row['managername']?></td>
                                        <td><?=$row['archaeologistname']?></td>
                                        <td><?=$row2['roomname']?></td>
                                        <td>
                                        <?=('<button class="btn btn-danger btn-xs" onclick="delete_from(\'syntiriseis\', \''.$row['id'].'\')">'.'<i class="fa fa-trash-o">'.'</i>'.'</button>') ?>
                                        <?=('<a href="" class="btn btn-primary btn-xs" onclick="bring_data(\'syntiriseis\', \''.$row['id'].'\')">'.'<i class="fa fa-pencil">'.'</i>'.'</button>') ?>             
                                        </td>
                                        </tr>       
                                        <?php
                                        }
                                        ?>
                                        <div id="result"></div>
                                    </tbody>
                                </table>
                            </div>  
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

     <section>
        <div class="container">
            <div class="row">
                <div class="col-lg-12 text-center">
                    <p class="footer">Copyright &copy; Dream Designs 2015</p>
                </div>
            </div>
        </div>
    </section>

    </div>
    <!-- /.container -->
    <!-- jQuery -->
    <script src="js/jquery.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="js/bootstrap.min.js"></script>

    <!-- Plugin JavaScript -->
    <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js"></script>
    <script src="js/classie.js"></script>
    <script src="js/cbpAnimatedHeader.js"></script>

    <!-- Contact Form JavaScript -->
    <script src="js/jqBootstrapValidation.js"></script>
    <script src="js/contact_me.js"></script>

    <!-- Custom Theme JavaScript -->
    <script src="js/freelancer.js"></script>

    <!-- jQuery -->
    <script src="js/jquery.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="js/bootstrap.min.js"></script>


     <!-- jQuery -->
    <script src="js/jquery.min.js"></script>


    <!-- Metis Menu Plugin JavaScript -->
    <script src="js/metisMenu.min.js"></script>

    <!-- DataTables JavaScript -->
   <script src="js/jquery.dataTables.min.js"></script>
   <script src="js/dataTables.bootstrap.min.js"></script>

    <!-- Page-Level Demo Scripts - Tables - Use for reference -->
    <script>
    $(document).ready(function() {
        $('#dataTables-example').DataTable({
                responsive: true
        });
    });
    </script>

</body>

</html>
