Add sha1 feature in Exercice class

This commit is contained in:
Quentin Grosyeux 2013-10-10 05:11:40 +02:00
parent 0640a261d6
commit fffb86e971

View File

@ -78,9 +78,9 @@ class Exercice
$format = $key['format']; $format = $key['format'];
$value = $key['value']; $value = $key['value'];
if (isset($key['id'])) if (isset($key['id']))
$kid = $key['id']; $kid = $key['id'];
else else
$kid = NULL; $kid = NULL;
$db->escape($format); $db->escape($format);
$db->escape($value); $db->escape($value);
@ -88,14 +88,14 @@ class Exercice
if (empty($kid)) if (empty($kid))
{ {
$db->query("INSERT INTO exercice_keys $db->query("INSERT INTO exercice_keys
VALUES (NULL, '".$this->id."', '".$format."', UNHEX('".strhex($value)."'))"); VALUES (NULL, '".$this->id."', '".$format."', UNHEX('".strhex($value)."'))");
$this->keys[$k]['id'] = $db->insert_id(); $this->keys[$k]['id'] = $db->insert_id();
} }
else else
{ {
$db->query("UPDATE exercice_keys $db->query("UPDATE exercice_keys
SET `format` = '".$format."', `value` = UNHEX('".strhex($value).")') SET `format` = '".$format."', `value` = UNHEX('".strhex($value).")')
WHERE id = ".$kid); WHERE id = ".$kid);
} }
@ -105,24 +105,27 @@ class Exercice
{ {
$path = $file['path']; $path = $file['path'];
$name = $file['name']; $name = $file['name'];
$sha1 = $file['sha1'];
if (isset($file['id'])) if (isset($file['id']))
$fid = intval($file['id']); $fid = intval($file['id']);
$db->escape($path); $db->escape($path);
$db->escape($name); $db->escape($name);
$db->escape($sha1);
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."');"); VALUES (NULL, '".$id."', '".$path."', '".$name."', '".$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."' SET `path` = '".$path."', `name` = '".$name."', `sha1` = '".$sha1."'
WHERE id = ".$fid); WHERE id = ".$fid);
} }
} }
@ -144,9 +147,9 @@ class Exercice
$this->keys[] = $key; $this->keys[] = $key;
} }
function add_file($path, $name) function add_file($path, $name, $sha1)
{ {
$file = ["path" => $path, "name" => $name]; $file = ["path" => $path, "name" => $name, "sha1" => $sha1];
if (isset($file)) if (isset($file))
$this->files[] = $file; $this->files[] = $file;
} }