Completed
Push — 1.11.x ( 78f130...f6f5c2 )
by José
50:40 queued 24:26
created
main/webservices/soap.php 2 patches
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -11,84 +11,84 @@  discard block
 block discarded – undo
11 11
  * SOAP error handler. Handles an error sending a SOAP fault
12 12
  */
13 13
 class WSSoapErrorHandler implements WSErrorHandler {
14
-	/**
15
-	 * Handles the error by sending a SOAP fault through the server
16
-	 *
17
-	 * @param WSError Error to handle
18
-	 */
19
-	public function handle($error) {
20
-		$server = WSSoapServer::singleton();
21
-		$server->fault(strval($error->code), $error->message);
22
-	}
14
+    /**
15
+     * Handles the error by sending a SOAP fault through the server
16
+     *
17
+     * @param WSError Error to handle
18
+     */
19
+    public function handle($error) {
20
+        $server = WSSoapServer::singleton();
21
+        $server->fault(strval($error->code), $error->message);
22
+    }
23 23
 }
24 24
 
25 25
 /**
26 26
  * SOAP server wrapper implementing a Singleton
27 27
  */
28 28
 class WSSoapServer {
29
-	/**
30
-	 * SOAP server instance
31
-	 *
32
-	 * @var soap_server
33
-	 */
34
-	private static $_instance;
29
+    /**
30
+     * SOAP server instance
31
+     *
32
+     * @var soap_server
33
+     */
34
+    private static $_instance;
35 35
 
36
-	/**
37
-	 * Private constructor
38
-	 */
39
-	private function __construct() {
40
-	}
36
+    /**
37
+     * Private constructor
38
+     */
39
+    private function __construct() {
40
+    }
41 41
 
42
-	/**
43
-	 * Singleton method
44
-	 */
45
-	public static function singleton() {
46
-		if(!isset(self::$_instance)) {
47
-			self::$_instance = new soap_server();
48
-			// Set the error handler
49
-			WSError::setErrorHandler(new WSSoapErrorHandler());
50
-			// Configure the service
51
-			self::$_instance->configureWSDL('WSService', 'urn:WSService');
52
-		}
42
+    /**
43
+     * Singleton method
44
+     */
45
+    public static function singleton() {
46
+        if(!isset(self::$_instance)) {
47
+            self::$_instance = new soap_server();
48
+            // Set the error handler
49
+            WSError::setErrorHandler(new WSSoapErrorHandler());
50
+            // Configure the service
51
+            self::$_instance->configureWSDL('WSService', 'urn:WSService');
52
+        }
53 53
 
54
-		return self::$_instance;
55
-	}
54
+        return self::$_instance;
55
+    }
56 56
 }
57 57
 
58 58
 $s = WSSoapServer::singleton();
59 59
 
60 60
 $s->wsdl->addComplexType(
61
-	'result',
62
-	'complexType',
63
-	'struct',
64
-	'all',
65
-	'',
66
-	array(
67
-		'code' => array('name' => 'code', 'type' => 'xsd:int'),
68
-		'message' => array('name' => 'message', 'type' => 'xsd:string')
69
-	)
61
+    'result',
62
+    'complexType',
63
+    'struct',
64
+    'all',
65
+    '',
66
+    array(
67
+        'code' => array('name' => 'code', 'type' => 'xsd:int'),
68
+        'message' => array('name' => 'message', 'type' => 'xsd:string')
69
+    )
70 70
 );
71 71
 
72 72
 $s->wsdl->addComplexType(
73
-  'extras',
74
-  'complexType',
75
-  'struct',
76
-  'all',
77
-  '',
78
-  array(
79
-          'field_name' => array('name' => 'field_name', 'type' => 'xsd:string'),
80
-          'field_value' => array('name' => 'field_value', 'type' => 'xsd:string')
81
-       )
73
+    'extras',
74
+    'complexType',
75
+    'struct',
76
+    'all',
77
+    '',
78
+    array(
79
+            'field_name' => array('name' => 'field_name', 'type' => 'xsd:string'),
80
+            'field_value' => array('name' => 'field_value', 'type' => 'xsd:string')
81
+        )
82 82
 );
83 83
 
84 84
 $s->wsdl->addComplexType(
85
-  'extra_field',
86
-  'complexType',
87
-  'array',
88
-  '',
89
-  'SOAP-ENC:Array',
90
-  array(),
91
-  array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType' => 'tns:extras[]')),'tns:extras'
85
+    'extra_field',
86
+    'complexType',
87
+    'array',
88
+    '',
89
+    'SOAP-ENC:Array',
90
+    array(),
91
+    array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType' => 'tns:extras[]')),'tns:extras'
92 92
 );
93 93
 
94 94
 /*
@@ -106,9 +106,9 @@  discard block
 block discarded – undo
106 106
 */
107 107
 
108 108
 $s->register(
109
-	'WS.test',
110
-	array(),
111
-	array('return' => 'xsd:string')
109
+    'WS.test',
110
+    array(),
111
+    array('return' => 'xsd:string')
112 112
 );
113 113
 
114 114
 require_once(dirname(__FILE__).'/soap_user.php');
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 	 * Singleton method
44 44
 	 */
45 45
 	public static function singleton() {
46
-		if(!isset(self::$_instance)) {
46
+		if (!isset(self::$_instance)) {
47 47
 			self::$_instance = new soap_server();
48 48
 			// Set the error handler
49 49
 			WSError::setErrorHandler(new WSSoapErrorHandler());
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
   '',
89 89
   'SOAP-ENC:Array',
90 90
   array(),
91
-  array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType' => 'tns:extras[]')),'tns:extras'
91
+  array(array('ref'=>'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:extras[]')), 'tns:extras'
92 92
 );
93 93
 
94 94
 /*
Please login to merge, or discard this patch.
main/webservices/cm_soap_forum.php 1 patch
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -12,12 +12,12 @@  discard block
 block discarded – undo
12 12
 
13 13
 $s->register(
14 14
         'WSCMForum.get_foruns_id',
15
-	array(
16
-		'username' => 'xsd:string',
17
-		'password' => 'xsd:string',
15
+    array(
16
+        'username' => 'xsd:string',
17
+        'password' => 'xsd:string',
18 18
                 'course_code' => 'xsd:string'
19
-	),
20
-	array('return' => 'xsd:string'),
19
+    ),
20
+    array('return' => 'xsd:string'),
21 21
         'urn:WSCMService',
22 22
         '',
23 23
         '',
@@ -26,14 +26,14 @@  discard block
 block discarded – undo
26 26
 );
27 27
 
28 28
 $s->register(
29
-	'WSCMForum.get_forum_title',
30
-	array(
31
-		'username' => 'xsd:string',
32
-		'password' => 'xsd:string',
29
+    'WSCMForum.get_forum_title',
30
+    array(
31
+        'username' => 'xsd:string',
32
+        'password' => 'xsd:string',
33 33
                 'course_code' => 'xsd:string',
34 34
                 'forum_id' => 'xsd:string'
35
-	),
36
-	array('return' => 'xsd:string'),
35
+    ),
36
+    array('return' => 'xsd:string'),
37 37
         'urn:WSCMService',
38 38
         '',
39 39
         '',
@@ -42,14 +42,14 @@  discard block
 block discarded – undo
42 42
 );
43 43
 
44 44
 $s->register(
45
-	'WSCMForum.get_forum_threads_id',
46
-	array(
47
-		'username' => 'xsd:string',
48
-		'password' => 'xsd:string',
45
+    'WSCMForum.get_forum_threads_id',
46
+    array(
47
+        'username' => 'xsd:string',
48
+        'password' => 'xsd:string',
49 49
                 'course_code' => 'xsd:string',
50 50
                 'forum_id' => 'xsd:string'
51
-	),
52
-	array('return' => 'xsd:string'),
51
+    ),
52
+    array('return' => 'xsd:string'),
53 53
         'urn:WSCMService',
54 54
         '',
55 55
         '',
@@ -58,15 +58,15 @@  discard block
 block discarded – undo
58 58
 );
59 59
 
60 60
 $s->register(
61
-	'WSCMForum.get_forum_thread_data',
62
-	array(
63
-		'username' => 'xsd:string',
64
-		'password' => 'xsd:string',
61
+    'WSCMForum.get_forum_thread_data',
62
+    array(
63
+        'username' => 'xsd:string',
64
+        'password' => 'xsd:string',
65 65
                 'course_code' => 'xsd:string',
66 66
                 'thread_id' => 'xsd:string',
67 67
                 'field' => 'xsd:string'
68
-	),
69
-	array('return' => 'xsd:string'),
68
+    ),
69
+    array('return' => 'xsd:string'),
70 70
         'urn:WSCMService',
71 71
         '',
72 72
         '',
@@ -75,14 +75,14 @@  discard block
 block discarded – undo
75 75
 );
76 76
 
77 77
 $s->register(
78
-	'WSCMForum.get_forum_thread_title',
79
-	array(
80
-		'username' => 'xsd:string',
81
-		'password' => 'xsd:string',
78
+    'WSCMForum.get_forum_thread_title',
79
+    array(
80
+        'username' => 'xsd:string',
81
+        'password' => 'xsd:string',
82 82
                 'course_code' => 'xsd:string',
83 83
                 'thread_id' => 'xsd:string'
84
-	),
85
-	array('return' => 'xsd:string'),
84
+    ),
85
+    array('return' => 'xsd:string'),
86 86
         'urn:WSCMService',
87 87
         '',
88 88
         '',
@@ -92,14 +92,14 @@  discard block
 block discarded – undo
92 92
 
93 93
 
94 94
 $s->register(
95
-	'WSCMForum.get_posts_id',
96
-	array(
97
-		'username' => 'xsd:string',
98
-		'password' => 'xsd:string',
95
+    'WSCMForum.get_posts_id',
96
+    array(
97
+        'username' => 'xsd:string',
98
+        'password' => 'xsd:string',
99 99
                 'course_code' => 'xsd:string',
100 100
                 'thread_id' => 'xsd:string'
101
-	),
102
-	array('return' => 'xsd:string'),
101
+    ),
102
+    array('return' => 'xsd:string'),
103 103
         'urn:WSCMService',
104 104
         '',
105 105
         '',
@@ -108,15 +108,15 @@  discard block
 block discarded – undo
108 108
 );
109 109
 
110 110
 $s->register(
111
-	'WSCMForum.get_post_data',
112
-	array(
113
-		'username' => 'xsd:string',
114
-		'password' => 'xsd:string',
111
+    'WSCMForum.get_post_data',
112
+    array(
113
+        'username' => 'xsd:string',
114
+        'password' => 'xsd:string',
115 115
                 'course_code' => 'xsd:string',
116 116
                 'post_id' => 'xsd:string',
117 117
                 'field' => 'xsd:string'
118
-	),
119
-	array('return' => 'xsd:string'),
118
+    ),
119
+    array('return' => 'xsd:string'),
120 120
         'urn:WSCMService',
121 121
         '',
122 122
         '',
@@ -126,17 +126,17 @@  discard block
 block discarded – undo
126 126
 
127 127
 
128 128
 $s->register(
129
-	'WSCMForum.send_post',
130
-	array(
131
-		'username' => 'xsd:string',
132
-		'password' => 'xsd:string',
129
+    'WSCMForum.send_post',
130
+    array(
131
+        'username' => 'xsd:string',
132
+        'password' => 'xsd:string',
133 133
                 'course_code' => 'xsd:string',
134 134
                 'forum_id' => 'xsd:string',
135 135
                 'thread_id' => 'xsd:string',
136 136
                 'title' => 'xsd:string',
137 137
                 'content' => 'xsd:string'
138
-	),
139
-	array('return' => 'xsd:string'),
138
+    ),
139
+    array('return' => 'xsd:string'),
140 140
         'urn:WSCMService',
141 141
         '',
142 142
         '',
Please login to merge, or discard this patch.
main/webservices/test.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -15,13 +15,13 @@  discard block
 block discarded – undo
15 15
 $script = isset($_POST['script']) ? $_POST['script'] : false;
16 16
 $function = isset($_POST['function']) ? $_POST['function'] : false;
17 17
 
18
-$contact= $server.$script.'?wsdl';
18
+$contact = $server.$script.'?wsdl';
19 19
 
20 20
 $client = new nusoap_client($contact);
21 21
 $err = $client->getError();
22 22
 if ($err) {
23 23
     // Display the error
24
-    echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
24
+    echo '<h2>Constructor error</h2><pre>'.$err.'</pre>';
25 25
     // At this point, you know the call that follows will fail
26 26
 }
27 27
 $response = array();
@@ -37,8 +37,8 @@  discard block
 block discarded – undo
37 37
 $list = scandir($serversys);
38 38
 $scripts = array();
39 39
 foreach ($list as $item) {
40
-    if (substr($item,0,1) == '.') { continue; }
41
-    if (substr($item,-8)=='soap.php') {
40
+    if (substr($item, 0, 1) == '.') { continue; }
41
+    if (substr($item, -8) == 'soap.php') {
42 42
         $scripts[] = $item;
43 43
     }
44 44
 }
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 ?>
56 56
 </select><br />
57 57
 <label for="function">Function</label>
58
-<input type="text" name="function" value="<?php echo $function;?>"></input><br />
58
+<input type="text" name="function" value="<?php echo $function; ?>"></input><br />
59 59
 <label for="param[0]">Param 0</label>
60 60
 <input type="text" name="param[0]" ></input><br />
61 61
 <input type="submit" name="submit" value="Send"/>
Please login to merge, or discard this patch.
main/webservices/courses_list.soap.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -28,11 +28,11 @@  discard block
 block discarded – undo
28 28
         'all',
29 29
         '',
30 30
         array(
31
-          'name'=>'code'  , 'type'=>'xsd:string',
32
-          'name'=>'title'  , 'type'=>'xsd:string',
33
-          'name'=>'url'    , 'type'=>'xsd:string',
31
+          'name'=>'code', 'type'=>'xsd:string',
32
+          'name'=>'title', 'type'=>'xsd:string',
33
+          'name'=>'url', 'type'=>'xsd:string',
34 34
           'name'=>'teacher', 'type'=>'xsd:string',
35
-          'name'=>'language','type'=>'xsd:string',
35
+          'name'=>'language', 'type'=>'xsd:string',
36 36
         )
37 37
 );
38 38
 
@@ -51,15 +51,15 @@  discard block
 block discarded – undo
51 51
 );
52 52
 
53 53
 // Register the method to expose
54
-$server->register('WSCourseList',         // method name
54
+$server->register('WSCourseList', // method name
55 55
     array('username' => 'xsd:string',
56 56
           'signature' => 'xsd:string',
57
-          'visibilities' => 'xsd:string'),      // input parameters
58
-    array('return' => 'xsd:Array'),             // output parameters
59
-    'urn:WSCourseList',                         // namespace
60
-    'urn:WSCourseList#WSCourseList',      // soapaction
61
-    'rpc',                                      // style
62
-    'encoded',                                  // use
57
+          'visibilities' => 'xsd:string'), // input parameters
58
+    array('return' => 'xsd:Array'), // output parameters
59
+    'urn:WSCourseList', // namespace
60
+    'urn:WSCourseList#WSCourseList', // soapaction
61
+    'rpc', // style
62
+    'encoded', // use
63 63
     'This service returns a list of courses'    // documentation
64 64
 );
65 65
 
Please login to merge, or discard this patch.
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -28,11 +28,11 @@  discard block
 block discarded – undo
28 28
         'all',
29 29
         '',
30 30
         array(
31
-          'name'=>'code'  , 'type'=>'xsd:string',
32
-          'name'=>'title'  , 'type'=>'xsd:string',
33
-          'name'=>'url'    , 'type'=>'xsd:string',
34
-          'name'=>'teacher', 'type'=>'xsd:string',
35
-          'name'=>'language','type'=>'xsd:string',
31
+            'name'=>'code'  , 'type'=>'xsd:string',
32
+            'name'=>'title'  , 'type'=>'xsd:string',
33
+            'name'=>'url'    , 'type'=>'xsd:string',
34
+            'name'=>'teacher', 'type'=>'xsd:string',
35
+            'name'=>'language','type'=>'xsd:string',
36 36
         )
37 37
 );
38 38
 
@@ -53,8 +53,8 @@  discard block
 block discarded – undo
53 53
 // Register the method to expose
54 54
 $server->register('WSCourseList',         // method name
55 55
     array('username' => 'xsd:string',
56
-          'signature' => 'xsd:string',
57
-          'visibilities' => 'xsd:string'),      // input parameters
56
+            'signature' => 'xsd:string',
57
+            'visibilities' => 'xsd:string'),      // input parameters
58 58
     array('return' => 'xsd:Array'),             // output parameters
59 59
     'urn:WSCourseList',                         // namespace
60 60
     'urn:WSCourseList#WSCourseList',      // soapaction
@@ -97,19 +97,19 @@  discard block
 block discarded – undo
97 97
 
98 98
     $courses_list = array();
99 99
 
100
-	if (!is_array($visibilities)) {
101
-		$visibilities = split(',', $visibilities);
102
-	}
103
-	foreach ($visibilities as $visibility) {
104
-		if (!in_array($visibility, array_keys($vis))) {
105
-   			return array('error_msg' => 'Security check failed');
106
-		}
107
-		$courses_list_tmp = CourseManager::get_courses_list(null, null, null, null, $vis[$visibility]);
108
-		foreach ($courses_list_tmp as $index => $course) {
109
-			$course_info = CourseManager::get_course_information($course['code']);
110
-			$courses_list[] = array('code' => $course['code'], 'title' => api_utf8_encode($course_info['title']), 'url' => api_get_path(WEB_COURSE_PATH).$course_info['directory'].'/', 'teacher' => api_utf8_encode($course_info['tutor_name']), 'language' => $course_info['course_language']);
111
-		}
112
-	}
100
+    if (!is_array($visibilities)) {
101
+        $visibilities = split(',', $visibilities);
102
+    }
103
+    foreach ($visibilities as $visibility) {
104
+        if (!in_array($visibility, array_keys($vis))) {
105
+                return array('error_msg' => 'Security check failed');
106
+        }
107
+        $courses_list_tmp = CourseManager::get_courses_list(null, null, null, null, $vis[$visibility]);
108
+        foreach ($courses_list_tmp as $index => $course) {
109
+            $course_info = CourseManager::get_course_information($course['code']);
110
+            $courses_list[] = array('code' => $course['code'], 'title' => api_utf8_encode($course_info['title']), 'url' => api_get_path(WEB_COURSE_PATH).$course_info['directory'].'/', 'teacher' => api_utf8_encode($course_info['tutor_name']), 'language' => $course_info['course_language']);
111
+        }
112
+    }
113 113
     return $courses_list;
114 114
 }
115 115
 
Please login to merge, or discard this patch.
main/webservices/user_import/service.php 2 patches
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -14,45 +14,45 @@
 block discarded – undo
14 14
  */
15 15
 function import_users_from_file($filepath, $security_key) {
16 16
 
17
-	global $_configuration;
18
-
19
-   	$errors_returned = array(
20
-	   	0 => 'success',
21
-	   	1 => 'file import does not exist',
22
-	   	2 => 'no users to import',
23
-	   	3 => 'wrong datas in file',
24
-	   	4 => 'security error'
25
-   	);
26
-
27
-   	// Check whether this script is launch by server and security key is ok.
28
-   	if (empty($_SERVER['REMOTE_ADDR']) || $_SERVER['REMOTE_ADDR'] != $_SERVER['SERVER_ADDR'] || $security_key != $_configuration['security_key']) {
29
-   		return $errors_returned[4];
30
-   	}
31
-
32
-   	// Libraries
33
-   	require_once 'import.lib.php';
34
-
35
-	// Check is users file exists.
36
-	if (!is_file($filepath)) {
37
-		return $errors_returned[1];
38
-	}
39
-
40
-	// Get list of users
41
-	$users = parse_csv_data($filepath);
42
-	if (count($users) == 0) {
43
-		return $errors_returned[2];
44
-	}
45
-
46
-	// Check the datas for each user
47
-	$errors = validate_data($users);
48
-	if (count($errors) > 0) {
49
-		return $errors_returned[3];
50
-	}
51
-
52
-	// Apply modifications in database
53
-	save_data($users);
54
-
55
-   	return $errors_returned[0]; // Import successfull
17
+    global $_configuration;
18
+
19
+        $errors_returned = array(
20
+            0 => 'success',
21
+            1 => 'file import does not exist',
22
+            2 => 'no users to import',
23
+            3 => 'wrong datas in file',
24
+            4 => 'security error'
25
+        );
26
+
27
+        // Check whether this script is launch by server and security key is ok.
28
+        if (empty($_SERVER['REMOTE_ADDR']) || $_SERVER['REMOTE_ADDR'] != $_SERVER['SERVER_ADDR'] || $security_key != $_configuration['security_key']) {
29
+            return $errors_returned[4];
30
+        }
31
+
32
+        // Libraries
33
+        require_once 'import.lib.php';
34
+
35
+    // Check is users file exists.
36
+    if (!is_file($filepath)) {
37
+        return $errors_returned[1];
38
+    }
39
+
40
+    // Get list of users
41
+    $users = parse_csv_data($filepath);
42
+    if (count($users) == 0) {
43
+        return $errors_returned[2];
44
+    }
45
+
46
+    // Check the datas for each user
47
+    $errors = validate_data($users);
48
+    if (count($errors) > 0) {
49
+        return $errors_returned[3];
50
+    }
51
+
52
+    // Apply modifications in database
53
+    save_data($users);
54
+
55
+        return $errors_returned[0]; // Import successfull
56 56
 }
57 57
 
58 58
 $server = new soap_server();
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -59,5 +59,5 @@
 block discarded – undo
59 59
 
60 60
 $server->register('import_users_from_file');
61 61
 
62
-$http_request = (isset($HTTP_RAW_POST_DATA)?$HTTP_RAW_POST_DATA:'');
62
+$http_request = (isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '');
63 63
 $server->service($http_request);
Please login to merge, or discard this patch.
main/webservices/user_import/import.lib.php 3 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -4,12 +4,12 @@  discard block
 block discarded – undo
4 4
  */
5 5
 function validate_data($users) {
6 6
 	global $defined_auth_sources;
7
-	$errors = array ();
8
-	$usernames = array ();
9
-	if(is_array($users)) {
7
+	$errors = array();
8
+	$usernames = array();
9
+	if (is_array($users)) {
10 10
 		foreach ($users as $index => $user) {
11 11
 			// 1. Check whether mandatory fields have been set.
12
-			$mandatory_fields = array ('LastName', 'FirstName');
12
+			$mandatory_fields = array('LastName', 'FirstName');
13 13
 			if (api_get_setting('registration', 'email') == 'true') {
14 14
 				$mandatory_fields[] = 'Email';
15 15
 			}
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
  */
91 91
 function save_data($users) {
92 92
 	$user_table = Database :: get_main_table(TABLE_MAIN_USER);
93
-	if(is_array($users)) {
93
+	if (is_array($users)) {
94 94
 		foreach ($users as $index => $user) {
95 95
 			$user = complete_missing_data($user);
96 96
 
@@ -98,8 +98,8 @@  discard block
 block discarded – undo
98 98
 
99 99
 			$user_id = UserManager :: create_user($user['FirstName'], $user['LastName'], $user['Status'], $user['Email'], $user['UserName'], $user['Password'], $user['OfficialCode'], api_get_setting('PlatformLanguage'), $user['PhoneNumber'], '', $user['AuthSource']);
100 100
 			foreach ($user['Courses'] as $index => $course) {
101
-				if(CourseManager :: course_exists($course))
102
-					CourseManager :: subscribe_user($user_id, $course,$user['Status']);
101
+				if (CourseManager :: course_exists($course))
102
+					CourseManager :: subscribe_user($user_id, $course, $user['Status']);
103 103
 			}
104 104
 			if (strlen($user['ClassName']) > 0) {
105 105
 				$class_id = ClassManager :: get_class_id($user['ClassName']);
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -98,8 +98,9 @@
 block discarded – undo
98 98
 
99 99
 			$user_id = UserManager :: create_user($user['FirstName'], $user['LastName'], $user['Status'], $user['Email'], $user['UserName'], $user['Password'], $user['OfficialCode'], api_get_setting('PlatformLanguage'), $user['PhoneNumber'], '', $user['AuthSource']);
100 100
 			foreach ($user['Courses'] as $index => $course) {
101
-				if(CourseManager :: course_exists($course))
102
-					CourseManager :: subscribe_user($user_id, $course,$user['Status']);
101
+				if(CourseManager :: course_exists($course)) {
102
+									CourseManager :: subscribe_user($user_id, $course,$user['Status']);
103
+				}
103 104
 			}
104 105
 			if (strlen($user['ClassName']) > 0) {
105 106
 				$class_id = ClassManager :: get_class_id($user['ClassName']);
Please login to merge, or discard this patch.
Indentation   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -3,121 +3,121 @@  discard block
 block discarded – undo
3 3
  * Validates imported data.
4 4
  */
5 5
 function validate_data($users) {
6
-	global $defined_auth_sources;
7
-	$errors = array ();
8
-	$usernames = array ();
9
-	if(is_array($users)) {
10
-		foreach ($users as $index => $user) {
11
-			// 1. Check whether mandatory fields have been set.
12
-			$mandatory_fields = array ('LastName', 'FirstName');
13
-			if (api_get_setting('registration', 'email') == 'true') {
14
-				$mandatory_fields[] = 'Email';
15
-			}
16
-			foreach ($mandatory_fields as $key => $field) {
17
-				if (!isset ($user[$field]) || strlen($user[$field]) == 0) {
18
-					$user['error'] = get_lang($field.'Mandatory');
19
-					$errors[] = $user;
20
-				}
21
-			}
22
-			// 2. Check username.
23
-			if (!UserManager::is_username_empty($user['UserName'])) {
24
-				// 2.1. Check whether username was used twice in the import file.
25
-				if (isset($usernames[$user['UserName']])) {
26
-					$user['error'] = get_lang('UserNameUsedTwice');
27
-					$errors[] = $user;
28
-				}
29
-				$usernames[$user['UserName']] = 1;
30
-				// 2.2. Check whether username is allready in use in database.
31
-				if (!UserManager::is_username_available($user['UserName'])) {
32
-					$user['error'] = get_lang('UserNameNotAvailable');
33
-					$errors[] = $user;
34
-				}
35
-				// 2.3. Check whether username is too long.
36
-				if (UserManager::is_username_too_long($user['UserName'])) {
37
-					$user['error'] = get_lang('UserNameTooLong');
38
-					$errors[] = $user;
39
-				}
40
-			}
41
-			// 3. Check status.
42
-			if (isset ($user['Status']) && !api_status_exists($user['Status'])) {
43
-				$user['error'] = get_lang('WrongStatus');
44
-				$errors[] = $user;
45
-			}
46
-			// 5. Check authentication source.
47
-			if (isset ($user['AuthSource']) && strlen($user['AuthSource']) != 0) {
48
-				if (!in_array($user['AuthSource'], $defined_auth_sources)) {
49
-					$user['error'] = get_lang('AuthSourceNotAvailable');
50
-					$errors[] = $user;
51
-				}
52
-			}
53
-		}
54
-	}
55
-	return $errors;
6
+    global $defined_auth_sources;
7
+    $errors = array ();
8
+    $usernames = array ();
9
+    if(is_array($users)) {
10
+        foreach ($users as $index => $user) {
11
+            // 1. Check whether mandatory fields have been set.
12
+            $mandatory_fields = array ('LastName', 'FirstName');
13
+            if (api_get_setting('registration', 'email') == 'true') {
14
+                $mandatory_fields[] = 'Email';
15
+            }
16
+            foreach ($mandatory_fields as $key => $field) {
17
+                if (!isset ($user[$field]) || strlen($user[$field]) == 0) {
18
+                    $user['error'] = get_lang($field.'Mandatory');
19
+                    $errors[] = $user;
20
+                }
21
+            }
22
+            // 2. Check username.
23
+            if (!UserManager::is_username_empty($user['UserName'])) {
24
+                // 2.1. Check whether username was used twice in the import file.
25
+                if (isset($usernames[$user['UserName']])) {
26
+                    $user['error'] = get_lang('UserNameUsedTwice');
27
+                    $errors[] = $user;
28
+                }
29
+                $usernames[$user['UserName']] = 1;
30
+                // 2.2. Check whether username is allready in use in database.
31
+                if (!UserManager::is_username_available($user['UserName'])) {
32
+                    $user['error'] = get_lang('UserNameNotAvailable');
33
+                    $errors[] = $user;
34
+                }
35
+                // 2.3. Check whether username is too long.
36
+                if (UserManager::is_username_too_long($user['UserName'])) {
37
+                    $user['error'] = get_lang('UserNameTooLong');
38
+                    $errors[] = $user;
39
+                }
40
+            }
41
+            // 3. Check status.
42
+            if (isset ($user['Status']) && !api_status_exists($user['Status'])) {
43
+                $user['error'] = get_lang('WrongStatus');
44
+                $errors[] = $user;
45
+            }
46
+            // 5. Check authentication source.
47
+            if (isset ($user['AuthSource']) && strlen($user['AuthSource']) != 0) {
48
+                if (!in_array($user['AuthSource'], $defined_auth_sources)) {
49
+                    $user['error'] = get_lang('AuthSourceNotAvailable');
50
+                    $errors[] = $user;
51
+                }
52
+            }
53
+        }
54
+    }
55
+    return $errors;
56 56
 }
57 57
 
58 58
 /**
59 59
  * Adds missing user-information (which isn't required, like password, username, etc).
60 60
  */
61 61
 function complete_missing_data($user) {
62
-	// 1. Create a username if necessary.
63
-	if (UserManager::is_username_empty($user['UserName'])) {
64
-		$user['UserName'] = UserManager::create_unique_username($user['FirstName'], $user['LastName']);
65
-	}
66
-	// 2. Generate a password if necessary.
67
-	if (!isset ($user['Password']) || strlen($user['Password']) == 0) {
68
-		$user['Password'] = api_generate_password();
69
-	}
70
-	// 3. set status if not allready set.
71
-	if (!isset ($user['Status']) || strlen($user['Status']) == 0) {
72
-		$user['Status'] = 'user';
73
-	}
74
-	// 4. Set authsource if not allready set.
75
-	if (!isset ($user['AuthSource']) || strlen($user['AuthSource']) == 0) {
76
-		$user['AuthSource'] = PLATFORM_AUTH_SOURCE;
77
-	}
78
-	return $user;
62
+    // 1. Create a username if necessary.
63
+    if (UserManager::is_username_empty($user['UserName'])) {
64
+        $user['UserName'] = UserManager::create_unique_username($user['FirstName'], $user['LastName']);
65
+    }
66
+    // 2. Generate a password if necessary.
67
+    if (!isset ($user['Password']) || strlen($user['Password']) == 0) {
68
+        $user['Password'] = api_generate_password();
69
+    }
70
+    // 3. set status if not allready set.
71
+    if (!isset ($user['Status']) || strlen($user['Status']) == 0) {
72
+        $user['Status'] = 'user';
73
+    }
74
+    // 4. Set authsource if not allready set.
75
+    if (!isset ($user['AuthSource']) || strlen($user['AuthSource']) == 0) {
76
+        $user['AuthSource'] = PLATFORM_AUTH_SOURCE;
77
+    }
78
+    return $user;
79 79
 }
80 80
 
81 81
 /**
82 82
  * Save the imported data
83 83
  */
84 84
 function save_data($users) {
85
-	$user_table = Database :: get_main_table(TABLE_MAIN_USER);
86
-	if(is_array($users)) {
87
-		foreach ($users as $index => $user) {
88
-			$user = complete_missing_data($user);
85
+    $user_table = Database :: get_main_table(TABLE_MAIN_USER);
86
+    if(is_array($users)) {
87
+        foreach ($users as $index => $user) {
88
+            $user = complete_missing_data($user);
89 89
 
90
-			$user['Status'] = api_status_key($user['Status']);
90
+            $user['Status'] = api_status_key($user['Status']);
91 91
 
92
-			$user_id = UserManager :: create_user($user['FirstName'], $user['LastName'], $user['Status'], $user['Email'], $user['UserName'], $user['Password'], $user['OfficialCode'], api_get_setting('PlatformLanguage'), $user['PhoneNumber'], '', $user['AuthSource']);
93
-			foreach ($user['Courses'] as $index => $course) {
94
-				if(CourseManager :: course_exists($course))
95
-					CourseManager :: subscribe_user($user_id, $course,$user['Status']);
96
-			}
92
+            $user_id = UserManager :: create_user($user['FirstName'], $user['LastName'], $user['Status'], $user['Email'], $user['UserName'], $user['Password'], $user['OfficialCode'], api_get_setting('PlatformLanguage'), $user['PhoneNumber'], '', $user['AuthSource']);
93
+            foreach ($user['Courses'] as $index => $course) {
94
+                if(CourseManager :: course_exists($course))
95
+                    CourseManager :: subscribe_user($user_id, $course,$user['Status']);
96
+            }
97 97
 
98
-			// TODO: Hard-coded French texts.
98
+            // TODO: Hard-coded French texts.
99 99
 
100
-			// Qualite
101
-			if (!empty($user['Qualite'])) {
102
-				UserManager::update_extra_field_value($user_id, 'qualite', $user['Qualite']);
103
-			}
100
+            // Qualite
101
+            if (!empty($user['Qualite'])) {
102
+                UserManager::update_extra_field_value($user_id, 'qualite', $user['Qualite']);
103
+            }
104 104
 
105
-			// Categorie
106
-			if (!empty($user['Categorie'])) {
107
-				UserManager::update_extra_field_value($user_id, 'categorie', $user['Categorie']);
108
-			}
105
+            // Categorie
106
+            if (!empty($user['Categorie'])) {
107
+                UserManager::update_extra_field_value($user_id, 'categorie', $user['Categorie']);
108
+            }
109 109
 
110
-			// Etat
111
-			if (!empty($user['Etat'])) {
112
-				UserManager::update_extra_field_value($user_id, 'etat', $user['Etat']);
113
-			}
110
+            // Etat
111
+            if (!empty($user['Etat'])) {
112
+                UserManager::update_extra_field_value($user_id, 'etat', $user['Etat']);
113
+            }
114 114
 
115
-			// Niveau
116
-			if (!empty($user['Niveau'])) {
117
-				UserManager::update_extra_field_value($user_id, 'niveau', $user['Niveau']);
118
-			}
119
-		}
120
-	}
115
+            // Niveau
116
+            if (!empty($user['Niveau'])) {
117
+                UserManager::update_extra_field_value($user_id, 'niveau', $user['Niveau']);
118
+            }
119
+        }
120
+    }
121 121
 }
122 122
 
123 123
 /**
@@ -126,12 +126,12 @@  discard block
 block discarded – undo
126 126
  * @return array All userinformation read from the file
127 127
  */
128 128
 function parse_csv_data($file) {
129
-	$users = Import :: csvToArray($file);
130
-	foreach ($users as $index => $user) {
131
-		if (isset ($user['Courses'])) {
132
-			$user['Courses'] = explode('|', trim($user['Courses']));
133
-		}
134
-		$users[$index] = $user;
135
-	}
136
-	return $users;
129
+    $users = Import :: csvToArray($file);
130
+    foreach ($users as $index => $user) {
131
+        if (isset ($user['Courses'])) {
132
+            $user['Courses'] = explode('|', trim($user['Courses']));
133
+        }
134
+        $users[$index] = $user;
135
+    }
136
+    return $users;
137 137
 }
Please login to merge, or discard this patch.
main/webservices/cm_soap_courses.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -11,12 +11,12 @@  discard block
 block discarded – undo
11 11
 
12 12
 
13 13
 $s->register(
14
-	'WSCMCourses.get_courses_code',
15
-	array(
16
-		'username' => 'xsd:string',
17
-		'password' => 'xsd:string'
18
-	),
19
-	array('return' => 'xsd:string'),
14
+    'WSCMCourses.get_courses_code',
15
+    array(
16
+        'username' => 'xsd:string',
17
+        'password' => 'xsd:string'
18
+    ),
19
+    array('return' => 'xsd:string'),
20 20
         'urn:WSCMService',
21 21
         '',
22 22
         '',
@@ -26,13 +26,13 @@  discard block
 block discarded – undo
26 26
 );
27 27
 
28 28
 $s->register(
29
-	'WSCMCourses.get_course_title',
30
-	array(
31
-		'username' => 'xsd:string',
32
-		'password' => 'xsd:string',
29
+    'WSCMCourses.get_course_title',
30
+    array(
31
+        'username' => 'xsd:string',
32
+        'password' => 'xsd:string',
33 33
                 'course_code' => 'xsd:string',
34
-	),
35
-	array('return' => 'xsd:string'),
34
+    ),
35
+    array('return' => 'xsd:string'),
36 36
         'urn:WSCMService',
37 37
         '',
38 38
         '',
Please login to merge, or discard this patch.
main/webservices/cm_webservice_announcements.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 
16 16
     public function get_announcements_id($username, $password, $course_code)
17 17
     {
18
-        if($this->verifyUserPass($username, $password) == "valid")
18
+        if ($this->verifyUserPass($username, $password) == "valid")
19 19
         {
20 20
 
21 21
             $result = self::get_announcements($username, $course_code);
@@ -33,13 +33,13 @@  discard block
 block discarded – undo
33 33
 
34 34
     public function get_announcement_data($username, $password, $course_code, $announcement_id, $field)
35 35
     {
36
-        if($this->verifyUserPass($username, $password) == "valid")
36
+        if ($this->verifyUserPass($username, $password) == "valid")
37 37
         {
38 38
             $htmlcode = false;
39 39
             $user_id = UserManager::get_user_id_from_username($username);
40 40
 
41 41
             $result = self::get_announcements($username, $course_code, $announcement_id);
42
-            while($announcement = Database::fetch_array($result))
42
+            while ($announcement = Database::fetch_array($result))
43 43
             {
44 44
                 $announcements[] = $announcement;
45 45
             }
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 
70 70
             return (htmlcode) ? html_entity_decode($announcements[0][$field_table]) : $announcements[0][$field_table];
71 71
 
72
-        }else
72
+        } else
73 73
             return get_lang('InvalidId');
74 74
     }
75 75
 
@@ -82,11 +82,11 @@  discard block
 block discarded – undo
82 82
         $announcement_id = ($announcement_id == 0) ? "" : "AND announcement.id=".$announcement_id;
83 83
         $user_id = UserManager::get_user_id_from_username($username);
84 84
         $course_info = CourseManager::get_course_information($course_code);
85
-        $tbl_item_property  	= Database::get_course_table(TABLE_ITEM_PROPERTY);
86
-        $tbl_announcement		= Database::get_course_table(TABLE_ANNOUNCEMENT);
87
-        $maximum 	= '12';
85
+        $tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
86
+        $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
87
+        $maximum = '12';
88 88
 
89
-        $group_memberships=GroupManager::get_group_ids($course_info['real_id'], $user_id);
89
+        $group_memberships = GroupManager::get_group_ids($course_info['real_id'], $user_id);
90 90
 
91 91
         if (api_get_group_id() == 0) {
92 92
             $cond_user_id = " AND (
@@ -104,8 +104,8 @@  discard block
 block discarded – undo
104 104
 
105 105
         // the user is member of several groups => display personal
106 106
         // announcements AND his group announcements AND the general announcements
107
-        if (is_array($group_memberships) && count($group_memberships)>0) {
108
-            $sql="SELECT
107
+        if (is_array($group_memberships) && count($group_memberships) > 0) {
108
+            $sql = "SELECT
109 109
                     announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
110 110
                 FROM $tbl_announcement announcement, $tbl_item_property ip
111 111
                 WHERE
Please login to merge, or discard this patch.
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -26,8 +26,9 @@  discard block
 block discarded – undo
26 26
             }
27 27
             return $announcements;
28 28
 
29
-        } else
30
-            return get_lang('InvalidId');
29
+        } else {
30
+                    return get_lang('InvalidId');
31
+        }
31 32
 
32 33
     }
33 34
 
@@ -69,8 +70,9 @@  discard block
 block discarded – undo
69 70
 
70 71
             return (htmlcode) ? html_entity_decode($announcements[0][$field_table]) : $announcements[0][$field_table];
71 72
 
72
-        }else
73
-            return get_lang('InvalidId');
73
+        } else {
74
+                    return get_lang('InvalidId');
75
+        }
74 76
     }
75 77
 
76 78
 
Please login to merge, or discard this patch.
main/webservices/cm_webservice_course.php 4 patches
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -521,8 +521,9 @@
 block discarded – undo
521 521
 
522 522
 	public function nada($username, $password)
523 523
 	{
524
-		if($this->verifyUserPass($username, $password) == "valid")
525
-			return $username.$password;
524
+		if($this->verifyUserPass($username, $password) == "valid") {
525
+					return $username.$password;
526
+		}
526 527
 		return $username;
527 528
 	}
528 529
 
Please login to merge, or discard this patch.
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -453,6 +453,7 @@
 block discarded – undo
453 453
 	 * @param string Session id field name
454 454
 	 * @param string Session id value
455 455
 	 * @param int State (1 to subscribe, 0 to unsubscribe)
456
+	 * @param integer $state
456 457
 	 * @return mixed True on success, WSError otherwise
457 458
 	 */
458 459
 	protected function changeCourseSubscription($course_id_field_name, $course_id_value, $session_id_field_name, $session_id_value, $state) {
Please login to merge, or discard this patch.
Indentation   +511 added lines, -511 removed lines patch added patch discarded remove patch
@@ -10,521 +10,521 @@
 block discarded – undo
10 10
  */
11 11
 class WSCMCourse extends WSCM
12 12
 {
13
-	/**
14
-	 * Deletes a course (helper method)
15
-	 *
16
-	 * @param string Course id field name
17
-	 * @param string Course id value
18
-	 * @return mixed True if the course was successfully deleted, WSError otherwise
19
-	 */
20
-	protected function deleteCourseHelper($course_id_field_name, $course_id_value) {
21
-		$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
22
-		if($course_id instanceof WSCMError) {
23
-			return $course_id;
24
-		} else {
25
-			$course_code = CourseManager::get_course_code_from_course_id($course_id);
26
-			CourseManager::delete_course($course_code);
27
-			return true;
28
-		}
29
-	}
30
-
31
-	/**
32
-	 * Deletes a course
33
-	 *
34
-	 * @param string API secret key
35
-	 * @param string Course id field name
36
-	 * @param string Course id value
37
-	 */
38
-	public function DeleteCourse($secret_key, $course_id_field_name, $course_id_value) {
39
-		$verifKey = $this->verifyKey($secret_key);
40
-		if($verifKey instanceof WSError) {
41
-			$this->handleError($verifKey);
42
-		} else {
43
-			$result = $this->deleteCourseHelper($course_id_field_name, $course_id_value);
44
-			if($result instanceof WSError) {
45
-				$this->handleError($result);
46
-			}
47
-		}
48
-	}
49
-
50
-	/**
51
-	 * Deletes multiple courses
52
-	 *
53
-	 * @param string API secret key
54
-	 * @param array Array of courses with elements of the form array('course_id_field_name' => 'name_of_field', 'course_id_value' => 'value')
55
-	 * @return array Array with elements like array('course_id_value' => 'value', 'result' => array('code' => 0, 'message' => 'Operation was successful')). Note that if the result array contains a code different
56
-	 * than 0, an error occured
57
-	 */
58
-	public function DeleteCourses($secret_key, $courses) {
59
-		$verifKey = $this->verifyKey($secret_key);
60
-		if($verifKey instanceof WSError) {
61
-			$this->handleError($verifKey);
62
-		} else {
63
-			$results = array();
64
-			foreach($courses as $course) {
65
-				$result_tmp = array();
66
-				$result_op = $this->deleteCourseHelper($course['course_id_field_name'], $course['course_id_value']);
67
-				$result_tmp['course_id_value'] = $course['course_id_value'];
68
-				if($result_op instanceof WSCMError) {
69
-					// Return the error in the results
70
-					$result_tmp['result'] = $result_op->toArray();
71
-				} else {
72
-					$result_tmp['result'] = $this->getSuccessfulResult();
73
-				}
74
-				$results[] = $result_tmp;
75
-			}
76
-			return $results;
77
-		}
78
-	}
79
-
80
-	/**
81
-	 * Creates a course (helper method)
82
-	 *
83
-	 * @param string Title
84
-	 * @param string Category code
85
-	 * @param string Wanted code. If it's not defined, it will be generated automatically
86
-	 * @param string Tutor name
87
-	 * @param string Course admin user id field name
88
-	 * @param string Course admin user id value
89
-	 * @param string Course language
90
-	 * @param string Course id field name
91
-	 * @param string Course id value
92
-	 * @param array Course extra fields
93
-	 * @return mixed Generated id if creation was successful, WSError otherwise
94
-	 */
95
-	protected function createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) {
96
-		// Add the original course id field name and value to the extra fields if needed
97
-		$extras_associative = array();
98
-		if($course_id_field_name != "chamilo_course_id") {
99
-			$extras_associative[$course_id_field_name] = $course_id_value;
100
-		}
101
-		foreach($extras as $extra) {
102
-			$extras_associative[$extra['field_name']] = $extra['field_value'];
103
-		}
104
-		$course_admin_id = $this->getUserId($course_admin_user_id_field_name, $course_admin_user_id_value);
105
-		if($course_admin_id instanceof WSError) {
106
-			return $course_admin_id;
107
-		}
108
-		if($wanted_code == '') {
109
-			$wanted_code = CourseManager::generate_course_code($title);
110
-		}
111
-		$result = create_course($wanted_code, $title, $tutor_name, $category_code, $language, $course_admin_id, $this->_configuration['db_prefix'], 0);
112
-		if (!$result) {
113
-			return new WSError(202, 'There was an error creating the course');
114
-		} else {
115
-			// Update extra fields
116
-			foreach($extras_associative as $fname => $fvalue) {
117
-				CourseManager::update_course_extra_field_value($result, $fname, $fvalue);
118
-			}
119
-			// Get course id
120
-			$course_info = CourseManager::get_course_information($result);
121
-			return $course_info['real_id'];
122
-		}
123
-	}
124
-
125
-	/**
126
-	 * Creates a course
127
-	 *
128
-	 * @param string API secret key
129
-	 * @param string Title
130
-	 * @param string Category code
131
-	 * @param string Wanted code. If it's not defined, it will be generated automatically
132
-	 * @param string Tutor name
133
-	 * @param string Course admin user id field name
134
-	 * @param string Course admin user id value
135
-	 * @param string Course language
136
-	 * @param string Course id field name
137
-	 * @param string Course id value
138
-	 * @param array Course extra fields
139
-	 * @return int Course id generated
140
-	 */
141
-	public function CreateCourse($secret_key, $title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) {
142
-		// First, verify the secret key
143
-		$verifKey = $this->verifyKey($secret_key);
144
-		if($verifKey instanceof WSError) {
145
-			$this->handleError($verifKey);
146
-		} else {
147
-			$result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras);
148
-			if($result instanceof WSError) {
149
-				$this->handleError($result);
150
-			} else {
151
-				return $result;
152
-			}
153
-		}
154
-	}
155
-
156
-	/**
157
-	 * Create multiple courses
158
-	 *
159
-	 * @param string API secret key
160
-	 * @param array Courses to be created, with elements following the structure presented in CreateCourse
161
-	 * @return array Array with elements of the form array('course_id_value' => 'original value sent', 'course_id_generated' => 'value_generated', 'result' => array('code' => 0, 'message' => 'Operation was successful'))
162
-	 */
163
-	public function CreateCourses($secret_key, $courses) {
164
-		// First, verify the secret key
165
-		$verifKey = $this->verifyKey($secret_key);
166
-		if($verifKey instanceof WSCMError) {
167
-			$this->handleError($verifKey);
168
-		} else {
169
-			$results = array();
170
-			foreach($courses as $course) {
171
-				$result_tmp = array();
172
-				//reinitialize variables just in case
173
-				$title = $category_code = $wanted_code = $tutor_name = $course_admin_user_id_field_name = $course_admin_user_id_value = $language = $course_id_field_name = $course_id_value = $extras = null;
174
-				extract($course);
175
-				$result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras);
176
-				if($result instanceof WSCMError) {
177
-					$result_tmp['result'] = $result->toArray();
178
-					$result_tmp['course_id_value'] = $course_id_value;
179
-					$result_tmp['course_id_generated'] = 0;
180
-				} else {
181
-					$result_tmp['result'] = $this->getSuccessfulResult();
182
-					$result_tmp['course_id_value'] = $course_id_value;
183
-					$result_tmp['course_id_generated'] = $result;
184
-				}
185
-				$results[] = $result_tmp;
186
-			}
187
-			return $results;
188
-		}
189
-	}
190
-
191
-	/**
192
-	 * Edits a course (helper method)
193
-	 *
194
-	 * @param string Course id field name
195
-	 * @param string Course id value
196
-	 * @param string Title
197
-	 * @param string Category code
198
-	 * @param string Department name
199
-	 * @param string Department url
200
-	 * @param string Course language
201
-	 * @param int Visibility
202
-	 * @param int Subscribe (0 = denied, 1 = allowed)
203
-	 * @param int Unsubscribe (0 = denied, 1 = allowed)
204
-	 * @param string Visual code
205
-	 * @param array Course extra fields
206
-	 * @return mixed True in case of success, WSError otherwise
207
-	 */
208
-	protected function editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) {
209
-		$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
210
-		if($course_id instanceof WSCMError) {
211
-			return $course_id;
212
-		} else {
213
-			$attributes = array();
214
-			if(!empty($title)) {
215
-				$attributes['title'] = $title;
216
-			}
217
-			if(!empty($category_code)) {
218
-				$attributes['category_code'] = $category_code;
219
-			}
220
-			if(!empty($department_name)) {
221
-				$attributes['department_name'] = $department_name;
222
-			}
223
-			if(!empty($department_url)) {
224
-				$attributes['department_url'] = $department_url;
225
-			}
226
-			if(!empty($language)) {
227
-				$attributes['course_language'] = $language;
228
-			}
229
-			if($visibility != '') {
230
-				$attributes['visibility'] = (int)$visibility;
231
-			}
232
-			if($subscribe != '') {
233
-				$attributes['subscribe'] = (int)$subscribe;
234
-			}
235
-			if($unsubscribe != '') {
236
-				$attributes['unsubscribe'] = (int)$unsubscribe;
237
-			}
238
-			if(!empty($visual_code)) {
239
-				$attributes['visual_code'] = $visual_code;
240
-			}
241
-			if(!empty($attributes)) {
242
-				CourseManager::update_attributes($course_id, $attributes);
243
-			}
244
-			if(!empty($extras)) {
245
-				$course_code = CourseManager::get_course_code_from_course_id($course_id);
246
-				$extras_associative = array();
247
-				foreach($extras as $extra) {
248
-					$extras_associative[$extra['field_name']] = $extra['field_value'];
249
-				}
250
-				foreach($extras_associative as $fname => $fvalue) {
251
-					CourseManager::update_extra_field_value($course_code, $fname, $fvalue);
252
-				}
253
-			}
254
-			return true;
255
-		}
256
-	}
257
-
258
-	/**
259
-	 * Edits a course
260
-	 *
261
-	 * @param string API secret key
262
-	 * @param string Course id field name
263
-	 * @param string Course id value
264
-	 * @param string Title
265
-	 * @param string Category code
266
-	 * @param string Department name
267
-	 * @param string Department url
268
-	 * @param string Course language
269
-	 * @param int Visibility
270
-	 * @param int Subscribe (0 = denied, 1 = allowed)
271
-	 * @param int Unsubscribe (0 = denied, 1 = allowed)
272
-	 * @param string Visual code
273
-	 * @param array Course extra fields
274
-	 */
275
-	public function EditCourse($secret_key, $course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) {
276
-		$verifKey = $this->verifyKey($secret_key);
277
-		if($verifKey instanceof WSCMError) {
278
-			$this->handleError($verifKey);
279
-		} else {
280
-			$result = $this->editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras);
281
-			if($result instanceof WSCMError) {
282
-				$this->handleError($result);
283
-			}
284
-		}
285
-	}
286
-
287
-	/**
288
-	 * List courses
289
-	 *
290
-	 * @param string API secret key
291
-	 * @param string Course id field name. Use "chamilo_course_id" to use internal id
292
-	 * @return array An array with elements of the form ('id' => 'Course internal id', 'code' => 'Course code', 'title' => 'Course title', 'language' => 'Course language', 'visibility' => 'Course visibility',
293
-	 * 'category_name' => 'Name of the category of the course', 'number_students' => 'Number of students in the course', 'external_course_id' => 'External course id')
294
-	 */
295
-	public function ListCourses($secret_key, $course_id_field_name) {
296
-		$verifKey = $this->verifyKey($secret_key);
297
-		if($verifKey instanceof WSError) {
298
-			$this->handleError($verifKey);
299
-		} else {
300
-			$courses_result = array();
301
-			$category_names = array();
302
-
303
-			$courses = CourseManager::get_courses_list();
304
-			foreach($courses as $course) {
305
-				$course_tmp = array();
306
-				$course_tmp['id'] = $course['id'];
307
-				$course_tmp['code'] = $course['code'];
308
-				$course_tmp['title'] = $course['title'];
309
-				$course_tmp['language'] = $course['course_language'];
310
-				$course_tmp['visibility'] = $course['visibility'];
311
-
312
-				// Determining category name
313
-				if($category_names[$course['category_code']]) {
314
-					$course_tmp['category_name'] = $category_names[$course['category_code']];
315
-				} else {
316
-					$category = CourseManager::get_course_category($course['category_code']);
317
-					$category_names[$course['category_code']] = $category['name'];
318
-					$course_tmp['category_name'] = $category['name'];
319
-				}
320
-
321
-				// Determining number of students registered in course
322
-				$user_list = CourseManager::get_user_list_from_course_code($course['code']);
323
-				$course_tmp['number_students'] = count($user_list);
324
-
325
-				// Determining external course id
326
-				$course_tmp['external_course_id'] = CourseManager::get_course_extra_field_value($course_id_field_name, $course['code']);
327
-
328
-
329
-				$courses_result[] = $course_tmp;
330
-			}
331
-
332
-			return $courses_result;
333
-		}
334
-	}
335
-
336
-	/**
337
-	 * Subscribe or unsubscribe user to a course (helper method)
338
-	 *
339
-	 * @param string Course id field name. Use "chamilo_course_id" to use internal id
340
-	 * @param string Course id value.
341
-	 * @param string User id field name. Use "chamilo_user_id" to use internal id
342
-	 * @param string User id value
343
-	 * @param int Set to 1 to subscribe, 0 to unsubscribe
344
-	 * @param int Status (STUDENT or TEACHER) Used for subscription only
345
-	 * @return mixed True if subscription or unsubscription was successful, false otherwise
346
-	 */
347
-	protected function changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $state, $status = STUDENT) {
348
-		$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
349
-		if($course_id instanceof WSError) {
350
-			return $course_id;
351
-		} else {
352
-			$user_id = $this->getUserId($user_id_field_name, $user_id_value);
353
-			if($user_id instanceof WSError) {
354
-				return $user_id;
355
-			} else {
356
-				$course_code = CourseManager::get_course_code_from_course_id($course_id);
357
-				if($state == 0) {
358
-					// Unsubscribe user
359
-					CourseManager::unsubscribe_user($user_id, $course_code);
360
-					return true;
361
-				} else {
362
-					// Subscribe user
363
-					if(CourseManager::subscribe_user($user_id, $course_code, $status)) {
364
-						return true;
365
-					} else {
366
-						return new WSError(203, 'An error occured subscribing to this course');
367
-					}
368
-				}
369
-			}
370
-		}
371
-	}
372
-
373
-	/**
374
-	 * Subscribe user to a course
375
-	 *
376
-	 * @param string API secret key
377
-	 * @param string Course id field name. Use "chamilo_course_id" to use internal id
378
-	 * @param string Course id value.
379
-	 * @param string User id field name. Use "chamilo_user_id" to use internal id
380
-	 * @param string User id value
381
-	 * @param int Status (1 = Teacher, 5 = Student)
382
-	 */
383
-	public function SubscribeUserToCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $status) {
384
-		$verifKey = $this->verifyKey($secret_key);
385
-		if($verifKey instanceof WSError) {
386
-			$this->handleError($verifKey);
387
-		} else {
388
-			$result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 1, $status);
389
-			if($result instanceof WSError) {
390
-				$this->handleError($result);
391
-			}
392
-		}
393
-	}
394
-
395
-	/**
396
-	 * Unsusbscribe user from course
397
-	 *
398
-	 * @param string API secret key
399
-	 * @param string Course id field name. Use "chamilo_course_id" to use internal id
400
-	 * @param string Course id value.
401
-	 * @param string User id field name. Use "chamilo_user_id" to use internal id
402
-	 * @param string User id value
403
-	 */
404
-	public function UnsubscribeUserFromCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value) {
405
-		$verifKey = $this->verifyKey($secret_key);
406
-		if($verifKey instanceof WSError) {
407
-			$this->handleError($verifKey);
408
-		} else {
409
-			$result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 0);
410
-			if($result instanceof WSError) {
411
-				$this->handleError($result);
412
-			}
413
-		}
414
-	}
415
-
416
-	/**
417
-	 * Returns the descriptions of a course, along with their id
418
-	 *
419
-	 * @param string API secret key
420
-	 * @param string Course id field name
421
-	 * @param string Course id value
422
-	 * @return array Returns an array with elements of the form ('course_desc_id' => 1, 'course_desc_title' => 'Title', 'course_desc_content' => 'Content')
423
-	 */
424
-	public function GetCourseDescriptions($secret_key, $course_id_field_name, $course_id_value) {
425
-		$verifKey = $this->verifyKey($secret_key);
426
-		if($verifKey instanceof WSError) {
427
-			$this->handleError($verifKey);
428
-		} else {
429
-			$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
430
-			if($course_id instanceof WSError) {
431
-				return $course_id;
432
-			} else {
433
-				// Course exists, get its descriptions
434
-				$descriptions = CourseDescription::get_descriptions($course_id);
435
-				$results = array();
436
-				foreach($descriptions as $description) {
437
-					$results[] = array('course_desc_id' => $description->get_description_type(),
438
-						'course_desc_title' => $description->get_title(),
439
-						'course_desc_content' => $description->get_content());
440
-				}
441
-				return $results;
442
-			}
443
-		}
444
-	}
445
-
446
-
447
-	/**
448
-	 * Edit course description
449
-	 *
450
-	 * @param string API secret key
451
-	 * @param string Course id field name
452
-	 * @param string Course id value
453
-	 * @param int Category id from course description
454
-	 * @param string Description title
455
-	 * @param string Course description content
456
-	 */
457
-	public function EditCourseDescription($secret_key, $course_id_field_name, $course_id_value, $course_desc_id, $course_desc_title, $course_desc_content) {
458
-		$verifKey = $this->verifyKey($secret_key);
459
-		if($verifKey instanceof WSError) {
460
-			$this->handleError($verifKey);
461
-		} else {
462
-			$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
463
-			if($course_id instanceof WSError) {
464
-				return $course_id;
465
-			} else {
466
-				// Create the new course description
467
-				$cd = new CourseDescription();
468
-				$cd->set_description_type($course_desc_id);
469
-				$cd->set_title($course_desc_title);
470
-				$cd->set_content($course_desc_content);
471
-				$cd->set_session_id(0);
472
-
473
-				// Get course info
13
+    /**
14
+     * Deletes a course (helper method)
15
+     *
16
+     * @param string Course id field name
17
+     * @param string Course id value
18
+     * @return mixed True if the course was successfully deleted, WSError otherwise
19
+     */
20
+    protected function deleteCourseHelper($course_id_field_name, $course_id_value) {
21
+        $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
22
+        if($course_id instanceof WSCMError) {
23
+            return $course_id;
24
+        } else {
25
+            $course_code = CourseManager::get_course_code_from_course_id($course_id);
26
+            CourseManager::delete_course($course_code);
27
+            return true;
28
+        }
29
+    }
30
+
31
+    /**
32
+     * Deletes a course
33
+     *
34
+     * @param string API secret key
35
+     * @param string Course id field name
36
+     * @param string Course id value
37
+     */
38
+    public function DeleteCourse($secret_key, $course_id_field_name, $course_id_value) {
39
+        $verifKey = $this->verifyKey($secret_key);
40
+        if($verifKey instanceof WSError) {
41
+            $this->handleError($verifKey);
42
+        } else {
43
+            $result = $this->deleteCourseHelper($course_id_field_name, $course_id_value);
44
+            if($result instanceof WSError) {
45
+                $this->handleError($result);
46
+            }
47
+        }
48
+    }
49
+
50
+    /**
51
+     * Deletes multiple courses
52
+     *
53
+     * @param string API secret key
54
+     * @param array Array of courses with elements of the form array('course_id_field_name' => 'name_of_field', 'course_id_value' => 'value')
55
+     * @return array Array with elements like array('course_id_value' => 'value', 'result' => array('code' => 0, 'message' => 'Operation was successful')). Note that if the result array contains a code different
56
+     * than 0, an error occured
57
+     */
58
+    public function DeleteCourses($secret_key, $courses) {
59
+        $verifKey = $this->verifyKey($secret_key);
60
+        if($verifKey instanceof WSError) {
61
+            $this->handleError($verifKey);
62
+        } else {
63
+            $results = array();
64
+            foreach($courses as $course) {
65
+                $result_tmp = array();
66
+                $result_op = $this->deleteCourseHelper($course['course_id_field_name'], $course['course_id_value']);
67
+                $result_tmp['course_id_value'] = $course['course_id_value'];
68
+                if($result_op instanceof WSCMError) {
69
+                    // Return the error in the results
70
+                    $result_tmp['result'] = $result_op->toArray();
71
+                } else {
72
+                    $result_tmp['result'] = $this->getSuccessfulResult();
73
+                }
74
+                $results[] = $result_tmp;
75
+            }
76
+            return $results;
77
+        }
78
+    }
79
+
80
+    /**
81
+     * Creates a course (helper method)
82
+     *
83
+     * @param string Title
84
+     * @param string Category code
85
+     * @param string Wanted code. If it's not defined, it will be generated automatically
86
+     * @param string Tutor name
87
+     * @param string Course admin user id field name
88
+     * @param string Course admin user id value
89
+     * @param string Course language
90
+     * @param string Course id field name
91
+     * @param string Course id value
92
+     * @param array Course extra fields
93
+     * @return mixed Generated id if creation was successful, WSError otherwise
94
+     */
95
+    protected function createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) {
96
+        // Add the original course id field name and value to the extra fields if needed
97
+        $extras_associative = array();
98
+        if($course_id_field_name != "chamilo_course_id") {
99
+            $extras_associative[$course_id_field_name] = $course_id_value;
100
+        }
101
+        foreach($extras as $extra) {
102
+            $extras_associative[$extra['field_name']] = $extra['field_value'];
103
+        }
104
+        $course_admin_id = $this->getUserId($course_admin_user_id_field_name, $course_admin_user_id_value);
105
+        if($course_admin_id instanceof WSError) {
106
+            return $course_admin_id;
107
+        }
108
+        if($wanted_code == '') {
109
+            $wanted_code = CourseManager::generate_course_code($title);
110
+        }
111
+        $result = create_course($wanted_code, $title, $tutor_name, $category_code, $language, $course_admin_id, $this->_configuration['db_prefix'], 0);
112
+        if (!$result) {
113
+            return new WSError(202, 'There was an error creating the course');
114
+        } else {
115
+            // Update extra fields
116
+            foreach($extras_associative as $fname => $fvalue) {
117
+                CourseManager::update_course_extra_field_value($result, $fname, $fvalue);
118
+            }
119
+            // Get course id
120
+            $course_info = CourseManager::get_course_information($result);
121
+            return $course_info['real_id'];
122
+        }
123
+    }
124
+
125
+    /**
126
+     * Creates a course
127
+     *
128
+     * @param string API secret key
129
+     * @param string Title
130
+     * @param string Category code
131
+     * @param string Wanted code. If it's not defined, it will be generated automatically
132
+     * @param string Tutor name
133
+     * @param string Course admin user id field name
134
+     * @param string Course admin user id value
135
+     * @param string Course language
136
+     * @param string Course id field name
137
+     * @param string Course id value
138
+     * @param array Course extra fields
139
+     * @return int Course id generated
140
+     */
141
+    public function CreateCourse($secret_key, $title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) {
142
+        // First, verify the secret key
143
+        $verifKey = $this->verifyKey($secret_key);
144
+        if($verifKey instanceof WSError) {
145
+            $this->handleError($verifKey);
146
+        } else {
147
+            $result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras);
148
+            if($result instanceof WSError) {
149
+                $this->handleError($result);
150
+            } else {
151
+                return $result;
152
+            }
153
+        }
154
+    }
155
+
156
+    /**
157
+     * Create multiple courses
158
+     *
159
+     * @param string API secret key
160
+     * @param array Courses to be created, with elements following the structure presented in CreateCourse
161
+     * @return array Array with elements of the form array('course_id_value' => 'original value sent', 'course_id_generated' => 'value_generated', 'result' => array('code' => 0, 'message' => 'Operation was successful'))
162
+     */
163
+    public function CreateCourses($secret_key, $courses) {
164
+        // First, verify the secret key
165
+        $verifKey = $this->verifyKey($secret_key);
166
+        if($verifKey instanceof WSCMError) {
167
+            $this->handleError($verifKey);
168
+        } else {
169
+            $results = array();
170
+            foreach($courses as $course) {
171
+                $result_tmp = array();
172
+                //reinitialize variables just in case
173
+                $title = $category_code = $wanted_code = $tutor_name = $course_admin_user_id_field_name = $course_admin_user_id_value = $language = $course_id_field_name = $course_id_value = $extras = null;
174
+                extract($course);
175
+                $result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras);
176
+                if($result instanceof WSCMError) {
177
+                    $result_tmp['result'] = $result->toArray();
178
+                    $result_tmp['course_id_value'] = $course_id_value;
179
+                    $result_tmp['course_id_generated'] = 0;
180
+                } else {
181
+                    $result_tmp['result'] = $this->getSuccessfulResult();
182
+                    $result_tmp['course_id_value'] = $course_id_value;
183
+                    $result_tmp['course_id_generated'] = $result;
184
+                }
185
+                $results[] = $result_tmp;
186
+            }
187
+            return $results;
188
+        }
189
+    }
190
+
191
+    /**
192
+     * Edits a course (helper method)
193
+     *
194
+     * @param string Course id field name
195
+     * @param string Course id value
196
+     * @param string Title
197
+     * @param string Category code
198
+     * @param string Department name
199
+     * @param string Department url
200
+     * @param string Course language
201
+     * @param int Visibility
202
+     * @param int Subscribe (0 = denied, 1 = allowed)
203
+     * @param int Unsubscribe (0 = denied, 1 = allowed)
204
+     * @param string Visual code
205
+     * @param array Course extra fields
206
+     * @return mixed True in case of success, WSError otherwise
207
+     */
208
+    protected function editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) {
209
+        $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
210
+        if($course_id instanceof WSCMError) {
211
+            return $course_id;
212
+        } else {
213
+            $attributes = array();
214
+            if(!empty($title)) {
215
+                $attributes['title'] = $title;
216
+            }
217
+            if(!empty($category_code)) {
218
+                $attributes['category_code'] = $category_code;
219
+            }
220
+            if(!empty($department_name)) {
221
+                $attributes['department_name'] = $department_name;
222
+            }
223
+            if(!empty($department_url)) {
224
+                $attributes['department_url'] = $department_url;
225
+            }
226
+            if(!empty($language)) {
227
+                $attributes['course_language'] = $language;
228
+            }
229
+            if($visibility != '') {
230
+                $attributes['visibility'] = (int)$visibility;
231
+            }
232
+            if($subscribe != '') {
233
+                $attributes['subscribe'] = (int)$subscribe;
234
+            }
235
+            if($unsubscribe != '') {
236
+                $attributes['unsubscribe'] = (int)$unsubscribe;
237
+            }
238
+            if(!empty($visual_code)) {
239
+                $attributes['visual_code'] = $visual_code;
240
+            }
241
+            if(!empty($attributes)) {
242
+                CourseManager::update_attributes($course_id, $attributes);
243
+            }
244
+            if(!empty($extras)) {
245
+                $course_code = CourseManager::get_course_code_from_course_id($course_id);
246
+                $extras_associative = array();
247
+                foreach($extras as $extra) {
248
+                    $extras_associative[$extra['field_name']] = $extra['field_value'];
249
+                }
250
+                foreach($extras_associative as $fname => $fvalue) {
251
+                    CourseManager::update_extra_field_value($course_code, $fname, $fvalue);
252
+                }
253
+            }
254
+            return true;
255
+        }
256
+    }
257
+
258
+    /**
259
+     * Edits a course
260
+     *
261
+     * @param string API secret key
262
+     * @param string Course id field name
263
+     * @param string Course id value
264
+     * @param string Title
265
+     * @param string Category code
266
+     * @param string Department name
267
+     * @param string Department url
268
+     * @param string Course language
269
+     * @param int Visibility
270
+     * @param int Subscribe (0 = denied, 1 = allowed)
271
+     * @param int Unsubscribe (0 = denied, 1 = allowed)
272
+     * @param string Visual code
273
+     * @param array Course extra fields
274
+     */
275
+    public function EditCourse($secret_key, $course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) {
276
+        $verifKey = $this->verifyKey($secret_key);
277
+        if($verifKey instanceof WSCMError) {
278
+            $this->handleError($verifKey);
279
+        } else {
280
+            $result = $this->editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras);
281
+            if($result instanceof WSCMError) {
282
+                $this->handleError($result);
283
+            }
284
+        }
285
+    }
286
+
287
+    /**
288
+     * List courses
289
+     *
290
+     * @param string API secret key
291
+     * @param string Course id field name. Use "chamilo_course_id" to use internal id
292
+     * @return array An array with elements of the form ('id' => 'Course internal id', 'code' => 'Course code', 'title' => 'Course title', 'language' => 'Course language', 'visibility' => 'Course visibility',
293
+     * 'category_name' => 'Name of the category of the course', 'number_students' => 'Number of students in the course', 'external_course_id' => 'External course id')
294
+     */
295
+    public function ListCourses($secret_key, $course_id_field_name) {
296
+        $verifKey = $this->verifyKey($secret_key);
297
+        if($verifKey instanceof WSError) {
298
+            $this->handleError($verifKey);
299
+        } else {
300
+            $courses_result = array();
301
+            $category_names = array();
302
+
303
+            $courses = CourseManager::get_courses_list();
304
+            foreach($courses as $course) {
305
+                $course_tmp = array();
306
+                $course_tmp['id'] = $course['id'];
307
+                $course_tmp['code'] = $course['code'];
308
+                $course_tmp['title'] = $course['title'];
309
+                $course_tmp['language'] = $course['course_language'];
310
+                $course_tmp['visibility'] = $course['visibility'];
311
+
312
+                // Determining category name
313
+                if($category_names[$course['category_code']]) {
314
+                    $course_tmp['category_name'] = $category_names[$course['category_code']];
315
+                } else {
316
+                    $category = CourseManager::get_course_category($course['category_code']);
317
+                    $category_names[$course['category_code']] = $category['name'];
318
+                    $course_tmp['category_name'] = $category['name'];
319
+                }
320
+
321
+                // Determining number of students registered in course
322
+                $user_list = CourseManager::get_user_list_from_course_code($course['code']);
323
+                $course_tmp['number_students'] = count($user_list);
324
+
325
+                // Determining external course id
326
+                $course_tmp['external_course_id'] = CourseManager::get_course_extra_field_value($course_id_field_name, $course['code']);
327
+
328
+
329
+                $courses_result[] = $course_tmp;
330
+            }
331
+
332
+            return $courses_result;
333
+        }
334
+    }
335
+
336
+    /**
337
+     * Subscribe or unsubscribe user to a course (helper method)
338
+     *
339
+     * @param string Course id field name. Use "chamilo_course_id" to use internal id
340
+     * @param string Course id value.
341
+     * @param string User id field name. Use "chamilo_user_id" to use internal id
342
+     * @param string User id value
343
+     * @param int Set to 1 to subscribe, 0 to unsubscribe
344
+     * @param int Status (STUDENT or TEACHER) Used for subscription only
345
+     * @return mixed True if subscription or unsubscription was successful, false otherwise
346
+     */
347
+    protected function changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $state, $status = STUDENT) {
348
+        $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
349
+        if($course_id instanceof WSError) {
350
+            return $course_id;
351
+        } else {
352
+            $user_id = $this->getUserId($user_id_field_name, $user_id_value);
353
+            if($user_id instanceof WSError) {
354
+                return $user_id;
355
+            } else {
356
+                $course_code = CourseManager::get_course_code_from_course_id($course_id);
357
+                if($state == 0) {
358
+                    // Unsubscribe user
359
+                    CourseManager::unsubscribe_user($user_id, $course_code);
360
+                    return true;
361
+                } else {
362
+                    // Subscribe user
363
+                    if(CourseManager::subscribe_user($user_id, $course_code, $status)) {
364
+                        return true;
365
+                    } else {
366
+                        return new WSError(203, 'An error occured subscribing to this course');
367
+                    }
368
+                }
369
+            }
370
+        }
371
+    }
372
+
373
+    /**
374
+     * Subscribe user to a course
375
+     *
376
+     * @param string API secret key
377
+     * @param string Course id field name. Use "chamilo_course_id" to use internal id
378
+     * @param string Course id value.
379
+     * @param string User id field name. Use "chamilo_user_id" to use internal id
380
+     * @param string User id value
381
+     * @param int Status (1 = Teacher, 5 = Student)
382
+     */
383
+    public function SubscribeUserToCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $status) {
384
+        $verifKey = $this->verifyKey($secret_key);
385
+        if($verifKey instanceof WSError) {
386
+            $this->handleError($verifKey);
387
+        } else {
388
+            $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 1, $status);
389
+            if($result instanceof WSError) {
390
+                $this->handleError($result);
391
+            }
392
+        }
393
+    }
394
+
395
+    /**
396
+     * Unsusbscribe user from course
397
+     *
398
+     * @param string API secret key
399
+     * @param string Course id field name. Use "chamilo_course_id" to use internal id
400
+     * @param string Course id value.
401
+     * @param string User id field name. Use "chamilo_user_id" to use internal id
402
+     * @param string User id value
403
+     */
404
+    public function UnsubscribeUserFromCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value) {
405
+        $verifKey = $this->verifyKey($secret_key);
406
+        if($verifKey instanceof WSError) {
407
+            $this->handleError($verifKey);
408
+        } else {
409
+            $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 0);
410
+            if($result instanceof WSError) {
411
+                $this->handleError($result);
412
+            }
413
+        }
414
+    }
415
+
416
+    /**
417
+     * Returns the descriptions of a course, along with their id
418
+     *
419
+     * @param string API secret key
420
+     * @param string Course id field name
421
+     * @param string Course id value
422
+     * @return array Returns an array with elements of the form ('course_desc_id' => 1, 'course_desc_title' => 'Title', 'course_desc_content' => 'Content')
423
+     */
424
+    public function GetCourseDescriptions($secret_key, $course_id_field_name, $course_id_value) {
425
+        $verifKey = $this->verifyKey($secret_key);
426
+        if($verifKey instanceof WSError) {
427
+            $this->handleError($verifKey);
428
+        } else {
429
+            $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
430
+            if($course_id instanceof WSError) {
431
+                return $course_id;
432
+            } else {
433
+                // Course exists, get its descriptions
434
+                $descriptions = CourseDescription::get_descriptions($course_id);
435
+                $results = array();
436
+                foreach($descriptions as $description) {
437
+                    $results[] = array('course_desc_id' => $description->get_description_type(),
438
+                        'course_desc_title' => $description->get_title(),
439
+                        'course_desc_content' => $description->get_content());
440
+                }
441
+                return $results;
442
+            }
443
+        }
444
+    }
445
+
446
+
447
+    /**
448
+     * Edit course description
449
+     *
450
+     * @param string API secret key
451
+     * @param string Course id field name
452
+     * @param string Course id value
453
+     * @param int Category id from course description
454
+     * @param string Description title
455
+     * @param string Course description content
456
+     */
457
+    public function EditCourseDescription($secret_key, $course_id_field_name, $course_id_value, $course_desc_id, $course_desc_title, $course_desc_content) {
458
+        $verifKey = $this->verifyKey($secret_key);
459
+        if($verifKey instanceof WSError) {
460
+            $this->handleError($verifKey);
461
+        } else {
462
+            $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
463
+            if($course_id instanceof WSError) {
464
+                return $course_id;
465
+            } else {
466
+                // Create the new course description
467
+                $cd = new CourseDescription();
468
+                $cd->set_description_type($course_desc_id);
469
+                $cd->set_title($course_desc_title);
470
+                $cd->set_content($course_desc_content);
471
+                $cd->set_session_id(0);
472
+
473
+                // Get course info
474 474
                 $course_info = CourseManager::get_course_information(
475 475
                     CourseManager::get_course_code_from_course_id($course_id)
476 476
                 );
477
-				// Check if this course description exists
478
-				$descriptions = CourseDescription::get_descriptions($course_id);
479
-				$exists = false;
480
-				foreach($descriptions as $description) {
481
-					if($description->get_description_type() == $course_desc_id) {
482
-						$exists = true;
483
-					}
484
-				}
477
+                // Check if this course description exists
478
+                $descriptions = CourseDescription::get_descriptions($course_id);
479
+                $exists = false;
480
+                foreach($descriptions as $description) {
481
+                    if($description->get_description_type() == $course_desc_id) {
482
+                        $exists = true;
483
+                    }
484
+                }
485 485
                 $cd->set_course_id($course_info['real_id']);
486
-				if (!$exists) {
487
-					$cd->set_progress(0);
488
-					$cd->insert();
489
-				} else {
490
-					$cd->update();
491
-				}
492
-			}
493
-		}
494
-	}
495
-	public function unreadMessage($username, $password)
496
-	{
497
-		if($this->verifyUserPass($username, $password) == "valid")
498
-		{
499
-			$table_message = Database::get_main_table(TABLE_MESSAGE);
500
-			$user_id = UserManager::get_user_id_from_username($username);
501
-			$condition_msg_status = ' msg_status = 1 '; // define('MESSAGE_STATUS_UNREAD', '1');
502
-
503
-			$sql_query = "SELECT COUNT(*) as number_messages FROM $table_message WHERE $condition_msg_status AND user_receiver_id=".$user_id;
504
-
505
-			$sql_result = Database::query($sql_query);
506
-			$result = Database::fetch_array($sql_result);
507
-			return $result['number_messages'];
508
-		}
509
-		return "0";
510
-	}
511
-
512
-	public function get_message_data($username, $password)
513
-	{
514
-		if($this->verifyUserPass($username, $password) == "valid")
515
-		{
516
-			$user_id = get_user_id_from_username($username);
517
-
518
-		}
519
-
520
-	}
521
-
522
-	public function nada($username, $password)
523
-	{
524
-		if($this->verifyUserPass($username, $password) == "valid")
525
-			return $username.$password;
526
-		return $username;
527
-	}
486
+                if (!$exists) {
487
+                    $cd->set_progress(0);
488
+                    $cd->insert();
489
+                } else {
490
+                    $cd->update();
491
+                }
492
+            }
493
+        }
494
+    }
495
+    public function unreadMessage($username, $password)
496
+    {
497
+        if($this->verifyUserPass($username, $password) == "valid")
498
+        {
499
+            $table_message = Database::get_main_table(TABLE_MESSAGE);
500
+            $user_id = UserManager::get_user_id_from_username($username);
501
+            $condition_msg_status = ' msg_status = 1 '; // define('MESSAGE_STATUS_UNREAD', '1');
502
+
503
+            $sql_query = "SELECT COUNT(*) as number_messages FROM $table_message WHERE $condition_msg_status AND user_receiver_id=".$user_id;
504
+
505
+            $sql_result = Database::query($sql_query);
506
+            $result = Database::fetch_array($sql_result);
507
+            return $result['number_messages'];
508
+        }
509
+        return "0";
510
+    }
511
+
512
+    public function get_message_data($username, $password)
513
+    {
514
+        if($this->verifyUserPass($username, $password) == "valid")
515
+        {
516
+            $user_id = get_user_id_from_username($username);
517
+
518
+        }
519
+
520
+    }
521
+
522
+    public function nada($username, $password)
523
+    {
524
+        if($this->verifyUserPass($username, $password) == "valid")
525
+            return $username.$password;
526
+        return $username;
527
+    }
528 528
 
529 529
 
530 530
 
Please login to merge, or discard this patch.
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 	 */
20 20
 	protected function deleteCourseHelper($course_id_field_name, $course_id_value) {
21 21
 		$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
22
-		if($course_id instanceof WSCMError) {
22
+		if ($course_id instanceof WSCMError) {
23 23
 			return $course_id;
24 24
 		} else {
25 25
 			$course_code = CourseManager::get_course_code_from_course_id($course_id);
@@ -37,11 +37,11 @@  discard block
 block discarded – undo
37 37
 	 */
38 38
 	public function DeleteCourse($secret_key, $course_id_field_name, $course_id_value) {
39 39
 		$verifKey = $this->verifyKey($secret_key);
40
-		if($verifKey instanceof WSError) {
40
+		if ($verifKey instanceof WSError) {
41 41
 			$this->handleError($verifKey);
42 42
 		} else {
43 43
 			$result = $this->deleteCourseHelper($course_id_field_name, $course_id_value);
44
-			if($result instanceof WSError) {
44
+			if ($result instanceof WSError) {
45 45
 				$this->handleError($result);
46 46
 			}
47 47
 		}
@@ -57,15 +57,15 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function DeleteCourses($secret_key, $courses) {
59 59
 		$verifKey = $this->verifyKey($secret_key);
60
-		if($verifKey instanceof WSError) {
60
+		if ($verifKey instanceof WSError) {
61 61
 			$this->handleError($verifKey);
62 62
 		} else {
63 63
 			$results = array();
64
-			foreach($courses as $course) {
64
+			foreach ($courses as $course) {
65 65
 				$result_tmp = array();
66 66
 				$result_op = $this->deleteCourseHelper($course['course_id_field_name'], $course['course_id_value']);
67 67
 				$result_tmp['course_id_value'] = $course['course_id_value'];
68
-				if($result_op instanceof WSCMError) {
68
+				if ($result_op instanceof WSCMError) {
69 69
 					// Return the error in the results
70 70
 					$result_tmp['result'] = $result_op->toArray();
71 71
 				} else {
@@ -95,17 +95,17 @@  discard block
 block discarded – undo
95 95
 	protected function createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) {
96 96
 		// Add the original course id field name and value to the extra fields if needed
97 97
 		$extras_associative = array();
98
-		if($course_id_field_name != "chamilo_course_id") {
98
+		if ($course_id_field_name != "chamilo_course_id") {
99 99
 			$extras_associative[$course_id_field_name] = $course_id_value;
100 100
 		}
101
-		foreach($extras as $extra) {
101
+		foreach ($extras as $extra) {
102 102
 			$extras_associative[$extra['field_name']] = $extra['field_value'];
103 103
 		}
104 104
 		$course_admin_id = $this->getUserId($course_admin_user_id_field_name, $course_admin_user_id_value);
105
-		if($course_admin_id instanceof WSError) {
105
+		if ($course_admin_id instanceof WSError) {
106 106
 			return $course_admin_id;
107 107
 		}
108
-		if($wanted_code == '') {
108
+		if ($wanted_code == '') {
109 109
 			$wanted_code = CourseManager::generate_course_code($title);
110 110
 		}
111 111
 		$result = create_course($wanted_code, $title, $tutor_name, $category_code, $language, $course_admin_id, $this->_configuration['db_prefix'], 0);
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 			return new WSError(202, 'There was an error creating the course');
114 114
 		} else {
115 115
 			// Update extra fields
116
-			foreach($extras_associative as $fname => $fvalue) {
116
+			foreach ($extras_associative as $fname => $fvalue) {
117 117
 				CourseManager::update_course_extra_field_value($result, $fname, $fvalue);
118 118
 			}
119 119
 			// Get course id
@@ -141,11 +141,11 @@  discard block
 block discarded – undo
141 141
 	public function CreateCourse($secret_key, $title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) {
142 142
 		// First, verify the secret key
143 143
 		$verifKey = $this->verifyKey($secret_key);
144
-		if($verifKey instanceof WSError) {
144
+		if ($verifKey instanceof WSError) {
145 145
 			$this->handleError($verifKey);
146 146
 		} else {
147 147
 			$result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras);
148
-			if($result instanceof WSError) {
148
+			if ($result instanceof WSError) {
149 149
 				$this->handleError($result);
150 150
 			} else {
151 151
 				return $result;
@@ -163,17 +163,17 @@  discard block
 block discarded – undo
163 163
 	public function CreateCourses($secret_key, $courses) {
164 164
 		// First, verify the secret key
165 165
 		$verifKey = $this->verifyKey($secret_key);
166
-		if($verifKey instanceof WSCMError) {
166
+		if ($verifKey instanceof WSCMError) {
167 167
 			$this->handleError($verifKey);
168 168
 		} else {
169 169
 			$results = array();
170
-			foreach($courses as $course) {
170
+			foreach ($courses as $course) {
171 171
 				$result_tmp = array();
172 172
 				//reinitialize variables just in case
173 173
 				$title = $category_code = $wanted_code = $tutor_name = $course_admin_user_id_field_name = $course_admin_user_id_value = $language = $course_id_field_name = $course_id_value = $extras = null;
174 174
 				extract($course);
175 175
 				$result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras);
176
-				if($result instanceof WSCMError) {
176
+				if ($result instanceof WSCMError) {
177 177
 					$result_tmp['result'] = $result->toArray();
178 178
 					$result_tmp['course_id_value'] = $course_id_value;
179 179
 					$result_tmp['course_id_generated'] = 0;
@@ -207,47 +207,47 @@  discard block
 block discarded – undo
207 207
 	 */
208 208
 	protected function editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) {
209 209
 		$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
210
-		if($course_id instanceof WSCMError) {
210
+		if ($course_id instanceof WSCMError) {
211 211
 			return $course_id;
212 212
 		} else {
213 213
 			$attributes = array();
214
-			if(!empty($title)) {
214
+			if (!empty($title)) {
215 215
 				$attributes['title'] = $title;
216 216
 			}
217
-			if(!empty($category_code)) {
217
+			if (!empty($category_code)) {
218 218
 				$attributes['category_code'] = $category_code;
219 219
 			}
220
-			if(!empty($department_name)) {
220
+			if (!empty($department_name)) {
221 221
 				$attributes['department_name'] = $department_name;
222 222
 			}
223
-			if(!empty($department_url)) {
223
+			if (!empty($department_url)) {
224 224
 				$attributes['department_url'] = $department_url;
225 225
 			}
226
-			if(!empty($language)) {
226
+			if (!empty($language)) {
227 227
 				$attributes['course_language'] = $language;
228 228
 			}
229
-			if($visibility != '') {
230
-				$attributes['visibility'] = (int)$visibility;
229
+			if ($visibility != '') {
230
+				$attributes['visibility'] = (int) $visibility;
231 231
 			}
232
-			if($subscribe != '') {
233
-				$attributes['subscribe'] = (int)$subscribe;
232
+			if ($subscribe != '') {
233
+				$attributes['subscribe'] = (int) $subscribe;
234 234
 			}
235
-			if($unsubscribe != '') {
236
-				$attributes['unsubscribe'] = (int)$unsubscribe;
235
+			if ($unsubscribe != '') {
236
+				$attributes['unsubscribe'] = (int) $unsubscribe;
237 237
 			}
238
-			if(!empty($visual_code)) {
238
+			if (!empty($visual_code)) {
239 239
 				$attributes['visual_code'] = $visual_code;
240 240
 			}
241
-			if(!empty($attributes)) {
241
+			if (!empty($attributes)) {
242 242
 				CourseManager::update_attributes($course_id, $attributes);
243 243
 			}
244
-			if(!empty($extras)) {
244
+			if (!empty($extras)) {
245 245
 				$course_code = CourseManager::get_course_code_from_course_id($course_id);
246 246
 				$extras_associative = array();
247
-				foreach($extras as $extra) {
247
+				foreach ($extras as $extra) {
248 248
 					$extras_associative[$extra['field_name']] = $extra['field_value'];
249 249
 				}
250
-				foreach($extras_associative as $fname => $fvalue) {
250
+				foreach ($extras_associative as $fname => $fvalue) {
251 251
 					CourseManager::update_extra_field_value($course_code, $fname, $fvalue);
252 252
 				}
253 253
 			}
@@ -274,11 +274,11 @@  discard block
 block discarded – undo
274 274
 	 */
275 275
 	public function EditCourse($secret_key, $course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) {
276 276
 		$verifKey = $this->verifyKey($secret_key);
277
-		if($verifKey instanceof WSCMError) {
277
+		if ($verifKey instanceof WSCMError) {
278 278
 			$this->handleError($verifKey);
279 279
 		} else {
280 280
 			$result = $this->editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras);
281
-			if($result instanceof WSCMError) {
281
+			if ($result instanceof WSCMError) {
282 282
 				$this->handleError($result);
283 283
 			}
284 284
 		}
@@ -294,14 +294,14 @@  discard block
 block discarded – undo
294 294
 	 */
295 295
 	public function ListCourses($secret_key, $course_id_field_name) {
296 296
 		$verifKey = $this->verifyKey($secret_key);
297
-		if($verifKey instanceof WSError) {
297
+		if ($verifKey instanceof WSError) {
298 298
 			$this->handleError($verifKey);
299 299
 		} else {
300 300
 			$courses_result = array();
301 301
 			$category_names = array();
302 302
 
303 303
 			$courses = CourseManager::get_courses_list();
304
-			foreach($courses as $course) {
304
+			foreach ($courses as $course) {
305 305
 				$course_tmp = array();
306 306
 				$course_tmp['id'] = $course['id'];
307 307
 				$course_tmp['code'] = $course['code'];
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
 				$course_tmp['visibility'] = $course['visibility'];
311 311
 
312 312
 				// Determining category name
313
-				if($category_names[$course['category_code']]) {
313
+				if ($category_names[$course['category_code']]) {
314 314
 					$course_tmp['category_name'] = $category_names[$course['category_code']];
315 315
 				} else {
316 316
 					$category = CourseManager::get_course_category($course['category_code']);
@@ -346,21 +346,21 @@  discard block
 block discarded – undo
346 346
 	 */
347 347
 	protected function changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $state, $status = STUDENT) {
348 348
 		$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
349
-		if($course_id instanceof WSError) {
349
+		if ($course_id instanceof WSError) {
350 350
 			return $course_id;
351 351
 		} else {
352 352
 			$user_id = $this->getUserId($user_id_field_name, $user_id_value);
353
-			if($user_id instanceof WSError) {
353
+			if ($user_id instanceof WSError) {
354 354
 				return $user_id;
355 355
 			} else {
356 356
 				$course_code = CourseManager::get_course_code_from_course_id($course_id);
357
-				if($state == 0) {
357
+				if ($state == 0) {
358 358
 					// Unsubscribe user
359 359
 					CourseManager::unsubscribe_user($user_id, $course_code);
360 360
 					return true;
361 361
 				} else {
362 362
 					// Subscribe user
363
-					if(CourseManager::subscribe_user($user_id, $course_code, $status)) {
363
+					if (CourseManager::subscribe_user($user_id, $course_code, $status)) {
364 364
 						return true;
365 365
 					} else {
366 366
 						return new WSError(203, 'An error occured subscribing to this course');
@@ -382,11 +382,11 @@  discard block
 block discarded – undo
382 382
 	 */
383 383
 	public function SubscribeUserToCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $status) {
384 384
 		$verifKey = $this->verifyKey($secret_key);
385
-		if($verifKey instanceof WSError) {
385
+		if ($verifKey instanceof WSError) {
386 386
 			$this->handleError($verifKey);
387 387
 		} else {
388 388
 			$result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 1, $status);
389
-			if($result instanceof WSError) {
389
+			if ($result instanceof WSError) {
390 390
 				$this->handleError($result);
391 391
 			}
392 392
 		}
@@ -403,11 +403,11 @@  discard block
 block discarded – undo
403 403
 	 */
404 404
 	public function UnsubscribeUserFromCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value) {
405 405
 		$verifKey = $this->verifyKey($secret_key);
406
-		if($verifKey instanceof WSError) {
406
+		if ($verifKey instanceof WSError) {
407 407
 			$this->handleError($verifKey);
408 408
 		} else {
409 409
 			$result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 0);
410
-			if($result instanceof WSError) {
410
+			if ($result instanceof WSError) {
411 411
 				$this->handleError($result);
412 412
 			}
413 413
 		}
@@ -423,17 +423,17 @@  discard block
 block discarded – undo
423 423
 	 */
424 424
 	public function GetCourseDescriptions($secret_key, $course_id_field_name, $course_id_value) {
425 425
 		$verifKey = $this->verifyKey($secret_key);
426
-		if($verifKey instanceof WSError) {
426
+		if ($verifKey instanceof WSError) {
427 427
 			$this->handleError($verifKey);
428 428
 		} else {
429 429
 			$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
430
-			if($course_id instanceof WSError) {
430
+			if ($course_id instanceof WSError) {
431 431
 				return $course_id;
432 432
 			} else {
433 433
 				// Course exists, get its descriptions
434 434
 				$descriptions = CourseDescription::get_descriptions($course_id);
435 435
 				$results = array();
436
-				foreach($descriptions as $description) {
436
+				foreach ($descriptions as $description) {
437 437
 					$results[] = array('course_desc_id' => $description->get_description_type(),
438 438
 						'course_desc_title' => $description->get_title(),
439 439
 						'course_desc_content' => $description->get_content());
@@ -456,11 +456,11 @@  discard block
 block discarded – undo
456 456
 	 */
457 457
 	public function EditCourseDescription($secret_key, $course_id_field_name, $course_id_value, $course_desc_id, $course_desc_title, $course_desc_content) {
458 458
 		$verifKey = $this->verifyKey($secret_key);
459
-		if($verifKey instanceof WSError) {
459
+		if ($verifKey instanceof WSError) {
460 460
 			$this->handleError($verifKey);
461 461
 		} else {
462 462
 			$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
463
-			if($course_id instanceof WSError) {
463
+			if ($course_id instanceof WSError) {
464 464
 				return $course_id;
465 465
 			} else {
466 466
 				// Create the new course description
@@ -477,8 +477,8 @@  discard block
 block discarded – undo
477 477
 				// Check if this course description exists
478 478
 				$descriptions = CourseDescription::get_descriptions($course_id);
479 479
 				$exists = false;
480
-				foreach($descriptions as $description) {
481
-					if($description->get_description_type() == $course_desc_id) {
480
+				foreach ($descriptions as $description) {
481
+					if ($description->get_description_type() == $course_desc_id) {
482 482
 						$exists = true;
483 483
 					}
484 484
 				}
@@ -494,7 +494,7 @@  discard block
 block discarded – undo
494 494
 	}
495 495
 	public function unreadMessage($username, $password)
496 496
 	{
497
-		if($this->verifyUserPass($username, $password) == "valid")
497
+		if ($this->verifyUserPass($username, $password) == "valid")
498 498
 		{
499 499
 			$table_message = Database::get_main_table(TABLE_MESSAGE);
500 500
 			$user_id = UserManager::get_user_id_from_username($username);
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
 
512 512
 	public function get_message_data($username, $password)
513 513
 	{
514
-		if($this->verifyUserPass($username, $password) == "valid")
514
+		if ($this->verifyUserPass($username, $password) == "valid")
515 515
 		{
516 516
 			$user_id = get_user_id_from_username($username);
517 517
 
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
 
522 522
 	public function nada($username, $password)
523 523
 	{
524
-		if($this->verifyUserPass($username, $password) == "valid")
524
+		if ($this->verifyUserPass($username, $password) == "valid")
525 525
 			return $username.$password;
526 526
 		return $username;
527 527
 	}
Please login to merge, or discard this patch.