Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Moodle/mod/print/print_xmlrpc.php
diff options
context:
space:
mode:
Diffstat (limited to 'Moodle/mod/print/print_xmlrpc.php')
-rwxr-xr-xMoodle/mod/print/print_xmlrpc.php133
1 files changed, 133 insertions, 0 deletions
diff --git a/Moodle/mod/print/print_xmlrpc.php b/Moodle/mod/print/print_xmlrpc.php
new file mode 100755
index 0000000..63df086
--- /dev/null
+++ b/Moodle/mod/print/print_xmlrpc.php
@@ -0,0 +1,133 @@
+<?php
+/*
+ * First, we define some PHP functions to expose via
+ * XML-RPC. Any functions that will be called by a
+ * XML-RPC client need to take three parameters:
+ * The first parameter passed is the name of the
+ * XML-RPC method called, the second is an array
+ * Containing the parameters sent by the client, and
+ * The third is any data sent in the app_data
+ * parameter of the xmlrpc_server_call_method()
+ * function (see below).
+ */
+require_once("../../config.php");
+require_once('lib.php');
+
+function actual_func($file, $title) {
+ require_once("../../config.php");
+ require_once("lib.php");
+ require_once("../../lib/moodlelib.php");
+ global $CFG;
+ global $USER;
+ error_log("okay first step done", 0);
+ #require_login();
+ $olpcxs = get_auth_plugin('olpcxs');
+ $olpcxs->loginpage_hook();
+
+ error_log("require login done", 0);
+ #$userrecord = get_record('user', 'username', $username);
+ #$userid = $userrecord->id;
+ $id = 2;
+ if ($id) {
+ if (! $cm = get_coursemodule_from_id('print', $id)) {
+ error("Course Module ID was incorrect");
+ }
+
+ if (! $assignment = get_record("print", "id", $cm->instance)) {
+ error("assignment ID was incorrect");
+ }
+
+ if (! $course = get_record("course", "id", $assignment->course)) {
+ error("Course is misconfigured");
+ }
+ } else {
+ if (!$assignment = get_record("print", "id", $a)) {
+ error("Course module is incorrect");
+ }
+ if (! $course = get_record("course", "id", $assignment->course)) {
+ error("Course is misconfigured");
+ }
+ if (! $cm = get_coursemodule_from_instance("print", $assignment->id, $course->id)) {
+ error("Course Module ID was incorrect");
+ }
+ }
+
+
+
+
+ $assignmentinstance = new print_base($cm->id, $assignment, $cm, $course);
+ $filearea = $assignmentinstance->file_area_name($USER->id);
+
+
+ $handle = fopen($CFG->dataroot."/".$filearea."/".$title.".pdf", "wb");
+ fwrite($handle, $file->scalar);
+ fclose($handle);
+ $fpath = $CFG->dataroot."/".$filearea."/".$title.".pdf";
+
+ $assignmentinstance->upload_xmlrpc($fpath, $userid, $title, $assignment);// Display or process the submissions
+ return 1;
+}
+function send_func($method_name, $params, $app_data) {
+ $file = $params[0];
+ $title = $params[1];
+ actual_func($file, $title);
+ return 1;
+}
+
+function greeting_func($method_name, $params, $app_data)
+{
+ $name = $params[0];
+ return "Hello, $name. How are you today?";
+}
+
+/*
+ * This creates a server and sets a handle for the
+ * server in the variable $xmlrpc_server
+ */
+$xmlrpc_server = xmlrpc_server_create();
+
+/*
+ * xmlrpc_server_register_method() registers a PHP
+ * function as an XML-RPC method. It takes three
+ * parameters:
+ * The first is the handle of a server created with
+ * xmlrpc_server_create(), the second is the name to
+ * register the server under (this is what needs to
+ * be in the <methodName> of a request for this
+ * method), and the third is the name of the PHP
+ * function to register.
+ */
+
+xmlrpc_server_register_method($xmlrpc_server, "send_func", "send_func");
+xmlrpc_server_register_method($xmlrpc_server, "greeting_func", "greeting_func");
+
+/*
+ * When an XML-RPC request is sent to this script, it
+ * can be found in the raw post data.
+ */
+$request_xml = $HTTP_RAW_POST_DATA;
+
+/*
+ * The xmlrpc_server_call_method() sends a request to
+ * the server and returns the response XML. In this case,
+ * it sends the raw post data we got before. It requires
+ * 3 arguments:
+ * The first is the handle of a server created with
+ * xmlrpc_server_create(), the second is a string containing
+ * an XML-RPC request, and the third is for application data.
+ * Whatever is passed into the third parameter of this function
+ * is passed as the third paramater of the PHP function that the
+ * request is asking for.
+ */
+$response = xmlrpc_server_call_method($xmlrpc_server, $request_xml, '');
+
+// Now we print the response for the client to read.
+print $response;
+
+/*
+ * This method frees the resources for the server specified
+ * It takes one argument, a handle of a server created with
+ * xmlrpc_server_create().
+ */
+xmlrpc_server_destroy($xmlrpc_server);
+?>