$usrcanjoin = true; } } // user has to be in a group if ($usrcanjoin and confirm_sesskey($sesskey)) { $usrprincipal = 0; $validuser = true; $groupobj = groups_get_group($groupid); // Get the meeting sco-id $param = array('instanceid' => $cm->instance, 'groupid' => $groupid); $meetingscoid = $DB->get_field('adobeconnect_meeting_groups', 'meetingscoid', $param); $aconnect = aconnect_login(); // Check if the meeting still exists on the Adobe server $meetfldscoid = aconnect_get_folder($aconnect, 'my-meetings'); $filter = array('filter-sco-id' => $meetingscoid); $meeting = aconnect_meeting_exists($aconnect, $meetfldscoid, $filter); if (!empty($meeting)) { $meeting = current($meeting); } if (!($usrprincipal = aconnect_user_exists($aconnect, $usrobj))) { if (!($usrprincipal = aconnect_create_user($aconnect, $usrobj))) { // DEBUG print_object("error creating user"); print_object($aconnect->_xmlresponse); $validuser = false; } } $context = get_context_instance(CONTEXT_MODULE, $id); // Check the user's capabilities and assign them the Adobe Role if (!empty($meetingscoid) and !empty($usrprincipal) and !empty($meeting)) { if (has_capability('mod/adobeconnect:meetinghost', $context, $usrobj->id, false)) {
function validation($data, $files) { global $CFG; $errors = parent::validation($data, $files); $aconnect = aconnect_login(); // Search for a Meeting with the same starting name. It will cause a duplicate // meeting name (and error) when the user begins to add participants to the meeting $meetfldscoid = aconnect_get_folder($aconnect, 'meetings'); $filter = array('filter-like-name' => $data['name']); $namematches = aconnect_meeting_exists($aconnect, $meetfldscoid, $filter); if (empty($namematches)) { $namematches = array(); } // Now search for existing meeting room URLs $url = $data['meeturl']; // Check to see if there are any trailing slashes or additional parts to the url // ex. mymeeting/mysecondmeeting/ Only the 'mymeeting' part is valid if (0 != substr_count($url, '/') and false !== strpos($url, '/', 1)) { $errors['meeturl'] = get_string('invalidadobemeeturl', 'adobeconnect'); } $filter = array('filter-like-url-path' => $url); $urlmatches = aconnect_meeting_exists($aconnect, $meetfldscoid, $filter); if (empty($urlmatches)) { $urlmatches = array(); } else { // format url for comparison if (false === strpos($url, '/') or 0 != strpos($url, '/')) { $url = '/' . $url; } } // Adding activity if (empty($data['update'])) { if ($data['starttime'] == $data['endtime']) { $errors['starttime'] = get_string('samemeettime', 'adobeconnect'); $errors['endtime'] = get_string('samemeettime', 'adobeconnect'); } elseif ($data['endtime'] < $data['starttime']) { $errors['starttime'] = get_string('greaterstarttime', 'adobeconnect'); } // Check for local activities with the same name if (record_exists('adobeconnect', 'name', $data['name'])) { $errors['name'] = get_string('duplicatemeetingname', 'adobeconnect'); return $errors; } // Check Adobe connect server for duplicated names foreach ($namematches as $matchkey => $match) { if (0 == substr_compare($match->name, $data['name'] . '_', 0, strlen($data['name'] . '_'), false)) { $errors['name'] = get_string('duplicatemeetingname', 'adobeconnect'); } } foreach ($urlmatches as $matchkey => $match) { $matchurl = rtrim($match->url, '/'); if (0 == substr_compare($matchurl, $url . '_', 0, strlen($url . '_'), false)) { $errors['meeturl'] = get_string('duplicateurl', 'adobeconnect'); } } } else { // Updating activity // Look for existing meeting names, excluding this activity's group meeting(s) $sql = "SELECT meetingscoid, groupid FROM {$CFG->prefix}adobeconnect_meeting_groups " . " WHERE instanceid = " . $data['instance']; $grpmeetings = get_records_sql($sql); if (empty($grpmeetings)) { $grpmeetings = array(); } foreach ($namematches as $matchkey => $match) { if (!array_key_exists($match->scoid, $grpmeetings)) { if (0 == substr_compare($match->name, $data['name'] . '_', 0, strlen($data['name'] . '_'), false)) { $errors['name'] = get_string('duplicatemeetingname', 'adobeconnect'); } } } foreach ($urlmatches as $matchkey => $match) { if (!array_key_exists($match->scoid, $grpmeetings)) { if (0 == substr_compare($match->url, $url . '_', 0, strlen($url . '_'), false)) { $errors['meeturl'] = get_string('duplicateurl', 'adobeconnect'); } } } // Validate start and end times if ($data['starttime'] == $data['endtime']) { $errors['starttime'] = get_string('samemeettime', 'adobeconnect'); $errors['endtime'] = get_string('samemeettime', 'adobeconnect'); } elseif ($data['endtime'] < $data['starttime']) { $errors['starttime'] = get_string('greaterstarttime', 'adobeconnect'); } } aconnect_logout($aconnect); return $errors; }
/** * Given an object containing all the necessary data, * (defined by the form in mod_form.php) this function * will update an existing instance with new data. * * @param object $adobeconnect An object from the form in mod_form.php * @return boolean Success/Fail */ function adobeconnect_update_instance($adobeconnect) { global $DB; $adobeconnect->timemodified = time(); $adobeconnect->id = $adobeconnect->instance; $aconnect = aconnect_login(); $meetfldscoid = aconnect_get_folder($aconnect, 'my-meetings'); // Look for meetings whose names are similar $filter = array('filter-like-name' => $adobeconnect->name); $namematches = aconnect_meeting_exists($aconnect, $meetfldscoid, $filter); if (empty($namematches)) { $namematches = array(); } // Find meeting URLs that are similar $url = $adobeconnect->meeturl; $filter = array('filter-like-url-path' => $url); $urlmatches = aconnect_meeting_exists($aconnect, $meetfldscoid, $filter); if (empty($urlmatches)) { $urlmatches = array(); } else { // format url for comparison if (false === strpos($url, '/') or 0 != strpos($url, '/')) { $url = '/' . $url; } } $url = adobeconnect_clean_meet_url($url); // Get all instances of the activity meetings $param = array('instanceid' => $adobeconnect->instance); $grpmeetings = $DB->get_records('adobeconnect_meeting_groups', $param); if (empty($grpmeetings)) { $grpmeetings = array(); } // If no errors then check to see if the updated name and URL are actually different // If true, then update the meeting names and URLs now. $namechange = true; $urlchange = true; $timechange = true; // Look for meeting name change foreach ($namematches as $matchkey => $match) { if (array_key_exists($match->scoid, $grpmeetings)) { if (0 == substr_compare($match->name, $adobeconnect->name . '_', 0, strlen($adobeconnect->name . '_'), false)) { // Break out of loop and change all referenced meetings $namechange = false; break; } elseif (date('c', $adobeconnect->starttime) == $match->starttime) { $timechange = false; break; } elseif (date('c', $adobeconnect->endtime) == $match->endtime) { $timechange = false; break; } } } // Look for URL change foreach ($urlmatches as $matchkey => $match) { if (array_key_exists($match->scoid, $grpmeetings)) { if (0 == substr_compare($match->url, $url . '_', 0, strlen($url . '_'), false)) { // Break out of loop and change all referenced meetings $urlchange = false; break; } elseif (date('c', $adobeconnect->starttime) == $match->starttime) { $timechange = false; break; } elseif (date('c', $adobeconnect->endtime) == $match->endtime) { $timechange = false; break; } } } if ($timechange or $urlchange or $namechange) { $group = ''; $meetingobj = new stdClass(); foreach ($grpmeetings as $scoid => $grpmeeting) { if ($adobeconnect->groupmode) { $group = groups_get_group($grpmeeting->groupid); $group = '_' . $group->name; } else { $group = ''; } $meetingobj->scoid = $grpmeeting->meetingscoid; $meetingobj->name = $adobeconnect->name . $group; // updating meeting URL using the API corrupts the meeting for some reason // $meetingobj->meeturl = $data['meeturl'] . '_' . $group->name; $meetingobj->starttime = date('c', $adobeconnect->starttime); $meetingobj->endtime = date('c', $adobeconnect->endtime); // Update each meeting instance if (!aconnect_update_meeting($aconnect, $meetingobj, $meetfldscoid)) { debugging('error updating meeting', DEBUG_DEVELOPER); } if (empty($adobeconnect->meetingpublic)) { aconnect_update_meeting_perm($aconnect, $grpmeeting->meetingscoid, ADOBE_MEETPERM_PRIVATE); } else { aconnect_update_meeting_perm($aconnect, $grpmeeting->meetingscoid, ADOBE_MEETPERM_PUBLIC); } // Update calendar event $param = array('courseid' => $adobeconnect->course, 'instance' => $adobeconnect->id, 'groupid' => $grpmeeting->groupid, 'modulename' => 'adobeconnect'); $eventid = $DB->get_field('event', 'id', $param); if (!empty($eventid)) { $event = new stdClass(); $event->id = $eventid; $event->name = $meetingobj->name; $event->description = format_module_intro('adobeconnect', $adobeconnect, $adobeconnect->coursemodule); $event->courseid = $adobeconnect->course; $event->groupid = $grpmeeting->groupid; $event->userid = 0; $event->instance = $adobeconnect->id; $event->eventtype = 0 == $grpmeeting->groupid ? 'course' : 'group'; $event->timestart = $adobeconnect->starttime; $event->timeduration = $adobeconnect->endtime - $adobeconnect->starttime; $event->visible = 1; $event->modulename = 'adobeconnect'; $calendarevent = calendar_event::load($eventid); $calendarevent->update($event); } } } aconnect_logout($aconnect); return $DB->update_record('adobeconnect', $adobeconnect); }
public function validation($data, $files) { global $DB, $USER, $COURSE; $errors = parent::validation($data, $files); $usrobj = clone $USER; $name = empty($usrobj->idnumber) ? $usrobj->username : $usrobj->idnumber; $usrobj->username = set_username($name, $usrobj->email); $aconnect = aconnect_login(); $groupprincipalid = aconnect_get_host_group($aconnect); // Check if the user exists and if not create the new user. if (!($usrprincipal = aconnect_user_exists($aconnect, $usrobj))) { if (!($usrprincipal = aconnect_create_user($aconnect, $usrobj))) { debugging("error creating user", DEBUG_DEVELOPER); } } // Add the user to the host group if they aren't already. aconnect_add_user_group($aconnect, $groupprincipalid, $usrprincipal); // Search for a Meeting with the same starting name. It will cause a duplicate // meeting name (and error) when the user begins to add participants to the meeting. $meetfldscoid = aconnect_get_folder($aconnect, 'meetings'); $filter = array('filter-like-name' => $data['name']); $namematches = aconnect_meeting_exists($aconnect, $meetfldscoid, $filter); // Search the user's adobe connect folder. $usrfldscoid = aconnect_get_user_folder_sco_id($aconnect, $usrobj->username); if (!empty($usrfldscoid)) { $namematches = $namematches + aconnect_meeting_exists($aconnect, $usrfldscoid, $filter); } if (empty($namematches)) { $namematches = array(); } // Now search for existing meeting room URLs. $url = $data['meeturl'] = adobeconnect_clean_meet_url($data['meeturl']); // Check to see if there are any trailing slashes or additional parts to the url // ex. mymeeting/mysecondmeeting/ Only the 'mymeeting' part is valid. if (0 != substr_count($url, '/') and false !== strpos($url, '/', 1)) { $errors['meeturl'] = get_string('invalidadobemeeturl', 'adobeconnect'); } $filter = array('filter-like-url-path' => $url); $urlmatches = aconnect_meeting_exists($aconnect, $meetfldscoid, $filter); // Search the user's adobe connect folder. if (!empty($usrfldscoid)) { $urlmatches = $urlmatches + aconnect_meeting_exists($aconnect, $usrfldscoid, $filter); } if (empty($urlmatches)) { $urlmatches = array(); } else { // Format url for comparison. if (false === strpos($url, '/') or 0 != strpos($url, '/')) { $url = '/' . $url; } } // Check URL for correct length and format. if (!empty($data['meeturl'])) { if (strlen($data['meeturl']) > 60) { $errors['meeturl'] = get_string('longurl', 'adobeconnect'); } else { if (!preg_match('/^[a-z][a-z\\-]*/i', $data['meeturl'])) { $errors['meeturl'] = get_string('invalidurl', 'adobeconnect'); } } } // Check for available groups if groupmode is selected. if ($data['groupmode'] > 0) { $crsgroups = groups_get_all_groups($COURSE->id); if (empty($crsgroups)) { $errors['groupmode'] = get_string('missingexpectedgroups', 'adobeconnect'); } } // Adding activity. if (empty($data['update'])) { if ($data['starttime'] == $data['endtime']) { $errors['starttime'] = get_string('samemeettime', 'adobeconnect'); $errors['endtime'] = get_string('samemeettime', 'adobeconnect'); } else { if ($data['endtime'] < $data['starttime']) { $errors['starttime'] = get_string('greaterstarttime', 'adobeconnect'); } } // Check for local activities with the same name. $params = array('name' => $data['name']); if ($DB->record_exists('adobeconnect', $params)) { $errors['name'] = get_string('duplicatemeetingname', 'adobeconnect'); return $errors; } // Check Adobe connect server for duplicated names. foreach ($namematches as $match) { if (0 == substr_compare($match->name, $data['name'] . '_', 0, strlen($data['name'] . '_'), false)) { $errors['name'] = get_string('duplicatemeetingname', 'adobeconnect'); } } foreach ($urlmatches as $match) { $matchurl = rtrim($match->url, '/'); if (0 == substr_compare($matchurl, $url . '_', 0, strlen($url . '_'), false)) { $errors['meeturl'] = get_string('duplicateurl', 'adobeconnect'); } } } else { // Updating activity // Look for existing meeting names, excluding this activity's group meeting(s). $grpmeetings = $DB->get_records('adobeconnect_meeting_groups', array('instanceid' => $data['instance']), null, 'meetingscoid, groupid'); if (empty($grpmeetings)) { $grpmeetings = array(); } foreach ($namematches as $match) { if (!array_key_exists($match->scoid, $grpmeetings)) { if (0 == substr_compare($match->name, $data['name'] . '_', 0, strlen($data['name'] . '_'), false)) { $errors['name'] = get_string('duplicatemeetingname', 'adobeconnect'); } } } foreach ($urlmatches as $match) { if (!array_key_exists($match->scoid, $grpmeetings)) { if (0 == substr_compare($match->url, $url . '_', 0, strlen($url . '_'), false)) { $errors['meeturl'] = get_string('duplicateurl', 'adobeconnect'); } } } // Validate start and end times. if ($data['starttime'] == $data['endtime']) { $errors['starttime'] = get_string('samemeettime', 'adobeconnect'); $errors['endtime'] = get_string('samemeettime', 'adobeconnect'); } else { if ($data['endtime'] < $data['starttime']) { $errors['starttime'] = get_string('greaterstarttime', 'adobeconnect'); } } } aconnect_logout($aconnect); if ($aconnect->timeout()) { $errors = array('name' => get_string('errortimeout', 'adobeconnect')); } return $errors; }