 <?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>";
        $mus_msg ="";
        
        include_once("/includes/errorcheck.php");


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

    
            if(!preg_match($string_exp2,$_POST['mus_name']) || strlen($_POST['mus_name'])<3)  
                $mus_msg .= 'Το Ονομα δεν είναι έγκυρο ή ειναι κάτω των τριών χαρακτήρων.<br/>';

            if(!preg_match($string_exp2,$_POST['mus_area']) || strlen($_POST['mus_area'])<3)  
                $mus_msg .= 'Η περιοχή δεν είναι έγκυρη ή ειναι κάτω των τριών χαρακτήρων.<br/>';

            if(!preg_match($strin_num_exp,$_POST['mus_adr']) || strlen($_POST['mus_adr'])<2)
                $mus_msg .= 'Η Διεύθυνση δεν είναι έγκυρη ή ειναι κάτω των δύο χαρακτήρων.<br/>';

            if(strlen($_POST['mus_tk']) < 4)
                $mus_msg .= 'Ο Ταχυδρομικός κώδικας που πληκτρολογήσατε δεν είναι έγκυρος.<br/>';

            if (!strlen($mus_msg) and isset($_SESSION['type']) and ($_SESSION['type']=='museam_up')){

                $result = $con->query("UPDATE museam SET full_name='".$_POST['mus_name']."',cat_id='".$_POST['mus_cate']."',area='".$_POST['mus_area']."',address='".$_POST['mus_adr']."',tk='".$_POST['mus_tk']."',site='".$_POST['mus_site']."',time_up='".$_POST['mus_timeup']."',time_until='".$_POST['mus_timeuntil']."',yph_id='".$_POST['mus_ypi']."' WHERE id=".$_SESSION['id'].";");
                $mus_msg .= 'Η Εγγραφή ενημερώθηκε επιτυχώς στην βάση.<br/>';
                if(isset($_SESSION))
                session_destroy();
            }

            if (!strlen($mus_msg) and !isset($_SESSION['type'])){
            $query = "INSERT INTO museam (full_name,cat_id,area,address,tk,site,time_up,time_until,yph_id) VALUES ('".$_POST['mus_name']."','".$_POST['mus_cate']."','".$_POST['mus_area']."','".$_POST['mus_adr']."','".$_POST['mus_tk']."','".$_POST['mus_site']."','".$_POST['mus_timeup']."','".($_POST['mus_timeuntil'])."','".$_POST['mus_ypi']."')";
                $result=mysqli_query($con,$query);
                $mus_msg .= 'Η Εγγραφή προστέθηκε επιτυχώς στην βάση.<br/>';
            }
             header("Refresh:3;url=http://127.0.0.1/museam/museam.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">


    <!-- 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>
    <script type='text/javascript' src='js/function/common.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/memorial.png">
                        </li>
                    <li class="page-scroll">
                        <a href="museam.php"><i class="fa fa-star-half" ></i>ΜΟΥΣΕΙΑ</a>
                    </li>
                    <li class="page-scroll">
                        <a href="aithouses.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="museam">
        <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"> 
                    <?=$mus_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/museam/akropoli.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-font"> </i> </span>
                                            <input name="mus_name" value="<?=((isset($_SESSION['full_name']) and ($_SESSION['type']=='museam_up')) ? $_SESSION['full_name'] : '')?>" type="text" class="form-control" placeholder="Δώστε ένα όνομα.">
                                        </div>

                                        <label>Κατηγορία:</label>
                                        <div class="form-group input-group">
                                            <span class="input-group-addon"> <i class="fa fa-sort-amount-asc"> </i> </span>
                                            <select name="mus_cate" class="form-control">
                                            <?php
                                                $query = "SELECT id,category FROM categoryselect ORDER BY category ASC;";
                                                 $result=mysqli_query($con, $query);  
                                                    if($result)
                                                        while(($row=$result->fetch_assoc())!= null){  
                                                        ?><option value="<?=$row['id']?>"<?=((isset($_SESSION['cat_id']) and ($row['id']==$_SESSION['cat_id']))  ? 'SELECTED' : '')?>> <?=$row['category']?> </option><?php
                                                    }
                                            ?>
                                            </select>
                                        </div>

                                        <label>Περιοχή:</label>
                                        <div class="form-group input-group">
                                            <span class="input-group-addon"> <i class="fa fa-compass"> </i> </span>
                                            <input name="mus_area" value="<?=((isset($_SESSION['area']) and ($_SESSION['type']=='museam_up')) ? $_SESSION['area'] : '')?>" type="text" class="form-control" placeholder="Δώστε ένα όνομα.">
                                        </div>

                                        <label>Διεύθυνση:</label>
                                        <div class="form-group input-group">
                                            <span class="input-group-addon"> <i class="fa fa-location-arrow"> </i> </span>
                                            <input name="mus_adr" value="<?=((isset($_SESSION['address']) and ($_SESSION['type']=='museam_up')) ? $_SESSION['address'] : '')?>" type="text" class="form-control" placeholder="Δώστε μία διεύθυνση.">
                                        </div>

                                        <label>T.K:</label>
                                        <div class="form-group input-group">
                                            <span class="input-group-addon"> <i class="fa fa-sort-numeric-asc"> </i> </span>
                                            <input name="mus_tk" value="<?=((isset($_SESSION['tk']) and ($_SESSION['type']=='museam_up')) ? $_SESSION['tk'] : '')?>" type="text" class="form-control" placeholder="Δώστε ένα ταχυδρ. κώδικα.">
                                        </div>
                                    </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-globe"> </i> </span>
                                            <input name="mus_site" value="<?=((isset($_SESSION['site']) and ($_SESSION['type']=='museam_up')) ? $_SESSION['site'] : '')?>" placeholder="Πχ. www.museams.gr" type="text" class="form-control">
                                        </div>

                                    <label>Ώρα Λειτουργίας Από:</label>
                                        <div class="form-group input-group">
                                            <span class="input-group-addon"> <i class="fa fa-clock-o"> </i> </span>
                                            <input name="mus_timeup" value="<?=((isset($_SESSION['time_up']) and ($_SESSION['type']=='museam_up')) ? $_SESSION['time_up'] : '09:00')?>" type="time" class="form-control">
                                    </div>

                                    <label>Ώρα Λειτουργίας Μέχρι:</label>
                                        <div class="form-group input-group">
                                            <span class="input-group-addon"> <i class="fa fa-clock-o"> </i> </span>
                                            <input name="mus_timeuntil" value="<?=((isset($_SESSION['time_until']) and ($_SESSION['type']=='museam_up')) ? $_SESSION['time_until'] : '15:00')?>" type="time" class="form-control">
                                    </div>

                                    <label>Επιλέξτε Εποπτεύων Υπηρεσία Εφορίας:</label>
                                    <div class="form-group input-group">
                                    <span class="input-group-addon"> <i class="fa fa-info"> </i> </span>
                                    <select name="mus_ypi" class="form-control">
                                       <?php
                                            $query = "SELECT id,full_name FROM ypiresies ORDER BY full_name ASC;";
                                             $result=mysqli_query($con, $query);  
                                                if($result)
                                                    while(($row=$result->fetch_assoc())!= null){
                                                    ?><option value="<?=$row['id']?>"<?=((isset($_SESSION['yph_id']) and ($row['id']==$_SESSION['yph_id']))  ? 'SELECTED' : '')?>><?=$row['full_name']?> </option><?php
                                                }
                                         ?>
                                    </select>
                                    </div>

                                    <label>Για καταχώρηση πατήστε εδώ:</label>
                                        <div class="form-group input-group">
                                            <input type="hidden" name="save" value="mus">
                                            <input type="submit" class="btn btn-success" onclick="this.form.submit();"></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-location-arrow"> </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>Web </th>
                                            <th>Del/Edit</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                        $query = "SELECT museam.id, categoryselect.category as cate1, museam.full_name, museam.area, museam.address, museam.tk, museam.time_up, museam.time_until, ypiresies.full_name as name1, museam.site FROM museam,ypiresies, categoryselect WHERE museam.yph_id=ypiresies.id AND museam.cat_id=categoryselect.id;";
                                        $result=mysqli_query($con, $query);  
                                        if($result)
                                        while(($row=$result->fetch_assoc())!= null){  
                                        ?>
                                        <tr class="">
                                        <td><?=$row['full_name']?></td>
                                        <td><?=$row['cate1']?></td>
                                        <td><?=$row['area']?></td>
                                        <td><?=$row['address']?></td>
                                        <td><?=$row['tk']?></td>
                                        <td><?=$row['time_up']?></td>
                                        <td><?=$row['time_until']?></td>
                                        <td><?=$row['name1']?></td>
                                        <td><a href="http://<?=$row['site']?>"  class="btn btn-block btn-xs" id="info_p2" target="_blank"><i class="fa fa-globe"></i></a></td>
                                        <td>
                                        <?=('<button class="btn btn-danger btn-xs" onclick="delete_from(\'museam\', \''.$row['id'].'\')">'.'<i class="fa fa-trash-o">'.'</i>'.'</button>') ?>
                                        <?=('<a href="museam.php" class="btn btn-primary btn-xs" onclick="bring_data(\'museam\', \''.$row['id'].'\')">'.'<i class="fa fa-pencil">'.'</i>'.'</a>') ?>             
                                        </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>


    <!-- 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>
     <!-- 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>