/**
 * Delete user in adobe connect
 * @param $user  object with the following fields: username, idnumber, email, firstname, lastname, password
 * @return bool
 */
function connectsync_delete_user($user)
{
    if ($aconnect = aconnect_login()) {
        $pid = aconnect_user_exists($aconnect, $user);
        if ($pid) {
            $rvalue = aconnect_delete_user($aconnect, $pid);
            // Pid = principle id.
            echo "Deleted user: "******" in Adobe Connect\n";
        } else {
            $rvalue = true;
            // TODO User doesn't exist.....delete successful log?
        }
    } else {
        // TODO: Logging? Log trouble connecting?
        $rvalue = false;
    }
    aconnect_logout($aconnect);
    return $rvalue;
    // Do nothing.
}
function adobe_connection_test($host = '', $port = 80, $username = '', $password = '', $httpheader = '', $emaillogin)
{
    if (empty($host) or empty($port) or 0 == $port or empty($username) or empty($password) or empty($httpheader)) {
        echo "</p>One of the required parameters is blank or incorrect: <br />" . "Host: {$host}<br /> Port: {$port}<br /> Username: {$username}<br /> Password: {$password}" . "<br /> HTTP Header: {$httpheader}</p>";
        die;
    }
    $messages = array();
    $aconnectDOM = new connect_class_dom($host, $port, $username, $password);
    $params = array('action' => 'common-info');
    // Send common-info call to obtain the session key
    echo '<p>Sending common-info call:</p>';
    $aconnectDOM->create_request($params);
    if (!empty($aconnectDOM->_xmlresponse)) {
        // Get the session key from the XML response
        $aconnectDOM->read_cookie_xml($aconnectDOM->_xmlresponse);
        $cookie = $aconnectDOM->get_cookie();
        if (empty($cookie)) {
            echo '<p>unable to obtain session key from common-info call</p>';
            echo '<p>xmlrequest:</p>';
            $doc = new DOMDocument();
            if ($doc->loadXML($aconnectDOM->_xmlrequest)) {
                echo '<p>' . htmlspecialchars($doc->saveXML()) . '</p>';
            } else {
                echo '<p>unable to display the XML request</p>';
            }
            echo '<p>xmlresponse:</p>';
            $doc = new DOMDocument();
            if ($doc->loadXML($aconnectDOM->_xmlresponse)) {
                echo '<p>' . htmlspecialchars($doc->saveHTML()) . '</p>';
            } else {
                echo '<p>unable to display the XML response</p>';
            }
        } else {
            // print success
            echo '<p style="color:#006633">successfully obtained the session key: ' . $aconnectDOM->get_cookie() . '</p>';
            // test logging in as the administrator
            $params = array('action' => 'login', 'login' => $aconnectDOM->get_username(), 'password' => $aconnectDOM->get_password());
            $aconnectDOM->create_request($params);
            if ($aconnectDOM->call_success()) {
                echo '<p style="color:#006633">successfully logged in as admin user</p>';
                //$username
                //Test retrevial of folders
                echo '<p>Testing retrevial of shared content, recording and meeting folders:</p>';
                $folderscoid = aconnect_get_folder($aconnectDOM, 'content');
                if ($folderscoid) {
                    echo '<p style="color:#006633">successfully obtained shared content folder scoid: ' . $folderscoid . '</p>';
                } else {
                    echo '<p>error obtaining shared content folder</p>';
                    echo '<p style="color:#680000">XML request:<br />' . htmlspecialchars($aconnectDOM->_xmlrequest) . '</p>';
                    echo '<p style="color:#680000">XML response:<br />' . htmlspecialchars($aconnectDOM->_xmlresponse) . '</p>';
                }
                $folderscoid = aconnect_get_folder($aconnectDOM, 'forced-archives');
                if ($folderscoid) {
                    echo '<p style="color:#006633">successfully obtained forced-archives (meeting recordings) folder scoid: ' . $folderscoid . '</p>';
                } else {
                    echo '<p>error obtaining forced-archives (meeting recordings) folder</p>';
                    echo '<p style="color:#680000">XML request:<br />' . htmlspecialchars($aconnectDOM->_xmlrequest) . '</p>';
                    echo '<p style="color:#680000">XML response:<br />' . htmlspecialchars($aconnectDOM->_xmlresponse) . '</p>';
                }
                $folderscoid = aconnect_get_folder($aconnectDOM, 'meetings');
                if ($folderscoid) {
                    echo '<p style="color:#006633">successfully obtained meetings folder scoid: ' . $folderscoid . '</p>';
                } else {
                    echo '<p>error obtaining meetings folder</p>';
                    echo '<p style="color:#680000">XML request:<br />' . htmlspecialchars($aconnectDOM->_xmlrequest) . '</p>';
                    echo '<p style="color:#680000">XML response:<br />' . htmlspecialchars($aconnectDOM->_xmlresponse) . '</p>';
                }
                //Test creating a meeting
                $folderscoid = aconnect_get_folder($aconnectDOM, 'meetings');
                $meeting = new stdClass();
                $meeting->name = 'testmeetingtest';
                $time = time();
                $meeting->starttime = $time;
                $time = $time + 60 * 60;
                $meeting->endtime = $time;
                if ($meetingscoid = aconnect_create_meeting($aconnectDOM, $meeting, $folderscoid)) {
                    echo '<p style="color:#006633">successfully created meeting <b>testmeetingtest</b> scoid: ' . $meetingscoid . '</p>';
                } else {
                    echo '<p>error creating meeting <b>testmeetingtest</b> folder</p>';
                    echo '<p style="color:#680000">XML request:<br />' . htmlspecialchars($aconnectDOM->_xmlrequest) . '</p>';
                    echo '<p style="color:#680000">XML response:<br />' . htmlspecialchars($aconnectDOM->_xmlresponse) . '</p>';
                }
                //Test creating a user
                $user = new stdClass();
                $user->username = '******';
                $user->firstname = 'testusertest';
                $user->lastname = 'testusertest';
                $user->email = '*****@*****.**';
                if (!empty($emaillogin)) {
                    $user->username = $user->email;
                }
                $skipdeletetest = false;
                if (!($usrprincipal = aconnect_user_exists($aconnectDOM, $user))) {
                    $usrprincipal = aconnect_create_user($aconnectDOM, $user);
                    if ($usrprincipal) {
                        echo '<p style="color:#006633">successfully created user <b>testusertest</b> principal-id: ' . $usrprincipal . '</p>';
                    } else {
                        echo '<p>error creating user  <b>testusertest</b></p>';
                        echo '<p style="color:#680000">XML request:<br />' . htmlspecialchars($aconnectDOM->_xmlrequest) . '</p>';
                        echo '<p style="color:#680000">XML response:<br />' . htmlspecialchars($aconnectDOM->_xmlresponse) . '</p>';
                    }
                } else {
                    echo '<p>user <b>testusertest</b> already exists skipping delete user test</p>';
                    $skipdeletetest = true;
                }
                //Test assigning a user a role to the meeting
                if (aconnect_check_user_perm($aconnectDOM, $usrprincipal, $meetingscoid, ADOBE_PRESENTER, true)) {
                    echo '<p style="color:#006633">successfully assigned user <b>testusertest</b>' . ' presenter role in meeting <b>testmeetingtest</b>: ' . $usrprincipal . '</p>';
                } else {
                    echo '<p>error assigning user <b>testusertest</b> presenter role in meeting <b>testmeetingtest</b></p>';
                    echo '<p style="color:#680000">XML request:<br />' . htmlspecialchars($aconnectDOM->_xmlrequest) . '</p>';
                    echo '<p style="color:#680000">XML response:<br />' . htmlspecialchars($aconnectDOM->_xmlresponse) . '</p>';
                }
                //Test removing role from meeting
                if (aconnect_check_user_perm($aconnectDOM, $usrprincipal, $meetingscoid, ADOBE_REMOVE_ROLE, true)) {
                    echo '<p style="color:#006633">successfully removed presenter role for user <b>testusertest</b>' . ' in meeting <b>testmeetingtest</b>: ' . $usrprincipal . '</p>';
                } else {
                    echo '<p>error remove presenter role for user <b>testusertest</b> in meeting <b>testmeetingtest</b></p>';
                    echo '<p style="color:#680000">XML request:<br />' . htmlspecialchars($aconnectDOM->_xmlrequest) . '</p>';
                    echo '<p style="color:#680000">XML response:<br />' . htmlspecialchars($aconnectDOM->_xmlresponse) . '</p>';
                }
                //Test removing user from server
                if (!$skipdeletetest) {
                    if (aconnect_delete_user($aconnectDOM, $usrprincipal)) {
                        echo '<p style="color:#006633">successfully removed user <b>testusertest</b> principal-id: ' . $usrprincipal . '</p>';
                    } else {
                        echo '<p>error removing user <b>testusertest</b></p>';
                        echo '<p style="color:#680000">XML request:<br />' . htmlspecialchars($aconnectDOM->_xmlrequest) . '</p>';
                        echo '<p style="color:#680000">XML response:<br />' . htmlspecialchars($aconnectDOM->_xmlresponse) . '</p>';
                    }
                }
                //Test removing meeting from server
                if ($meetingscoid) {
                    if (aconnect_remove_meeting($aconnectDOM, $meetingscoid)) {
                        echo '<p style="color:#006633">successfully removed meeting <b>testmeetingtest</b> scoid: ' . $meetingscoid . '</p>';
                    } else {
                        echo '<p>error removing meeting <b>testmeetingtest</b> folder</p>';
                        echo '<p style="color:#680000">XML request:<br />' . htmlspecialchars($aconnectDOM->_xmlrequest) . '</p>';
                        echo '<p style="color:#680000">XML response:<br />' . htmlspecialchars($aconnectDOM->_xmlresponse) . '</p>';
                    }
                }
            } else {
                echo '<p style="color:#680000">logging in as ' . $username . ' was not successful, check to see if the username and password are correct </p>';
            }
        }
    } else {
        echo '<p style="color:#680000">common-info API call returned an empty document.  Please check your settings and try again </p>';
    }
    aconnect_logout($aconnectDOM);
}
Beispiel #3
0
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)) {
            if (aconnect_check_user_perm($aconnect, $usrprincipal, $meetingscoid, ADOBE_HOST, true)) {
                //DEBUG
                //                 echo 'host';
                //                 die();
 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;
 }