 <?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>";
        $ayto_msg ="";

        include_once("/includes/errorcheck.php");


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


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

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

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

            if(strlen($_POST['ayto_xrono1']) < 2)
                $ayto_msg .= 'Η Χρονολογική περίοδος αρχής που πληκτρολογήσατε δεν είναι έγκυρη.<br/>';

            if(strlen($_POST['ayto_xrono2']) < 2)
                $ayto_msg .= 'Η Χρονολογική περίοδος τέλους που πληκτρολογήσατε δεν είναι έγκυρη.<br/>';



            if (!strlen($ayto_msg) and isset($_SESSION['type']) and ($_SESSION['type']=='aytokratores_up')){

                $result = $con->query("UPDATE aytokratores SET full_name='".$_POST['ayto_name']."',dynasteia='".$_POST['ayto_dyn']."',century='".$_POST['ayto_aiw']."',cent_id='".$_POST['ayto_type1']."',era_start='".$_POST['ayto_xrono1']."',era_startid='".$_POST['ayto_type2']."',era_end='".$_POST['ayto_xrono2']."',era_endid='".$_POST['ayto_type3']."' WHERE id=".$_SESSION['id'].";");
                $ayto_msg .= 'Η Εγγραφή ενημερώθηκε επιτυχώς στην βάση.<br/>';
                if(isset($_SESSION))
                session_destroy();
                header("Refresh:3;url=http://127.0.0.1/museam/autokratores.php");            }

            if (!strlen($ayto_msg) and !isset($_SESSION['type'])){
            $query = "INSERT INTO aytokratores (full_name,dynasteia,century,cent_id,era_start,era_startid,era_end,era_endid) VALUES ('".$_POST['ayto_name']."','".$_POST['ayto_dyn']."','".$_POST['ayto_aiw']."','".($_POST['ayto_type1'])."','".$_POST['ayto_xrono1']."','".$_POST['ayto_type2']."','".$_POST['ayto_xrono2']."','".$_POST['ayto_type3']."')";
                $result=mysqli_query($con,$query);
                $ayto_msg .= 'Η Εγγραφή προστέθηκε επιτυχώς στην βάση.<br/>';
            }
        header("Refresh:3;url=http://127.0.0.1/museam/autokratores.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/profile.png">
                        </li>
                    <li class="page-scroll">
                        <a href="eklisiastika.php"> <i class="fa fa-star-half"> </i>ΕΚΚΛ. ΠΡΟΣΩΠΑ</a>
                    </li>
                    <li class="page-scroll">
                        <a href="autokratores.php"><i class="fa fa-star-half"> </i>ΑΥΤΟΚΡΑΤΟΡΕΣ</a>
                    </li>
                    <li class="page-scroll">
                        <a href="stratiwtikoi.php"><i class="fa fa-star-half"> </i>ΣΤΡΑΤΙΩΤΙΚΟΙ</a>
                    </li>
                    <li class="page-scroll">
                        <a href="politikoi.php"><i class="fa fa-star-half"> </i>ΑΡΧ. ΠΟΛΙΤΙΚΟΙ</a>
                    </li>
                    <li class="page-scroll">
                        <a href="glyptes.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="aytokratores">
        <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"> 
                    <?=$ayto_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/proswpa/aytokratores/ioustinianos.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="ayto_name" value="<?=((isset($_SESSION['full_name']) and ($_SESSION['type']=='aytokratores_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-flag"> </i></span>
                                            <input name="ayto_dyn" value="<?=((isset($_SESSION['dynasteia']) and ($_SESSION['type']=='aytokratores_up')) ? $_SESSION['dynasteia'] : '')?>" 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-o"> </i> </span>
                                            <input name="ayto_aiw" value="<?=((isset($_SESSION['century']) and ($_SESSION['type']=='aytokratores_up')) ? $_SESSION['century'] : '')?>" type="text" class="form-control" id="input_crop1" placeholder="Δώστε αιώνα αναφοράς.">

                                            <select name="ayto_type1" id="input_crop2" class="form-control">
                                            <?php
                                                $query = "SELECT id,era_type FROM eraselect WHERE 1;";
                                                 $result=mysqli_query($con, $query);  
                                                    if($result)
                                                        while(($row=$result->fetch_assoc())!= null){  
                                                        ?><option value="<?=$row['id']?>"<?=((isset($_SESSION['cent_id']) and ($row['id']==$_SESSION['cent_id']) and ($_SESSION['type']=='aytokratores_up'))  ? 'SELECTED' : '')?>> <?=$row['era_type']?> </option><?php
                                                    }
                                            ?>
                                            </select>

                                        </div>

                                        <label>Χρονολογική Περίοδος Αρχής:</label>
                                        <div class="form-group input-group">
                                            <span class="input-group-addon"> <i class="fa fa-calendar-o"> </i> </span>
                                            <input name="ayto_xrono1" value="<?=((isset($_SESSION['era_start']) and ($_SESSION['type']=='aytokratores_up')) ? $_SESSION['era_start'] : '')?>" type="text" class="form-control" id="input_crop1" placeholder="Δώστε χρ. περίοδο.">

                                            <select name="ayto_type2" id="input_crop2" class="form-control">
                                            <?php
                                                $query = "SELECT id,era_type FROM eraselect WHERE 1;";
                                                 $result=mysqli_query($con, $query);  
                                                    if($result)
                                                        while(($row=$result->fetch_assoc())!= null){  
                                                        ?><option value="<?=$row['id']?>"<?=((isset($_SESSION['era_startid']) and ($row['id']==$_SESSION['era_startid']) and ($_SESSION['type']=='aytokratores_up'))  ? 'SELECTED' : '')?>> <?=$row['era_type']?> </option><?php
                                                    }
                                            ?>
                                            </select>

                                        </div>

                                        <label>Χρονολογική Περίοδος Τέλους:</label>
                                       <div class="form-group input-group">
                                            <span class="input-group-addon"> <i class="fa fa-calendar-o"> </i> </span>
                                            <input name="ayto_xrono2" value="<?=((isset($_SESSION['era_end']) and ($_SESSION['type']=='aytokratores_up')) ? $_SESSION['era_end'] : '')?>" type="text" class="form-control" id="input_crop1" placeholder="Δώστε χρ. περίοδο.">

                                            <select name="ayto_type3" id="input_crop2" class="form-control">
                                            <?php
                                                $query = "SELECT id,era_type FROM eraselect WHERE 1;";
                                                 $result=mysqli_query($con, $query);  
                                                    if($result)
                                                        while(($row=$result->fetch_assoc())!= null){  
                                                        ?><option value="<?=$row['id']?>"<?=((isset($_SESSION['era_endid']) and ($row['id']==$_SESSION['era_endid']) and ($_SESSION['type']=='aytokratores_up'))  ? 'SELECTED' : '')?>> <?=$row['era_type']?> </option><?php
                                                    }
                                            ?>
                                            </select>

                                        </div>
                                    </div>
                            </td>
                            <td rowspan="2">
                               <div class="main_div1">

                                   <label>Για καταχώρηση πατήστε εδώ:</label>
                                        <div class="form-group input-group">
                                            <input type="hidden" name="save" value="ayto">
                                            <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-history"> </i> Χρ.Περίοδος Αρχής: </strong> 685 π.Χ. </p>
                                    <p id="info_p"> <strong> <i class="fa fa-history"> </i> Χρ.Περίοδος Τέλους: </strong> 711 π.Χ. </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>Del/Edit</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
$query ="SELECT aytokratores.id , aytokratores.full_name ,aytokratores.dynasteia ,aytokratores.century ,aytokratores.era_start, aytokratores.era_end, (SELECT era_type FROM eraselect WHERE eraselect.id=aytokratores.cent_id) AS erasel1 , (SELECT era_type FROM eraselect WHERE eraselect.id=aytokratores.era_startid) AS erasel2 , (SELECT era_type FROM eraselect WHERE eraselect.id=aytokratores.era_endid) AS erasel3 FROM aytokratores WHERE 1; ";
                                        $result=mysqli_query($con, $query);  
                                        if($result)
                                        while(($row=$result->fetch_assoc())!= null){  
                                        ?>
                                        <tr class="">
                                        <td><?=$row['full_name']?></td>
                                        <td><?=$row['dynasteia']?></td>
                                        <td><?=$row['century'].' '.$row['erasel1']?></td>
                                        <td><?=$row['era_start'].' '.$row['erasel2']?></td>
                                        <td><?=$row['era_end'].' '.$row['erasel3']?></td>
                                        <td>
                                        <?=('<button class="btn btn-danger btn-xs" onclick="delete_from(\'aytokratores\', \''.$row['id'].'\')">'.'<i class="fa fa-trash-o">'.'</i>'.'</button>') ?>
                                        <?=('<a href="" class="btn btn-primary btn-xs" onclick="bring_data(\'aytokratores\', \''.$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>






