This commit is contained in:
Némunaire 2013-10-10 05:52:48 +02:00
commit 38ed722d15
3 changed files with 146 additions and 150 deletions

View file

@ -4,24 +4,23 @@ if(!defined('ONYX')) exit;
class Exercice
{
var $id=null;
var $id = null;
var $theme;
var $require;
var $level;
var $points;
var $statement;
var $files;
var $keys;
var $files = array();
var $keys = array();
function Exercice($id=null)
{
if (!empty($id))
{
$db = new BDD();
$res = $db->unique_query("SELECT `id`, `id_theme`, `require`, `level`, `points`, `statement`
FROM exercices
WHERE id=" . intval($id));
FROM exercices
WHERE id=" . intval($id));
if (!empty($res))
{
@ -78,24 +77,23 @@ class Exercice
$format = $key['format'];
$value = $key['value'];
if (isset($key['id']))
$kid = $key['id'];
$kid = intval($key['id']);
else
$kid = NULL;
$kid = 0;
$db->escape($format);
$db->escape($value);
$db->escape($kid);
if (empty($kid))
{
$db->query("INSERT INTO exercice_keys
VALUES (NULL, '".$this->id."', '".$format."', UNHEX('".strhex($value)."'))");
$db->query("INSERT INTO exercice_keys
VALUES (NULL, '".$this->id."', '".$format."', UNHEX('".strhex($value)."'))");
$this->keys[$k]['id'] = $db->insert_id();
$this->keys[$k]['id'] = $db->insert_id();
}
else
{
$db->query("UPDATE exercice_keys
$db->query("UPDATE exercice_keys
SET `format` = '".$format."', `value` = UNHEX('".strhex($value).")')
WHERE id = ".$kid);
}
@ -108,7 +106,7 @@ class Exercice
$sha1 = $file['sha1'];
if (isset($file['id']))
$fid = intval($file['id']);
$fid = intval($file['id']);
$db->escape($path);
$db->escape($name);
@ -116,16 +114,16 @@ class Exercice
if (!isset($file['id']))
{
$db->query("INSERT INTO exercice_files
$db->query("INSERT INTO exercice_files
VALUES (NULL, '".$id."', '".$path."', '".$name."', '".$sha1."');");
$this->files[$k]['id'] = $db->insert_id();
$this->files[$k]['id'] = $db->insert_id();
}
else
{
$db->query("UPDATE exercice_files
SET `path` = '".$path."', `name` = '".$name."', `sha1` = '".$sha1."'
WHERE id = ".$fid);
$db->query("UPDATE exercice_files
SET `path` = '".$path."', `name` = '".$name."', `sha1` = '".$sha1."'
WHERE id = ".$fid);
}
}
@ -142,15 +140,18 @@ class Exercice
function add_key($format, $value)
{
$key = ["format" => $format, "value" => $value];
if (isset($key))
$this->keys[] = $key;
$this->keys[] = array(
"format" => $format,
"value" => $value
);
}
function add_file($path, $name, $sha1)
{
$file = ["path" => $path, "name" => $name, "sha1" => $sha1];
if (isset($file))
$this->files[] = $file;
$this->files[] = array(
"path" => $path,
"name" => $name,
"sha1" => $sha1
);
}
}