// Store things that gradeSubmit.php will need into the session session_start(); $_SESSION['lis_outcome_service_url'] = $_REQUEST['lis_outcome_service_url']; $_SESSION['lis_result_sourcedid'] = $_REQUEST['lis_result_sourcedid']; $_SESSION['lis_person_name_given'] = $_REQUEST['lis_person_name_given']; $_SESSION['oauth_consumer_key'] = $_REQUEST['oauth_consumer_key']; $_SESSION['oauth_consumer_secret'] = $oauth_consumer_secret; session_write_close(); /* * READ BACK OUR GRADE * If it exists, show the grade and disable the submit button. */ $endpoint = $_REQUEST['lis_outcome_service_url']; $sourcedid = $_REQUEST['lis_result_sourcedid']; $postBody = str_replace(array('SOURCEDID', 'OPERATION', 'MESSAGE'), array($sourcedid, 'readResultRequest', uniqid()), getPOXRequest()); $response = parseResponse(sendOAuthBodyPOST('POST', $endpoint, $oauth_consumer_key, $oauth_consumer_secret, 'application/xml', $postBody)); if ($response['imsx_codeMajor'] == 'success' && $response['textString'] != '') { $grade = $response['textString']; $showGrade = true; $disabled = 'disabled'; } } /* * CUSTOM LTI LAUNCH PARAMETERS * The "posted date" is the date that the quiz is posted. It is either set * in the "Edit Link" page of "External Learning Tools" in your LMS, or set * when the link is created with the Valence REST API. * This example parameter is NOT automatically set by the LMS! */ if (isset($_SESSION['custom_timecreated'])) { $postedDate = date('l, F j, Y', $_SESSION['custom_timecreated']);
function getWxUserByOpenid($openid) { $access_token = getAccessToken(); $param = array('access_token' => $access_token, 'openid' => $openid, 'lang' => 'zh_CN'); $url = "https://api.weixin.qq.com/cgi-bin/user/info"; //获取userinfo" $resp = SimpleHttpClient::get($url, $param); $resp = parseResponse($resp); return $resp; }
function replaceResultRequest($grade, $sourcedid, $endpoint, $oauth_consumer_key, $oauth_consumer_secret) { $method = "POST"; $content_type = "application/xml"; $operation = 'replaceResultRequest'; $postBody = str_replace(array('SOURCEDID', 'GRADE', 'OPERATION', 'MESSAGE'), array($sourcedid, $grade, $operation, uniqid()), getPOXGradeRequest()); $response = sendOAuthBody($method, $endpoint, $oauth_consumer_key, $oauth_consumer_secret, $content_type, $postBody); return parseResponse($response); }
<?php require_once './config.php'; $page = new AdminPage(); $page->title = "Delete Releases"; $page->smarty->assign(array('error', 'done'), ''); // Set the current action. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'view'; switch ($action) { case 'submit': $values = parseResponse($_POST); if ($values === false) { $page->smarty->assign('error', 'Your search criteria is wrong.'); } else { $RR = new ReleaseRemover(['Browser' => true, 'Settings' => $page->settings]); $succeeded = $RR->removeByCriteria($values); if (is_string($succeeded) && substr($succeeded, 0, 7) === 'Success') { $page->smarty->assign('done', $succeeded); } else { $page->smarty->assign('error', $succeeded); } } $release = array(); foreach ($_POST as $key => $value) { $release[$key] = $value; } $page->smarty->assign('release', $release); break; case 'view': default: $release = array('name' => '', 'searchname' => '', 'fromname' => '', 'groupname' => '', 'relsize' => '', 'adddate' => '', 'postdate' => '', 'relguid' => '', 'completion' => '', 'nametypesel' => '1', 'snametypesel' => '1', 'fnametypesel' => '1', 'gnametypesel' => '1', 'sizetypesel' => '0', 'adatetypesel' => '0', 'pdatetypesel' => '0');
$endpoint = $_REQUEST['url']; $content_type = "application/xml"; if ($_REQUEST['submit'] == "Get Course Structure" && isset($_REQUEST['context_id']) && isset($_REQUEST['lis_result_sourcedid'])) { $postBody = str_replace(array('USER_ID', 'CONTEXT_ID', 'LIS_RESULT_SOURCEDID', 'MESSAGE'), array($user_id, $context_id, htmlentities($lis_result_sourcedid), uniqid()), $getCourseStructureRequest); } else { if ($_REQUEST['submit'] == "Add Course Resource" && isset($_REQUEST['context_id']) && isset($_REQUEST['lis_result_sourcedid'])) { $postBody = str_replace(array('USER_ID', 'CONTEXT_ID', 'LIS_RESULT_SOURCEDID', 'FOLDER_ID', 'MESSAGE'), array($user_id, $context_id, htmlentities($lis_result_sourcedid), $folderId, uniqid()), $addCourseResourcesRequest); } else { exit; } } $response = sendOAuthBodyPOST($method, $endpoint, $oauth_consumer_key, $oauth_consumer_secret, $content_type, $postBody); global $LastOAuthBodyBaseString; $lbs = $LastOAuthBodyBaseString; try { $retval = parseResponse($response); } catch (Exception $e) { $retval = $e->getMessage(); } echo "\n<pre>\n"; echo "Service Url:\n"; echo htmlentities($endpoint) . "\n\n"; print_r($retval); echo "\n"; echo "------------ POST RETURNS ------------\n"; $response = str_replace("><", ">\n<", $response); $response = str_replace("<", "<", $response); $response = str_replace(">", ">", $response); echo $response; echo "\n\n------------ WE SENT ------------\n"; $postBody = str_replace("<", "<", $postBody);
$oauth_consumer_key = $_SESSION['oauth_consumer_key']; $oauth_consumer_secret = $_SESSION['oauth_consumer_secret']; /* * READ BACK OUR GRADE * If it exists we don't want to resubmit! */ $postBody = str_replace(array('SOURCEDID', 'OPERATION', 'MESSAGE'), array($sourcedid, 'readResultRequest', uniqid()), getPOXRequest()); $response = parseResponse(sendOAuthBodyPOST('POST', $endpoint, $oauth_consumer_key, $oauth_consumer_secret, 'application/xml', $postBody)); if ($response['imsx_codeMajor'] == 'success' && $response['textString'] != '') { exit('Grade was already set in LMS - a cheater?!'); } /* * SET GRADE * Calculate the grade and send it to the LMS via the LTI outcome url */ if (isset($_REQUEST['question1']) && isset($_REQUEST['question2'])) { // Calculate the students grade based on their answers $grade = ($_REQUEST['question1'] == 'B' ? 1 : 0) + ($_REQUEST['question2'] == 'A' ? 1 : 0); $grade /= 2.0; // Submit the grade to the LMS with LTI $postBody = str_replace(array('SOURCEDID', 'GRADE', 'OPERATION', 'MESSAGE'), array($sourcedid, $grade, 'replaceResultRequest', uniqid()), getPOXGradeRequest()); $response = sendOAuthBodyPOST('POST', $endpoint, $oauth_consumer_key, $oauth_consumer_secret, 'application/xml', $postBody); $response = parseResponse($response); if ($response['imsx_codeMajor'] == 'success') { header('Location: whmis.php?grade=' . $grade); } else { header('Location: whmis.php?grade=0&setGradeFailure=1&imsx_codeMajor=' . $response['imsx_codeMajor']); } } else { exit("The questions weren't answered - huh?"); }
function addResponse($id, $response) { $success = parseResponse($response); dbUpdate('tasks', array('response_xml' => $response, 'accepted' => $success, 'updated_at' => now()), $id); }
<?php require 'vendor/autoload.php'; $config = (require 'config.php'); use GuzzleHttp\Client; $client = new Client(); $url = 'https://ais.nutc.edu.tw/student/WebService.asmx/stuClassMod'; $headers = ['Content-Type' => 'application/json; charset=UTF-8', 'Cookie' => $config['cookie']]; $payload = $config['payload']; $times = 0; function addCourse($client, $url, $headers, $payload) { $response = $client->request('post', $url, ['headers' => $headers, 'body' => $payload]); return $response; } function parseResponse($response) { $resBody = (string) $response->getBody(); $resJson = json_decode($resBody); $json_str = str_replace('\\', '', $resJson->d); $result = json_decode($json_str); return $result; } do { $response = addCourse($client, $url, $headers, $payload); $result = parseResponse($response); $message = $result[0]->args[0]; $state = $message == '課程人數已滿 !'; $times++; print "times: {$times}, message: {$message}\n"; } while ($state);
function xpanel_ChangePackage($params) { $serviceid = $params['serviceid']; $serverip = $params['serverip']; $serverhostname = $params['serverhostname']; $serverusername = $params['serverusername']; $serverpassword = $params['serverpassword']; $serversecure = $params['serversecure']; $package_id = $params['configoption2']; $curl = curlInit($serverip, $serverhostname, $serverusername, $serverpassword, $serversecure); $data = "action=changepackage" . "&account_id=" . $serviceid . "&package_id=" . $package_id; try { $response = sendRequest($curl, $data); $responseXml = parseResponse($response); foreach ($responseXml->xpath("/account/changepackage/result") as $resultNode) { if ("error" == (bool) $resultNode->status) { return "" . (bool) $resultNode->errtext . "\n"; } return "success"; } } catch (ApiRequestException $e) { return $e; } return null; }
} else { if ($action == 'write') { $grade = $_REQUEST['newgrade']; $operation = 'replaceResultRequest'; $postBody = str_replace(array('SOURCEDID', 'GRADE', 'OPERATION', 'MESSAGE'), array($sourcedid, $grade, $operation, uniqid()), getPOXGradeRequest()); $response = parseResponse(sendOAuthBodyPOST($method, $endpoint, $oauth_consumer_key, $oauth_consumer_secret, $content_type, $postBody)); if ($response['imsx_codeMajor'] == 'success') { $grade = 'success'; } else { $grade = 'failure'; } } else { if ($action = 'delete') { $operation = 'deleteResultRequest'; $postBody = str_replace(array('SOURCEDID', 'OPERATION', 'MESSAGE'), array($sourcedid, $operation, uniqid()), getPOXRequest()); $response = parseResponse(sendOAuthBodyPOST($method, $endpoint, $oauth_consumer_key, $oauth_consumer_secret, $content_type, $postBody)); } } } } ?> <!doctype html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device.width, initial-scale=1.0"> <title>Grade Test Page</title> <link href="../css/bootstrap.min.css" rel="stylesheet"> <script src="http://code.jquery.com/jquery-latest.js"></script>