Beispiel #1
0
 /**
  * Delete a meeting/webinar on Zoom.
  *
  * @param object $zoom
  * @return bool Success/Failure
  */
 public function meeting_delete($zoom)
 {
     $url = $zoom->webinar ? 'webinar/delete' : 'meeting/delete';
     $data = array('id' => $zoom->meeting_id, 'host_id' => $zoom->host_id);
     try {
         $this->make_call($url, $data);
     } catch (moodle_exception $e) {
         // If meeting isn't found or has expired, that's fine.
         global $CFG;
         require_once $CFG->dirroot . '/mod/zoom/lib.php';
         return zoom_is_meeting_gone_error($e->getMessage());
     }
     return true;
 }
Beispiel #2
0
/**
 * Print a user-friendly error message when a Zoom API call errors,
 * or fall back to a generic error message.
 *
 * @param string $apicall API endpoint (e.g. meeting/get)
 * @param string $error Error message (most likely from mod_zoom_webservice->lasterror)
 */
function zoom_print_error($apicall, $error)
{
    global $CFG, $COURSE, $OUTPUT, $PAGE;
    // Lang string for the error.
    $errstring = 'zoomerr';
    // Parameter for the lang string.
    $param = null;
    // Style of the error notification.
    $style = 'notifyproblem';
    // Link that the continue button points to.
    if (isset($_SERVER['HTTP_REFERER'])) {
        $nexturl = clean_param($_SERVER['HTTP_REFERER'], PARAM_LOCALURL);
    } else {
        $nexturl = '/';
    }
    // This handles special error messages that aren't the generic zoomerr.
    $settingsurl = '/admin/settings.php?section=modsettingzoom';
    if (strpos($error, 'Api key and secret are required') !== false) {
        $errstring = 'zoomerr_apisettings_missing';
        $nexturl = $settingsurl;
    } else {
        if (strpos($error, 'Invalid api key or secret') !== false) {
            $errstring = 'zoomerr_apisettings_invalid';
            $nexturl = $settingsurl;
        } else {
            if (strpos($error, '404 Not Found') !== false) {
                $errstring = 'zoomerr_apiurl_404';
                $nexturl = $settingsurl;
            } else {
                if (strpos($error, "Couldn't resolve host") !== false) {
                    $errstring = 'zoomerr_apiurl_unresolved';
                    $nexturl = $settingsurl;
                } else {
                    switch ($apicall) {
                        case 'user/getbyemail':
                            if (strpos($error, 'not exist') !== false) {
                                // Assume user is using Zoom for the first time.
                                $errstring = 'zoomerr_usernotfound';
                                $param = get_config('mod_zoom', 'zoomurl');
                                // Not an error.
                                $style = 'notifymessage';
                                // After they set up their account, the user should
                                // continue to the page they were on.
                                $nexturl = $PAGE->url;
                            }
                            break;
                        case 'meeting/get':
                        case 'meeting/update':
                        case 'meeting/delete':
                            if (zoom_is_meeting_gone_error($error)) {
                                $errstring = 'zoomerr_meetingnotfound';
                            }
                            break;
                    }
                }
            }
        }
    }
    // Based on fatal_error() in lib/outputrenderers.php, but with Bootstrap notification.
    $protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
    @header($protocol . ' 404 Not Found');
    $PAGE->set_title(get_string('error'));
    $PAGE->set_heading($COURSE->fullname);
    echo $OUTPUT->header();
    echo $OUTPUT->notification(get_string($errstring, 'mod_zoom', $param), $style);
    if ($CFG->debugdeveloper) {
        echo $OUTPUT->notification("<strong>Debug info:</strong> {$apicall}: {$error}", 'notifytiny');
        echo $OUTPUT->notification('<strong>Stack trace:</strong> ' . format_backtrace(debug_backtrace()), 'notifytiny');
    }
    echo $OUTPUT->continue_button($nexturl);
    echo $OUTPUT->footer();
    exit(1);
}