Merge branch 'master' of ssh://git.nemunai.re:6224/fic2014-server

This commit is contained in:
Quentin Grosyeux 2013-10-22 06:09:53 +02:00
commit b69ecd3e70
3 changed files with 145 additions and 149 deletions

View File

@ -4,24 +4,23 @@ if(!defined('ONYX')) exit;
class Exercice
{
var $id=null;
var $id = null;
var $theme;
var $require;
var $level;
var $points;
var $statement;
var $files;
var $keys;
var $files = array();
var $keys = array();
function Exercice($id=null)
{
if (!empty($id))
{
$db = new BDD();
$res = $db->unique_query("SELECT `id`, `id_theme`, `require`, `level`, `points`, `statement`
FROM exercices
WHERE id=" . intval($id));
FROM exercices
WHERE id=" . intval($id));
if (!empty($res))
{
@ -78,24 +77,23 @@ class Exercice
$format = $key['format'];
$value = $key['value'];
if (isset($key['id']))
$kid = $key['id'];
$kid = intval($key['id']);
else
$kid = NULL;
$kid = 0;
$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)."'))");
$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);
}
@ -108,7 +106,7 @@ class Exercice
$sha1 = $file['sha1'];
if (isset($file['id']))
$fid = intval($file['id']);
$fid = intval($file['id']);
$db->escape($path);
$db->escape($name);
@ -116,16 +114,16 @@ class Exercice
if (!isset($file['id']))
{
$db->query("INSERT INTO exercice_files
$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."', `sha1` = '".$sha1."'
WHERE id = ".$fid);
$db->query("UPDATE exercice_files
SET `path` = '".$path."', `name` = '".$name."', `sha1` = '".$sha1."'
WHERE id = ".$fid);
}
}
@ -142,15 +140,18 @@ class Exercice
function add_key($format, $value)
{
$key = ["format" => $format, "value" => $value];
if (isset($key))
$this->keys[] = $key;
$this->keys[] = array(
"format" => $format,
"value" => $value
);
}
function add_file($path, $name, $sha1)
{
$file = ["path" => $path, "name" => $name, "sha1" => $sha1];
if (isset($file))
$this->files[] = $file;
$this->files[] = array(
"path" => $path,
"name" => $name,
"sha1" => $sha1
);
}
}

View File

@ -4,8 +4,7 @@ if(!defined('ONYX')) exit;
class Theme
{
var $id=null;
var $id = null;
var $title;
function Theme($id=null)

View File

@ -2,141 +2,137 @@
if(!defined('ONYX')) exit;
class User {
var $id = null;
var $firstname;
var $lastname;
var $username;
var $company;
var $auth_level;
var $points = null;
var $nb_themes = null;
class User
{
var $id = null;
var $firstname;
var $lastname;
var $username;
var $company;
var $auth_level;
var $points = null;
var $nb_themes = null;
function User ($id=null) {
if (!empty($id))
{
$db = new BDD();
$res = $db->unique_query("SELECT id, firstname, lastname, username, company, auth_level
FROM users WHERE id=" . intval($id));
if (!empty($res))
{
$this->firstname = $res['firstname'];
$this->lastname = $res['lastname'];
$this->username = $res['username'];
$this->company = $res['company'];
$this->auth_level = $res['auth_level'];
}
$db->deconnexion();
}
}
function update()
{
$username = $this->username;
$auth_level = intval($this->auth_level);
$firstname = $this->firstname;
$lastname = $this->lastname;
$company = $this->company;
$db = new BDD();
$db->escape($username);
$db->escape($firstname);
$db->escape($lastname);
$db->escape($company);
if (empty($this->id))
{
$db->query("INSERT INTO users
VALUES (NULL, '".$username."', 0x0, ".$auth_level.", '".$firstname."', '".$lastname."', '".$company."')");
$this->id = $db->insert_id();
$aff = ($this->id > 0);
}
else
{
$db->query("UPDATE users
SET username = '".$username."', auth_level = '".$auth_level."', firstname = '".$firstname."', lastname = '".$lastname."', company = '".$company."'
WHERE id = ".intval($this->id));
$aff = $db->affected();
}
$db->deconnexion();
return ($aff == 1);
}
function get_id()
function User ($id=null)
{
if (!empty($id))
{
return $this->id;
}
$db = new BDD();
$res = $db->unique_query("SELECT id, firstname, lastname, username, company, auth_level
FROM users WHERE id=" . intval($id));
function get_firstname()
if (!empty($res))
{
$this->firstname = $res['firstname'];
$this->lastname = $res['lastname'];
$this->username = $res['username'];
$this->company = $res['company'];
$this->auth_level = $res['auth_level'];
}
$db->deconnexion();
}
}
function update()
{
$username = $this->username;
$auth_level = intval($this->auth_level);
$firstname = $this->firstname;
$lastname = $this->lastname;
$company = $this->company;
$db = new BDD();
$db->escape($username);
$db->escape($firstname);
$db->escape($lastname);
$db->escape($company);
if (empty($this->id))
{
return $this->firstname;
$db->query("INSERT INTO users
VALUES (NULL, '".$username."', 0x0, ".$auth_level.", '".$firstname."', '".$lastname."', '".$company."')");
$this->id = $db->insert_id();
$aff = ($this->id > 0);
}
function get_lastname()
else
{
return $this->lastname;
$db->query("UPDATE users
SET username = '".$username."', auth_level = '".$auth_level."', firstname = '".$firstname."', lastname = '".$lastname."', company = '".$company."'
WHERE id = ".intval($this->id));
$aff = $db->affected();
}
$db->deconnexion();
function get_username()
return ($aff == 1);
}
function get_id() {
return $this->id;
}
function get_firstname() {
return $this->firstname;
}
function get_lastname() {
return $this->lastname;
}
function get_username() {
return $this->username;
}
function get_company() {
return $this->company;
}
function get_auth_level() {
return $this->auth_level;
}
function get_pts()
{
if(isset($this->points))
{
return $this->username;
$db = new BDD();
$res = $db->query("SELECT e.id, s.id_user, SUM(e.points) as sum_points
FROM exercices e
LEFT OUTER JOIN solved s ON e.id = s.id_exercice
WHERE s.id_user = " . intval($this->id) . "
GROUP BY s.id_user");
$db->deconnexion();
if (!empty($res))
{
$this->points = $res['sum_points'];
}
}
}
function get_company()
{
return $this->company;
}
function authenticate($certificate)
{
//TODO
}
function get_auth_level()
{
return $this->auth_level;
}
function get_pts()
{
if(isset($this->points))
{
$db = new BDD();
$res = $db->query("SELECT e.id, s.id_user, SUM(e.points) as sum_points
FROM exercices e
LEFT OUTER JOIN solved s ON e.id = s.id_exercice
WHERE s.id_user = " . intval($this->id) . "
GROUP BY s.id_user");
if (!empty($res))
{
$this->points = $res['sum_points'];
}
$db->deconnexion();
}
}
function authenticate($certificate)
{
//TODO
}
// Points par theme (theme, user, sum_points)
//$res = $db->query("SELECT e.id_theme, s.id_user, SUM(e.points) as sum_points
//FROM exercices e
//LEFT OUTER JOIN solved s ON e.id = s.id_exercice
//WHERE s.id_user = " . intval($this->id) . "
//GROUP BY s.id_user, e.id_theme");
// Points par theme (theme, user, sum_points)
//$res = $db->query("SELECT e.id_theme, s.id_user, SUM(e.points) as sum_points
//FROM exercices e
//LEFT OUTER JOIN solved s ON e.id = s.id_exercice
//WHERE s.id_user = " . intval($this->id) . "
//GROUP BY s.id_user, e.id_theme");
//SELECT e.id_theme,
// (select e.points from exercices where e.id=???),
// (select e.points from exercices where e.id=???),
// (select e.points from exercices where e.id=???),
// (select e.points from exercices where e.id=???),
// (select e.points from exercices where e.id=???)
// (select max(e.points) from exercices)
//FROM exercices e
//LEFT OUTER JOIN solved s ON e.id = s.id_exercice
//WHERE s.id_user = " . intval($this->id) . "
//GROUP BY s.id_user, e.id_theme");
//SELECT e.id_theme,
// (select e.points from exercices where e.id=???),
// (select e.points from exercices where e.id=???),
// (select e.points from exercices where e.id=???),
// (select e.points from exercices where e.id=???),
// (select e.points from exercices where e.id=???)
// (select max(e.points) from exercices)
//FROM exercices e
//LEFT OUTER JOIN solved s ON e.id = s.id_exercice
//WHERE s.id_user = " . intval($this->id) . "
//GROUP BY s.id_user, e.id_theme");
}