* Data class that holds a lot of queries that load specific tickets.
* These queries are being used by the ticket_queue_handler class. An object of this class holds 2 attributes: the query and the params used for the query.
* @author Daan Janssens, mentored by Matthew Lagoe
* loads the not yet assigned tickets query into the objects attributes.
*/
public function loadAllNotAssignedTickets(){
public function loadAllNotAssignedTickets(){
$this->query = "SELECT ticket . * FROM ticket LEFT JOIN assigned ON ticket.TId = assigned.Ticket WHERE assigned.Ticket IS NULL";
$this->query = "SELECT ticket . * FROM ticket LEFT JOIN assigned ON ticket.TId = assigned.Ticket WHERE assigned.Ticket IS NULL";
$this->params = array();
$this->params = array();
}
}
/**
* loads the 'all' tickets query into the objects attributes.
*/
public function loadAllTickets(){
public function loadAllTickets(){
$this->query = "SELECT * FROM `ticket`";
$this->query = "SELECT * FROM `ticket`";
$this->params = array();
$this->params = array();
}
}
/**
* loads the 'all open' tickets query into the objects attributes.
*/
public function loadAllOpenTickets(){
public function loadAllOpenTickets(){
$this->query = "SELECT * FROM ticket INNER JOIN ticket_user ON ticket.Author = ticket_user.TUserId and ticket.Status!=3";
$this->query = "SELECT * FROM ticket INNER JOIN ticket_user ON ticket.Author = ticket_user.TUserId and ticket.Status!=3";
$this->params = array();
$this->params = array();
}
}
/**
* loads the 'closed' tickets query into the objects attributes.
*/
public function loadAllClosedTickets(){
public function loadAllClosedTickets(){
$this->query = "SELECT * FROM ticket INNER JOIN ticket_user ON ticket.Author = ticket_user.TUserId and ticket.Status=3";
$this->query = "SELECT * FROM ticket INNER JOIN ticket_user ON ticket.Author = ticket_user.TUserId and ticket.Status=3";
$this->params = array();
$this->params = array();
}
}
/**
* loads the 'todo' tickets query & params into the objects attributes.
* first: find the tickets assigned to the user with status = waiting on support,
* second find all not assigned tickets that aren't forwarded yet.
* find all tickets assigned to someone else witht status waiting on support, with timestamp of last reply > 1 day,
* find all non-assigned tickets forwarded to the support groups to which that user belongs
* @param $user_id the user's id to whom the tickets should be assigned
*/
public function loadToDoTickets($user_id){
public function loadToDoTickets($user_id){
//first: find the tickets assigned to the user with status = waiting on support
//second find all not assigned tickets that aren't forwarded yet.
//find all tickets assigned to someone else witht status waiting on support, with timestamp of last reply > 1 day
//find all non-assigned tickets forwarded to the support groups to which that user belongs
$this->query = "SELECT * FROM `ticket` t LEFT JOIN `assigned` a ON t.TId = a.Ticket LEFT JOIN `ticket_user` tu ON tu.TUserId = a.User LEFT JOIN `forwarded` f ON t.TId = f.Ticket
$this->query = "SELECT * FROM `ticket` t LEFT JOIN `assigned` a ON t.TId = a.Ticket LEFT JOIN `ticket_user` tu ON tu.TUserId = a.User LEFT JOIN `forwarded` f ON t.TId = f.Ticket
WHERE (tu.ExternId = :user_id AND t.Status = 1)
WHERE (tu.ExternId = :user_id AND t.Status = 1)
OR (a.Ticket IS NULL AND f.Group IS NULL)
OR (a.Ticket IS NULL AND f.Group IS NULL)
@ -39,12 +60,26 @@ class Ticket_Queue{
$this->params = array('user_id' => $user_id);
$this->params = array('user_id' => $user_id);
}
}
/**
* loads the 'tickets asssigned to a user and waiting on support' query & params into the objects attributes.
* @param $user_id the user's id to whom the tickets should be assigned
*/
public function loadAssignedandWaiting($user_id){
public function loadAssignedandWaiting($user_id){
$this->query = "SELECT * FROM `ticket` t LEFT JOIN `assigned` a ON t.TId = a.Ticket LEFT JOIN `ticket_user` tu ON tu.TUserId = a.User
$this->query = "SELECT * FROM `ticket` t LEFT JOIN `assigned` a ON t.TId = a.Ticket LEFT JOIN `ticket_user` tu ON tu.TUserId = a.User
WHERE (tu.ExternId = :user_id AND t.Status = 1)";
WHERE (tu.ExternId = :user_id AND t.Status = 1)";
$this->params = array('user_id' => $user_id);
$this->params = array('user_id' => $user_id);
}
}
/**
* loads the 'created' query & params into the objects attributes.
* This function creates dynamically a query based on the selected features.
* @param $who specifies if we want to user the user_id or group_id to form the query.
* @param $user_id the user's id to whom the tickets should be assigned/not assigned
* @param $group_id the group's id to whom the tickets should be forwarded/not forwarded
* @param $what specifies what kind of tickets we want to return: waiting for support, waiting on user, closed
* @param $how specifies if the tickets should be or shouldn't be assigned/forwarded to the group/user selected.
*/
public function createQueue($userid, $groupid, $what, $how, $who){
public function createQueue($userid, $groupid, $what, $how, $who){
* returns tickets (queues) that are related in some way.
* This class handles the creation and returning of existing ticket queues. Normally a $_GET['get'] parameter is being used to identify what kind of tickets should be shown.
* the getTickets() function uses this parameter($input) and uses the ticket_queue class to load the specific query.
* @author Daan Janssens, mentored by Matthew Lagoe
* returns the tickets that are related in someway defined by $input.
* The $input parameter should be a string that defines what kind of queue should be loaded. A new pagination object will be instantiated and will load 10 entries,
* related to the $_GET['pagenum'] variable.
* @param $input identifier that defines what queue to load.
* @param $user_id the id of the user that browses the queues, some queues can be depending on this.
* @return an array consisting of ticket objects, beware, the author & category of a ticket, are objects on their own (no integers are used this time).
*/
public function getTickets($input, $user_id){
public function getTickets($input, $user_id){
switch ($input){
switch ($input){
@ -51,17 +68,29 @@ class Ticket_Queue_Handler{
}
}
/**
* get pagination attribute of the object.
*/
public function getPagination(){
public function getPagination(){
return $this->pagination;
return $this->pagination;
}
}
/**
* creates the queue.
* afterwards the getTickets function should be called, else a lot of extra parameters had to be added to the getTickets function..
*/
public function createQueue($userid, $groupid, $what, $how, $who){
public function createQueue($userid, $groupid, $what, $how, $who){
* @param $ticket_id the id of the ticket of which we want the replies.
* @param $view_as_admin if the browsing user is an admin/mod it should be 1, this will also show the hidden replies.
* @return an array with ticket_reply objects (beware the author and content are objects on their own, not integers!)
*/
public static function getRepliesOfTicket( $ticket_id, $view_as_admin) {
public static function getRepliesOfTicket( $ticket_id, $view_as_admin) {
$dbl = new DBLayer("lib");
$dbl = new DBLayer("lib");
$statement = $dbl->execute("SELECT * FROM ticket_reply INNER JOIN ticket_content INNER JOIN ticket_user ON ticket_reply.Content = ticket_content.TContentId and ticket_reply.Ticket=:id and ticket_user.TUserId = ticket_reply.Author ORDER BY ticket_reply.TReplyId ASC", array('id' => $ticket_id));
$statement = $dbl->execute("SELECT * FROM ticket_reply INNER JOIN ticket_content INNER JOIN ticket_user ON ticket_reply.Content = ticket_content.TContentId and ticket_reply.Ticket=:id and ticket_user.TUserId = ticket_reply.Author ORDER BY ticket_reply.TReplyId ASC", array('id' => $ticket_id));
$row = $statement->fetchAll();
$row = $statement->fetchAll();
$result = Array();
$result = Array();
foreach($row as $tReply){
foreach($row as $tReply){
//only add hidden replies if the user is a mod/admin
* The ticket_user makes a link between the entire ticket system's lib db and the www user, which is stored in another db (this is the external ID).
* The externalID could be the ID of a drupal user or wordpress user,.. The ticket_user also stores the permission of that user, this way the permission system
* is inside the lib itself and can be used in any www version that you like. permission 1 = user, 2 = mod, 3 = admin.
* @author Daan Janssens, mentored by Matthew Lagoe
* handles basic user registration & management functions (shard related).
* The Users class is the basis class of WebUsers, this class provides functions being used by all CMS's and our own www version. The WebUsers class however needs to be reimplemented
* by using the CMS's it's funcionality. This class handles the writing to the shard db mainly, and in case it's offline: writing to the ams_querycache.
* @author Daan Janssens, mentored by Matthew Lagoe
*/
class Users{
class Users{
/**
/**
* Function check_register
* checks if entered values before registering are valid.
*
* @param $array with Username,Password, ConfirmPass and Email.
* @takes $array with username,password and email
* @return string Info: Returns a string, if input data is valid then "success" is returned, else an array with errors
* @return string Info: Returns a string, if input data is valid then "success" is returned, else an array with errors
*/
*/
public function check_Register($values){
public function check_Register($values){
@ -64,12 +69,9 @@ class Users{
}
}
/**
/**
* Function checkUser
* checks if entered username is valid.
*
* @param $username the username that the user wants to use.
* @takes $username
* @return string Info: Returns a string based on if the username is valid, if valid then "success" is returned
* @return string Info: Returns a string based on if the username is valid, if valid then "success" is returned
*/
*/
public function checkUser( $username )
public function checkUser( $username )
@ -93,9 +95,9 @@ class Users{
}
}
/**
/**
* Function checkUserNameExists
* check if username already exists.
*
* This is the base function, it should be overwritten by the WebUsers class.
* @takes $username
* @param $username the username
* @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 checkUserNameExists($username){
protected function checkUserNameExists($username){
@ -106,9 +108,8 @@ class Users{
/**
/**
* Function checkPassword
* checks if the password is valid.
*
* @param $pass the password willing to be used.
* @takes $pass
* @return string Info: Returns a string based on if the password is valid, if valid then "success" is returned
* @return string Info: Returns a string based on if the password is valid, if valid then "success" is returned
*/
*/
public function checkPassword( $pass )
public function checkPassword( $pass )
@ -129,9 +130,10 @@ class Users{
/**
/**
* Function confirmPassword
* checks if the confirmPassword matches the original.
*
* @param $pass_result the result of the previous password check.
* @takes $pass
* @param $pass the original pass.
* @param $confirmpass the confirmation password.
* @return string Info: Verify's $_POST["Password"] is the same as $_POST["ConfirmPass"]
* @return string Info: Verify's $_POST["Password"] is the same as $_POST["ConfirmPass"]
*/
*/
private function confirmPassword($pass_result,$pass,$confirmpass)
private function confirmPassword($pass_result,$pass,$confirmpass)
@ -151,10 +153,9 @@ class Users{
/**
/**
* Function checkEmail
* wrapper to check if the email address is valid.
*
* @param $email the email address
* @takes $email
* @return "success", else in case it isn't valid an error will be returned.
* @return
*/
*/
public function checkEmail( $email )
public function checkEmail( $email )
{
{
@ -174,10 +175,10 @@ class Users{
/**
/**
* Function checkEmailExists
* check if email already exists.
*
* This is the base function, it should be overwritten by the WebUsers class.
* @takes $username
* @param $email the email address
* @return string Info: Returns true or false if the user is in the www db.
* @return string Info: Returns true or false if the email is in the www db.
*/
*/
protected function checkEmailExists($email){
protected function checkEmailExists($email){
//TODO: You should overwrite this method with your own version!
//TODO: You should overwrite this method with your own version!
@ -187,10 +188,9 @@ class Users{
/**
/**
* Function validEmail
* check if the emailaddress structure is valid.
*
* @param $email the email address
* @takes $email
* @return true or false
* @return true or false depending on if its a valid email format.
*/
*/
public function validEmail( $email ){
public function validEmail( $email ){
$isValid = true;
$isValid = true;
@ -238,9 +238,8 @@ class Users{
/**
/**
* Function generateSALT
* generate a SALT.
*
* @param $length, which is by default 2
* @takes $length, which is by default 2
* @return a random salt of 2 chars
* @return a random salt of 2 chars
*/
*/
public static function generateSALT( $length = 2 )
public static function generateSALT( $length = 2 )
@ -279,9 +278,9 @@ class Users{
/**
/**
* Function create
* creates a user in the shard.
*
* incase the shard is offline it will place it in the ams_querycache.
* @takes $array with name,pass and mail
* @param $values with name,pass and mail
* @return ok if it's get correctly added to the shard, else return lib offline and put in libDB, if libDB is also offline return liboffline.
* @return ok if it's get correctly added to the shard, else return lib offline and put in libDB, if libDB is also offline return liboffline.
*/
*/
public static function createUser($values, $user_id){
public static function createUser($values, $user_id){
@ -308,6 +307,11 @@ class Users{
}
}
/**
* creates permissions in the shard db for a user.
* incase the shard is offline it will place it in the ams_querycache.
* @param $pvalues with username
*/
public static function createPermissions($pvalues) {
public static function createPermissions($pvalues) {
try {
try {
@ -333,10 +337,22 @@ class Users{
}
}
/**
* check if username and password matches.
* This is the base function, it should be overwritten by the WebUsers class.
* @param $user the inserted username
* @param $pass the inserted password
*/
protected function checkLoginMatch($user,$pass){
protected function checkLoginMatch($user,$pass){
print('This is the base class!');
print('This is the base class!');
}
}
/**
* check if the changing of a password is valid.
* a mod/admin doesn't has to fill in the previous password when he wants to change the password, however for changing his own password he has to fill it in.
* @param $values an array containing the CurrentPass, ConfirmNewPass, NewPass and adminChangesOthers
* @return if it is valid "success will be returned, else an array with errors will be returned.
*/
public function check_change_password($values){
public function check_change_password($values){
//if admin isn't changing others
//if admin isn't changing others
if(!$values['adminChangesOther']){
if(!$values['adminChangesOther']){
@ -390,6 +406,13 @@ class Users{
}
}
}
}
/**
* sets the shards password.
* in case the shard is offline, the entry will be stored in the ams_querycache.
* @param $user the usersname of the account of which we want to change the password.
* @param $pass the new password.
* @return ok if it worked, if the lib or shard is offline it will return liboffline or shardoffline.