Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Moodle/mod/print/print_xmlrpc.php
blob: 63df086f84f63c650f5c014271029bef2ce366da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
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);
?>