Administration: can edit exercices
This commit is contained in:
parent
868e3403ee
commit
aeb4b5dd52
9 changed files with 138 additions and 31 deletions
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
if(!defined('ONYX')) exit;
|
||||
|
||||
$template->assign("fortyp", array("raw" => "RAW", "sha1" => "SHA-1", "md5" => "MD5", "sha224" => "SHA-224", "sha256" => "SHA-256", "sha384" => "SHA-384", "sha512" => "SHA-512"));
|
||||
|
||||
$p = $out[0];
|
||||
|
||||
//TODO maybe move the try catch to index.html ?
|
||||
|
|
@ -18,7 +20,28 @@ try
|
|||
}
|
||||
|
||||
if (isset($p[3]))
|
||||
$template->assign("ex", new Exercice($p[3], $theme));
|
||||
{
|
||||
$exercice = new Exercice($p[3], $theme);
|
||||
|
||||
if (!empty($_POST))
|
||||
{
|
||||
$exercice->points = intval($_POST["points"]);
|
||||
$exercice->statement = $_POST["desc"];
|
||||
$exercice->require = $_POST["require"];
|
||||
$exercice->level = intval($_POST["level"]);
|
||||
|
||||
$exercice->keys = array();
|
||||
foreach ($_POST as $k => $key)
|
||||
{
|
||||
if (preg_match("/k([0-9]+)_value/", $k, $out) && !empty($key) && !empty($_POST["k".$out[1]."_type"]))
|
||||
$exercice->add_key($_POST["k".$out[1]."_type"], $key);
|
||||
}
|
||||
|
||||
//$exercice->update();
|
||||
}
|
||||
|
||||
$template->assign("ex", $exercice);
|
||||
}
|
||||
}
|
||||
catch (ThemeNotFoundException $e)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -102,6 +102,11 @@ class Exercice
|
|||
return "Exercice ".$this->number;
|
||||
}
|
||||
|
||||
function get_statement()
|
||||
{
|
||||
return $this->statement;
|
||||
}
|
||||
|
||||
// retourne le nombre d'equipes qui ont résolues l'exercice
|
||||
// trié par date
|
||||
function get_solved()
|
||||
|
|
@ -177,7 +182,7 @@ class Exercice
|
|||
$db->deconnexion();
|
||||
}
|
||||
|
||||
function update($create)
|
||||
function update($create=false)
|
||||
{
|
||||
$id = $this->id;
|
||||
$theme = intval($this->theme->get_id());
|
||||
|
|
@ -202,7 +207,7 @@ class Exercice
|
|||
else
|
||||
{
|
||||
$db->query("UPDATE exercices
|
||||
SET `theme` = '".$theme."', `require` = '".$require."', `level` = '".$level."', `point` = '".$point."', `statement` = '".$statement."'
|
||||
SET `id_theme` = '".$theme."', `require` = '".$require."', `level` = '".$level."', `points` = '".$points."', `statement` = '".$statement."'
|
||||
WHERE id = '$id'");
|
||||
|
||||
$aff = $db->affected();
|
||||
|
|
@ -276,9 +281,16 @@ class Exercice
|
|||
|
||||
function add_key($format, $value)
|
||||
{
|
||||
$this->keys[] = array(
|
||||
"format" => $format,
|
||||
"value" => $value
|
||||
if ($format == "raw")
|
||||
{
|
||||
$this->add_key("sha1", hash("sha1", $value));
|
||||
$this->add_key("sha512", hash("sha512", $value));
|
||||
$this->add_key("md5", hash("md5", $value));
|
||||
}
|
||||
else
|
||||
$this->keys[] = array(
|
||||
"format" => $format,
|
||||
"value" => $value
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +1,82 @@
|
|||
{extends file="admin/layout.tpl"}
|
||||
{block name=content}
|
||||
{if isset($ex)}
|
||||
<h2>{$theme->name} <small>{$ex->id}</small></h2>
|
||||
<form role="form" method="post" action="/{$SALT_ADMIN}/ex/{$theme->id}-{$theme->name}/{$ex->id}">
|
||||
<div class="form-group">
|
||||
<label for="desc">Description</label>
|
||||
<textarea class="form-control" name="desc" id="desc">{$ex->statement|escape}</textarea>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="points">Points</label>
|
||||
<input type="text" class="form-control" value="{$ex->points|escape}" name="points" id="points">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="require">Dépendance</label>
|
||||
<input type="text" class="form-control" value="{$ex->require|escape}" name="require" id="require">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="level">Niveau de difficulté</label>
|
||||
<input type="text" class="form-control" value="{$ex->level}" name="level" id="level">
|
||||
</div>
|
||||
{foreach from=$ex->keys item=key key=k}
|
||||
<div class="panel panel-info">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">Clef {$k}</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="form-group">
|
||||
<label for="k{$k}_type">Type</label>
|
||||
<select name="k{$k}_type" id="k{$k}_type" class="form-control">
|
||||
{html_options options=$fortyp selected=$key.format}
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="k{$k}_value">Valeur</label>
|
||||
<input type="text" class="form-control" value="{$key.value|escape}" name="k{$k}_value" id="k{$k}_value">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/foreach}
|
||||
<div class="panel panel-success">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">Nouvelle clef</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="form-group">
|
||||
<label for="k{$k+1}_type">Type</label>
|
||||
<input type="text" class="form-control" name="k{$k+1}_type" id="k{$k+1}_type" value="raw">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="k{$k+1}_value">Valeur</label>
|
||||
<input type="text" class="form-control" name="k{$k+1}_value" id="k{$k+1}_value" placeholder="Clef">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel panel-warning">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">Fichiers</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<ul>
|
||||
{foreach from=$ex->files item=file key=k}
|
||||
<li><a href="{$file.path}">{$file.name}</a>: {$file.sha1}</li>
|
||||
{/foreach}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<button type="submit" class="btn btn-success">Modifier</button>
|
||||
</div>
|
||||
</form>
|
||||
{else}
|
||||
<h2>{$theme->name}</h2>
|
||||
<p>
|
||||
Theme: {$theme->name} </br>
|
||||
{if isset($ex)}
|
||||
Exercice: {$ex->id}
|
||||
{else}
|
||||
<ul>
|
||||
{foreach $theme->get_exercices_ordered() as $ex}
|
||||
<li><a href="/{$SALT_ADMIN}/ex/{$theme->id}-{$theme->name}/{$ex->id}">{$ex->get_name()}</a></li>
|
||||
{/foreach}
|
||||
</ul>
|
||||
{/if}
|
||||
<ul>
|
||||
{foreach from=$theme->get_exercices_ordered() item=ex}
|
||||
<li><a href="/{$SALT_ADMIN}/ex/{$theme->id}-{$theme->name}/{$ex->id}">{$ex->get_name()}</a></li>
|
||||
{/foreach}
|
||||
</ul>
|
||||
</p>
|
||||
{/if}
|
||||
{/block}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,11 @@
|
|||
<li><a href="/{$SALT_ADMIN}/ex/{$t->id}-{$t->name}/{$e->id}">{$e->get_name()}</a></li>
|
||||
{/foreach}
|
||||
</ul></td>
|
||||
<td>FIXME</td>
|
||||
<td>
|
||||
{foreach from=$t->get_exercices_ordered() item=e}
|
||||
{count($e->get_solved())}<br>
|
||||
{/foreach}
|
||||
</td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
</tbody>
|
||||
|
|
|
|||
Reference in a new issue