<?php
//define this module's name and path
$mn = basename(__FILE__ , ".php");
include("modules/modules.php");
$nonMultilingualSections = array("users", "slots", "banner_slots", "banner_types", "fpa_cat");

/*
Available variables:
All system classes
All request variables
$p (the template path)
$mp (the module path)
$sufixID (id sufix for this module's divs)
*/

$marginTop = ($moduleParameters['marginTop'] == "__EMPTY__" || empty($moduleParameters['marginTop'])) ? 0 : $moduleParameters['marginTop'];
$marginRight = ($moduleParameters['marginRight'] == "__EMPTY__" || empty($moduleParameters['marginRight'])) ? 0 : $moduleParameters['marginRight'];
$marginBottom = ($moduleParameters['marginBottom'] == "__EMPTY__" || empty($moduleParameters['marginBottom'])) ? 0 : $moduleParameters['marginBottom'];
$marginLeft = ($moduleParameters['marginLeft'] == "__EMPTY__" || empty($moduleParameters['marginLeft'])) ? 0 : $moduleParameters['marginLeft'];
$paddingTop = ($moduleParameters['paddingTop'] == "__EMPTY__" || empty($moduleParameters['paddingTop'])) ? 0 : $moduleParameters['paddingTop'];
$paddingRight = ($moduleParameters['paddingRight'] == "__EMPTY__" || empty($moduleParameters['paddingRight'])) ? 0 : $moduleParameters['paddingRight'];
$paddingBottom = ($moduleParameters['paddingBottom'] == "__EMPTY__" || empty($moduleParameters['paddingBottom'])) ? 0 : $moduleParameters['paddingBottom'];
$paddingLeft = ($moduleParameters['paddingLeft'] == "__EMPTY__" || empty($moduleParameters['paddingLeft'])) ? 0 : $moduleParameters['paddingLeft'];
$useModuleContainer = ($moduleParameters['useModuleContainer'] == "__EMPTY__" || empty($moduleParameters['useModuleContainer'])) ? 0 : (int)$moduleParameters['useModuleContainer'];
$widthInPixels = ($moduleParameters['widthInPixels'] == "__EMPTY__" || empty($moduleParameters['widthInPixels'])) ? null : (int)$moduleParameters['widthInPixels'];


if (empty($marginTop) && empty($marginRight) && empty($marginBottom) && empty($marginLeft)) {
    $Mmargin = "0";
} else {
    $Mmargin = $marginTop . " " . $marginRight . " " . $marginBottom . " " . $marginLeft . " ";
}
if (empty($paddingTop) && empty($paddingRight) && empty($paddingBottom) && empty($paddingLeft)) {
    $Mpadding = "0";
} else {
    $Mpadding = $paddingTop . " " . $paddingRight . " " . $paddingBottom . " " . $paddingLeft . " ";
}

$showLoginLinks = ($moduleParameters['showLoginLinks'] == "__EMPTY__" || empty($moduleParameters['showLoginLinks'])) ? 0 : (int)$moduleParameters['showLoginLinks'];
$allowJavascript = ($moduleParameters['allowJavascript'] == "__EMPTY__" || empty($moduleParameters['allowJavascript'])) ? 0 : (int)$moduleParameters['allowJavascript'];
$maxRecords = ($moduleParameters['maxRecords'] == "__EMPTY__" || empty($moduleParameters['maxRecords'])) ? 0 : (int)$moduleParameters['maxRecords'];
$colorPrimary = $moduleParameters['colorPrimary'];
$colorPrimaryDark = $moduleParameters['colorPrimaryDark'];
$colorSecondary = $moduleParameters['colorSecondary'];
$colorSecondaryDark = $moduleParameters['colorSecondaryDark'];
$colorBorderLight = $moduleParameters['colorBorderLight'];
$colorBorderDark = $moduleParameters['colorBorderDark'];
$colorMessaging = $moduleParameters['colorMessaging'];
$colorMessagingDark = $moduleParameters['colorMessagingDark'];
$colorWarning = $moduleParameters['colorWarning'];
$colorWarningDark = $moduleParameters['colorWarningDark'];


if ($useModuleContainer){
?>

<div id="<?php echo $mn . $sufixID; ?>" data-editable="editable" class="responsive_float">
    <?php
    }
    if ($moduleParameters['moduleAlign'] && $moduleParameters['moduleHR']) { // there are system parameters...
        ?>
        <style type="text/css">
            <?php
if($useModuleContainer ){
?>
            #<?php echo $mn.$sufixID;?>{
	<?php
	$alignRule = ($moduleParameters['moduleAlign'] == "center") ? "text-align" : "float";
	echo $alignRule.": ".$moduleParameters['moduleAlign'].";".PHP_EOL;
	?>
	margin : <?php echo $Mmargin;?>;
	padding : <?php echo $Mpadding;?>;
<?php
if($widthInPixels){
	?>
	width: <?php echo $widthInPixels;?>px;
	<?php
}
if($moduleParameters['moduleHR'] == "top" || $moduleParameters['moduleHR'] == "bottom"){
?>
	border-<?php echo $moduleParameters['moduleHR'];?> : 1px solid black;
<?php
}
?>
}

            <?php
}
?>

        </style>
        <?php
    }

    // start module's actual code
    global $langID;
    global $urlExtension;
    $langExt = $language->getLanguageExtension($langID);
    $userID = $_SESSION['userID'];
    $name = $_SESSION['userUsername'];
    $token1 = "38629649";
    $token2 = "73972658";
    $u = $token1 . $userID . $token2;

    $showPanel = ($this->section == "pages" and $id == 11);

    global $auth;
    global $parameters;
    $querySymbol = (preg_match('/\?/', $sef->url("index.php", false))) ? "&" : "?";

    // show login links
    if ($auth->getLoginStatus()) {
        $html = t("Έχετε συνδεθεί ως") . ' <b>' . $_SESSION['userUsername'] . '</b> | ';
        $html .= '<a href="' . $sef->url("index.php?section=pages&view=render&id=11", false) . '" title="' . t("πίνακας διαχείρισης", NULL, "login") . '">' . t("πίνακας διαχείρισης", NULL, "login") . '</a> | ';
        $html .= '<a href="' . $sef->url("index.php?section=users&view=profile", false) . '" title="' . t("επεξεργασία των στοιχείων σας") . '">profile</a> | ';
        $html .= '<a href="' . $sef->url("index.php", false) . $querySymbol . 'logout=1">' . t("αποσύνδεση") . '</a>';
    } else {
        $html = '<a href="' . $sef->url("index.php?section=users&view=login", false) . '" title="' . t("σύνδεση", "login") . '">' . t("σύνδεση", NULL, "login") . '</a> | ';
        $html .= '<a href="' . $sef->url("index.php?section=users&view=register", false) . '" title="' . t("εγγραφή", "login") . '">' . t("εγγραφή", NULL, "login") . '</a>';

    }
    ?>
    <script type="text/javascript">
          jQuery().ready(function () {
            $('[data-type="advanced"]').each(function () {
              if ($(this).attr('data-required') && $(this).find('option[value]:eq(0)').val() == "0") {
                $(this).find('option[value]:eq(0)').remove();
              }
              var name = $(this).prop('name');
              var width = name.match(/ID$/) ? "copy" : "element";
              $(this).select2({
                formatResult: format,
                formatSelection: format,
                width: width,
                matcher: function (term, optText, els) {
                  var allText = optText + els[0].parentNode.getAttribute('label') || '';
                  return ('' + allText).toUpperCase().indexOf(('' + term).toUpperCase()) >= 0;
                }
              });
            });
            if (!$('#user_links').length) { // check if already exists a container with ID [ user_links ], and create it if needed
                var div_users = $('<div id="users"></div>');
                var div = $('<div id="user_links"></div>');
                div_users.append(div);
                <?php
                if($showPanel){
                ?>
                $('#admin_panel_wrap').parent().prepend(div_users);
                <?php
                }
                ?>
            }
            $('#user_links').html('<?php echo $html;?>');
        });
    </script>
    <?php

    if (!$showPanel) return; //  no admin panel except in the memebars page

    if (!$auth->getLoginStatus()) {
        if (is_file($p . "view_users_login.php")) {
            global $domain_name;
            ?>
            <script type="text/javascript">
                jQuery().ready(function () {
                    $('#admin_panel_wrap').hide(); // hide while is redirecting
                });
                setTimeout(function () {
                    document.location.href = "<?php echo "http://" . $domain_name . "/index.php?section=users&view=login&langID=" . $langID;?>";
                }, 100);
            </script>
            <?php
        } else {
            $messages->addError("Login page not found!");
            $messages->printSystemMessages();
            return;
        }
    }


    ?>
    <div id="admin_panel_wrap">
        <div id="admin_panel_container">

            <?php

            $adminPanelEnabled = true;


            // get sections with user management capabilities
            $sections = $system->getUserSections();
            if (!count($sections)) {
                $messages->addMessage(t("Δεν βρέθηκαν ενότητες περιεχομένου που να έχετε πρόσβαση"));
                $messages->printSystemMessages();
                $adminPanelEnabled = false;
            }

            // get sections where this user has access
            $userSections = array();
            foreach ($sections as $sName) {
                if ($system->hasAccess($userID, $sName)) $userSections[] = $sName;
            }
            $sections = $userSections;
            if (!count($sections)) {
                $messages->addMessage(t("Δεν βρέθηκαν ενότητες περιεχομένου που να έχετε πρόσβαση"));
                $messages->printSystemMessages();
                $adminPanelEnabled = false;
            }

            if ($auth->getLoginStatus() && $adminPanelEnabled) {

                /*
	$expire_date = $db->getRecord("select expiredate from users where id='$userID'")->expiredate;
	if($expire_date > time()){
		$messages->addMessage(t("Η συνδρομή σας έχει λήξει και πρέπει να ανανεωθεί"));
		$messages->addMessage(t("Μέχρι τότε οι εγγραφές σας θα παραμένουν ανενεργές"));
		$messages->printSystemMessages();
		return;
	}
	*/

                if ($auth->getLoginStatus() < 3) {
                    $messages->addMessage(t("Δεν έχετε δικαιώματα επεξεργασίας περιεχομένου"));
                    $messages->printSystemMessages();
                    return;
                }

                if ($usection) {
                    if (!$system->hasAccess($userID, $usection)) {
                        $messages->addMessage(t("Δεν έχετε δικαιώματα επεξεργασίας περιεχομένου"));
                        $messages->printSystemMessages();
                        return;
                    }
                }


                if (empty($allowJavascript)) {
                    $filterFile = $mp . "filter/HTMLPurifier.auto.php";
                    if (is_file($filterFile)) {
                        require_once($filterFile);
                        $config = HTMLPurifier_Config::createDefault();
                        $config->set('Core.Encoding', 'UTF-8'); // replace with your encoding
                        $config->set('HTML.Doctype', 'HTML 4.01 Transitional'); // replace with your doctype
                        $config->set('Attr.EnableID', true);
                        $config->set('Attr.AllowedFrameTargets', array('_blank', '_top', '_self'));
                        $config->set('HTML.Allowed', 'a,address,article,aside,audio,b,blockquote,br,button,canvas,caption,center,code,dd,div,dl, dt,em,embed,font,footer,form,header,hgroup,h1,h2,h3,h4,h5,h6,hr,i,iframe,img[alt|src],input,label,legend,li,link,map,meta,nav,object,ol,optgroup,option,p,param,pre,section,select,small,span,strong,style,sub,summary,sup,table,tbody,td,textarea,th,thead,time,title,tr,u,ul,video,wbr');
                        $config->set('HTML.AllowedAttributes', 'acceskey,class,dir,id,lang,style,tabindex,title,href,media,name,rel,target,type,autoplay,controls,loop,muted,preload,src,cite,autofocus,disabled,value,width,height,align,color,face,size,accept,action,autocomplete,enctype,method,noshade,frameborder,scrolling,alt,border,hspace,ismap,usemap,vspace,checked,max,maxlength,min,multiple,pattern,placeholder,readonly,required,step,for,content,http-equiv,classid,data,reversed,start,selected,scoped,bgcolor,cellpadding,cellspacing,valign,colspan,nowrap,rowspan,cols,rows,wrap,datetime,poster');
                        $config->set('CSS.AllowedProperties', 'background,background-attachment,background-color,background-image,background-position,background-repeat,background-clip,background-origin,background-size,border,border-bottom,border-bottom-color,border-bottom-style,border-bottom-width,border-collapse,border-color,border-left,border-left-color,border-left-style,border-left-width,border-right,border-right-color,border-right-style,border-right-width,border-spacing,border-style,border-top,border-top-color,border-top-style,border-top-width,border-width,border-bottom-left-radius,border-bottom-right-radius,border-top-left-radius,border-top-right-radius,border-image,border-image-outset,border-image-repeat,border-image-slice,border-image-source,border-image-width,border-radius,bottom,clear,clip,color,column-count,column-fill,column-gap,column-rule,column-rule-color,column-rule-style,column-rule-width,column-span,column-width,columns,content,counter-increment,counter-reset,cursor,direction,display,empty-cells,float,font,font-family,font-size,font-style,font-variant,font-weight,@font-face,font-size-adjust,font-stretch,grid-volumns,grid-rows,hanging-punctuation,height,icon,@keyframes,left,letter-spacing,line-height,list-style,list-style-image,list-style-position,list-style-type,margin,margin-bottom,margin-left,margin-right,margin-top,max-height,max-width,min-height,min-width,nav-down,nav-index,nav-left,nav-right,nav-width,opacity,outline,outline-color,outline-offset,outline-style,outline-width,overflow,overflow-x,overflow-y,padding,padding-bottom,padding-left,padding-right,padding-top,page-break-after,page-break-before,page-break-inside,perspective,perspevtive-origin,position,punctuation-trim,quotes,resize,right,rotation,rotation-point,table-layout,target,target-name,target-new,target-position,text-align,text-decoration,text-indent,text-justify,text-outline,text-overflow,text-shadow,text-tranform,text-wrap,top,transform,transform-origin,transform-style,transition,transition-property,transition-duration,transition-timing-function,transition-delay,vertical-align,visibility,width,white-space,word-spacing,word-break,word-wrap,z-index');
                        global $purifier;
                        $purifier = new HTMLPurifier($config);
                    } else {
                        $messages->addError("HTMLPurify plugin is missing while Javascript is not allowed.");
                        $messages->addError("Module «Odyssey Users» suspended for security reasons.");
                        $messages->printSystemMessages();
                        return;
                    }
                }
                $variables->getSafeVars(array_keys($_REQUEST));
            if ($submitedData){

                require("save.php");
                ?>
                <script type="text/javascript">
                    jQuery().ready(function () {
                        goto("admin_panel");
                    });
                </script>
            <?php
            }

            if (($tableSectionID || $itemID) && !$submitedData){
            ?>
                <script type="text/javascript">
                    jQuery().ready(function () {
                        goto("admin_panel_container");
                    });
                </script>
            <?php
            }

            if (!$tableSectionID && !$usection) { // section initialization
                $usection = $sections[0];
                $tableSectionID = $system->getTableSectionID($usection);
            } else {
                if (empty($tableSectionID)) $tableSectionID = $system->getTableSectionID($usection);
                $usection = $system->getTableSectionName($tableSectionID);
            }

            if (isset($_REQUEST['delID'])) {
                if ($withSelected) {
                    if ($withSelected == "activate") {
                        $content->massContentActivation($_REQUEST['delID'], $usection, true);
                    }
                    if ($withSelected == "deactivate") {
                        $content->massContentActivation($_REQUEST['delID'], $usection, false);
                    }
                } else {
                    $content->massContentDelete($_REQUEST['delID'], $usection, "main");
                }
            }

            $messages->printSystemMessages();

            ?>
                <div id="users_admin_selectors">
                    <form method="get" id="add_section_form" action="index.php">
                        <div id="add_item" style="text-align:right; margin-top:30px">
                            <a href="javascript:void(0)" onclick="$('#add_section_form').submit();"><?php echo t("Προσθήκη νέας δημοσίευσης σε"); ?></a>
                            <div style="padding: 6px"><select name="tableSectionID" class="listbox" onchange="$('#add_section_form').submit()">
                                    <?php
                                    foreach ($sections as $thisSection) {
                                        $sid = $system->getTableSectionID($thisSection);
                                        $stitle = $system->getTableSectionTitle($sid);
                                        ?>
                                        <option value="<?php echo $sid; ?>" <?php if ($tableSectionID == $sid) echo "selected"; ?>><?php echo t($stitle); ?></option>
                                        <?php
                                    }
                                    ?>
                                </select>
                            </div>
                        </div>
                        <input type="hidden" name="action" value="form">
                        <input type="hidden" name="section" value="<?php echo $section; ?>">
                        <input type="hidden" name="view" value="<?php echo $view; ?>">
                        <input type="hidden" name="id" value="<?php echo $id; ?>">
                        <input type="hidden" name="langID" value="<?php echo $langID; ?>">

                    </form>

                    <form method="get" id="edit_section_form" action="index.php">
                        <div id="edit_item" style="text-align:right; margin-top:15px">
                            <a href="javascript:void(0)" onclick="$('#edit_section_form').submit();"><?php echo t("Επεξεργασία δημοσίευσης σε"); ?></a>
                            <div style="padding: 6px"><select name="tableSectionID" class="listbox" onchange="$('#edit_section_form').submit()">
                                    <?php
                                    $sortable = false;
                                    foreach ($sections as $thisSection) {
                                        $sid = $system->getTableSectionID($thisSection);
                                        $stitle = $system->getTableSectionTitle($sid);
                                        if (empty($sortable)) $sortable = ($system->getSectionProperty($sid, "sortType") > "0");
                                        ?>
                                        <option value="<?php echo $sid; ?>" <?php if ($tableSectionID == $sid) echo "selected"; ?>><?php echo t($stitle); ?></option>
                                        <?php
                                    }
                                    ?>
                                </select>
                            </div>
                        </div>
                        <input type="hidden" name="action" value="list">
                        <input type="hidden" name="section" value="<?php echo $section; ?>">
                        <input type="hidden" name="view" value="<?php echo $view; ?>">
                        <input type="hidden" name="id" value="<?php echo $id; ?>">
                        <input type="hidden" name="langID" value="<?php echo $langID; ?>">
                    </form>

                    <?php
                    if ($sortable) { // only if sortable sections havebeen found
                        ?>

                        <form method="get" id="sort_section_form" action="index.php">
                            <div id="sort_item" style="text-align:right; margin-top:15px">
                                <a href="javascript:void(0)" onclick="$('#sort_section_form').submit();"><?php echo t("Ταξινόμηση καταχωρήσεων σε"); ?></a>
                                <div style="padding: 6px"><select name="tableSectionID" class="listbox" onchange="$('#sort_section_form').submit()">
                                        <?php
                                        foreach ($sections as $thisSection) {
                                            $sid = $system->getTableSectionID($thisSection);
                                            $stitle = $system->getTableSectionTitle($sid);
                                            if ($system->getSectionProperty($sid, "sortType") > "0") {
                                                ?>
                                                <option value="<?php echo $sid; ?>" <?php if ($tableSectionID == $sid) echo "selected"; ?>><?php echo t($stitle); ?></option>
                                                <?php
                                            }
                                        }
                                        ?>
                                    </select>
                                </div>
                            </div>
                            <input type="hidden" name="action" value="sort">
                            <input type="hidden" name="section" value="<?php echo $section; ?>">
                            <input type="hidden" name="view" value="<?php echo $view; ?>">
                            <input type="hidden" name="id" value="<?php echo $id; ?>">
                            <input type="hidden" name="langID" value="<?php echo $langID; ?>">
                        </form>

                        <?php
                    }
                    ?>

                </div>

                <div style="margin-top: -20px; text-align:left; color:#<?php echo $colorPrimaryDark; ?>"><h3><?php echo t("Τρέχουσα ενότητα") . ": " . t($system->getTableSectionTitle($tableSectionID)); ?></h3></div>
                <link href="css/buttons.css" rel="stylesheet" type="text/css">
                <link href="<?php echo $mp; ?>css/pagination.css" rel="stylesheet" type="text/css">


            <?php
            if ($action == "form"){
            if (empty($itemID) && !empty($maxRecords)) { // add mode so let's check user limits
            $existing = $db->getNumRows("select id from $usection where userID='$userID'");
            if ($existing >= $maxRecords) {
            $messages->addError(t("Έχετε φτάσει το όριο των επιτρεπόμενων καταχωρήσεων"));
            $messages->printSystemMessages();
            ?>
                <style>
                    #add_item a {
                        background: # <?php echo $colorPrimaryDark;?> url(../images/add.gif) 10px center no-repeat;
                    }
                    #add_item div {
                        background-color: # <?php echo $colorPrimaryDark;?>;
                    }
                    #edit_item a {
                        background: # <?php echo $colorPrimaryDark;?> url(../images/edit.gif) 10px center no-repeat;
                    }
                    #edit_item div {
                        background-color: # <?php echo $colorPrimaryDark;?>;
                    }
                    #sort_item a {
                        background: # <?php echo $colorPrimaryDark;?> url(../images/sort.gif) 10px center no-repeat;
                    }
                    #sort_item div {
                        background-color: # <?php echo $colorPrimaryDark;?>;
                    }
                </style>
            <?php
            return;
            }
            }
            ?>

                <script type="text/javascript">
                    function setAllLanguages() {
                        window.lang = "all";
                        $('div[data-lang]').each(function () {
                            $(this).show();
                            if ($(this).attr('class') == "seo" && !$('#enableSEO').is(':checked')) {
                                $(this).hide();
                            }
                        });
                    }

                    function setCurrentLanguage(lang) {
                        window.lang = lang;
                        $('div[data-lang]').each(function () {
                            $(this).show();

                            if ($(this).attr('data-lang') != window.lang) {
                                $(this).hide();
                            }
                            if ($(this).attr('class') == "seo" && !$('#enableSEO').is(':checked')) {
                                $(this).hide();
                            }
                        });
                    }
                    jQuery(function ($) {
                        setCurrentLanguage("<?php echo $langID . $langExt;?>");
                    });
                </script>

                <script type="text/javascript" src="admin/editor/tiny_mce/tiny_mce.js"></script>
            <?php
            $requiredVars = $variables->getRequiredVars($tableSectionID);
            $defaultLanguage = $language->getDefaultLanguage();
            require("modules/odyssey_users/js.php");

            $sectionTitle = $system->getTableSectionTitle($tableSectionID);
            if (!$sectionTitle) {
                $messages->addError(t("Δεν προσδιορίστηκε κάποια ενότητα"));
                $messages->printSystemMessages();
                return;
            }
            // display form
            $usection = $system->getTableSectionName($tableSectionID);
            $requiredVars = $variables->getRequiredVars($tableSectionID);
            $hasAttachments = $system->getSectionProperty($tableSectionID, "hasAttachments");
            $isMultilingualSite = $language->isMultilingualSite();
            if ($itemID) {
                $sectionRows = $db->getNumRows("select * from `$usection` where id='$itemID'");
                if (!$sectionRows) {
                    $messages->addError(t("Η εγγραφή δεν βρέθηκε!"));
                    $messages->printSystemMessages();
                    return;
                }
            }
            $fieldsRows = $db->getNumRows("select * from `fields` where tableSectionID='$tableSectionID' and active=1 order by sort");
            if (!$fieldsRows) {
                $messages->addError(t("Ακόμα δεν έχουν ορισθεί ενεργά πεδία σε αυτή την ενότητα!"));
                $messages->printSystemMessages();
                return;
            }

            $itemID = isset($_REQUEST['itemID']) ? (int)$_REQUEST['itemID'] : null;
            $table = $usection;
            $header = ($itemID) ? t("Επεξεργασία δημοσίευσης") : t("Δημιουργία νέας δημοσίευσης");
            ?>
                <div id="admin_panel">
                    <div style="text-align:right"><h3><?php echo $header; ?></h3></div>
                    <?php
                    if ($itemID) {
                        ?>
                        <div class="admin_record_title"><h4>
                                <?php
                                $recordTitle = $content->getValue($usection, $itemID, "title", $langID); // try to get a title for the selected language
                                if (empty($recordTitle)) $recordTitle = $content->getValue($usection, $itemID, "title"); // get the title for the default language
                                echo $recordTitle;
                                ?>
                            </h4></div>
                        <?php
                    }
                    if ($hasAttachments) {
                        ?>
                        <div class="edit_bar">
                            <a id="option1" href="javascript:void(0)" <?php if ($itemID) { ?>onclick="setSelected(this)" <?php } ?> class="edit_bar_selected"><span class="icon1"></span><?php echo t("Στοιχεία καταχώρησης"); ?></a>
                            <?php
                            if ($itemID) {
                                ?>
                                <a id="option2" href="javascript:void(0)" onclick="setSelected(this)"><span class="icon2"></span><?php echo t("Εικόνες & άλλα αρχεία"); ?></a>
                                <a id="option3" href="javascript:void(0)" onclick="setSelected(this)"><span class="icon3"></span><?php echo t("Βίντεο"); ?></a>
                                <?php
                            }
                            ?>
                        </div>
                        <?php
                    }
                    ?>


                    <link rel="stylesheet" type="text/css" href="css/jPicker-1.1.2.min.css">
                    <link rel="stylesheet" type="text/css" href="css/select2/select2.css">
                    <link type="text/css" href="admin/css/ui/jquery-ui-odyssey.css" rel="stylesheet">
                    <script type="text/javascript" src="js/jpicker-1.1.2.min.js"></script>
                    <script type="text/javascript" src="js/select2.min.js"></script>
                    <style>
                        .select2-search-hidden {
                            display: none !important;
                        }
                    </style>

                    <form method="post" action="<?php echo("index.php?section=" . $section . "&view=" . $view . "&id=" . $id) ?>" name="editRecord" id="option1content" class="form_centered">
                        <div class="normal">
                            <div style="text-align:right">
                                <?php
                                $record = $db->getRecord("select * from `$usection` where id='$itemID'");
                                if ($record) {
                                    if (property_exists($record, "lat")) $lat = $record->lat;
                                    if (property_exists($record, "lng")) $lng = $record->lng;
                                    if (property_exists($record, "zoom")) $zoom = $record->zoom;
                                }
                                $fields = $db->getRecords("select * from `fields` where tableSectionID='$tableSectionID' and active=1 order by sort");

                                ?>
                                (<span style="font-weight:bold; color:#CC0000">*</span>) <?php echo t("Απαιτούμενα πεδία"); ?>
                                <hr>
                                <?php
                                if ($language->isMultilingualSite() && !in_array($section, $nonMultilingualSections)) {
                                    ?>
                                    <div style="margin: 10px 0">
                                        <div class="admin_label"><?php echo t("Επιλογή τρέχουσας γλώσσας"); ?>:</div>

                                        <?php
                                        $LRecords = $db->getRecords("SELECT * FROM languages WHERE active=1 ");
                                        foreach ($LRecords as $Lrow) {
                                            $languageID = $Lrow->id;
                                            $extension = ($Lrow->extension) ? $Lrow->extension : '_gr';
                                            $currentLanguage = ($currentLanguage) ? $currentLanguage : $language->getDefaultLanguage();
                                            $flag_class = ($languageID == $currentLanguage) ? "selected_flag" : NULL;
                                            ?>
                                            <a href="javascript:void(0)" onclick="setCurrentLanguage('<?php echo $Lrow->id . $extension; ?>')" title="<?php echo t("Να εμφανίζονται μόνο τα") . " " . mb_strtolower(t($Lrow->title), 'UTF-8') . "  " . t("πεδία"); ?>"><img style="padding:1px; border:1px solid black; margin-bottom:-7px;" src="mediabank/flags/flag<?php echo $extension; ?>.png" width="30" height="18"></a>
                                            <?php
                                        }
                                        ?>
                                        <a href="javascript:void(0)" onclick="setAllLanguages()" title="<?php echo t("Να εμφανίζονται τα πεδία σε όλες τις γλώσσες"); ?>"><img style="padding:1px; border:1px solid black; margin-bottom:-7px;" src="mediabank/flags/flag_all.png" width="30" height="18"></a>
                                    </div>
                                    <?php
                                }
                                ?>
                            </div>
                            <?php
                            $requiredHTMLCode = '(<span style="font-weight:bold; color:#CC0000">*</span>) ';
                            foreach ($fields as $field) {
                                if (!empty($field->hiddenInPublicAdmin)) {
                                    continue; // skip hidden for front-end admin fields
                                }
                                $Lsufix = ((int)$langID > 1) ? "_translated" : NULL;
                            if ($field->fieldType == "textfield" || $field->fieldType == "int" || $field->fieldType == "decimal"){
                            if ($field->isMultilingual){ // start language
                                $LRecords = $db->getRecords("SELECT * FROM languages WHERE active=1 ");
                            foreach ($LRecords as $Lrow) {
                                $extension = ($Lrow->extension) ? $Lrow->extension : '_gr';
                                ?>
                                <div data-lang="<?php echo $Lrow->id . $extension; ?>">
                                    <?php
                                    if ($isMultilingualSite && !in_array($usection, $nonMultilingualSections)) {
                                        ?>
                                        <img class="admin_label_flag" src="mediabank/flags/flag<?php echo $extension; ?>.png">
                                        <?php
                                    }
                                    ?>
                                    <div class="admin_label">
                                        <?php
                                        $languageID = $Lrow->id;
                                        if ($field->required && $languageID == $defaultLanguage) echo($requiredHTMLCode);
                                        echo t($field->fieldDescription);
                                        if ($Lrow->extension) echo(' <span style="font-size:9px; color:silver;"><i>(' . t("στα") . ' ' . $Lrow->{title . $Lsufix} . ')</i></span>');
                                        $row = $db->getRecord("select * from content_$usection where mainID='$itemID' and langID='$languageID'");
                                        echo ":";
                                        ?>
                                    </div>
                                    <div style="clear:both">
                                        <?php
                                        $inputType = (preg_match('/password/', mb_strtolower($field->fieldDescription, 'UTF-8')) && ($field->fieldType == "textfield")) ? "password" : "text";
                                        ?>
                                        <input name="<?php echo $field->fieldVarName . $extension; ?>" type="<?php echo $inputType; ?>" class="listbox" id="<?php echo $field->fieldVarName . $extension; ?>" value="<?php if ($row) echo htmlspecialchars($row->{$field->fieldVarName}, ENT_QUOTES, "UTF-8") ?>">
                                    </div>
                                </div>
                                <?php
                            }
                            }else{ // end language
                                $size = ($field->fieldType == "int" || $field->fieldType == "decimal") ? 10 : 35;
                                ?>
                                <div class="admin_label">
                                    <?php
                                    if ($field->required) echo($requiredHTMLCode);
                                    echo t($field->fieldDescription);
                                    $row = $db->getRecord("select * from `$usection` where id='$itemID' ");
                                    if ($field->fieldType == "decimal") {
                                        $fvnValue = ($row) ? $variables->cleanDecimal($row->{$field->fieldVarName}) : 0;
                                    } else {
                                        $fvnValue = ($row) ? $row->{$field->fieldVarName} : null;
                                    }
                                    $fvn = ($field) ? $field->fieldVarName : null;
                                    $inputType = (preg_match('/password/', mb_strtolower($field->fieldDescription, 'UTF-8')) && ($field->fieldType == "textfield")) ? "password" : "text";
                                    echo ":";
                                    ?>
                                </div>
                                <div style="clear:both">
                                    <input name="<?php echo $fvn; ?>" type="<?php echo $inputType; ?>" class="listbox" id="<?php echo $fvn; ?>" size="<?php echo $size; ?>" value="<?php echo $fvnValue; ?>">
                                </div>
                            <?php

                            }
                            }
                            if ($field->fieldType == "textarea" || $field->fieldType == "richTextarea"){
                            if ($field->isMultilingual){ // start language
                            $Lresult = $db->query("SELECT * FROM languages WHERE active=1 ");
                            $LRecords = $db->getRecords("SELECT * FROM languages WHERE active=1 ");
                            foreach ($LRecords as $Lrow) {
                            $extension = ($Lrow->extension) ? $Lrow->extension : '_gr';
                            ?>
                                <div data-lang="<?php echo $Lrow->id . $extension; ?>">
                                    <?php
                                    if ($isMultilingualSite && !in_array($section, $nonMultilingualSections)) {
                                        ?>
                                        <img class="admin_label_flag" src="mediabank/flags/flag<?php echo $extension; ?>.png">
                                        <?php
                                    }
                                    ?>
                                    <div class="admin_label">
                                        <?php
                                        $languageID = $Lrow->id;
                                        if ($field->required && $languageID == $defaultLanguage) echo($requiredHTMLCode);
                                        echo t($field->fieldDescription);
                                        if ($Lrow->extension) echo(' <span style="font-size:9px; color:silver;"><i>(' . t("στα") . ' ' . $Lrow->{title . $Lsufix} . ')</i></span>');
                                        $row = $db->getRecord("select * from content_$usection where mainID='$itemID' and langID='$languageID'");
                                        $class = ($field->fieldType == "richTextarea") ? 'mceEditor' : 'listbox';
                                        $cols = ($field->fieldType == "richTextarea") ? '' : '40';
                                        echo ":";
                                        ?>
                                    </div>
                                    <div style="clear:both"><textarea name="<?php if ($field) echo $field->fieldVarName . $extension; ?>" rows="3" cols="<?php echo $cols; ?>" class="<?php echo $class; ?>" id="<?php if ($field) echo $field->fieldVarName . $extension; ?>"><?php if ($row) echo stripslashes(ltrim(rtrim($row->{$field->fieldVarName}))) ?></textarea>
                                    </div>
                                </div>
                                <?php
                            }
                            }else{ // end language
                                ?>
                                <div class="admin_label">
                                    <?php
                                    if ($field->required) echo($requiredHTMLCode);
                                    echo t($field->fieldDescription);
                                    $row = $db->getRecord("select * from `$usection` where id='$itemID' ");
                                    $class = ($field->fieldType == "richTextarea") ? 'mceEditor' : 'listbox';
                                    $cols = ($field->fieldType == "richTextarea") ? '' : '50';
                                    $fvn = ($field) ? $field->fieldVarName : null;
                                    $fvnValue = ($row) ? stripslashes(ltrim(rtrim($row->{$field->fieldVarName}))) : null;
                                    echo ":";
                                    ?>
                                </div>
                                <div style="clear:both"><textarea name="<?php echo $fvn; ?>" rows="3" cols="<?php echo $cols; ?>" class="<?php echo $class; ?>" id="<?php echo $fvn; ?>"><?php echo $fvnValue ?></textarea>
                                </div>
                            <?php
                            }
                            }

                            if ($field->fieldType == "date"){
                            $dpClass = rand();
                            $isEvent = ($field->fieldVarName == "eventDate") ? true : false;
                            if (empty($itemID) || empty($isEvent)){
                            ?>
                                <div class="admin_label">
                                    <?php
                                    echo t($field->fieldDescription);
                                    $row = $db->getRecord("select * from `$usection` where id='$itemID' ");
                                    $d = ($row) ? $dates->makeDatefromTimestamp($row->{$field->fieldVarName}) : $dates->makeDatefromTimestamp(time());
                                    echo ":";
                                    ?>
                                </div>
                                <div style="clear:both">
                                    <input type="text" name="<?php echo $field->fieldVarName; ?>"<?php if ($isEvent) echo ' id="eventDate"'; ?> class="listbox <?php echo $dpClass; ?>" size="15" value="<?php if ($d) echo $d; ?>">
                                    <script>$('.<?php echo $dpClass;?>').datepicker();</script>
                                </div>
                                <?php
                            }
                            if (!$itemID && in_array($usection, $useCalendar) && $isEvent){ // new record, add events the old fashion way
                                ?>
                                <div class="admin_label">
                                    <div style="float:left; margin: 0 5px 0 0">
                                        <input name="calendar" type="checkbox" id="calendar" value="1" onClick="document.getElementById('publishedEvent').style.visibility = (this.checked) ? 'visible' : 'hidden';"></div>
                                    <div><?php echo t("Να δημοσιευθεί στο ημερολόγιο"); ?>
                                        <div id="publishedEvent" style="visibility:hidden; width:auto !important; font-weight:normal"> <?php echo t("και να ισχύει για"); ?> <input type="text" name="daysOfEvent" class="listbox" style="width:auto" size="3" value="1" onkeyup="this.value=(!this.value || parseInt(this.value) <1 || isNaN(this.value)) ? '1' : this.value;"> <?php echo t("μέρες"); ?></div>
                                    </div>
                                </div>
                                <?php
                            }
                            if ($itemID && in_array($usection, $useCalendar) && $isEvent){ // edit mode, so crud events in popup mode
                                ?>
                                <div><a href="<?php echo $mp; ?>events.php?section=<?php echo $usection; ?>&itemID=<?php echo $itemID; ?>&session_data=<?php echo $_GET['session_data']; ?>&langID=<?php echo $langID; ?>" rel="open_events" class="edit_events"><?php echo t("Διαχείριση ημερομηνιών του event"); ?></a></div>
                            <?php
                            }
                            }


                            if ($field->fieldType == "colorpicker"){
                            if (!$field->access || $adminMode){ // εμφάνιση μόνο σε master Admins ή σε επιτρεπόμενη πρόσβαση
                            $row = $db->getRecord("select * from `$usection` where id='$itemID' ");
                            $color = (isset($row->{$field->fieldVarName})) ? $row->{$field->fieldVarName} : "ffffff";
                            ?>
                                <script type="text/javascript">
                                    <!--
                                    $(document).ready(function () {
                                        $('#<?php  echo $field->fieldVarName; ?>').jPicker({window: {effects: {type: 'fade'}, title: '<?php echo t("Επιλογή χρώματος");?>'}, color: {active: new $.jPicker.Color({hex: '<?php echo $color; ?>'})}});
                                    });
                                    //-->
                                </script>
                                <div class="admin_label">
                                    <?php
                                    echo t($field->fieldDescription);
                                    echo ":";
                                    ?>
                                    <div style="display:inline-block; margin-bottom:10px"><input type="text" name="<?php echo $field->fieldVarName; ?>" id="<?php echo $field->fieldVarName; ?>" style="display:none" class="listbox" size="15" value="<?php echo $color; ?>"></div>
                                </div>
                            <?php
                            } else {

                                $row = $db->getRecord("select * from `$usection` where id='$itemID' ");
                                echo '<input name="' . $field->fieldVarName . '" type="hidden" value="' . $color . '">' . PHP_EOL;

                            }
                            }

                            if ($field->fieldType == "checkbox"){
                            if (!$field->access || $adminMode){ // εμφάνιση μόνο σε master Admins ή σε επιτρεπόμενη πρόσβαση
                            $row = $db->getRecord("select * from `$usection` where id='$itemID' ");
                            ?>
                                <div class="admin_label">
                                    <div style="float:left; margin: 0 5px 0 0">
                                        <input name="<?php echo $field->fieldVarName; ?>" type="checkbox" id="<?php echo $field->fieldVarName; ?>" value="1" <?php if ($row) if ($row->{$field->fieldVarName}) {
                                            echo(' checked="checked"');
                                        } ?>>
                                    </div>
                                    <?php echo t($field->fieldDescription); ?>
                                </div>
                            <?php
                            } else {

                                $row = $db->getRecord("select * from `$usection` where id='$itemID' ");
                                echo '<input name="' . $field->fieldVarName . '" type="hidden" id="' . $field->fieldVarName . '" value="' . $row->{$field->fieldVarName} . '">' . PHP_EOL;

                            }
                            }


                            if ($field->fieldType == "selectMenu"){
                            if (!$field->access || $adminMode){ // εμφάνιση μόνο σε master Admins ή σε επιτρεπόμενη πρόσβαση
                            $row = $db->getRecord("select * from `$usection` where id='$itemID' ");
                            ?>
                                <div class="admin_label"><?php echo t($field->fieldDescription); ?>:</div>
                                <div style="clear:both;">
                                    <select data-type="advanced" name="<?php echo $field->fieldVarName; ?>" class="listbox" id="<?php echo $field->fieldVarName; ?>">
                                        <?php
                                        if ($field->selectType == 'category') {
                                            $catTableName = $field->selectTableSectionName;
                                            $categories->getCategoriesForSelect(0, 0, false, $catTableName, $row->{$field->fieldVarName});
                                        } else {
                                            $append = null;
                                            $flatTableName = $field->selectTableSectionName;
                                            if ($flatTableName == $table || ($flatTableName != "cities" && $flatTableName != "counties" && $flatTableName != "sections" && $flatTableName != "users")) {
                                                ?>
                                                <option value="0" <?php if ($row->{$field->fieldVarName} == 0) {
                                                    echo(' selected="selected"');
                                                } ?> style="padding-right:20px">Επιλέξτε
                                                </option>
                                                <?php
                                            }
                                            $q = "select " . $flatTableName . ".id as id, content_" . $flatTableName . ".title as title 
												   from " . $flatTableName . ", content_" . $flatTableName . " 
												   where content_" . $flatTableName . ".mainID=" . $flatTableName . ".id 
												   and content_" . $flatTableName . ".langID=" . $langID . " 
												   order by " . $flatTableName . ".sort, content_" . $flatTableName . ".title";
                                            $tempRecords = $db->getRecords($q);
                                            $isFirst = true;
                                            foreach ($tempRecords as $temprow) {
                                                ?>
                                                <option value="<?php echo $temprow->id ?>" <?php if ($row) if (($row->{$field->fieldVarName} == $temprow->id) || (!$itemID && $isFirst)) {
                                                    echo(' selected="selected"');
                                                } ?> style="padding-right:20px">
                                                    <?php
                                                    if ($flatTableName == "cities") {
                                                        $optionText = ($langID == 1) ? "Αττική και Ν. Πειραιώς" : "Attica and Piraeus";
                                                        $append = str_replace($optionText, null, getCountyName($temprow->id));
                                                        $append = ($append) ? " (" . $append . ")" : null;
                                                    }
                                                    echo $temprow->title . $append;
                                                    ?>
                                                </option>
                                                <?php
                                                $isFirst = false;
                                            }
                                        }
                                        ?>
                                    </select>
                                </div>
                            <?php
                            } else {

                                $row = $db->getRecord("select * from `$usection` where id='$itemID' ");
                                echo '<input name="' . $field->fieldVarName . '" type="hidden" id="' . $field->fieldVarName . '" value="' . $row->{$field->fieldVarName} . '">' . PHP_EOL;

                            }
                            }

                            if ($field->fieldType == "selectList"){
                            $row = $db->getRecord("select * from `$usection` where id='$itemID' ");
                            $fieldID = $field->id;
                            $q = "select optionID from `selectlists` where itemID='$itemID' and sectionID='$tableSectionID' and fieldID='$fieldID'";
                            $selectedOptions = $db->getRecords($q);
                            ?>
                                <div class="admin_label"><?php echo t($field->fieldDescription); ?>:</div>
                                <div style="clear:both">
                                    <select data-type="advanced" name="<?php echo $field->fieldVarName; ?>[]" class="listbox" id="<?php echo $field->fieldVarName; ?>" multiple style="padding-right:20px; min-width:280px">
                                        <?php
                                        if ($field->selectType == 'category') {
                                            $catTableName = $field->selectTableSectionName;
                                            $b = $row->{$field->fieldVarName};
                                            $categories->getCategoriesForSelectList(0, 0, $catTableName, $selectedOptions);
                                        } else {
                                            $flatTableName = $field->selectTableSectionName;
                                            $q = "select " . $flatTableName . ".id as id, content_" . $flatTableName . ".title as title 
											   from " . $flatTableName . ", content_" . $flatTableName . " 
											   where content_" . $flatTableName . ".mainID=" . $flatTableName . ".id 
											   and content_" . $flatTableName . ".langID=" . $langID . " 
											   order by " . $flatTableName . ".sort, content_" . $flatTableName . ".title";
                                            $tempRecords = $db->getRecords($q);
                                            foreach ($tempRecords as $temprow) {
                                                if (!$itemID) { // add form
                                                    ?>
                                                    <option value="<?php echo $temprow->id ?>">
                                                        <?php echo $temprow->title ?>
                                                    </option>
                                                    <?php
                                                } else { //edit form
                                                    ?>
                                                    <option value="<?php echo $temprow->id ?>" <?php foreach ($selectedOptions as $selectedOption) {
                                                        if ($temprow->id == $selectedOption->optionID) {
                                                            echo(' selected="selected"');
                                                        }
                                                    } ?>>
                                                        <?php echo $temprow->title ?>
                                                    </option>
                                                    <?php
                                                }
                                            }
                                        }
                                        ?>
                                    </select>
                                    <br>

                                    <input type="button" style="height: 20px; padding-top:0; margin: 5px 0 20px 0" class="btn btn-info" value="<?php echo t("Επιλογή όλων"); ?>" onclick="selectAllOptions('<?php echo $field->fieldVarName; ?>')">
                                    <input type="button" style="height: 20px; padding-top:0; margin: 5px 0 20px 0" class="btn btn-inverse" value="<?php echo t("Αποεπιλογή όλων"); ?>" onclick="diselectAllOptions('<?php echo $field->fieldVarName; ?>')">
                                    <input type="hidden" id="forceDeleteOptions" name="forceDeleteOptions" value="">
                                </div>
                                <?php
                            }
                                if ($field->fieldType == "hidden") {
                                    $row = $db->getRecord("select * from `$usection` where id='$itemID' ");
                                    if ($row) $hiddenValue = $row->{$field->fieldVarName};
                                    if ($field->fieldVarName == "publishedDate" && !isset($hiddenValue)) $row->{$field->fieldVarName} = time();
                                    $fvn = ($field) ? $field->fieldVarName : null;
                                    $fvmValue = ($row) ? $row->{$field->fieldVarName} : null;
                                    echo '<input name="' . $fvn . '" type="hidden" id="' . $fvn . '" value="' . $fvmValue . '">' . PHP_EOL;
                                }
                            }

                            if ($system->getSectionProperty($tableSectionID, 'hasGoogleMaps')) {
                                if (isset($lat) && isset($lng) && isset($zoom)) {
                                    $mapInfo = t("Βρέθηκαν καταχωρημένες οι κάτωθι συντεταγμένες") . ":<br>" . t("Γεωγραφικό μήκος") . ": " . $lng . "<br>" . t("Γεωγραφικό πλάτος") . ": " . $lat . "<br>Zoom Level:" . $zoom;
                                } else {
                                    $mapInfo = t("Δεν έχουν επιλεγεί ακόμα γεωγραφικές συντεταγμένες");
                                }
                                if (!$field->access || $adminMode) { // εμφάνιση μόνο σε master Admins ή σε επιτρεπόμενη πρόσβαση
                                    ?>
                                    <div class="admin_label"><span style="padding-top: 5px"><?php echo t("Ορισμός θέσης στο χάρτη"); ?>:</span></div>
                                    <div style="clear:both">
                                        <a href="<?php echo $mp; ?>gmap.php?zoom=<?php echo $zoom; ?>&amp;lat=<?php echo $lat; ?>&amp;lng=<?php echo $lng; ?>&amp;langID=<?php echo $langID; ?>" rel="open_gmap"><img src="<?php echo $mp; ?>images/locateOnMap<?php echo $urlExtension; ?>.gif" width="197" height="25" alt="<?php echo t("εντοπισμός στον χάρτη"); ?>" style="border:0"></a>
                                        <input type="hidden" name="lat" id="lat" value="<?php echo $lat; ?>">
                                        <input type="hidden" name="lng" id="lng" value="<?php echo $lng; ?>">
                                        <input type="hidden" name="zoom" id="zoom" value="<?php echo $zoom; ?>">
                                    </div>
                                    <div id="mapInfo" style="max-width:350px; border-bottom:solid 1px grey; margin-bottom:20px; padding-bottom:20px"><?php echo $mapInfo; ?></div>
                                    <?php
                                }
                            }

                            if ($usection == "events" && $system->isFieldNameExists("day", $tableSectionID) && $system->isFieldNameExists("month", $tableSectionID) && $system->isFieldNameExists("year", $tableSectionID)) {
                                ?>
                                <script type="text/javascript">
                                    window.onload = function () {
                                        var d = document.getElementById('day').value + "/" + document.getElementById('month').value + "/" + document.getElementById('year').value;
                                        d = (d == "//") ? null : d;
                                        document.getElementById('eventDate').value = d;
                                    }
                                    function setDateParts(d) {
                                        var parts = d.split("/");
                                        document.getElementById('day').value = parts[0];
                                        document.getElementById('month').value = parts[1];
                                        document.getElementById('year').value = parts[2];
                                    }
                                </script>
                                <div class="admin_label"><?php echo t("Ημερομηνία"); ?>:</div>
                                <div style="clear:both">
                                    <input onfocus="this.blur()" type="text" id="datepicker" class="listbox dp" size="15" onchange="setDateParts(this.value)">
                                </div>
                                <?php
                            }


                            // ***********************************************	TAGS   **********************************************
                            if (in_array($usection, $useTags)) {
                                ?>
                                <script type="text/javascript">

                                    function addTags(tags, extension) {
                                        var tagContainer = "#tag_container" + extension;
                                        $('#tag_finder' + extension).val('');
                                        var tag;
                                        var tagID;
                                        if (typeof tags == "string") tags = tags.split(",");
                                        for (idx in tags) {
                                            tag = $.trim(tags[idx]);
                                            tagID = makeID();
                                            if (tag != "") {
                                                var newTag = "<span id='tag_" + tagID + "' class='tag'><a href='javascript:void(0)' onclick='removeTag(this, \"" + tag + "\", \"" + extension + "\");'></a><tag>" + tag + "</tag></span>";
                                                if (isTagExists(tag, extension) === false) {
                                                    $("#tag_container" + extension).append(newTag);
                                                    var theTags = $('#tags' + extension).val();
                                                    tag += "|||";
                                                    theTags += tag;
                                                    $('#tags' + extension).val(theTags);
                                                }
                                            }
                                        }
                                    }

                                    function removeTag(elm, tag, extension) {
                                        var theTags = $('#tags' + extension).val().split("|||");
                                        var idx = theTags.indexOf(tag); // Find the index
                                        if (idx != -1) theTags.splice(idx, 1); // Remove it if really found!
                                        theTags = theTags.join("|||");
                                        $('#tags' + extension).val(theTags);
                                        $(elm).parent().remove();
                                    }

                                    function checkEnter(elm, extension, e) {
                                        e = e || event;
                                        if ((e.keyCode || event.which || event.charCode || 0) == 13) { // if enter pressed
                                            var tags = $(elm).val();
                                            if (tags == "") return false;
                                            tags = tags.split(",");
                                            addTags(tags, extension);
                                            return false;
                                        }
                                    }

                                    function isTagExists(tag, extension) {
                                        var exists = false;
                                        var content;
                                        var needle = "<tag>" + tag + "</tag>";
                                        var content = document.getElementById("tag_container" + extension).innerHTML;
                                        if (content) {
                                            if (content.indexOf(needle) != -1) {
                                                exists = true;
                                            }
                                        }
                                        return exists;
                                    }

                                    function makeID() {
                                        var text = "";
                                        var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
                                        for (var i = 0; i < 5; i++)
                                            text += possible.charAt(Math.floor(Math.random() * possible.length));
                                        return text;
                                    }

                                </script>
                                <div class="silver_box">
                                    <h1 class="admin_label admin_label_shadow" style="font-size: 16px !important">Tags</h1>
                                    <i>
                                        <?php
                                        echo t("Καταχωρήστε όσες ετικέτες επιθυμείτε") . ",<br>" . t("χωρισμένες με κόμμα");
                                        if (count($LRecords) > 1) {
                                            echo " " . t("και ξεχωριστά για κάθε γλώσσα");
                                        } ?>
                                    </i>
                                    <?php
                                    $sectionID = $system->getTableSectionID($usection);
                                    $LRecords = $db->getRecords("SELECT * FROM languages WHERE active=1 ");
                                    foreach ($LRecords as $Lrow) {
                                        $extension = ($Lrow->extension) ? $Lrow->extension : '_gr';
                                        $languageID = $Lrow->id;
                                        ?>
                                        <div data-lang="<?php echo $Lrow->id . $extension; ?>">
                                            <div class="admin_label"><span style="line-height:15px">Tags: </span>
                                                <?php
                                                if (count($LRecords) > 1) {
                                                    echo(' <span style="font-size:9px; color:silver;"><i>(' . t("στα") . ' ' . $Lrow->{title . $Lsufix} . ')</i></span>');
                                                    ?>
                                                    <img class="admin_label_flag" src="mediabank/flags/flag<?php echo $extension; ?>.png">

                                                    <?php
                                                }
                                                ?>
                                            </div>
                                            <div style="clear:both">
                                                <input name="tag_finder<?php echo $extension; ?>" id="tag_finder<?php echo $extension; ?>" type="text" class="listbox" style="margin-bottom:5px;max-width:200px"
                                                       onkeypress="return checkEnter(this, '<?php echo $extension; ?>', event)"
                                                       onblur="addTags($('#tag_finder<?php echo $extension; ?>').val(), '<?php echo $extension; ?>' )">
                                                <input type="button" value="<?php echo t("Προσθήκη ετικετών"); ?>" onclick="addTags($('#tag_finder<?php echo $extension; ?>').val(), '<?php echo $extension; ?>' )" class="btn btn-success" style="height: 20px; padding-top:0; margin-top: -3px; margin-left: 5px;">
                                                <input name="tags<?php echo $extension; ?>" id="tags<?php echo $extension; ?>" type="hidden">
                                                <br>
                                                <div id="tag_container<?php echo $extension; ?>" class="tag_container"></div>
                                                <?php
                                                $loadedTags = $content->getTags($sectionID, $itemID, $languageID);
                                                $imploded = null;
                                                if (count($loadedTags)) {
                                                    foreach ($loadedTags as $tag) $imploded .= "'" . $tag . "',";
                                                    $imploded = substr($imploded, 0, -1); // remove trailing comma
                                                    ?>
                                                    <script type="text/javascript">
                                                        var loadedTags<?php echo $extension;?> = new Array(<?php echo $imploded; ?>);
                                                        addTags(loadedTags<?php echo $extension;?>, '<?php echo $extension;?>');
                                                    </script>
                                                    <?php
                                                }
                                                ?>
                                            </div>
                                        </div>
                                        <?php
                                    }
                                    ?>
                                </div>
                                <?php
                            }

                            // ***********************************************	END TAGS    ******************************************


                            // ***********************************************	SEO    ***********************************************
                            if (!in_array($usection, $system_tables) || $usection == "pages") { // display seo options only in content sections
                                $sectionID = $system->getTableSectionID($usection);
                                $q = "select * from `seo` where sectionID='$sectionID' and itemID='$itemID'";
                                $seo = $db->getRecord($q);
                                ?>
                                <div style="background-color:#ececec; padding:0 4px 4px 4px; margin-bottom:10px"><h1 class="admin_label admin_label_shadow" style="font-size: 16px !important">SEO</h1>
                                    <div style="float:left; margin: 0 5px 0 0">
                                        <input name="enableSEO" id="enableSEO" type="checkbox" value="1" <?php if ($seo) echo "checked"; ?> onclick="toggleSEO()">
                                    </div>
                                    <?php echo t("Ενεργοποίηση ρυθμίσεων SEO για αυτή την δημοσίευση"); ?>

                                    <script type="text/javascript">
                                        <?php
                                        if($seo){
                                        ?>
                                        jQuery(function ($) {
                                            window.lang = "<?php echo $langID . $langExt;?>";
                                            $('.seo').each(function () {
                                                $(this).show();
                                                if ($(this).attr('data-lang') != window.lang) $(this).hide();
                                            });
                                        });
                                        <?php
                                        }
                                        ?>
                                        function toggleSEO() {
                                            var lang = (window.lang) ? window.lang : "<?php echo $langID . $langExt;?>";
                                            $('.seo').each(function () {
                                                $(this).toggle();
                                                if (lang == "all") return 1;
                                                if ($(this).attr('data-lang') != lang) $(this).hide();
                                            })
                                        }
                                    </script>
                                    <?php
                                    $LRecords = $db->getRecords("SELECT * FROM languages WHERE active=1 ");
                                    foreach ($LRecords as $Lrow) {
                                        $extension = ($Lrow->extension) ? $Lrow->extension : '_gr';
                                        $languageID = $Lrow->id;
                                        $sq = $q . " and langID='$languageID'";
                                        $seo = $db->getRecord($sq);
                                        ?>
                                        <div class="seo" data-lang="<?php echo $Lrow->id . $extension; ?>">
                                            <?php
                                            if (count($LRecords) > 1) {
                                                ?>
                                                <img class="admin_label_flag" src="mediabank/flags/flag<?php echo $extension; ?>.png">
                                                <?php
                                            }
                                            ?>
                                            <div class="admin_label"><span style="line-height:15px">TITLE HTML TAG: </span>
                                                <?php
                                                if (count($LRecords) > 1) {
                                                    echo(' <span style="font-size:9px; color:silver;"><i>(' . t("στα") . ' ' . $Lrow->{title . $Lsufix} . ')</i></span>');
                                                }
                                                ?>
                                            </div>
                                            <div style="clear:both">
                                                <input name="seo_title<?php echo $extension; ?>" type="text" class="listbox" id="seo_title<?php echo $extension; ?>" value="<?php echo htmlspecialchars($seo->title, ENT_COMPAT, "UTF-8") ?>">
                                            </div>
                                        </div>
                                        <?php
                                    }
                                    ?>
                                    <div class="seo">
                                        <div class="admin_label"><?php echo t("Τρόπος ενσωμάτωσης του τίτλου"); ?>:</div>
                                        <div style="clear:both">
                                            <select name="overwrite_title" class="listbox" id="overwrite_title" style="margin-bottom:10px">
                                                <option value='0' style='padding-right:20px' <?php if ($seo->overwrite_title == 0) echo "selected"; ?>><?php echo t("Να προστεθεί στον υπάρχοντα τίτλο του site"); ?></option>
                                                <option value='1' style='padding-right:20px' <?php if ($seo->overwrite_title == 1) echo "selected"; ?>><?php echo t("Πλήρης αντικατάσταση του υπάρχοντος τίτλου"); ?>&nbsp;&nbsp;&nbsp;&nbsp;</option>
                                            </select>
                                        </div>
                                    </div>

                                    <?php
                                    foreach ($LRecords as $Lrow) {
                                        $extension = ($Lrow->extension) ? $Lrow->extension : '_gr';
                                        $languageID = $Lrow->id;
                                        $sq = $q . " and langID='$languageID'";
                                        $seo = $db->getRecord($sq);
                                        ?>
                                        <div class="seo" data-lang="<?php echo $Lrow->id . $extension; ?>">
                                            <?php
                                            if (count($LRecords) > 1) {
                                                ?>
                                                <img class="admin_label_flag" src="mediabank/flags/flag<?php echo $extension; ?>.png">
                                                <?php
                                            }
                                            ?>
                                            <div class="admin_label"><span style="line-height:15px">DESCRIPTION META TAG: </span>
                                                <?php
                                                if (count($LRecords) > 1) {
                                                    echo(' <span style="font-size:9px; color:silver;"><i>(' . t("στα") . ' ' . $Lrow->{title . $Lsufix} . ')</i></span>');
                                                }
                                                ?>
                                            </div>
                                            <div style="clear:both"><textarea name="seo_description<?php echo $extension; ?>" rows="3" cols="40" class="listbox" id="seo_description<?php echo $extension; ?>"><?php echo stripslashes(trim($seo->description)); ?></textarea>
                                            </div>
                                        </div>
                                        <?php
                                    }
                                    foreach ($LRecords as $Lrow) {
                                        $extension = ($Lrow->extension) ? $Lrow->extension : '_gr';
                                        $languageID = $Lrow->id;
                                        $sq = $q . " and langID='$languageID'";
                                        $seo = $db->getRecord($sq);
                                        ?>
                                        <div class="seo" data-lang="<?php echo $Lrow->id . $extension; ?>">
                                            <?php
                                            if (count($LRecords) > 1) {
                                                ?>
                                                <img class="admin_label_flag" src="mediabank/flags/flag<?php echo $extension; ?>.png">
                                                <?php
                                            }
                                            ?>
                                            <div class="admin_label"><span style="line-height:15px">KEYWORDS META TAG: </span>
                                                <?php
                                                if (count($LRecords) > 1) {
                                                    echo(' <span style="font-size:9px; color:silver;"><i>(' . t("στα") . ' ' . $Lrow->{title . $Lsufix} . ')</i></span>');
                                                }
                                                ?>
                                            </div>
                                            <div style="clear:both"><textarea name="seo_keywords<?php echo $extension; ?>" rows="3" cols="40" class="listbox" id="seo_keywords<?php echo $extension; ?>"><?php echo stripslashes(trim($seo->keywords)); ?></textarea>
                                            </div>
                                        </div>
                                        <?php
                                    }
                                    foreach ($LRecords as $Lrow) {
                                        $extension = ($Lrow->extension) ? $Lrow->extension : '_gr';
                                        $languageID = $Lrow->id;
                                        $sq = $q . " and langID='$languageID'";
                                        $seo = $db->getRecord($sq);
                                        ?>
                                        <div class="seo" data-lang="<?php echo $Lrow->id . $extension; ?>">

                                            <div class="admin_label">
                                                <?php
                                                if (!$displayedExample) {
                                                    ?>
                                                    <span style="line-height:15px"><a title="<?php echo t("εμφάνιση παραδείγματος"); ?>" href="javascript:alert('<?php echo t("πχ") . " " . htmlspecialchars('<META HTTP-EQUIV="CONTENT-LANGUAGE" CONTENT="en-US">\n') . t("Η κάθε εγγραφή πρέπει να εισάγεται σε νέα γραμμή"); ?>');"><?php echo t("Άλλα"); ?> SEO META TAGS:</a></span>
                                                    <?php
                                                    $displayedExample = true;
                                                } else {
                                                    ?>
                                                    <span style="line-height:15px"><?php echo t("Άλλα"); ?> SEO META TAGS: </span>
                                                    <?php
                                                }
                                                if (count($LRecords) > 1) {
                                                    ?>
                                                    <img class="admin_label_flag" src="mediabank/flags/flag<?php echo $extension; ?>.png">
                                                    <?php
                                                    echo(' <span style="font-size:9px; color:silver;"><i>(' . t("στα") . ' ' . $Lrow->{title . $Lsufix} . ')</i></span>');

                                                }
                                                ?>
                                            </div>
                                            <div style="clear:both"><textarea name="seo_meta<?php echo $extension; ?>" rows="3" cols="40" class="listbox" id="seo_meta<?php echo $extension; ?>"><?php echo stripslashes(trim($seo->meta)); ?></textarea>
                                            </div>
                                        </div>
                                        <?php
                                    }
                                    ?>
                                    <div style="height:20px"></div>
                                </div>
                                <?php
                            }


                            // ***********************************************	END SEO    *******************************************


                            $row = $db->getRecord("select * from `$usection` where id='$itemID' ");
                            $isChecked = (empty($itemID)) ? 'checked="checked"' : null;
                            if ($row) {
                                if (!empty($row->active)) $isChecked = 'checked="checked"';
                            }
                            ?>

                            <div class="admin_label">
                                <div style="float:left; margin: 0 5px 0 0"><input name="active" type="checkbox" id="active" value="1" <?php echo $isChecked; ?>></div>
                                <?php echo t("Να είναι ενεργή και να εμφανίζεται αυτή η εγγραφή"); ?>
                            </div>
                            <?php
                            if ($itemID) {
                                ?>
                                <div class="admin_label">
                                    <div style="float:left; margin: 0 5px 0 0"><input type="checkbox" name="delete" value="1" id="delete" onClick="CheckLabel(this)"></div>
                                    <font color="#9f163f"><b><?php echo t("Διαγραφή"); ?></b></font><br><br>
                                    <span style="display:inline-block; font-style:italic; font-weight:normal; margin-top: -15px">(<?php echo t("Προσοχή! Η ενέργεια αυτή είναι μη αναστρέψιμη!"); ?>)</span>
                                </div>
                                <?php
                            }
                            ?>
                            <div>
                                <input name="submitedData" type="submit" class="btn btn-success" id="edit_delete" value="<?php echo t("Αποθήκευση"); ?>" <?php echo $validationJS; ?>>
                                <input name="action" type="hidden" id="action" value="<?php echo $action; ?>">
                                <input name="itemID" type="hidden" id="itemID" value="<?php echo $itemID; ?>">
                                <input name="userID" type="hidden" id="userID" value="<?php echo $userID; ?>">
                                <input name="usection" type="hidden" id="section" value="<?php echo $usection; ?>">
                                <input name="id" type="hidden" value="<?php echo $id; ?>">
                                <input name="section" type="hidden" value="<?php echo $section; ?>">
                                <input name="view" type="hidden" value="<?php echo $view; ?>">
                            </div>
                        </div>
                    </form>


                    <?php
                    if ($hasAttachments) {

                        // **************************************************** ATTACHMENTS ************************************************
                        ?>
                        <script>
                            $(function () {
                                $('a[data-rel="attachments"]').fancybox({
                                    'overlayOpacity': 0.9,
                                    'overlayColor': '#000',
                                    'width': 870,
                                    'height': 600,
                                    'autoScale': false,
                                    'transitionIn': 'elastic',
                                    'transitionOut': 'elastic',
                                    'type': 'iframe',
                                    'showNavArrows': false,
                                    'titleShow': false
                                });

                                $('a[data-rel="videos"]').fancybox({
                                    'overlayOpacity': 0.9,
                                    'overlayColor': '#000',
                                    'width': 600,
                                    'height': 400,
                                    'autoScale': false,
                                    'transitionIn': 'elastic',
                                    'transitionOut': 'elastic',
                                    'type': 'iframe',
                                    'showNavArrows': false,
                                    'titleShow': false
                                });

                                $('a[data-rel="edit_attachments"]').fancybox({
                                    'onClosed': function () {
                                        attachments.location.reload();
                                        videos.location.reload();
                                    },
                                    'overlayOpacity': 0.9,
                                    'overlayColor': '#000',
                                    'width': 600,
                                    'height': '98%',
                                    'autoScale': false,
                                    'transitionIn': 'elastic',
                                    'transitionOut': 'elastic',
                                    'type': 'iframe',
                                    'showNavArrows': false,
                                    'titleShow': false
                                });


                            });
                        </script>

                        <div id="option2content">

                            <div style="text-align: center; margin:5px;">
                                <br><br><img src="<?php echo $mp; ?>images/attachments.png" alt="attachments" style="border:0;"><br>
                                <div id="add_item" style="text-align:center; margin-bottom:10px;">
                                    <a data-rel="attachments" href="<?php echo $mp; ?>attachments.php?action=add&linkID=<?php echo $itemID; ?>&sectionID=<?php echo $tableSectionID; ?>&u=<?php echo $u; ?>"><?php echo t("Προσθήκη νέας εικόνας ή άλλου αρχείου"); ?></a>
                                </div>
                                <?php
                                if ($itemID) {
                                    $displayStyle = ($content->getNumOfAttachments($tableSectionID, $itemID, $langID)) ? "block" : "none"
                                    ?>
                                    <div id="attachments_instructions" style="display:<?php echo $displayStyle; ?>">
                                        <i style="line-height:15px;"><?php echo t("Για να αφαιρέσετε κάποιο επισυναπτόμενο αρχείο"); ?>,<br><?php echo t("από αυτή την καταχώρηση, απλά κάντε κλικ στο εικονίδιο του"); ?></i>
                                        <div style="text-align:center; margin-top:20px">
                                            <input type="button" class="btn btn-success" value="<?php echo t("Αποθήκευση"); ?>" onclick="$('#option1content').submit();" style="margin-top:2px">
                                            <a data-rel="edit_attachments" class="btn btn-info" style="margin-top:2px;" href="<?php echo $mp; ?>edit_attachments.php?sectionID=<?php echo $tableSectionID; ?>&langID=<?php echo $langID; ?>&linkID=<?php echo $itemID; ?>&u=<?php echo $u; ?>"><?php echo t("Επεξεργασία & ταξινόμηση"); ?></a>
                                        </div>
                                    </div>
                                    <?php
                                }
                                ?>
                                <iframe style="margin-top:20px; border:none; max-width:700px" src="<?php echo $mp; ?>preview_delete_attachments.php?category=<?php echo $category; ?>&sectionID=<?php echo $tableSectionID; ?>&linkID=<?php echo $itemID; ?>&u=<?php echo $u; ?>&langID=<?php echo $langID; ?>" name="attachments" width="100%" height="470"></iframe>
                            </div>

                        </div>


                        <div id="option3content">

                            <div style="text-align: center; margin:5px;">
                                <br><br>
                                <a data-rel="videos" href="<?php echo $mp; ?>videos.php?action=add&linkID=<?php echo $itemID; ?>&sectionID=<?php echo $tableSectionID; ?>&u=<?php echo $u; ?>">
                                    <img src="<?php echo $mp; ?>images/video_logos.png" alt="video logos" style="border:0;">
                                </a><br><br>
                                <div id="add_item" style="text-align:center; margin-bottom:10px;">
                                    <a data-rel="videos" href="<?php echo $mp; ?>videos.php?action=add&linkID=<?php echo $itemID; ?>&sectionID=<?php echo $tableSectionID; ?>&u=<?php echo $u; ?>"><?php echo t("Προσθήκη νέου βίντεο"); ?></a>
                                </div>
                                <?php
                                if ($itemID) {
                                    $displayStyle = ($content->getNumOfVideos($tableSectionID, $itemID, $langID)) ? " block" : "none";
                                    ?>
                                    <div id="video_instructions" style="display:<?php echo $displayStyle; ?>">
                                        <i style="line-height:15px;"><?php echo t("Για να αφαιρέσετε κάποιο video από αυτή την καταχώρηση"); ?>,<br><?php echo t("πατήστε το αντίστοιχο κουμπί «Διαγραφή»"); ?></i>
                                        <div style="text-align:center; margin:20px 0">
                                            <input type="button" class="btn btn-success" value="<?php echo t("Αποθήκευση"); ?>" onclick="$('#option1content').submit();" style="margin-top:2px">
                                            <a data-rel="edit_attachments" class="btn btn-info" href="<?php echo $mp; ?>edit_videos.php?sectionID=<?php echo $tableSectionID; ?>&linkID=<?php echo $itemID; ?>&u=<?php echo $u; ?>" style="margin-top:2px"><?php echo t("Επεξεργασία & ταξινόμηση"); ?></a>
                                        </div>
                                    </div>
                                    <?php
                                }
                                ?>
                                <iframe style="display:block; vertical-align:middle; margin-top:20px; border: none" src="<?php echo $mp; ?>preview_delete_videos.php?sectionID=<?php echo $tableSectionID; ?>&linkID=<?php echo $itemID; ?>&u=<?php echo $u; ?>&langID=<?php echo $langID; ?>" name="videos" width="100%" height="550"></iframe>
                            </div>
                        </div>

                        <?php
                    }

                    // **************************************************** END OF ATTACHMENTS *****************************************
                    ?>

                </div> <!-- end #admin_panel -->
            <?php

            }








            if ($action == "list" || empty($action)){ // start listing

            $header = t("Επιλογή καταχώρησης για επεξεργασία στοιχείων");
            require("modules/odyssey_users/js.php");
            if ($search){
            ?>
                <script type="text/javascript">
                    jQuery().ready(function () {
                        goto("admin_panel");
                    });
                </script>
            <?php
            }
            ?>
                <div id="admin_panel">
                    <div style="text-align:right"><h3><?php echo $header; ?></h3></div>
                    <?php
                    if ($_REQUEST['criteria_search']) {
                        ?>
                        <script type="text/javascript">
                            jQuery(function ($) {
                                toggleSearch($('.find'));
                            });
                        </script>
                        <?php
                    }
                    ?>
                    <a href="javascript:void(0)" onclick="toggleSearch(this)" class="find search_off" style='font-size: .85em !important; font-family: "Roboto Condensed",sans-serif !important'><?php echo t("Αναζήτηση"); ?></a>
                    <form id="find" class="hidden" method="get" action="<?php $sef->url("index.php?section=" . $section . "&view=" . $view . "&id=" . $id) ?>">
                        <div class="normal">
                            <?php
                            if ($system->getSectionProperty($tableSectionID, "hasCategory")) {
                                ?>

                                <div style="margin: 0 auto;" class="form_container">
                                    <div class="formLabel left"><?php echo t("Κατηγορία"); ?>:</div>
                                    <div>
                                        <select data-type="advanced" name="catID" class="listbox" id="ext" onchange="$('find').submit()">
                                            <option value="0" selected="selected"><?php echo t("Όλες οι κατηγορίες"); ?>...</option>
                                            <?php
                                            $catID = ($catID) ? $catID : 0;
                                            $categoriesTable = $usection . "_categories";
                                            $categories->getCategoriesForSelect(0, 0, false, $categoriesTable, $catID);
                                            ?>
                                        </select>
                                    </div>
                                </div>
                                <?php
                            }
                            ?>

                            <div style="margin: 0 auto;" class="form_container">
                                <div class="formLabel left"><?php echo t("Λέξη ή φράση κλειδί"); ?>:</div>
                                <div>
                                    <input name="keyword" type="text" class="listbox" id="keyword" value="<?php if (isset($keyword)) echo htmlspecialchars($keyword, ENT_COMPAT, "UTF-8"); ?>" onClick="this.value=''">
                                </div>
                            </div>

                            <div style="margin: 0 auto 15px auto;" class="form_container">
                                <div class="formLabel left">
                                    <input name="criteria_search" type="submit" class="btn btn-success" id="button" value="<?php echo t("Αναζήτηση"); ?>">
                                    <input name="action" type="hidden" id="action" value="<?php echo $action; ?>">
                                    <input name="usection" type="hidden" id="section" value="<?php echo $usection; ?>">
                                    <input name="tableSectionID" type="hidden" id="section" value="<?php echo $tableSectionID; ?>">
                                </div>
                            </div>
                        </div>
                    </form>
                </div>


                <div style="margin-bottom:40px; text-align:left">
                    <form method="get" id="massSelectionForm">
                        <?php

                        $q = "select $usection.active as active, " . $usection . ".id as id, content_" . $usection . ".title as title from " . $usection . ", content_" . $usection . " where " . $usection . ".userID='$userID' and " . $usection . ".id=content_" . $usection . ".mainID and content_" . $usection . ".langID=" . $langID;
                        if ($catID) {
                            $q .= " and " . $usection . ".catID=" . $catID;
                        }
                        $keyword = (isset($keyword)) ? $keyword : null;
                        $keyword = ltrim(rtrim($keyword));
                        if ($keyword) {
                            $q .= " and (content_" . $usection . ".title LIKE '%$keyword%')";
                        }
                        $presults = $system->getPresults($usection);
                        $page = isset($_REQUEST['ppage']) ? $_REQUEST['ppage'] : null;
                        $maxrows = $db->getNumRows($q);
                        $page = ($page > 0) ? $page : 1; // αν δεν έχει δωθεί η μεταβλητή $page να ορισθεί ως 1
                        $startrecord = ($page * $presults) - $presults; // η πρώτη εγγραφή του σετ (αρχική τιμή της LIMIT)
                        $startrecord = ($startrecord < 0) ? 0 : $startrecord; // Απαγορεύεται η αρνητική τιμή
                        if ($system->getSectionProperty($tableSectionID, "sortType")) {
                            $q .= " order by " . $usection . ".sort, content_" . $usection . ".title LIMIT $startrecord, $presults";
                        } else {
                            $q .= " order by title LIMIT $startrecord, $presults";
                        }
                        $rows = $db->getNumRows($q);
                        if (!$rows) {
                            if (!$catID && !$keyword) {
                                $messages->addMessage(t("Δεν βρέθηκαν καταχωρημένες εγγραφές"));
                            } else {
                                $messages->addError(t("Δεν βρέθηκαν καταχωρημένες εγγραφές με αυτά τα κριτήρια"));
                            }
                            $messages->printSystemMessages();
                        } else {
                            global $presults;
                            $presults = $system->getPresults($usection);
                            $pagination = new pagination($maxrows, true, $presults);
                            $pagination->printPages();
                            echo("<div style='margin-bottom:20px;'></div>");
                            ?>
                            <div style="margin:0 0 20px 0; text-align:left; ">
		<span style="position:relative">
		<input style="position:absolute; top :0; left: 6px" type="checkbox" onclick="selectAllcb(this)">
		<span class="hideText"><?php echo t("Επιλογή όλων"); ?></span>
		</span>
                            </div>
                            <?php
                            $counter = 0;
                            $records = $db->getRecords($q);

                            foreach ($records as $row) {
                                $mass_action = ($row->active) ? 'deactivate' : 'activate';
                                $trigger = ($row->active) ? 'on' : 'off';
                                $deactivate = ($row->active) ? NULL : '_deactivate';

                                ?>
                                <div class="record_row">
                                    <div>
                                        <div style="clear:both"></div>
                                        <div class="chk_container">
                                            <input name="delID[]" id="<?php echo "delID_" . $row->id; ?>" value="<?php echo $row->id; ?>" type="checkbox">
                                            <a href="javascript:void(0)" class="toggler record_<?php echo $trigger; ?>" onclick="$('#<?php echo "delID_" . $row->id; ?>').attr('checked','checked'); $('#withSelected').val('<?php echo $mass_action; ?>'); $('#massSelectionForm').submit();"></a>
                                        </div>
                                    </div>
                                    <a href="<?php echo $sef->url("index.php?section=" . $section . "&view=" . $view . "&id=" . $id); echo $querySymbol; ?>action=form&amp;usection=<?php echo $usection; ?>&amp;itemID=<?php echo $row->id; ?>" class="edit_category<?php echo $deactivate; ?>" title="<?php if (!$row->active) {
                                        echo "(" . t("η εγγραφή αυτή είναι ανενεργή") . ")";
                                    } ?>">
                                        <?php echo $row->title; ?>
                                    </a>
                                </div>

                                <?php
                            }
                            echo("<div style='margin-top:20px;'></div>");
                            $pagination = new pagination($maxrows, false, $presults);
                            $pagination->printPages();
                        }
                        if ($rows){
                        ?>
                        <div class="massButtons"><?php echo t("με τα επιλεγμένα"); ?>:
                            <input type="submit" name="massDelete" id="massDelete" value="<?php echo t("Διαγραφή"); ?>" class="btn btn-danger" onClick="return checkMassDelete()">
                            <input type="submit" value="<?php echo t("Ενεργοποίηση"); ?>" class="btn btn-success" onClick="$('#withSelected').val('activate'); return checkMassActivation();">
                            <input type="submit" value="<?php echo t("Απενεργοποίηση"); ?>" class="btn btn-inverse" onClick="$('#withSelected').val('deactivate'); return checkMassSelection()">
                            <?php
                            }
                            ?>
                            <input name="action" type="hidden" id="action" value="<?php echo $action; ?>">
                            <input name="ppage" type="hidden" value="<?php echo $ppage; ?>">
                            <input name="usection" type="hidden" id="usection" value="<?php echo $usection; ?>">
                            <input name="tableSectionID" type="hidden" value="<?php echo $tableSectionID; ?>">
                            <input name="withSelected" type="hidden" id="withSelected" value="">
                        </div>
                    </form>
                </div>
            <?php
            } // end listing


            if ($action == "sort" && !$messages->hasErrors){
            if ($system->getSectionProperty($tableSectionID, "sortType") == "0"){
                $messages->addError(t("Η συγκεκριμένη ενότητα δεν υποστηρίζει ταξινόμηση"));
                $messages->printSystemMessages();
            }else{
            $header = t("Ταξινόμηση των καταχωρήσεων της ενότητας");
            require("modules/odyssey_users/js.php");
            ?>
                <div id="sortInfo" style="display:block"></div>
                <div id="admin_panel" style="margin-bottom:150px;">
                    <div style="text-align:right"><h3><?php echo $header; ?></h3></div>
                    <?php
                    $sortType = $system->getSectionProperty($usection, 'sortType');
                    $fieldType = $db->getRecord("select fieldType from fields where selectTableSectionName='" . $usection . "_categories'");
                    if ($fieldType) $fieldType = $fieldType->fieldType;
                    $tableSectionTitle = $system->getTableSectionTitle($tableSectionID);
                    $q = "select " . $usection . ".id as id, content_" . $usection . ".title as title from " . $usection . ", content_" . $usection . " where " . $usection . ".userID=" . $userID . " and " . $usection . ".id=content_" . $usection . ".mainID and content_" . $usection . ".langID=" . $langID;
                    if ($catID && $sortType == 2) {
                        $q .= " and " . str_replace("_categories", "", $usection) . ".catID=" . $catID;
                    }
                    $order = " order by $usection.sort, $usection.id";
                    $q .= $order;

                    if ($fieldType == "selectList") {
                        $table = $usection;
                        $content_table = "content_" . $table;
                        $catID = ($catID) ? $catID : 0;
                        $q = "select distinct $table.id as id, $content_table.title as title 
			from $table, $content_table, selectlists 
			where $table.id=$content_table.mainID 
			and selectlists.sectionID='$tableSectionID' 
			and selectlists.itemID=$table.id 
			and selectlists.optionID='$catID' ";
                        $q .= $order;
                    }
                    $sortRecords = $db->getRecords($q);
                    if ($sortType == 2) { // main section sortable by category
                        ?>

                        <div style="text-align:right;">
                            <form id="byCategory" name="byCategory" method="get" action="<?php $sef->url("index.php?section=" . $section . "&view=" . $view . "&id=" . $id) ?>">
                                <?php
                                if ($system->getSectionProperty($tableSectionID, "hasCategory")) {
                                    ?>
                                    <label for "catID" style="line-height:33px;"><?php echo t("Ταξινόμηση ανά κατηγορία"); ?>:</label>
                                    <select data-type="advanced" name="catID" class="listbox" id="catID" onchange="$('#byCategory').submit()">
                                        <option value="0" <?php if (empty($catID)) echo "selected"; ?>><?php echo t("Όλες οι κατηγορίες"); ?></option>
                                        <?php
                                        $categoriesTable = $usection . "_categories";
                                        $categories->getCategoriesForSelect(0, 0, false, $categoriesTable, $catID);
                                        ?>
                                    </select>
                                    <input name="action" type="hidden" value="sort">
                                    <input name="tableSectionID" type="hidden" value="<?php echo $tableSectionID; ?>">
                                    <?php
                                }
                                ?>
                            </form>
                        </div>
                        <?php
                    }
                    if (count($sortRecords) > 1) {
                        ?>


                        <div style="margin: 20px 0; text-align:right; font-style:italic">
                            <img src="<?php echo $mp; ?>images/sort_icon.png" width="78" height="70" alt="sort" style="float:right;margin-left:20px"><br>
                            <?php echo t("Απλά μετακινήστε τις εγγραφές στις νέες επιθυμητές θέσεις"); ?>.<br>
                            <?php echo t("Η νέα ταξινόμηση αποθηκεύεται αυτόματα"); ?>!
                            <div style="clear:both"></div>
                        </div>
                        <ul id="sort-list">
                            <?php
                            foreach ($sortRecords as $row) {
                                ?>
                                <li id="listItem_<?php echo $row->id; ?>" style="padding-left:30px; min-height: 30px;">
                                    <div class="handle" onmousedown="setDragStyle(this, 'startDrag');" onmouseup="setDragStyle(this, 'stopDrag');">
                                        <div class="sort_title" onselectstart="return false;" onmousedown="return false;">
                                            <img src="<?php echo $mp; ?>images/arrow.png" alt="move" width="24" height="24" align="absmiddle" style="margin-left: -30px;float: left;">
                                            <div style="display:inline-block; padding-top:5px"><?php echo $row->title; ?></div>
                                        </div>
                                    </div>
                                </li>
                                <?php
                            }
                            ?>
                        </ul>
                        <?php
                    } else {
                        $messages->addError(t("Χρειάζονται τουλάχιστον δύο εγγραφές για να γίνει η ταξινόμηση"));
                        $messages->printSystemMessages();
                    }
                    ?>
                </div>
            <?php
            }
            }  // end sorting

            $editorID = "body" . $langExt . "_ifr";
            ?>
                <script type="text/javascript">
                    jQuery(function ($) {
                        setTimeout(function () {
                            var iframe = $('#<?php echo $editorID;?>');
                            $('.mceContentBody', iframe.contents()).css({'font-family': 'Verdana', 'font-size': '11px'});
                        }, 2000);
                    });
                </script>
                <?php
            }

            // end module's actual code

            ?>
        </div>
    </div>
    <div style="clear: both"></div>

    <!-- dynamic colors  -->
    <style type="text/css">
        .sort_hover {
            background: # <?php echo $colorPrimary;?>; /* Old browsers */
            background: -moz-linear-gradient(top, #<?php echo $colorPrimary;?> 0%, #<?php echo $colorPrimaryDark;?> 97%, #<?php echo $colorPrimaryDark;?> 97%, #<?php echo $colorPrimaryDark;?> 100%); /* FF3.6+ */
            background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #<?php echo $colorPrimary;?>), color-stop(97%, #<?php echo $colorPrimaryDark;?>), color-stop(97%, #<?php echo $colorPrimaryDark;?>), color-stop(100%, #<?php echo $colorPrimaryDark;?>)); /* Chrome,Safari4+ */
            background: -webkit-linear-gradient(top, #<?php echo $colorPrimary;?> 0%, #<?php echo $colorPrimaryDark;?> 97%, #<?php echo $colorPrimaryDark;?> 97%, #<?php echo $colorPrimaryDark;?> 100%); /* Chrome10+,Safari5.1+ */
            background: -o-linear-gradient(top, #<?php echo $colorPrimary;?> 0%, #<?php echo $colorPrimaryDark;?> 97%, #<?php echo $colorPrimaryDark;?> 97%, #<?php echo $colorPrimaryDark;?> 100%); /* Opera 11.10+ */
            background: -ms-linear-gradient(top, #<?php echo $colorPrimary;?> 0%, #<?php echo $colorPrimaryDark;?> 97%, #<?php echo $colorPrimaryDark;?> 97%, #<?php echo $colorPrimaryDark;?> 100%); /* IE10+ */
            background: linear-gradient(to bottom, #<?php echo $colorPrimary;?> 0%, #<?php echo $colorPrimaryDark;?> 97%, #<?php echo $colorPrimaryDark;?> 97%, #<?php echo $colorPrimaryDark;?> 100%); /* W3C */
            filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#<?php echo $colorPrimary;?>', endColorstr='#<?php echo $colorPrimaryDark;?>', GradientType=0); /* IE6-9 */
            border-left-color: # <?php echo $colorBorderLight;?> !important;
            border-top-color: # <?php echo $colorBorderLight;?> !important;
            border-right-color: # <?php echo $colorBorderDark;?> !important;
            border-bottom-color: # <?php echo $colorBorderDark;?> !important;
        }

        .edit_category:hover {
            background: # <?php echo $colorPrimary;?>; /* Old browsers */
            background: -moz-linear-gradient(top, #<?php echo $colorPrimary;?> 0%, #<?php echo $colorPrimaryDark;?> 97%, #<?php echo $colorPrimaryDark;?> 97%, #<?php echo $colorPrimaryDark;?> 100%); /* FF3.6+ */
            background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #<?php echo $colorPrimary;?>), color-stop(97%, #<?php echo $colorPrimaryDark;?>), color-stop(97%, #<?php echo $colorPrimaryDark;?>), color-stop(100%, #<?php echo $colorPrimaryDark;?>)); /* Chrome,Safari4+ */
            background: -webkit-linear-gradient(top, #<?php echo $colorPrimary;?> 0%, #<?php echo $colorPrimaryDark;?> 97%, #<?php echo $colorPrimaryDark;?> 97%, #<?php echo $colorPrimaryDark;?> 100%); /* Chrome10+,Safari5.1+ */
            background: -o-linear-gradient(top, #<?php echo $colorPrimary;?> 0%, #<?php echo $colorPrimaryDark;?> 97%, #<?php echo $colorPrimaryDark;?> 97%, #<?php echo $colorPrimaryDark;?> 100%); /* Opera 11.10+ */
            background: -ms-linear-gradient(top, #<?php echo $colorPrimary;?> 0%, #<?php echo $colorPrimaryDark;?> 97%, #<?php echo $colorPrimaryDark;?> 97%, #<?php echo $colorPrimaryDark;?> 100%); /* IE10+ */
            background: linear-gradient(to bottom, #<?php echo $colorPrimary;?> 0%, #<?php echo $colorPrimaryDark;?> 97%, #<?php echo $colorPrimaryDark;?> 97%, #<?php echo $colorPrimaryDark;?> 100%); /* W3C */
            filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#<?php echo $colorPrimary;?>', endColorstr='#<?php echo $colorPrimaryDark;?>', GradientType=0); /* IE6-9 */
            border-left-color: # <?php echo $colorBorderLight;?>;
            border-top-color: # <?php echo $colorBorderLight;?>;
            border-right-color: # <?php echo $colorBorderDark;?>;
            border-bottom-color: # <?php echo $colorBorderDark;?>;
        }

        #add_item a {
            background: # <?php echo $colorPrimaryDark;?> url(../images/add.gif) 10px center no-repeat;
        }

        #add_item div {
            background-color: # <?php echo $colorPrimaryDark;?>;
        }

        #edit_item a {
            background: # <?php echo $colorPrimaryDark;?> url(../images/edit.gif) 10px center no-repeat;
        }

        #edit_item div {
            background-color: # <?php echo $colorPrimaryDark;?>;
        }

        #sort_item a {
            background: # <?php echo $colorPrimaryDark;?> url(../images/sort.gif) 10px center no-repeat;
        }

        #sort_item div {
            background-color: # <?php echo $colorPrimaryDark;?>;
        }

        .edit_bar {
            border-bottom: 2px solid # <?php echo $colorPrimaryDark;?>;
        }

        .edit_bar_selected {
            background-color: # <?php echo $colorPrimaryDark;?> !important;
        }

        #admin_panel h3 {
            color: # <?php echo $colorPrimaryDark;?> !important;
            border-bottom: 1px solid # <?php echo $colorPrimaryDark;?>;
        }

        #add_item a:hover {
            background: # <?php echo $colorSecondary;?> url(../images/add.gif) 10px center no-repeat;
        }

        #edit_item a:hover {
            background: # <?php echo $colorSecondary;?> url(../images/edit.gif) 10px center no-repeat;
        }

        #sort_item a:hover {
            background: # <?php echo $colorSecondary;?> url(../images/sort.gif) 10px center no-repeat;
        }

        .edit_bar a:hover {
            background-color: # <?php echo $colorSecondary;?>;
        }

        .sort_title {
            color: # <?php echo $colorSecondaryDark;?>;
        }

        .edit_bar a {
            background-color: # <?php echo $colorSecondaryDark;?>;
        }

        .notify,
        .notifyMessage {
            color: white;
            background: # <?php echo $colorMessaging;?>;
        }

        .btn-warning {
            background-color: # <?php echo $colorSecondaryDark;?>;
        }

        .btn-warning:hover, .btn-warning:active, .btn-warning.active, .btn-warning.disabled, .btn-warning[disabled] {
            background-color: # <?php echo $colorSecondary;?>;
        }

        .btn-danger {
            background-color: # <?php echo $colorWarningDark;?>;
        }

        .btn-danger:hover, .btn-danger:active, .btn-danger.active, .btn-danger.disabled, .btn-danger[disabled] {
            background-color: # <?php echo $colorWarning;?>;
        }

        .btn-success {
            background-color: # <?php echo $colorPrimaryDark;?>;
        }

        .btn-success:hover, .btn-success:active, .btn-success.active, .btn-success.disabled, .btn-success[disabled] {
            background-color: # <?php echo $colorPrimary;?>;
        }

        .btn-info {
            background-color: # <?php echo $colorMessagingDark;?>;
        }

        .btn-info:hover, .btn-info:active, .btn-info.active, .btn-info.disabled, .btn-info[disabled] {
            background-color: # <?php echo $colorMessaging;?>;
        }

        .ui-state-hover,
        .ui-widget-content .ui-state-hover,
        .ui-widget-header .ui-state-hover,
        .ui-state-focus,
        .ui-widget-content .ui-state-focus,
        .ui-widget-header .ui-state-focus {
            border: 1px solid # <?php echo $colorPrimary;?>;
            background-color: # <?php echo $colorPrimary;?>;
        }

        .ui-state-active,
        .ui-widget-content .ui-state-active,
        .ui-widget-header .ui-state-active {
            border: 1px solid # <?php echo $colorPrimary;?>;
            color2: # <?php echo $colorPrimary;?>;
        }

        .ui-state-active a,
        .ui-state-active a:link,
        .ui-state-active a:visited {
            color: # <?php echo $colorPrimary;?>;
        }

        .ui-state-highlight,
        .ui-widget-content .ui-state-highlight,
        .ui-widget-header .ui-state-highlight {
            border: 1px solid # <?php echo $colorPrimary;?>;
            background-color: # <?php echo $colorPrimary;?>;
        }

    </style>


    <?php
    if ($auth->getLoginStatus()) {
        $helperMenuFile = $this->getTemplatePath() . "view_users_menu_helper.php";
        if (is_file($helperMenuFile)) include($helperMenuFile);
    }
    if ($useModuleContainer){
    ?>
</div>
<?php
}
?>

