<?PHP
/************************************************************************/
/* DUNE by NPDS                                                         */
/* ===========================                                          */
/*                                                                      */
/* Based on PhpNuke 4.x source code                                     */
/*                                                                      */
/* NPDS Copyright (c) 2002-2007 by Philippe Brunier                     */
/*                                                                      */
/* This program 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.       */
/************************************************************************/
if (!function_exists("Mysql_Connexion")) {
   include ("mainfile.php");
}

$header = 1;

function head($tiny_mce_init, $css_pages_ref, $css) {
   global $slogan, $site_font, $Titlesitename, $banners, $Default_Theme, $gzhandler, $language;
   global $topic, $hlpfile, $user, $hr, $theme, $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5, $bgcolor6, $textcolor1, $textcolor2, $long_chain;
   global $bargif, $theme_width, $bloc_width, $page_width;
   if ($gzhandler==1) {ob_start("ob_gzhandler");}
   if (isset($user)) {
      global $cookie;
      if ($cookie[9]=="") $cookie[9]=$Default_Theme;
      if (isset($theme)) $cookie[9]=$theme;
      $tmp_theme=$cookie[9];
      if (!$file=@opendir("themes/$cookie[9]")) $tmp_theme=$Default_Theme;
   } else {
      $tmp_theme=$Default_Theme;
   }
   include("themes/$tmp_theme/theme.php");

   if (file_exists("meta/meta.php"))
      include ("meta/meta.php");

   // Favicon
   if (file_exists("themes/$tmp_theme/images/favicon.ico")) {
      $favico="themes/$tmp_theme/images/favicon.ico";
   } else {
      $favico="images/favicon.ico";
   }
   echo "<link rel=\"shortcut icon\" href=\"$favico\" type=\"image/x-icon\" />\n";

   // Syndication RSS FF
   global $sitename;
   echo "<link href=\"backend.php?op=RSS0.91\" title=\"$sitename - RSS 0.91\" rel=\"alternate\" type=\"text/xml\" />\n";
   echo "<link href=\"backend.php?op=RSS1.0\" title=\"$sitename - RSS 1.0\" rel=\"alternate\" type=\"text/xml\" />\n";
   echo "<link href=\"backend.php?op=RSS2.0\" title=\"$sitename - RSS 2.0\" rel=\"alternate\" type=\"text/xml\" />\n";
   echo "<link href=\"backend.php?op=ATOM\" title=\"$sitename - ATOM\" rel=\"alternate\" type=\"application/atom+xml\" />\n";

   echo import_css($tmp_theme, $language, $site_font, $css_pages_ref, $css);

   // Tiny_mce
   if ($tiny_mce_init)
      echo aff_editeur("tiny_mce", "begin");

   echo "<script type=\"text/javascript\" language=\"JavaScript\">\n";
   echo "function showimage() {\n";
   echo "if (!document.images)\n";
   echo "   return\n";
   echo "document.images.avatar.src=\n";
   if ($ibid=theme_image("forum/avatar/blank.gif")) {$imgtmp=substr($ibid,0,strrpos($ibid,"/")+1);} else {$imgtmp="images/forum/avatar/";}
   echo "'$imgtmp' + document.Register.user_avatar.options[document.Register.user_avatar.selectedIndex].value\n";
   echo "}\n";
   echo "</script>\n";
   echo "<script type=\"text/javascript\" language=\"JavaScript\">\n\n";
   echo "function init() {\n";
      // include externe JAVASCRIPT file from modules/include or themes/.../include for functions, codes in the <body onload="..." event...
      if (file_exists("modules/include/body_onload.inc")) {include ("modules/include/body_onload.inc");}
      if (file_exists("themes/$tmp_theme/include/body_onload.inc")) {include ("themes/$tmp_theme/include/body_onload.inc");}
   echo "}\n";
   echo "</script>\n";

   // include externe file from modules/include or themes/.../include for functions, codes ...
   if (file_exists("modules/include/header_head.inc")) {include ("modules/include/header_head.inc");}
   if (file_exists("themes/$tmp_theme/include/header_head.inc")) {include ("themes/$tmp_theme/include/header_head.inc");}
   echo "</head>\n";
   include("themes/$tmp_theme/header.php");
}

   // include externe file from modules/include for functions, codes ...
   if (file_exists("modules/include/header_before.inc")) {include ("modules/include/header_before.inc");}

   // Made the title and pdst value from the pages.php config file
   settype($PAGES, array());
   global $pdst, $Titlesitename, $REQUEST_URI;
   require_once("themes/pages.php");
   $page_uri=split("[&?]",$REQUEST_URI);
   $Npage_uri=count($page_uri);
   $pages_ref=basename($page_uri[0]);

   // Static page and Module can have Bloc, Title ....
   if ($pages_ref=="static.php") {
      $pages_ref=substr($REQUEST_URI,strpos($REQUEST_URI,"static.php"));
   }
   if ($pages_ref=="modules.php") {
      if (isset($PAGES["modules.php?ModPath=$ModPath&ModStart=$ModStart*"][title])) {
         $pages_ref="modules.php?ModPath=$ModPath&ModStart=$ModStart*";
      } else
         $pages_ref=substr($REQUEST_URI,strpos($REQUEST_URI,"modules.php"));
   }

   // extend usage of pages.php : blocking script with part of URI for user, admin or with the value of a VAR
   if ($Npage_uri>1) {
      for ($uri=1; $uri<$Npage_uri; $uri++) {
         if ($PAGES[$page_uri[$uri]][run]!="") {
            if (!$$PAGES[$page_uri[$uri]][run]) {
               header("location: ".$PAGES[$page_uri[$uri]][title]);
               die();
            }
         }
      }
   }

   if ($PAGES[$pages_ref][blocs]!="") {
      $pdst=$PAGES[$pages_ref][blocs];
   }

   // block execution of page with run attribute = no
   if ($PAGES[$pages_ref][run]=="no") {
      if ($pages_ref=="index.php") {
          $Titlesitename="NPDS";
          if (file_exists("meta/meta.php"))
             include("meta/meta.php");
         echo "</head><body bgcolor=\"white\"><br /><p align=\"center\"><span style=\"font-size: 14px; font-family: Arial; font-weight: bold; color: red;\">";
         echo "Web Site closed  / Site Web ferm&eacute;";
         if (cur_charset=="utf-8") echo" / &#x901A;&#x5165;&#x88AB;&#x5426;&#x8BA4;";
         echo "<br /><br />NPDS - Portal System";
         echo "</span></p></body></html>";
         die();
      } else {
         header("location: index.php");
      }
   // run script to another 'location'
   } elseif (($PAGES[$pages_ref][run]!="yes") and (($PAGES[$pages_ref][run]!=""))) {
      header("location: ".$PAGES[$pages_ref][run]);
   }

   // Assure la gestion des titres ALTERNATIFS
   $tab_page_ref=explode("|",$PAGES[$pages_ref][title]);
   if (strlen($tab_page_ref[1])>1) {
      $PAGES[$pages_ref][title]=$tab_page_ref[1];
   } else {
      $PAGES[$pages_ref][title]=$tab_page_ref[0];
   }
   $PAGES[$pages_ref][title]=strip_tags($PAGES[$pages_ref][title]);

   if (substr($PAGES[$pages_ref][title],-1)=="+") {
      $TitlesitenameX=aff_langue(substr($PAGES[$pages_ref][title],0,strlen($PAGES[$pages_ref][title])-1));
      $Titlesitename=$TitlesitenameX." - ".$Titlesitename;
   } else if (substr($PAGES[$pages_ref][title],-1)=="-") {
      $Titlesitename=aff_langue(substr($PAGES[$pages_ref][title],0,strlen($PAGES[$pages_ref][title])-1));
   }
   if ($Titlesitename=="") {$Titlesitename=$sitename;}
   // globalisation de la variable title pour marquetapage mais protection pour la zone admin
   if ($pages_ref!="admin.php")
      global $title;
   if (!$title)
      $title=aff_langue(substr($PAGES[$pages_ref][title],0,strlen($PAGES[$pages_ref][title])-1));
   else
      $title=removeHack($title);

   // Initialisation de TinyMce
   global $tiny_mce,$tiny_mce_theme;
   if ($tiny_mce) {
      if ($PAGES[$pages_ref][TinyMce]) {
         $tiny_mce_init=true;
         $tiny_mce_theme=$PAGES[$pages_ref][TinyMce-theme];
      } else {
         $tiny_mce_init=false;
         $tiny_mce=false;
      }
   } else {
      $tiny_mce_init=false;
   }

   // CSS specifique
   if ($PAGES[$pages_ref][css]!="") {
      $css_pages_ref=$pages_ref;
      $css=$PAGES[$pages_ref][css];
   } else {
      $css_pages_ref="";
      $css="";
   }

   head($tiny_mce_init, $css_pages_ref, $css);

   // Menu dynamique des Rubriques - Alat 2004
   if (file_exists("sections.config.php")) {
      include ("sections.config.php");
      if ($sections_menudyn) { rubrique_menudyn(); }
   }

   global $httpref, $nuke_url, $httprefmax, $admin;
   global $NPDS_Prefix;
   if ($httpref==1) {
      $referer= removeHack(getenv("HTTP_REFERER"));
      if ($referer=="" OR strstr($referer,"unknown") OR stristr($referer,$nuke_url)) {
      } else {
         sql_query("insert into ".$NPDS_Prefix."referer values (NULL, '$referer')");
      }
      $result=sql_fetch_assoc(sql_query("select count(*) as total from ".$NPDS_Prefix."referer"));
      if (($result[total]>=$httprefmax) and ($admin)) {
         echo " <span class=\"rouge\">".translate("Referer max count limit : Save your referer via Admin function.")."</span>";
      }
   }
   include("counter.php");

   // include externe file from modules/include for functions, codes ...
   if (file_exists("modules/include/header_after.inc")) {include ("modules/include/header_after.inc");}
?>