
<meta charset="utf-8">
<link href="../../css/templatemo_style.css" rel="stylesheet" type="text/css" />


<?php
session_start();
if (isset($_GET['s'])) {
    $s = $_GET['s'];
    $_SESSION['GROUPOFUSE'] = $s;
}


if ($_SESSION['GROUPOFUSE'] == 2) {
    $pagetitle = "2oυ Γραφείου!!!";
    include('../../divs/header.php');
} else {
    require_once('../../login/login_functions.inc.php');
    $url = absolute_url('../../login/login.php');
    header("Location: $url");
    exit();
}
?>


<!--  MENU  -->

<div id="templatemo_menu_wrapper">

        <div id="templatemo_menu">
        <?php
    if (isset($_GET['s'])) {
        echo'<div id="templatemo_menu">
        <ul>
           <li><a href="2oGrafeio.php" class="current"><span></span>Αρχική</a></li>
            <li><a><span></span>Ενημέρωση Στελεχών</a><ul>
                   <li><a href="enhmerosh.php" target="_parent" ><span></span>Δείτε τις πρόσφατες ανακοινώσεις</a></li>
                   <li><a href="anakoinosh.php" target="_parent"><span></span>Αναρτήστε τη δική σας ανακοίνωση</a></li>
                                                     </ul> </li>
            <li><a><span></span>Υπηρεσίες</a><ul>
                   <li><a href="view_yphresies.php" target="_parent"><span></span>Δείτε ολες τις υπηρεσίες</a></li>
                   <li><a href="add_yphresies.php" target="_parent"><span></span>Καταχωρήστε νέα υπηρεσία</a></li>
                                            </ul> </li>                        
            <li><a href="fullcalendar/default.php" target="_blank"><span></span>Ημερολόγιο Υπηρεσιών</a>                        
           <li><a href="../dkths/dkths.php?s=6"><span></span>Επιστροφή στη Σελίδα Διοικητή </a></li> 
          <li><a href="logout.php" target="_parent"><span></span>Logout </a></li>
        </ul>
	</div>';
    } else {
        echo'
    <div id="templatemo_menu">
        <ul>
            <li><a href="2oGrafeio.php" class="current"><span></span>Αρχική</a></li>
            <li><a><span></span>Ενημέρωση Στελεχών</a><ul>
                   <li><a href="enhmerosh.php" target="_parent" ><span></span>Δείτε τις πρόσφατες ανακοινώσεις</a></li>
                   <li><a href="anakoinosh.php" target="_parent"><span></span>Αναρτήστε τη δική σας ανακοίνωση</a></li>
                                                     </ul> </li>
            <li><a><span></span>Υπηρεσίες</a><ul>
                   <li><a href="view_yphresies.php" target="_parent"><span></span>Δείτε ολες τις υπηρεσίες</a></li>
                   <li><a href="add_yphresies.php" target="_parent"><span></span>Καταχωρήστε νέα υπηρεσία</a></li>
                                            </ul> </li>                        
            <li><a href="fullcalendar/default.php" target="_blank"><span></span>Ημερολόγιο Υπηρεσιών</a>                        
            <li><a href="logout.php" target="_parent"><span></span>Logout </a></li>
        </ul>    
        
	</div>';
    }
    ?>
</div> <!-- end of templatemo_menu -->








<!-- CONTENT -->
<div id="templatemo_main"> <span class="tm_bottom"></span>
    <style>

        table tr td{
            color: #2b2b2b;

        }
        table tr td a{
            color: #696443;

        }
        table tr td a:hover{
            color: #C03;

        }

    </style>
    <?php
    require_once('../../mysqli_connect.php');
    $user = $_SESSION['GROUPOFUSE'];
    $display = 5;

    if (isset($_GET['p']) && is_numeric($_GET['p'])) {
        $pages = $_GET['p'];
    } else {
        $q = "SELECT  count(e.aa)fROM enhmerosh e, groups g, anakoinoshapopros a WHERE e.aa = a.aaenhmeroshs
        AND g.groupofuse = a.groupapostolea and a.groupparplhpth=$user   ";
        $r = mysqli_query($dbc, $q);
        $row = mysqli_fetch_array($r, MYSQLI_NUM);
        $records = $row[0];
        // echo $records;
        if ($records > $display) {
            $pages = ceil($records / $display);
        } else {
            $pages = 1;
        }
    }

    if (isset($_GET['s1']) && is_numeric($_GET['s1'])) {
        $start = $_GET['s1'];
    } else {
        $start = 0;
    }

    $sort = (isset($_GET['sort'])) ? $_GET['sort'] : 'dt';
    switch ($sort) {
        case 'dt':
            $order_by = 'date ASC';
            break;
        case 'dtr':
            $order_by = 'date DESC';
            break;
        case 'ap':
            $order_by = 'gr ASC';
            break;
        case 'apt':
            $order_by = 'gr DESC';
            break;
        default:
            $order_by = 'date ASC';
            $sort = 'dt';
            break;
    }


    $q = "SELECT distinct e.aa, e.anakoinosh AS ana, g.groupname AS gr,date_format(a.date,'%d %M %Y')as date
    FROM enhmerosh e, groups g, anakoinoshapopros a WHERE e.aa = a.aaenhmeroshs AND g.groupofuse = a.groupapostolea
    and a.groupparplhpth=$user ORDER by $order_by LIMIT $start,$display ";

    $r = mysqli_query($dbc, $q);

    $num = mysqli_num_rows($r);

    if ($r) {
        //Correct execution
        $sort_dt = ($sort == 'dt') ? 'dtr' : 'dt';
        $sort_ap = ($sort == 'ap') ? 'apr' : 'ap';

        echo '<table align="center"  bgcolor="#FFFF99"  bordercolor="#FF3300" border="2" cellspacing="3" cellpadding="3" width="100%">
          <tr>
             <td align="left"><a href="enhmerosh.php?sort=' . $sort_dt . '"><b>Ημερομηνία</b></a></td>
             <td align="left"><b>Ανακοίνωση</b></td>
              
            <td align="left"><a href="enhmerosh.php?sort=' . $sort_ap . '"><b>Αποστολέας</b></a></td>
         
          </tr>
          ';
        $bg = '#eeeeee';
        while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
            $bg = ($bg == '#eeeeee' ? '#ffffff' : '#eeeeee');
            echo '<tr bgcolor="' . $bg . '"
                <td align="left"></td>
                <td align="left">' . $row['date'] . '</td>
            <td align="left">' . $row['ana'] . '</td>
            
            <td align="left">' . $row['gr'] . '</td>
              </tr>
              ';
        }
        echo '</table>';

        mysqli_free_result($r);
    } else {
        //Incorrect query execution
        echo '<p class="error">Συγνώμη αλλά δε μπορέσαμε να ανακτήσουμε τις ανακοινώσεις!!!</p>
        ';
        // echo '<p>' . mysqli_error($dbc) . '<br>Query: ' . $q . '</p>';
    }
    mysqli_close($dbc);
    if ($pages > 1) {
        echo '<br><p>';
        $current_page = ($start / $display) + 1;

        // If not the first page, create a Previous button
        if ($current_page != 1) {
            echo '<a href="enhmerosh.php?s1=' . ($start - $display) . '&p=' . $pages . '&sort=' . $sort . '">Previous</a> ';
        }

        // Create all the numbered pages
        for ($i = 1; $i <= $pages; $i++) {
            if ($i != $current_page) {
                echo '<a href="enhmerosh.php?s1=' . (($i - 1) * $display) .
                '&p=' . $pages . '&sort=' . $sort . '">' . $i . '</a> ';
            } else {
                echo $i . ' ';
            }
        }

        // If not the last page, create a Next button
        if ($current_page != $pages) {
            echo ' <a href="enhmerosh.php?s1=' . ($start + $display) .
            '&p=' . $pages . '&sort=' . $sort . '">Next</a>';
        }
    }
    ?>


    <div class="cleaner"></div>
</div> 


<!-- SIDEBAR -->








<?php
include('../../divs/footer.php');
?>
<style>
    #templatemo_menu ul li a:hover span, #templatemo_menu ul .current span {
        position: absolute;
        top: 0;
        left: 0;
        width: 5px;
        height: 33px;
        background: url(../images/templatemo_menu_left.jpg) no-repeat;
    }</style>