diff --git a/db/fic2014.sql b/db/fic2014.sql index ec666486..01945b2e 100644 --- a/db/fic2014.sql +++ b/db/fic2014.sql @@ -100,7 +100,7 @@ CREATE TABLE IF NOT EXISTS `teams` ( `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, `key_hash` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `auth_level` tinyint(1) NOT NULL, - `company` varchar(255) COLLATE utf8_unicode_ci NOT NULL, + `slogan` varchar(64) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; @@ -113,9 +113,10 @@ CREATE TABLE IF NOT EXISTS `teams` ( CREATE TABLE IF NOT EXISTS `team_members` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `id_team` int(10) unsigned NOT NULL, - `firstname` varchar(255) COLLATE utf8_unicode_ci NOT NULL, - `lastname` varchar(255) COLLATE utf8_unicode_ci NOT NULL, - `nickname` varchar(255) COLLATE utf8_unicode_ci NOT NULL, + `firstname` varchar(32) COLLATE utf8_unicode_ci NOT NULL, + `lastname` varchar(32) COLLATE utf8_unicode_ci NOT NULL, + `nickname` varchar(32) COLLATE utf8_unicode_ci NOT NULL, + `company` varchar(32) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; @@ -127,6 +128,6 @@ CREATE TABLE IF NOT EXISTS `team_members` ( CREATE TABLE IF NOT EXISTS `themes` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL, + `name` varchar(32) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; diff --git a/onyx/include/common.php b/onyx/include/common.php index 6754e327..6e0f0067 100644 --- a/onyx/include/common.php +++ b/onyx/include/common.php @@ -7,6 +7,7 @@ if (empty($sess->values["connected"]) && !defined("xCSRF")) require_once("functions.php"); //Inclusion des principales fonctions require_once("common/Exercice.class.php"); +require_once("common/Member.class.php"); require_once("common/Team.class.php"); require_once("common/Theme.class.php"); diff --git a/onyx/include/common/Member.class.php b/onyx/include/common/Member.class.php new file mode 100644 index 00000000..677b9c37 --- /dev/null +++ b/onyx/include/common/Member.class.php @@ -0,0 +1,84 @@ +unique_query("SELECT id, id_team, firstname, lastname, nickname, company + FROM team_members WHERE id=" . intval($id)) or die($db->erreur()); + $db->deconnexion(); + + if (!empty($res)) + { + $this->id = $res['id']; + if (empty($team)) + $this->team = $res['id_team']; + else + $this->team = $team; + $this->firstname = $res['firstname']; + $this->lastname = $res['lastname']; + $this->nickname = $res['nickname']; + $this->company = $res['company']; + } + } + } + + function update() + { + $firstname = $this->firstname; + $lastname = $this->lastname; + $nickname = $this->nickname; + $company = $this->company; + + if (gettype($this->team) != "object") + $id_team = intval($this->team); + else + $id_team = $this->team->id; + + $db = new BDD(); + $db->escape($firstname); + $db->escape($lastname); + $db->escape($nickname); + $db->escape($company); + + if (empty($this->id)) + { + $db->query("INSERT INTO team_members + VALUES (NULL, ".intval($id_team).", '".$firstname."', '".$lastname."', '".$nickname."', '".$company."')"); + $this->id = $db->insert_id(); + $aff = ($this->id > 0); + } + else + { + $db->query("UPDATE team_members + SET id_team = ".intval($id_team).", firstname = '$firstname', lastname = '$lastname', nickname = '$lastname', company = '$company' + WHERE id = ".intval($this->id)); + $aff = $db->affected(); + } + $db->deconnexion(); + + return ($aff == 1); + } + + function get_team() + { + if (gettype($this->team) != "object") + $this->team = new Team(intval($this->team)); + + return $this->team; + } +} + +?> \ No newline at end of file diff --git a/onyx/include/common/Team.class.php b/onyx/include/common/Team.class.php index 4debbf23..aeeb6799 100644 --- a/onyx/include/common/Team.class.php +++ b/onyx/include/common/Team.class.php @@ -17,8 +17,8 @@ class Team var $id = null; var $key_hash; var $auth_level; - var $company; - var $members = null; + var $slogan; + var $members = array(); var $points = null; // Constructor @@ -27,14 +27,14 @@ class Team if (!empty($id)) { $db = new BDD(); - $res = $db->unique_query("SELECT id, key_hash, company, auth_level + $res = $db->unique_query("SELECT id, key_hash, slogan, auth_level FROM teams WHERE id=" . intval($id)) or die($db->erreur()); if (!empty($res)) { $this->id = $res['id']; $this->key_hash = $res['key_hash']; - $this->company = $res['company']; + $this->slogan = $res['slogan']; $this->auth_level = $res['auth_level']; } $db->deconnexion(); @@ -46,23 +46,23 @@ class Team { $key_hash = $this->key_hash; $auth_level = intval($this->auth_level); - $company = $this->company; + $slogan = $this->slogan; $db = new BDD(); $db->escape($key_hash); - $db->escape($company); + $db->escape($slogan); if (empty($this->id)) { $db->query("INSERT INTO teams - VALUES (NULL, '".$key_hash."', ".$auth_level.", '".$company."')"); + VALUES (NULL, '".$key_hash."', ".$auth_level.", '".$slogan."')"); $this->id = $db->insert_id(); $aff = ($this->id > 0); } else { - $db->query("UPDATE users - SET auth_level = ".$auth_level.", key_hash = '".$key_hash."', company = '".$company."' + $db->query("UPDATE teams + SET auth_level = ".$auth_level.", key_hash = '".$key_hash."', slogan = '".$slogan."' WHERE id = ".intval($this->id)); $aff = $db->affected(); } @@ -75,8 +75,8 @@ class Team return $this->id; } - function get_company() { - return $this->company; + function get_slogan() { + return $this->slogan; } function get_auth_level() { @@ -85,18 +85,17 @@ class Team function get_members() { - if(!isset($this->members)) + if(count($this->members) == 0) { $db = new BDD(); - $res = $db->query("SELECT id, firstname, lastname, nickname - FROM team_members + $res = $db->query("SELECT id FROM team_members WHERE id_team = " . intval($this->id)); $db->deconnexion(); - if (!empty($res)) - $this->members = $res; + foreach($res as $member) + $this->members[] = new Member($member["id"], $this); } return $this->members; @@ -117,9 +116,9 @@ class Team $db->deconnexion(); if (!empty($res)) - { $this->points = $res['sum_points']; - } + else + $this->points = 0; } return $this->points; diff --git a/onyx/tpl/bootstrap/public/team.tpl b/onyx/tpl/bootstrap/public/team.tpl index f9a9f87f..39094e42 100644 --- a/onyx/tpl/bootstrap/public/team.tpl +++ b/onyx/tpl/bootstrap/public/team.tpl @@ -1,14 +1,14 @@ {extends file="layout.tpl"} {block name=content}