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)
{
try{
$dsn = "mysql:";
$dsn .= "host=". $db['host'].";";
$dsn .= "dbname=". $db['name'].";";
$dsn .= "port=". $db['port'].";";
global $cfg;
$dsn = "mysql:";
$dsn .= "host=". $cfg['db'][$db]['host'].";";
$dsn .= "dbname=". $cfg['db'][$db]['name'].";";
$dsn .= "port=". $cfg['db'][$db]['port'].";";
$opt = array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
);
$this->PDO = new PDO($dsn,$cfg['db'][$db]['user'],$cfg['db'][$db]['pass'], $opt);
$opt = array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
);
$this->PDO = new PDO($dsn,$db['user'],$db['pass'], $opt);
}catch (PDOException $e) {
throw $e;
}
}
public function executeWithoutParams($query){
try{
$statement = $this->PDO->prepare($query);
$statement->execute();
return $statement;
}catch (PDOException $e) {
throw $e;
}
$statement = $this->PDO->prepare($query);
$statement->execute();
return $statement;
}
public function execute($query,$params){
try{
$statement = $this->PDO->prepare($query);
$statement->execute($params);
return $statement;
}catch (PDOException $e) {
throw $e;
}
$statement = $this->PDO->prepare($query);
$statement->execute($params);
return $statement;
}
public function executeReturnId($query,$params){
try{
$statement = $this->PDO->prepare($query);
$this->PDO->beginTransaction();
$statement->execute($params);
$lastId =$this->PDO->lastInsertId();
$this->PDO->commit();
return $lastId;
}catch (PDOException $e) {
throw $e;
}
$statement = $this->PDO->prepare($query);
$this->PDO->beginTransaction();
$statement->execute($params);
$lastId =$this->PDO->lastInsertId();
$this->PDO->commit();
return $lastId;
}
}

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 () {
global $cfg;
try {
$dbl = new DBLayer($cfg['db']['lib']);
$dbl = new DBLayer("lib");
$statement = $dbl->executeWithoutParams("SELECT * FROM ams_querycache");
$rows = $statement->fetchAll();
$dbs = new DBLayer($cfg['db']['shard']);
$dbs = new DBLayer("shard");
foreach ($rows as $record) {
switch($record['type']) {

View file

@ -8,7 +8,6 @@ class Ticket{
private $queue;
private $ticket_category;
private $author;
private $db;
////////////////////////////////////////////Functions////////////////////////////////////////////////////
@ -16,10 +15,10 @@ class Ticket{
* return all ticket of the given author's id.
*
*/
public static function getEntireTicket($id, $db_data) {
$ticket = new Ticket($db_data);
public static function getEntireTicket($id) {
$ticket = new Ticket();
$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);
}
@ -28,13 +27,13 @@ class Ticket{
* return all ticket of the given author's id.
*
*/
public static function getTicketsOf($author, $db_data) {
$dbl = new DBLayer($db_data);
public static function getTicketsOf($author) {
$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));
$row = $statement->fetchAll();
$result = Array();
foreach($row as $ticket){
$instance = new self($db_data);
$instance = new self();
$instance->setTId($ticket['TId']);
$instance->setTimestamp($ticket['Timestamp']);
$instance->setTitle($ticket['Title']);
@ -52,21 +51,21 @@ class Ticket{
* 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->create();
$ticket_id = $ticket->getTId();
$ticket_content = new Ticket_Content($db_data);
$ticket_content = new Ticket_Content();
$ticket_content->setContent($content);
$ticket_content->create();
$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->create();
@ -75,8 +74,8 @@ class Ticket{
}
////////////////////////////////////////////Methods////////////////////////////////////////////////////
public function __construct($db_data) {
$this->db = $db_data;
public function __construct() {
}
@ -91,7 +90,7 @@ class Ticket{
//create ticket by writing private data to DB.
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)";
$values = Array('title' => $this->title, 'status' => $this->status, 'queue' => $this->queue, 'tcat' => $this->ticket_category, 'author' => $this->author);
$this->tId = $dbl->executeReturnId($query, $values); ;
@ -99,7 +98,7 @@ class Ticket{
//return constructed element based on TId
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));
$row = $statement->fetch();
$this->tId = $row['TId'];
@ -114,7 +113,7 @@ class Ticket{
//update private data to DB.
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";
$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);
@ -152,8 +151,7 @@ class Ticket{
}
public function getCategoryName(){
global $cfg;
$category = Ticket_Category::constr_TCategoryId($this->getTicket_Category(), $cfg['db']['lib']);
$category = Ticket_Category::constr_TCategoryId($this->getTicket_Category());
return $category->getName();
}

View file

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

View file

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

View file

@ -6,30 +6,29 @@ class Ticket_Reply{
private $content;
private $author;
private $timestamp;
private $db;
////////////////////////////////////////////Functions////////////////////////////////////////////////////
//return constructed element based on TCategoryId
public static function constr_TReplyId( $id, $db_data) {
$instance = new self($db_data);
public static function constr_TReplyId( $id) {
$instance = new self();
$instance->setTReplyId($id);
return $instance;
}
//return constructed element based on TCategoryId
public static function getRepliesOfTicket( $ticket_id, $db_data) {
$dbl = new DBLayer($db_data);
public static function getRepliesOfTicket( $ticket_id) {
$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));
$row = $statement->fetchAll();
$result = Array();
foreach($row as $tReply){
$instanceReply = new self($db_data);
$instanceReply = new self();
$instanceReply->setTReplyId($tReply['TReplyId']);
$instanceReply->setTimestamp($tReply['Timestamp']);
$instanceReply->set($tReply['Ticket'],$tReply['Content'],$tReply['Author']);
$instanceContent = new Ticket_Content($db_data);
$instanceContent = new Ticket_Content();
$instanceContent->setTContentId($tReply['TContentId']);
$instanceContent->setContent($tReply['Content']);
@ -42,8 +41,7 @@ class Ticket_Reply{
////////////////////////////////////////////Methods////////////////////////////////////////////////////
public function __construct($db_data) {
$this->db = $db_data;
public function __construct() {
}
@ -56,7 +54,7 @@ class Ticket_Reply{
//create ticket by writing private data to DB.
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())";
$values = Array('ticket' => $this->ticket, 'content' => $this->content, 'author' => $this->author);
$dbl->execute($query, $values);
@ -64,7 +62,7 @@ class Ticket_Reply{
//return constructed element based on TId
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));
$row = $statement->fetch();
$this->tReplyId = $row['TReplyId'];
@ -76,7 +74,7 @@ class Ticket_Reply{
//update private data to DB.
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";
$values = Array('id' => $this->tReplyId, 'timestamp' => $this->timestamp, 'ticket' => $this->ticket, 'content' => $this->content, 'author' => $this->author);
$statement = $dbl->execute($query, $values);

View file

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

View file

@ -287,19 +287,18 @@ class Users{
public function createUser($values, $user_id){
try {
//make connection with and put into shard db
global $cfg;
$dbs = new DBLayer($cfg['db']['shard']);
$dbs = new DBLayer("shard");
$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";
}
catch (PDOException $e) {
//oh noooz, the shard is offline! Put in query queue at ams_lib db!
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",
"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";
}catch (PDOException $e) {
print_r($e);
@ -369,19 +368,18 @@ class Users{
protected function setAmsPassword($user, $pass){
global $cfg;
$values = Array('user' => $user, 'pass' => $pass);
try {
//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);
return "ok";
}
catch (PDOException $e) {
//oh noooz, the shard is offline! Put in query queue at ams_lib db!
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",
"query" => json_encode(array($values["user"],$values["pass"]))));
return "shardoffline";
@ -393,19 +391,18 @@ class Users{
protected function setAmsEmail($user, $mail){
global $cfg;
$values = Array('user' => $user, 'mail' => $mail);
try {
//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);
return "ok";
}
catch (PDOException $e) {
//oh noooz, the shard is offline! Put in query queue at ams_lib db!
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",
"query" => json_encode(array($values["user"],$values["mail"]))));
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.
*/
protected function checkUserNameExists($username){
global $cfg;
$dbw = new DBLayer($cfg['db']['web']);
$dbw = new DBLayer("web");
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.
*/
protected function checkEmailExists($email){
global $cfg;
$dbw = new DBLayer($cfg['db']['web']);
$dbw = new DBLayer("web");
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
*/
public function checkLoginMatch($username,$password){
global $cfg;
$dbw = new DBLayer($cfg['db']['web']);
$dbw = new DBLayer("web");
$statement = $dbw->execute("SELECT * FROM ams_user WHERE Login=:user", array('user' => $username));
$row = $statement->fetch();
@ -51,36 +47,28 @@ class WebUsers extends Users{
}
public function getId($username){
global $cfg;
$dbw = new DBLayer($cfg['db']['web']);
$dbw = new DBLayer("web");
$statement = $dbw->execute("SELECT * FROM ams_user WHERE Login=:username", array('username' => $username));
$row = $statement->fetch();
return $row['UId'];
}
public function getUsername($id){
global $cfg;
$dbw = new DBLayer($cfg['db']['web']);
$dbw = new DBLayer("web");
$statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $id));
$row = $statement->fetch();
return $row['Login'];
}
public function getEmail($id){
global $cfg;
$dbw = new DBLayer($cfg['db']['web']);
$dbw = new DBLayer("web");
$statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $id));
$row = $statement->fetch();
return $row['Email'];
}
public function getInfo($id){
global $cfg;
$dbw = new DBLayer($cfg['db']['web']);
$dbw = new DBLayer("web");
$statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $id));
$row = $statement->fetch();
$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){
global $cfg;
$reply = WebUsers::setAmsPassword($user, $pass);
$values = Array('user' => $user, 'pass' => $pass);
try {
//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);
}
catch (PDOException $e) {
@ -117,12 +104,11 @@ class WebUsers extends Users{
}
public function setEmail($user, $mail){
global $cfg;
$reply = WebUsers::setAmsEmail($user, $mail);
$values = Array('user' => $user, 'mail' => $mail);
try {
//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);
}
catch (PDOException $e) {
@ -132,8 +118,7 @@ class WebUsers extends Users{
}
public function getUsers(){
global $cfg;
$dbl = new DBLayer($cfg['db']['web']);
$dbl = new DBLayer("web");
$data = $dbl->executeWithoutParams("SELECT * FROM ams_user");
return $data;
}

View file

@ -47,9 +47,8 @@ function write_user($newUser){
);
try{
global $cfg;
//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);
//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($updated){
global $cfg;
//execute the query in the web DB.
$dbw = new DBLayer($cfg['db']['web']);
$dbw = new DBLayer("web");
$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( ($_POST['target_id'] == $_SESSION['id']) || WebUsers::isAdmin() ){
global $cfg;
$category = filter_var($_POST['Category'], FILTER_SANITIZE_NUMBER_INT);
$title = filter_var($_POST['Title'], FILTER_SANITIZE_STRING);
$content = filter_var($_POST['Content'], FILTER_SANITIZE_STRING);
@ -17,9 +16,9 @@ function create_ticket(){
if($_POST['target_id'] == $_SESSION['id']){
$author = $_SESSION['ticket_user']->getTUserId();
}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) {
//ERROR: LIB DB is not online!
header("Location: index.php");

View file

@ -2,8 +2,6 @@
function login(){
global $cfg;
try{
$result = WebUsers::checkLoginMatch($_POST["Username"],$_POST["Password"]);
if( $result != "fail"){
@ -11,7 +9,7 @@ function login(){
$_SESSION['user'] = $_POST["Username"];
$_SESSION['permission'] = $result['Permission'];
$_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.
header( 'Location: index.php' );

View file

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

View file

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

View file

@ -4,14 +4,13 @@ function show_ticket(){
//if logged in
if(WebUsers::isLoggedIn() && isset($_GET['id'])){
global $cfg;
$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']);
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_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"));

View file

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

View file

@ -9,7 +9,7 @@
try{
//SETUP THE WWW DB
$dbw = new DBLayer($cfg['db']['web']);
$dbw = new DBLayer("web");
$sql = "
CREATE DATABASE IF NOT EXISTS `" . $cfg['db']['web']['name'] ."`;
USE `". $cfg['db']['web']['name'] . "`;
@ -33,7 +33,7 @@
$dbw->executeWithoutParams($sql);
//SETUP THE AMS_LIB DB
$dbl = new DBLayer($cfg['db']['lib']);
$dbl = new DBLayer("lib");
$sql = "
CREATE DATABASE IF NOT EXISTS `" . $cfg['db']['lib']['name'] ."`;
USE `" . $cfg['db']['lib']['name'] ."`;
@ -259,7 +259,7 @@
Users::createUser($params, 1);
try{
$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);
print "The admin account is created, you can login with id: admin, pass: admin!";
}catch (PDOException $e){