@ -7,6 +7,7 @@
/**
* Initialization
*/
namespace Chamilo\Plugin\OpenMeetings;
include_once __DIR__.'/session.class.php';
include_once __DIR__.'/room.class.php';
include_once __DIR__.'/user.class.php';
@ -27,6 +28,9 @@ class OpenMeetings
public $plugin_enabled = false;
public $sessionId = "";
public $roomName = '';
public $chamiloCourseId;
public $chamiloSessionId;
public $externalType;
/**
* Constructor (generates a connection to the API and the Chamilo settings
@ -35,14 +39,21 @@ class OpenMeetings
function __construct()
{
// initialize video server settings from global settings
$plugin = OpenMeetingsPlugin::create();
$plugin = \ OpenMeetingsPlugin::create();
$om_plugin = $plugin->get('tool_enable');
$om_host = $plugin->get('host');
$om_user = $plugin->get('user');
$om_pass = $plugin->get('pass');
global $_configuration;
$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');
$this->table = \ Database::get_main_table('plugin_openmeetings');
if ($om_plugin) {
$user_info = api_get_user_info();
@ -56,10 +67,19 @@ class OpenMeetings
define('CONFIG_OPENMEETINGS_PASS', $this->pass);
define('CONFIG_OPENMEETINGS_SERVER_URL', $this->url);
$this->gateway = new OpenMeetingsGateway();
$this->gateway = new \ OpenMeetingsGateway($this->url, $this->user, $this->pass );
$this->plugin_enabled = $om_plugin;
// The room has a name composed of C + course ID + '-' + session ID
$this->roomName = 'C'.api_get_course_int_id().'-'.api_get_session_id();
$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;
}
}
/**
@ -77,100 +97,103 @@ class OpenMeetings
* It is similar to opening a PHP session. In fact, the session ID is kept
* inside the $_SESSION['openmeetings_session'] session variable
* @return bool True if the user is correct and false when is incorrect
* @deprecated loginUser now called at object instanciation
*/
/**
function loginUser()
{
try {
//$objGetSession = new Chamilo\Plugin\OpenMeetings\Session();
//$urlWsdl = CONFIG_OPENMEETINGS_SERVER_URL . "/services/UserService?wsdl";
//$omServices = new SoapClient( $urlWsdl );
//Verifying if there is already an active session
if (empty($_SESSION['openmeetings_session'])) {
//$gsFun = $omServices->getSession($objGetSession);
//$loginUser = $omServices->loginUser(array('SID' => $this->sessionId, 'username' => $this->user, 'userpass' => $this->pass));
$loginUser = $this->gateway->loginUser();
$this->sessionId = $_SESSION['openmeetings_session'] = $this->gateway->session_id;
if ($loginUser) {
//error_log(__FILE__.' '.__LINE__.' user logged in and received session ID '.$this->gateway->session_id);
// Login user returns either 0 or >0, depending on the results
// Technically, as long as the SOAP user has been configured in OpenMeetings and OpenMeetings is on, this should always succeed.
if ($this->gateway->loginUser()) {
$this->sessionId = $_SESSION['openmeetings_session'] = $this->gateway->session_id;
return true;
} else {
// error_log(__FILE__. ' '.__LINE__ );
error_log('loginUser did not succeed');
return false;
}
} else {
//error_log(__FILE__.' '.__LINE__.' '.$_SESSION['openmeetings_session']);
$this->sessionId = $_SESSION['openmeetings_session'];
return true;
}
} catch (SoapFault $e) {
echo "< h1 > Warning< / h1 >
< p > We have detected some problems < / br >
Fault: {$e->faultstring}< / p > ";
return false;
error_log(__FILE__.'+'.__LINE__.' Warning: We have detected some problems. Fault: '.$e->faultstring);
return false;
}
}
*/
/*
* Creating a Room for the meeting
* @return bool True if the user is correct and false when is incorrect
*/
function createMeeting($params)
{
//$id = Database::insert($this->table, $params);
try {
$objAddRoom = new Chamilo\Plugin\OpenMeetings\Room();
$roomTypeId = $isModerated = ( $this->isTeacher() ) ? 1 : 2 ;
$params['c_id'] = api_get_course_int_id();
$urlWsdl = CONFIG_OPENMEETINGS_SERVER_URL . "/services/RoomService?wsdl";
$objAddRoom->SID = $this->sessionId;
$objAddRoom->name = $this->roomName;
$objAddRoom->roomtypes_id = $roomTypeId;
$objAddRoom->comment = get_lang('Course').': ' . $params['meeting_name'] . ' Plugin for Chamilo';
$objAddRoom->numberOfPartizipants = 40;
$objAddRoom->ispublic = true;
$objAddRoom->appointment = false;
$objAddRoom->isDemoRoom = false;
$objAddRoom->demoTime = false;
$objAddRoom->isModeratedRoom = $isModerated;
$objAddRoom->externalRoomType = 'chamilolms';
$omServices = new SoapClient($urlWsdl, array("trace" => 1, "exceptions" => true, "cache_wsdl" => WSDL_CACHE_NONE));
//$id = \Database::insert($this->table, $params);
// First, try to see if there is an active room for this course and session
$roomId = null;
$meetingData = \Database::select('*', $this->table, array('where' => array('c_id = ?' => $this->chamiloCourseId, ' AND session_id = ? ' => $this->chamiloSessionId)), 'first');
if (count($meetingData) > 0) {
//error_log('Found previous room reference - reusing');
// There has been a room in the past for this course. It should
// still be on the server, so update (instead of creating a new one)
// This fills the following attributes: status, name, comment, chamiloCourseId, chamiloSessionId
$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'].')';
error_log($msg);
die($msg);
}
try {
$s = $omServices->addRoomWithModerationAndExternalType($objAddRoom);
//error_log($omServices->__getLastRequest());
//error_log($omServices->__getLastResponse());
error_log(print_r($s,1));
} catch (SoapFault $e) {
echo "< h1 > Warning< / h1 >
< p > We have detected some problems < / br >
Fault: {$e->faultstring}< / p > ";
return -1;
} else {
error_log('Found no previous room - creating');
$room = new Room();
// Room types are described here http://openmeetings.apache.org/RoomService.html#addRoomWithModerationAndExternalType
// 1 = Conference, 2 = Audience, 3 = Restricted, 4 = Interview
$roomTypeId = ( $this->isTeacher() ) ? 1 : 2 ;
$isModerated = ($roomTypeId > 0); //bool
$urlWsdl = $this->url . "/services/RoomService?wsdl";
$room->SID = $this->sessionId;
$room->name = $this->roomName;
$room->roomtypes_id = $roomTypeId;
$room->comment = get_lang('Course').': ' . $params['meeting_name'] . ' Plugin for Chamilo';
$room->numberOfPartizipants = 40;
$room->ispublic = true;
$room->appointment = false;
$room->isDemoRoom = false;
$room->demoTime = 0;
$room->isModeratedRoom = $isModerated;
$room->externalRoomType = 'chamilolms';
$roomId = $this->gateway->createRoomWithModAndType($room);
}
//if we get here, this means addRoomWithModerationAndExternalType worked
if ($s->return > -1) {
$meetingId = $params['id'] = $s->return;
if (!empty($roomId)) {
/*
// Find the biggest room_id so far, and create a new one
if (empty($roomId)) {
$roomData = \Database::select('MAX(room_id) as room_id', $this->table, array(), 'first');
$roomId = $roomData['room_id'] + 1;
}*/
$params['status'] = '1';
$params['meeting_name'] = $this->roomName;
$params['meeting_name'] = $room->n ame;
$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();
Database::insert($this->table, $params);
$id = \ Database::insert($this->table, $params);
$this->joinMeeting($meet ingI d);
$this->joinMeeting($id);
} else {
return -1;
}
} catch(SoapFault $e) {
echo "< h1 > Warning< / h1 >
< p > We have detected some problems < / br >
Fault: {$e->faultstring}< / p > ";
return -1;
}
}
/**
* Returns a meeting "join" URL
@ -185,19 +208,19 @@ class OpenMeetings
if (empty($meetingId)) {
return false;
}
$meetingData = Database::select('*', $this->table, array('where' => array('id = ? AND status = 1 ' => $meetingId)), 'first');
$meetingData = \ Database::select('*', $this->table, array('where' => array('id = ? AND status = 1 ' => $meetingId)), 'first');
if (empty($meetingData)) {
if ($this->debug) error_log("meeting does not exist: $meetingId ");
return false;
}
$params = array( 'room_id' => $meetingId );
$params = array( 'room_id' => $meetingData['room_id'] );
$returnVal = $this->setUserObjectAndGenerateRoomHashByURLAndRecFlag( $params );
//$urlWithoutProtocol = str_replace("http://", CONFIG_OPENMEETINGS_SERVER_URL);
//$imgWithoutProtocol = str_replace("http://", $_SESSION['_user']['avatar'] );
$iframe = CONFIG_OPENMEETINGS_SERVER_URL . "/?" .
$iframe = $this->url . "/?" .
"secureHash=" . $returnVal /*.
'& username=FRAGOTE' .
'& firstname=DD' .
@ -221,6 +244,9 @@ class OpenMeetings
*/
function isServerRunning()
{
// Always return true for now as this requires the openmeetings object
// to have been instanciated and this includes a loginUser() which
// connects to the server
return true;
}
/**
@ -254,12 +280,12 @@ class OpenMeetings
try {
$result = $this->api->getMeetingInfoArray($params);
if ($result == null) {
if ($this->debug) error_log("Failed to get any response. Maybe we can't contact the OpenMeetings server.");
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('Caught exception: ', $e->getMessage(), "\n");
if ($this->debug) error_log(__FILE__. '+'.__LINE__.' Caught exception: ', $e->getMessage(), "\n");
}
return false;
}
@ -277,9 +303,9 @@ class OpenMeetings
$systemType = 'chamilo';
$room_id = $params['room_id'];
$urlWsdl = CONFIG_OPENMEETINGS_SERVER_URL . "/services/UserService?wsdl";
$omServices = new SoapClient( $urlWsdl );
$objRec = new Chamilo\Plugin\OpenMeetings\ User();
$urlWsdl = $this->url . "/services/UserService?wsdl";
$omServices = new \ SoapClient( $urlWsdl );
$objRec = new User();
$objRec->SID = $this->sessionId;
$objRec->username = $username;
@ -311,9 +337,9 @@ class OpenMeetings
$becomeModerator = ( $this->isTeacher() ? 1 : 0 );
$allowRecording = 1; //Provisional
$urlWsdl = CONFIG_OPENMEETINGS_SERVER_URL . "/services/UserService?wsdl";
$omServices = new SoapClient( $urlWsdl );
$objRec = new Chamilo\Plugin\OpenMeetings\ User();
$urlWsdl = $this->url . "/services/UserService?wsdl";
$omServices = new \ SoapClient( $urlWsdl );
$objRec = new User();
$objRec->SID = $this->sessionId;
$objRec->username = $username;
@ -339,18 +365,18 @@ class OpenMeetings
*/
function getCourseMeetings()
{
$new_meeting_l ist = array();
$newMeetingsL ist = array();
$item = array();
$this->loginUser();
$meeting_list = Database::select('*', $this->table, array('where' => array('c_id = ? ' => api_get_course_int_id(), ' AND session_id = ? ' => api_get_session_id())));
$meetingsList = \Database::select('*', $this->table, array('where' => array('c_id = ? ' => api_get_course_int_id(), ' AND session_id = ? ' => api_get_session_id())));
error_log(__FILE__.' '.__FUNCTION__.' '.__LINE__.' '.print_r($meeting_l ist,1));
//error_log(__FILE__.'+'.__LINE__.' Meetings found: '.print_r($meetingsL ist,1));
$urlWsdl = CONFIG_OPENMEETINGS_SERVER_URL . "/services/RoomService?wsdl";
$omServices = new SoapClient($urlWsdl);
$objRoom = new Chamilo\Plugin\OpenMeetings\Room();
$urlWsdl = $this->url . "/services/RoomService?wsdl";
$omServices = new \SoapClient($urlWsdl);
$room = new Room();
/*
try {
$rooms = $this->gateway->getRoomsWithCurrentUsersByType($this->sessionId );
$rooms = $this->gateway->getRoomsWithCurrentUsersByType();
//$rooms = $omServices->getRoomsPublic(array(
//'SID' => $this->sessionId,
//'start' => 0,
@ -362,23 +388,39 @@ class OpenMeetings
//)
//);
} catch (SoapFault $e) {
error_log($e->faultstring);
error_log(__FILE__.'+'.__LINE__.' '. $e->faultstring);
//error_log($rooms->getDebug());
return false;
}
$objRoom->SID = $this->sessionId;
foreach ($meeting_list as $meeting_db) {
$objRoom->rooms_id = $meeting_db['id'];
*/
$room->SID = $this->sessionId;
//error_log(__FILE__.'+'.__LINE__.' Meetings found: '.print_r($room->SID,1));
foreach ($meetingsList as $meetingDb) {
//$room->rooms_id = $meetingDb['room_id'];
//error_log(__FILE__.'+'.__LINE__.' Meetings found: '.print_r($meetingDb['room_id'],1));
$remoteMeeting = array();
$meetingDb['created_at'] = api_get_local_time($meetingDb['created_at']);
$meetingDb['closed_at'] = (!empty($meetingDb['closed_at'])?api_get_local_time($meetingDb['closed_at']):'');
// Fixed value for now
$meetingDb['participantCount'] = 40;
// The following code is currently commented because the web service
// says this is not allowed by the SOAP user.
/*
try {
$objRoomId = $omServices->getRoomById($objRoom);
// Get the conference room object from OpenMeetings server - requires SID and rooms_id to be defined
$objRoomId = $this->gateway->getRoomById($meetingDb['room_id']);
if (empty($objRoomId->return)) {
Database::delete($this->table, "id = {$meeting_db['id']}");
error_log(__FILE__.'+'.__LINE__.' Emptyyyyy ');
//\Database::delete($this->table, "id = {$meetingDb['id']}");
// Don't delete expired rooms, just mark as closed
\Database::update($this->table, array('status' => 0, 'closed_at' => api_get_utc_datetime()), array('id = ? ' => $meetingDb['id']));
continue;
}
//$objCurUs = $omServices->getRoomWithCurrentUsersById($objCurrentUsers);
} catch (SoapFault $e) {
echo $e->faultstring;
error_log(__FILE__.'+'.__LINE__.' '.$e->faultstring) ;
exit;
}
//if( empty($objCurUs->returnMeetingID) ) continue;
@ -409,22 +451,26 @@ class OpenMeetings
);
}
$meeting_om = $current_room;
$remoteMeeting = $current_room;
*/
if (empty( $meeting_om )) {
if ($meeting_db['status'] == 1 & & $this->isTeacher()) {
$this->endMeeting($meeting_db['id']);
if (empty( $remoteMeeting )) {
/*
error_log(__FILE__.'+'.__LINE__.' Empty remote Meeting for now');
if ($meetingDb['status'] == 1 & & $this->isTeacher()) {
$this->endMeeting($meetingDb['id']);
}
*/
} else {
$meeting_om ['add_to_calendar_url'] = api_get_self().'?action=add_to_calendar&id='.$meeting_db['id'].'&start='.api_strtotime($meeting_d b['startTime']);
$re moteM eeting['add_to_calendar_url'] = api_get_self().'?action=add_to_calendar&id='.$meetingDb['id'].'&start='.api_strtotime($meetingD b['startTime']);
}
$meeting_om ['end_url'] = api_get_self().'?action=end&id='.$meeting_d b['id'];
$re moteM eeting['end_url'] = api_get_self().'?action=end&id='.$meetingD b['id'];
$record_array = array();
// $record_array = array();
// if ($meeting_d b['record'] == 1) {
// if ($meetingD b['record'] == 1) {
// $recordingParams = array(
// 'meetingId' => $meeting_d b['id'], //-- OPTIONAL - comma separate if multiple ids
// 'meetingId' => $meetingD b['id'], //-- OPTIONAL - comma separate if multiple ids
// );
//
// $records = $this->api->getRecordingsWithXmlResponseArray($recordingParams);
@ -441,8 +487,8 @@ class OpenMeetings
// if (is_array($record) & & isset($record['recordId'])) {
// $url = Display::url(get_lang('ViewRecord'), $record['playbackFormatUrl'], array('target' => '_blank'));
// if ($this->is_teacher()) {
// $url .= Display::url(Display::return_icon('link.gif',get_lang('CopyToLinkTool')), api_get_self().'?action=copy_record_to_link_tool&id='.$meeting_d b['id'].'&record_id='.$record['recordId']);
// $url .= Display::url(Display::return_icon('agenda.png',get_lang('AddToCalendar')), api_get_self().'?action=add_to_calendar&id='.$meeting_db['id'].'&start='.api_strtotime($meeting_d b['created_at']).'&url='.$record['playbackFormatUrl']);
// $url .= Display::url(Display::return_icon('link.gif',get_lang('CopyToLinkTool')), api_get_self().'?action=copy_record_to_link_tool&id='.$meetingD b['id'].'&record_id='.$record['recordId']);
// $url .= Display::url(Display::return_icon('agenda.png',get_lang('AddToCalendar')), api_get_self().'?action=add_to_calendar&id='.$meetingDb['id'].'&start='.api_strtotime($meetingD b['created_at']).'&url='.$record['playbackFormatUrl']);
// $url .= Display::url(Display::return_icon('delete.png',get_lang('Delete')), api_get_self().'?action=delete_record&id='.$record['recordId']);
// }
// //$url .= api_get_self().'?action=publish&id='.$record['recordID'];
@ -459,31 +505,32 @@ class OpenMeetings
//
// }
//
//$item['created_at'] = api_convert_and_format_date($meeting_d b['created_at']);
//$item['created_at'] = api_convert_and_format_date($meetingD b['created_at']);
// //created_at
//
// $item['publish_url'] = api_get_self().'?action=publish&id='.$meeting_d b['id'];
// $item['unpublish_url'] = api_get_self().'?action=unpublish&id='.$meeting_d b['id'];
// $item['publish_url'] = api_get_self().'?action=publish&id='.$meetingD b['id'];
// $item['unpublish_url'] = api_get_self().'?action=unpublish&id='.$meetingD b['id'];
//
//if ($meeting_d b['status'] == 1) {
//if ($meetingD b['status'] == 1) {
// $joinParams = array(
// 'meetingId' => $meeting_d b['id'], //-- REQUIRED - A unique id for the meeting
// 'meetingId' => $meetingD b['id'], //-- REQUIRED - A unique id for the meeting
// 'username' => $this->user_complete_name, //-- REQUIRED - The name that will display for the user in the meeting
// 'password' => $pass, //-- REQUIRED - The attendee or moderator password, depending on what's passed here
// 'createTime' => '', //-- OPTIONAL - string. Leave blank ('') unless you set this correctly.
// 'userID' => '', // -- OPTIONAL - string
// 'webVoiceConf' => '' // -- OPTIONAL - string
// );
// $returnVal = $this->setUserObjectAndGenerateRoomHashByURLAndRecFlag( array('room_id' => $meeting_d b['id']) );
// $returnVal = $this->setUserObjectAndGenerateRoomHashByURLAndRecFlag( array('room_id' => $meetingD b['id']) );
// $joinUrl = CONFIG_OPENMEETINGS_SERVER_URL . "?" .
// "secureHash=" . $returnVal;
//
// $item['go_url'] = $joinUrl;
//}
$item = array_merge($item, $meeting_db, $meeting_om);
$new_meeting_list[] = $item;
}
return $new_meeting_list;
$item = array_merge($item, $meetingDb, $remoteMeeting);
//error_log(__FILE__.'+'.__LINE__.' Item: '.print_r($item,1));
$newMeetingsList[] = $item;
} //end foreach $meetingsList
return $newMeetingsList;
}
/**
@ -494,24 +541,20 @@ class OpenMeetings
function endMeeting($meetingId)
{
try {
$this->loginUser();
$urlWsdl = CONFIG_OPENMEETINGS_SERVER_URL . "/services/RoomService?wsdl";
$omServices = new SoapClient( $urlWsdl );
$objClose = new Chamilo\Plugin\OpenMeetings\Room();
$objClose->SID = $this->sessionId;
$objClose->room_id = intval($meetingId);
$objClose->status = false;
$roomClosed = $omServices->closeRoom( $objClose );
error_log('Closing');
$urlWsdl = $this->url . "/services/RoomService?wsdl";
$ws = new \SoapClient( $urlWsdl );
$room = new Room($meetingId);
$room->SID = $this->sessionId;
$room->room_id = intval($meetingId);
$room->status = false;
$roomClosed = $ws->closeRoom($room);
if ($roomClosed > 0) {
error_log('Closing returned '.print_r($roomClosed,1));
Database::update($this->table, array('status' => 0, 'closed_at' => api_get_utc_datetime()), array('id = ? ' => $meetingId));
//error_log(__FILE__.'+'.__LINE__.' Closing returned '.print_r($roomClosed,1));
\ Database::update($this->table, array('status' => 0, 'closed_at' => api_get_utc_datetime()), array('id = ? ' => $meetingId));
}
error_log('Finished closing');
// error_log(__FILE__.'+ '.__LINE__.' Finished closing');
} catch (SoapFault $e) {
echo "< h1 > Warning< / h1 >
< p > We have detected some problems < / br >
Fault: {$e->faultstring}< / p > ";
error_log(__FILE__.'+'.__LINE__.' Warning: We have detected some problems: Fault: '.$e->faultstring);
exit;
return -1;
}