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,149 +2,152 @@
if(!defined('ONYX')) exit;
class Exercice {
var $id=null;
var $theme;
var $require;
var $level;
var $points;
var $statement;
var $files;
var $keys;
class Exercice
{
var $id=null;
var $theme;
var $require;
var $level;
var $points;
var $statement;
var $files;
var $keys;
function Exercice($id=null)
{
function Exercice($id=null)
{
if (!empty($id))
{
$db = new BDD();
$res = $db->unique_query("SELECT `id`, `id_theme`, `require`, `level`, `points`, `statement`
if (!empty($id))
{
$db = new BDD();
$res = $db->unique_query("SELECT `id`, `id_theme`, `require`, `level`, `points`, `statement`
FROM exercices
WHERE id=" . intval($id));
if (!empty($res))
{
$this->id = $res['id'];
$this->theme = new Theme($res['id_theme']);
$this->require = $res['require'];
$this->level = $res['level'];
$this->points = $res['points'];
$this->statement = $res['statement'];
$this->files = $db->query("SELECT `id`, `path`, `name`
FROM exercice_files
WHERE id_exercice = id");
$this->keys = $db->query("SELECT `id`, `format`, `value`
FROM exercice_keys
WHERE id_exercice = id");
}
$db->deconnexion();
}
}
if (!empty($res))
{
$this->id = intval($res['id']);
$this->theme = new Theme($res['id_theme']);
$this->require = $res['require'];
$this->level = $res['level'];
$this->points = $res['points'];
$this->statement = $res['statement'];
$this->files = $db->query("SELECT `id`, `path`, `name`
FROM exercice_files
WHERE id_exercice = $id");
$this->keys = $db->query("SELECT `id`, `format`, `value`
FROM exercice_keys
WHERE id_exercice = $id");
}
$db->deconnexion();
}
}
function update($create)
{
$id = $this->id;
$theme = intval($this->theme->get_id());
$require = $this->require;
$level = intval($this->level);
$points = intval($this->points);
$statement = $this->statement;
$files = $this->files;
$keys = $this->keys;
function update($create)
{
$id = $this->id;
$theme = intval($this->theme->get_id());
$require = $this->require;
$level = intval($this->level);
$points = intval($this->points);
$statement = $this->statement;
$files = $this->files;
$keys = $this->keys;
$db = new BDD();
$db->escape($id);
$db->escape($theme);
$db->escape($require);
$db->escape($statement);
$db = new BDD();
$db->escape($id);
$db->escape($theme);
$db->escape($require);
$db->escape($statement);
if ($create)
{
$db->query("INSERT INTO exercices
VALUES ('"$id"', '".$theme."', '".$require."', '".$level."', '".$points."','".$statement));
if ($create)
{
$db->query("INSERT INTO exercices
VALUES ('".$id."', '".$theme."', '".$require."', '".$level."', '".$points."','".$statement."');");
}
else
{
$db->query("UPDATE exercices
SET `theme` = '".$theme."', `require` = '".$require."', `level` = '".$level."', `point` = '".$point."', `statement` = '".$statement."'
WHERE id = ".$id);
$aff = $db->affected();
}
else
{
$db->query("UPDATE exercices
SET `theme` = '".$theme."', `require` = '".$require."', `level` = '".$level."', `point` = '".$point."', `statement` = '"$statement"'
WHERE id = ".$id);
$aff = $db->affected();
}
$aff = $db->affected();
}
foreach ($this->keys as $k => $key)
{
$format = $key['format'];
$value = $key['value'];
if (isset($key['id']))
$kid = $key['id'];
else
$kid = NULL;
foreach ($this->keys as $k => $key)
{
$format = $key['format'];
$value = $key['value'];
$kid = $key['id'];
$db->escape($format);
$db->escape($value);
$db->escape($kid);
$db->escape($format);
$db->escape($value);
$db->escape($kid);
if (empty($kid))
{
$db->query("INSERT INTO exercice_keys
VALUES (NULL, '".$this->id."', '".$format."', UNHEX('".strhex($value)."'))");
if (!isset($kid))
{
$db->query("INSERT INTO exercice_keys
VALUES (NULL, '".$id."', '".$format."', '".$value);
$this->keys[$k]['id'] = $db->insert_id();
}
else
{
$db->query("UPDATE exercice_keys
SET `format` = '".$format."', `value` = UNHEX('".strhex($value).")')
WHERE id = ".$kid);
}
}
$this->keys[$k]['id'] = $db->insert_id();
}
else
{
$db->query("UPDATE exercice_keys
SET `format` = '".$format."', `value` = '".$value."'
WHERE id = '".$kid);
}
}
foreach ($this->files as $k => $file)
{
$path = $file['path'];
$name = $file['name'];
if (isset($file['id']))
$fid = intval($file['id']);
foreach ($this->files as $k => $file)
{
$path = $file['path'];
$name = $file['name'];
$fid = $file['id'];
$db->escape($path);
$db->escape($name);
$db->escape($path);
$db->escape($name);
$db->escape($fid);
if (!isset($file['id']))
{
$db->query("INSERT INTO exercice_files
VALUES (NULL, '".$id."', '".$path."', '".$name."');");
if (!isset($file['id']))
{
$db->query("INSERT INTO exercice_files
VALUES ('"$id"', '".$path."', '".$name);
$this->files[$k]['id'] = $db->insert_id();
}
else
{
$db->query("UPDATE exercice_files
SET `path` = '".$path."', `name` = '".$name."'
WHERE id = ".$fid);
}
}
$this->files[$k]['id'] = $db->insert_id();
}
else
{
$db->query("UPDATE exercice_files
SET `path` = '".$path."', `name` = '".$name."'
WHERE id = '".$fid);
}
}
$db->deconnexion();
$db->deconnexion();
//FIXME
return 1;
}
return ($aff == 1);
}
function create()
{
update(true);
}
function create()
{
update(true);
}
function add_key($format, $value)
{
$key = ["format" => $format, "value" => $value];
if (isset($key))
$this->keys[] = $key;
}
function add_key($format, $value)
{
$key = ["format" => $format, "value" => $value];
if (isset($key))
$this->keys[] = $key;
}
function add_file($path, $name)
{
$file = ["path" => $path, "name" => $name];
if (isset($file))
$this->files[] = $file;
}
function add_file($path, $name)
{
$file = ["path" => $path, "name" => $name];
if (isset($file))
$this->files[] = $file;
}
}

View File

@ -2,69 +2,71 @@
if(!defined('ONYX')) exit;
class Theme {
class Theme
{
$id=null;
$title;
var $id=null;
var $title;
function Theme($id=null)
{
if (!empty($id))
{
$db = new BDD();
$res = $db->unique_query("SELECT id, title
FROM themes WHERE id=" . intval($id));
function Theme($id=null)
{
if (!empty($id))
{
$db = new BDD();
$res = $db->unique_query("SELECT id, title
FROM themes WHERE id=" . intval($id));
if (!empty($res))
{
$this->title = $res['title'];
}
$db->deconnexion();
}
}
if (!empty($res))
{
$this->title = $res['title'];
}
$db->deconnexion();
}
}
function update()
{
$title = $this->title;
function update()
{
$title = $this->title;
$db = new BDD();
$db->escape($title);
$db = new BDD();
$db->escape($title);
if (empty($this->id))
{
$db->query("INSERT INTO themes
VALUES (NULL, '".$title);
$this->id = $db->insert_id();
$aff = ($this->id > 0);
}
else
{
$db->query("UPDATE themes
if (empty($this->id))
{
$db->query("INSERT INTO themes
VALUES (NULL, '".$title."');");
$this->id = $db->insert_id();
$aff = ($this->id > 0);
}
else
{
$db->query("UPDATE themes
SET title = '".$title."'
WHERE id = ".intval($this->id));
$aff = $db->affected();
}
$db->deconnexion();
$aff = $db->affected();
}
$db->deconnexion();
return ($aff == 1);
}
return ($aff == 1);
}
function get_title()
{
return $this->title;
}
function get_title()
{
return $this->title;
}
function get_id()
{
return $this->id;
}
function get_id()
{
return $this->id;
}
function add_exercice($exercice)
{
if (isset($exercice))
{
$exercice->theme = $this;
$exercice->update(true);
}
}
function add_exercice($exercice)
{
if (isset($exercice))
{
$exercice->theme = $this;
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();
}