<?php
require_once( DMCROOT . 'lib/class/DMC.php');
require_once( DMCROOT . 'lib/class/Sesion.php');
require_once( DMCROOT . 'lib/class/Course.php');
require_once( DMCROOT . 'lib/class/Ejercicio.php');
$DMC = new DMC();
$Sesion = new Sesion();
$Course = new Course();
$Ejercicio = new Ejercicio();
if (!$Sesion->validateCurso($cursos_id,1)) {
$Sesion->logout();
header ("Location: index.php");
}
$DMC->setPage('be_ejercicio');
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if (!isset($cursos_id) || !isset($_GET['accion'])) header ("Location: index.php");
// manejo del post para crear/modificar/eliminar
if ((isset($_POST["DM_post"])) && ($_POST["DM_post"] == "frm_ejercicio")) {
if ($_POST['accion'] == 1) {
// accion crear
if ($_FILES['tempfoto']['name'] != '') $_POST['foto'] = $Ejercicio->updateExcercisePhoto('tempfoto',$_POST['path']);
if ($_FILES['temparchivo']['name'] != '') $_POST['archivo'] = $Ejercicio->updateExcercisePhoto('temparchivo',$_POST['path']);
$e = $Ejercicio->insertExcercise($_POST['titulo'], $_POST['breve'], $_POST['texto'], $_POST['foto'], $_POST['vigencia'], $_POST['archivo'], $_POST['cursos_id']);
} elseif ($_POST['accion'] == 2) {
// accion modificar
if ($_POST['borrarfoto'] == 'si') {
$_POST['foto'] = $Ejercicio->updateExcercisePhoto(false,$_POST['path'],$_POST['foto']);
} else {
if ($_FILES['tempfoto']['name'] != '') $_POST['foto'] = $Ejercicio->updateExcercisePhoto('tempfoto',$_POST['path'],$_POST['foto']);
}
if ($_POST['borrararchivo'] == 'si') {
$_POST['archivo'] = $Ejercicio->updateExcercisePhoto(false,$_POST['path'],$_POST['archivo']);
} else {
if ($_FILES['temparchivo']['name'] != '') $_POST['archivo'] = $Ejercicio->updateExcercisePhoto('temparchivo',$_POST['path'],$_POST['archivo']);
}
$e = $Ejercicio->updateExcercise($_POST['titulo'], $_POST['breve'], $_POST['texto'], $_POST['foto'], $_POST['vigencia'], $_POST['archivo'], $_POST['cursos_id'], $_POST['id']);
} elseif ($_POST['accion'] == 3) {
// accion borrar
$e = $Ejercicio->deleteExcercise($_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 = $Ejercicio->excerciseDetail($_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 language="JavaScript" type="text/javascript">
<!--
imageUrl = '../../../cal';
-->
</script>
<script src="../../../cal/js/javascript.js" type="text/javascript" language="JavaScript"></script>
<script src="../../../cal/js/popcalendar.js" type="text/javascript" language="JavaScript"></script>
<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>« <a href="curso.php?id=<?php echo $cursos_id ?>&accion=2"><?php echo $DMC->m('ln_volver') ?></a> « <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_ejercicio') ?></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_ejercicio" />
<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 method="post" name="frm_ejercicio" action="<?php echo $editFormAction; ?>" enctype="multipart/form-data" onsubmit="return validar('frm_ejercicio','boton');">
<table>
<tr valign="baseline">
<th align="right" nowrap="nowrap" class="req"><?php echo $DMC->m('frm_titulo') ?>:</th>
<td><input type="text" name="titulo" value="<?php echo $titulo ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<th nowrap="nowrap" align="right"><?php echo $DMC->m('frm_breve') ?>:</th>
<td><input type="text" name="breve" value="<?php echo $breve ?>" 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/photos/' . $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 align="right" valign="top" nowrap="nowrap"><?php echo $DMC->m('frm_archivo') ?>:</th>
<td>
<?php
if ($_GET['accion'] == 2 && $archivo != "") {
?>
<a href="<?php echo $DMC->app['DMC_url'] . $DMC->app['DMC_course_folder'] . '/' . $path . '/files/photos/' . $archivo ?>" target="_blank"><?php echo $DMC->m('frm_archivo_ver') ?></a><br />
<input type="checkbox" name="borrararchivo" id="borrararchivo" value="si" />
<label for="borrararchivo"><?php echo $DMC->m('frm_borrar_archivo') ?></label><br />
<?php
}
?>
<input type="hidden" name="archivo" value="<?php echo $archivo ?>" />
<input type="file" name="temparchivo" size="20" />
</td>
</tr>
<tr valign="baseline">
<th nowrap="nowrap" align="right" class="req"><?php echo $DMC->m('frm_vigencia') ?>:</th>
<td><input type="text" name="vigencia" value="<?php echo $vigencia ?>" size="10" />
<img src='../../../cal/cal.gif' alt="<?php echo $DMC->m('frm_seleccione_fecha') ?>" name="date_button" id="date_button" onclick="popUpCalendar(this, document.frm_ejercicio.vigencia, 'dd/mm/yyyy')" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td> </td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </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="cursos_id" value="<?php echo $cursos_id ?>" />
<input type="hidden" name="DM_post" value="frm_ejercicio" />
<input type="hidden" name="path" value="<?php echo $path ?>" />
<input type="hidden" name="__campos__" value="titulo" />
<input type="hidden" name="__nombres__" value="<?php echo $DMC->m('js_titulo') ?>" />
<input type="hidden" name="__tipos__" value="texto" />
</form>
<?php
}
?>
</body>
</html>