aboutsummaryrefslogtreecommitdiff
path: root/lib/elearning/Ilias5Soap.class.php
blob: cf8bd4c4e5b180e9a474eeb6819cfe062a1b0263 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/**
 * class to use ILIAS-5-Webservices
 *
 * This class contains methods to connect to the ILIAS-5-Soap-Server.
 *
 * @author    Arne Schröder <schroeder@data-quest.de>
 * @access    public
 * @modulegroup    elearning_interface_modules
 * @module        Ilias5Soap
 * @package    ELearning-Interface
 */
class Ilias5Soap extends Ilias4Soap
{
    var $cms_type;
    var $admin_sid;
    var $user_sid;
    var $user_type;
    var $soap_cache;
    var $separator_string;

    /**
     * call soap-function
     *
     * calls soap-function with given parameters
     * @access public
     * @param string method method-name
     * @param string params parameters
     * @return mixed result
     */
    function call($method, $params)
    {
        $index = md5($method . ":" . implode('-', $params));
        // return false if no session_id is given
        if (($method != "login") AND ($params["sid"] == ""))
            return false;
//      echo $this->caching_active;
        if (($this->caching_active == true) AND (isset($this->soap_cache[$index])))
        {
//          echo $index;
//          echo " from Cache<br>";
            $result = $this->soap_cache[$index];
        }
        else
        {
            $result = $this->_call($method, $params);
            // if Session is expired, re-login and try again
            if (($method != "login") AND $this->soap_client->fault AND in_array(mb_strtolower($this->faultstring), ["session not valid","session invalid", "session idled"]) )
            {
                $caching_status = $this->caching_active;
                $this->caching_active = false;
                $user_type = $this->user_type;
                $this->user_type = 'admin';
                $params["sid"] = $this->login();
                $result = $this->_call($method, $params);
                $this->caching_active = $caching_status;
                $this->user_type = $user_type;
            }
            elseif (! $this->soap_client->fault)
                $this->soap_cache[$index] = $result;
        }
        return $result;
    }

    /**
    * login
    *
    * login to soap-webservice
    * @access public
    * @return string result
    */
    function login()
    {
        global $ELEARNING_INTERFACE_MODULES, $connected_cms;
        if ($this->user_type == "admin") {
            $param = [
                'client' => $ELEARNING_INTERFACE_MODULES[$this->cms_type]["soap_data"]["client"],
                'username' => $ELEARNING_INTERFACE_MODULES[$this->cms_type]["soap_data"]["username"],
                'password' => $ELEARNING_INTERFACE_MODULES[$this->cms_type]["soap_data"]["password"]
                ];
            $result = $this->call('login', $param);
        } elseif ($this->user_type == "user") {
            $param = [
                'sid' => $this->admin_sid,
                'user_id' => $connected_cms[$this->cms_type]->user->getId()
                ];
            $result = $this->call('loginStudipUser', $param);
        }
        if ($this->user_type == "admin")
            $this->admin_sid = $result;
        if ($this->user_type == "user")
            $this->user_sid = $result;
        return $result;
    }

    /**
    * Check Auth
    *
    * login to soap-webservice
    * @access public
    * @return string result
    */
    function checkPassword($username, $password)
    {
        global $ELEARNING_INTERFACE_MODULES, $connected_cms;
        $param = [
            'client' => $ELEARNING_INTERFACE_MODULES[$this->cms_type]["soap_data"]["client"],
            'username' => $username,
            'password' => $password
        ];
        $result = $this->call('login', $param);
        return $result;
    }
}