Location: PHPKode > projects > Digital Media Courseware > template/admin/persona.php
<?php 

require_once( DMCROOT . 'lib/class/DMC.php');
require_once( DMCROOT . 'lib/class/Sesion.php');
require_once( DMCROOT . 'lib/class/Persona.php');
require_once( DMCROOT . 'lib/class/Course.php');

$DMC = new DMC();
$Sesion = new Sesion();
$Persona = new Persona();
$Course = new Course();

if (!$Sesion->validateCurso($cursos_id,1)) {
	$Sesion->logout();
	header ("Location: index.php");
}

$DMC->setPage('be_persona');

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if (!isset($_GET['cursos_id']) || !isset($_GET['accion'])) header ("Location: index.php");

$valid = 1;

// manejo del post para crear/modificar/eliminar

if ((isset($_POST["DM_post"])) && ($_POST["DM_post"] == "frm_persona")) {
	if ($_POST['accion'] == 1) {
		// accion crear
		// primero debemos validar que el usuario no exista
		$valid = $Persona->isValidUser($_POST['usuario'],$_POST['cursos_id']);
		if ($valid) {
			$e = $Persona->insertPerson($_POST['nombre'],$_POST['apellido'],$_POST['texto'],$_POST['foto'],$_POST['usuario'],$_POST['clave'],$_POST['cursos_id'],$_POST['email'],$_POST['url'],$_POST['tipo'],$_POST['path']);
			$Persona->personFolder($e, $_POST['path']);
			if ($_FILES['tempfoto']['name'] != '') $_POST['foto'] = $Persona->updatePersonPhoto('tempfoto',$_POST['path'],$e,false,true);
		}
	} elseif ($_POST['accion'] == 2) {
		// accion modificar
		$valid = $Persona->isValidUser($_POST['usuario'],$_POST['cursos_id'],$_POST['id']);
		if ($valid) {
			if ($_POST['borrarfoto'] == 'si') {
				$_POST['foto'] = $Persona->updatePersonPhoto(false,$_POST['path'],$_POST['id'],$_POST['foto']);
			} else {
				if ($_FILES['tempfoto']['name'] != '') $_POST['foto'] = $Persona->updatePersonPhoto('tempfoto',$_POST['path'],$_POST['id'],$_POST['foto']);
			}
			if ($_POST['clave'] != $_POST['clave_old']) $_POST['clave'] = md5($_POST['clave']);
			$e = $Persona->updatePerson($_POST['nombre'],$_POST['apellido'],$_POST['texto'],$_POST['foto'],$_POST['usuario'],$_POST['clave'],$_POST['cursos_id'],$_POST['email'],$_POST['url'],$_POST['tipo'], $_POST['id']);
		}
	} elseif ($_POST['accion'] == 3) {
		// accion borrar
		$e = $Persona->deletePerson($_POST['id']);
	}
	// nos largamos de acá
	if ($e) header ("Location: curso.php?id=".$_POST['cursos_id']."&accion=2");
}

$path = $Course->coursePath($_GET['cursos_id']);

// si es accion == 2 sacamos la info del curso y de los ejercicios

if ($_GET['accion'] == 2 && $_GET['id']) {
	$q = $Persona->personDetail($_GET['id']);
	if (count($q) > 0) {
		foreach ($q as $key => $value) {
			$GLOBALS[$key] = $value;
		}
	}
}

?>

<!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><?php echo $DMC->lang_data['base']['nombre'] ?>: <?php echo $DMC->m('encabezado') ?></title>
<link href="../../../css/admin.css" rel="stylesheet" type="text/css" />
<script src="../../../js/validador.php" type="text/javascript" language="JavaScript"></script>
</head>

<body>
<h1><?php echo $DMC->m('encabezado') ?>: <?php if ($_GET['accion'] == 1) { echo $DMC->m('titulo_crear'); } else { echo $DMC->m('titulo_modificar'); } ?></h1>
<p>&laquo; <a href="curso.php?id=<?php echo $cursos_id ?>&amp;accion=2"><?php echo $DMC->m('ln_volver') ?></a> &laquo; <a href="logout.php"><?php echo $DMC->m('ln_salir') ?></a></p>
<?php
if (!$q && $_GET['accion'] == 2) {
?>
<p><?php echo $DMC->m('err_no_persona') ?></p>
<?php
} else {
?>
<?php
	if ($_GET['accion'] == 2) {
?>
<form action="<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data" name="frm_delete" onsubmit="return validar('frm_delete','boton');">
	<table>
    	<tr>
    		<td><input type="submit" name="boton" value="<?php echo $DMC->m('frm_boton_borrar') ?>" class="boton" /></td>
    		<td>
				<input type="checkbox" name="confirma" id="confirma" value="si" />
    			<label for="confirma"><?php echo $DMC->m('frm_borrar_confirmar') ?></label><br />
			</td>
   		</tr>
    	</table>
	<input type="hidden" name="id" value="<?php echo $id ?>" />
	<input type="hidden" name="accion" value="3" />
	<input type="hidden" name="path" value="<?php echo $path ?>" />
	<input type="hidden" name="DM_post" value="frm_persona" />
	<input type="hidden" name="__campos__" value="confirma" />
	<input type="hidden" name="__nombres__" value="<?php echo $DMC->m('js_borrar') ?>" />
	<input type="hidden" name="__tipos__" value="accept" />
</form>
<?php
	}	
?>
<form action="<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data" name="frm_persona" onsubmit="return validar('frm_persona','boton')">
	<table>
		<tr valign="baseline">
			<th align="right" nowrap="nowrap" class="req"><?php echo $DMC->m('frm_nombre') ?>:</th>
			<td><input type="text" name="nombre" value="<?php echo $nombre ?>" size="32" /></td>
		</tr>
		<tr valign="baseline">
			<th align="right" nowrap="nowrap" class="req"><?php echo $DMC->m('frm_apellido') ?>:</th>
			<td><input type="text" name="apellido" value="<?php echo $apellido ?>" size="32" /></td>
		</tr>
		<tr valign="baseline">
			<th nowrap="nowrap" align="right" valign="top"><?php echo $DMC->m('frm_texto') ?>:</th>
			<td><textarea name="texto" cols="32" rows="5"><?php echo htmlentities($texto,ENT_QUOTES,'UTF-8') ?></textarea>
			</td>
		</tr>
		<tr valign="baseline">
			<th align="right" valign="top" nowrap="nowrap"><?php echo $DMC->m('frm_foto') ?>:</th>
			<td>
<?php 
	if ($_GET['accion'] == 2 && $foto != "") {
?>
				<img src="<?php echo $DMC->app['DMC_url'] . $DMC->app['DMC_course_folder'] . '/' . $path . '/files/person' . $id . '/' . $foto ?>" /><br />
				<input type="checkbox" name="borrarfoto" id="borrarfoto" value="si" />
				<label for="borrarfoto"><?php echo $DMC->m('frm_borrar_foto') ?></label><br />
<?php 
	}
?>
				<input type="hidden" name="foto" value="<?php echo $foto ?>" />
				<input type="file" name="tempfoto" size="20" />
			</td>
		</tr>
		<tr valign="baseline">
			<th nowrap="nowrap" align="right" class="req"><?php echo $DMC->m('frm_usuario') ?>:</th>
			<td><input type="text" name="usuario" value="<?php echo $usuario ?>" size="20" />
			<?php if (!$valid) { ?> <span class="nota"><?php echo $DMC->m('err_usuario') ?></span><?php } ?></td>
		</tr>
		<tr valign="baseline">
			<th nowrap="nowrap" align="right" class="req"><?php echo $DMC->m('frm_clave') ?>:</th>
			<td><input type="password" name="clave" value="<?php echo $clave ?>" size="10" />
			<input type="hidden" name="clave_old" value="<?php echo $clave ?>" /></td>
		</tr>
		<tr valign="baseline">
			<th nowrap="nowrap" align="right" class="req"><?php echo $DMC->m('frm_confirma_clave') ?>:</th>
			<td><input type="password" name="clave2" value="<?php echo $clave ?>" size="10" /></td>
		</tr>
		<tr valign="baseline">
			<th nowrap="nowrap" align="right"><?php echo $DMC->m('frm_email') ?>:</th>
			<td><input type="text" name="email" value="<?php echo $email ?>" size="32" /></td>
		</tr>
		<tr valign="baseline">
			<th nowrap="nowrap" align="right"><?php echo $DMC->m('frm_url') ?>:</th>
			<td><input type="text" name="url" value="<?php echo $url ?>" size="32" /></td>
		</tr>
		<tr valign="baseline">
			<th nowrap="nowrap" align="right"><?php echo $DMC->m('frm_tipo') ?>:</th>
			<td>
			<select name="tipo">
					<option value="0" <?php if ($tipo==0) { ?>selected="selected"<?php } ?>><?php echo $DMC->m('frm_tipo_alumno') ?></option>
					<option value="1" <?php if ($tipo==1) { ?>selected="selected"<?php } ?>><?php echo $DMC->m('frm_tipo_profesor') ?></option>
					<option value="2" <?php if ($tipo==2) { ?>selected="selected"<?php } ?>><?php echo $DMC->m('frm_tipo_asistente') ?></option>
			</select>
			</td>
		</tr>
		<tr valign="baseline">
			<td nowrap="nowrap" align="right">&nbsp;</td>
			<td>&nbsp;</td>
		</tr>
		<tr valign="baseline">
			<td nowrap="nowrap" align="right">&nbsp;</td>
			<td><input type="submit" value="<?php if ($_GET['accion']==1) { echo $DMC->m('frm_boton_crear'); } else { echo $DMC->m('frm_boton_modificar'); } ?>" name="boton" class="boton" /></td>
		</tr>
	</table>
<?php
	if ($id) {
?>
	<input type="hidden" name="id" value="<?php echo $id ?>" />
<?php
	}
?>
	<input type="hidden" name="accion" value="<?php if ($_POST['accion']) { echo $_POST['accion']; } elseif ($_GET['accion']) { echo $_GET['accion']; } else { echo $accion; } ?>" />
	<input type="hidden" name="path" value="<?php echo $path ?>" />
	<input type="hidden" name="cursos_id" value="<?php echo $cursos_id ?>" />
	<input type="hidden" name="DM_post" value="frm_persona" />
	<input type="hidden" name="__campos__" value="nombre,apellido,usuario,clave" />
	<input type="hidden" name="__nombres__" value="<?php echo $DMC->m('js_nombre') ?>,<?php echo $DMC->m('js_apellido') ?>,<?php echo $DMC->m('js_usuario') ?>,<?php echo $DMC->m('js_clave') ?>" />
	<input type="hidden" name="__tipos__" value="texto,texto,texto,clave" />
</form>
<?php 
}
?>
</body>
</html>
Return current item: Digital Media Courseware