<?php
/*
 *   This file is part of NOALYSS.
 *
 *   NOALYSS is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   NOALYSS is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with NOALYSS; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
/*! \file
 * \brief Welcome page where the folder and module are choosen
 */

// Copyright Author Dany De Bontridder danydb@aevalys.eu
require_once '../include/constant.php';
include_once NOALYSS_INCLUDE.'/lib/ac_common.php';
require_once NOALYSS_INCLUDE.'/class/database.class.php';
require_once NOALYSS_INCLUDE.'/lib/itext.class.php';
require_once NOALYSS_INCLUDE.'/lib/http_input.class.php';
require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
require_once NOALYSS_INCLUDE.'/lib/icon_action.class.php';
@html_page_start($_SESSION[SESSION_KEY.'g_theme']);
MaintenanceMode("block.html");

$rep=new Database();
require_once NOALYSS_INCLUDE . '/class/noalyss_user.class.php';

$User=new Noalyss_user($rep);

$User->Check();
/**
 * check if 2FA is completed
 */
if ( ! $User->is_double_identified()) {
   exit();
}

/*  Check Browser version if < IE6 then unsupported */
$browser=$_SERVER['HTTP_USER_AGENT'];
if ( strpos($browser,'MSIE 6')!=false ||
        strpos($browser,'MSIE 5')!=false )
{
    $nav=_('Vous utilisez un navigateur dépassé depuis près de 8 ans!');
    $nav2=_("Pour une meilleure expérience web, prenez le temps de mettre votre navigateur à jour");
    echo <<<EOF
      <!--[if lt IE 7]>
      <div style='border: 1px solid #F7941D; background: #FEEFDA; text-align: center; clear: both; height: 75px; position: relative;'>
      <div style='position: absolute; right: 3px; top: 3px; font-family: courier new; font-weight: bold;'><a href='#' onclick='javascript:this.parentNode.parentNode.style.display="none"; return false;'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-cornerx.jpg' style='border: none;' alt='Close this notice'/></a></div>
      <div style='width: 640px; margin: 0 auto; text-align: left; padding: 0; overflow: hidden; color: black;'>
      <div style='width: 75px; float: left;'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-warning.jpg' alt='Warning!'/></div>
      <div style='width: 275px; float: left; font-family: Arial, sans-serif;'>
      <div style='font-size: 14px; font-weight: bold; margin-top: 12px;'>$nav</div>
      <div style='font-size: 12px; margin-top: 6px; line-height: 12px;'>$nav2.</div>
      </div>
      <div style='width: 75px; float: left;'><a href='http://fr.www.mozilla.com/fr/' target='_blank'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-firefox.jpg' style='border: none;' alt='Get Firefox 3.5'/></a></div>
      <div style='width: 73px; float: left;'><a href='http://www.apple.com/fr/safari/download/' target='_blank'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-safari.jpg' style='border: none;' alt='Get Safari 4'/></a></div>
      <div style='float: left;'><a href='http://www.google.com/chrome?hl=fr' target='_blank'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-chrome.jpg' style='border: none;' alt='Get Google Chrome'/></a></div>
      </div>
      </div>
      <![endif]-->
EOF;
    exit();
}
if ( DEBUGNOALYSS > 1 ) {
    /**
     * Debug Design
     */
    \Noalyss\Dbg::display_size();
    \Noalyss\Dbg::display_request();
    \Noalyss\Dbg::display_global();
} //<--- if DEBUG
$ac=new Database();
$hi=new HttpInput();

/* check if repo valid */
if ( $ac->exist_table('version') == false)
{
    echo '<h2 class="error" style="font-size:12px">'._("Base de donnée invalide").'</h2>';
    echo '<a hreF="'.NOALYSS_URL.'/user_login.php">'._("Retour").'</a></h2>';
    exit();
}

/* check repo version */
if (!defined("MULTI")||(defined("MULTI")&&MULTI==1))
{
    $version = $ac->get_value('select max(val) from version');
} else {
    $version = $ac->get_value('select max(val) from repo_version');
    
}
if ( $version < DBVERSIONREPO )
{
    echo '<h2 class="error" style="font-size:12px">'._("Votre base de données n'est pas à jour").'   ';
    $a=_("cliquez ici pour appliquer le patch");
    $base =NOALYSS_URL.'/admin-noalyss.php';
    echo '<a hreF="'.$base.'">'.$a.'</a></h2>';

}
if ( $User->isAdmin()  == 1)
{
    if (SITE_UPDATE !="") {
        $file=$_ENV['TMP']."/version_noalyss".domaine;
        $update=\Noalyss\File_Cache::get_content(SITE_UPDATE,$file,172800);

	 if ($update > $version_noalyss ) {
            echo '<div id="version_div" class="inner_box" style="width:25%;margin-left:10%;margin-top:3px;">';
            echo '<p class="notice">';
            printf ( "Mise à jour disponible de NOALYSS version actuelle : %s  votre version %s ",$update,$version_noalyss);

            // Link to admin_repo : upgrade application
            $base =NOALYSS_URL."/admin-noalyss.php?action=upgrade&sb=application";

           echo '<a hreF="' . $base . '">' . _("Cliquez ici pour mettre à jour") . '</a>';
           echo '</p>';
           echo '<p style="text-align:center"> <a class="button" onclick="document.body.removeChild(document.getElementById(\'version_div\'))">'.
                   _('Fermer').
                   "</a></p>";
           echo '</div>';
        }
    }
}

include_once NOALYSS_INCLUDE."/lib/user_menu.php";

$priv=($User->admin==1)?_("Administrateur"):_("Utilisateur");
load_all_script();

/**
 *
 * If the user is NOT admin and can access only ONE folder,
 * OR for a One Folder Installation
 * he will be directly redirected to his folder or to the plugins of this
 * folder if he's an "plugin user"
 */


$result="";
$result.="<table border=\"0\">";
$result.='<TR>';
if ( $User->isAdmin()  == 1 )
{
    $result.="<TD  class=\"tool\" ><A class=\"cell\" HREF=\"admin-noalyss.php\">"._("Administration")."  </A></TD>";
}
$result.='<TD class="tool">';
$result.='<a onclick="set_preference(0)" title="Préférence" href="javascript:void(0)" class="cell">'._('Préférence').'</a>';
$result.= '</TD>';
$result.='<TD  class="tool" ><A class="cell" HREF="logout.php" >'._('Deconnexion').'</a></TD>';
$result.="</TR>";
$result.="</table>";

echo '<div id="module" style="position:absolute;">'.$result.'</div>';
echo '<div class="welcome"> ';
if ( $User->admin == 0 || (defined("MULTI")&& MULTI == 0 ) )
{
    // how many folder ?
    $folder=$User->get_available_folder();
    if ( $folder != null  && count($folder) == 1 )
    {
            echo _("Si la redirection ne fonctionne pas, vous devez changer la valeur de NOALYSS_URL ");
            redirect(NOALYSS_URL.'/do.php?gDossier='.$folder[0]['dos_id']);
            exit();
    }

}
echo '</div>';
?>
<div class="foldercontent">
	<span style="margin:2%" class="visible_gt800">
 <?php
                        echo _('Cherche').Icon_Action::infobulle(23);
?>
<?php
	echo HtmlInput::filter_table("folder", '0,1,2',1);
?>
</span>
<?php

// If admin show everything otherwise only the available dossier
$res=$User->show_dossier("");
echo $res;
?>
<P>

</P>
</div>
<?php
html_page_stop();
?>
