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