Completed
Push — 1.10.x ( e39098...d9ba33 )
by Julito
34:46
created
main/permissions/user_permissions.inc.php 3 patches
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -5,10 +5,10 @@  discard block
 block discarded – undo
5 5
 /**
6 6
  * Code
7 7
  */
8
-$user_id=$userIdViewed;
9
-if ($mainUserInfo['status']==1)
8
+$user_id = $userIdViewed;
9
+if ($mainUserInfo['status'] == 1)
10 10
 {
11
-	$course_admin=1;
11
+	$course_admin = 1;
12 12
 }
13 13
 include_once('permissions_functions.inc.php');
14 14
 include_once('all_permissions.inc.php');
@@ -17,9 +17,9 @@  discard block
 block discarded – undo
17 17
 // ---------------------------------------------------
18 18
 // 			ACTIONS
19 19
 // ---------------------------------------------------
20
-if ($_POST['StoreUserPermissions'] and $setting_visualisation=='checkbox')
20
+if ($_POST['StoreUserPermissions'] and $setting_visualisation == 'checkbox')
21 21
 {
22
-	$result_message=store_permissions('user', $user_id);
22
+	$result_message = store_permissions('user', $user_id);
23 23
 	if ($result_message)
24 24
 	{
25 25
 		Display::display_normal_message($result_message);
@@ -27,13 +27,13 @@  discard block
 block discarded – undo
27 27
 }
28 28
 if (isset($_GET['action']))
29 29
 {
30
-	if ( isset($_GET['permission']) AND isset($_GET['tool']) AND ($_GET['action']=='grant' OR $_GET['action']=='revoke'))
30
+	if (isset($_GET['permission']) AND isset($_GET['tool']) AND ($_GET['action'] == 'grant' OR $_GET['action'] == 'revoke'))
31 31
 	{
32
-		$result_message=store_one_permission('user', $_GET['action'], $user_id, $_GET['tool'], $_GET['permission']);
32
+		$result_message = store_one_permission('user', $_GET['action'], $user_id, $_GET['tool'], $_GET['permission']);
33 33
 	}
34
-	if (isset($_GET['role']) AND ($_GET['action']=='grant' OR $_GET['action']=='revoke'))
34
+	if (isset($_GET['role']) AND ($_GET['action'] == 'grant' OR $_GET['action'] == 'revoke'))
35 35
 	{
36
-		$result_message=assign_role('user', $_GET['action'], $user_id, $_GET['role'], $_GET['scope']);
36
+		$result_message = assign_role('user', $_GET['action'], $user_id, $_GET['role'], $_GET['scope']);
37 37
 	}
38 38
 }
39 39
 if (isset($result_message))
@@ -44,33 +44,33 @@  discard block
 block discarded – undo
44 44
 // ---------------------------------------------------
45 45
 // 			RETRIEVING THE PERMISSIONS OF THE USER
46 46
 // ---------------------------------------------------
47
-$current_user_permissions=array();
48
-$current_user_permissions=get_permissions('user',$user_id);
47
+$current_user_permissions = array();
48
+$current_user_permissions = get_permissions('user', $user_id);
49 49
 
50 50
 
51 51
 //   INHERITED PERMISSIONS (group permissions, user roles, group roles)
52 52
 
53 53
 // 			RETRIEVING THE PERMISSIONS OF THE GROUPS OF THE USER
54
-$groups_of_user=array();
55
-$groups_of_user=GroupManager::get_group_ids($_course['real_id'],$user_id);
54
+$groups_of_user = array();
55
+$groups_of_user = GroupManager::get_group_ids($_course['real_id'], $user_id);
56 56
 foreach ($groups_of_user as $group)
57 57
 {
58
-	$this_group_permissions=get_permissions('group',$group);
58
+	$this_group_permissions = get_permissions('group', $group);
59 59
 	foreach ($this_group_permissions as $tool=>$permissions)
60 60
 	{
61 61
 		foreach ($permissions as $permission)
62 62
 		{
63
-			$inherited_group_permissions[$tool][]=$permission;
63
+			$inherited_group_permissions[$tool][] = $permission;
64 64
 		}
65 65
 	}
66 66
 }
67
-$inherited_permissions=$inherited_group_permissions;
67
+$inherited_permissions = $inherited_group_permissions;
68 68
 
69 69
 // 			RETRIEVING THE PERMISSIONS OF THE ROLES OF THE USER
70
-if (api_get_setting('user_roles')=='true') {
70
+if (api_get_setting('user_roles') == 'true') {
71 71
 	// course roles that are assigned to the user
72
-	$current_user_role_permissions_of_user=get_roles_permissions('user',$user_id);
73
-	$inherited_permissions=permission_array_merge($inherited_permissions,$current_user_role_permissions_of_user);
72
+	$current_user_role_permissions_of_user = get_roles_permissions('user', $user_id);
73
+	$inherited_permissions = permission_array_merge($inherited_permissions, $current_user_role_permissions_of_user);
74 74
 	// NOTE: deze array moet nog gemerged worden met de $inherited_permissions array
75 75
 	// (heet momenteel nog $current_group_permissions_of_user omdat voorlopig enkel de
76 76
 	// groepsge�rfde permissions in beschouwing worden genomen
@@ -80,16 +80,16 @@  discard block
 block discarded – undo
80 80
 	// NOTE: checken als de rollen brol wel degelijk geactiveerd is voordat we dit allemaal
81 81
 	// ophalen.
82 82
 	// platform roles that are assigned to the user
83
-	$current_user_role_permissions_of_user=get_roles_permissions('user',$user_id, 'platform');
84
-	$inherited_permissions=permission_array_merge($inherited_permissions,$current_user_role_permissions_of_user);
83
+	$current_user_role_permissions_of_user = get_roles_permissions('user', $user_id, 'platform');
84
+	$inherited_permissions = permission_array_merge($inherited_permissions, $current_user_role_permissions_of_user);
85 85
 }
86 86
 //	RETRIEVING THE PERMISSIONS OF THE ROLES OF THE GROUPS OF THE USER
87
-if (api_get_setting('group_roles')=='true')
87
+if (api_get_setting('group_roles') == 'true')
88 88
 {
89 89
 	// NOTE: DIT MOET NOG VERDER UITGEWERKT WORDEN
90 90
 	foreach ($groups_of_user as $group)
91 91
 	{
92
-		$this_current_group_role_permissions_of_user=get_roles_permissions('user',$user_id);
92
+		$this_current_group_role_permissions_of_user = get_roles_permissions('user', $user_id);
93 93
 		//$inherited_permissions[$tool][]=$permission;
94 94
 	}
95 95
 }
@@ -97,15 +97,15 @@  discard block
 block discarded – undo
97 97
 // ---------------------------------------------------
98 98
 // 			LIMITED OR FULL
99 99
 // ---------------------------------------------------
100
-$current_user_permissions=limited_or_full($current_user_permissions);
101
-$inherited_permissions=limited_or_full($inherited_permissions);
102
-if (api_get_setting('permissions')=='limited')
100
+$current_user_permissions = limited_or_full($current_user_permissions);
101
+$inherited_permissions = limited_or_full($inherited_permissions);
102
+if (api_get_setting('permissions') == 'limited')
103 103
 {
104
-	$header_array=$rights_limited;
104
+	$header_array = $rights_limited;
105 105
 }
106
-if (api_get_setting('permissions')=='full')
106
+if (api_get_setting('permissions') == 'full')
107 107
 {
108
-	$header_array=$rights_full;
108
+	$header_array = $rights_full;
109 109
 }
110 110
 
111 111
 
@@ -114,12 +114,12 @@  discard block
 block discarded – undo
114 114
 // ---------------------------------------------------
115 115
 // 		DISPLAYING THE ROLES LIST
116 116
 // ---------------------------------------------------
117
-if (api_get_setting('user_roles')=='true')
117
+if (api_get_setting('user_roles') == 'true')
118 118
 {
119 119
 	// the list of the roles for the user
120 120
 	echo '<strong>'.get_lang('UserRoles').'</strong><br />';
121
-	$current_user_course_roles=get_roles('user',$user_id);
122
-	$current_user_platform_roles=get_roles('user',$user_id, 'platform');
121
+	$current_user_course_roles = get_roles('user', $user_id);
122
+	$current_user_platform_roles = get_roles('user', $user_id, 'platform');
123 123
 	display_role_list($current_user_course_roles, $current_user_platform_roles);
124 124
 	echo '<br />';
125 125
 }
@@ -144,12 +144,12 @@  discard block
 block discarded – undo
144 144
 {
145 145
 	echo "\t<tr>\n";
146 146
 	echo "\t\t<td>\n";
147
-	if (strstr($tool,'BLOG'))
147
+	if (strstr($tool, 'BLOG'))
148 148
 	{
149 149
 		// Not dealing with a real tool here, get name of this blog
150 150
 		// Strip blog id
151
-		$tmp = strpos($tool,'_')+1;
152
-		$blog_id = substr($tool,$tmp,strlen($tool));
151
+		$tmp = strpos($tool, '_') + 1;
152
+		$blog_id = substr($tool, $tmp, strlen($tool));
153 153
 		// Get title
154 154
 		echo get_lang('Blog').": ".Blog::get_blog_title($blog_id);
155 155
 	}
@@ -164,15 +164,15 @@  discard block
 block discarded – undo
164 164
 	{
165 165
 
166 166
 		echo "\t\t<td align='center'>\n";
167
-		if (in_array($value,$rights))
167
+		if (in_array($value, $rights))
168 168
 		{
169
-			if ($setting_visualisation=='checkbox')
169
+			if ($setting_visualisation == 'checkbox')
170 170
 			{
171
-				display_checkbox_matrix($current_user_permissions, $tool, $value, $inherited_permissions,$course_admin);
171
+				display_checkbox_matrix($current_user_permissions, $tool, $value, $inherited_permissions, $course_admin);
172 172
 			}
173
-			if ($setting_visualisation=='image')
173
+			if ($setting_visualisation == 'image')
174 174
 			{
175
-				display_image_matrix($current_user_permissions, $tool, $value,$inherited_permissions, $course_admin);
175
+				display_image_matrix($current_user_permissions, $tool, $value, $inherited_permissions, $course_admin);
176 176
 			}
177 177
 		}
178 178
 		// note: in a later stage this part will be replaced by a function
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
 }
186 186
 
187 187
 echo "</table>\n";
188
-if ($setting_visualisation=='checkbox')
188
+if ($setting_visualisation == 'checkbox')
189 189
 {
190 190
 	echo "<input type=\"Submit\" name=\"StoreUserPermissions\" value=\"".get_lang('StorePermissions')."\">";
191 191
 }
Please login to merge, or discard this patch.
Braces   +4 added lines, -3 removed lines patch added patch discarded remove patch
@@ -140,9 +140,11 @@  discard block
 block discarded – undo
140 140
 echo "\t</tr>\n";
141 141
 
142 142
 // the main area with the checkboxes or images
143
-foreach ($tool_rights as $tool=>$rights) // $tool_rights contains all the possible tools and their rights
143
+foreach ($tool_rights as $tool=>$rights) {
144
+    // $tool_rights contains all the possible tools and their rights
144 145
 {
145 146
 	echo "\t<tr>\n";
147
+}
146 148
 	echo "\t\t<td>\n";
147 149
 	if (strstr($tool,'BLOG'))
148 150
 	{
@@ -152,8 +154,7 @@  discard block
 block discarded – undo
152 154
 		$blog_id = substr($tool,$tmp,strlen($tool));
153 155
 		// Get title
154 156
 		echo get_lang('Blog').": ".Blog::get_blog_title($blog_id);
155
-	}
156
-	else
157
+	} else
157 158
 	{
158 159
 		echo get_lang($tool);
159 160
 	}
Please login to merge, or discard this patch.
Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 $user_id=$userIdViewed;
9 9
 if ($mainUserInfo['status']==1)
10 10
 {
11
-	$course_admin=1;
11
+    $course_admin=1;
12 12
 }
13 13
 include_once('permissions_functions.inc.php');
14 14
 include_once('all_permissions.inc.php');
@@ -19,26 +19,26 @@  discard block
 block discarded – undo
19 19
 // ---------------------------------------------------
20 20
 if ($_POST['StoreUserPermissions'] and $setting_visualisation=='checkbox')
21 21
 {
22
-	$result_message=store_permissions('user', $user_id);
23
-	if ($result_message)
24
-	{
25
-		Display::display_normal_message($result_message);
26
-	}
22
+    $result_message=store_permissions('user', $user_id);
23
+    if ($result_message)
24
+    {
25
+        Display::display_normal_message($result_message);
26
+    }
27 27
 }
28 28
 if (isset($_GET['action']))
29 29
 {
30
-	if ( isset($_GET['permission']) AND isset($_GET['tool']) AND ($_GET['action']=='grant' OR $_GET['action']=='revoke'))
31
-	{
32
-		$result_message=store_one_permission('user', $_GET['action'], $user_id, $_GET['tool'], $_GET['permission']);
33
-	}
34
-	if (isset($_GET['role']) AND ($_GET['action']=='grant' OR $_GET['action']=='revoke'))
35
-	{
36
-		$result_message=assign_role('user', $_GET['action'], $user_id, $_GET['role'], $_GET['scope']);
37
-	}
30
+    if ( isset($_GET['permission']) AND isset($_GET['tool']) AND ($_GET['action']=='grant' OR $_GET['action']=='revoke'))
31
+    {
32
+        $result_message=store_one_permission('user', $_GET['action'], $user_id, $_GET['tool'], $_GET['permission']);
33
+    }
34
+    if (isset($_GET['role']) AND ($_GET['action']=='grant' OR $_GET['action']=='revoke'))
35
+    {
36
+        $result_message=assign_role('user', $_GET['action'], $user_id, $_GET['role'], $_GET['scope']);
37
+    }
38 38
 }
39 39
 if (isset($result_message))
40 40
 {
41
-	Display::display_normal_message($result_message);
41
+    Display::display_normal_message($result_message);
42 42
 }
43 43
 
44 44
 // ---------------------------------------------------
@@ -55,43 +55,43 @@  discard block
 block discarded – undo
55 55
 $groups_of_user=GroupManager::get_group_ids($_course['real_id'],$user_id);
56 56
 foreach ($groups_of_user as $group)
57 57
 {
58
-	$this_group_permissions=get_permissions('group',$group);
59
-	foreach ($this_group_permissions as $tool=>$permissions)
60
-	{
61
-		foreach ($permissions as $permission)
62
-		{
63
-			$inherited_group_permissions[$tool][]=$permission;
64
-		}
65
-	}
58
+    $this_group_permissions=get_permissions('group',$group);
59
+    foreach ($this_group_permissions as $tool=>$permissions)
60
+    {
61
+        foreach ($permissions as $permission)
62
+        {
63
+            $inherited_group_permissions[$tool][]=$permission;
64
+        }
65
+    }
66 66
 }
67 67
 $inherited_permissions=$inherited_group_permissions;
68 68
 
69 69
 // 			RETRIEVING THE PERMISSIONS OF THE ROLES OF THE USER
70 70
 if (api_get_setting('user_roles')=='true') {
71
-	// course roles that are assigned to the user
72
-	$current_user_role_permissions_of_user=get_roles_permissions('user',$user_id);
73
-	$inherited_permissions=permission_array_merge($inherited_permissions,$current_user_role_permissions_of_user);
74
-	// NOTE: deze array moet nog gemerged worden met de $inherited_permissions array
75
-	// (heet momenteel nog $current_group_permissions_of_user omdat voorlopig enkel de
76
-	// groepsge�rfde permissions in beschouwing worden genomen
77
-	// dit moet ook de rol permissies van rollen die toegekend worden aan een gebruiker
78
-	// en de rol permissies van rollen die toegekend worden aan de groepen van een gebruiker
79
-	// omvatten.
80
-	// NOTE: checken als de rollen brol wel degelijk geactiveerd is voordat we dit allemaal
81
-	// ophalen.
82
-	// platform roles that are assigned to the user
83
-	$current_user_role_permissions_of_user=get_roles_permissions('user',$user_id, 'platform');
84
-	$inherited_permissions=permission_array_merge($inherited_permissions,$current_user_role_permissions_of_user);
71
+    // course roles that are assigned to the user
72
+    $current_user_role_permissions_of_user=get_roles_permissions('user',$user_id);
73
+    $inherited_permissions=permission_array_merge($inherited_permissions,$current_user_role_permissions_of_user);
74
+    // NOTE: deze array moet nog gemerged worden met de $inherited_permissions array
75
+    // (heet momenteel nog $current_group_permissions_of_user omdat voorlopig enkel de
76
+    // groepsge�rfde permissions in beschouwing worden genomen
77
+    // dit moet ook de rol permissies van rollen die toegekend worden aan een gebruiker
78
+    // en de rol permissies van rollen die toegekend worden aan de groepen van een gebruiker
79
+    // omvatten.
80
+    // NOTE: checken als de rollen brol wel degelijk geactiveerd is voordat we dit allemaal
81
+    // ophalen.
82
+    // platform roles that are assigned to the user
83
+    $current_user_role_permissions_of_user=get_roles_permissions('user',$user_id, 'platform');
84
+    $inherited_permissions=permission_array_merge($inherited_permissions,$current_user_role_permissions_of_user);
85 85
 }
86 86
 //	RETRIEVING THE PERMISSIONS OF THE ROLES OF THE GROUPS OF THE USER
87 87
 if (api_get_setting('group_roles')=='true')
88 88
 {
89
-	// NOTE: DIT MOET NOG VERDER UITGEWERKT WORDEN
90
-	foreach ($groups_of_user as $group)
91
-	{
92
-		$this_current_group_role_permissions_of_user=get_roles_permissions('user',$user_id);
93
-		//$inherited_permissions[$tool][]=$permission;
94
-	}
89
+    // NOTE: DIT MOET NOG VERDER UITGEWERKT WORDEN
90
+    foreach ($groups_of_user as $group)
91
+    {
92
+        $this_current_group_role_permissions_of_user=get_roles_permissions('user',$user_id);
93
+        //$inherited_permissions[$tool][]=$permission;
94
+    }
95 95
 }
96 96
 
97 97
 // ---------------------------------------------------
@@ -101,11 +101,11 @@  discard block
 block discarded – undo
101 101
 $inherited_permissions=limited_or_full($inherited_permissions);
102 102
 if (api_get_setting('permissions')=='limited')
103 103
 {
104
-	$header_array=$rights_limited;
104
+    $header_array=$rights_limited;
105 105
 }
106 106
 if (api_get_setting('permissions')=='full')
107 107
 {
108
-	$header_array=$rights_full;
108
+    $header_array=$rights_full;
109 109
 }
110 110
 
111 111
 
@@ -116,12 +116,12 @@  discard block
 block discarded – undo
116 116
 // ---------------------------------------------------
117 117
 if (api_get_setting('user_roles')=='true')
118 118
 {
119
-	// the list of the roles for the user
120
-	echo '<strong>'.get_lang('UserRoles').'</strong><br />';
121
-	$current_user_course_roles=get_roles('user',$user_id);
122
-	$current_user_platform_roles=get_roles('user',$user_id, 'platform');
123
-	display_role_list($current_user_course_roles, $current_user_platform_roles);
124
-	echo '<br />';
119
+    // the list of the roles for the user
120
+    echo '<strong>'.get_lang('UserRoles').'</strong><br />';
121
+    $current_user_course_roles=get_roles('user',$user_id);
122
+    $current_user_platform_roles=get_roles('user',$user_id, 'platform');
123
+    display_role_list($current_user_course_roles, $current_user_platform_roles);
124
+    echo '<br />';
125 125
 }
126 126
 
127 127
 // ---------------------------------------------------
@@ -135,59 +135,59 @@  discard block
 block discarded – undo
135 135
 echo "\t\t<th>".get_lang('Module')."</th>\n";
136 136
 foreach ($header_array as $header_key=>$header_value)
137 137
 {
138
-	echo "\t\t<th>".get_lang($header_value)."</th>\n";
138
+    echo "\t\t<th>".get_lang($header_value)."</th>\n";
139 139
 }
140 140
 echo "\t</tr>\n";
141 141
 
142 142
 // the main area with the checkboxes or images
143 143
 foreach ($tool_rights as $tool=>$rights) // $tool_rights contains all the possible tools and their rights
144 144
 {
145
-	echo "\t<tr>\n";
146
-	echo "\t\t<td>\n";
147
-	if (strstr($tool,'BLOG'))
148
-	{
149
-		// Not dealing with a real tool here, get name of this blog
150
-		// Strip blog id
151
-		$tmp = strpos($tool,'_')+1;
152
-		$blog_id = substr($tool,$tmp,strlen($tool));
153
-		// Get title
154
-		echo get_lang('Blog').": ".Blog::get_blog_title($blog_id);
155
-	}
156
-	else
157
-	{
158
-		echo get_lang($tool);
159
-	}
160
-
161
-	echo "\t\t</td>\n";
162
-
163
-	foreach ($header_array as $key=>$value)
164
-	{
165
-
166
-		echo "\t\t<td align='center'>\n";
167
-		if (in_array($value,$rights))
168
-		{
169
-			if ($setting_visualisation=='checkbox')
170
-			{
171
-				display_checkbox_matrix($current_user_permissions, $tool, $value, $inherited_permissions,$course_admin);
172
-			}
173
-			if ($setting_visualisation=='image')
174
-			{
175
-				display_image_matrix($current_user_permissions, $tool, $value,$inherited_permissions, $course_admin);
176
-			}
177
-		}
178
-		// note: in a later stage this part will be replaced by a function
179
-		// so that we can easily switch between a checkbox approach or an image approach
180
-		// where every click is in fact a change of status. In the checkbox approach you first have to
181
-		// do the changes and then store them by clicking the submit button.
182
-		echo "\t\t</td>\n";
183
-	}
184
-	echo "\t</tr>\n";
145
+    echo "\t<tr>\n";
146
+    echo "\t\t<td>\n";
147
+    if (strstr($tool,'BLOG'))
148
+    {
149
+        // Not dealing with a real tool here, get name of this blog
150
+        // Strip blog id
151
+        $tmp = strpos($tool,'_')+1;
152
+        $blog_id = substr($tool,$tmp,strlen($tool));
153
+        // Get title
154
+        echo get_lang('Blog').": ".Blog::get_blog_title($blog_id);
155
+    }
156
+    else
157
+    {
158
+        echo get_lang($tool);
159
+    }
160
+
161
+    echo "\t\t</td>\n";
162
+
163
+    foreach ($header_array as $key=>$value)
164
+    {
165
+
166
+        echo "\t\t<td align='center'>\n";
167
+        if (in_array($value,$rights))
168
+        {
169
+            if ($setting_visualisation=='checkbox')
170
+            {
171
+                display_checkbox_matrix($current_user_permissions, $tool, $value, $inherited_permissions,$course_admin);
172
+            }
173
+            if ($setting_visualisation=='image')
174
+            {
175
+                display_image_matrix($current_user_permissions, $tool, $value,$inherited_permissions, $course_admin);
176
+            }
177
+        }
178
+        // note: in a later stage this part will be replaced by a function
179
+        // so that we can easily switch between a checkbox approach or an image approach
180
+        // where every click is in fact a change of status. In the checkbox approach you first have to
181
+        // do the changes and then store them by clicking the submit button.
182
+        echo "\t\t</td>\n";
183
+    }
184
+    echo "\t</tr>\n";
185 185
 }
186 186
 
187 187
 echo "</table>\n";
188 188
 if ($setting_visualisation=='checkbox')
189 189
 {
190
-	echo "<input type=\"Submit\" name=\"StoreUserPermissions\" value=\"".get_lang('StorePermissions')."\">";
190
+    echo "<input type=\"Submit\" name=\"StoreUserPermissions\" value=\"".get_lang('StorePermissions')."\">";
191 191
 }
192 192
 echo "</form><br />";
193 193
 
Please login to merge, or discard this patch.
main/permissions/roles.php 3 patches
Indentation   +179 added lines, -179 removed lines patch added patch discarded remove patch
@@ -18,56 +18,56 @@  discard block
 block discarded – undo
18 18
 // storing all the permission for a given role when the checkbox approach is used
19 19
 if ($_POST['StoreRolePermissions'])
20 20
 {
21
-	if (!empty($_POST['role_name']))
22
-	{
23
-		$table_role=Database::get_course_table(TABLE_ROLE);
24
-		$sql="INSERT INTO $table_role (role_name, role_comment, default_role)
21
+    if (!empty($_POST['role_name']))
22
+    {
23
+        $table_role=Database::get_course_table(TABLE_ROLE);
24
+        $sql="INSERT INTO $table_role (role_name, role_comment, default_role)
25 25
 					VALUES ('".Database::escape_string($_POST['role_name'])."','".Database::escape_string($_POST['role_comment'])."','".Database::escape_string($_POST['default_role'])."')";
26
-		$result=Database::query($sql);
27
-		$role_id=Database::insert_id();
28
-		$result_message=store_permissions('role', $role_id);
29
-	}
30
-	else
31
-	{
32
-		$result_message=get_lang('ErrorPleaseGiveRoleName');
33
-	}
26
+        $result=Database::query($sql);
27
+        $role_id=Database::insert_id();
28
+        $result_message=store_permissions('role', $role_id);
29
+    }
30
+    else
31
+    {
32
+        $result_message=get_lang('ErrorPleaseGiveRoleName');
33
+    }
34 34
 }
35 35
 // storing a permission for a given role when the image approach is used
36 36
 if (isset($_GET['action']) AND isset($_GET['permission']) AND isset($_GET['tool']))
37 37
 {
38
-	if ($_GET['action']=='grant' OR $_GET['action']=='revoke')
39
-	{
40
-		$result_message=store_one_permission('role', $_GET['action'], $role_id, $_GET['tool'], $_GET['permission']);
41
-	}
38
+    if ($_GET['action']=='grant' OR $_GET['action']=='revoke')
39
+    {
40
+        $result_message=store_one_permission('role', $_GET['action'], $role_id, $_GET['tool'], $_GET['permission']);
41
+    }
42 42
 }
43 43
 
44 44
 // deleting a role
45 45
 if (isset($_GET['action']) AND isset($_GET['role_id']) AND $_GET['action']=='delete') {
46
-	//deleting the assignments fo this role: users
47
-	$table=Database::get_course_table(TABLE_ROLE_USER);
48
-	$sql="DELETE FROM $table WHERE role_id='".intval($_GET['role_id'])."'";
49
-	$result=Database::query($sql);
46
+    //deleting the assignments fo this role: users
47
+    $table=Database::get_course_table(TABLE_ROLE_USER);
48
+    $sql="DELETE FROM $table WHERE role_id='".intval($_GET['role_id'])."'";
49
+    $result=Database::query($sql);
50 50
 
51
-	// deleting the assignments of this role: groups
52
-	$table=Database::get_course_table(TABLE_ROLE_GROUP);
53
-	$sql="DELETE FROM $table WHERE role_id='".intval($_GET['role_id'])."'";
54
-	$result=Database::query($sql);
51
+    // deleting the assignments of this role: groups
52
+    $table=Database::get_course_table(TABLE_ROLE_GROUP);
53
+    $sql="DELETE FROM $table WHERE role_id='".intval($_GET['role_id'])."'";
54
+    $result=Database::query($sql);
55 55
 
56
-	// deleting the permissions of this role
57
-	$table=Database::get_course_table(TABLE_ROLE_PERMISSION);
58
-	$sql="DELETE FROM $table WHERE role_id='".intval($_GET['role_id'])."'";
59
-	$result=Database::query($sql);
56
+    // deleting the permissions of this role
57
+    $table=Database::get_course_table(TABLE_ROLE_PERMISSION);
58
+    $sql="DELETE FROM $table WHERE role_id='".intval($_GET['role_id'])."'";
59
+    $result=Database::query($sql);
60 60
 
61
-	// deleting the role
62
-	$table_role=Database::get_course_table(TABLE_ROLE);
63
-	$sql="DELETE FROM $table_role WHERE role_id='".intval($_GET['role_id'])."'";
64
-	$result=Database::query($sql);
65
-	$result_message=get_lang('RoleDeleted');
61
+    // deleting the role
62
+    $table_role=Database::get_course_table(TABLE_ROLE);
63
+    $sql="DELETE FROM $table_role WHERE role_id='".intval($_GET['role_id'])."'";
64
+    $result=Database::query($sql);
65
+    $result_message=get_lang('RoleDeleted');
66 66
 }
67 67
 
68 68
 // displaying the return message of the actions
69 69
 if (isset($result_message)) {
70
-	Display::display_normal_message($result_message);
70
+    Display::display_normal_message($result_message);
71 71
 }
72 72
 
73 73
 // 		ADDING A NEW ROLE (FORM AND LINK)
@@ -75,73 +75,73 @@  discard block
 block discarded – undo
75 75
 
76 76
 if ($_GET['action']=='add')
77 77
 {
78
-	echo "<form method=\"post\" action=\"".api_get_self()."\">";
79
-	echo "\n<table>";
80
-	echo "\n\t<tr>";
81
-	echo "\n\t\t<td>";
82
-	echo get_lang('RoleName');
83
-	echo "\n\t\t</td>";
84
-	echo "\n\t\t<td>";
85
-	echo "\n\t\t\t<input type='text' name='role_name'>";
86
-	echo "\n\t\t</td>";
87
-	echo "\n\t</tr>";
88
-	echo "\n\t<tr>";
89
-	echo "\n\t\t<td>";
90
-	echo get_lang('RoleComment');
91
-	echo "\n\t\t</td>";
92
-	echo "\n\t\t<td>";
93
-	echo "\n\t\t\t<textarea name='role_comment'></textarea>";
94
-	echo "\n\t\t</td>";
95
-	echo "\n\t</tr>";
96
-	echo "\n\t<tr>";
97
-	echo "\n\t\t<td>";
98
-	echo get_lang('DefaultRole');
99
-	echo "\n\t\t</td>";
100
-	echo "\n\t\t<td>";
101
-	echo "\n\t\t\t<input type=\"checkbox\" name=\"default_role\" value=\"1\">";
102
-	echo "\n\t\t</td>";
103
-	echo "\n\t</tr>";
104
-	echo "\n</table>";
105
-	echo "<table class=\"data_table\">\n";
78
+    echo "<form method=\"post\" action=\"".api_get_self()."\">";
79
+    echo "\n<table>";
80
+    echo "\n\t<tr>";
81
+    echo "\n\t\t<td>";
82
+    echo get_lang('RoleName');
83
+    echo "\n\t\t</td>";
84
+    echo "\n\t\t<td>";
85
+    echo "\n\t\t\t<input type='text' name='role_name'>";
86
+    echo "\n\t\t</td>";
87
+    echo "\n\t</tr>";
88
+    echo "\n\t<tr>";
89
+    echo "\n\t\t<td>";
90
+    echo get_lang('RoleComment');
91
+    echo "\n\t\t</td>";
92
+    echo "\n\t\t<td>";
93
+    echo "\n\t\t\t<textarea name='role_comment'></textarea>";
94
+    echo "\n\t\t</td>";
95
+    echo "\n\t</tr>";
96
+    echo "\n\t<tr>";
97
+    echo "\n\t\t<td>";
98
+    echo get_lang('DefaultRole');
99
+    echo "\n\t\t</td>";
100
+    echo "\n\t\t<td>";
101
+    echo "\n\t\t\t<input type=\"checkbox\" name=\"default_role\" value=\"1\">";
102
+    echo "\n\t\t</td>";
103
+    echo "\n\t</tr>";
104
+    echo "\n</table>";
105
+    echo "<table class=\"data_table\">\n";
106 106
 
107
-	// the header
108
-	if (api_get_setting('permissions')=='limited')
109
-	{
110
-		$header_array=$rights_limited;
111
-	}
112
-	if (api_get_setting('permissions')=='full')
113
-	{
114
-		$header_array=$rights_full;
115
-	}
116
-	echo "\t<tr>\n";
117
-	echo "\t\t<th>".get_lang('Module')."</th>\n";
118
-	foreach ($header_array as $header_key=>$header_value)
119
-	{
120
-		echo "\t\t<th>".get_lang($header_value)."</th>\n";
121
-	}
122
-	echo "\t</tr>\n";
107
+    // the header
108
+    if (api_get_setting('permissions')=='limited')
109
+    {
110
+        $header_array=$rights_limited;
111
+    }
112
+    if (api_get_setting('permissions')=='full')
113
+    {
114
+        $header_array=$rights_full;
115
+    }
116
+    echo "\t<tr>\n";
117
+    echo "\t\t<th>".get_lang('Module')."</th>\n";
118
+    foreach ($header_array as $header_key=>$header_value)
119
+    {
120
+        echo "\t\t<th>".get_lang($header_value)."</th>\n";
121
+    }
122
+    echo "\t</tr>\n";
123 123
 
124
-	// the main area with the checkboxes or images
125
-	foreach ($tool_rights as $tool=>$rights) // $tool_rights contains all the possible tools and their rights
126
-	{
127
-		echo "\t<tr>\n";
128
-		echo "\t\t<td>\n";
129
-		echo get_lang($tool);
130
-		echo "\t\t</td>\n";
124
+    // the main area with the checkboxes or images
125
+    foreach ($tool_rights as $tool=>$rights) // $tool_rights contains all the possible tools and their rights
126
+    {
127
+        echo "\t<tr>\n";
128
+        echo "\t\t<td>\n";
129
+        echo get_lang($tool);
130
+        echo "\t\t</td>\n";
131 131
 
132
-		foreach ($header_array as $key=>$value)
133
-		{
134
-			echo "\t\t<td align='center'>\n";
135
-			display_checkbox_matrix(array(), $tool, $value);
136
-			echo "\t\t</td>\n";
137
-		}
138
-		echo "\t</tr>\n";
139
-	}
132
+        foreach ($header_array as $key=>$value)
133
+        {
134
+            echo "\t\t<td align='center'>\n";
135
+            display_checkbox_matrix(array(), $tool, $value);
136
+            echo "\t\t</td>\n";
137
+        }
138
+        echo "\t</tr>\n";
139
+    }
140 140
 
141
-	echo "</table>\n";
141
+    echo "</table>\n";
142 142
 
143
-	echo "<input type=\"Submit\" name=\"StoreRolePermissions\" value=\"".get_lang('StorePermissions')."\">";
144
-	echo "</form>";
143
+    echo "<input type=\"Submit\" name=\"StoreRolePermissions\" value=\"".get_lang('StorePermissions')."\">";
144
+    echo "</form>";
145 145
 
146 146
 }
147 147
 
@@ -154,23 +154,23 @@  discard block
 block discarded – undo
154 154
 $all_roles=get_all_roles('platform');
155 155
 foreach ($all_roles as $role)
156 156
 {
157
-	echo '<div><a href="roles.php?action=view&amp;role_id='.$role['role_id'].'&amp;scope=platform">'.$role['role_name'].'</a></div>';
158
-	echo '<div>'.$role['role_comment'].'</div><br />';
159
-	if ($role['role_id']==$_GET['role_id'])
160
-	{
161
-		$current_role_info=$role;
162
-	}
157
+    echo '<div><a href="roles.php?action=view&amp;role_id='.$role['role_id'].'&amp;scope=platform">'.$role['role_name'].'</a></div>';
158
+    echo '<div>'.$role['role_comment'].'</div><br />';
159
+    if ($role['role_id']==$_GET['role_id'])
160
+    {
161
+        $current_role_info=$role;
162
+    }
163 163
 }
164 164
 // course roles
165 165
 $all_roles=get_all_roles();
166 166
 foreach ($all_roles as $role)
167 167
 {
168
-	echo '<div><a href="roles.php?action=view&amp;role_id='.$role['role_id'].'">'.$role['role_name'].'</a><a href="roles.php?action=delete&amp;role_id='.$role['role_id'].'"><img src="../img/delete.gif" /></a></div>';
169
-	echo '<div>'.$role['role_comment'].'</div><br />';
170
-	if ($role['role_id']==$_GET['role_id'])
171
-	{
172
-		$current_role_info=$role;
173
-	}
168
+    echo '<div><a href="roles.php?action=view&amp;role_id='.$role['role_id'].'">'.$role['role_name'].'</a><a href="roles.php?action=delete&amp;role_id='.$role['role_id'].'"><img src="../img/delete.gif" /></a></div>';
169
+    echo '<div>'.$role['role_comment'].'</div><br />';
170
+    if ($role['role_id']==$_GET['role_id'])
171
+    {
172
+        $current_role_info=$role;
173
+    }
174 174
 }
175 175
 
176 176
 // ===================================================
@@ -178,83 +178,83 @@  discard block
 block discarded – undo
178 178
 // ===================================================
179 179
 if ($_GET['role_id'])
180 180
 {
181
-	$current_role_permissions=get_permissions('role',$_GET['role_id']);
181
+    $current_role_permissions=get_permissions('role',$_GET['role_id']);
182 182
 
183
-	// ---------------------------------------------------
184
-	// 			LIMITED OR FULL
185
-	// ---------------------------------------------------
186
-	$current_role_permissions=limited_or_full($current_role_permissions);
187
-	if (api_get_setting('permissions')=='limited')
188
-	{
189
-		$header_array=$rights_limited;
190
-	}
191
-	if (api_get_setting('permissions')=='full')
192
-	{
193
-		$header_array=$rights_full;
194
-	}
195
-	// ---------------------------------------------------
196
-	// 			DISPLAYING THE MATRIX
197
-	// ---------------------------------------------------
198
-	echo "<form method=\"post\" action=\"".str_replace('&', '&amp;', $_SERVER['REQUEST_URI'])."\">";
183
+    // ---------------------------------------------------
184
+    // 			LIMITED OR FULL
185
+    // ---------------------------------------------------
186
+    $current_role_permissions=limited_or_full($current_role_permissions);
187
+    if (api_get_setting('permissions')=='limited')
188
+    {
189
+        $header_array=$rights_limited;
190
+    }
191
+    if (api_get_setting('permissions')=='full')
192
+    {
193
+        $header_array=$rights_full;
194
+    }
195
+    // ---------------------------------------------------
196
+    // 			DISPLAYING THE MATRIX
197
+    // ---------------------------------------------------
198
+    echo "<form method=\"post\" action=\"".str_replace('&', '&amp;', $_SERVER['REQUEST_URI'])."\">";
199 199
 
200
-	// the list of the roles for the user
201
-	echo get_lang('PermissionsOfRole').':'.$current_role_info['role_name'].'<br />';
202
-	if ($_GET['scope']=='platform')
203
-	{
204
-		echo get_lang('IsPlatformRoleNotEditable').'<br />';
205
-	}
200
+    // the list of the roles for the user
201
+    echo get_lang('PermissionsOfRole').':'.$current_role_info['role_name'].'<br />';
202
+    if ($_GET['scope']=='platform')
203
+    {
204
+        echo get_lang('IsPlatformRoleNotEditable').'<br />';
205
+    }
206 206
 
207
-	echo "<table class=\"data_table\">\n";
207
+    echo "<table class=\"data_table\">\n";
208 208
 
209
-	// the header
210
-	echo "\t<tr>\n";
211
-	echo "\t\t<th>".get_lang('Module')."</th>\n";
212
-	foreach ($header_array as $header_key=>$header_value)
213
-	{
214
-		echo "\t\t<th>".get_lang($header_value)."</th>\n";
215
-	}
216
-	echo "\t</tr>\n";
209
+    // the header
210
+    echo "\t<tr>\n";
211
+    echo "\t\t<th>".get_lang('Module')."</th>\n";
212
+    foreach ($header_array as $header_key=>$header_value)
213
+    {
214
+        echo "\t\t<th>".get_lang($header_value)."</th>\n";
215
+    }
216
+    echo "\t</tr>\n";
217 217
 
218
-	// the main area with the checkboxes or images
219
-	foreach ($tool_rights as $tool=>$rights) // $tool_rights contains all the possible tools and their rights
220
-	{
221
-		echo "\t<tr>\n";
222
-		echo "\t\t<td>\n";
223
-		echo get_lang($tool);
224
-		echo "\t\t</td>\n";
218
+    // the main area with the checkboxes or images
219
+    foreach ($tool_rights as $tool=>$rights) // $tool_rights contains all the possible tools and their rights
220
+    {
221
+        echo "\t<tr>\n";
222
+        echo "\t\t<td>\n";
223
+        echo get_lang($tool);
224
+        echo "\t\t</td>\n";
225 225
 
226
-		foreach ($header_array as $key=>$value)
227
-		{
228
-			echo "\t\t<td align='center'>\n";
229
-			if (in_array($value,$rights))
230
-			{
231
-				if ($setting_visualisation=='checkbox')
232
-				{
233
-					display_checkbox_matrix($current_role_permissions, $tool, $value);
234
-				}
235
-				if ($setting_visualisation=='image')
236
-				{
237
-					if ($_GET['scope']=='platform')
238
-					{
239
-						$roles_editable=false;
240
-					}
241
-					else
242
-					{
243
-						$roles_editable=true;
244
-					}
245
-					display_image_matrix($current_role_permissions, $tool, $value, '','',$roles_editable);
246
-				}
247
-			}
248
-			echo "\t\t</td>\n";
249
-		}
250
-		echo "\t</tr>\n";
251
-	}
226
+        foreach ($header_array as $key=>$value)
227
+        {
228
+            echo "\t\t<td align='center'>\n";
229
+            if (in_array($value,$rights))
230
+            {
231
+                if ($setting_visualisation=='checkbox')
232
+                {
233
+                    display_checkbox_matrix($current_role_permissions, $tool, $value);
234
+                }
235
+                if ($setting_visualisation=='image')
236
+                {
237
+                    if ($_GET['scope']=='platform')
238
+                    {
239
+                        $roles_editable=false;
240
+                    }
241
+                    else
242
+                    {
243
+                        $roles_editable=true;
244
+                    }
245
+                    display_image_matrix($current_role_permissions, $tool, $value, '','',$roles_editable);
246
+                }
247
+            }
248
+            echo "\t\t</td>\n";
249
+        }
250
+        echo "\t</tr>\n";
251
+    }
252 252
 
253
-	echo "</table>\n";
254
-	if ($setting_visualisation=='checkbox')
255
-	{
256
-		echo "<input type=\"Submit\" name=\"StoreRolePermissions\" value=\"".get_lang('StorePermissions')."\">";
257
-	}
258
-	echo "</form>";
253
+    echo "</table>\n";
254
+    if ($setting_visualisation=='checkbox')
255
+    {
256
+        echo "<input type=\"Submit\" name=\"StoreRolePermissions\" value=\"".get_lang('StorePermissions')."\">";
257
+    }
258
+    echo "</form>";
259 259
 }
260 260
 Display::display_footer();
261 261
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -20,49 +20,49 @@  discard block
 block discarded – undo
20 20
 {
21 21
 	if (!empty($_POST['role_name']))
22 22
 	{
23
-		$table_role=Database::get_course_table(TABLE_ROLE);
24
-		$sql="INSERT INTO $table_role (role_name, role_comment, default_role)
23
+		$table_role = Database::get_course_table(TABLE_ROLE);
24
+		$sql = "INSERT INTO $table_role (role_name, role_comment, default_role)
25 25
 					VALUES ('".Database::escape_string($_POST['role_name'])."','".Database::escape_string($_POST['role_comment'])."','".Database::escape_string($_POST['default_role'])."')";
26
-		$result=Database::query($sql);
27
-		$role_id=Database::insert_id();
28
-		$result_message=store_permissions('role', $role_id);
26
+		$result = Database::query($sql);
27
+		$role_id = Database::insert_id();
28
+		$result_message = store_permissions('role', $role_id);
29 29
 	}
30 30
 	else
31 31
 	{
32
-		$result_message=get_lang('ErrorPleaseGiveRoleName');
32
+		$result_message = get_lang('ErrorPleaseGiveRoleName');
33 33
 	}
34 34
 }
35 35
 // storing a permission for a given role when the image approach is used
36 36
 if (isset($_GET['action']) AND isset($_GET['permission']) AND isset($_GET['tool']))
37 37
 {
38
-	if ($_GET['action']=='grant' OR $_GET['action']=='revoke')
38
+	if ($_GET['action'] == 'grant' OR $_GET['action'] == 'revoke')
39 39
 	{
40
-		$result_message=store_one_permission('role', $_GET['action'], $role_id, $_GET['tool'], $_GET['permission']);
40
+		$result_message = store_one_permission('role', $_GET['action'], $role_id, $_GET['tool'], $_GET['permission']);
41 41
 	}
42 42
 }
43 43
 
44 44
 // deleting a role
45
-if (isset($_GET['action']) AND isset($_GET['role_id']) AND $_GET['action']=='delete') {
45
+if (isset($_GET['action']) AND isset($_GET['role_id']) AND $_GET['action'] == 'delete') {
46 46
 	//deleting the assignments fo this role: users
47
-	$table=Database::get_course_table(TABLE_ROLE_USER);
48
-	$sql="DELETE FROM $table WHERE role_id='".intval($_GET['role_id'])."'";
49
-	$result=Database::query($sql);
47
+	$table = Database::get_course_table(TABLE_ROLE_USER);
48
+	$sql = "DELETE FROM $table WHERE role_id='".intval($_GET['role_id'])."'";
49
+	$result = Database::query($sql);
50 50
 
51 51
 	// deleting the assignments of this role: groups
52
-	$table=Database::get_course_table(TABLE_ROLE_GROUP);
53
-	$sql="DELETE FROM $table WHERE role_id='".intval($_GET['role_id'])."'";
54
-	$result=Database::query($sql);
52
+	$table = Database::get_course_table(TABLE_ROLE_GROUP);
53
+	$sql = "DELETE FROM $table WHERE role_id='".intval($_GET['role_id'])."'";
54
+	$result = Database::query($sql);
55 55
 
56 56
 	// deleting the permissions of this role
57
-	$table=Database::get_course_table(TABLE_ROLE_PERMISSION);
58
-	$sql="DELETE FROM $table WHERE role_id='".intval($_GET['role_id'])."'";
59
-	$result=Database::query($sql);
57
+	$table = Database::get_course_table(TABLE_ROLE_PERMISSION);
58
+	$sql = "DELETE FROM $table WHERE role_id='".intval($_GET['role_id'])."'";
59
+	$result = Database::query($sql);
60 60
 
61 61
 	// deleting the role
62
-	$table_role=Database::get_course_table(TABLE_ROLE);
63
-	$sql="DELETE FROM $table_role WHERE role_id='".intval($_GET['role_id'])."'";
64
-	$result=Database::query($sql);
65
-	$result_message=get_lang('RoleDeleted');
62
+	$table_role = Database::get_course_table(TABLE_ROLE);
63
+	$sql = "DELETE FROM $table_role WHERE role_id='".intval($_GET['role_id'])."'";
64
+	$result = Database::query($sql);
65
+	$result_message = get_lang('RoleDeleted');
66 66
 }
67 67
 
68 68
 // displaying the return message of the actions
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 // 		ADDING A NEW ROLE (FORM AND LINK)
74 74
 echo '<img src="../img/add.png" /> <a href="roles.php?action=add">'.get_lang('AddRole').'</a>';
75 75
 
76
-if ($_GET['action']=='add')
76
+if ($_GET['action'] == 'add')
77 77
 {
78 78
 	echo "<form method=\"post\" action=\"".api_get_self()."\">";
79 79
 	echo "\n<table>";
@@ -105,13 +105,13 @@  discard block
 block discarded – undo
105 105
 	echo "<table class=\"data_table\">\n";
106 106
 
107 107
 	// the header
108
-	if (api_get_setting('permissions')=='limited')
108
+	if (api_get_setting('permissions') == 'limited')
109 109
 	{
110
-		$header_array=$rights_limited;
110
+		$header_array = $rights_limited;
111 111
 	}
112
-	if (api_get_setting('permissions')=='full')
112
+	if (api_get_setting('permissions') == 'full')
113 113
 	{
114
-		$header_array=$rights_full;
114
+		$header_array = $rights_full;
115 115
 	}
116 116
 	echo "\t<tr>\n";
117 117
 	echo "\t\t<th>".get_lang('Module')."</th>\n";
@@ -151,25 +151,25 @@  discard block
 block discarded – undo
151 151
 // 		DISPLAYING THE EXISTING ROLES
152 152
 // ===================================================
153 153
 // platform roles
154
-$all_roles=get_all_roles('platform');
154
+$all_roles = get_all_roles('platform');
155 155
 foreach ($all_roles as $role)
156 156
 {
157 157
 	echo '<div><a href="roles.php?action=view&amp;role_id='.$role['role_id'].'&amp;scope=platform">'.$role['role_name'].'</a></div>';
158 158
 	echo '<div>'.$role['role_comment'].'</div><br />';
159
-	if ($role['role_id']==$_GET['role_id'])
159
+	if ($role['role_id'] == $_GET['role_id'])
160 160
 	{
161
-		$current_role_info=$role;
161
+		$current_role_info = $role;
162 162
 	}
163 163
 }
164 164
 // course roles
165
-$all_roles=get_all_roles();
165
+$all_roles = get_all_roles();
166 166
 foreach ($all_roles as $role)
167 167
 {
168 168
 	echo '<div><a href="roles.php?action=view&amp;role_id='.$role['role_id'].'">'.$role['role_name'].'</a><a href="roles.php?action=delete&amp;role_id='.$role['role_id'].'"><img src="../img/delete.gif" /></a></div>';
169 169
 	echo '<div>'.$role['role_comment'].'</div><br />';
170
-	if ($role['role_id']==$_GET['role_id'])
170
+	if ($role['role_id'] == $_GET['role_id'])
171 171
 	{
172
-		$current_role_info=$role;
172
+		$current_role_info = $role;
173 173
 	}
174 174
 }
175 175
 
@@ -178,19 +178,19 @@  discard block
 block discarded – undo
178 178
 // ===================================================
179 179
 if ($_GET['role_id'])
180 180
 {
181
-	$current_role_permissions=get_permissions('role',$_GET['role_id']);
181
+	$current_role_permissions = get_permissions('role', $_GET['role_id']);
182 182
 
183 183
 	// ---------------------------------------------------
184 184
 	// 			LIMITED OR FULL
185 185
 	// ---------------------------------------------------
186
-	$current_role_permissions=limited_or_full($current_role_permissions);
187
-	if (api_get_setting('permissions')=='limited')
186
+	$current_role_permissions = limited_or_full($current_role_permissions);
187
+	if (api_get_setting('permissions') == 'limited')
188 188
 	{
189
-		$header_array=$rights_limited;
189
+		$header_array = $rights_limited;
190 190
 	}
191
-	if (api_get_setting('permissions')=='full')
191
+	if (api_get_setting('permissions') == 'full')
192 192
 	{
193
-		$header_array=$rights_full;
193
+		$header_array = $rights_full;
194 194
 	}
195 195
 	// ---------------------------------------------------
196 196
 	// 			DISPLAYING THE MATRIX
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 
200 200
 	// the list of the roles for the user
201 201
 	echo get_lang('PermissionsOfRole').':'.$current_role_info['role_name'].'<br />';
202
-	if ($_GET['scope']=='platform')
202
+	if ($_GET['scope'] == 'platform')
203 203
 	{
204 204
 		echo get_lang('IsPlatformRoleNotEditable').'<br />';
205 205
 	}
@@ -226,23 +226,23 @@  discard block
 block discarded – undo
226 226
 		foreach ($header_array as $key=>$value)
227 227
 		{
228 228
 			echo "\t\t<td align='center'>\n";
229
-			if (in_array($value,$rights))
229
+			if (in_array($value, $rights))
230 230
 			{
231
-				if ($setting_visualisation=='checkbox')
231
+				if ($setting_visualisation == 'checkbox')
232 232
 				{
233 233
 					display_checkbox_matrix($current_role_permissions, $tool, $value);
234 234
 				}
235
-				if ($setting_visualisation=='image')
235
+				if ($setting_visualisation == 'image')
236 236
 				{
237
-					if ($_GET['scope']=='platform')
237
+					if ($_GET['scope'] == 'platform')
238 238
 					{
239
-						$roles_editable=false;
239
+						$roles_editable = false;
240 240
 					}
241 241
 					else
242 242
 					{
243
-						$roles_editable=true;
243
+						$roles_editable = true;
244 244
 					}
245
-					display_image_matrix($current_role_permissions, $tool, $value, '','',$roles_editable);
245
+					display_image_matrix($current_role_permissions, $tool, $value, '', '', $roles_editable);
246 246
 				}
247 247
 			}
248 248
 			echo "\t\t</td>\n";
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 	}
252 252
 
253 253
 	echo "</table>\n";
254
-	if ($setting_visualisation=='checkbox')
254
+	if ($setting_visualisation == 'checkbox')
255 255
 	{
256 256
 		echo "<input type=\"Submit\" name=\"StoreRolePermissions\" value=\"".get_lang('StorePermissions')."\">";
257 257
 	}
Please login to merge, or discard this patch.
Braces   +8 added lines, -6 removed lines patch added patch discarded remove patch
@@ -26,8 +26,7 @@  discard block
 block discarded – undo
26 26
 		$result=Database::query($sql);
27 27
 		$role_id=Database::insert_id();
28 28
 		$result_message=store_permissions('role', $role_id);
29
-	}
30
-	else
29
+	} else
31 30
 	{
32 31
 		$result_message=get_lang('ErrorPleaseGiveRoleName');
33 32
 	}
@@ -122,9 +121,11 @@  discard block
 block discarded – undo
122 121
 	echo "\t</tr>\n";
123 122
 
124 123
 	// the main area with the checkboxes or images
125
-	foreach ($tool_rights as $tool=>$rights) // $tool_rights contains all the possible tools and their rights
124
+	foreach ($tool_rights as $tool=>$rights) {
125
+	    // $tool_rights contains all the possible tools and their rights
126 126
 	{
127 127
 		echo "\t<tr>\n";
128
+	}
128 129
 		echo "\t\t<td>\n";
129 130
 		echo get_lang($tool);
130 131
 		echo "\t\t</td>\n";
@@ -216,9 +217,11 @@  discard block
 block discarded – undo
216 217
 	echo "\t</tr>\n";
217 218
 
218 219
 	// the main area with the checkboxes or images
219
-	foreach ($tool_rights as $tool=>$rights) // $tool_rights contains all the possible tools and their rights
220
+	foreach ($tool_rights as $tool=>$rights) {
221
+	    // $tool_rights contains all the possible tools and their rights
220 222
 	{
221 223
 		echo "\t<tr>\n";
224
+	}
222 225
 		echo "\t\t<td>\n";
223 226
 		echo get_lang($tool);
224 227
 		echo "\t\t</td>\n";
@@ -237,8 +240,7 @@  discard block
 block discarded – undo
237 240
 					if ($_GET['scope']=='platform')
238 241
 					{
239 242
 						$roles_editable=false;
240
-					}
241
-					else
243
+					} else
242 244
 					{
243 245
 						$roles_editable=true;
244 246
 					}
Please login to merge, or discard this patch.
main/webservices/webservice_course.php 2 patches
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 	 */
22 22
 	protected function deleteCourseHelper($course_id_field_name, $course_id_value) {
23 23
 		$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
24
-		if($course_id instanceof WSError) {
24
+		if ($course_id instanceof WSError) {
25 25
 			return $course_id;
26 26
 		} else {
27 27
 			$course_code = CourseManager::get_course_code_from_course_id($course_id);
@@ -39,11 +39,11 @@  discard block
 block discarded – undo
39 39
 	 */
40 40
 	public function DeleteCourse($secret_key, $course_id_field_name, $course_id_value) {
41 41
 		$verifKey = $this->verifyKey($secret_key);
42
-		if($verifKey instanceof WSError) {
42
+		if ($verifKey instanceof WSError) {
43 43
 			$this->handleError($verifKey);
44 44
 		} else {
45 45
 			$result = $this->deleteCourseHelper($course_id_field_name, $course_id_value);
46
-			if($result instanceof WSError) {
46
+			if ($result instanceof WSError) {
47 47
 				$this->handleError($result);
48 48
 			}
49 49
 		}
@@ -59,15 +59,15 @@  discard block
 block discarded – undo
59 59
 	 */
60 60
 	public function DeleteCourses($secret_key, $courses) {
61 61
 		$verifKey = $this->verifyKey($secret_key);
62
-		if($verifKey instanceof WSError) {
62
+		if ($verifKey instanceof WSError) {
63 63
 			$this->handleError($verifKey);
64 64
 		} else {
65 65
 			$results = array();
66
-			foreach($courses as $course) {
66
+			foreach ($courses as $course) {
67 67
 				$result_tmp = array();
68 68
 				$result_op = $this->deleteCourseHelper($course['course_id_field_name'], $course['course_id_value']);
69 69
 				$result_tmp['course_id_value'] = $course['course_id_value'];
70
-				if($result_op instanceof WSError) {
70
+				if ($result_op instanceof WSError) {
71 71
 					// Return the error in the results
72 72
 					$result_tmp['result'] = $result_op->toArray();
73 73
 				} else {
@@ -97,17 +97,17 @@  discard block
 block discarded – undo
97 97
 	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) {
98 98
 		// Add the original course id field name and value to the extra fields if needed
99 99
 		$extras_associative = array();
100
-		if($course_id_field_name != "chamilo_course_id") {
100
+		if ($course_id_field_name != "chamilo_course_id") {
101 101
 			$extras_associative[$course_id_field_name] = $course_id_value;
102 102
 		}
103
-		foreach($extras as $extra) {
103
+		foreach ($extras as $extra) {
104 104
 			$extras_associative[$extra['field_name']] = $extra['field_value'];
105 105
 		}
106 106
 		$course_admin_id = $this->getUserId($course_admin_user_id_field_name, $course_admin_user_id_value);
107
-		if($course_admin_id instanceof WSError) {
107
+		if ($course_admin_id instanceof WSError) {
108 108
 			return $course_admin_id;
109 109
 		}
110
-		if($wanted_code == '') {
110
+		if ($wanted_code == '') {
111 111
 			$wanted_code = CourseManager::generate_course_code($title);
112 112
 		}
113 113
 		$result = create_course($wanted_code, $title, $tutor_name, $category_code, $language, $course_admin_id, $this->_configuration['db_prefix'], 0);
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 			return new WSError(202, 'There was an error creating the course');
116 116
 		} else {
117 117
 			// Update extra fields
118
-			foreach($extras_associative as $fname => $fvalue) {
118
+			foreach ($extras_associative as $fname => $fvalue) {
119 119
 				CourseManager::update_course_extra_field_value($result, $fname, $fvalue);
120 120
 			}
121 121
 			// Get course id
@@ -143,11 +143,11 @@  discard block
 block discarded – undo
143 143
 	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) {
144 144
 		// First, verify the secret key
145 145
 		$verifKey = $this->verifyKey($secret_key);
146
-		if($verifKey instanceof WSError) {
146
+		if ($verifKey instanceof WSError) {
147 147
 			$this->handleError($verifKey);
148 148
 		} else {
149 149
 			$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);
150
-			if($result instanceof WSError) {
150
+			if ($result instanceof WSError) {
151 151
 				$this->handleError($result);
152 152
 			} else {
153 153
 				return $result;
@@ -165,17 +165,17 @@  discard block
 block discarded – undo
165 165
 	public function CreateCourses($secret_key, $courses) {
166 166
 		// First, verify the secret key
167 167
 		$verifKey = $this->verifyKey($secret_key);
168
-		if($verifKey instanceof WSError) {
168
+		if ($verifKey instanceof WSError) {
169 169
 			$this->handleError($verifKey);
170 170
 		} else {
171 171
 			$results = array();
172
-			foreach($courses as $course) {
172
+			foreach ($courses as $course) {
173 173
 				$result_tmp = array();
174 174
                 // re-initialize variables just in case
175 175
                 $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 = 0;
176 176
 				extract($course);
177 177
 				$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);
178
-				if($result instanceof WSError) {
178
+				if ($result instanceof WSError) {
179 179
 					$result_tmp['result'] = $result->toArray();
180 180
 					$result_tmp['course_id_value'] = $course_id_value;
181 181
 					$result_tmp['course_id_generated'] = 0;
@@ -209,47 +209,47 @@  discard block
 block discarded – undo
209 209
 	 */
210 210
 	protected function editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) {
211 211
 		$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
212
-		if($course_id instanceof WSError) {
212
+		if ($course_id instanceof WSError) {
213 213
 			return $course_id;
214 214
 		} else {
215 215
 			$attributes = array();
216
-			if(!is_empty($title)) {
216
+			if (!is_empty($title)) {
217 217
 				$attributes['title'] = $title;
218 218
 			}
219
-			if(!is_empty($category_code)) {
219
+			if (!is_empty($category_code)) {
220 220
 				$attributes['category_code'] = $category_code;
221 221
 			}
222
-			if(!is_empty($department_name)) {
222
+			if (!is_empty($department_name)) {
223 223
 				$attributes['department_name'] = $department_name;
224 224
 			}
225
-			if(!is_empty($department_url)) {
225
+			if (!is_empty($department_url)) {
226 226
 				$attributes['department_url'] = $department_url;
227 227
 			}
228
-			if(!is_empty($language)) {
228
+			if (!is_empty($language)) {
229 229
 				$attributes['course_language'] = $language;
230 230
 			}
231
-			if($visibility != '') {
232
-				$attributes['visibility'] = (int)$visibility;
231
+			if ($visibility != '') {
232
+				$attributes['visibility'] = (int) $visibility;
233 233
 			}
234
-			if($subscribe != '') {
235
-				$attributes['subscribe'] = (int)$subscribe;
234
+			if ($subscribe != '') {
235
+				$attributes['subscribe'] = (int) $subscribe;
236 236
 			}
237
-			if($unsubscribe != '') {
238
-				$attributes['unsubscribe'] = (int)$unsubscribe;
237
+			if ($unsubscribe != '') {
238
+				$attributes['unsubscribe'] = (int) $unsubscribe;
239 239
 			}
240
-			if(!is_empty($visual_code)) {
240
+			if (!is_empty($visual_code)) {
241 241
 				$attributes['visual_code'] = $visual_code;
242 242
 			}
243
-			if(!is_empty($attributes)) {
243
+			if (!is_empty($attributes)) {
244 244
 				CourseManager::update_attributes($course_id, $attributes);
245 245
 			}
246
-			if(!empty($extras)) {
246
+			if (!empty($extras)) {
247 247
 				$course_code = CourseManager::get_course_code_from_course_id($course_id);
248 248
 				$extras_associative = array();
249
-				foreach($extras as $extra) {
249
+				foreach ($extras as $extra) {
250 250
 					$extras_associative[$extra['field_name']] = $extra['field_value'];
251 251
 				}
252
-				foreach($extras_associative as $fname => $fvalue) {
252
+				foreach ($extras_associative as $fname => $fvalue) {
253 253
 					CourseManager::update_extra_field_value($course_code, $fname, $fvalue);
254 254
 				}
255 255
 			}
@@ -276,11 +276,11 @@  discard block
 block discarded – undo
276 276
 	 */
277 277
 	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) {
278 278
 		$verifKey = $this->verifyKey($secret_key);
279
-		if($verifKey instanceof WSError) {
279
+		if ($verifKey instanceof WSError) {
280 280
 			$this->handleError($verifKey);
281 281
 		} else {
282 282
 			$result = $this->editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras);
283
-			if($result instanceof WSError) {
283
+			if ($result instanceof WSError) {
284 284
 				$this->handleError($result);
285 285
 			}
286 286
 		}
@@ -296,10 +296,10 @@  discard block
 block discarded – undo
296 296
 	 */
297 297
 	public function ListCourses($secret_key, $visibility = 'public,public-registered,private,closed') {
298 298
 		$verifKey = $this->verifyKey($secret_key);
299
-		if($verifKey instanceof WSError) {
299
+		if ($verifKey instanceof WSError) {
300 300
 			$this->handleError($verifKey);
301 301
 		} else {
302
-            $visibilities = split(',',$visibility);
302
+            $visibilities = split(',', $visibility);
303 303
             $vis = array('public' => '3', 'public-registered' => '2', 'private' => '1', 'closed' => '0');
304 304
             foreach ($visibilities as $p => $visibility) {
305 305
                 $visibilities[$p] = $vis[$visibility];
@@ -308,9 +308,9 @@  discard block
 block discarded – undo
308 308
 			$category_names = array();
309 309
 
310 310
 			$courses = CourseManager::get_courses_list();
311
-			foreach($courses as $course) {
311
+			foreach ($courses as $course) {
312 312
                 //skip elements that do not match required visibility
313
-                if (!in_array($course['visibility'],$visibilities)) { continue; }
313
+                if (!in_array($course['visibility'], $visibilities)) { continue; }
314 314
 				$course_tmp = array();
315 315
 				$course_tmp['id'] = $course['id'];
316 316
 				$course_tmp['code'] = $course['code'];
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
 				$course_tmp['visibility'] = $course['visibility'];
320 320
 
321 321
 				// Determining category name
322
-				if($category_names[$course['category_code']]) {
322
+				if ($category_names[$course['category_code']]) {
323 323
 					$course_tmp['category_name'] = $category_names[$course['category_code']];
324 324
 				} else {
325 325
 					$category = CourseManager::get_course_category($course['category_code']);
@@ -355,21 +355,21 @@  discard block
 block discarded – undo
355 355
 	 */
356 356
 	protected function changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $state, $status = STUDENT) {
357 357
 		$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
358
-		if($course_id instanceof WSError) {
358
+		if ($course_id instanceof WSError) {
359 359
 			return $course_id;
360 360
 		} else {
361 361
 			$user_id = $this->getUserId($user_id_field_name, $user_id_value);
362
-			if($user_id instanceof WSError) {
362
+			if ($user_id instanceof WSError) {
363 363
 				return $user_id;
364 364
 			} else {
365 365
 				$course_code = CourseManager::get_course_code_from_course_id($course_id);
366
-				if($state == 0) {
366
+				if ($state == 0) {
367 367
 					// Unsubscribe user
368 368
 					CourseManager::unsubscribe_user($user_id, $course_code);
369 369
 					return true;
370 370
 				} else {
371 371
 					// Subscribe user
372
-					if(CourseManager::subscribe_user($user_id, $course_code, $status)) {
372
+					if (CourseManager::subscribe_user($user_id, $course_code, $status)) {
373 373
 						return true;
374 374
 					} else {
375 375
 						return new WSError(203, 'An error occured subscribing to this course');
@@ -391,11 +391,11 @@  discard block
 block discarded – undo
391 391
 	 */
392 392
 	public function SubscribeUserToCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $status) {
393 393
 		$verifKey = $this->verifyKey($secret_key);
394
-		if($verifKey instanceof WSError) {
394
+		if ($verifKey instanceof WSError) {
395 395
 			$this->handleError($verifKey);
396 396
 		} else {
397 397
 			$result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 1, $status);
398
-			if($result instanceof WSError) {
398
+			if ($result instanceof WSError) {
399 399
 				$this->handleError($result);
400 400
 			}
401 401
 		}
@@ -412,11 +412,11 @@  discard block
 block discarded – undo
412 412
 	 */
413 413
 	public function UnsubscribeUserFromCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value) {
414 414
 		$verifKey = $this->verifyKey($secret_key);
415
-		if($verifKey instanceof WSError) {
415
+		if ($verifKey instanceof WSError) {
416 416
 			$this->handleError($verifKey);
417 417
 		} else {
418 418
 			$result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 0);
419
-			if($result instanceof WSError) {
419
+			if ($result instanceof WSError) {
420 420
 				$this->handleError($result);
421 421
 			}
422 422
 		}
@@ -432,17 +432,17 @@  discard block
 block discarded – undo
432 432
 	 */
433 433
 	public function GetCourseDescriptions($secret_key, $course_id_field_name, $course_id_value) {
434 434
 		$verifKey = $this->verifyKey($secret_key);
435
-		if($verifKey instanceof WSError) {
435
+		if ($verifKey instanceof WSError) {
436 436
 			$this->handleError($verifKey);
437 437
 		} else {
438 438
 			$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
439
-			if($course_id instanceof WSError) {
439
+			if ($course_id instanceof WSError) {
440 440
 				return $course_id;
441 441
 			} else {
442 442
 				// Course exists, get its descriptions
443 443
 				$descriptions = CourseDescription::get_descriptions($course_id);
444 444
 				$results = array();
445
-				foreach($descriptions as $description) {
445
+				foreach ($descriptions as $description) {
446 446
 					$results[] = array('course_desc_id' => $description->get_description_type(),
447 447
 										'course_desc_title' => $description->get_title(),
448 448
 										'course_desc_content' => $description->get_content());
@@ -465,11 +465,11 @@  discard block
 block discarded – undo
465 465
 	 */
466 466
 	public function EditCourseDescription($secret_key, $course_id_field_name, $course_id_value, $course_desc_id, $course_desc_title, $course_desc_content) {
467 467
 		$verifKey = $this->verifyKey($secret_key);
468
-		if($verifKey instanceof WSError) {
468
+		if ($verifKey instanceof WSError) {
469 469
 			$this->handleError($verifKey);
470 470
 		} else {
471 471
 			$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
472
-			if($course_id instanceof WSError) {
472
+			if ($course_id instanceof WSError) {
473 473
 				return $course_id;
474 474
 			} else {
475 475
 				// Create the new course description
@@ -484,8 +484,8 @@  discard block
 block discarded – undo
484 484
 				// Check if this course description exists
485 485
 				$descriptions = CourseDescription::get_descriptions($course_id);
486 486
 				$exists = false;
487
-				foreach($descriptions as $description) {
488
-					if($description->get_description_type() == $course_desc_id) {
487
+				foreach ($descriptions as $description) {
488
+					if ($description->get_description_type() == $course_desc_id) {
489 489
 						$exists = true;
490 490
 					}
491 491
 				}
Please login to merge, or discard this patch.
Indentation   +455 added lines, -455 removed lines patch added patch discarded remove patch
@@ -12,490 +12,490 @@
 block discarded – undo
12 12
  */
13 13
 class WSCourse extends WS
14 14
 {
15
-	/**
16
-	 * Deletes a course (helper method)
17
-	 *
18
-	 * @param string Course id field name
19
-	 * @param string Course id value
20
-	 * @return mixed True if the course was successfully deleted, WSError otherwise
21
-	 */
22
-	protected function deleteCourseHelper($course_id_field_name, $course_id_value) {
23
-		$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
24
-		if($course_id instanceof WSError) {
25
-			return $course_id;
26
-		} else {
27
-			$course_code = CourseManager::get_course_code_from_course_id($course_id);
28
-			CourseManager::delete_course($course_code);
29
-			return true;
30
-		}
31
-	}
15
+    /**
16
+     * Deletes a course (helper method)
17
+     *
18
+     * @param string Course id field name
19
+     * @param string Course id value
20
+     * @return mixed True if the course was successfully deleted, WSError otherwise
21
+     */
22
+    protected function deleteCourseHelper($course_id_field_name, $course_id_value) {
23
+        $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
24
+        if($course_id instanceof WSError) {
25
+            return $course_id;
26
+        } else {
27
+            $course_code = CourseManager::get_course_code_from_course_id($course_id);
28
+            CourseManager::delete_course($course_code);
29
+            return true;
30
+        }
31
+    }
32 32
 
33
-	/**
34
-	 * Deletes a course
35
-	 *
36
-	 * @param string API secret key
37
-	 * @param string Course id field name
38
-	 * @param string Course id value
39
-	 */
40
-	public function DeleteCourse($secret_key, $course_id_field_name, $course_id_value) {
41
-		$verifKey = $this->verifyKey($secret_key);
42
-		if($verifKey instanceof WSError) {
43
-			$this->handleError($verifKey);
44
-		} else {
45
-			$result = $this->deleteCourseHelper($course_id_field_name, $course_id_value);
46
-			if($result instanceof WSError) {
47
-				$this->handleError($result);
48
-			}
49
-		}
50
-	}
33
+    /**
34
+     * Deletes a course
35
+     *
36
+     * @param string API secret key
37
+     * @param string Course id field name
38
+     * @param string Course id value
39
+     */
40
+    public function DeleteCourse($secret_key, $course_id_field_name, $course_id_value) {
41
+        $verifKey = $this->verifyKey($secret_key);
42
+        if($verifKey instanceof WSError) {
43
+            $this->handleError($verifKey);
44
+        } else {
45
+            $result = $this->deleteCourseHelper($course_id_field_name, $course_id_value);
46
+            if($result instanceof WSError) {
47
+                $this->handleError($result);
48
+            }
49
+        }
50
+    }
51 51
 
52
-	/**
53
-	 * Deletes multiple courses
54
-	 *
55
-	 * @param string API secret key
56
-	 * @param array Array of courses with elements of the form array('course_id_field_name' => 'name_of_field', 'course_id_value' => 'value')
57
-	 * @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
58
-	 * than 0, an error occured
59
-	 */
60
-	public function DeleteCourses($secret_key, $courses) {
61
-		$verifKey = $this->verifyKey($secret_key);
62
-		if($verifKey instanceof WSError) {
63
-			$this->handleError($verifKey);
64
-		} else {
65
-			$results = array();
66
-			foreach($courses as $course) {
67
-				$result_tmp = array();
68
-				$result_op = $this->deleteCourseHelper($course['course_id_field_name'], $course['course_id_value']);
69
-				$result_tmp['course_id_value'] = $course['course_id_value'];
70
-				if($result_op instanceof WSError) {
71
-					// Return the error in the results
72
-					$result_tmp['result'] = $result_op->toArray();
73
-				} else {
74
-					$result_tmp['result'] = $this->getSuccessfulResult();
75
-				}
76
-				$results[] = $result_tmp;
77
-			}
78
-			return $results;
79
-		}
80
-	}
52
+    /**
53
+     * Deletes multiple courses
54
+     *
55
+     * @param string API secret key
56
+     * @param array Array of courses with elements of the form array('course_id_field_name' => 'name_of_field', 'course_id_value' => 'value')
57
+     * @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
58
+     * than 0, an error occured
59
+     */
60
+    public function DeleteCourses($secret_key, $courses) {
61
+        $verifKey = $this->verifyKey($secret_key);
62
+        if($verifKey instanceof WSError) {
63
+            $this->handleError($verifKey);
64
+        } else {
65
+            $results = array();
66
+            foreach($courses as $course) {
67
+                $result_tmp = array();
68
+                $result_op = $this->deleteCourseHelper($course['course_id_field_name'], $course['course_id_value']);
69
+                $result_tmp['course_id_value'] = $course['course_id_value'];
70
+                if($result_op instanceof WSError) {
71
+                    // Return the error in the results
72
+                    $result_tmp['result'] = $result_op->toArray();
73
+                } else {
74
+                    $result_tmp['result'] = $this->getSuccessfulResult();
75
+                }
76
+                $results[] = $result_tmp;
77
+            }
78
+            return $results;
79
+        }
80
+    }
81 81
 
82
-	/**
83
-	 * Creates a course (helper method)
84
-	 *
85
-	 * @param string Title
86
-	 * @param string Category code
87
-	 * @param string Wanted code. If it's not defined, it will be generated automatically
88
-	 * @param string Tutor name
89
-	 * @param string Course admin user id field name
90
-	 * @param string Course admin user id value
91
-	 * @param string Course language
92
-	 * @param string Course id field name
93
-	 * @param string Course id value
94
-	 * @param array Course extra fields
95
-	 * @return mixed Generated id if creation was successful, WSError otherwise
96
-	 */
97
-	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) {
98
-		// Add the original course id field name and value to the extra fields if needed
99
-		$extras_associative = array();
100
-		if($course_id_field_name != "chamilo_course_id") {
101
-			$extras_associative[$course_id_field_name] = $course_id_value;
102
-		}
103
-		foreach($extras as $extra) {
104
-			$extras_associative[$extra['field_name']] = $extra['field_value'];
105
-		}
106
-		$course_admin_id = $this->getUserId($course_admin_user_id_field_name, $course_admin_user_id_value);
107
-		if($course_admin_id instanceof WSError) {
108
-			return $course_admin_id;
109
-		}
110
-		if($wanted_code == '') {
111
-			$wanted_code = CourseManager::generate_course_code($title);
112
-		}
113
-		$result = create_course($wanted_code, $title, $tutor_name, $category_code, $language, $course_admin_id, $this->_configuration['db_prefix'], 0);
114
-		if (!$result) {
115
-			return new WSError(202, 'There was an error creating the course');
116
-		} else {
117
-			// Update extra fields
118
-			foreach($extras_associative as $fname => $fvalue) {
119
-				CourseManager::update_course_extra_field_value($result, $fname, $fvalue);
120
-			}
121
-			// Get course id
122
-			$course_info = CourseManager::get_course_information($result);
123
-			return $course_info['real_id'];
124
-		}
125
-	}
82
+    /**
83
+     * Creates a course (helper method)
84
+     *
85
+     * @param string Title
86
+     * @param string Category code
87
+     * @param string Wanted code. If it's not defined, it will be generated automatically
88
+     * @param string Tutor name
89
+     * @param string Course admin user id field name
90
+     * @param string Course admin user id value
91
+     * @param string Course language
92
+     * @param string Course id field name
93
+     * @param string Course id value
94
+     * @param array Course extra fields
95
+     * @return mixed Generated id if creation was successful, WSError otherwise
96
+     */
97
+    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) {
98
+        // Add the original course id field name and value to the extra fields if needed
99
+        $extras_associative = array();
100
+        if($course_id_field_name != "chamilo_course_id") {
101
+            $extras_associative[$course_id_field_name] = $course_id_value;
102
+        }
103
+        foreach($extras as $extra) {
104
+            $extras_associative[$extra['field_name']] = $extra['field_value'];
105
+        }
106
+        $course_admin_id = $this->getUserId($course_admin_user_id_field_name, $course_admin_user_id_value);
107
+        if($course_admin_id instanceof WSError) {
108
+            return $course_admin_id;
109
+        }
110
+        if($wanted_code == '') {
111
+            $wanted_code = CourseManager::generate_course_code($title);
112
+        }
113
+        $result = create_course($wanted_code, $title, $tutor_name, $category_code, $language, $course_admin_id, $this->_configuration['db_prefix'], 0);
114
+        if (!$result) {
115
+            return new WSError(202, 'There was an error creating the course');
116
+        } else {
117
+            // Update extra fields
118
+            foreach($extras_associative as $fname => $fvalue) {
119
+                CourseManager::update_course_extra_field_value($result, $fname, $fvalue);
120
+            }
121
+            // Get course id
122
+            $course_info = CourseManager::get_course_information($result);
123
+            return $course_info['real_id'];
124
+        }
125
+    }
126 126
 
127
-	/**
128
-	 * Creates a course
129
-	 *
130
-	 * @param string API secret key
131
-	 * @param string Title
132
-	 * @param string Category code
133
-	 * @param string Wanted code. If it's not defined, it will be generated automatically
134
-	 * @param string Tutor name
135
-	 * @param string Course admin user id field name
136
-	 * @param string Course admin user id value
137
-	 * @param string Course language
138
-	 * @param string Course id field name
139
-	 * @param string Course id value
140
-	 * @param array Course extra fields
141
-	 * @return int Course id generated
142
-	 */
143
-	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) {
144
-		// First, verify the secret key
145
-		$verifKey = $this->verifyKey($secret_key);
146
-		if($verifKey instanceof WSError) {
147
-			$this->handleError($verifKey);
148
-		} else {
149
-			$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);
150
-			if($result instanceof WSError) {
151
-				$this->handleError($result);
152
-			} else {
153
-				return $result;
154
-			}
155
-		}
156
-	}
127
+    /**
128
+     * Creates a course
129
+     *
130
+     * @param string API secret key
131
+     * @param string Title
132
+     * @param string Category code
133
+     * @param string Wanted code. If it's not defined, it will be generated automatically
134
+     * @param string Tutor name
135
+     * @param string Course admin user id field name
136
+     * @param string Course admin user id value
137
+     * @param string Course language
138
+     * @param string Course id field name
139
+     * @param string Course id value
140
+     * @param array Course extra fields
141
+     * @return int Course id generated
142
+     */
143
+    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) {
144
+        // First, verify the secret key
145
+        $verifKey = $this->verifyKey($secret_key);
146
+        if($verifKey instanceof WSError) {
147
+            $this->handleError($verifKey);
148
+        } else {
149
+            $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);
150
+            if($result instanceof WSError) {
151
+                $this->handleError($result);
152
+            } else {
153
+                return $result;
154
+            }
155
+        }
156
+    }
157 157
 
158
-	/**
159
-	 * Create multiple courses
160
-	 *
161
-	 * @param string API secret key
162
-	 * @param array Courses to be created, with elements following the structure presented in CreateCourse
163
-	 * @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'))
164
-	 */
165
-	public function CreateCourses($secret_key, $courses) {
166
-		// First, verify the secret key
167
-		$verifKey = $this->verifyKey($secret_key);
168
-		if($verifKey instanceof WSError) {
169
-			$this->handleError($verifKey);
170
-		} else {
171
-			$results = array();
172
-			foreach($courses as $course) {
173
-				$result_tmp = array();
158
+    /**
159
+     * Create multiple courses
160
+     *
161
+     * @param string API secret key
162
+     * @param array Courses to be created, with elements following the structure presented in CreateCourse
163
+     * @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'))
164
+     */
165
+    public function CreateCourses($secret_key, $courses) {
166
+        // First, verify the secret key
167
+        $verifKey = $this->verifyKey($secret_key);
168
+        if($verifKey instanceof WSError) {
169
+            $this->handleError($verifKey);
170
+        } else {
171
+            $results = array();
172
+            foreach($courses as $course) {
173
+                $result_tmp = array();
174 174
                 // re-initialize variables just in case
175 175
                 $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 = 0;
176
-				extract($course);
177
-				$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);
178
-				if($result instanceof WSError) {
179
-					$result_tmp['result'] = $result->toArray();
180
-					$result_tmp['course_id_value'] = $course_id_value;
181
-					$result_tmp['course_id_generated'] = 0;
182
-				} else {
183
-					$result_tmp['result'] = $this->getSuccessfulResult();
184
-					$result_tmp['course_id_value'] = $course_id_value;
185
-					$result_tmp['course_id_generated'] = $result;
186
-				}
187
-				$results[] = $result_tmp;
188
-			}
189
-			return $results;
190
-		}
191
-	}
176
+                extract($course);
177
+                $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);
178
+                if($result instanceof WSError) {
179
+                    $result_tmp['result'] = $result->toArray();
180
+                    $result_tmp['course_id_value'] = $course_id_value;
181
+                    $result_tmp['course_id_generated'] = 0;
182
+                } else {
183
+                    $result_tmp['result'] = $this->getSuccessfulResult();
184
+                    $result_tmp['course_id_value'] = $course_id_value;
185
+                    $result_tmp['course_id_generated'] = $result;
186
+                }
187
+                $results[] = $result_tmp;
188
+            }
189
+            return $results;
190
+        }
191
+    }
192 192
 
193
-	/**
194
-	 * Edits a course (helper method)
195
-	 *
196
-	 * @param string Course id field name
197
-	 * @param string Course id value
198
-	 * @param string Title
199
-	 * @param string Category code
200
-	 * @param string Department name
201
-	 * @param string Department url
202
-	 * @param string Course language
203
-	 * @param int Visibility
204
-	 * @param int Subscribe (0 = denied, 1 = allowed)
205
-	 * @param int Unsubscribe (0 = denied, 1 = allowed)
206
-	 * @param string Visual code
207
-	 * @param array Course extra fields
208
-	 * @return mixed True in case of success, WSError otherwise
209
-	 */
210
-	protected function editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) {
211
-		$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
212
-		if($course_id instanceof WSError) {
213
-			return $course_id;
214
-		} else {
215
-			$attributes = array();
216
-			if(!is_empty($title)) {
217
-				$attributes['title'] = $title;
218
-			}
219
-			if(!is_empty($category_code)) {
220
-				$attributes['category_code'] = $category_code;
221
-			}
222
-			if(!is_empty($department_name)) {
223
-				$attributes['department_name'] = $department_name;
224
-			}
225
-			if(!is_empty($department_url)) {
226
-				$attributes['department_url'] = $department_url;
227
-			}
228
-			if(!is_empty($language)) {
229
-				$attributes['course_language'] = $language;
230
-			}
231
-			if($visibility != '') {
232
-				$attributes['visibility'] = (int)$visibility;
233
-			}
234
-			if($subscribe != '') {
235
-				$attributes['subscribe'] = (int)$subscribe;
236
-			}
237
-			if($unsubscribe != '') {
238
-				$attributes['unsubscribe'] = (int)$unsubscribe;
239
-			}
240
-			if(!is_empty($visual_code)) {
241
-				$attributes['visual_code'] = $visual_code;
242
-			}
243
-			if(!is_empty($attributes)) {
244
-				CourseManager::update_attributes($course_id, $attributes);
245
-			}
246
-			if(!empty($extras)) {
247
-				$course_code = CourseManager::get_course_code_from_course_id($course_id);
248
-				$extras_associative = array();
249
-				foreach($extras as $extra) {
250
-					$extras_associative[$extra['field_name']] = $extra['field_value'];
251
-				}
252
-				foreach($extras_associative as $fname => $fvalue) {
253
-					CourseManager::update_extra_field_value($course_code, $fname, $fvalue);
254
-				}
255
-			}
256
-			return true;
257
-		}
258
-	}
193
+    /**
194
+     * Edits a course (helper method)
195
+     *
196
+     * @param string Course id field name
197
+     * @param string Course id value
198
+     * @param string Title
199
+     * @param string Category code
200
+     * @param string Department name
201
+     * @param string Department url
202
+     * @param string Course language
203
+     * @param int Visibility
204
+     * @param int Subscribe (0 = denied, 1 = allowed)
205
+     * @param int Unsubscribe (0 = denied, 1 = allowed)
206
+     * @param string Visual code
207
+     * @param array Course extra fields
208
+     * @return mixed True in case of success, WSError otherwise
209
+     */
210
+    protected function editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) {
211
+        $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
212
+        if($course_id instanceof WSError) {
213
+            return $course_id;
214
+        } else {
215
+            $attributes = array();
216
+            if(!is_empty($title)) {
217
+                $attributes['title'] = $title;
218
+            }
219
+            if(!is_empty($category_code)) {
220
+                $attributes['category_code'] = $category_code;
221
+            }
222
+            if(!is_empty($department_name)) {
223
+                $attributes['department_name'] = $department_name;
224
+            }
225
+            if(!is_empty($department_url)) {
226
+                $attributes['department_url'] = $department_url;
227
+            }
228
+            if(!is_empty($language)) {
229
+                $attributes['course_language'] = $language;
230
+            }
231
+            if($visibility != '') {
232
+                $attributes['visibility'] = (int)$visibility;
233
+            }
234
+            if($subscribe != '') {
235
+                $attributes['subscribe'] = (int)$subscribe;
236
+            }
237
+            if($unsubscribe != '') {
238
+                $attributes['unsubscribe'] = (int)$unsubscribe;
239
+            }
240
+            if(!is_empty($visual_code)) {
241
+                $attributes['visual_code'] = $visual_code;
242
+            }
243
+            if(!is_empty($attributes)) {
244
+                CourseManager::update_attributes($course_id, $attributes);
245
+            }
246
+            if(!empty($extras)) {
247
+                $course_code = CourseManager::get_course_code_from_course_id($course_id);
248
+                $extras_associative = array();
249
+                foreach($extras as $extra) {
250
+                    $extras_associative[$extra['field_name']] = $extra['field_value'];
251
+                }
252
+                foreach($extras_associative as $fname => $fvalue) {
253
+                    CourseManager::update_extra_field_value($course_code, $fname, $fvalue);
254
+                }
255
+            }
256
+            return true;
257
+        }
258
+    }
259 259
 
260
-	/**
261
-	 * Edits a course
262
-	 *
263
-	 * @param string API secret key
264
-	 * @param string Course id field name
265
-	 * @param string Course id value
266
-	 * @param string Title
267
-	 * @param string Category code
268
-	 * @param string Department name
269
-	 * @param string Department url
270
-	 * @param string Course language
271
-	 * @param int Visibility
272
-	 * @param int Subscribe (0 = denied, 1 = allowed)
273
-	 * @param int Unsubscribe (0 = denied, 1 = allowed)
274
-	 * @param string Visual code
275
-	 * @param array Course extra fields
276
-	 */
277
-	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) {
278
-		$verifKey = $this->verifyKey($secret_key);
279
-		if($verifKey instanceof WSError) {
280
-			$this->handleError($verifKey);
281
-		} else {
282
-			$result = $this->editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras);
283
-			if($result instanceof WSError) {
284
-				$this->handleError($result);
285
-			}
286
-		}
287
-	}
260
+    /**
261
+     * Edits a course
262
+     *
263
+     * @param string API secret key
264
+     * @param string Course id field name
265
+     * @param string Course id value
266
+     * @param string Title
267
+     * @param string Category code
268
+     * @param string Department name
269
+     * @param string Department url
270
+     * @param string Course language
271
+     * @param int Visibility
272
+     * @param int Subscribe (0 = denied, 1 = allowed)
273
+     * @param int Unsubscribe (0 = denied, 1 = allowed)
274
+     * @param string Visual code
275
+     * @param array Course extra fields
276
+     */
277
+    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) {
278
+        $verifKey = $this->verifyKey($secret_key);
279
+        if($verifKey instanceof WSError) {
280
+            $this->handleError($verifKey);
281
+        } else {
282
+            $result = $this->editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras);
283
+            if($result instanceof WSError) {
284
+                $this->handleError($result);
285
+            }
286
+        }
287
+    }
288 288
 
289
-	/**
290
-	 * List courses
291
-	 *
292
-	 * @param string API secret key
293
-	 * @param string A list of visibility filter we want to apply
294
-	 * @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',
295
-	 * 'category_name' => 'Name of the category of the course', 'number_students' => 'Number of students in the course', 'external_course_id' => 'External course id')
296
-	 */
297
-	public function ListCourses($secret_key, $visibility = 'public,public-registered,private,closed') {
298
-		$verifKey = $this->verifyKey($secret_key);
299
-		if($verifKey instanceof WSError) {
300
-			$this->handleError($verifKey);
301
-		} else {
289
+    /**
290
+     * List courses
291
+     *
292
+     * @param string API secret key
293
+     * @param string A list of visibility filter we want to apply
294
+     * @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',
295
+     * 'category_name' => 'Name of the category of the course', 'number_students' => 'Number of students in the course', 'external_course_id' => 'External course id')
296
+     */
297
+    public function ListCourses($secret_key, $visibility = 'public,public-registered,private,closed') {
298
+        $verifKey = $this->verifyKey($secret_key);
299
+        if($verifKey instanceof WSError) {
300
+            $this->handleError($verifKey);
301
+        } else {
302 302
             $visibilities = split(',',$visibility);
303 303
             $vis = array('public' => '3', 'public-registered' => '2', 'private' => '1', 'closed' => '0');
304 304
             foreach ($visibilities as $p => $visibility) {
305 305
                 $visibilities[$p] = $vis[$visibility];
306 306
             }
307
-			$courses_result = array();
308
-			$category_names = array();
307
+            $courses_result = array();
308
+            $category_names = array();
309 309
 
310
-			$courses = CourseManager::get_courses_list();
311
-			foreach($courses as $course) {
310
+            $courses = CourseManager::get_courses_list();
311
+            foreach($courses as $course) {
312 312
                 //skip elements that do not match required visibility
313 313
                 if (!in_array($course['visibility'],$visibilities)) { continue; }
314
-				$course_tmp = array();
315
-				$course_tmp['id'] = $course['id'];
316
-				$course_tmp['code'] = $course['code'];
317
-				$course_tmp['title'] = $course['title'];
318
-				$course_tmp['language'] = $course['course_language'];
319
-				$course_tmp['visibility'] = $course['visibility'];
314
+                $course_tmp = array();
315
+                $course_tmp['id'] = $course['id'];
316
+                $course_tmp['code'] = $course['code'];
317
+                $course_tmp['title'] = $course['title'];
318
+                $course_tmp['language'] = $course['course_language'];
319
+                $course_tmp['visibility'] = $course['visibility'];
320 320
 
321
-				// Determining category name
322
-				if($category_names[$course['category_code']]) {
323
-					$course_tmp['category_name'] = $category_names[$course['category_code']];
324
-				} else {
325
-					$category = CourseManager::get_course_category($course['category_code']);
326
-					$category_names[$course['category_code']] = $category['name'];
327
-					$course_tmp['category_name'] = $category['name'];
328
-				}
321
+                // Determining category name
322
+                if($category_names[$course['category_code']]) {
323
+                    $course_tmp['category_name'] = $category_names[$course['category_code']];
324
+                } else {
325
+                    $category = CourseManager::get_course_category($course['category_code']);
326
+                    $category_names[$course['category_code']] = $category['name'];
327
+                    $course_tmp['category_name'] = $category['name'];
328
+                }
329 329
 
330
-				// Determining number of students registered in course
331
-				$user_list = CourseManager::get_user_list_from_course_code($course['code'], 0);
332
-				$course_tmp['number_students'] = count($user_list);
330
+                // Determining number of students registered in course
331
+                $user_list = CourseManager::get_user_list_from_course_code($course['code'], 0);
332
+                $course_tmp['number_students'] = count($user_list);
333 333
 
334
-				// Determining external course id - this code misses the external course id field name
335
-				// $course_tmp['external_course_id'] = CourseManager::get_course_extra_field_value($course_field_name, $course['code']);
334
+                // Determining external course id - this code misses the external course id field name
335
+                // $course_tmp['external_course_id'] = CourseManager::get_course_extra_field_value($course_field_name, $course['code']);
336 336
 
337 337
 
338
-				$courses_result[] = $course_tmp;
339
-			}
338
+                $courses_result[] = $course_tmp;
339
+            }
340 340
 
341
-			return $courses_result;
342
-		}
343
-	}
341
+            return $courses_result;
342
+        }
343
+    }
344 344
 
345
-	/**
346
-	 * Subscribe or unsubscribe user to a course (helper method)
347
-	 *
348
-	 * @param string Course id field name. Use "chamilo_course_id" to use internal id
349
-	 * @param string Course id value.
350
-	 * @param string User id field name. Use "chamilo_user_id" to use internal id
351
-	 * @param string User id value
352
-	 * @param int Set to 1 to subscribe, 0 to unsubscribe
353
-	 * @param int Status (STUDENT or TEACHER) Used for subscription only
354
-	 * @return mixed True if subscription or unsubscription was successful, false otherwise
355
-	 */
356
-	protected function changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $state, $status = STUDENT) {
357
-		$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
358
-		if($course_id instanceof WSError) {
359
-			return $course_id;
360
-		} else {
361
-			$user_id = $this->getUserId($user_id_field_name, $user_id_value);
362
-			if($user_id instanceof WSError) {
363
-				return $user_id;
364
-			} else {
365
-				$course_code = CourseManager::get_course_code_from_course_id($course_id);
366
-				if($state == 0) {
367
-					// Unsubscribe user
368
-					CourseManager::unsubscribe_user($user_id, $course_code);
369
-					return true;
370
-				} else {
371
-					// Subscribe user
372
-					if(CourseManager::subscribe_user($user_id, $course_code, $status)) {
373
-						return true;
374
-					} else {
375
-						return new WSError(203, 'An error occured subscribing to this course');
376
-					}
377
-				}
378
-			}
379
-		}
380
-	}
345
+    /**
346
+     * Subscribe or unsubscribe user to a course (helper method)
347
+     *
348
+     * @param string Course id field name. Use "chamilo_course_id" to use internal id
349
+     * @param string Course id value.
350
+     * @param string User id field name. Use "chamilo_user_id" to use internal id
351
+     * @param string User id value
352
+     * @param int Set to 1 to subscribe, 0 to unsubscribe
353
+     * @param int Status (STUDENT or TEACHER) Used for subscription only
354
+     * @return mixed True if subscription or unsubscription was successful, false otherwise
355
+     */
356
+    protected function changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $state, $status = STUDENT) {
357
+        $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
358
+        if($course_id instanceof WSError) {
359
+            return $course_id;
360
+        } else {
361
+            $user_id = $this->getUserId($user_id_field_name, $user_id_value);
362
+            if($user_id instanceof WSError) {
363
+                return $user_id;
364
+            } else {
365
+                $course_code = CourseManager::get_course_code_from_course_id($course_id);
366
+                if($state == 0) {
367
+                    // Unsubscribe user
368
+                    CourseManager::unsubscribe_user($user_id, $course_code);
369
+                    return true;
370
+                } else {
371
+                    // Subscribe user
372
+                    if(CourseManager::subscribe_user($user_id, $course_code, $status)) {
373
+                        return true;
374
+                    } else {
375
+                        return new WSError(203, 'An error occured subscribing to this course');
376
+                    }
377
+                }
378
+            }
379
+        }
380
+    }
381 381
 
382
-	/**
383
-	 * Subscribe user to a course
384
-	 *
385
-	 * @param string API secret key
386
-	 * @param string Course id field name. Use "chamilo_course_id" to use internal id
387
-	 * @param string Course id value.
388
-	 * @param string User id field name. Use "chamilo_user_id" to use internal id
389
-	 * @param string User id value
390
-	 * @param int Status (1 = Teacher, 5 = Student)
391
-	 */
392
-	public function SubscribeUserToCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $status) {
393
-		$verifKey = $this->verifyKey($secret_key);
394
-		if($verifKey instanceof WSError) {
395
-			$this->handleError($verifKey);
396
-		} else {
397
-			$result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 1, $status);
398
-			if($result instanceof WSError) {
399
-				$this->handleError($result);
400
-			}
401
-		}
402
-	}
382
+    /**
383
+     * Subscribe user to a course
384
+     *
385
+     * @param string API secret key
386
+     * @param string Course id field name. Use "chamilo_course_id" to use internal id
387
+     * @param string Course id value.
388
+     * @param string User id field name. Use "chamilo_user_id" to use internal id
389
+     * @param string User id value
390
+     * @param int Status (1 = Teacher, 5 = Student)
391
+     */
392
+    public function SubscribeUserToCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $status) {
393
+        $verifKey = $this->verifyKey($secret_key);
394
+        if($verifKey instanceof WSError) {
395
+            $this->handleError($verifKey);
396
+        } else {
397
+            $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 1, $status);
398
+            if($result instanceof WSError) {
399
+                $this->handleError($result);
400
+            }
401
+        }
402
+    }
403 403
 
404
-	/**
405
-	 * Unsusbscribe user from course
406
-	 *
407
-	 * @param string API secret key
408
-	 * @param string Course id field name. Use "chamilo_course_id" to use internal id
409
-	 * @param string Course id value.
410
-	 * @param string User id field name. Use "chamilo_user_id" to use internal id
411
-	 * @param string User id value
412
-	 */
413
-	public function UnsubscribeUserFromCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value) {
414
-		$verifKey = $this->verifyKey($secret_key);
415
-		if($verifKey instanceof WSError) {
416
-			$this->handleError($verifKey);
417
-		} else {
418
-			$result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 0);
419
-			if($result instanceof WSError) {
420
-				$this->handleError($result);
421
-			}
422
-		}
423
-	}
404
+    /**
405
+     * Unsusbscribe user from course
406
+     *
407
+     * @param string API secret key
408
+     * @param string Course id field name. Use "chamilo_course_id" to use internal id
409
+     * @param string Course id value.
410
+     * @param string User id field name. Use "chamilo_user_id" to use internal id
411
+     * @param string User id value
412
+     */
413
+    public function UnsubscribeUserFromCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value) {
414
+        $verifKey = $this->verifyKey($secret_key);
415
+        if($verifKey instanceof WSError) {
416
+            $this->handleError($verifKey);
417
+        } else {
418
+            $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 0);
419
+            if($result instanceof WSError) {
420
+                $this->handleError($result);
421
+            }
422
+        }
423
+    }
424 424
 
425
-	/**
426
-	 * Returns the descriptions of a course, along with their id
427
-	 *
428
-	 * @param string API secret key
429
-	 * @param string Course id field name
430
-	 * @param string Course id value
431
-	 * @return array Returns an array with elements of the form ('course_desc_id' => 1, 'course_desc_title' => 'Title', 'course_desc_content' => 'Content')
432
-	 */
433
-	public function GetCourseDescriptions($secret_key, $course_id_field_name, $course_id_value) {
434
-		$verifKey = $this->verifyKey($secret_key);
435
-		if($verifKey instanceof WSError) {
436
-			$this->handleError($verifKey);
437
-		} else {
438
-			$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
439
-			if($course_id instanceof WSError) {
440
-				return $course_id;
441
-			} else {
442
-				// Course exists, get its descriptions
443
-				$descriptions = CourseDescription::get_descriptions($course_id);
444
-				$results = array();
445
-				foreach($descriptions as $description) {
446
-					$results[] = array('course_desc_id' => $description->get_description_type(),
447
-										'course_desc_title' => $description->get_title(),
448
-										'course_desc_content' => $description->get_content());
449
-				}
450
-				return $results;
451
-			}
452
-		}
453
-	}
425
+    /**
426
+     * Returns the descriptions of a course, along with their id
427
+     *
428
+     * @param string API secret key
429
+     * @param string Course id field name
430
+     * @param string Course id value
431
+     * @return array Returns an array with elements of the form ('course_desc_id' => 1, 'course_desc_title' => 'Title', 'course_desc_content' => 'Content')
432
+     */
433
+    public function GetCourseDescriptions($secret_key, $course_id_field_name, $course_id_value) {
434
+        $verifKey = $this->verifyKey($secret_key);
435
+        if($verifKey instanceof WSError) {
436
+            $this->handleError($verifKey);
437
+        } else {
438
+            $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
439
+            if($course_id instanceof WSError) {
440
+                return $course_id;
441
+            } else {
442
+                // Course exists, get its descriptions
443
+                $descriptions = CourseDescription::get_descriptions($course_id);
444
+                $results = array();
445
+                foreach($descriptions as $description) {
446
+                    $results[] = array('course_desc_id' => $description->get_description_type(),
447
+                                        'course_desc_title' => $description->get_title(),
448
+                                        'course_desc_content' => $description->get_content());
449
+                }
450
+                return $results;
451
+            }
452
+        }
453
+    }
454 454
 
455 455
 
456
-	/**
457
-	 * Edit course description
458
-	 *
459
-	 * @param string API secret key
460
-	 * @param string Course id field name
461
-	 * @param string Course id value
462
-	 * @param int Category id from course description
463
-	 * @param string Description title
464
-	 * @param string Course description content
465
-	 */
466
-	public function EditCourseDescription($secret_key, $course_id_field_name, $course_id_value, $course_desc_id, $course_desc_title, $course_desc_content) {
467
-		$verifKey = $this->verifyKey($secret_key);
468
-		if($verifKey instanceof WSError) {
469
-			$this->handleError($verifKey);
470
-		} else {
471
-			$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
472
-			if($course_id instanceof WSError) {
473
-				return $course_id;
474
-			} else {
475
-				// Create the new course description
476
-				$cd = new CourseDescription();
477
-				$cd->set_description_type($course_desc_id);
478
-				$cd->set_title($course_desc_title);
479
-				$cd->set_content($course_desc_content);
480
-				$cd->set_session_id(0);
481
-				// Get course info
482
-				$course_info = CourseManager::get_course_information(CourseManager::get_course_code_from_course_id($course_id));
456
+    /**
457
+     * Edit course description
458
+     *
459
+     * @param string API secret key
460
+     * @param string Course id field name
461
+     * @param string Course id value
462
+     * @param int Category id from course description
463
+     * @param string Description title
464
+     * @param string Course description content
465
+     */
466
+    public function EditCourseDescription($secret_key, $course_id_field_name, $course_id_value, $course_desc_id, $course_desc_title, $course_desc_content) {
467
+        $verifKey = $this->verifyKey($secret_key);
468
+        if($verifKey instanceof WSError) {
469
+            $this->handleError($verifKey);
470
+        } else {
471
+            $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
472
+            if($course_id instanceof WSError) {
473
+                return $course_id;
474
+            } else {
475
+                // Create the new course description
476
+                $cd = new CourseDescription();
477
+                $cd->set_description_type($course_desc_id);
478
+                $cd->set_title($course_desc_title);
479
+                $cd->set_content($course_desc_content);
480
+                $cd->set_session_id(0);
481
+                // Get course info
482
+                $course_info = CourseManager::get_course_information(CourseManager::get_course_code_from_course_id($course_id));
483 483
                 $cd->set_course_id($course_info['real_id']);
484
-				// Check if this course description exists
485
-				$descriptions = CourseDescription::get_descriptions($course_id);
486
-				$exists = false;
487
-				foreach($descriptions as $description) {
488
-					if($description->get_description_type() == $course_desc_id) {
489
-						$exists = true;
490
-					}
491
-				}
492
-				if (!$exists) {
493
-					$cd->set_progress(0);
494
-					$cd->insert();
495
-				} else {
496
-					$cd->update();
497
-				}
498
-			}
499
-		}
500
-	}
484
+                // Check if this course description exists
485
+                $descriptions = CourseDescription::get_descriptions($course_id);
486
+                $exists = false;
487
+                foreach($descriptions as $description) {
488
+                    if($description->get_description_type() == $course_desc_id) {
489
+                        $exists = true;
490
+                    }
491
+                }
492
+                if (!$exists) {
493
+                    $cd->set_progress(0);
494
+                    $cd->insert();
495
+                } else {
496
+                    $cd->update();
497
+                }
498
+            }
499
+        }
500
+    }
501 501
 }
Please login to merge, or discard this patch.
main/webservices/additional_webservices.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -19,12 +19,12 @@  discard block
 block discarded – undo
19 19
 {
20 20
     $fileData = $pptData['file_data'];
21 21
     $dataInfo = pathinfo($pptData['file_name']);
22
-    $fileName =  basename($pptData['file_name'], '.' . $dataInfo['extension']);
22
+    $fileName = basename($pptData['file_name'], '.'.$dataInfo['extension']);
23 23
     $fullFileName = $pptData['file_name'];
24 24
 
25 25
     $tempArchivePath = api_get_path(SYS_ARCHIVE_PATH);
26
-    $tempPath = $tempArchivePath . 'wsConvert/' . $fileName . '/';
27
-    $tempPathNewFiles = $tempArchivePath . 'wsConvert/' . $fileName . '-n/';
26
+    $tempPath = $tempArchivePath.'wsConvert/'.$fileName.'/';
27
+    $tempPathNewFiles = $tempArchivePath.'wsConvert/'.$fileName.'-n/';
28 28
 
29 29
     $perms = api_get_permissions_for_new_directories();
30 30
     if (!is_dir($tempPath)) {
@@ -33,28 +33,28 @@  discard block
 block discarded – undo
33 33
     if (!is_dir($tempPathNewFiles)) {
34 34
         mkdir($tempPathNewFiles, $perms, true);
35 35
     }
36
-    if (!is_dir($tempPathNewFiles . $fileName)) {
37
-        mkdir($tempPathNewFiles . $fileName, $perms, true);
36
+    if (!is_dir($tempPathNewFiles.$fileName)) {
37
+        mkdir($tempPathNewFiles.$fileName, $perms, true);
38 38
     }
39 39
 
40 40
     $file = base64_decode($fileData);
41
-    file_put_contents($tempPath . $fullFileName, $file);
41
+    file_put_contents($tempPath.$fullFileName, $file);
42 42
 
43 43
     if (IS_WINDOWS_OS) { // IS_WINDOWS_OS has been defined in main_api.lib.php
44
-        $converterPath = str_replace('/', '\\', api_get_path(SYS_PATH) . 'main/inc/lib/ppt2png');
45
-        $classPath = $converterPath . ';' . $converterPath . '/jodconverter-2.2.2.jar;' . $converterPath . '/jodconverter-cli-2.2.2.jar';
46
-        $cmd = 'java -Dfile.encoding=UTF-8 -cp "' . $classPath . '" DokeosConverter';
44
+        $converterPath = str_replace('/', '\\', api_get_path(SYS_PATH).'main/inc/lib/ppt2png');
45
+        $classPath = $converterPath.';'.$converterPath.'/jodconverter-2.2.2.jar;'.$converterPath.'/jodconverter-cli-2.2.2.jar';
46
+        $cmd = 'java -Dfile.encoding=UTF-8 -cp "'.$classPath.'" DokeosConverter';
47 47
     } else {
48
-        $converterPath = api_get_path(SYS_PATH) . 'main/inc/lib/ppt2png';
48
+        $converterPath = api_get_path(SYS_PATH).'main/inc/lib/ppt2png';
49 49
         $classPath = ' -Dfile.encoding=UTF-8 -cp .:jodconverter-2.2.2.jar:jodconverter-cli-2.2.2.jar';
50
-        $cmd = 'cd ' . $converterPath . ' && java ' . $classPath . ' DokeosConverter';
50
+        $cmd = 'cd '.$converterPath.' && java '.$classPath.' DokeosConverter';
51 51
     }
52 52
 
53
-    $cmd .= ' -p ' . api_get_setting('service_ppt2lp', 'port');
54
-    $cmd .= ' -w 720 -h 540 -d oogie "' . $tempPath . $fullFileName.'"  "' . $tempPathNewFiles . $fileName . '.html"';
53
+    $cmd .= ' -p '.api_get_setting('service_ppt2lp', 'port');
54
+    $cmd .= ' -w 720 -h 540 -d oogie "'.$tempPath.$fullFileName.'"  "'.$tempPathNewFiles.$fileName.'.html"';
55 55
 
56 56
     $perms = api_get_permissions_for_new_files();
57
-    chmod($tempPathNewFiles . $fileName, $perms, true);
57
+    chmod($tempPathNewFiles.$fileName, $perms, true);
58 58
 
59 59
     $files = array();
60 60
     $return = 0;
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
         $images = array();
65 65
         foreach ($files as $file) {
66 66
             $imageData = explode('||', $file);
67
-            $images[$imageData[1]] = base64_encode(file_get_contents($tempPathNewFiles . $fileName . '/' . $imageData[1]));
67
+            $images[$imageData[1]] = base64_encode(file_get_contents($tempPathNewFiles.$fileName.'/'.$imageData[1]));
68 68
         }
69 69
         $data = array(
70 70
             'files' => $files,
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
  */
90 90
 function deleteDirectory($directoryPath)
91 91
 {
92
-    $files = array_diff(scandir($directoryPath), array('.','..'));
92
+    $files = array_diff(scandir($directoryPath), array('.', '..'));
93 93
     foreach ($files as $file) {
94 94
         if (is_dir("$directoryPath/$file")) {
95 95
             deleteDirectory("$directoryPath/$file");
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 $webCodePath = api_get_path(WEB_CODE_PATH);
107 107
 $options = array(
108 108
     'uri' => $webPath,
109
-    'location' => $webCodePath . 'webservices/additional_webservices.php'
109
+    'location' => $webCodePath.'webservices/additional_webservices.php'
110 110
 );
111 111
 
112 112
 $soapServer = new SoapServer(NULL, $options);
Please login to merge, or discard this patch.
main/webservices/testip.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@
 block discarded – undo
5 5
  */
6 6
 $ip = trim($_SERVER['REMOTE_ADDR']);
7 7
 if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
8
-  list($ip1,$ip2) = preg_split('/,/',$_SERVER['HTTP_X_FORWARDED_FOR']);
9
-  $ip = trim($ip1);
8
+    list($ip1,$ip2) = preg_split('/,/',$_SERVER['HTTP_X_FORWARDED_FOR']);
9
+    $ip = trim($ip1);
10 10
 }
11 11
 echo htmlentities($ip);
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@
 block discarded – undo
5 5
  */
6 6
 $ip = trim($_SERVER['REMOTE_ADDR']);
7 7
 if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
8
-  list($ip1,$ip2) = preg_split('/,/',$_SERVER['HTTP_X_FORWARDED_FOR']);
8
+  list($ip1, $ip2) = preg_split('/,/', $_SERVER['HTTP_X_FORWARDED_FOR']);
9 9
   $ip = trim($ip1);
10 10
 }
11 11
 echo htmlentities($ip);
Please login to merge, or discard this patch.
main/webservices/webservice_report.php 2 patches
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -11,32 +11,32 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class WSReport extends WS {
13 13
 
14
-	/**
15
-	 * Gets the time spent on the platform by a given user
16
-	 *
17
-	 * @param string User id field name
18
-	 * @param string User id value
14
+    /**
15
+     * Gets the time spent on the platform by a given user
16
+     *
17
+     * @param string User id field name
18
+     * @param string User id value
19 19
      * @return array Array of results
20
-	 */
21
-	public function GetTimeSpentOnPlatform($user_id_field_name, $user_id_value) {
22
-		$user_id = $this->getUserId($user_id_field_name, $user_id_value);
23
-		if($user_id instanceof WSError) {
24
-			return $user_id;
25
-		} else {
20
+     */
21
+    public function GetTimeSpentOnPlatform($user_id_field_name, $user_id_value) {
22
+        $user_id = $this->getUserId($user_id_field_name, $user_id_value);
23
+        if($user_id instanceof WSError) {
24
+            return $user_id;
25
+        } else {
26 26
             return Tracking::get_time_spent_on_the_platform($user_id);
27
-		}
28
-	}
27
+        }
28
+    }
29 29
 
30
-	/**
30
+    /**
31 31
      * Gets the time spent in a course by a given user
32
-	 *
32
+     *
33 33
      * @param string User id field name
34 34
      * @param string User id value
35 35
      * @param string Course id field name
36 36
      * @param string Course id value
37
-	 * @return array Array of results
38
-	 */
39
-	public function GetTimeSpentOnCourse($user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value) {
37
+     * @return array Array of results
38
+     */
39
+    public function GetTimeSpentOnCourse($user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value) {
40 40
         $user_id = $this->getUserId($user_id_field_name, $user_id_value);
41 41
         if($user_id instanceof WSError) {
42 42
             return $user_id;
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
             $course_code = CourseManager::get_course_code_from_course_id($course_id);
49 49
         }
50 50
         return Tracking::get_time_spent_on_the_course($user_id, $course_id);
51
-	}
51
+    }
52 52
 
53 53
     /**
54 54
      * Gets the time spent in a course by a given user
@@ -128,8 +128,8 @@  discard block
 block discarded – undo
128 128
         }
129 129
         $lp = new learnpath($course_code, $learnpath_id, $user_id);
130 130
         $return = array(
131
-          'progress_bar_mode' => $lp->progress_bar_mode,
132
-          'progress_db' => $lp->progress_db,
131
+            'progress_bar_mode' => $lp->progress_bar_mode,
132
+            'progress_db' => $lp->progress_db,
133 133
         );
134 134
         return $return;
135 135
     }
@@ -191,10 +191,10 @@  discard block
 block discarded – undo
191 191
 
192 192
         $lp = new learnpath($course_code, $learnpath_id, $user_id);
193 193
         $return = array(
194
-          'min_score' => $lp->items[$learnpath_item_id]->min_score,
195
-          'max_score' => $lp->items[$learnpath_item_id]->max_score,
196
-          'mastery_score' => $lp->items[$learnpath_item_id]->mastery_score,
197
-          'current_score' => $lp->items[$learnpath_item_id]->current_score,
194
+            'min_score' => $lp->items[$learnpath_item_id]->min_score,
195
+            'max_score' => $lp->items[$learnpath_item_id]->max_score,
196
+            'mastery_score' => $lp->items[$learnpath_item_id]->mastery_score,
197
+            'current_score' => $lp->items[$learnpath_item_id]->current_score,
198 198
         );
199 199
         return $return;
200 200
     }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 	 */
21 21
 	public function GetTimeSpentOnPlatform($user_id_field_name, $user_id_value) {
22 22
 		$user_id = $this->getUserId($user_id_field_name, $user_id_value);
23
-		if($user_id instanceof WSError) {
23
+		if ($user_id instanceof WSError) {
24 24
 			return $user_id;
25 25
 		} else {
26 26
             return Tracking::get_time_spent_on_the_platform($user_id);
@@ -38,11 +38,11 @@  discard block
 block discarded – undo
38 38
 	 */
39 39
 	public function GetTimeSpentOnCourse($user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value) {
40 40
         $user_id = $this->getUserId($user_id_field_name, $user_id_value);
41
-        if($user_id instanceof WSError) {
41
+        if ($user_id instanceof WSError) {
42 42
             return $user_id;
43 43
         }
44 44
         $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
45
-        if($course_id instanceof WSError) {
45
+        if ($course_id instanceof WSError) {
46 46
             return $course_id;
47 47
         } else {
48 48
             $course_code = CourseManager::get_course_code_from_course_id($course_id);
@@ -61,17 +61,17 @@  discard block
 block discarded – undo
61 61
      */
62 62
     public function GetTimeSpentOnCourseInSession($user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value, $session_id_field_name, $session_id_value) {
63 63
         $user_id = $this->getUserId($user_id_field_name, $user_id_value);
64
-        if($user_id instanceof WSError) {
64
+        if ($user_id instanceof WSError) {
65 65
             return $user_id;
66 66
         }
67 67
         $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
68
-        if($course_id instanceof WSError) {
68
+        if ($course_id instanceof WSError) {
69 69
             return $course_id;
70 70
         } else {
71 71
             $course_code = CourseManager::get_course_code_from_course_id($course_id);
72 72
         }
73 73
         $session_id = $this->getSessionId($session_id_field_name, $session_id_value);
74
-        if($session_id instanceof WSError) {
74
+        if ($session_id instanceof WSError) {
75 75
             return $session_id;
76 76
         }
77 77
         return Tracking::get_time_spent_on_the_course($user_id, $course_id, $session_id);
@@ -87,17 +87,17 @@  discard block
 block discarded – undo
87 87
      */
88 88
     public function GetLearnpathsByCourse($secret_key, $user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value) {
89 89
         $user_id = $this->getUserId($user_id_field_name, $user_id_value);
90
-        if($user_id instanceof WSError) {
90
+        if ($user_id instanceof WSError) {
91 91
             return $user_id;
92 92
         }
93 93
         $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
94
-        if($course_id instanceof WSError) {
94
+        if ($course_id instanceof WSError) {
95 95
             return $course_id;
96 96
         } else {
97 97
             $course_code = CourseManager::get_course_code_from_course_id($course_id);
98 98
         }
99 99
 
100
-        $lp = new LearnpathList($user_id,$course_code);
100
+        $lp = new LearnpathList($user_id, $course_code);
101 101
         $list = $lp->list;
102 102
         $return = array();
103 103
         foreach ($list as $id => $item) {
@@ -117,11 +117,11 @@  discard block
 block discarded – undo
117 117
      */
118 118
     public function GetLearnpathProgress($secret_key, $user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value, $learnpath_id) {
119 119
         $user_id = $this->getUserId($user_id_field_name, $user_id_value);
120
-        if($user_id instanceof WSError) {
120
+        if ($user_id instanceof WSError) {
121 121
             return $user_id;
122 122
         }
123 123
         $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
124
-        if($course_id instanceof WSError) {
124
+        if ($course_id instanceof WSError) {
125 125
             return $course_id;
126 126
         } else {
127 127
             $course_code = CourseManager::get_course_code_from_course_id($course_id);
@@ -150,11 +150,11 @@  discard block
 block discarded – undo
150 150
      */
151 151
     public function GetLearnpathHighestLessonLocation($secret_key, $user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value, $learnpath_id) {
152 152
         $user_id = $this->getUserId($user_id_field_name, $user_id_value);
153
-        if($user_id instanceof WSError) {
153
+        if ($user_id instanceof WSError) {
154 154
             return $user_id;
155 155
         }
156 156
         $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
157
-        if($course_id instanceof WSError) {
157
+        if ($course_id instanceof WSError) {
158 158
             return $course_id;
159 159
         } else {
160 160
             $course_code = CourseManager::get_course_code_from_course_id($course_id);
@@ -179,11 +179,11 @@  discard block
 block discarded – undo
179 179
      */
180 180
     public function GetLearnpathScoreSingleItem($secret_key, $user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value, $learnpath_id, $learnpath_item_id) {
181 181
         $user_id = $this->getUserId($user_id_field_name, $user_id_value);
182
-        if($user_id instanceof WSError) {
182
+        if ($user_id instanceof WSError) {
183 183
             return $user_id;
184 184
         }
185 185
         $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
186
-        if($course_id instanceof WSError) {
186
+        if ($course_id instanceof WSError) {
187 187
             return $course_id;
188 188
         } else {
189 189
             $course_code = CourseManager::get_course_code_from_course_id($course_id);
@@ -213,15 +213,15 @@  discard block
 block discarded – undo
213 213
      */
214 214
     public function GetLearnpathStatusSingleItem($secret_key, $user_id_field_name, $user_id_value, $course_id_field_name, $course_id_value, $learnpath_id, $learnpath_item_id) {
215 215
         $verifKey = $this->verifyKey($secret_key);
216
-        if($verifKey instanceof WSError) {
216
+        if ($verifKey instanceof WSError) {
217 217
             $this->handleError($verifKey);
218 218
         } else {
219 219
             $user_id = $this->getUserId($user_id_field_name, $user_id_value);
220
-            if($user_id instanceof WSError) {
220
+            if ($user_id instanceof WSError) {
221 221
                 return $user_id;
222 222
             }
223 223
             $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
224
-            if($course_id instanceof WSError) {
224
+            if ($course_id instanceof WSError) {
225 225
                 return $course_id;
226 226
             } else {
227 227
                 $course_code = CourseManager::get_course_code_from_course_id($course_id);
Please login to merge, or discard this patch.
main/webservices/access_url.php 2 patches
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
     }
76 76
 
77 77
     if ($debug) {
78
-        error_log("checkip " . intval($check_ip));
78
+        error_log("checkip ".intval($check_ip));
79 79
     }
80 80
 
81 81
     if ($check_ip) {
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
     '',
132 132
     'SOAP-ENC:Array',
133 133
     array(),
134
-    array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType' => 'tns:portalItem[]')),'tns:portalItem'
134
+    array(array('ref'=>'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:portalItem[]')), 'tns:portalItem'
135 135
 );
136 136
 
137 137
 $server->wsdl->addComplexType(
@@ -146,13 +146,13 @@  discard block
 block discarded – undo
146 146
 );
147 147
 
148 148
 // Register the method to expose
149
-$server->register('WSGetPortals',                   // method name
150
-    array('getPortals' => 'tns:getPortals'),    // input parameters
151
-    array('return' => 'tns:portalList'),                    // output parameters
152
-    'urn:WSAccessUrl',                               // namespace
153
-    'urn:WSAccessUrl#WSGetPortals',              // soapaction
154
-    'rpc',                                              // style
155
-    'encoded',                                          // use
149
+$server->register('WSGetPortals', // method name
150
+    array('getPortals' => 'tns:getPortals'), // input parameters
151
+    array('return' => 'tns:portalList'), // output parameters
152
+    'urn:WSAccessUrl', // namespace
153
+    'urn:WSAccessUrl#WSGetPortals', // soapaction
154
+    'rpc', // style
155
+    'encoded', // use
156 156
     'This service adds a user to portal'               // documentation
157 157
 );
158 158
 
@@ -193,13 +193,13 @@  discard block
 block discarded – undo
193 193
 );
194 194
 
195 195
 // Register the method to expose
196
-$server->register('WSAddUserToPortal',                   // method name
197
-    array('addUserToPortal' => 'tns:AddUserToPortal'),    // input parameters
198
-    array('return' => 'xsd:string'),                    // output parameters
199
-    'urn:WSAccessUrl',                               // namespace
200
-    'urn:WSAccessUrl#WSAddUserToPortal',              // soapaction
201
-    'rpc',                                              // style
202
-    'encoded',                                          // use
196
+$server->register('WSAddUserToPortal', // method name
197
+    array('addUserToPortal' => 'tns:AddUserToPortal'), // input parameters
198
+    array('return' => 'xsd:string'), // output parameters
199
+    'urn:WSAccessUrl', // namespace
200
+    'urn:WSAccessUrl#WSAddUserToPortal', // soapaction
201
+    'rpc', // style
202
+    'encoded', // use
203 203
     'This service adds a user to portal'               // documentation
204 204
 );
205 205
 
@@ -224,13 +224,13 @@  discard block
 block discarded – undo
224 224
 }
225 225
 
226 226
 // Register the method to expose
227
-$server->register('WSRemoveUserFromPortal',                      // method name
228
-    array('removeUserFromPortal' => 'tns:AddUserToPortal'),  // input parameters
229
-    array('return' => 'xsd:string'),                            // output parameters
230
-    'urn:WSAccessUrl',                                       // namespace
231
-    'urn:WSAccessUrl#WSRemoveUserFromPortal',                 // soapaction
232
-    'rpc',                                                      // style
233
-    'encoded',                                                  // use
227
+$server->register('WSRemoveUserFromPortal', // method name
228
+    array('removeUserFromPortal' => 'tns:AddUserToPortal'), // input parameters
229
+    array('return' => 'xsd:string'), // output parameters
230
+    'urn:WSAccessUrl', // namespace
231
+    'urn:WSAccessUrl#WSRemoveUserFromPortal', // soapaction
232
+    'rpc', // style
233
+    'encoded', // use
234 234
     'This service remove a user from a portal'                  // documentation
235 235
 );
236 236
 
@@ -267,13 +267,13 @@  discard block
 block discarded – undo
267 267
 );
268 268
 
269 269
 // Register the method to expose
270
-$server->register('WSGetPortalListFromUser',                      // method name
271
-    array('getPortalListFromUser' => 'tns:getPortalListFromUser'),  // input parameters
272
-    array('return' => 'tns:portalList'),                            // output parameters
273
-    'urn:WSAccessUrl',                                       // namespace
274
-    'urn:WSAccessUrl#WSGetPortalListFromUser',                 // soapaction
275
-    'rpc',                                                      // style
276
-    'encoded',                                                  // use
270
+$server->register('WSGetPortalListFromUser', // method name
271
+    array('getPortalListFromUser' => 'tns:getPortalListFromUser'), // input parameters
272
+    array('return' => 'tns:portalList'), // output parameters
273
+    'urn:WSAccessUrl', // namespace
274
+    'urn:WSAccessUrl#WSGetPortalListFromUser', // soapaction
275
+    'rpc', // style
276
+    'encoded', // use
277 277
     'This service remove a user from a portal'                  // documentation
278 278
 );
279 279
 
@@ -311,13 +311,13 @@  discard block
 block discarded – undo
311 311
 );
312 312
 
313 313
 // Register the method to expose
314
-$server->register('WSGetPortalListFromCourse',                      // method name
315
-    array('getPortalListFromCourse' => 'tns:getPortalListFromCourse'),  // input parameters
316
-    array('return' => 'tns:portalList'),                            // output parameters
317
-    'urn:WSAccessUrl',                                       // namespace
318
-    'urn:WSAccessUrl#getPortalListFromCourse',                 // soapaction
319
-    'rpc',                                                      // style
320
-    'encoded',                                                  // use
314
+$server->register('WSGetPortalListFromCourse', // method name
315
+    array('getPortalListFromCourse' => 'tns:getPortalListFromCourse'), // input parameters
316
+    array('return' => 'tns:portalList'), // output parameters
317
+    'urn:WSAccessUrl', // namespace
318
+    'urn:WSAccessUrl#getPortalListFromCourse', // soapaction
319
+    'rpc', // style
320
+    'encoded', // use
321 321
     'This service remove a user from a portal'                  // documentation
322 322
 );
323 323
 
@@ -361,13 +361,13 @@  discard block
 block discarded – undo
361 361
 );
362 362
 
363 363
 // Register the method to expose
364
-$server->register('WSAddCourseToPortal',                   // method name
365
-    array('addCourseToPortal' => 'tns:addCourseToPortal'),    // input parameters
366
-    array('return' => 'xsd:string'),                    // output parameters
367
-    'urn:WSAccessUrl',                               // namespace
368
-    'urn:WSAccessUrl#WSAddCourseToPortal',              // soapaction
369
-    'rpc',                                              // style
370
-    'encoded',                                          // use
364
+$server->register('WSAddCourseToPortal', // method name
365
+    array('addCourseToPortal' => 'tns:addCourseToPortal'), // input parameters
366
+    array('return' => 'xsd:string'), // output parameters
367
+    'urn:WSAccessUrl', // namespace
368
+    'urn:WSAccessUrl#WSAddCourseToPortal', // soapaction
369
+    'rpc', // style
370
+    'encoded', // use
371 371
     'This service adds a course to portal'               // documentation
372 372
 );
373 373
 
@@ -394,13 +394,13 @@  discard block
 block discarded – undo
394 394
 }
395 395
 
396 396
 // Register the method to expose
397
-$server->register('WSRemoveCourseFromPortal',                      // method name
398
-    array('removeCourseFromPortal' => 'tns:addCourseToPortal'),  // input parameters
399
-    array('return' => 'xsd:string'),                            // output parameters
400
-    'urn:WSAccessUrl',                                       // namespace
401
-    'urn:WSAccessUrl#WSRemoveCourseFromPortal',                 // soapaction
402
-    'rpc',                                                      // style
403
-    'encoded',                                                  // use
397
+$server->register('WSRemoveCourseFromPortal', // method name
398
+    array('removeCourseFromPortal' => 'tns:addCourseToPortal'), // input parameters
399
+    array('return' => 'xsd:string'), // output parameters
400
+    'urn:WSAccessUrl', // namespace
401
+    'urn:WSAccessUrl#WSRemoveCourseFromPortal', // soapaction
402
+    'rpc', // style
403
+    'encoded', // use
404 404
     'This service remove a course from a portal'                  // documentation
405 405
 );
406 406
 
Please login to merge, or discard this patch.
Braces   +12 added lines, -8 removed lines patch added patch discarded remove patch
@@ -58,19 +58,22 @@  discard block
 block discarded – undo
58 58
         list($ip1, $ip2) = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
59 59
         $ip = trim($ip1);
60 60
     }
61
-    if ($debug)
62
-        error_log("ip: $ip");
61
+    if ($debug) {
62
+            error_log("ip: $ip");
63
+    }
63 64
     // Check if a file that limits access from webservices exists and contains
64 65
     // the restraining check
65 66
     if (is_file('webservice-auth-ip.conf.php')) {
66 67
         include 'webservice-auth-ip.conf.php';
67
-        if ($debug)
68
-            error_log("webservice-auth-ip.conf.php file included");
68
+        if ($debug) {
69
+                    error_log("webservice-auth-ip.conf.php file included");
70
+        }
69 71
         if (!empty($ws_auth_ip)) {
70 72
             $check_ip = true;
71 73
             $ip_matches = api_check_ip_in_range($ip, $ws_auth_ip);
72
-            if ($debug)
73
-                error_log("ip_matches: $ip_matches");
74
+            if ($debug) {
75
+                            error_log("ip_matches: $ip_matches");
76
+            }
74 77
         }
75 78
     }
76 79
 
@@ -87,8 +90,9 @@  discard block
 block discarded – undo
87 90
 
88 91
     $result = api_is_valid_secret_key($secret_key, $security_key);
89 92
     //error_log($secret_key.'-'.$security_key);
90
-    if ($debug)
91
-        error_log('WSHelperVerifyKey result: '.intval($result));
93
+    if ($debug) {
94
+            error_log('WSHelperVerifyKey result: '.intval($result));
95
+    }
92 96
     return $result;
93 97
 }
94 98
 
Please login to merge, or discard this patch.
main/webservices/webservice.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 	 * @param WSErrorHandler Error handler
50 50
 	 */
51 51
 	public static function setErrorHandler($handler) {
52
-		if($handler instanceof WSErrorHandler) {
52
+		if ($handler instanceof WSErrorHandler) {
53 53
 			self::$_handler = $handler;
54 54
 		}
55 55
 	}
@@ -114,12 +114,12 @@  discard block
 block discarded – undo
114 114
 		// if we are behind a reverse proxy, assume it will send the
115 115
 		// HTTP_X_FORWARDED_FOR header and use this IP instead
116 116
 		if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
117
-			list($ip1,$ip2) = preg_split('/,/',$_SERVER['HTTP_X_FORWARDED_FOR']);
117
+			list($ip1, $ip2) = preg_split('/,/', $_SERVER['HTTP_X_FORWARDED_FOR']);
118 118
 			$ip = trim($ip1);
119 119
 		}
120 120
 		$security_key = $ip.$this->_configuration['security_key'];
121 121
 
122
-		if(!api_is_valid_secret_key($secret_key, $security_key)) {
122
+		if (!api_is_valid_secret_key($secret_key, $security_key)) {
123 123
 			return new WSError(1, "API key is invalid");
124 124
 		} else {
125 125
 			return null;
@@ -136,15 +136,15 @@  discard block
 block discarded – undo
136 136
 	 * @return mixed System user id if the user was found, WSError otherwise
137 137
 	 */
138 138
 	protected function getUserId($user_id_field_name, $user_id_value) {
139
-		if($user_id_field_name == "chamilo_user_id") {
140
-			if(UserManager::is_user_id_valid(intval($user_id_value))) {
139
+		if ($user_id_field_name == "chamilo_user_id") {
140
+			if (UserManager::is_user_id_valid(intval($user_id_value))) {
141 141
 				return intval($user_id_value);
142 142
 			} else {
143 143
 				return new WSError(100, "User not found");
144 144
 			}
145 145
 		} else {
146 146
 			$user_id = UserManager::get_user_id_from_original_id($user_id_value, $user_id_field_name);
147
-			if($user_id == 0) {
147
+			if ($user_id == 0) {
148 148
 				return new WSError(100, "User not found");
149 149
 			} else {
150 150
 				return $user_id;
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 	protected function getSessionId($session_id_field_name, $session_id_value)
198 198
 	{
199 199
 		if ($session_id_field_name == "chamilo_session_id") {
200
-			$session = SessionManager::fetch((int)$session_id_value);
200
+			$session = SessionManager::fetch((int) $session_id_value);
201 201
 			if (!empty($session)) {
202 202
 				return intval($session_id_value);
203 203
 			} else {
Please login to merge, or discard this patch.
Indentation   +220 added lines, -220 removed lines patch added patch discarded remove patch
@@ -11,237 +11,237 @@
 block discarded – undo
11 11
  */
12 12
 class WSError
13 13
 {
14
-	/**
15
-	 * Error handler. This needs to be a class that implements the interface WSErrorHandler
16
-	 *
17
-	 * @var WSErrorHandler
18
-	 */
19
-	protected static $_handler;
20
-
21
-	/**
22
-	 * Error code
23
-	 *
24
-	 * @var int
25
-	 */
26
-	public $code;
27
-
28
-	/**
29
-	 * Error message
30
-	 *
31
-	 * @var string
32
-	 */
33
-	public $message;
34
-
35
-	/**
36
-	 * Constructor
37
-	 *
38
-	 * @param int Error code
39
-	 * @param string Error message
40
-	 */
41
-	public function __construct($code, $message) {
42
-		$this->code = $code;
43
-		$this->message = $message;
44
-	}
45
-
46
-	/**
47
-	 * Sets the error handler
48
-	 *
49
-	 * @param WSErrorHandler Error handler
50
-	 */
51
-	public static function setErrorHandler($handler) {
52
-		if($handler instanceof WSErrorHandler) {
53
-			self::$_handler = $handler;
54
-		}
55
-	}
56
-
57
-	/**
58
-	 * Returns the error handler
59
-	 *
60
-	 * @return WSErrorHandler Error handler
61
-	 */
62
-	public static function getErrorHandler() {
63
-		return self::$_handler;
64
-	}
65
-
66
-	/**
67
-	 * Transforms the error into an array
68
-	 *
69
-	 * @return array Associative array with code and message
70
-	 */
71
-	public function toArray() {
72
-		return array('code' => $this->code, 'message' => $this->message);
73
-	}
14
+    /**
15
+     * Error handler. This needs to be a class that implements the interface WSErrorHandler
16
+     *
17
+     * @var WSErrorHandler
18
+     */
19
+    protected static $_handler;
20
+
21
+    /**
22
+     * Error code
23
+     *
24
+     * @var int
25
+     */
26
+    public $code;
27
+
28
+    /**
29
+     * Error message
30
+     *
31
+     * @var string
32
+     */
33
+    public $message;
34
+
35
+    /**
36
+     * Constructor
37
+     *
38
+     * @param int Error code
39
+     * @param string Error message
40
+     */
41
+    public function __construct($code, $message) {
42
+        $this->code = $code;
43
+        $this->message = $message;
44
+    }
45
+
46
+    /**
47
+     * Sets the error handler
48
+     *
49
+     * @param WSErrorHandler Error handler
50
+     */
51
+    public static function setErrorHandler($handler) {
52
+        if($handler instanceof WSErrorHandler) {
53
+            self::$_handler = $handler;
54
+        }
55
+    }
56
+
57
+    /**
58
+     * Returns the error handler
59
+     *
60
+     * @return WSErrorHandler Error handler
61
+     */
62
+    public static function getErrorHandler() {
63
+        return self::$_handler;
64
+    }
65
+
66
+    /**
67
+     * Transforms the error into an array
68
+     *
69
+     * @return array Associative array with code and message
70
+     */
71
+    public function toArray() {
72
+        return array('code' => $this->code, 'message' => $this->message);
73
+    }
74 74
 }
75 75
 
76 76
 /**
77 77
  * Interface that must be implemented by any error handler
78 78
  */
79 79
 interface WSErrorHandler {
80
-	/**
81
-	 * Handle method
82
-	 *
83
-	 * @param WSError Error
84
-	 */
85
-	public function handle($error);
80
+    /**
81
+     * Handle method
82
+     *
83
+     * @param WSError Error
84
+     */
85
+    public function handle($error);
86 86
 }
87 87
 
88 88
 /**
89 89
  * Main class of the webservice. Webservice classes extend this class
90 90
  */
91 91
 class WS {
92
-	/**
93
-	 * Chamilo configuration
94
-	 *
95
-	 * @var array
96
-	 */
97
-	protected $_configuration;
98
-
99
-	/**
100
-	 * Constructor
101
-	 */
102
-	public function __construct() {
103
-		$this->_configuration = $GLOBALS['_configuration'];
104
-	}
105
-
106
-	/**
107
-	 * Verifies the API key
108
-	 *
109
-	 * @param string Secret key
110
-	 * @return mixed WSError in case of failure, null in case of success
111
-	 */
112
-	protected function verifyKey($secret_key) {
113
-		$ip = trim($_SERVER['REMOTE_ADDR']);
114
-		// if we are behind a reverse proxy, assume it will send the
115
-		// HTTP_X_FORWARDED_FOR header and use this IP instead
116
-		if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
117
-			list($ip1,$ip2) = preg_split('/,/',$_SERVER['HTTP_X_FORWARDED_FOR']);
118
-			$ip = trim($ip1);
119
-		}
120
-		$security_key = $ip.$this->_configuration['security_key'];
121
-
122
-		if(!api_is_valid_secret_key($secret_key, $security_key)) {
123
-			return new WSError(1, "API key is invalid");
124
-		} else {
125
-			return null;
126
-		}
127
-	}
128
-
129
-	/**
130
-	 * Gets the real user id based on the user id field name and value.
131
-	 * Note that if the user id field name is "chamilo_user_id", it will use the user id
132
-	 * in the system database
133
-	 *
134
-	 * @param string User id field name
135
-	 * @param string User id value
136
-	 * @return mixed System user id if the user was found, WSError otherwise
137
-	 */
138
-	protected function getUserId($user_id_field_name, $user_id_value) {
139
-		if($user_id_field_name == "chamilo_user_id") {
140
-			if(UserManager::is_user_id_valid(intval($user_id_value))) {
141
-				return intval($user_id_value);
142
-			} else {
143
-				return new WSError(100, "User not found");
144
-			}
145
-		} else {
146
-			$user_id = UserManager::get_user_id_from_original_id($user_id_value, $user_id_field_name);
147
-			if($user_id == 0) {
148
-				return new WSError(100, "User not found");
149
-			} else {
150
-				return $user_id;
151
-			}
152
-		}
153
-	}
154
-
155
-	/**
156
-	 * Gets the real course id based on the course id field name and value.
157
-	 * Note that if the course id field name is "chamilo_course_id", it will use the course id
158
-	 * in the system database
159
-	 *
160
-	 * @param string Course id field name
161
-	 * @param string Course id value
162
-	 * @return mixed System course id if the course was found, WSError otherwise
163
-	 */
164
-	protected function getCourseId($course_id_field_name, $course_id_value)
165
-	{
166
-		if ($course_id_field_name == "chamilo_course_id") {
167
-			if (CourseManager::get_course_code_from_course_id(
168
-					intval($course_id_value)
169
-				) != null
170
-			) {
171
-				return intval($course_id_value);
172
-			} else {
173
-				return new WSError(200, "Course not found");
174
-			}
175
-		} else {
176
-			$courseId = CourseManager::get_course_code_from_original_id(
177
-				$course_id_value,
178
-				$course_id_field_name
179
-			);
180
-			if (!empty($courseId)) {
181
-				return $courseId;
182
-			} else {
183
-				return new WSError(200, "Course not found");
184
-			}
185
-		}
186
-	}
187
-
188
-	/**
189
-	 * Gets the real session id based on the session id field name and value.
190
-	 * Note that if the session id field name is "chamilo_session_id", it will use the session id
191
-	 * in the system database
192
-	 *
193
-	 * @param string Session id field name
194
-	 * @param string Session id value
195
-	 * @return mixed System session id if the session was found, WSError otherwise
196
-	 */
197
-	protected function getSessionId($session_id_field_name, $session_id_value)
198
-	{
199
-		if ($session_id_field_name == "chamilo_session_id") {
200
-			$session = SessionManager::fetch((int)$session_id_value);
201
-			if (!empty($session)) {
202
-				return intval($session_id_value);
203
-			} else {
204
-				return new WSError(300, "Session not found");
205
-			}
206
-		} else {
207
-			$session_id = SessionManager::getSessionIdFromOriginalId(
208
-				$session_id_value,
209
-				$session_id_field_name
210
-			);
211
-			if ($session_id == 0) {
212
-				return new WSError(300, "Session not found");
213
-			} else {
214
-				return $session_id;
215
-			}
216
-		}
217
-	}
218
-
219
-	/**
220
-	 * Handles an error by calling the WSError error handler
221
-	 *
222
-	 * @param WSError Error
223
-	 */
224
-	protected function handleError($error) {
225
-		$handler = WSError::getErrorHandler();
226
-		$handler->handle($error);
227
-	}
228
-
229
-	/**
230
-	 * Gets a successful result
231
-	 *
232
-	 * @return array Array with a code of 0 and a message 'Operation was successful'
233
-	 */
234
-	protected function getSuccessfulResult() {
235
-		return array('code' => 0, 'message' => 'Operation was successful');
236
-	}
237
-
238
-	/**
239
-	 * Test function. Returns the string success
240
-	 *
241
-	 * @return string Success
242
-	 */
243
-	public function test() {
244
-		return "success";
245
-	}
92
+    /**
93
+     * Chamilo configuration
94
+     *
95
+     * @var array
96
+     */
97
+    protected $_configuration;
98
+
99
+    /**
100
+     * Constructor
101
+     */
102
+    public function __construct() {
103
+        $this->_configuration = $GLOBALS['_configuration'];
104
+    }
105
+
106
+    /**
107
+     * Verifies the API key
108
+     *
109
+     * @param string Secret key
110
+     * @return mixed WSError in case of failure, null in case of success
111
+     */
112
+    protected function verifyKey($secret_key) {
113
+        $ip = trim($_SERVER['REMOTE_ADDR']);
114
+        // if we are behind a reverse proxy, assume it will send the
115
+        // HTTP_X_FORWARDED_FOR header and use this IP instead
116
+        if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
117
+            list($ip1,$ip2) = preg_split('/,/',$_SERVER['HTTP_X_FORWARDED_FOR']);
118
+            $ip = trim($ip1);
119
+        }
120
+        $security_key = $ip.$this->_configuration['security_key'];
121
+
122
+        if(!api_is_valid_secret_key($secret_key, $security_key)) {
123
+            return new WSError(1, "API key is invalid");
124
+        } else {
125
+            return null;
126
+        }
127
+    }
128
+
129
+    /**
130
+     * Gets the real user id based on the user id field name and value.
131
+     * Note that if the user id field name is "chamilo_user_id", it will use the user id
132
+     * in the system database
133
+     *
134
+     * @param string User id field name
135
+     * @param string User id value
136
+     * @return mixed System user id if the user was found, WSError otherwise
137
+     */
138
+    protected function getUserId($user_id_field_name, $user_id_value) {
139
+        if($user_id_field_name == "chamilo_user_id") {
140
+            if(UserManager::is_user_id_valid(intval($user_id_value))) {
141
+                return intval($user_id_value);
142
+            } else {
143
+                return new WSError(100, "User not found");
144
+            }
145
+        } else {
146
+            $user_id = UserManager::get_user_id_from_original_id($user_id_value, $user_id_field_name);
147
+            if($user_id == 0) {
148
+                return new WSError(100, "User not found");
149
+            } else {
150
+                return $user_id;
151
+            }
152
+        }
153
+    }
154
+
155
+    /**
156
+     * Gets the real course id based on the course id field name and value.
157
+     * Note that if the course id field name is "chamilo_course_id", it will use the course id
158
+     * in the system database
159
+     *
160
+     * @param string Course id field name
161
+     * @param string Course id value
162
+     * @return mixed System course id if the course was found, WSError otherwise
163
+     */
164
+    protected function getCourseId($course_id_field_name, $course_id_value)
165
+    {
166
+        if ($course_id_field_name == "chamilo_course_id") {
167
+            if (CourseManager::get_course_code_from_course_id(
168
+                    intval($course_id_value)
169
+                ) != null
170
+            ) {
171
+                return intval($course_id_value);
172
+            } else {
173
+                return new WSError(200, "Course not found");
174
+            }
175
+        } else {
176
+            $courseId = CourseManager::get_course_code_from_original_id(
177
+                $course_id_value,
178
+                $course_id_field_name
179
+            );
180
+            if (!empty($courseId)) {
181
+                return $courseId;
182
+            } else {
183
+                return new WSError(200, "Course not found");
184
+            }
185
+        }
186
+    }
187
+
188
+    /**
189
+     * Gets the real session id based on the session id field name and value.
190
+     * Note that if the session id field name is "chamilo_session_id", it will use the session id
191
+     * in the system database
192
+     *
193
+     * @param string Session id field name
194
+     * @param string Session id value
195
+     * @return mixed System session id if the session was found, WSError otherwise
196
+     */
197
+    protected function getSessionId($session_id_field_name, $session_id_value)
198
+    {
199
+        if ($session_id_field_name == "chamilo_session_id") {
200
+            $session = SessionManager::fetch((int)$session_id_value);
201
+            if (!empty($session)) {
202
+                return intval($session_id_value);
203
+            } else {
204
+                return new WSError(300, "Session not found");
205
+            }
206
+        } else {
207
+            $session_id = SessionManager::getSessionIdFromOriginalId(
208
+                $session_id_value,
209
+                $session_id_field_name
210
+            );
211
+            if ($session_id == 0) {
212
+                return new WSError(300, "Session not found");
213
+            } else {
214
+                return $session_id;
215
+            }
216
+        }
217
+    }
218
+
219
+    /**
220
+     * Handles an error by calling the WSError error handler
221
+     *
222
+     * @param WSError Error
223
+     */
224
+    protected function handleError($error) {
225
+        $handler = WSError::getErrorHandler();
226
+        $handler->handle($error);
227
+    }
228
+
229
+    /**
230
+     * Gets a successful result
231
+     *
232
+     * @return array Array with a code of 0 and a message 'Operation was successful'
233
+     */
234
+    protected function getSuccessfulResult() {
235
+        return array('code' => 0, 'message' => 'Operation was successful');
236
+    }
237
+
238
+    /**
239
+     * Test function. Returns the string success
240
+     *
241
+     * @return string Success
242
+     */
243
+    public function test() {
244
+        return "success";
245
+    }
246 246
 }
247 247
 
Please login to merge, or discard this patch.
main/webservices/client_soap.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 $soap_error = $client->getError();
34 34
 
35 35
 if (!empty($soap_error)) {
36
-    $error_message = 'Nusoap object creation failed: ' . $soap_error;
36
+    $error_message = 'Nusoap object creation failed: '.$soap_error;
37 37
     throw new Exception($error_message);
38 38
 }
39 39
 $client->setDebugLevel(10000);
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 $ip_address = "127.0.0.1";
46 46
 
47 47
 //Secret key
48
-$secret_key = sha1($ip_address.$security_key);// Hash of the combination of IP Address + Chamilo security key
48
+$secret_key = sha1($ip_address.$security_key); // Hash of the combination of IP Address + Chamilo security key
49 49
 //$secret_key = sha1($security_key);
50 50
 
51 51
 //Creating a random user_id, this values need to be provided from your system
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 
94 94
 if ($err) {
95 95
     // Display the error
96
-    echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
96
+    echo '<h2>Constructor error</h2><pre>'.$err.'</pre>';
97 97
 }
98 98
 
99 99
 
@@ -325,14 +325,14 @@  discard block
 block discarded – undo
325 325
 
326 326
 if ($err) {
327 327
     // Display the error
328
-    echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
328
+    echo '<h2>Constructor error</h2><pre>'.$err.'</pre>';
329 329
 }
330 330
 
331 331
 
332 332
 //1. Create user webservice
333 333
 $result = $client->call(
334 334
     'WSGetPortals',
335
-    array('getPortals' => [    'secret_key'                => $secret_key])
335
+    array('getPortals' => ['secret_key'                => $secret_key])
336 336
 );
337 337
 
338 338
 $result = $client->call(
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
 );
364 364
 
365 365
 
366
-var_dump($user_id);exit;
366
+var_dump($user_id); exit;
367 367
 
368 368
 
369 369
 
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
     $err = $client->getError();
383 383
     if ($err) {
384 384
         // Display the error
385
-        echo '<h2>Error</h2><pre>' . $err . '</pre>';
385
+        echo '<h2>Error</h2><pre>'.$err.'</pre>';
386 386
     } else {
387 387
         // Display the result
388 388
         echo '<h2>There are no errors</h2>';
Please login to merge, or discard this patch.