Refacoring of DBLayer seems to work now :)

This commit is contained in:
Quitta 2013-07-10 12:36:14 +02:00
parent 18bc121efd
commit 423982a9d1
19 changed files with 111 additions and 172 deletions

View file

@ -5,53 +5,39 @@ class DBLayer{
function __construct($db) function __construct($db)
{ {
try{ global $cfg;
$dsn = "mysql:"; $dsn = "mysql:";
$dsn .= "host=". $db['host'].";"; $dsn .= "host=". $cfg['db'][$db]['host'].";";
$dsn .= "dbname=". $db['name'].";"; $dsn .= "dbname=". $cfg['db'][$db]['name'].";";
$dsn .= "port=". $db['port'].";"; $dsn .= "port=". $cfg['db'][$db]['port'].";";
$opt = array( $opt = array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
); );
$this->PDO = new PDO($dsn,$db['user'],$db['pass'], $opt); $this->PDO = new PDO($dsn,$cfg['db'][$db]['user'],$cfg['db'][$db]['pass'], $opt);
}catch (PDOException $e) {
throw $e;
}
} }
public function executeWithoutParams($query){ public function executeWithoutParams($query){
try{ $statement = $this->PDO->prepare($query);
$statement = $this->PDO->prepare($query); $statement->execute();
$statement->execute(); return $statement;
return $statement;
}catch (PDOException $e) {
throw $e;
}
} }
public function execute($query,$params){ public function execute($query,$params){
try{ $statement = $this->PDO->prepare($query);
$statement = $this->PDO->prepare($query); $statement->execute($params);
$statement->execute($params); return $statement;
return $statement;
}catch (PDOException $e) {
throw $e;
}
} }
public function executeReturnId($query,$params){ public function executeReturnId($query,$params){
try{ $statement = $this->PDO->prepare($query);
$statement = $this->PDO->prepare($query); $this->PDO->beginTransaction();
$this->PDO->beginTransaction(); $statement->execute($params);
$statement->execute($params); $lastId =$this->PDO->lastInsertId();
$lastId =$this->PDO->lastInsertId(); $this->PDO->commit();
$this->PDO->commit(); return $lastId;
return $lastId;
}catch (PDOException $e) {
throw $e;
}
} }
} }

View file

@ -1,10 +0,0 @@
<?php
class Sql{
public function db_query( $query, $values = array() )
{
echo "tst";
}
}

View file

@ -14,13 +14,11 @@ class Sync{
*/ */
static public function syncdata () { static public function syncdata () {
global $cfg;
try { try {
$dbl = new DBLayer($cfg['db']['lib']); $dbl = new DBLayer("lib");
$statement = $dbl->executeWithoutParams("SELECT * FROM ams_querycache"); $statement = $dbl->executeWithoutParams("SELECT * FROM ams_querycache");
$rows = $statement->fetchAll(); $rows = $statement->fetchAll();
$dbs = new DBLayer($cfg['db']['shard']); $dbs = new DBLayer("shard");
foreach ($rows as $record) { foreach ($rows as $record) {
switch($record['type']) { switch($record['type']) {

View file

@ -8,7 +8,6 @@ class Ticket{
private $queue; private $queue;
private $ticket_category; private $ticket_category;
private $author; private $author;
private $db;
////////////////////////////////////////////Functions//////////////////////////////////////////////////// ////////////////////////////////////////////Functions////////////////////////////////////////////////////
@ -16,10 +15,10 @@ class Ticket{
* return all ticket of the given author's id. * return all ticket of the given author's id.
* *
*/ */
public static function getEntireTicket($id, $db_data) { public static function getEntireTicket($id) {
$ticket = new Ticket($db_data); $ticket = new Ticket();
$ticket->load_With_TId($id); $ticket->load_With_TId($id);
$reply_array = Ticket_Reply::getRepliesOfTicket($id,$db_data); $reply_array = Ticket_Reply::getRepliesOfTicket($id);
return Array('ticket_obj' => $ticket,'reply_array' => $reply_array); return Array('ticket_obj' => $ticket,'reply_array' => $reply_array);
} }
@ -28,13 +27,13 @@ class Ticket{
* return all ticket of the given author's id. * return all ticket of the given author's id.
* *
*/ */
public static function getTicketsOf($author, $db_data) { public static function getTicketsOf($author) {
$dbl = new DBLayer($db_data); $dbl = new DBLayer("lib");
$statement = $dbl->execute("SELECT * FROM ticket INNER JOIN ticket_user ON ticket.Author = ticket_user.TUserId and ticket_user.ExternId=:id", array('id' => $author)); $statement = $dbl->execute("SELECT * FROM ticket INNER JOIN ticket_user ON ticket.Author = ticket_user.TUserId and ticket_user.ExternId=:id", array('id' => $author));
$row = $statement->fetchAll(); $row = $statement->fetchAll();
$result = Array(); $result = Array();
foreach($row as $ticket){ foreach($row as $ticket){
$instance = new self($db_data); $instance = new self();
$instance->setTId($ticket['TId']); $instance->setTId($ticket['TId']);
$instance->setTimestamp($ticket['Timestamp']); $instance->setTimestamp($ticket['Timestamp']);
$instance->setTitle($ticket['Title']); $instance->setTitle($ticket['Title']);
@ -52,21 +51,21 @@ class Ticket{
* creates a ticket + first initial reply and fills in the content of it! * creates a ticket + first initial reply and fills in the content of it!
* *
*/ */
public static function create_Ticket( $title, $content, $category, $author, $db_data) { public static function create_Ticket( $title, $content, $category, $author) {
$ticket = new Ticket($db_data); $ticket = new Ticket();
$ticket->set($title,0,0,$category,$author); $ticket->set($title,0,0,$category,$author);
$ticket->create(); $ticket->create();
$ticket_id = $ticket->getTId(); $ticket_id = $ticket->getTId();
$ticket_content = new Ticket_Content($db_data); $ticket_content = new Ticket_Content();
$ticket_content->setContent($content); $ticket_content->setContent($content);
$ticket_content->create(); $ticket_content->create();
$content_id = $ticket_content->getTContentId(); $content_id = $ticket_content->getTContentId();
$ticket_reply = new Ticket_Reply($db_data); $ticket_reply = new Ticket_Reply();
$ticket_reply->set($ticket_id, $content_id, $author); $ticket_reply->set($ticket_id, $content_id, $author);
$ticket_reply->create(); $ticket_reply->create();
@ -75,8 +74,8 @@ class Ticket{
} }
////////////////////////////////////////////Methods//////////////////////////////////////////////////// ////////////////////////////////////////////Methods////////////////////////////////////////////////////
public function __construct($db_data) { public function __construct() {
$this->db = $db_data;
} }
@ -91,7 +90,7 @@ class Ticket{
//create ticket by writing private data to DB. //create ticket by writing private data to DB.
public function create(){ public function create(){
$dbl = new DBLayer($this->db); $dbl = new DBLayer("lib");
$query = "INSERT INTO ticket (Timestamp, Title, Status, Queue, Ticket_Category, Author) VALUES (now(), :title, :status, :queue, :tcat, :author)"; $query = "INSERT INTO ticket (Timestamp, Title, Status, Queue, Ticket_Category, Author) VALUES (now(), :title, :status, :queue, :tcat, :author)";
$values = Array('title' => $this->title, 'status' => $this->status, 'queue' => $this->queue, 'tcat' => $this->ticket_category, 'author' => $this->author); $values = Array('title' => $this->title, 'status' => $this->status, 'queue' => $this->queue, 'tcat' => $this->ticket_category, 'author' => $this->author);
$this->tId = $dbl->executeReturnId($query, $values); ; $this->tId = $dbl->executeReturnId($query, $values); ;
@ -99,7 +98,7 @@ class Ticket{
//return constructed element based on TId //return constructed element based on TId
public function load_With_TId( $id) { public function load_With_TId( $id) {
$dbl = new DBLayer($this->db); $dbl = new DBLayer("lib");
$statement = $dbl->execute("SELECT * FROM ticket WHERE TId=:id", array('id' => $id)); $statement = $dbl->execute("SELECT * FROM ticket WHERE TId=:id", array('id' => $id));
$row = $statement->fetch(); $row = $statement->fetch();
$this->tId = $row['TId']; $this->tId = $row['TId'];
@ -114,7 +113,7 @@ class Ticket{
//update private data to DB. //update private data to DB.
public function update(){ public function update(){
$dbl = new DBLayer($this->db); $dbl = new DBLayer("lib");
$query = "UPDATE ticket SET Timestamp = :timestamp, Title = :title, Status = :status, Queue = :queue, Ticket_Category = :tcat, Author = :author WHERE TId=:id"; $query = "UPDATE ticket SET Timestamp = :timestamp, Title = :title, Status = :status, Queue = :queue, Ticket_Category = :tcat, Author = :author WHERE TId=:id";
$values = Array('id' => $this->tId, 'timestamp' => $this->timestamp, 'title' => $this->title, 'status' => $this->status, 'queue' => $this->queue, 'tcat' => $this->ticket_category, 'author' => $this->author); $values = Array('id' => $this->tId, 'timestamp' => $this->timestamp, 'title' => $this->title, 'status' => $this->status, 'queue' => $this->queue, 'tcat' => $this->ticket_category, 'author' => $this->author);
$statement = $dbl->execute($query, $values); $statement = $dbl->execute($query, $values);
@ -152,8 +151,7 @@ class Ticket{
} }
public function getCategoryName(){ public function getCategoryName(){
global $cfg; $category = Ticket_Category::constr_TCategoryId($this->getTicket_Category());
$category = Ticket_Category::constr_TCategoryId($this->getTicket_Category(), $cfg['db']['lib']);
return $category->getName(); return $category->getName();
} }

View file

@ -9,8 +9,8 @@ class Ticket_Category{
//Creates a ticket_Catergory in the DB //Creates a ticket_Catergory in the DB
public static function createTicketCategory( $name ,$db ) { public static function createTicketCategory( $name) {
$dbl = new DBLayer($db); $dbl = new DBLayer("lib");
$query = "INSERT INTO ticket_category (Name) VALUES (:name)"; $query = "INSERT INTO ticket_category (Name) VALUES (:name)";
$values = Array('name' => $name); $values = Array('name' => $name);
$dbl->execute($query, $values); $dbl->execute($query, $values);
@ -19,20 +19,20 @@ class Ticket_Category{
//return constructed element based on TCategoryId //return constructed element based on TCategoryId
public static function constr_TCategoryId( $id, $db_data) { public static function constr_TCategoryId( $id) {
$instance = new self($db_data); $instance = new self();
$instance->setTCategoryId($id); $instance->setTCategoryId($id);
return $instance; return $instance;
} }
//returns list of all category objects //returns list of all category objects
public static function getAllCategories($db_data) { public static function getAllCategories() {
$dbl = new DBLayer($db_data); $dbl = new DBLayer("lib");
$statement = $dbl->executeWithoutParams("SELECT * FROM ticket_category"); $statement = $dbl->executeWithoutParams("SELECT * FROM ticket_category");
$row = $statement->fetchAll(); $row = $statement->fetchAll();
$result = Array(); $result = Array();
foreach($row as $category){ foreach($row as $category){
$instance = new self($db_data); $instance = new self();
$instance->tCategoryId = $category['TCategoryId']; $instance->tCategoryId = $category['TCategoryId'];
$instance->name = $category['Name']; $instance->name = $category['Name'];
$result[] = $instance; $result[] = $instance;
@ -43,13 +43,12 @@ class Ticket_Category{
////////////////////////////////////////////Methods//////////////////////////////////////////////////// ////////////////////////////////////////////Methods////////////////////////////////////////////////////
public function __construct($db_data) { public function __construct() {
$this->db = $db_data;
} }
//return constructed element based on TCategoryId //return constructed element based on TCategoryId
public function load_With_TCategoryId( $id) { public function load_With_TCategoryId( $id) {
$dbl = new DBLayer($this->db); $dbl = new DBLayer("lib");
$statement = $dbl->execute("SELECT * FROM ticket_category WHERE TCategoryId=:id", array('id' => $id)); $statement = $dbl->execute("SELECT * FROM ticket_category WHERE TCategoryId=:id", array('id' => $id));
$row = $statement->fetch(); $row = $statement->fetch();
$this->tCategoryId = $row['TCategoryId']; $this->tCategoryId = $row['TCategoryId'];
@ -59,7 +58,7 @@ class Ticket_Category{
//update private data to DB. //update private data to DB.
public function update(){ public function update(){
$dbl = new DBLayer($this->db); $dbl = new DBLayer("lib");
$query = "UPDATE ticket_category SET Name = :name WHERE TCategoryId=:id"; $query = "UPDATE ticket_category SET Name = :name WHERE TCategoryId=:id";
$values = Array('id' => $this->tCategoryId, 'name' => $this->name); $values = Array('id' => $this->tCategoryId, 'name' => $this->name);
$statement = $dbl->execute($query, $values); $statement = $dbl->execute($query, $values);

View file

@ -9,8 +9,8 @@ class Ticket_Content{
////////////////////////////////////////////Functions//////////////////////////////////////////////////// ////////////////////////////////////////////Functions////////////////////////////////////////////////////
//return constructed element based on TCategoryId //return constructed element based on TCategoryId
public static function constr_TContentId( $id, $db_data) { public static function constr_TContentId( $id) {
$instance = new self($db_data); $instance = new self();
$instance->setTContentId($id); $instance->setTContentId($id);
return $instance; return $instance;
} }
@ -18,13 +18,12 @@ class Ticket_Content{
////////////////////////////////////////////Methods//////////////////////////////////////////////////// ////////////////////////////////////////////Methods////////////////////////////////////////////////////
public function __construct($db_data) { public function __construct() {
$this->db = $db_data;
} }
//Creates a ticket_content entry in the DB //Creates a ticket_content entry in the DB
public function create() { public function create() {
$dbl = new DBLayer($this->db); $dbl = new DBLayer("lib");
$query = "INSERT INTO ticket_content (Content) VALUES (:content)"; $query = "INSERT INTO ticket_content (Content) VALUES (:content)";
$values = Array('content' => $this->content); $values = Array('content' => $this->content);
$this->tContentId = $dbl->executeReturnId($query, $values); ; $this->tContentId = $dbl->executeReturnId($query, $values); ;
@ -32,7 +31,7 @@ class Ticket_Content{
//return constructed element based on TContentId //return constructed element based on TContentId
public function load_With_TContentId( $id) { public function load_With_TContentId( $id) {
$dbl = new DBLayer($this->db); $dbl = new DBLayer("lib");
$statement = $dbl->execute("SELECT * FROM ticket_content WHERE TContentId=:id", array('id' => $id)); $statement = $dbl->execute("SELECT * FROM ticket_content WHERE TContentId=:id", array('id' => $id));
$row = $statement->fetch(); $row = $statement->fetch();
$this->tContentId = $row['TContentId']; $this->tContentId = $row['TContentId'];
@ -41,7 +40,7 @@ class Ticket_Content{
//update private data to DB. //update private data to DB.
public function update(){ public function update(){
$dbl = new DBLayer($this->db); $dbl = new DBLayer("lib");
$query = "UPDATE ticket_content SET Content = :content WHERE TContentId=:id"; $query = "UPDATE ticket_content SET Content = :content WHERE TContentId=:id";
$values = Array('id' => $this->tContentId, 'content' => $this->content); $values = Array('id' => $this->tContentId, 'content' => $this->content);
$statement = $dbl->execute($query, $values); $statement = $dbl->execute($query, $values);

View file

@ -6,30 +6,29 @@ class Ticket_Reply{
private $content; private $content;
private $author; private $author;
private $timestamp; private $timestamp;
private $db;
////////////////////////////////////////////Functions//////////////////////////////////////////////////// ////////////////////////////////////////////Functions////////////////////////////////////////////////////
//return constructed element based on TCategoryId //return constructed element based on TCategoryId
public static function constr_TReplyId( $id, $db_data) { public static function constr_TReplyId( $id) {
$instance = new self($db_data); $instance = new self();
$instance->setTReplyId($id); $instance->setTReplyId($id);
return $instance; return $instance;
} }
//return constructed element based on TCategoryId //return constructed element based on TCategoryId
public static function getRepliesOfTicket( $ticket_id, $db_data) { public static function getRepliesOfTicket( $ticket_id) {
$dbl = new DBLayer($db_data); $dbl = new DBLayer("lib");
$statement = $dbl->execute("SELECT * FROM ticket_reply INNER JOIN ticket_content ON ticket_reply.Content = ticket_content.TContentId and ticket_reply.Ticket=:id", array('id' => $ticket_id)); $statement = $dbl->execute("SELECT * FROM ticket_reply INNER JOIN ticket_content ON ticket_reply.Content = ticket_content.TContentId and ticket_reply.Ticket=:id", array('id' => $ticket_id));
$row = $statement->fetchAll(); $row = $statement->fetchAll();
$result = Array(); $result = Array();
foreach($row as $tReply){ foreach($row as $tReply){
$instanceReply = new self($db_data); $instanceReply = new self();
$instanceReply->setTReplyId($tReply['TReplyId']); $instanceReply->setTReplyId($tReply['TReplyId']);
$instanceReply->setTimestamp($tReply['Timestamp']); $instanceReply->setTimestamp($tReply['Timestamp']);
$instanceReply->set($tReply['Ticket'],$tReply['Content'],$tReply['Author']); $instanceReply->set($tReply['Ticket'],$tReply['Content'],$tReply['Author']);
$instanceContent = new Ticket_Content($db_data); $instanceContent = new Ticket_Content();
$instanceContent->setTContentId($tReply['TContentId']); $instanceContent->setTContentId($tReply['TContentId']);
$instanceContent->setContent($tReply['Content']); $instanceContent->setContent($tReply['Content']);
@ -42,8 +41,7 @@ class Ticket_Reply{
////////////////////////////////////////////Methods//////////////////////////////////////////////////// ////////////////////////////////////////////Methods////////////////////////////////////////////////////
public function __construct($db_data) { public function __construct() {
$this->db = $db_data;
} }
@ -56,7 +54,7 @@ class Ticket_Reply{
//create ticket by writing private data to DB. //create ticket by writing private data to DB.
public function create(){ public function create(){
$dbl = new DBLayer($this->db); $dbl = new DBLayer("lib");
$query = "INSERT INTO ticket_reply (Ticket, Content, Author, Timestamp) VALUES (:ticket, :content, :author, now())"; $query = "INSERT INTO ticket_reply (Ticket, Content, Author, Timestamp) VALUES (:ticket, :content, :author, now())";
$values = Array('ticket' => $this->ticket, 'content' => $this->content, 'author' => $this->author); $values = Array('ticket' => $this->ticket, 'content' => $this->content, 'author' => $this->author);
$dbl->execute($query, $values); $dbl->execute($query, $values);
@ -64,7 +62,7 @@ class Ticket_Reply{
//return constructed element based on TId //return constructed element based on TId
public function load_With_TReplyId( $id) { public function load_With_TReplyId( $id) {
$dbl = new DBLayer($this->db); $dbl = new DBLayer("lib");
$statement = $dbl->execute("SELECT * FROM ticket_reply WHERE TReplyId=:id", array('id' => $id)); $statement = $dbl->execute("SELECT * FROM ticket_reply WHERE TReplyId=:id", array('id' => $id));
$row = $statement->fetch(); $row = $statement->fetch();
$this->tReplyId = $row['TReplyId']; $this->tReplyId = $row['TReplyId'];
@ -76,7 +74,7 @@ class Ticket_Reply{
//update private data to DB. //update private data to DB.
public function update(){ public function update(){
$dbl = new DBLayer($this->db); $dbl = new DBLayer("lib");
$query = "UPDATE ticket SET Ticket = :ticket, Content = :content, Author = :author, Timestamp = :timestamp WHERE TReplyId=:id"; $query = "UPDATE ticket SET Ticket = :ticket, Content = :content, Author = :author, Timestamp = :timestamp WHERE TReplyId=:id";
$values = Array('id' => $this->tReplyId, 'timestamp' => $this->timestamp, 'ticket' => $this->ticket, 'content' => $this->content, 'author' => $this->author); $values = Array('id' => $this->tReplyId, 'timestamp' => $this->timestamp, 'ticket' => $this->ticket, 'content' => $this->content, 'author' => $this->author);
$statement = $dbl->execute($query, $values); $statement = $dbl->execute($query, $values);

View file

@ -4,13 +4,12 @@ class Ticket_User{
private $tUserId; private $tUserId;
private $permission; private $permission;
private $externId; private $externId;
private $db;
////////////////////////////////////////////Functions//////////////////////////////////////////////////// ////////////////////////////////////////////Functions////////////////////////////////////////////////////
//Creates a ticket_user in the DB //Creates a ticket_user in the DB
public static function createTicketUser( $extern_id, $permission,$db ) { public static function createTicketUser( $extern_id, $permission) {
$dbl = new DBLayer($db); $dbl = new DBLayer("lib");
$query = "INSERT INTO ticket_user (Permission, ExternId) VALUES (:perm, :ext_id)"; $query = "INSERT INTO ticket_user (Permission, ExternId) VALUES (:perm, :ext_id)";
$values = Array('perm' => $permission, 'ext_id' => $extern_id); $values = Array('perm' => $permission, 'ext_id' => $extern_id);
$dbl->execute($query, $values); $dbl->execute($query, $values);
@ -19,17 +18,17 @@ class Ticket_User{
//return constructed element based on TUserId //return constructed element based on TUserId
public static function constr_TUserId( $id, $db_data) { public static function constr_TUserId( $id) {
$instance = new self($db_data); $instance = new self();
$instance->setTUserId($id); $instance->setTUserId($id);
return $instance; return $instance;
} }
//return constructed element based on ExternId //return constructed element based on ExternId
public static function constr_ExternId( $id, $db_data ) { public static function constr_ExternId( $id) {
$instance = new self($db_data); $instance = new self();
$dbl = new DBLayer($instance->db); $dbl = new DBLayer("lib");
$statement = $dbl->execute("SELECT * FROM ticket_user WHERE ExternId=:id", array('id' => $id)); $statement = $dbl->execute("SELECT * FROM ticket_user WHERE ExternId=:id", array('id' => $id));
$row = $statement->fetch(); $row = $statement->fetch();
$instance->tUserId = $row['TUserId']; $instance->tUserId = $row['TUserId'];
@ -41,13 +40,12 @@ class Ticket_User{
////////////////////////////////////////////Methods//////////////////////////////////////////////////// ////////////////////////////////////////////Methods////////////////////////////////////////////////////
public function __construct($db_data) { public function __construct() {
$this->db = $db_data;
} }
//return constructed element based on TUserId //return constructed element based on TUserId
public function load_With_TUserId( $id) { public function load_With_TUserId( $id) {
$dbl = new DBLayer($this->db); $dbl = new DBLayer("lib");
$statement = $dbl->execute("SELECT * FROM ticket_user WHERE TUserId=:id", array('id' => $id)); $statement = $dbl->execute("SELECT * FROM ticket_user WHERE TUserId=:id", array('id' => $id));
$row = $statement->fetch(); $row = $statement->fetch();
$instance->tUserId = $row['TUserId']; $instance->tUserId = $row['TUserId'];
@ -58,7 +56,7 @@ class Ticket_User{
//update private data to DB. //update private data to DB.
public function update(){ public function update(){
$dbl = new DBLayer($this->db); $dbl = new DBLayer("lib");
$query = "UPDATE ticket_user SET Permission = :perm, ExternId = :ext_id WHERE TUserId=:id"; $query = "UPDATE ticket_user SET Permission = :perm, ExternId = :ext_id WHERE TUserId=:id";
$values = Array('id' => $this->tUserId, 'perm' => $this->permission, 'ext_id' => $this->externId); $values = Array('id' => $this->tUserId, 'perm' => $this->permission, 'ext_id' => $this->externId);
$statement = $dbl->execute($query, $values); $statement = $dbl->execute($query, $values);

View file

@ -287,19 +287,18 @@ class Users{
public function createUser($values, $user_id){ public function createUser($values, $user_id){
try { try {
//make connection with and put into shard db //make connection with and put into shard db
global $cfg; $dbs = new DBLayer("shard");
$dbs = new DBLayer($cfg['db']['shard']);
$dbs->execute("INSERT INTO user (Login, Password, Email) VALUES (:name, :pass, :mail)",$values); $dbs->execute("INSERT INTO user (Login, Password, Email) VALUES (:name, :pass, :mail)",$values);
ticket_user::createTicketUser( $user_id , 1, $cfg['db']['lib'] ); ticket_user::createTicketUser( $user_id, 1);
return "ok"; return "ok";
} }
catch (PDOException $e) { catch (PDOException $e) {
//oh noooz, the shard is offline! Put in query queue at ams_lib db! //oh noooz, the shard is offline! Put in query queue at ams_lib db!
try { try {
$dbl = new DBLayer($cfg['db']['lib']); $dbl = new DBLayer("lib");
$dbl->execute("INSERT INTO ams_querycache (type, query) VALUES (:type, :query)",array("type" => "createUser", $dbl->execute("INSERT INTO ams_querycache (type, query) VALUES (:type, :query)",array("type" => "createUser",
"query" => json_encode(array($values["name"],$values["pass"],$values["mail"])))); "query" => json_encode(array($values["name"],$values["pass"],$values["mail"]))));
ticket_user::createTicketUser( $user_id , 1, $cfg['db']['lib'] ); ticket_user::createTicketUser( $user_id , 1 );
return "shardoffline"; return "shardoffline";
}catch (PDOException $e) { }catch (PDOException $e) {
print_r($e); print_r($e);
@ -369,19 +368,18 @@ class Users{
protected function setAmsPassword($user, $pass){ protected function setAmsPassword($user, $pass){
global $cfg;
$values = Array('user' => $user, 'pass' => $pass); $values = Array('user' => $user, 'pass' => $pass);
try { try {
//make connection with and put into shard db //make connection with and put into shard db
$dbs = new DBLayer($cfg['db']['shard']); $dbs = new DBLayer("shard");
$dbs->execute("UPDATE user SET Password = :pass WHERE Login = :user ",$values); $dbs->execute("UPDATE user SET Password = :pass WHERE Login = :user ",$values);
return "ok"; return "ok";
} }
catch (PDOException $e) { catch (PDOException $e) {
//oh noooz, the shard is offline! Put in query queue at ams_lib db! //oh noooz, the shard is offline! Put in query queue at ams_lib db!
try { try {
$dbl = new DBLayer($cfg['db']['lib']); $dbl = new DBLayer("lib");
$dbl->execute("INSERT INTO ams_querycache (type, query) VALUES (:type, :query)",array("type" => "change_pass", $dbl->execute("INSERT INTO ams_querycache (type, query) VALUES (:type, :query)",array("type" => "change_pass",
"query" => json_encode(array($values["user"],$values["pass"])))); "query" => json_encode(array($values["user"],$values["pass"]))));
return "shardoffline"; return "shardoffline";
@ -393,19 +391,18 @@ class Users{
protected function setAmsEmail($user, $mail){ protected function setAmsEmail($user, $mail){
global $cfg;
$values = Array('user' => $user, 'mail' => $mail); $values = Array('user' => $user, 'mail' => $mail);
try { try {
//make connection with and put into shard db //make connection with and put into shard db
$dbs = new DBLayer($cfg['db']['shard']); $dbs = new DBLayer("shard");
$dbs->execute("UPDATE user SET Email = :mail WHERE Login = :user ",$values); $dbs->execute("UPDATE user SET Email = :mail WHERE Login = :user ",$values);
return "ok"; return "ok";
} }
catch (PDOException $e) { catch (PDOException $e) {
//oh noooz, the shard is offline! Put in query queue at ams_lib db! //oh noooz, the shard is offline! Put in query queue at ams_lib db!
try { try {
$dbl = new DBLayer($cfg['db']['lib']); $dbl = new DBLayer("lib");
$dbl->execute("INSERT INTO ams_querycache (type, query) VALUES (:type, :query)",array("type" => "change_mail", $dbl->execute("INSERT INTO ams_querycache (type, query) VALUES (:type, :query)",array("type" => "change_mail",
"query" => json_encode(array($values["user"],$values["mail"])))); "query" => json_encode(array($values["user"],$values["mail"]))));
return "shardoffline"; return "shardoffline";

View file

@ -9,8 +9,7 @@ class WebUsers extends Users{
* @return string Info: Returns true or false if the user is in the web db. * @return string Info: Returns true or false if the user is in the web db.
*/ */
protected function checkUserNameExists($username){ protected function checkUserNameExists($username){
global $cfg; $dbw = new DBLayer("web");
$dbw = new DBLayer($cfg['db']['web']);
return $dbw->execute("SELECT * FROM ams_user WHERE Login = :name",array('name' => $username))->rowCount(); return $dbw->execute("SELECT * FROM ams_user WHERE Login = :name",array('name' => $username))->rowCount();
} }
@ -22,8 +21,7 @@ class WebUsers extends Users{
* @return string Info: Returns true or false if the user is in the www db. * @return string Info: Returns true or false if the user is in the www db.
*/ */
protected function checkEmailExists($email){ protected function checkEmailExists($email){
global $cfg; $dbw = new DBLayer("web");
$dbw = new DBLayer($cfg['db']['web']);
return $dbw->execute("SELECT * FROM ams_user WHERE Email = :email",array('email' => $email))->rowCount(); return $dbw->execute("SELECT * FROM ams_user WHERE Email = :email",array('email' => $email))->rowCount();
} }
@ -35,9 +33,7 @@ class WebUsers extends Users{
* @return string Info: Returns true or false if a login match is found in the web db * @return string Info: Returns true or false if a login match is found in the web db
*/ */
public function checkLoginMatch($username,$password){ public function checkLoginMatch($username,$password){
global $cfg; $dbw = new DBLayer("web");
$dbw = new DBLayer($cfg['db']['web']);
$statement = $dbw->execute("SELECT * FROM ams_user WHERE Login=:user", array('user' => $username)); $statement = $dbw->execute("SELECT * FROM ams_user WHERE Login=:user", array('user' => $username));
$row = $statement->fetch(); $row = $statement->fetch();
@ -51,36 +47,28 @@ class WebUsers extends Users{
} }
public function getId($username){ public function getId($username){
global $cfg; $dbw = new DBLayer("web");
$dbw = new DBLayer($cfg['db']['web']);
$statement = $dbw->execute("SELECT * FROM ams_user WHERE Login=:username", array('username' => $username)); $statement = $dbw->execute("SELECT * FROM ams_user WHERE Login=:username", array('username' => $username));
$row = $statement->fetch(); $row = $statement->fetch();
return $row['UId']; return $row['UId'];
} }
public function getUsername($id){ public function getUsername($id){
global $cfg; $dbw = new DBLayer("web");
$dbw = new DBLayer($cfg['db']['web']);
$statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $id)); $statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $id));
$row = $statement->fetch(); $row = $statement->fetch();
return $row['Login']; return $row['Login'];
} }
public function getEmail($id){ public function getEmail($id){
global $cfg; $dbw = new DBLayer("web");
$dbw = new DBLayer($cfg['db']['web']);
$statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $id)); $statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $id));
$row = $statement->fetch(); $row = $statement->fetch();
return $row['Email']; return $row['Email'];
} }
public function getInfo($id){ public function getInfo($id){
global $cfg; $dbw = new DBLayer("web");
$dbw = new DBLayer($cfg['db']['web']);
$statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $id)); $statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $id));
$row = $statement->fetch(); $row = $statement->fetch();
$result = Array('FirstName' => $row['FirstName'], 'LastName' => $row['LastName'], 'Gender' => $row['Gender'], 'Country' => $row['Country']); $result = Array('FirstName' => $row['FirstName'], 'LastName' => $row['LastName'], 'Gender' => $row['Gender'], 'Country' => $row['Country']);
@ -102,12 +90,11 @@ class WebUsers extends Users{
} }
public function setPassword($user, $pass){ public function setPassword($user, $pass){
global $cfg;
$reply = WebUsers::setAmsPassword($user, $pass); $reply = WebUsers::setAmsPassword($user, $pass);
$values = Array('user' => $user, 'pass' => $pass); $values = Array('user' => $user, 'pass' => $pass);
try { try {
//make connection with and put into shard db //make connection with and put into shard db
$dbw = new DBLayer($cfg['db']['web']); $dbw = new DBLayer("web");
$dbw->execute("UPDATE ams_user SET Password = :pass WHERE Login = :user ",$values); $dbw->execute("UPDATE ams_user SET Password = :pass WHERE Login = :user ",$values);
} }
catch (PDOException $e) { catch (PDOException $e) {
@ -117,12 +104,11 @@ class WebUsers extends Users{
} }
public function setEmail($user, $mail){ public function setEmail($user, $mail){
global $cfg;
$reply = WebUsers::setAmsEmail($user, $mail); $reply = WebUsers::setAmsEmail($user, $mail);
$values = Array('user' => $user, 'mail' => $mail); $values = Array('user' => $user, 'mail' => $mail);
try { try {
//make connection with and put into shard db //make connection with and put into shard db
$dbw = new DBLayer($cfg['db']['web']); $dbw = new DBLayer("web");
$dbw->execute("UPDATE ams_user SET Email = :mail WHERE Login = :user ",$values); $dbw->execute("UPDATE ams_user SET Email = :mail WHERE Login = :user ",$values);
} }
catch (PDOException $e) { catch (PDOException $e) {
@ -132,8 +118,7 @@ class WebUsers extends Users{
} }
public function getUsers(){ public function getUsers(){
global $cfg; $dbl = new DBLayer("web");
$dbl = new DBLayer($cfg['db']['web']);
$data = $dbl->executeWithoutParams("SELECT * FROM ams_user"); $data = $dbl->executeWithoutParams("SELECT * FROM ams_user");
return $data; return $data;
} }

View file

@ -47,9 +47,8 @@ function write_user($newUser){
); );
try{ try{
global $cfg;
//make connection with web db and put it in there //make connection with web db and put it in there
$dbw = new DBLayer($cfg['db']['web']); $dbw = new DBLayer("web");
$user_id = $dbw->executeReturnId("INSERT INTO ams_user (Login, Password, Email) VALUES (:name, :pass, :mail)",$params); $user_id = $dbw->executeReturnId("INSERT INTO ams_user (Login, Password, Email) VALUES (:name, :pass, :mail)",$params);
//Create the user on the shard + in case shard is offline put copy of query in query db //Create the user on the shard + in case shard is offline put copy of query in query db

View file

@ -70,9 +70,8 @@ function change_info(){
//if some field is update then: //if some field is update then:
if($updated){ if($updated){
global $cfg;
//execute the query in the web DB. //execute the query in the web DB.
$dbw = new DBLayer($cfg['db']['web']); $dbw = new DBLayer("web");
$dbw->execute($query,$values); $dbw->execute($query,$values);
} }

View file

@ -9,7 +9,6 @@ function create_ticket(){
//if target_id is the same as session id or is admin //if target_id is the same as session id or is admin
if( ($_POST['target_id'] == $_SESSION['id']) || WebUsers::isAdmin() ){ if( ($_POST['target_id'] == $_SESSION['id']) || WebUsers::isAdmin() ){
global $cfg;
$category = filter_var($_POST['Category'], FILTER_SANITIZE_NUMBER_INT); $category = filter_var($_POST['Category'], FILTER_SANITIZE_NUMBER_INT);
$title = filter_var($_POST['Title'], FILTER_SANITIZE_STRING); $title = filter_var($_POST['Title'], FILTER_SANITIZE_STRING);
$content = filter_var($_POST['Content'], FILTER_SANITIZE_STRING); $content = filter_var($_POST['Content'], FILTER_SANITIZE_STRING);
@ -17,9 +16,9 @@ function create_ticket(){
if($_POST['target_id'] == $_SESSION['id']){ if($_POST['target_id'] == $_SESSION['id']){
$author = $_SESSION['ticket_user']->getTUserId(); $author = $_SESSION['ticket_user']->getTUserId();
}else{ }else{
$author= Ticket_User::constr_ExternId($_POST['target_id'], $cfg['db']['lib'])->getTUserId(); $author= Ticket_User::constr_ExternId($_POST['target_id'])->getTUserId();
} }
Ticket::create_Ticket($title, $content, $category, $author, $cfg['db']['lib'] ); Ticket::create_Ticket($title, $content, $category, $author);
}catch (PDOException $e) { }catch (PDOException $e) {
//ERROR: LIB DB is not online! //ERROR: LIB DB is not online!
header("Location: index.php"); header("Location: index.php");

View file

@ -2,8 +2,6 @@
function login(){ function login(){
global $cfg;
try{ try{
$result = WebUsers::checkLoginMatch($_POST["Username"],$_POST["Password"]); $result = WebUsers::checkLoginMatch($_POST["Username"],$_POST["Password"]);
if( $result != "fail"){ if( $result != "fail"){
@ -11,7 +9,7 @@ function login(){
$_SESSION['user'] = $_POST["Username"]; $_SESSION['user'] = $_POST["Username"];
$_SESSION['permission'] = $result['Permission']; $_SESSION['permission'] = $result['Permission'];
$_SESSION['id'] = $result['UId']; $_SESSION['id'] = $result['UId'];
$_SESSION['ticket_user'] = Ticket_User::constr_ExternId($result['UId'],$cfg['db']['lib']); $_SESSION['ticket_user'] = Ticket_User::constr_ExternId($result['UId']);
//go back to the index page. //go back to the index page.
header( 'Location: index.php' ); header( 'Location: index.php' );

View file

@ -27,8 +27,7 @@ function createticket(){
} }
//create array of category id & names //create array of category id & names
global $cfg; $catArray = Ticket_Category::getAllCategories();
$catArray = Ticket_Category::getAllCategories($cfg['db']['lib']);
$result['category'] = Gui_Elements::make_table_with_key_is_id($catArray, Array("getName"), "getTCategoryId" ); $result['category'] = Gui_Elements::make_table_with_key_is_id($catArray, Array("getName"), "getTCategoryId" );
return $result; return $result;

View file

@ -11,8 +11,7 @@ function libuserlist(){
} }
//Here we count the number of results //Here we count the number of results
global $cfg; $dbl = new DBLayer("lib");
$dbl = new DBLayer($cfg['db']['lib']);
$rows = $dbl->executeWithoutParams("SELECT * FROM ams_querycache")->rowCount(); $rows = $dbl->executeWithoutParams("SELECT * FROM ams_querycache")->rowCount();
//the array hat will contain all users //the array hat will contain all users
@ -53,7 +52,7 @@ function libuserlist(){
//check if shard is online //check if shard is online
try{ try{
$dbs = new DBLayer($cfg['db']['shard']); $dbs = new DBLayer("shard");
$pageResult['shard'] = "online"; $pageResult['shard'] = "online";
}catch(PDOException $e) { }catch(PDOException $e) {
$pageResult['shard'] = "offline"; $pageResult['shard'] = "offline";

View file

@ -4,14 +4,13 @@ function show_ticket(){
//if logged in //if logged in
if(WebUsers::isLoggedIn() && isset($_GET['id'])){ if(WebUsers::isLoggedIn() && isset($_GET['id'])){
global $cfg;
$result['ticket_id'] = filter_var($_GET['id'], FILTER_SANITIZE_NUMBER_INT); $result['ticket_id'] = filter_var($_GET['id'], FILTER_SANITIZE_NUMBER_INT);
$target_ticket = new Ticket($cfg['db']['lib']); $target_ticket = new Ticket();
$target_ticket->load_With_TId($result['ticket_id']); $target_ticket->load_With_TId($result['ticket_id']);
if(($target_ticket->getAuthor() == $_SESSION['ticket_user']->getTUserId()) || WebUsers::isAdmin() ){ if(($target_ticket->getAuthor() == $_SESSION['ticket_user']->getTUserId()) || WebUsers::isAdmin() ){
$entire_ticket = Ticket::getEntireTicket( $result['ticket_id'], $cfg['db']['lib']); $entire_ticket = Ticket::getEntireTicket( $result['ticket_id']);
$result['ticket_tId'] = $entire_ticket['ticket_obj']->getTId(); $result['ticket_tId'] = $entire_ticket['ticket_obj']->getTId();
$result['ticket_title'] = $entire_ticket['ticket_obj']->getTitle(); $result['ticket_title'] = $entire_ticket['ticket_obj']->getTitle();
$result['ticket_replies'] = Gui_Elements::make_table($entire_ticket['reply_array'], Array("getTReplyId","getContent()->getContent","getTimestamp"), Array("tReplyId","replyContent","timestamp")); $result['ticket_replies'] = Gui_Elements::make_table($entire_ticket['reply_array'], Array("getTReplyId","getContent()->getContent","getTimestamp"), Array("tReplyId","replyContent","timestamp"));

View file

@ -19,9 +19,8 @@ function show_user(){
$result['country'] = $info['Country']; $result['country'] = $info['Country'];
$result['gender'] = $info['Gender']; $result['gender'] = $info['Gender'];
global $cfg; $ticket_user = Ticket_User::constr_ExternId($result['target_id']);
$ticket_user = Ticket_User::constr_ExternId($result['target_id'],$cfg['db']['lib']); $ticketlist = Ticket::getTicketsOf($ticket_user->getTUserId());
$ticketlist = Ticket::getTicketsOf($ticket_user->getTUserId(),$cfg['db']['lib']);
$result['ticketlist'] = Gui_Elements::make_table($ticketlist, Array("getTId","getTimestamp","getTitle","getStatus","getStatusText","getCategoryName"), Array("tId","timestamp","title","status","statusText","category")); $result['ticketlist'] = Gui_Elements::make_table($ticketlist, Array("getTId","getTimestamp","getTitle","getStatus","getStatusText","getCategoryName"), Array("tId","timestamp","title","status","statusText","category"));
return $result; return $result;

View file

@ -9,7 +9,7 @@
try{ try{
//SETUP THE WWW DB //SETUP THE WWW DB
$dbw = new DBLayer($cfg['db']['web']); $dbw = new DBLayer("web");
$sql = " $sql = "
CREATE DATABASE IF NOT EXISTS `" . $cfg['db']['web']['name'] ."`; CREATE DATABASE IF NOT EXISTS `" . $cfg['db']['web']['name'] ."`;
USE `". $cfg['db']['web']['name'] . "`; USE `". $cfg['db']['web']['name'] . "`;
@ -33,7 +33,7 @@
$dbw->executeWithoutParams($sql); $dbw->executeWithoutParams($sql);
//SETUP THE AMS_LIB DB //SETUP THE AMS_LIB DB
$dbl = new DBLayer($cfg['db']['lib']); $dbl = new DBLayer("lib");
$sql = " $sql = "
CREATE DATABASE IF NOT EXISTS `" . $cfg['db']['lib']['name'] ."`; CREATE DATABASE IF NOT EXISTS `" . $cfg['db']['lib']['name'] ."`;
USE `" . $cfg['db']['lib']['name'] ."`; USE `" . $cfg['db']['lib']['name'] ."`;
@ -259,7 +259,7 @@
Users::createUser($params, 1); Users::createUser($params, 1);
try{ try{
$params['permission'] = 2; $params['permission'] = 2;
$dbw = new DBLayer($cfg['db']['web']); $dbw = new DBLayer("web");
$dbw->execute("INSERT INTO ams_user (Login, Password, Email, Permission) VALUES (:name, :pass, :mail, :permission)",$params); $dbw->execute("INSERT INTO ams_user (Login, Password, Email, Permission) VALUES (:name, :pass, :mail, :permission)",$params);
print "The admin account is created, you can login with id: admin, pass: admin!"; print "The admin account is created, you can login with id: admin, pass: admin!";
}catch (PDOException $e){ }catch (PDOException $e){