changed git call from https to git readonly
[atutor.git] / mods / adobe_connect / lib / ACRoom.php
1 <?php
2
3 require_once('lib/ACConnection.php');
4 require_once('lib/ACUser.php');
5
6 class ACRoom extends ACConnection {
7
8
9     public function createRoom($sessionid, $roomname) {
10
11         $fp = @fsockopen($this->adobe_connect_host, $this->adobe_connect_port);
12         if (!$fp) {
13             return false;
14         }
15         if ($this->checkRoom($sessionid, $roomname)) {
16             return false;
17         }
18   
19         $roomname = trim($roomname);
20         $url = "/api/xml?action=sco-update&name=$roomname&folder-id=".$this->adobe_connect_folderid."&type=meeting&session=$sessionid";
21         fputs($fp, "GET ".$url." HTTP/1.0\r\nHost: ".$this->adobe_connect_host."\r\n\r\n");
22
23         while($line = fgets($fp)) {
24
25             if (preg_match('/\ sco-id=\"([0-9]*)\"/', $line, $result)) {
26                 $scoid = $result[1];
27             }
28         }
29         fclose($fp);
30
31         if (empty($scoid)) {
32             return false;
33         }
34
35         return true;
36     }
37
38
39     public function deleteRoom($sessionid, $roomname) {
40
41         if (!$scoid = $this->checkRoom($sessionid, $roomname)) {
42             return false;
43         } else {
44
45             $fp = @fsockopen($this->adobe_connect_host, $this->adobe_connect_port);
46             if (!$fp) {
47                 return false;
48             }
49
50             $url = "/api/xml?action=sco-delete&sco-id=$scoid&session=$sessionid";
51             fputs($fp, "GET ".$url." HTTP/1.0\r\nHost: ".$this->adobe_connect_host."\r\n\r\n");
52
53             $response = $this->checkResponse($fp, __FUNCTION__);
54             fclose($fp);
55
56             return $response;
57         }
58     }
59
60
61     public function assignUser($sessionid, $username, $roomname, $role) {
62
63         if (!$scoid = $this->checkRoom($sessionid, $roomname)) {
64             return false;
65         }
66
67         $user = new ACUser();
68         $principalid = $user->checkUser($sessionid, $username);
69         if (!$principalid) {
70             return false;
71         }
72   
73         switch ($role) {
74           case 'instructor':
75             $acrole = 'host';
76             break;
77           case 'student':
78             $acrole = 'view';
79             break;
80           default:
81             return false;
82         }
83
84         return $this->assignAction($sessionid, $scoid, $principalid, $acrole);
85     }
86
87
88     public function assignAction($sessionid, $scoid, $principalid, $role) {
89   
90         $fp = @fsockopen($this->adobe_connect_host, $this->adobe_connect_port);
91         if (!$fp) {
92             return false;
93         }
94
95         $url = "/api/xml?action=permissions-update&permission-id=$role&acl-id=$scoid&principal-id=$principalid&session=$sessionid";
96         fputs($fp, "GET ".$url." HTTP/1.0\r\nHost: ".$this->adobe_connect_host."\r\n\r\n");
97   
98         $response = $this->checkResponse($fp, __FUNCTION__);
99         fclose($fp);
100
101         return $response;
102     }
103
104
105     public function getRoomUrl($sessionid, $scoid) {
106
107   
108         $fp = @fsockopen($this->adobe_connect_host, $this->adobe_connect_port);
109         if (!$fp) {
110             return false;
111         }
112
113         $url = "/api/xml?action=sco-info&sco-id=$scoid&session=$sessionid";
114         fputs($fp, "GET ".$url." HTTP/1.0\r\nHost: ".$this->adobe_connect_host."\r\n\r\n");
115
116         while ($line = fgets($fp)) {
117             if (preg_match('@\<url-path\>\/([^/]+)@', $line, $result)) {
118                 $roomurl = $result[1];
119             }
120         }
121         fclose($fp);
122
123         if (empty($roomurl)) {
124             return false;
125         }
126
127         return $roomurl;
128     }
129
130
131     public function checkRoom($sessionid, $roomname) {
132   
133         $fp = @fsockopen($this->adobe_connect_host, $this->adobe_connect_port);
134         if (!$fp) {
135             return false;
136         }
137
138         $url = "/api/xml?action=sco-expanded-contents&sco-id=".$this->adobe_connect_folderid."&filter-type=meeting&filter-name=$roomname&session=$sessionid";
139         fputs($fp, "GET ".$url." HTTP/1.0\r\nHost: ".$this->adobe_connect_host."\r\n\r\n");
140
141         while($line = fgets($fp)) {
142
143             if (preg_match('/\ sco-id=\"([0-9]*)\"/', $line, $result)) {
144                 $scoid = $result[1];
145             }
146
147         }
148        fclose($fp);
149
150        if (empty($scoid)) {
151            return false;
152        }
153
154        return $scoid;
155     }
156
157 }
158
159 ?>