/** * Perform the result of an action. * * This function may redirect the user to another URL rather than returning a value. * * @return string Output to be displayed (redirection, or display HTML or message) */ private function result() { $ok = false; if (!$this->ok) { $ok = $this->onError(); } if (!$ok) { if (!$this->ok) { // If not valid, return an error message to the tool consumer if a return URL is provided if (!empty($this->returnUrl)) { $errorUrl = $this->returnUrl; if (strpos($errorUrl, '?') === false) { $errorUrl .= '?'; } else { $errorUrl .= '&'; } if ($this->debugMode && !is_null($this->reason)) { $errorUrl .= 'lti_errormsg=' . urlencode("Debug error: {$this->reason}"); } else { $errorUrl .= 'lti_errormsg=' . urlencode($this->message); if (!is_null($this->reason)) { $errorUrl .= '<i_errorlog=' . urlencode("Debug error: {$this->reason}"); } } if (!is_null($this->consumer) && isset($_POST['lti_message_type']) && $_POST['lti_message_type'] === 'ContentItemSelectionRequest') { $formParams = array(); if (isset($_POST['data'])) { $formParams['data'] = $_POST['data']; } $version = isset($_POST['lti_version']) ? $_POST['lti_version'] : self::LTI_VERSION1; $formParams = $this->consumer->signParameters($errorUrl, 'ContentItemSelection', $version, $formParams); $page = self::sendForm($errorUrl, $formParams); echo $page; } else { header("Location: {$errorUrl}"); } exit; } else { if (!is_null($this->errorOutput)) { echo $this->errorOutput; } else { if ($this->debugMode && !empty($this->reason)) { echo "Debug error: {$this->reason}"; } else { echo "Error: {$this->message}"; } } } } else { if (!is_null($this->redirectUrl)) { header("Location: {$this->redirectUrl}"); exit; } else { if (!is_null($this->output)) { echo $this->output; } } } } }