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("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 //On charge la session
$SESS = new Session(); $SESS = new Session();
@ -25,4 +29,3 @@ if ($SESS->level > 2 && !empty($_SERVER["HTTP_REFERER"]) && !(preg_match('#^http
unset($_POST, $_GET); unset($_POST, $_GET);
$_GET = $_POST = array(); $_GET = $_POST = array();
} }
?>

View File

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

View File

@ -2,10 +2,11 @@
if(!defined('ONYX')) exit; if(!defined('ONYX')) exit;
class Theme { class Theme
{
$id=null; var $id=null;
$title; var $title;
function Theme($id=null) function Theme($id=null)
{ {
@ -33,7 +34,7 @@ class Theme {
if (empty($this->id)) if (empty($this->id))
{ {
$db->query("INSERT INTO themes $db->query("INSERT INTO themes
VALUES (NULL, '".$title); VALUES (NULL, '".$title."');");
$this->id = $db->insert_id(); $this->id = $db->insert_id();
$aff = ($this->id > 0); $aff = ($this->id > 0);
} }
@ -64,7 +65,8 @@ class Theme {
if (isset($exercice)) if (isset($exercice))
{ {
$exercice->theme = $this; $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); $auth_level = intval($this->auth_level);
$firstname = $this->firstname; $firstname = $this->firstname;
$lastname = $this->lastname; $lastname = $this->lastname;
$company = $this->company;
$db = new BDD(); $db = new BDD();
$db->escape($username); $db->escape($username);
@ -47,7 +48,7 @@ class User {
if (empty($this->id)) if (empty($this->id))
{ {
$db->query("INSERT INTO users $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(); $this->id = $db->insert_id();
$aff = ($this->id > 0); $aff = ($this->id > 0);
} }
@ -107,7 +108,7 @@ class User {
if (!empty($res)) if (!empty($res))
{ {
$this->points = res['sum_points']; $this->points = $res['sum_points'];
} }
$db->deconnexion(); $db->deconnexion();
} }