From fe2fdecad5dfb6b3a5449f1da08a368cf24f34b2 Mon Sep 17 00:00:00 2001
From: Peter Rotich <peter@enhancesoft.com>
Date: Thu, 9 Jan 2014 16:47:53 +0000
Subject: [PATCH] Make collaborator extends ticket user  - necessary for
 authtoken support Make Clientession extends EndUser

Allow variable replacer to call __call functions
---
 include/class.collaborator.php | 36 ++++++++++++----------------------
 include/class.usersession.php  | 14 ++++++-------
 include/class.variable.php     |  3 +--
 3 files changed, 21 insertions(+), 32 deletions(-)

diff --git a/include/class.collaborator.php b/include/class.collaborator.php
index 215dd25fe..abf0a52a4 100644
--- a/include/class.collaborator.php
+++ b/include/class.collaborator.php
@@ -14,19 +14,18 @@
     vim: expandtab sw=4 ts=4 sts=4:
 **********************************************************************/
 require_once(INCLUDE_DIR . 'class.user.php');
+require_once(INCLUDE_DIR . 'class.client.php');
 
-class Collaborator {
+class Collaborator extends TicketUser {
 
     var $ht;
 
     var $user;
     var $ticket;
 
-    static private $token_regex = '/^c(?P<id>\d+)x(?P<algo>\d+)h(?P<hash>.*)$/i';
-
     function __construct($id) {
-
         $this->load($id);
+        parent::__construct($this->getUser());
     }
 
     function load($id) {
@@ -38,13 +37,14 @@ class Collaborator {
             .' WHERE id='.db_input($id);
 
         $this->ht = db_fetch_array(db_query($sql));
-        $this->ticket = $this->user = null;
+        $this->ticket = null;
     }
 
     function reload() {
         return $this->load();
     }
 
+<<<<<<< HEAD
     function __call($name, $args) {
 
         if(!($user=$this->getUser()) || !method_exists($user, $name))
@@ -60,6 +60,8 @@ class Collaborator {
                     $this->getEmail()));
     }
 
+=======
+>>>>>>> efe5b0f... Make collaborator extends ticket user  - necessary for authtoken support
     function getId() {
         return $this->ht['id'];
     }
@@ -68,6 +70,10 @@ class Collaborator {
         return ($this->ht['isactive']);
     }
 
+    function getCreateDate() {
+        return $this->ht['created'];
+    }
+
     function getTicketId() {
         return $this->ht['ticket_id'];
     }
@@ -149,27 +155,11 @@ class Collaborator {
             .' WHERE ticket_id='.db_input($info['ticketId'])
             .' AND user_id='.db_input($info['userId']);
 
-        list($id) = db_fetch_row(db_query($sql));
-
-        return $id;
-    }
-
-    static function lookupByAuthToken($token) {
-
-        //Expecting well formatted token see getAuthToken routine for details.
-        $matches = array();
-        if (preg_match(static::$token_regex, $token, $matches)
-                && $matches['id']
-                && ($c = self::lookup($matches['id']))
-                && strcasecmp($c->getAuthToken($matches['algo']), $token)  == 0
-                )
-            return $c;
-
-        return null;
-
+        return db_result(db_query($sql));
     }
 
     static function lookup($criteria) {
+
         $id = is_numeric($criteria)
             ? $criteria : self::getIdByInfo($criteria);
 
diff --git a/include/class.usersession.php b/include/class.usersession.php
index c24bb76ab..09b31601d 100644
--- a/include/class.usersession.php
+++ b/include/class.usersession.php
@@ -103,13 +103,13 @@ class UserSession {
 
 }
 
-class ClientSession extends Client {
+class ClientSession extends EndUser {
 
     var $session;
 
-    function ClientSession($email, $id){
-        parent::Client($id, $email);
-        $this->session= new UserSession($email);
+    function __construct($user) {
+        parent::__construct($user);
+        $this->session= new UserSession($user->getUserName());
     }
 
     function isValid(){
@@ -145,13 +145,13 @@ class StaffSession extends Staff {
 
     var $session;
 
-    function StaffSession($var){
-        parent::Staff($var);
+    function __construct($var) {
+        parent::__construct($var);
         $this->session= new UserSession($this->getId());
     }
 
     function isValid(){
-        global $_SESSION,$cfg;
+        global $_SESSION, $cfg;
 
         if(!$this->getId() || $this->session->getSessionId()!=session_id())
             return false;
diff --git a/include/class.variable.php b/include/class.variable.php
index 76ad8c12d..32704a909 100644
--- a/include/class.variable.php
+++ b/include/class.variable.php
@@ -67,8 +67,7 @@ class VariableReplacer {
             return call_user_func(array($obj, 'asVar'));
 
         list($v, $part) = explode('.', $var, 2);
-        if ($v && method_exists($obj, 'get'.ucfirst($v))
-                && is_callable(array($obj, 'get'.ucfirst($v)))) {
+        if ($v && is_callable(array($obj, 'get'.ucfirst($v)))) {
             $rv = call_user_func(array($obj, 'get'.ucfirst($v)));
             if(!$rv || !is_object($rv))
                 return $rv;
-- 
GitLab