Fixed sha1 Exercice.class

This commit is contained in:
nemunaire 2013-12-12 16:43:01 +01:00
parent 60ec66ee2d
commit 0f7c1bc7e9

View File

@ -16,6 +16,8 @@ class Exercice
function Exercice($id=null, $theme=null) function Exercice($id=null, $theme=null)
{ {
global $VAR;
if (!empty($id)) if (!empty($id))
{ {
$db = new BDD(); $db = new BDD();
@ -33,7 +35,13 @@ class Exercice
// Decode sha1 // Decode sha1
if ($this->files) if ($this->files)
foreach($this->files as &$f) foreach($this->files as &$f)
{
$f["path_orig"] = $f["path"];
if (isset($VAR["files_dir"]))
$f["path"] = $VAR["files_dir"].$f["path"];
$f["basename"] = basename($f["path"]);
$f["sha1"] = strhex($f["sha1"]); $f["sha1"] = strhex($f["sha1"]);
}
$this->keys = $db->query("SELECT `id`, `format`, `value` $this->keys = $db->query("SELECT `id`, `format`, `value`
FROM exercice_keys FROM exercice_keys
@ -135,7 +143,7 @@ class Exercice
do do
{ {
array_push($checked, $exo); array_push($checked, $exo);
$res = $db->unique_query("SELECT `require` FROM exercices WHERE id = ".$exo); $res = $db->unique_query("SELECT `require` FROM exercices WHERE id = '".$exo."'");
$exo = $res['require']; $exo = $res['require'];
$ret++; $ret++;
} while ($exo != "" && !in_array($exo, $checked)); } while ($exo != "" && !in_array($exo, $checked));
@ -181,7 +189,7 @@ class Exercice
$format = $key['format']; $format = $key['format'];
$value = $key['value']; $value = $key['value'];
if (isset($key['id'])) if (isset($key['id']))
$kid = intval($key['id']); $kid = $key['id'];
else else
$kid = 0; $kid = 0;
@ -219,14 +227,14 @@ class Exercice
if (!isset($file['id'])) if (!isset($file['id']))
{ {
$db->query("INSERT INTO exercice_files $db->query("INSERT INTO exercice_files
VALUES (NULL, '".$id."', '".$path."', '".$name."', '".$sha1."');"); VALUES (NULL, '".$id."', '".$path."', '".$name."', UNHEX('".$sha1."'));");
$this->files[$k]['id'] = $db->insert_id(); $this->files[$k]['id'] = $db->insert_id();
} }
else else
{ {
$db->query("UPDATE exercice_files $db->query("UPDATE exercice_files
SET `path` = '".$path."', `name` = '".$name."', `sha1` = '".$sha1."' SET `path` = '".$path."', `name` = '".$name."', `sha1` = UNHEX('".$sha1."')
WHERE id = ".$fid); WHERE id = ".$fid);
} }
} }