-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.php
117 lines (82 loc) · 2.86 KB
/
lib.php
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
115
116
117
<?php
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once($CFG->dirroot.'/course/lib.php');
////include 'invite.php';
//require_once('module.php');
//require_once('invite.php');
defined('MOODLE_INTERNAL') || die();
function oneclick_add_instance(stdClass $oneclick, mod_oneclick_mod_form $mform = null){
global $DB;
$roomname = $oneclick->name;
$duration = $oneclick->duration;
echo $roomname;
echo $duration;
create_room($roomname, $duration);
return $DB->insert_record('oneclick', $oneclick);
}
function oneclick_update_instance(stdClass $oneclick, mod_oneclick_mod_form $mform = null){
global $DB;
$oneclick->id = $oneclick->instance;
return $DB->update_record('oneclick', $oneclick);
}
function oneclick_delete_instance($id){
global $DB;
if (! $oneclick = $DB->get_record('oneclick', array('id' => $id))) {
return false;
}
# Delete any dependent records here #
$DB->delete_records('oneclick', array('id' => $oneclick->id));
return true;
}
function create_room($name,$datetime){
global $CFG;
$service_url = "https://1click.io/api/v1/conference/";
$curl = curl_init();
curl_setopt($curl, CURLOPT_HEADER, false);
$accesstoken= "Apikey ".$CFG->email.":".$CFG->apikey;
//$accesstoken = "Apikey [email protected]:59db3e24045923cc0da98d472c9429809bd50d7e";
$data = array(
'title'=>$name,
// 'scheduled_time'=>$datetime,
//'scheduled_time' => $datetime,
'scheduled_duration' => '60',
'layout' => 'dynamic',
'conference_type'=>'multiway'
);
$data_string = json_encode($data);
curl_setopt($curl, CURLOPT_URL,$service_url);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($curl, CURLOPT_HTTPHEADER,array(
'Content-Type: application/json',
'Accept: application/json',
'user: '.$accesstoken,
'Authorization: '.$accesstoken)
);
curl_setopt($curl, CURLOPT_POST,true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$rest = curl_exec($curl);
$httpCode = curl_getinfo ( $curl, CURLINFO_HTTP_CODE );
//$data = curl_getinfo($curl);
//print_r($data);
if($httpCode == 201){
echo "succesfully created room";
/* echo "<form name='invite' method ='post' action='invite.php'>";
echo "add invites email (put a , after each invite email) <br>";
echo "<input type='text' name = 'email' size='60' ><br>";
echo "<input type='hidden' value='".$name."' name='roomname'>";
echo "<INPUT type='submit' value='Send invite'>";
echo "</form>";*/
}
else if($httpCode == 404)
echo "Already existing room";
/*if ($rest === false)
{
throw new Exception('Curl error: ' . curl_error($crl));
print_r('Curl error: ' . curl_error($curl));
}
*/
curl_close($curl);
//print_r($rest);
}
?>