diff --git a/onyx/include/common/Exercice.class.php b/onyx/include/common/Exercice.class.php index 48010ae2..df3cde50 100644 --- a/onyx/include/common/Exercice.class.php +++ b/onyx/include/common/Exercice.class.php @@ -16,6 +16,8 @@ class Exercice function Exercice($id=null, $theme=null) { + global $VAR; + if (!empty($id)) { $db = new BDD(); @@ -33,7 +35,13 @@ class Exercice // Decode sha1 if ($this->files) 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"]); + } $this->keys = $db->query("SELECT `id`, `format`, `value` FROM exercice_keys @@ -135,7 +143,7 @@ class Exercice do { 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']; $ret++; } while ($exo != "" && !in_array($exo, $checked)); @@ -181,7 +189,7 @@ class Exercice $format = $key['format']; $value = $key['value']; if (isset($key['id'])) - $kid = intval($key['id']); + $kid = $key['id']; else $kid = 0; @@ -219,14 +227,14 @@ class Exercice if (!isset($file['id'])) { $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(); } else { $db->query("UPDATE exercice_files - SET `path` = '".$path."', `name` = '".$name."', `sha1` = '".$sha1."' + SET `path` = '".$path."', `name` = '".$name."', `sha1` = UNHEX('".$sha1."') WHERE id = ".$fid); } }