250 lines
		
	
	
		
			7.9 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			250 lines
		
	
	
		
			7.9 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?
 | 
						||
if ( $user_auth && $user_level <= -1 )
 | 
						||
{
 | 
						||
 $blq1 ="parent,titulo,descr";
 | 
						||
 | 
						||
 $list = true;
 | 
						||
 | 
						||
 if ( isset( $sins ) )
 | 
						||
 {
 | 
						||
	displayForm( "./?dgo=adm/estilos.php&ins=new" );
 | 
						||
	$list = false;
 | 
						||
 }
 | 
						||
 if ( isset( $smod ) ) 
 | 
						||
 {	
 | 
						||
	$res = @mysql_query( "SELECT id,$blq1  FROM estilos WHERE id=$smod", $conexion );
 | 
						||
	$datos = @mysql_fetch_array( $res );
 | 
						||
 | 
						||
	list( $db_id, $db_parent,$db_titulo,$db_descr ) = $datos;
 | 
						||
 | 
						||
	displayForm( "./?dgo=adm/estilos.php&mod=$smod" );
 | 
						||
	$list = false;
 | 
						||
 }
 | 
						||
 if ( isset( $mod ) )
 | 
						||
 {
 | 
						||
	if ( !empty($imgData_name) && $imgData_size > 0 )
 | 
						||
		  {
 | 
						||
			$img_prop = GetImageSize($imgData);
 | 
						||
			$db_Foto_w = $img_prop[0];
 | 
						||
			$db_Foto_h = $img_prop[1];
 | 
						||
			$addsql_p1 = ",Foto_mime='$imgData_type', Foto_w='$db_Foto_w', Foto_h='$db_Foto_h'";
 | 
						||
		  }		
 | 
						||
	$sql = "UPDATE estilos SET ".
 | 
						||
		"parent='$db_parent' ".
 | 
						||
		",titulo='$db_titulo' ".
 | 
						||
		",descr='".urlencode($db_descr)."' $addsql_p1".
 | 
						||
		" WHERE id=$mod";
 | 
						||
	$res = @mysql_query( $sql, $conexion );
 | 
						||
	$last_id = $mod;
 | 
						||
	echo "Algunos datos:<br>";
 | 
						||
	
 | 
						||
	if ( !empty($imgData_name) && $imgData_size > 0 )
 | 
						||
	{
 | 
						||
		$file_size = filesize($imgData);
 | 
						||
 | 
						||
		fwrite( fopen("db/estilos/".$last_id."_i001", "wb"),
 | 
						||
			fread(fopen($imgData,"rb"),$file_size), $file_size);
 | 
						||
 | 
						||
		
 | 
						||
	}
 | 
						||
	$list = true;
 | 
						||
 }
 | 
						||
 if( isset( $ins ) )
 | 
						||
 {
 | 
						||
	if ( !empty($imgData_name) && $imgData_size > 0 )
 | 
						||
		  {
 | 
						||
			$img_prop = GetImageSize($imgData);
 | 
						||
			$db_Foto_w = $img_prop[0];
 | 
						||
			$db_Foto_h = $img_prop[1];
 | 
						||
			$addsql_p1 = ",Foto_mime, Foto_w, Foto_h";
 | 
						||
			$addsql_p2 = ",'$imgData_type', '$db_Foto_w', '$db_Foto_h'";
 | 
						||
		  }		
 | 
						||
 | 
						||
	$sql = "INSERT INTO estilos ($blq1 $addsql_p1) VALUES ('$db_parent','$db_titulo','$db_descr' $addsql_p2)";
 | 
						||
	$res = @mysql_query( $sql, $conexion ) OR die( "Error<br>".@mysql_error($conexion) );
 | 
						||
	$last_id = @mysql_insert_id($conexion);
 | 
						||
 | 
						||
	if ( !empty($imgData_name) && $imgData_size > 0 )
 | 
						||
	{
 | 
						||
		$file_size = filesize($imgData);
 | 
						||
		fwrite( fopen("db/estilos/".$last_id."_i001", "wb"),
 | 
						||
			fread(fopen($imgData,"rb"),$file_size), $file_size);
 | 
						||
		
 | 
						||
	}
 | 
						||
        echo "<h1>Estilo insertado</h1><br><br><br>";
 | 
						||
        echo "<p class=remark>ID asignado = ".$last_id."</p>";
 | 
						||
	$list = true;
 | 
						||
 }
 | 
						||
 if( isset( $del ) )
 | 
						||
 {
 | 
						||
	if ( !unlink( "estilos/".$del."_i001" ) )
 | 
						||
		echo "<h1>No he podido eliminar la imagen asociada:</h1><br><p class=remark>Borre el fichero: estilos/$del"."_i001 manualmente por favor...<br>";
 | 
						||
	else
 | 
						||
		echo "<li>Ficheros asociados eliminados</li>";
 | 
						||
 | 
						||
	$res = @mysql_query( "UPDATE estilos SET parent='0' WHERE parent=$del", $conexion );
 | 
						||
	echo "<li>Estilos heredados, descompuestos</li>";
 | 
						||
	$res = @mysql_query( "DELETE FROM estilos WHERE id=$del", $conexion );
 | 
						||
	echo "<li>Estilo $del, ELIMINADO</li><br>";
 | 
						||
	$list = true;
 | 
						||
 }
 | 
						||
 | 
						||
 if ( isset( $list ) && $list )
 | 
						||
 {
 | 
						||
   if ( !isset($orderBy) ) $orderBy ="id";
 | 
						||
   if ( !isset($orderDir) ) $orderDir ="ASC";
 | 
						||
 | 
						||
   echo "Listado de Estilos >> Ver listado<br><br>";
 | 
						||
   displayList($conexion, $orderBy, $orderDir);
 | 
						||
 }
 | 
						||
 displayMenu();
 | 
						||
}
 | 
						||
 | 
						||
function cambiaProporciones()
 | 
						||
{
 | 
						||
 global $db_Foto_w, $db_Foto_h;
 | 
						||
 $W = 150; $H=150; 
 | 
						||
 | 
						||
 // Las proporciones correctas seran de 100x100
 | 
						||
// $db_Foto_w=50;
 | 
						||
// $db_Foto_h=50;
 | 
						||
 | 
						||
 if ( $db_Foto_w > 0 )
 | 
						||
 {
 | 
						||
  if ( $db_Foto_w > $db_Foto_h )
 | 
						||
  {
 | 
						||
	  $db_Foto_h = intval(($db_Foto_h/$db_Foto_w)*$W); $db_Foto_w=$W;
 | 
						||
  } else {
 | 
						||
	  $db_Foto_w = intval(($db_Foto_w/$db_Foto_h)*$H); $db_Foto_h=$H;
 | 
						||
  }
 | 
						||
 }
 | 
						||
 | 
						||
}
 | 
						||
 | 
						||
function displayList($cnx, $orderBy, $orderDir)
 | 
						||
{
 | 
						||
 global $db_Foto_w, $db_Foto_h;
 | 
						||
 | 
						||
 $thisLOCATION = "./?dgo=adm/estilos.php";
 | 
						||
 $res = @mysql_query( "SELECT e.id, ep.titulo, e.titulo, e.descr, e.Foto_mime, e.Foto_w, e.Foto_h FROM estilos AS e LEFT JOIN estilos AS ep ON (ep.id=e.parent) ORDER BY e.$orderBy $orderDir", $cnx ) OR die( "Error<br>".@mysql_error($conexion) );;
 | 
						||
 | 
						||
 $parity = true;
 | 
						||
 | 
						||
 while( $datos=@mysql_fetch_array($res) )
 | 
						||
 {
 | 
						||
  list ( $db_id, $db_ptitulo, $db_titulo, $db_descr, $db_Foto_mime, $db_Foto_w, $db_Foto_h )= $datos;
 | 
						||
  $parity = !$parity;
 | 
						||
 | 
						||
  cambiaProporciones(/* $db_Foto_w, $db_Foto_h*/);
 | 
						||
  $lBlq1 = "<img src=\"gimage.php?db=estilos&db_id=$db_id&db_mime=$db_Foto_mime\" width=\"$db_Foto_w\" height=\"$db_Foto_h\"><br>$db_titulo"; 
 | 
						||
  $lBlq2 = "<p><a href=\"javascript:deleteUser($db_id)\" class=lmenuo>>> >Eliminar Estilo</a> ## "
 | 
						||
          ."<a href=\"$thisLOCATION&smod=$db_id\" class=lmenuo>>> >Modificar Estilo</a><br></p>";
 | 
						||
  if ( $parity )
 | 
						||
	  echo "<table class=td_estilos><tr><td>$lBlq1</td><td>".urldecode($db_descr)."$lBlq2</td></tr></table><br><br>";
 | 
						||
  else
 | 
						||
	  echo "<table class=td_estilos><tr><td>".urldecode($db_descr)."$lBlq2</td><td>$lBlq1</td></tr></table><br><br>";
 | 
						||
 }
 | 
						||
 | 
						||
 echo '<script language="JavaScript"> 
 | 
						||
	function deleteUser( which )
 | 
						||
	{
 | 
						||
	  var submitOK = confirm("Atencion: Esta a punto de eliminar el estilo.");
 | 
						||
	  if ( submitOK )
 | 
						||
		  document.location.href = "'.$thisLOCATION.'&orderBy='.$orderBy.'&orderDir='.$orderDir.'&del="+which;
 | 
						||
	}
 | 
						||
	</script>';
 | 
						||
}
 | 
						||
 | 
						||
function displayMenu()
 | 
						||
{
 | 
						||
 echo '<hr noshade color="#800000">';
 | 
						||
 echo '<p align="center"><a href="./?dgo=adm/estilos.php&sins=new">Insertar nuevo estilo</a></p>';
 | 
						||
 echo '<hr noshade color="#800000">';
 | 
						||
}
 | 
						||
 | 
						||
function displayForm( $form_action )
 | 
						||
{
 | 
						||
 global $db_parent, $db_titulo, $db_descr, $imgData;
 | 
						||
 | 
						||
 echo '<form action="'.$form_action.'" method="POST" name="register"  enctype="multipart/form-data" onsubmit="return validateform( this.form )">';
 | 
						||
 echo '<p align="center"> </p><div align="center"><center><table border="0" cellpadding="0" cellspacing="0" width="100%">';
 | 
						||
 echo '<tr>
 | 
						||
            <td><h1>Datos del estilo</h1>
 | 
						||
            <p> </p>
 | 
						||
            <table border="0" cellpadding="0" cellspacing="0"
 | 
						||
            width="100%" bgcolor="#800000">
 | 
						||
                <tr>
 | 
						||
                    <td> </td>
 | 
						||
                </tr>
 | 
						||
            </table>
 | 
						||
            <table border="0" width="100%">
 | 
						||
                <tr>
 | 
						||
                    <td width="30%">Titulo:</td>
 | 
						||
                    <td width="20%"><input type="text" size="15"
 | 
						||
                    name="db_titulo"
 | 
						||
                    value="'.$db_titulo.'"></td>
 | 
						||
                    <td valign="top" rowspan="3" width="50%"
 | 
						||
                    bgcolor="#B4CCE9" class="tdSuave"><strong>Informaci<63>n
 | 
						||
                    del estilo</strong><p>Aqui van el titulo y descripci<63>n del estilo que esta definiendo. <br>
 | 
						||
Tambien puede agregar una imagen que represente este estilo. Recuerde que deberia ser JPG con un tama<6D>o de 50x50 m<>ximo.</p>
 | 
						||
                    <p>ATENCION: <20><> Se admiten controles HTML
 | 
						||
                    !!, por lo que aconsejamos sea muy cuidadoso
 | 
						||
                    con los mismos.</p>
 | 
						||
                    </td>
 | 
						||
                </tr>
 | 
						||
                <tr>
 | 
						||
                    <td width="30%">Padre:</td>
 | 
						||
                    <td width="20%"><select name="db_parent" size="1">
 | 
						||
			<option value="0">ninguno</option>';
 | 
						||
 | 
						||
		 global $conexion;
 | 
						||
		 $resp = @mysql_query( "SELECT id, titulo FROM estilos WHERE parent ='0' Order By titulo", $conexion );
 | 
						||
		 while( $datos=@mysql_fetch_array($resp) )
 | 
						||
		 {
 | 
						||
			list ( $epid, $eptit ) = $datos;
 | 
						||
			echo "<option value=\"$epid\">$eptit</option>";
 | 
						||
		 }
 | 
						||
echo '</select></td>
 | 
						||
                </tr>
 | 
						||
                <tr>
 | 
						||
                    <td colspan="2" width="30%">Comentarios
 | 
						||
                    adicionales:<p><textarea name="db_descr" rows="5"
 | 
						||
                    cols="20">'.urldecode($db_descr).'</textarea></p>
 | 
						||
                    </td>
 | 
						||
                </tr>
 | 
						||
                <tr>
 | 
						||
                    <td width="30%"> Imagen:</td>
 | 
						||
                    <td width="20%" colspan="2">
 | 
						||
			<input type="file" size="15" name="imgData"></td>
 | 
						||
                </tr>            </table>
 | 
						||
 | 
						||
            <hr noshade color="#800000">
 | 
						||
            <p align="center"><input type="button" name="btCancelar" value="Cancelar"><input
 | 
						||
            type="submit" name="B2" value="Enviar >>"></p>
 | 
						||
 | 
						||
            <p><script language="JavaScript"><!--
 | 
						||
 | 
						||
function validateform(wf)
 | 
						||
{
 | 
						||
 | 
						||
if (document.register.db_titulo.value=="")
 | 
						||
{
 | 
						||
	window.alert ("Por favor, introduce el titulo")
 | 
						||
	return false;
 | 
						||
}
 | 
						||
if (document.register.db_descr.value=="")
 | 
						||
{
 | 
						||
	window.alert ("Por favor, introduce la descripcion")
 | 
						||
	return false;
 | 
						||
}
 | 
						||
}
 | 
						||
// --></script><br>
 | 
						||
            </p>
 | 
						||
            </td>
 | 
						||
        </tr>
 | 
						||
    </table>
 | 
						||
    </center></div>
 | 
						||
</form>';
 | 
						||
}
 | 
						||
?>
 |