<?php
//Conectamos a DB
//Caracter aleatorio
function RandomString($length=10,$uc=TRUE,$n=TRUE,$sc=FALSE){
$source = 'abcdefghijklmnopqrstuvwxyz';
if($uc==1) $source .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
if($n==1) $source .= '1234567890';
if($sc==1) $source .= '|@#~$%()=^*+[]{}-_';
if($length>0){
$rstr = "";
for($i=1; $i<=$length; $i++){
$rstr .= $source[$num-1];
}
}
return $rstr;
}
// Cerramos sesiones
if(isset($_GET['exit'])){ header ("location: ".$_SERVER['PHP_SELF'].""); }//If isset Cerrar Session
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="includes/SpryAssets/SpryTabbedPanels.js" type="text/javascript"></script>
<link href="includes/SpryAssets/SpryTabbedPanels.css" rel="stylesheet" type="text/css" />
<style>
#content {
position:relative;
margin:auto auto;
text-align:center;
}
.border {
border:3px solid #000000;
}
.text {
font-weight:bold;
text-align:center;
}
</style>
</head>
<?php
###################################
# Pagina para Admin logeado
###################################
if (isset($_SESSION['username'])){ ?>
<div align="right"><a href="index.php?exit">Cerrar sesión</a></div>
<div id="TabbedPanels1" class="TabbedPanels">
<ul class="TabbedPanelsTabGroup">
<li class="TabbedPanelsTab" tabindex="0"><a href="index.php?general">General</a></li>
<li class="TabbedPanelsTab" tabindex="0">Usuarios</li>
<li class="TabbedPanelsTab" tabindex="0">Fotos</li>
<li class="TabbedPanelsTab" tabindex="0">Videos</li>
<li class="TabbedPanelsTab" tabindex="0">Cartas</li>
<li class="TabbedPanelsTab" tabindex="0">Email</li>
</ul>
<div class="TabbedPanelsContentGroup">
<div class="TabbedPanelsContent">
<?php
if(isset($_GET['general'])){
if(isset($_POST['edit_site'])){ //Verificar campos vacios
if(empty($_POST['title'])){ echo "*Debe seleccionar un titulo"; } elseif(empty($_POST['theme'])) { echo "Debe seleccionar un thema"; } elseif(empty($_POST['language'])) { echo "Debe seleccionar un lenguage"; } else {
$title = $_POST['title'];
$theme = $_POST['theme'];
$language = $_POST['language'];
$sql = "UPDATE site SET title = '$title', theme = '$theme', language ='$language' WHERE id ='1'";
if(!$res) { echo "No se ha podido guardar"; } else { echo "Se ha guardado"; }
}//Fin else campos vacios
}// If isset $_POST[edit_save]
if(isset($_POST['add_theme'])){ //Definimo variables
$tmp_name = $_POST['tmp_name'];
$tmp_alt_name = $_POST['tmp_alt_name'];
$temp = $_FILES['tmp_file']['tmp_name'];
$ruta = "D:/_root/AppServ/www/scripts/001/themes/".$tmp_alt_name.".zip";
$direction = "http://localhost/scripts/001/themes/".$tmp_alt_name;
//Verificar campos vacios
if(empty($_POST['tmp_name'])){ echo "Debe ponerle un nombre a su tema"; } elseif(empty($_POST['tmp_alt_name'])) { echo "El sistema no puede completar su solicitud"; } elseif(empty($_FILES['tmp_file']['name'])) { echo "Debe subir un archivo"; } else {
if($_FILES['tmp_file']['type'] == "application/zip"){
// Iniciamos sesion FTP
include('includes/login_ftp.php');
//Subimos archivo
$ifcopy = copy($temp, $ruta);
// Cerramos coneccion FTP
}
//Comprobamos si se subio el archivo
if(!$ifcopy){ echo "No se ha subido el archivo, ERROR DEL SERVIDOR"; }
// Descomprimimos el arcivo
include('includes/dUnzip2.inc.php');
include('includes/dZip.inc.php');
$zip = new dUnzip2('../themes/'.$tmp_alt_name.'.zip');
$zip->debug = false;
$zip->unzipAll('../themes/'.$tmp_alt_name.'');
if($zip) {
//Borramos carpeta ZIP
chdir('D:/_root/AppServ/www/scripts/001/themes/');
} else { echo "No se ha descomprimido"; }
// Insertamos en DB
$sql = "INSERT INTO themes (name,name_alt,ruta,date,dir) VALUES ('$tmp_name','$tmp_alt_name','$direction',NOW(),'$ruta')";
//Comprobamos si se ha insertado
if(!$res){ echo "NO SE HA INSERTADO"; }
//Seleccionamos de DB
$sql = "SELECT * FROM themes WHERE name_alt = '".$_POST['tmp_alt_name']."'";
}//Fin if($_FILES['tmp_file']['type'] == "application/zip")
else { echo "El archivo no es admitido"; }
}// Fin else campos vacios
}//If isset $_POST[add_theme]
$sql = "SELECT * FROM site";
echo "<h2>Configuracion del sitio</h2>";
echo "<form action='' method='post'>";
echo "<table>";
echo "<tr>";
echo "<td>Titulo: </td>";
echo "<td><input type='text' name='title' value='".$row['title']."'></td>";
echo "</tr><tr>";
echo "<td>Plantilla por defecto: </td>";
echo "<td><input type='text' name='theme' value='".$row['theme']."'></td>";
echo "</tr><tr>";
echo "<td>Lenguaje por defecto: </td>";
echo "<td><input type='text' name='language' value='".$row['language']."'></td>";
echo "</tr><tr>";
echo "<td collspan='2'><input type='submit' name='edit_site' value='Editar'></td>";
echo "</tr></table></form>";
echo "<hr>";
echo "<h2>Instalar plantillas</h2>";
echo "<form action='' method='post' enctype='multipart/form-data'>";
echo "<input type='hidden' name='tmp_alt_name' value='".RandomString(5,TRUE,TRUE,FALSE)."' />";
echo "<table width='512'><tr>";
echo "<td>Nombre: </td>";
echo "<td><input type='text' name='tmp_name' /></td>";
echo "</tr><tr>";
echo "<td>Archivo ZIP:</td>";
echo "<td><input type='file' name='tmp_file'/></td>";
echo "</tr><tr>";
echo "<td colspan='2'><input type='submit' name='add_theme' value='Enviar' /></td>";
echo "</tr></table></form>";
}
?>
</div>
<div class="TabbedPanelsContent">Contenido 2</div>
<div class="TabbedPanelsContent">Contenido 3</div>
<div class="TabbedPanelsContent">Contenido 4</div>
<div class="TabbedPanelsContent">Contenido 5</div>
<div class="TabbedPanelsContent">Contenido 6</div>
</div>
</div>
<script type="text/javascript">
<!--
var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1");
//-->
</script>
<?php
}// fin del if isset $_SESSION[username]
else { include('login.php');
?>
<div align="center">
<form action="" method="post">
<table cellpadding="5" cellspacing="5" class="border">
<tr>
<td colspan="2">
<h1>Admin Control Panel</h1>
<?php
echo "<span class='text'>";
echo $empty_username;
echo $empty_password;
echo $error_login;
echo "</span>";
} else {
echo "<meta http-equiv=\"Refresh\" content=\"0\" />"; }
?>
</td>
</tr>
<tr>
<td>Nombre: </td>
<td><input type="text" name="username"/></td>
</tr>
<tr>
<td>Password: </td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="submit_login" value="Entrar" /></td>
</tr>
</table>
</form>
</div>
<?php
}
?>