Merge branch 'master' of ssh://git.nemunai.re:6224/fic2014-server
This commit is contained in:
commit
b69ecd3e70
3 changed files with 145 additions and 149 deletions
|
@ -4,24 +4,23 @@ if(!defined('ONYX')) exit;
|
||||||
|
|
||||||
class Exercice
|
class Exercice
|
||||||
{
|
{
|
||||||
var $id=null;
|
var $id = null;
|
||||||
var $theme;
|
var $theme;
|
||||||
var $require;
|
var $require;
|
||||||
var $level;
|
var $level;
|
||||||
var $points;
|
var $points;
|
||||||
var $statement;
|
var $statement;
|
||||||
var $files;
|
var $files = array();
|
||||||
var $keys;
|
var $keys = array();
|
||||||
|
|
||||||
function Exercice($id=null)
|
function Exercice($id=null)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!empty($id))
|
if (!empty($id))
|
||||||
{
|
{
|
||||||
$db = new BDD();
|
$db = new BDD();
|
||||||
$res = $db->unique_query("SELECT `id`, `id_theme`, `require`, `level`, `points`, `statement`
|
$res = $db->unique_query("SELECT `id`, `id_theme`, `require`, `level`, `points`, `statement`
|
||||||
FROM exercices
|
FROM exercices
|
||||||
WHERE id=" . intval($id));
|
WHERE id=" . intval($id));
|
||||||
|
|
||||||
if (!empty($res))
|
if (!empty($res))
|
||||||
{
|
{
|
||||||
|
@ -78,24 +77,23 @@ class Exercice
|
||||||
$format = $key['format'];
|
$format = $key['format'];
|
||||||
$value = $key['value'];
|
$value = $key['value'];
|
||||||
if (isset($key['id']))
|
if (isset($key['id']))
|
||||||
$kid = $key['id'];
|
$kid = intval($key['id']);
|
||||||
else
|
else
|
||||||
$kid = NULL;
|
$kid = 0;
|
||||||
|
|
||||||
$db->escape($format);
|
$db->escape($format);
|
||||||
$db->escape($value);
|
$db->escape($value);
|
||||||
$db->escape($kid);
|
|
||||||
|
|
||||||
if (empty($kid))
|
if (empty($kid))
|
||||||
{
|
{
|
||||||
$db->query("INSERT INTO exercice_keys
|
$db->query("INSERT INTO exercice_keys
|
||||||
VALUES (NULL, '".$this->id."', '".$format."', UNHEX('".strhex($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` = UNHEX('".strhex($value).")')
|
SET `format` = '".$format."', `value` = UNHEX('".strhex($value).")')
|
||||||
WHERE id = ".$kid);
|
WHERE id = ".$kid);
|
||||||
}
|
}
|
||||||
|
@ -108,7 +106,7 @@ class Exercice
|
||||||
$sha1 = $file['sha1'];
|
$sha1 = $file['sha1'];
|
||||||
|
|
||||||
if (isset($file['id']))
|
if (isset($file['id']))
|
||||||
$fid = intval($file['id']);
|
$fid = intval($file['id']);
|
||||||
|
|
||||||
$db->escape($path);
|
$db->escape($path);
|
||||||
$db->escape($name);
|
$db->escape($name);
|
||||||
|
@ -116,16 +114,16 @@ class Exercice
|
||||||
|
|
||||||
if (!isset($file['id']))
|
if (!isset($file['id']))
|
||||||
{
|
{
|
||||||
$db->query("INSERT INTO exercice_files
|
$db->query("INSERT INTO exercice_files
|
||||||
VALUES (NULL, '".$id."', '".$path."', '".$name."', '".$sha1."');");
|
VALUES (NULL, '".$id."', '".$path."', '".$name."', '".$sha1."');");
|
||||||
|
|
||||||
$this->files[$k]['id'] = $db->insert_id();
|
$this->files[$k]['id'] = $db->insert_id();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$db->query("UPDATE exercice_files
|
$db->query("UPDATE exercice_files
|
||||||
SET `path` = '".$path."', `name` = '".$name."', `sha1` = '".$sha1."'
|
SET `path` = '".$path."', `name` = '".$name."', `sha1` = '".$sha1."'
|
||||||
WHERE id = ".$fid);
|
WHERE id = ".$fid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,15 +140,18 @@ class Exercice
|
||||||
|
|
||||||
function add_key($format, $value)
|
function add_key($format, $value)
|
||||||
{
|
{
|
||||||
$key = ["format" => $format, "value" => $value];
|
$this->keys[] = array(
|
||||||
if (isset($key))
|
"format" => $format,
|
||||||
$this->keys[] = $key;
|
"value" => $value
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function add_file($path, $name, $sha1)
|
function add_file($path, $name, $sha1)
|
||||||
{
|
{
|
||||||
$file = ["path" => $path, "name" => $name, "sha1" => $sha1];
|
$this->files[] = array(
|
||||||
if (isset($file))
|
"path" => $path,
|
||||||
$this->files[] = $file;
|
"name" => $name,
|
||||||
|
"sha1" => $sha1
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,8 +4,7 @@ if(!defined('ONYX')) exit;
|
||||||
|
|
||||||
class Theme
|
class Theme
|
||||||
{
|
{
|
||||||
|
var $id = null;
|
||||||
var $id=null;
|
|
||||||
var $title;
|
var $title;
|
||||||
|
|
||||||
function Theme($id=null)
|
function Theme($id=null)
|
||||||
|
|
|
@ -2,141 +2,137 @@
|
||||||
|
|
||||||
if(!defined('ONYX')) exit;
|
if(!defined('ONYX')) exit;
|
||||||
|
|
||||||
class User {
|
class User
|
||||||
var $id = null;
|
{
|
||||||
var $firstname;
|
var $id = null;
|
||||||
var $lastname;
|
var $firstname;
|
||||||
var $username;
|
var $lastname;
|
||||||
var $company;
|
var $username;
|
||||||
var $auth_level;
|
var $company;
|
||||||
var $points = null;
|
var $auth_level;
|
||||||
var $nb_themes = null;
|
var $points = null;
|
||||||
|
var $nb_themes = null;
|
||||||
|
|
||||||
function User ($id=null) {
|
function User ($id=null)
|
||||||
if (!empty($id))
|
{
|
||||||
{
|
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()
|
|
||||||
{
|
{
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
function get_lastname()
|
|
||||||
{
|
{
|
||||||
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()
|
function authenticate($certificate)
|
||||||
{
|
{
|
||||||
return $this->company;
|
//TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_auth_level()
|
// Points par theme (theme, user, sum_points)
|
||||||
{
|
//$res = $db->query("SELECT e.id_theme, s.id_user, SUM(e.points) as sum_points
|
||||||
return $this->auth_level;
|
//FROM exercices e
|
||||||
}
|
//LEFT OUTER JOIN solved s ON e.id = s.id_exercice
|
||||||
|
//WHERE s.id_user = " . intval($this->id) . "
|
||||||
function get_pts()
|
//GROUP BY s.id_user, e.id_theme");
|
||||||
{
|
|
||||||
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");
|
|
||||||
|
|
||||||
|
|
||||||
//SELECT 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 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)
|
// (select max(e.points) from exercices)
|
||||||
//FROM exercices e
|
//FROM exercices e
|
||||||
//LEFT OUTER JOIN solved s ON e.id = s.id_exercice
|
//LEFT OUTER JOIN solved s ON e.id = s.id_exercice
|
||||||
//WHERE s.id_user = " . intval($this->id) . "
|
//WHERE s.id_user = " . intval($this->id) . "
|
||||||
//GROUP BY s.id_user, e.id_theme");
|
//GROUP BY s.id_user, e.id_theme");
|
||||||
|
|
||||||
}
|
}
|
Reference in a new issue