<div id="center-column">
<div class="top-bar">
<a href="index.php?act=news" class="button">Aņadir Noticias</a>
<h1>Cpanel - Configuracion</h1>
<div class="breadcrumbs"><a href="index.php?act=categories">Categorias</a> / <a href="index.php?act=links">Enlaces</a></div>
</div><br />
<div class="select-bar">
<label>
<h3>Configuracion general del sitio</h3>
</label>
</div>
<?php
$query1 = yasDB_select("SELECT * FROM links WHERE approved = 'no'",false);
$links = $query1->num_rows;
$query1->close();

$query2 = yasDB_select("SELECT id FROM games");
$tgames = $query2->num_rows;
$query2->close();

$query3 = yasDB_select("SELECT * FROM stats WHERE id = '1'",false);
$totalplays = $query3->fetch_array(MYSQLI_ASSOC);
$totalplays = $totalplays['numbers'];
$query3->close();

$query4 = yasDB_select("SELECT * FROM stats WHERE id = '2'",false);
$todayplays = $query4->fetch_array(MYSQLI_ASSOC);
$todayplays = $todayplays['numbers'];
$query5 = yasDB_select("SELECT * FROM comments");
$comments = $query5->fetch_array(MYSQLI_ASSOC);
$comments = $query5->num_rows;
$query5->close();

$query6 = yasDB_select("SELECT count(id) as count FROM user");
$user = $query6->fetch_array(MYSQLI_ASSOC);
$user = $query6->num_rows;
$query6->close();
if(isset($_POST['settings'])) {
    if(empty($_POST['gperpage']) || empty($_POST['gamesort']) || empty($_POST['numbgames']) || empty($_POST['lightbox']) || empty($_POST['approvelinks']) || empty($_POST['disabled'])|| empty($_POST['numblinks'])) {
        echo '<center>One or more fields that were required were left empty.<br />';
        echo '<a href="index.php?act=settings">Click here to go back.</a></center>';
    } else {
        if(!ctype_digit($_POST['gperpage'])) {
            echo '<center>Files per page must be a number.</center>';
        } else {            
            if ($_POST['use'] == 1) {
                $captcha = 'yes';
            } else {
                $captcha = 'no';
            }
            if(!empty($_POST['password']) && $_POST['password'] == $_POST['passwordcheck']) {
                $id = '1';
                yasDB_update("UPDATE settings SET gperpage = ".intval($_POST['gperpage']).", numbgames = ".intval($_POST['numbgames']).", gamesort = '{$_POST['gamesort']}', approvelinks = '{$_POST['approvelinks']}', numblinks = ".intval($_POST['numblinks']).", seo = '{$_POST['seo']}' , lightbox = '{$_POST['lightbox']}', theme = '{$_POST['theme']}', skin = '{$_POST['skin']}', disabled = '{$_POST['disabled']}', email = '{$_POST['email']}', sitename = '".yasDB_clean($_POST['sitename'])."', slogan = '".yasDB_clean($_POST['slogan'])."', metades = '".yasDB_clean($_POST['metades'])."', metakeywords = '".yasDB_clean($_POST['metakeywords'])."',`userecaptcha` = '$captcha', `cachelife` = ".intval($_POST['pagecache']).", `password` = '".md5($_POST['password'])."' where id = '1'");
                include("../includes/settings_function.inc.php");
				createConfigFile();
				echo '<center>Site settings updated!<br />';
                echo '<a href="index.php?act=settings">Click here to proceed.</a></center>';
            } elseif (empty($_POST['password'])){
                yasDB_update("UPDATE settings SET gperpage = ".intval($_POST['gperpage']).", numbgames = ".intval($_POST['numbgames']).", gamesort = '{$_POST['gamesort']}', approvelinks = '{$_POST['approvelinks']}', numblinks = ".intval($_POST['numblinks']).", seo = '{$_POST['seo']}' , lightbox = '{$_POST['lightbox']}', theme = '{$_POST['theme']}', skin = '{$_POST['skin']}', disabled = '{$_POST['disabled']}', email = '{$_POST['email']}', sitename = '".yasDB_clean($_POST['sitename'])."', slogan = '".yasDB_clean($_POST['slogan'])."', metades = '".yasDB_clean($_POST['metades'])."', metakeywords = '".yasDB_clean($_POST['metakeywords'])."',`userecaptcha` = '$captcha', `cachelife` = ".intval($_POST['pagecache'])."  where id = '1'");
                include("../includes/settings_function.inc.php");
				createConfigFile();
				echo '<center>La configuracion del sitio se ha actualizado correctamente!<br />';
                echo '<a href="index.php?act=settings"><span style="color:green;">Haga clic aqui para continuar.</span></a></center>';
            } else {
                echo '<center>Passwords did not match!<br />';
                echo '<a href="index.php?act=settings">Click here to proceed.</a></center>';
            }        
        }
    }
} else {
    $query = yasDB_select("SELECT * FROM settings");
    $row = $query->fetch_array(MYSQLI_ASSOC);
    $dir = $setting['sitepath'].'/templates/';
    $files = scandir($dir);
    ?>
 <div class="table">
                <img src="img/bg-th-left.gif" width="8" height="7" alt="" class="left" />
                <img src="img/bg-th-right.gif" width="7" height="7" alt="" class="right" />
                <table class="listing form" cellpadding="0" cellspacing="0">
                    <tr>
                    <th class="full" colspan="2">Configuracion general</th>
                    </tr>
                    <tr>
                    <td class="first" width="172"><strong>Version</strong></td>
                    <td class="last"><b><?php echo $setting['version'];?></b></td>
                    </tr>
                    <tr class="bg">
                    <td class="first"><strong>Enlaces no autorizados</strong></td>
                    <td class="last"><?php if ($links != 0) { echo '<font color="red">'.$links.'</font>';} else { echo '0'; } ?></td>
                    </tr>
                    <tr>
                    <td class="first"><strong>Comentarios</strong></td>
                    <td class="last"><?php echo $comments; ?></td>
                    </tr>
                    <tr class="bg">
                    <td class="first"><strong>Total de juegos</strong></td>
                    <td class="last"><?php echo $tgames; ?></td>
                    </tr>
                    <tr>
                    <td class="first"><strong>Total jugados</strong></td>
                    <td class="last"><?php echo $totalplays; ?></td>
                    </tr>
                    <tr class="bg">
                    <td class="first"><strong>Jugados hoy</strong></td>
                    <td class="last"><?php echo $todayplays; ?></td>
                    </tr>
                    <tr>
                    <td class="first"><strong>Miembros</strong></td>
                    <td class="last"><?php echo $user; ?></td>
                    </tr>
                    <form name="settings" method="post" action="index.php?act=settings">
                    <tr class="bg">                    
                    <td class="first"><strong>Plantillas</strong></td>
                    <td class="last">
                    <select name="theme" onchange="changeSkins('<?php echo $setting['sitepath'].'/templates/';?>' + this.options[this.selectedIndex].value + '<?php echo '/skins/';?>')">
                    <option value ="<?php echo $row['theme']; ?>" /><?php echo $row['theme']; ?></option>
                    <?php
					foreach ($files as &$file) {
						if ($file!='.' && $file!='..' && substr($file, -3) == '_24') { ?>
							<option value ="<?php echo $file;?>"><?php echo $file;?></option>
						<?php }
					}
					?>
					</select><br/>
                    </td>
                    </tr>
                    <tr>                    
                    <td class="first"><strong>Color de la plantilla</strong></td>
                    <td class="last"><?php
                    $dir = $setting['sitepath'].'/templates/';
					$files = scandir($setting['sitepath'].'/templates/'.$row['theme'].'/skins/');
					?><select name="skin" id="skin">
                    <option value ="<?php echo $row['skin']; ?>" /><?php echo $row['skin'];?></option>
                    <?php
					foreach ($files as &$file) {
						if ($file!='.' && $file!='..' )	{ ?>
							<option value ="<?php echo $file;?>"><?php echo $file;?></option>
						<?php }						
                    }
                    ?>
					</select><br/>
                    </td>
                    </tr>
					<tr class="bg">
                    <td class="first"><strong>Anti-Spam</strong></td>
                    <td class="last"><input type="checkbox" name="use" value="1" <?php if ($row['userecaptcha'] == "yes") echo ' checked="checked"';?>/>  Uso del sistema de captcha?<br /></td>
                    </tr>
					<tr>
						<td class="first"><strong>Paginas de vida del cache</strong></td>
						<td class="last"><input type="text" name="pagecache" value="<?php echo $row['cachelife'];?>" size="4" /> Segundos (300 = 5 minutos)<br /></td>
					</tr>
				</table>
          </div> 
           <div class="table">
                <img src="img/bg-th-left.gif" width="8" height="7" alt="" class="left" />
                <img src="img/bg-th-right.gif" width="7" height="7" alt="" class="right" />
                <table class="listing form" cellpadding="0" cellspacing="0">
                    <tr>
                    <th class="full" colspan="2">Configuracion del juego</th>
                    </tr>
                    <tr>
                    <td class="first" width="172"><strong>Jugabilidad de luz</strong></td>
                    <td class="last"><select name="lightbox">
                    <option value ="<?php echo $row['lightbox'];?>" selected><?php echo $row['lightbox'];?></option>
                    <option value ="yes">si</option>  
                    <option value ="no">no</option>
                    </select> Depende de la disponibilidad en la plantilla<br/></td>
                    </tr>
                    <tr class="bg">
                    <td class="first"><strong>Juegos por categoria</strong></td>
                    <td class="last"><input type="text" name="numbgames" value="<?php echo $row['numbgames'];?>" size="2" /><br /></td>
                    </tr>
                    <tr>
                    <td class="first"><strong>Juegos por clase</strong></td>
                    <td class="last"><select name="gamesort">
                    <option value ="<?php echo $row['gamesort'];?>" /><?php echo $row['gamesort'];?></option>
                    <option value ="popular">Popular</option>
                    <option value ="Mas reciente">Mas reciente</option>
                    <option value ="Al azar">Al azar</option>
                    </select></td>
                    </tr>
                    <tr class="bg">
                    <td class="first"><strong>Juegos por pagina</strong></td>
                    <td class="last"><input type="text" name="gperpage" value="<?php echo $row['gperpage'];?>" size="2" /> (Tambien para las paginas de las categorias)</td>
                    </tr>
                </table>
          </div>
          <div class="table">
                <img src="img/bg-th-left.gif" width="8" height="7" alt="" class="left" />
                <img src="img/bg-th-right.gif" width="7" height="7" alt="" class="right" />
                <table class="listing form" cellpadding="0" cellspacing="0">
                    <tr>
                    <th class="full" colspan="2">Otros</th>
                    </tr>
                    <tr>
                    <td class="first" width="172"><strong>Desactivar el sitio</strong></td>
                    <td class="last"><select name="disabled">
                    <option value ="<?php echo $row['disabled'];?>" /><?php echo $row['disabled'];?></option>
                    <option value ="yes">si</option>  
                    <option value ="no">no</option>
                    </select></td>
                    </tr>
                    <tr class="bg">
                    <td class="first"><strong>Intercambio de enlaces automatico</strong></td>
                    <td class="last"><select name="approvelinks">
                    <option value ="<?php echo $row['approvelinks'];?>" /><?php echo $row['approvelinks'];?></option>
                    <option value ="yes">si</option>
                    <option value ="no">no</option>
                    </select></td>
                    </tr>
                    <tr class="bg">
                    <td class="first"><strong>Intercambio de enlaces en la pagina principal</strong></td>
                    <td class="last"><input type="text" name="numblinks" value="<?php echo $row['numblinks'];?>" size="2" /><br /></td>
                    </tr>
					<tr>
                    <td class="first"><strong>URLs y SEO amistoso</strong></td>
                    <td class="last"><select name="seo">
                    <option value ="<?php echo $row['seo'];?>" /><?php echo $row['seo'];?></option>
                    <option value ="yes">si</option>
                    <option value ="no">no</option>
                    </select></td>
                    </tr>
                    </table>
                </div>
                <div class="table">
                <img src="img/bg-th-left.gif" width="8" height="7" alt="" class="left" />
                <img src="img/bg-th-right.gif" width="7" height="7" alt="" class="right" />
                <table class="listing form" cellpadding="0" cellspacing="0">
                    <tr>
                    <th class="full" colspan="2">Actualizar</th>
                    </tr>
                    <tr>
                    <td class="first" width="172"><strong>Email</strong></td>
                    <td class="last"><input type="text" name="email" value="<?php echo $row['email'];?>" size="28"/></td>
                    </tr>
                    <tr>
                    <td class="first" width="172"><strong>Nombre del sitio</strong></td>
                    <td class="last"><input type="text" name="sitename" value="<?php echo $row['sitename'];?>" size="28"/></td>
                    </tr>
					<tr>
                    <td class="first" width="172"><strong>Slogan</strong></td>
                    <td class="last"><input type="text" name="slogan" value="<?php echo $row['slogan'];?>" size="28"/></td>
                    </tr>
					<tr>
                    <td class="first" width="172"><strong>Descripcion del meta (Visto en los motores de busqueda)</strong></td>
                    <td class="last"><input type="text" name="metades" value="<?php echo $row['metades'];?>" size="28"/></td>
                    </tr>
					<tr>
                    <td class="first" width="172"><strong>Palabras claves del meta</strong></td>
                    <td class="last"><input type="text" name="metakeywords" value="<?php echo $row['metakeywords'];?>" size="28"/></td>
                    </tr>
					<tr class="bg">
                    <td class="first"><strong>Contraseņa de administrador</strong></td>
                    <td class="last"><input type="text" name="password" /> Nueva contraseņa</td>
                    </tr>
                    <tr>
                    <td class="first"><strong>Repita la contraseņa</strong></td>
                    <td class="last"><input type="text" name="passwordcheck" /> Vuelva a entrar la contraseņa</td>
                    </tr>
                    <tr class="bg">
                    <td class="first"><strong>Configuracion de la Actualizacion</strong></td>
                    <td class="last"><input type="submit" class="button" name="settings" value="Guardar la configuracion" /></td>
                    </tr>
                    </form>
                </table>                
          </div>         
<?php
}
?>
</div>