123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581 |
- <?php
- namespace Chamilo\Plugin\OpenMeetings;
- include_once __DIR__.'/session.class.php';
- include_once __DIR__.'/room.class.php';
- include_once __DIR__.'/user.class.php';
- class OpenMeetings
- {
- public $url;
- public $user;
- public $pass;
- public $api;
- public $user_complete_name = null;
- public $protocol = 'http://';
- public $debug = false;
- public $logout_url = null;
- public $plugin_enabled = false;
- public $sessionId = "";
- public $roomName = '';
- public $chamiloCourseId;
- public $chamiloSessionId;
- public $externalType;
-
- public function __construct()
- {
- global $_configuration;
-
- $plugin = \OpenMeetingsPlugin::create();
- $om_plugin = (bool) $plugin->get('tool_enable');
- $om_host = $plugin->get('host');
- $om_user = $plugin->get('user');
- $om_pass = $plugin->get('pass');
- $accessUrl = api_get_access_url($_configuration['access_url']);
- $this->externalType = substr($accessUrl['url'], strpos($accessUrl['url'], '://') + 3, -1);
- if (strcmp($this->externalType, 'localhost') == 0) {
- $this->externalType = substr(api_get_path(WEB_PATH), strpos(api_get_path(WEB_PATH), '://') + 3, -1);
- }
- $this->externalType = 'chamilolms.'.$this->externalType;
- $this->table = \Database::get_main_table('plugin_openmeetings');
- if ($om_plugin) {
- $user_info = api_get_user_info();
- $this->user_complete_name = $user_info['complete_name'];
- $this->user = $om_user;
- $this->pass = $om_pass;
- $this->url = $om_host;
-
- define('CONFIG_OPENMEETINGS_USER', $this->user);
- define('CONFIG_OPENMEETINGS_PASS', $this->pass);
- define('CONFIG_OPENMEETINGS_SERVER_URL', $this->url);
- $this->gateway = new \OpenMeetingsGateway($this->url, $this->user, $this->pass);
- $this->plugin_enabled = $om_plugin;
-
- $this->chamiloCourseId = api_get_course_int_id();
- $this->chamiloSessionId = api_get_session_id();
- $this->roomName = 'C'.$this->chamiloCourseId.'-'.$this->chamiloSessionId;
- $return = $this->gateway->loginUser();
- if ($return == 0) {
- $msg = 'Could not initiate session with server through OpenMeetingsGateway::loginUser()';
- error_log(__FILE__.'+'.__LINE__.': '.$msg);
- die($msg);
- }
- $this->sessionId = $this->gateway->sessionId;
- }
- }
-
- public function isTeacher()
- {
- return api_is_course_admin() || api_is_coach() || api_is_platform_admin();
- }
-
- public function createMeeting($params)
- {
- global $_configuration;
-
- $roomId = null;
- $meetingData = \Database::select(
- '*',
- $this->table,
- [
- 'where' => [
- 'c_id = ?' => $this->chamiloCourseId,
- ' AND session_id = ? ' => $this->chamiloSessionId,
- ' AND status <> ? ' => 2,
- ],
- ],
- 'first'
- );
- if ($meetingData != false && count($meetingData) > 0) {
-
-
-
- $room = new Room();
- $room->loadRoomId($meetingData['room_id']);
- $roomArray = (array) $room;
- $roomArray['SID'] = $this->sessionId;
- $roomId = $this->gateway->updateRoomWithModeration($room);
- if ($roomId != $meetingData['room_id']) {
- $msg = 'Something went wrong: the updated room ID ('.$roomId.') is not the same as the one we had ('.$meetingData['room_id'].')';
- die($msg);
- }
- } else {
- $room = new Room();
- $room->SID = $this->sessionId;
- $room->name = $this->roomName;
-
- $room->comment = urlencode(get_lang('Course').': '.$params['meeting_name'].' - '.$_configuration['software_name']);
-
- $room->ispublic = boolval($room->getString('isPublic', 'false'));
-
-
-
-
- $roomId = $this->gateway->createRoomWithModAndType($room);
- }
- if (!empty($roomId)) {
-
- $params['status'] = '1';
- $params['meeting_name'] = $room->name;
- $params['created_at'] = api_get_utc_datetime();
- $params['room_id'] = $roomId;
- $params['c_id'] = api_get_course_int_id();
- $params['session_id'] = api_get_session_id();
- $params['record'] = ($room->allowRecording ? 1 : 0);
- $id = \Database::insert($this->table, $params);
- $this->joinMeeting($id);
- } else {
- return -1;
- }
- }
-
- public function joinMeeting($meetingId)
- {
- if (empty($meetingId)) {
- return false;
- }
- $meetingData = \Database::select(
- '*',
- $this->table,
- ['where' => ['id = ? AND status = 1 ' => $meetingId]],
- 'first'
- );
- if (empty($meetingData)) {
- if ($this->debug) {
- error_log("meeting does not exist: $meetingId ");
- }
- return false;
- }
- $params = ['room_id' => $meetingData['room_id']];
- $returnVal = $this->setUserObjectAndGenerateRoomHashByURLAndRecFlag($params);
- $iframe = $this->url."/?"."secureHash=".$returnVal;
- printf("<iframe src='%s' width='%s' height = '%s' />", $iframe, "100%", 640);
- }
-
- public function isServerRunning()
- {
-
-
-
- return true;
- }
-
- public function getMeetingUserPassword()
- {
- if ($this->isTeacher()) {
- return $this->getMeetingModerationPassword();
- } else {
- return api_get_course_id();
- }
- }
-
- public function getMeetingModerationPassword()
- {
- return api_get_course_id().'mod';
- }
-
- public function getMeetingInfo($params)
- {
- try {
- $result = $this->api->getMeetingInfoArray($params);
- if ($result == null) {
- if ($this->debug) {
- error_log(__FILE__.'+'.__LINE__." Failed to get any response. Maybe we can't contact the OpenMeetings server.");
- }
- } else {
- return $result;
- }
- } catch (Exception $e) {
- if ($this->debug) {
- error_log(__FILE__.'+'.__LINE__.' Caught exception: ', $e->getMessage(), "\n");
- }
- }
- return false;
- }
-
- public function setUserObjectAndGenerateRecordingHashByURL($params)
- {
- $username = $_SESSION['_user']['username'];
- $firstname = $_SESSION['_user']['firstname'];
- $lastname = $_SESSION['_user']['lastname'];
- $userId = $_SESSION['_user']['user_id'];
- $systemType = 'chamilo';
- $room_id = $params['room_id'];
- $urlWsdl = $this->url."/services/UserService?wsdl";
- $omServices = new \SoapClient($urlWsdl);
- $objRec = new User();
- $objRec->SID = $this->sessionId;
- $objRec->username = $username;
- $objRec->firstname = $firstname;
- $objRec->lastname = $lastname;
- $objRec->externalUserId = $userId;
- $objRec->externalUserType = $systemType;
- $objRec->recording_id = $recording_id;
- $orFn = $omServices->setUserObjectAndGenerateRecordingHashByURL($objRec);
- return $orFn->return;
- }
-
- public function setUserObjectAndGenerateRoomHashByURLAndRecFlag($params)
- {
- $username = $_SESSION['_user']['username'];
- $firstname = $_SESSION['_user']['firstname'];
- $lastname = $_SESSION['_user']['lastname'];
- $profilePictureUrl = $_SESSION['_user']['avatar'];
- $email = $_SESSION['_user']['mail'];
- $userId = $_SESSION['_user']['user_id'];
- $systemType = 'Chamilo';
- $room_id = $params['room_id'];
- $becomeModerator = ($this->isTeacher() ? 1 : 0);
- $allowRecording = 1;
- $urlWsdl = $this->url."/services/UserService?wsdl";
- $omServices = new \SoapClient($urlWsdl);
- $objRec = new User();
- $objRec->SID = $this->sessionId;
- $objRec->username = $username;
- $objRec->firstname = $firstname;
- $objRec->lastname = $lastname;
- $objRec->profilePictureUrl = $profilePictureUrl;
- $objRec->email = $email;
- $objRec->externalUserId = $userId;
- $objRec->externalUserType = $systemType;
- $objRec->room_id = $room_id;
- $objRec->becomeModeratorAsInt = $becomeModerator;
- $objRec->showAudioVideoTestAsInt = 1;
- $objRec->allowRecording = $allowRecording;
- $rcFn = $omServices->setUserObjectAndGenerateRoomHashByURLAndRecFlag($objRec);
- return $rcFn->return;
- }
-
- public function getCourseMeetings()
- {
- $newMeetingsList = [];
- $item = [];
- $meetingsList = \Database::select(
- '*',
- $this->table,
- ['where' => [
- 'c_id = ? ' => api_get_course_int_id(),
- ' AND session_id = ? ' => api_get_session_id(),
- ' AND status <> ? ' => 2,
- ],
- ]
- );
- $room = new Room();
- $room->SID = $this->sessionId;
- if (!empty($meetingsList)) {
- foreach ($meetingsList as $meetingDb) {
-
- error_log(__FILE__.'+'.__LINE__.' Meetings found: '.print_r($meetingDb, 1));
- $remoteMeeting = [];
- $meetingDb['created_at'] = api_get_local_time($meetingDb['created_at']);
- $meetingDb['closed_at'] = (!empty($meetingDb['closed_at']) ? api_get_local_time($meetingDb['closed_at']) : '');
-
- $meetingDb['participantCount'] = 40;
- $rec = $this->gateway->getFlvRecordingByRoomId($meetingDb['room_id']);
- $links = [];
-
-
- $link = $this->url.'/DownloadHandler?fileName=%s&moduleName=lzRecorderApp&parentPath=&room_id=%s&sid=%s';
- if (!empty($rec)) {
- $link1 = sprintf($link, $rec['fileHash'], $meetingDb['room_id'], $this->sessionId);
- $link2 = sprintf($link, $rec['alternateDownload'], $meetingDb['room_id'], $this->sessionId);
- $links[] = $rec['fileName'].' '.
- \Display::url('[.flv]', $link1, ['target' => '_blank']).' '.
- \Display::url('[.avi]', $link2, ['target' => '_blank']);
- }
- $item['show_links'] = implode('<br />', $links);
-
-
-
- if (empty($remoteMeeting)) {
-
- } else {
- $remoteMeeting['add_to_calendar_url'] = api_get_self().'?action=add_to_calendar&id='.$meetingDb['id'].'&start='.api_strtotime($meetingDb['startTime']);
- }
- $remoteMeeting['end_url'] = api_get_self().'?action=end&id='.$meetingDb['id'];
- $remoteMeeting['delete_url'] = api_get_self().'?action=delete&id='.$meetingDb['id'];
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- $item = array_merge($item, $meetingDb, $remoteMeeting);
-
- $newMeetingsList[] = $item;
- }
- }
- return $newMeetingsList;
- }
-
- public function endMeeting($meetingId)
- {
- try {
- $room = new Room($meetingId);
- $room->SID = $this->sessionId;
- $room->room_id = intval($meetingId);
- $room->status = false;
- $urlWsdl = $this->url."/services/RoomService?wsdl";
- $ws = new \SoapClient($urlWsdl);
- $roomClosed = $ws->closeRoom($room);
- if ($roomClosed > 0) {
- \Database::update(
- $this->table,
- [
- 'status' => 0,
- 'closed_at' => api_get_utc_datetime(),
- ],
- ['id = ? ' => $meetingId]
- );
- }
- } catch (SoapFault $e) {
- error_log(__FILE__.'+'.__LINE__.' Warning: We have detected some problems: Fault: '.$e->faultstring);
- exit;
- return -1;
- }
- }
-
- public function deleteMeeting($id)
- {
- try {
- $room = new Room();
- $room->loadRoomId($id);
- $this->gateway->deleteRoom($room);
- \Database::update(
- $this->table,
- [
- 'status' => 2,
- ],
- ['id = ? ' => $id]
- );
- return $id;
- } catch (SoapFault $e) {
- error_log(__FILE__.'+'.__LINE__.' Warning: We have detected some problems: Fault: '.$e->faultstring);
- exit;
- return -1;
- }
- }
- }
|