Beispiel #1
0
 /**
  * Retrieve nick from users table
  *
  * @return String
  * @author  
  */
 function GetNick($user, $admin)
 {
     $sth = DB::prep("SELECT nick, email, sess, (SELECT username FROM messaging_admin WHERE id = :this_admin) as admin FROM messaging_users WHERE user_id = :id");
     $sth->bindParam(":id", $user, PDO::PARAM_INT);
     $sth->bindParam(":this_admin", $admin, PDO::PARAM_INT);
     $result = DB::getFirst($sth, null, PDO::FETCH_OBJ);
     return $result;
 }
Beispiel #2
0
 public function DeleteOld($expire)
 {
     try {
         $sth = DB::prep("DELETE FROM messaging WHERE time < (NOW() - INTERVAL :interval MINUTE)");
         $sth->bindParam(":interval", $expire, PDO::PARAM_INT);
         DB::Exec($sth);
     } catch (Exception $e) {
         die($e->getMessage());
     }
 }
Beispiel #3
0
 public static function ListSmiley()
 {
     try {
         $sth = DB::prep("SELECT * FROM messaging_smiley");
         $result = DB::getAll($sth, null, PDO::FETCH_OBJ);
         return $result;
     } catch (Exception $e) {
         die($e->getMessage());
     }
 }
Beispiel #4
0
 /**
  * Return first online visitor
  *
  * @return object User details in object (user_id, nick)
  * @author  
  */
 function GetFirstUser()
 {
     try {
         $sth = DB::prep("SELECT user_id,nick FROM messaging_users LIMIT 1");
         $result = DB::getFirst($sth, null, PDO::FETCH_OBJ);
         return $result;
     } catch (Exception $e) {
         die($e->getMessage());
     }
 }
Beispiel #5
0
 /**
  * Get permissions from messagin_group table
  * @return void
  */
 function __construct()
 {
     try {
         $sth = DB::prep("SELECT groups,banned,history FROM messaging_groups WHERE id = (SELECT `group` FROM messaging_admin WHERE id = :id)");
         $sth->bindParam(":id", $_SESSION['userid'], PDO::PARAM_INT);
         $this->result = DB::getFirst($sth, null, PDO::FETCH_OBJ);
     } catch (Exception $e) {
         Exceptions::PrintOut($e);
     }
 }
Beispiel #6
0
 /**
  * Check if user is banned or not
  *
  * @param Integer 
  * @return Integer
  * @author  
  */
 public static function IsBanned($ip)
 {
     try {
         $sth = DB::prep("SELECT COUNT(*) as c FROM messaging_ban WHERE ip = INET_ATON(:ip)");
         $sth->bindParam(":ip", $ip, PDO::PARAM_STR);
         $result = DB::getFirst($sth, null, PDO::FETCH_OBJ);
         return $result->c;
     } catch (Exception $e) {
         Exceptions::PrintOut($e);
     }
 }
Beispiel #7
0
 private function Update()
 {
     try {
         $sth = DB::prep("UPDATE messaging_users SET upload = :type WHERE user_id = :id");
         $sth->bindParam(":type", $this->type, PDO::PARAM_INT);
         $sth->bindParam(":id", $this->user, PDO::PARAM_INT);
         $sth->execute();
     } catch (Exception $e) {
         die($e->getMessage());
     }
 }
Beispiel #8
0
 public function UserProperties()
 {
     try {
         $sth = DB::prep("SELECT upload FROM messaging_users WHERE user_id = :user");
         $sth->bindParam(":user", $_SESSION['visitor_chat_user'], PDO::PARAM_INT);
         $result = DB::getFirst($sth, null, PDO::FETCH_OBJ);
         return isset($result->upload) ? $result->upload : 0;
     } catch (Exception $e) {
         die($e->getMessage());
     }
 }
Beispiel #9
0
 /**
  * Inserts permanent message data into history table
  *
  * @return void
  * @author  
  */
 public function InsertHistory()
 {
     $sth = DB::prep("INSERT INTO messaging_history (user,from_ip, email, sess, msg, admin, type) VALUES(:user,INET_ATON(:from_ip), :email, :sess,:msg,:this_admin, 'user')");
     $sth->bindParam(":msg", $this->msg, PDO::PARAM_STR);
     $sth->bindParam(":email", $_SESSION['visitor_chat_email'], PDO::PARAM_STR);
     $sth->bindParam(":from_ip", $_SERVER['REMOTE_ADDR'], PDO::PARAM_STR);
     $sth->bindParam(":sess", session_id(), PDO::PARAM_STR);
     $sth->bindParam(":this_admin", $this->admin_username, PDO::PARAM_STR);
     $sth->bindParam(":user", $this->user_nick, PDO::PARAM_STR);
     DB::Exec($sth);
 }
Beispiel #10
0
 /**
  * Check if username is valid and insert it
  */
 public function ChangeIt()
 {
     try {
         VarTest::Length(1, 255, $this->nick);
         $sth = DB::prep("UPDATE messaging_users SET nick = :nick WHERE user_id = :userid");
         $sth->bindParam(":nick", $this->nick, PDO::PARAM_STR, 255);
         $sth->bindParam(":userid", $this->user_id, PDO::PARAM_INT);
         $sth->execute();
         $_SESSION['visitor_chat_nick'] = $this->nick;
         echo 1;
     } catch (Exception $e) {
         echo $e->getMessage();
     }
 }
Beispiel #11
0
 public function Check()
 {
     try {
         $sth = DB::prep("\r\n                SELECT id, username, pass, `group`\r\n                FROM messaging_admin\r\n                WHERE username = :user AND pass = :pass");
         $sth->bindParam(":user", $this->username, PDO::PARAM_STR);
         $sth->bindParam(":pass", $this->hash, PDO::PARAM_STR);
         $result = DB::getFirst($sth, null, PDO::FETCH_OBJ);
         if (!empty($result)) {
             $signup = new SignUp();
             $signup->SetSession(array("userid" => $result->id, "group" => $result->group, "username" => $result->username));
         }
     } catch (Exception $e) {
         die($e->getMessage());
     }
 }
Beispiel #12
0
 /**
  * Returns array of users currently online
  *
  * @return array User array
  * @author  
  */
 function Get()
 {
     global $_;
     try {
         $sth = DB::prep("SELECT g1.user_id,g1.nick as user_nick,g1.upload as upload, UNIX_TIMESTAMP(g2.time) as time\r\nFROM messaging_users g1\r\nLEFT JOIN\r\n(SELECT user,time FROM messaging WHERE type = 'user' ORDER BY id DESC) as g2 ON g1.user_id = g2.user\r\n GROUP BY g1.user_id ORDER BY g2.time DESC");
         $result = DB::getAll($sth);
         foreach ($result as $key => $value) {
             $_SESSION['msg_admin_update_' . $value['user_id']] = isset($_SESSION['msg_admin_update_' . $value['user_id']]) ? $_SESSION['msg_admin_update_' . $value['user_id']] : time();
             $result[$key]['new_msg'] = $result[$key]['time'] > $_SESSION['msg_admin_update_' . $value['user_id']] ? 1 : 0;
         }
         return $result;
     } catch (Exception $e) {
         die($e->getMessage());
     }
 }
Beispiel #13
0
 public static function tryRegister($username, $pass)
 {
     if (!empty($username) || !empty($pass)) {
         $user = DB::findOne("user", "username = ?", [$username]);
         if (!$user) {
             $newuser = DB::prep("user");
             $newuser->username = $username;
             $newuser->password = $pass;
             DB::store($newuser);
             return true;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
Beispiel #14
0
 public function CheckLogin()
 {
     try {
         $sth = DB::prep("\r\n                SELECT id,username,pass,`group`\r\n                FROM messaging_admin\r\n                WHERE username = :user AND pass = sha1(:pass)");
         $sth->bindParam(":user", $this->user, PDO::PARAM_STR);
         $sth->bindParam(":pass", $this->pass, PDO::PARAM_STR);
         $result = DB::getFirst($sth, null, PDO::FETCH_OBJ);
         if (!empty($result)) {
             $signup = new SignUp();
             $signup->SetCookieName($this->cookie_name);
             $signup->SetSession(array("userid" => $result->id, "username" => $result->username, "group" => $result->group));
             if ($this->remember == 1) {
                 $signup->SetCookie("login", array("username" => $result->username, "hash" => $result->pass), 31556926, $_SERVER['SERVER_NAME']);
                 $signup->SignUp();
             }
             $this->success = true;
         } else {
             $this->failed = true;
         }
     } catch (Exception $e) {
         die($e->getMessage());
     }
 }
Beispiel #15
0
 /**
  * Delete historic conversation from database
  *
  * @return Integer
  * @author  
  */
 public static function DeleteConv($session, $email)
 {
     try {
         $sth = DB::prep("DELETE FROM messaging_history WHERE email = :email AND sess = :sess");
         $sth->bindParam(":sess", $session, PDO::PARAM_STR);
         $sth->bindParam(":email", $email, PDO::PARAM_STR);
         $sth->execute();
         return $sth->rowCount();
     } catch (Exception $e) {
         Exceptions::PrintOut($e);
     }
 }
Beispiel #16
0
 /**
  * Delete expired (users that are not in browser anymore) users from database.
  *
  * @return void
  * @author  
  */
 function UserExpire()
 {
     $sth = DB::prep("DELETE FROM messaging_users WHERE time < (NOW() - INTERVAL 30 SECOND)");
     DB::Exec($sth);
 }
Beispiel #17
0
 /**
  * Get new messages based on last time update
  *
  * @return array
  * @author  
  */
 public static function GetNewMsg()
 {
     try {
         $sth = DB::prep("SELECT COUNT(id) as c FROM messaging WHERE (user = :curr_user AND to_user = :this_admin AND type = 'admin')  AND time > FROM_UNIXTIME(:time) ");
         $sth->bindParam(":curr_user", $_SESSION['visitor_chat_user'], PDO::PARAM_INT);
         $sth->bindParam(":this_admin", $_SESSION['assigned_admin'], PDO::PARAM_INT);
         $sth->bindParam(":time", $_SESSION['msg_update'], PDO::PARAM_INT);
         $result = DB::getFirst($sth, null, PDO::FETCH_OBJ);
         return $result;
     } catch (Exception $e) {
         die($e->getMessage());
     }
 }
Beispiel #18
0
 /**
  * Delete expired (users that are on in browsers anymore) users from database.
  *
  * @return void
  * @author  
  */
 function UserExpire()
 {
     $sth = DB::prep("DELETE FROM messaging_users WHERE time < (NOW() - INTERVAL :time SECOND)");
     $sth->bindParam(":time", $this->time, PDO::PARAM_INT);
     DB::Exec($sth);
 }
Beispiel #19
0
 /**
  * Returns group information from database
  *
  * @return Object
  * @author  Gregor Kuplenik, gregor.kuplenik@insis.si
  */
 public static function GetGroup($id)
 {
     try {
         $sth = DB::prep("SELECT * FROM messaging_groups WHERE id = :id");
         $sth->bindParam(":id", $id, PDO::PARAM_INT);
         return DB::getFirst($sth, null, PDO::FETCH_OBJ);
     } catch (Exception $e) {
         Exceptions::PrintOut($e);
     }
 }
Beispiel #20
0
 /**
  * Delete user from users table
  *
  * @param Integer User id
  * @return void
  * @author  
  */
 private static function DeleteUser($id)
 {
     $sth = DB::prep("DELETE FROM messaging_users WHERE user_id = :id");
     $sth->bindParam(":id", $id, PDO::PARAM_INT);
     $sth->execute();
 }