Add classes to common includes

This commit is contained in:
Némunaire 2013-10-10 04:47:02 +02:00
parent e1a654359a
commit 0fdc0703f6
4 changed files with 198 additions and 189 deletions

View File

@ -6,6 +6,10 @@ if (empty($sess->values["connected"]) && !defined("xCSRF"))
require_once("functions.php"); //Inclusion des principales fonctions
require_once("common/Exercice.class.php");
require_once("common/Theme.class.php");
require_once("common/User.class.php");
//On charge la session
$SESS = new Session();
@ -25,4 +29,3 @@ if ($SESS->level > 2 && !empty($_SERVER["HTTP_REFERER"]) && !(preg_match('#^http
unset($_POST, $_GET);
$_GET = $_POST = array();
}
?>

View File

@ -2,7 +2,8 @@
if(!defined('ONYX')) exit;
class Exercice {
class Exercice
{
var $id=null;
var $theme;
var $require;
@ -24,7 +25,7 @@ class Exercice {
if (!empty($res))
{
$this->id = $res['id'];
$this->id = intval($res['id']);
$this->theme = new Theme($res['id_theme']);
$this->require = $res['require'];
$this->level = $res['level'];
@ -32,10 +33,10 @@ class Exercice {
$this->statement = $res['statement'];
$this->files = $db->query("SELECT `id`, `path`, `name`
FROM exercice_files
WHERE id_exercice = id");
WHERE id_exercice = $id");
$this->keys = $db->query("SELECT `id`, `format`, `value`
FROM exercice_keys
WHERE id_exercice = id");
WHERE id_exercice = $id");
}
$db->deconnexion();
}
@ -61,14 +62,12 @@ class Exercice {
if ($create)
{
$db->query("INSERT INTO exercices
VALUES ('"$id"', '".$theme."', '".$require."', '".$level."', '".$points."','".$statement));
$aff = $db->affected();
VALUES ('".$id."', '".$theme."', '".$require."', '".$level."', '".$points."','".$statement."');");
}
else
{
$db->query("UPDATE exercices
SET `theme` = '".$theme."', `require` = '".$require."', `level` = '".$level."', `point` = '".$point."', `statement` = '"$statement"'
SET `theme` = '".$theme."', `require` = '".$require."', `level` = '".$level."', `point` = '".$point."', `statement` = '".$statement."'
WHERE id = ".$id);
$aff = $db->affected();
@ -78,24 +77,27 @@ class Exercice {
{
$format = $key['format'];
$value = $key['value'];
if (isset($key['id']))
$kid = $key['id'];
else
$kid = NULL;
$db->escape($format);
$db->escape($value);
$db->escape($kid);
if (!isset($kid))
if (empty($kid))
{
$db->query("INSERT INTO exercice_keys
VALUES (NULL, '".$id."', '".$format."', '".$value);
VALUES (NULL, '".$this->id."', '".$format."', UNHEX('".strhex($value)."'))");
$this->keys[$k]['id'] = $db->insert_id();
}
else
{
$db->query("UPDATE exercice_keys
SET `format` = '".$format."', `value` = '".$value."'
WHERE id = '".$kid);
SET `format` = '".$format."', `value` = UNHEX('".strhex($value).")')
WHERE id = ".$kid);
}
}
@ -103,16 +105,16 @@ class Exercice {
{
$path = $file['path'];
$name = $file['name'];
$fid = $file['id'];
if (isset($file['id']))
$fid = intval($file['id']);
$db->escape($path);
$db->escape($name);
$db->escape($fid);
if (!isset($file['id']))
{
$db->query("INSERT INTO exercice_files
VALUES ('"$id"', '".$path."', '".$name);
VALUES (NULL, '".$id."', '".$path."', '".$name."');");
$this->files[$k]['id'] = $db->insert_id();
}
@ -120,13 +122,14 @@ class Exercice {
{
$db->query("UPDATE exercice_files
SET `path` = '".$path."', `name` = '".$name."'
WHERE id = '".$fid);
WHERE id = ".$fid);
}
}
$db->deconnexion();
return ($aff == 1);
//FIXME
return 1;
}
function create()

View File

@ -2,10 +2,11 @@
if(!defined('ONYX')) exit;
class Theme {
class Theme
{
$id=null;
$title;
var $id=null;
var $title;
function Theme($id=null)
{
@ -33,7 +34,7 @@ class Theme {
if (empty($this->id))
{
$db->query("INSERT INTO themes
VALUES (NULL, '".$title);
VALUES (NULL, '".$title."');");
$this->id = $db->insert_id();
$aff = ($this->id > 0);
}
@ -64,7 +65,8 @@ class Theme {
if (isset($exercice))
{
$exercice->theme = $this;
$exercice->update(true);
}
return $exercice->update(true);
}
return false;
}
}

View File

@ -37,6 +37,7 @@ class User {
$auth_level = intval($this->auth_level);
$firstname = $this->firstname;
$lastname = $this->lastname;
$company = $this->company;
$db = new BDD();
$db->escape($username);
@ -47,7 +48,7 @@ class User {
if (empty($this->id))
{
$db->query("INSERT INTO users
VALUES (NULL, '".$username."', NULL , ".$auth_level." '".$firstname."', '".$lastname."', '".$company."')");
VALUES (NULL, '".$username."', 0x0, ".$auth_level.", '".$firstname."', '".$lastname."', '".$company."')");
$this->id = $db->insert_id();
$aff = ($this->id > 0);
}
@ -107,7 +108,7 @@ class User {
if (!empty($res))
{
$this->points = res['sum_points'];
$this->points = $res['sum_points'];
}
$db->deconnexion();
}