<?php

/**************************************************************************/
/* Module Gbook MX v2.0 Copyright (c) 2004 by Víctor Simental             */
/* $Revision 14/02/2004 - $Id index.php - v4.1.2    EPX $                 */ 
/* @URI: http://www.phpwebmasters.com                                     */ 
/* ============================================                           */
/* Based in Gbook MX v4.1.0 Copyright (c) 2003 by                         */
/* Víctor Simental - http://gbookmx.sourceforge.net                       */
/* ============================================                           */
/* GbookMX is Based in the Gbook v1.0 for PHP Nuke Copyright (c) 2003 by  */
/* http://www.PHP-Mania.com.ar                                            */
/* Programed and Design By Víctor Simental and German Cúevas              */
/* vicmx@phpwebmasters.com                                                */
/*                                                                        */
/* 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 (!eregi("modules.php", $_SERVER['PHP_SELF'])) {   
 die ("You can't access this file directly...");
}

$module_name = basename(dirname(__FILE__));
	if(@file_exists("modules/$module_name/install.php"))
	  die("Please delete install.php in <b>modules/$module_name/install.php</b>!");
	  if(!@file_exists("modules/$module_name/copyright.php"))
	  die("<h1>Your Gbook MX its an copy ilegal<br> <b>DO NOT REMOVE THE COPYRIGHT. YOU'RE NOT ALLOWED TO REMOVE NOR EDIT THIS.!!!!</b></h1>");	  
require("modules/$module_name/includes/funciones.inc.php");
require_once("modules/$module_name/common.php");
include("modules/$module_name/includes/settings.php");

    function offline(){
	   include("header.php");
	   global $sitename, $module_name, $bordercolor, $tableheader, $Colortab, $offline, $admin;
	   Opentable();
	echo "<table cellpadding=\"3\" cellspacing=\"1\" border=\"0\" bgcolor=\"$bordercolor\" align=\"center\">
	<tr bgcolor=\"$tableheader\">
	<td><center><font class=\"title\"><b>&raquo; $sitename";
		if(is_admin($admin)){
		echo "&nbsp;&nbsp;<img src=\"modules/$module_name/images/lock.gif\" alt=\""._GOADMIN."\"> <a href='modules.php?name=$module_name&amp;op=admin'>"._GOADMIN."</a> ";
		}
	echo _OFFLINE ."  <img src=\"modules/$module_name/images/smilies/sm16.gif\" alt=\""._OFFLINE."\"></b></font></center></td>
	</tr>
	<tr bgcolor=\"$Colortab\">
	<td>"._BOOKOOFLINE."<br><blockquote>".$offline."</blockquote></font></td>
	</tr>
	</table>";
	CloseTable();
	include("footer.php");
   }
   
   
function paginar($actual, $total, $por_pagina, $enlace, $maxpags=14) {
  $total_paginas = ceil($total/$por_pagina);
  $anterior = $actual - 1;
  $posterior = $actual + 1;
  $minimo = $maxpags ? max(1, $actual-ceil($maxpags/2)): 1;
  $maximo = $maxpags ? min($total_paginas, $actual+floor($maxpags/2)): $total_paginas;
  if ($actual>1)
    $texto = "<a href=\"$enlace$anterior\">"._ANTERIOR."</a> ";
  /*else
    $texto = "<b>&laquo;</b> ";*/
  if ($minimo!=1) $texto.= "... ";
  for ($i=$minimo; $i<$actual; $i++)
    $texto .= "<a href=\"$enlace$i\">$i</a> ";
  $texto .= "<b>$actual</b> ";
  for ($i=$actual+1; $i<=$maximo; $i++)
    $texto .= "<a href=\"$enlace$i\">$i</a> ";
  if ($maximo!=$total_paginas) $texto.= "... ";
  if ($actual<$total_paginas)
    $texto .= "<a href=\"$enlace$posterior\">"._SIGUIENTE."</a>";
  /*else
    $texto .= "<b>&raquo;</b>";*/
  return $texto;
}

	if(!$copy) die("Copy Ilegal!!!");
	  if(isset($op)){
	  if($op == "Add_Sign")
	  include("modules/$module_name/addsign.php");
	  elseif($op == "Showsmilies")
	  include("modules/$module_name/smilies.php");
	  elseif($op == "preview")
	  include("modules/$module_name/preview.php");
	  elseif($op == "save")
	  include("modules/$module_name/save.php");
	  elseif(($op == "admin")&&(is_admin($admin)))
	  include("modules/$module_name/admin.php");
	 }
	 else
	 {
	 
	 	if($online == "yes"){ echo offline(); }
		
		else
		{
		include("header.php");
		Table();
		
?>

<table align="center" border="0" width="100%">
<tr><td width="50%" valign="top"><h3><?php echo $sitename; ?></h3>
<?php echo "<form><br>" ._LANG." <select name='idioma' onChange=\"self.location=this.options[this.selectedIndex].value;\">\n";
	
	$handle=opendir('modules/'.$module_name.'/language');
    while ($file = readdir($handle)) {
	if (ereg("^lang\-(.+)\.php", $file, $matches)) {
            $langFound = $matches[1];
            $languageslist .= "$langFound ";
        }
    }
    closedir($handle);
	$languageslist = explode(" ", $languageslist);
    sort($languageslist);
    for ($i=0; $i < sizeof($languageslist); $i++) {
	if($languageslist[$i]!="") {
	
	if(isset($idioma))	$nuevo_idioma2=$idioma;
	elseif(isset($nuevo_idioma)) $nuevo_idioma2=$nuevo_idioma;
	else $nuevo_idioma2=$countrylang;
	
	    echo "<option name='idioma' value='modules.php?name=$module_name&amp;idioma=$languageslist[$i]' ";
		if($languageslist[$i]==$nuevo_idioma2) echo "selected";
		echo ">".ucfirst($languageslist[$i])."</option>\n";
	}
    }
    echo "</select>\n</form>";
	?></td>
<td width="50%"><center>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000
  codebase="http://active.macromedia.com/flash4/cabs/swflash.cab#version=4,0,0,0
  id="gbookmx" width="143" height="17">
  <param name="movie" value="modules/<?=$module_name?>/images/gbook.swf">
  <param name="menu" value="false">
  <param name="quality" value="high">
  <param name="bgcolor" value="<?php echo $bgcolor1; ?>">
  <embed name="gbook" src="modules/<?=$module_name?>/images/gbook.swf" quality="high" bgcolor="<?php echo $bgcolor1; ?>"
    width="143" height="17"
    type="application/x-shockwave-flash"
    pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">
  </embed>
</object><br>
<img src="modules/<?=$module_name?>/images/fir.gif" title="<?php echo _SIGNGB; ?>" alt="<?php echo _SIGNGB; ?>" border="0"><a href="modules.php?name=<?=$module_name?>&amp;op=Add_Sign"><?php echo _SIGNGB; ?></a> <img src="modules/<?=$module_name?>/images/view.gif" alt="<?php echo _SEEGB; ?>" title="<?php echo _SEEGB; ?>" border="0"><a href="modules.php?name=<?=$module_name?>"><?php echo _SEEGB; ?></a>
<?php
     if(is_admin($admin)){
?>
<br><img src="modules/<?=$module_name?>/images/lock.gif" alt="<?php echo _GOADMIN; ?>" title="<?php echo _GOADMIN; ?>" border="0"> <a href="modules.php?name=<?=$module_name?>&amp;op=admin"><?php echo _GOADMIN; ?></a>
<?php
   }
?>
<br><?php echo $welcome;?>
</center>
</td></tr>
</table>
<?php
         if (!isset($page)) $page = 1; // Por defecto, pagina 1
      $reg1 = ($page-1) * $num_sign;
      $result = $mysql->sql_query("SELECT * FROM ".$prefix."_gbook ORDER BY id ".$displayorder.""); 
      $total = $mysql->sql_num_rows($result);
      
      if($total == 0 OR $total<$num_sign){
	  echo "<br>";
	  }
	  else
	  {
	  echo "<br>" ._SHOWPAGE .paginar($page, $total, $num_sign, "modules.php?name=".$module_name."&amp;page=");
	  }
	  echo "<left><img src=\"modules/$module_name/images/sign2.gif\" border=\"0\" alt=\"\"> "._HAY." <b>".$total."</b> "._MENDB."&nbsp;&nbsp;<img src=\"modules/$module_name/images/sign.gif\" border=\"0\" alt=\"\"> "._PAGEVIEW." <b>".$num_sign."</b></left><br><br>\n";
	  
	      if ($mysql->sql_num_rows($result)){
?>

<table width="100%" align="center" border="0" cellpadding="7" cellspacing="1" bgcolor="<?php echo $bordercolor; ?>">
<tr bgcolor="<?php echo $tableheader; ?>">
<td width="20%" valign="top">
<center><font class="title"><b><?php echo _TABLENOMBRE; ?></b></font></center></td>
<td width="80%" valign="top">
<center><font class="title"><b><?php echo _COMENTARIOS; ?></b></font></center>
</td></tr>
<?php

             $colortab="$Colortab";
			 for ($i=$reg1; $i<min($reg1+$num_sign, $total); $i++) {
			 
	$mysql->sql_data_seek($result, $i);
	$row = $mysql->sql_fetch_assoc($result);
	
	echo "<tr bgcolor=\"$colortab\">\n<td width=\"20%\" rowspan=\"3\" valign=\"middle\">\n"
	     ."<center>";
		 if($allowhtml == 1){
		 if($row["user"]==1){
		 echo "<img src=\"modules/$module_name/images/smilies/sm29.gif\" alt=\"\" border=\"0\" align=\"absmiddle\"> <a href=\"modules.php?name=Your_Account&op=userinfo&username=".$row["nombre"]."\">";
		 }
		 echo $row["nombre"];
		 if($row["user"]==1) echo "</a>";
		 }
		 else
		 {
		 $row["nombre"] = htmlspecialchars($row["nombre"]);
		 if($row["user"]==1){
		 echo "<a href=\"modules.php?name=Your_Account&op=userinfo&username=".$row["nombre"]."\">";
		 }
		 echo $row["nombre"];
		 if($row["user"]==1) echo "</a>";
		 }
		 
		 if($genero_field == 1){
		    if($row["genero"]== "male"){
			echo "\n<img src=\"modules/$module_name/images/male.gif\" align=\"absmiddle\" alt=\""._MALE."\">";
			}
			elseif($row["genero"]== "female") {
			echo "\n<img src=\"modules/$module_name/images/female.gif\" align=\"absmiddle\" alt=\""._FEMALE."\">";
			}
			else
			{
		    }
		 }
		 
		 if($pais_field == 1){
		    if($row["bandera"]!="blank.gif" AND $row["bandera"]!=""){
			echo "<br>\n<b>"._PAIS."</b><br>\n<img src=\"modules/$module_name/images/flags/".$row["bandera"]."\" width=\"30\" height=\"20\" ";
			
			//FIX door peter, voor oude versie van basename
			//$row["bandera"]=basename(strval($row["bandera"]),".gif");
			$row["bandera"]=basename(strval($row["bandera"]));
			    if (substr($row["bandera"], -4) == ".gif"){
				$row["bandera"]=substr($row["bandera"], 0, -4);
				}
			//einde FIX
			echo "alt=\"".ucfirst($row["bandera"])."\" border=\"0\" align=\"absmiddle\">\n";
			}
			}
			else
			echo "&nbsp;\n";
			
			if($ciudad_field == 1){
			   if($row["ciudad"]){
			      if($allowhtml == 1){
				  echo "<br><b>"._CIUDAD."</b><br>".$row["ciudad"]."</center>\n";
				  }
				  else
				  echo "<br><b>"._CIUDAD."</b><br>";
			   }
			   else
			   echo $row["ciudad"] = htmlspecialchars($row["ciudad"])."</center>\n";
			 }
			 
			 echo "</td>\n<td width=\"80%\" valign=\"top\">\n&nbsp;&nbsp;<img src=\"modules/$module_name/images/posticon.gif\" align=\"absmiddle\">"
			 ."&nbsp;"._MENSAJE." "._FIRMADO." ".Convertir_Fecha($row["fecha"])."\n";
			 
			    if($row["useragent"]!=""){
				echo "&nbsp;<img src=\"modules/$module_name/images/navegador/".$row["useragent"].".gif\" alt=\"".ucfirst($row["useragent"])."\" border=\"0\">";
				}
				//Administracion
				
				if(is_admin($admin)){
				echo "<a href=\"modules.php?name=$module_name&amp;op=admin&amp;action=Add_Comment&id=".$row["id"]."\"><img src=\"modules/$module_name/images/add_comment.gif\" border=\"0\" alt=\""._BOOKCOMMENTS."\"></a>\n"
				."<a href=\"modules.php?name=$module_name&amp;op=admin&amp;action=edit&amp;id=".$row["id"]."\"><img src=\"modules/$module_name/images/edit.gif\" border=\"0\" alt=\""._BOOKEDIT."\"></a>\n"
				."<a href=\"modules.php?name=$module_name&amp;op=admin&amp;action=delete&amp;id=".$row["id"]."\"><img src=\"modules/$module_name/images/del.gif\" border=\"0\" ALT=\""._BOOKBORRAR."\"></a>";
				}
				echo "</td>\n</tr>\n<tr bgcolor=\"$colortab\">\n<td width=\"80%\" valign=\"top\">\n";
				
				if($allowhtml == 1){
				echo emoticon($row["firma"])."\n<br><br>\n";
				}
				else
				echo emoticon(parse_html($row["firma"]))."\n<br><br>\n";
	if($row["comentario"]){
	echo "<!-- Begin Admin Comments --><i>"._ADMINWRITE." ".emoticon($row["comentario"])."</i>\n<!-- End Admin Comments -->\n";
	}
	echo "</td>\n</tr>\n<tr bgcolor=\"$colortab\">\n<td valign=\"bottom\">\n"
	."<table border=\"0\" width=\"90%\"><tr><td valign=\"top\" align=\"left\">\n";
	if($row["email"]){
	echo "<a href=\"mailto:".$row["email"]."\"><img src=\"modules/$module_name/images/email.gif\" border=\"0\" alt=\"".$row["email"]."\"></a>\n";
	}
	if($row["url"]!="http://"){
	echo "<a href=\"".$row["url"]."\" target=\"_blank\"><img src=\"modules/$module_name/images/home.gif\" border=\"0\" align=\"absmiddle\" alt=\"".$row["url"]."\"></a>\n";
	}
	if($row["msn"]){
	echo "<img src=\"modules/$module_name/images/msn.gif\" align=\"absmiddle\" border=\"0\" alt=\"".$row["msn"]."\">\n";
	}
	if($row["yim"]){
	echo "<a href=\"http://edit.yahoo.com/config/send_webmesg?.target=".$row["yim"]."&.src=pg\"><img src=\"modules/$module_name/images/yim.gif\" align=\"absmiddle\" border=\"0\" alt=\"".$row["yim"]."\"></a>\n";
	}
	if($row["aim"]){
	echo "<a href=\"aim:goim?screenname=".$row["aim"]."&amp;message=Hello+Are+you+there?\"><img src=\"modules/$module_name/images/aim.gif\" align=\"absmiddle\" border=\"0\"></a>\n";
	}
	if($row["icq"]){
	echo "<a href=\"http://wwp.icq.com/scripts/search.dll?to=".$row["icq"]."\"><img src=\"modules/$module_name/images/icq.gif\" align=\"absmiddle\" border=\"0\"></a>\n";
	}
	echo "</td><td valign=\"top\" align=\"right\">";
		
		if(Comprobar_Fecha($row["fecha"])){
		echo "<img src=\"modules/$module_name/images/new.gif\">";
		}
	echo "&nbsp;<img src=\"modules/$module_name/images/ip.gif\" align=\"absmiddle\" alt=\""._IPLOGIN."\" align=\"right\" width=\"13\" height=\"13\">";
		
		if((is_admin($admin))||($showipuser=="yes")){
		echo " "._IP." ".$row["ip"]."\n";
		}
	echo "</td></tr></table>\n</td></tr>";
	    
		if($colortab=="$Colortab"){
		$colortab="$Colortab2";
		}
		else
		{
		$colortab="$Colortab";
		}
	}//end for
	
	echo "</table><br>\n";
}
else
{
EndTable();
echo "<br>\n";
Table();
echo "<br><center><b>"._BOOKEMPTY."</b></center></br>";
     
	 }//Fin de sql result
	 EndTable();
	 if($total == 0 OR $total<$num_sign){
	 echo "<br>";
	 }
	 else
	 {
	 echo "<br>";
	 Table();
	 echo _SHOWPAGE .paginar($page, $total, $num_sign, "modules.php?name=".$module_name."&amp;page=");
	 EndTable();
	 }
	 
	 $mysql->sql_close();
	 include("footer.php");
	 }
}
?>