Test Setup Failed
Push — master ( ec638a...cb9435 )
by Julito
51:10
created

permissions_functions.inc.php ➔ get_roles()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 15
nc 8
nop 3
dl 0
loc 22
rs 8.9197
c 0
b 0
f 0
1
<?php
2
/**
3
 * This files contains the common functions for the permissions
4
 *
5
 * A list of all the functions (in no particular order)
6
 * ----------------------------------------------------
7
 *    store_permissions($content,$id)
8
 *    get_permissions($content,$id)
9
 *    limited_or_full($current_permissions)
10
 * @author Patrick Cool <[email protected]>, Ghent University
11
 * @package chamilo.permissions
12
 */
13
14
/**
15
 * This function stores the permissions in the correct table.
16
 * Since Checkboxes are used we do not know which ones are unchecked.
17
 * That's why we first delete them all (for the given user/group/role
18
 * and afterwards we store the checked ones only.
19
 * @param $content are we storing rights for a user, a group or a role (the database depends on it)
20
 * @param $id the id of the user, group or role
21
 * @author Patrick Cool <[email protected]>, Ghent University
22
 * @version 1.0
23
 */
24
function store_permissions($content, $id)
25
{
26
    $course_id = api_get_course_int_id();
27
28
    // Which database are we using (depending on the $content parameter)
29
    if ($content == 'user') {
30
        $table = Database::get_course_table(TABLE_PERMISSION_USER);
31
        $id_field = user_id;
32
    }
33
    if ($content == 'group') {
34
        $table = Database::get_course_table(TABLE_PERMISSION_GROUP);
35
        $id_field = group_id;
36
    }
37
    if ($content == 'role') {
38
        $table = Database::get_course_table(TABLE_ROLE_PERMISSION);
39
        $id_field = role_id;
40
    }
41
42
    // We first delete all the existing permissions for that user/group/role
43
    $sql = "DELETE FROM $table  WHERE c_id = $course_id AND $id_field = '".Database::escape_string($id)."'";
44
    $result = Database::query($sql);
45
46
    // looping through the post values to find the permission (containing the string permission* )
47
    foreach ($_POST as $key => $value) {
48
        if (strstr($key, "permission*")) {
49
            list($brol, $tool, $action) = explode("*", $key);
0 ignored issues
show
Unused Code introduced by
The assignment to $brol is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
50
            $sql = "INSERT INTO $table (c_id, $id_field,tool,action) VALUES ($course_id, '".Database::escape_string($id)."','".Database::escape_string($tool)."','".Database::escape_string($action)."')";
51
            $result = Database::query($sql);
52
        }
53
    }
54
55
    return get_lang('PermissionsStored');
56
}
57
58
/**
59
* This function stores one permission in the correct table.
60
* @param $content are we storing rights for a user, a group or a role (the database depends on it)
61
* @param $action are we granting or revoking a permission?
62
* @param $id the id of the user, group or role
63
* @param $tool the tool
64
* @param $permission the permission the user, group or role has been granted or revoked
65
* @author Patrick Cool <[email protected]>, Ghent University
66
* @version 1.0
67
*/
68
function store_one_permission($content, $action, $id, $tool, $permission)
69
{
70
    global $rights_full;
71
    $course_id = api_get_course_int_id();
72
    // for some reason I don't know, he can't get to the $rights_full array, so commented the following lines out.
73
74
    // check
75
    //if(!in_array($permission, $rights_full))
76
    //{
77
    //	return get_lang('Error');
78
    //}
79
80
    // Which database are we using (depending on the $content parameter)
81
82
    if ($content == 'user') {
83
        $table = Database::get_course_table(TABLE_PERMISSION_USER);
84
        $id_field = user_id;
85
    }
86
    if ($content == 'group') {
87
        $table = Database::get_course_table(TABLE_PERMISSION_GROUP);
88
        $id_field = group_id;
89
    }
90
    if ($content == 'role') {
91
        $table = Database::get_course_table(TABLE_ROLE_PERMISSION);
92
        $id_field = role_id;
93
    }
94
95
    // grating a right
96 View Code Duplication
    if ($action == 'grant') {
97
        $sql = "INSERT INTO $table (c_id, $id_field,tool,action) VALUES ($course_id, '".Database::escape_string($id)."','".Database::escape_string($tool)."','".Database::escape_string($permission)."')";
98
        $result = Database::query($sql);
99
        if ($result) {
100
            $result_message = get_lang('PermissionGranted');
101
        }
102
    }
103 View Code Duplication
    if ($action == 'revoke') {
104
        $sql = "DELETE FROM $table WHERE c_id = $course_id AND $id_field = '".Database::escape_string($id)."' AND tool='".Database::escape_string($tool)."' AND action='".Database::escape_string($permission)."'";
105
        $result = Database::query($sql);
106
        if ($result) {
107
            $result_message = get_lang('PermissionRevoked');
108
        }
109
    }
110
111
    return $result_message;
112
}
113
114
/**
115
* This function retrieves the existing permissions of a user, group or role.
116
* @param $content are we retrieving the rights of a user, a group or a role (the database depends on it)
117
* @param $id the id of the user, group or role
118
* @author Patrick Cool <[email protected]>, Ghent University
119
* @version 1.0
120
*/
121
function get_permissions($content, $id)
122
{
123
    $course_id = api_get_course_int_id();
124
    $currentpermissions = array();
125
    // Which database are we using (depending on the $content parameter)
126
    $course_id_condition = " c_id = $course_id AND ";
127
    if ($content == 'user') {
128
        $table = Database::get_course_table(TABLE_PERMISSION_USER);
129
        $id_field = 'user_id';
130
    } elseif ($content == 'group') {
131
        $table = Database::get_course_table(TABLE_PERMISSION_GROUP);
132
        $id_field = 'group_id';
133
    } elseif ($content == 'role') {
134
        $table = Database::get_course_table(TABLE_ROLE_PERMISSION);
135
        $id_field = 'role_id';
136
    } elseif ($content == 'platform_role') {
137
        $table = Database::get_main_table(TABLE_ROLE_PERMISSION);
138
        $id_field = 'role_id';
139
        $course_id_condition = '';
140
    } elseif ($content == 'task') {
141
        $table = Database::get_course_table(TABLE_BLOGS_TASKS_PERMISSIONS);
142
        $id_field = 'task_id';
143
    }
144
145
    // finding all the permissions. We store this in a multidimensional array
146
    // where the first dimension is the tool.
147
    $sql = "
148
        SELECT * FROM " . $table."
149
        WHERE $course_id_condition ".$id_field."='".Database::escape_string($id)."'";
150
    $result = Database::query($sql);
151
152
    while ($row = Database::fetch_array($result)) {
153
        $currentpermissions[$row['tool']][] = $row['action'];
154
    }
155
156
    return $currentpermissions;
157
}
158
159
/**
160
* the array that contains the current permission a user, group or role has will now be changed depending on
161
* the Dokeos Config Setting for the permissions (limited [add, edit, delete] or full [view, add, edit, delete, move, visibility]
162
* @param $content are we retrieving the rights of a user, a group or a role (the database depends on it)
163
* @param $id the id of the user, group or role
164
* @author Patrick Cool <[email protected]>, Ghent University
165
* @version 1.0
166
* @todo currently there is a setting user_permissions and group_permissions. We should merge this in one config setting.
167
*/
168
function limited_or_full($current_permissions)
169
{
170
    if (api_get_setting('permissions') == 'limited') {
171
        foreach ($current_permissions as $tool => $tool_rights) {
172
            // we loop through the possible permissions of a tool and unset the entry if it is view
173
            // if it is visibility or move we have to grant the edit right
174
            foreach ($tool_rights as $key => $value) {
175
                if ($value == 'View') {
176
                    unset($current_permissions[$tool][$key]);
177
                }
178
                if ($value == 'Visibility' OR $value == 'Move') {
179
                    if (!in_array('Edit', $current_permissions[$tool])) {
180
                        $current_permissions[$tool][] = 'Edit';
181
                    }
182
                    unset($current_permissions[$tool][$key]);
183
                }
184
                //else
185
                //{
186
                //	$current_permissions[$tool][]=$value;
187
                //}
188
            }
189
        }
190
        return $current_permissions;
191
    }
192
    if (api_get_setting('permissions') == 'full') {
193
        return $current_permissions;
194
    }
195
}
196
/**
197
* This function displays a checked or unchecked checkbox. The checkbox will be checked if the
198
* user, group or role has the permission for the given tool, unchecked if the user, group or role
199
* does not have the right
200
* @param $permission_array the array that contains all the permissions of the user, group, role
201
* @param $tool the tool we want to check a permission for
202
* @param $permission the permission we want to check for
203
* @author Patrick Cool <[email protected]>, Ghent University
204
* @version 1.0
205
*/
206
function display_checkbox_matrix($permission_array, $tool, $permission, $inherited_permissions = array())
207
{
208
    $checked = "";
209
    if (is_array($permission_array[$tool]) AND in_array($permission, $permission_array[$tool]))
210
    {
211
        $checked = "checked";
212
    }
213
    echo "\t\t\t<input type=\"checkbox\" name=\"permission*$tool*$permission\" $checked>\n";
214
215
}
216
217
/**
218
* This function displays a checked or unchecked image. The image will be checked if the
219
* user, group or role has the permission for the given tool, unchecked if the user, group or role
220
* does not have the right
221
* @param $permission_array the array that contains all the permissions of the user, group, role
222
* @param $tool the tool we want to check a permission for
223
* @param $permission the permission we want to check for
224
* @author Patrick Cool <[email protected]>, Ghent University
225
* @version 1.0
226
*/
227
function display_image_matrix($permission_array, $tool, $permission, $inherited_permissions = array(), $course_admin = false, $editable = true)
228
{
229
    if ($course_admin) {
230
        echo "\t\t\t<img src=\"../img/checkbox_on3.gif\" border=\"0\"/ title=\"".get_lang('PermissionGrantedByGroupOrRole')."\">";
231
    } else {
232
        if (in_array($permission, $inherited_permissions[$tool])) {
233
            echo "\t\t\t<img src=\"../img/checkbox_on3.gif\" border=\"0\"/ title=\"".get_lang('PermissionGrantedByGroupOrRole')."\">";
234
        } else {
235
            if (is_array($permission_array[$tool]) AND in_array($permission, $permission_array[$tool])) {
236 View Code Duplication
                if ($editable) {
237
                    $url = api_get_self();
238
                    $urlparameters = '';
239
                    foreach ($_GET as $key=>$value) {
240
                        $parameter[$key] = $value;
241
                    }
242
                    $parameter['action'] = 'revoke';
243
                    $parameter['permission'] = $permission;
244
                    $parameter['tool'] = $tool;
245
                    foreach ($parameter as $key=>$value) {
246
                        $urlparameters .= $key.'='.$value.'&amp;';
247
                    }
248
                    $url = $url.'?'.$urlparameters;
249
250
                    echo "\t\t\t <a href=\"".$url."\">";
251
                }
252
                echo "<img src=\"../img/checkbox_on2.gif\" border=\"0\"/>";
253
                if ($editable) {
254
                    echo "</a>";
255
                }
256
            } else {
257 View Code Duplication
                if ($editable)
258
                {
259
                    $url = api_get_self();
260
                    $urlparameters = '';
261
                    foreach ($_GET as $key => $value) {
262
                        $parameter[$key] = $value;
263
                    }
264
                    $parameter['action'] = 'grant';
265
                    $parameter['permission'] = $permission;
266
                    $parameter['tool'] = $tool;
267
                    foreach ($parameter as $key => $value) {
268
                        $urlparameters .= $key.'='.$value.'&amp;';
269
                    }
270
                    $url = $url.'?'.$urlparameters;
271
272
                    //echo "\t\t\t <a href=\"".str_replace('&', '&amp;', $_SERVER['REQUEST_URI'])."&amp;action=grant&amp;permission=$permission&amp;tool=$tool\">";
273
                    echo "\t\t\t <a href=\"".$url."\">";
274
                }
275
                echo "<img src=\"../img/wrong.gif\" border=\"0\"/>";
276
                if ($editable)
277
                {
278
                    echo "</a>";
279
                }
280
            }
281
        }
282
    }
283
}
284
285
286
/**
287
* Slightly modified:  Toon Keppens
288
* This function displays a checked or unchecked image. The image will be checked if the
289
* user, group or role has the permission for the given tool, unchecked if the user, group or role
290
* does not have the right
291
* @param $permission_array the array that contains all the permissions of the user, group, role
292
* @param $tool the tool we want to check a permission for
293
* @param $permission the permission we want to check for
294
* @author Patrick Cool <[email protected]>, Ghent University
295
* @version 1.0
296
*/
297
function display_image_matrix_for_blogs($permission_array, $user_id, $tool, $permission, $inherited_permissions = array(), $course_admin = false, $editable = true)
298
{
299
    if ($course_admin) {
300
        echo "\t\t\t<img src=\"../img/checkbox_on3.gif\" border=\"0\"/ title=\"".get_lang('PermissionGrantedByGroupOrRole')."\">";
301
    } else {
302
        if (!empty($inherited_permissions) and in_array($permission, $inherited_permissions[$tool])) {
303
            echo "\t\t\t<img src=\"../img/checkbox_on3.gif\" border=\"0\"/ title=\"".get_lang('PermissionGrantedByGroupOrRole')."\">";
304
        } else {
305
            if (is_array($permission_array[$tool]) AND in_array($permission, $permission_array[$tool])) {
306 View Code Duplication
                if ($editable) {
307
                    $url = api_get_self();
308
                    $urlparameters = '';
309
                    foreach ($_GET as $key => $value)
310
                    {
311
                        $parameter[$key] = $value;
312
                    }
313
                    $parameter['action'] = 'manage_rights';
314
                    $parameter['do'] = 'revoke';
315
                    $parameter['permission'] = $permission;
316
                    $parameter['tool'] = $tool;
317
                    $parameter['user_id'] = $user_id;
318
                    foreach ($parameter as $key=>$value)
319
                    {
320
                        $urlparameters .= $key.'='.$value.'&amp;';
321
                    }
322
                    $url = $url.'?'.$urlparameters;
323
324
                    echo "\t\t\t <a href=\"".$url."\">";
325
                }
326
                echo "<img src=\"../img/checkbox_on2.gif\" border=\"0\"/ title=\"".get_lang('UserHasPermission')."\">";
327
                if ($editable) {
328
                    echo "</a>";
329
                }
330
            } else {
331 View Code Duplication
                if ($editable) {
332
                    $url = api_get_self();
333
                    $urlparameters = '';
334
                    foreach ($_GET as $key => $value) {
335
                        $parameter[$key] = $value;
336
                    }
337
                    $parameter['action'] = 'manage_rights';
338
                    $parameter['do'] = 'grant';
339
                    $parameter['permission'] = $permission;
340
                    $parameter['tool'] = $tool;
341
                    $parameter['user_id'] = $user_id;
342
                    foreach ($parameter as $key=>$value) {
343
                        $urlparameters .= $key.'='.$value.'&amp;';
344
                    }
345
                    $url = $url.'?'.$urlparameters;
346
347
                    //echo "\t\t\t <a href=\"".str_replace('&', '&amp;', $_SERVER['REQUEST_URI'])."&amp;action=grant&amp;permission=$permission&amp;tool=$tool\">";
348
                    echo "\t\t\t <a href=\"".$url."\">";
349
                }
350
                echo "<img src=\"../img/wrong.gif\" border=\"0\"/ title=\"".get_lang('UserHasPermissionNot')."\">";
351
                if ($editable) {
352
                    echo "</a>";
353
                }
354
            }
355
        }
356
    }
357
}
358
359
360
/**
361
* This function displays a list off all the roles of the course (and those defined by the platform admin)
362
* @author Patrick Cool <[email protected]>, Ghent University
363
* @version 1.0
364
*/
365
function display_role_list($current_course_roles, $current_platform_roles)
366
{
367
    global $setting_visualisation;
368
    $course_id = api_get_course_int_id();
369
370
    $coures_roles_table = Database::get_course_table(TABLE_ROLE);
371
372
    // course roles
373
    $sql = "SELECT * FROM $coures_roles_table WHERE c_id = $course_id ";
374
    $result = Database::query($sql);
375
    while ($row = Database::fetch_array($result)) {
376
        if (in_array($row['role_id'], $current_course_roles)) {
377
            $checked = 'checked';
378
            $image = 'checkbox_on2.gif';
379
            $action = 'revoke';
380
        } else {
381
            $checked = '';
382
            $image = 'wrong.gif';
383
            $action = 'grant';
384
        }
385
        if ($setting_visualisation == 'checkbox') {
386
            echo "<input type=\"checkbox\" name=\"role*course*".$row['role_id']."\" $checked>";
387
        }
388
        if ($setting_visualisation == 'image') {
389
            echo "<a href=\"".str_replace('&', '&amp;', $_SERVER['REQUEST_URI'])."&amp;action=$action&amp;role=".$row['role_id']."&amp;scope=course\"><img src=\"../img/".$image."\" border=\"0\"/></a>";
390
        }
391
392
393
        echo $row['role_name']." <a href=\"../permissions/roles.php?role_id=".$row['role_id']."&amp;scope=course\"><img src=\"../img/edit.gif\" /></a><br />\n";
394
        echo $row['role_comment']."<br />\n";
395
    }
396
}
397
398
/**
399
* This function gets all the current roles of the user or group
400
* @param $content are we finding the roles for a user or a group (the database depends on it)
401
* @param $id the id of the user or group
402
* @return array that contains the name of the roles the user has
403
* @todo consider having a separate table that contains only an id and a name of the role.
404
* @author Patrick Cool <[email protected]>, Ghent University
405
* @version 1.0
406
*/
407
function get_roles($content, $id, $scope = 'course')
408
{
409
    $course_id = api_get_course_int_id();
410
    if ($content == 'user') {
411
        $table = Database::get_course_table(TABLE_ROLE_USER);
412
        $id_field = user_id;
413
    }
414
    if ($content == 'group') {
415
        $table = Database::get_course_table(TABLE_ROLE_GROUP);
416
        $id_field = 'group_id';
417
    }
418
    $table_role = Database::get_course_table(TABLE_ROLE);
419
420
    $current_roles = array();
421
    //$sql="SELECT role.role_id FROM $table role_group_user, $table_role role WHERE role_group_user.$id_field = '$id' AND role_group_user.role_id=role.role_id AND role_group_user.scope='".$scope."'";$sql="SELECT role.role_id FROM $table role_group_user, $table_role role WHERE role_group_user.$id_field = '$id' AND role_group_user.role_id=role.role_id AND role_group_user.scope='".$scope."'";
422
    $sql = "SELECT role_id FROM $table WHERE c_id = $course_id AND $id_field = '$id' AND scope='".$scope."'";
423
    $result = Database::query($sql);
424
    while ($row = Database::fetch_array($result)) {
425
        $current_roles[] = $row['role_id'];
426
    }
427
    return $current_roles;
428
}
429
430
/**
431
* This function gets all the current roles of the user or group
432
* @return array that contains the name of the roles the user has
433
* @author Patrick Cool <[email protected]>, Ghent University
434
* @version 1.0
435
*/
436
function get_all_roles($content = 'course') {
437
    $course_id = api_get_course_int_id();
438
    $course_id_condition = " WHERE c_id = $course_id ";
439
440
    if ($content == 'course')
441
    {
442
        $table_role = Database::get_course_table(TABLE_ROLE);
443
    }
444
    if ($content == 'platform')
445
    {
446
        $table_role = Database::get_main_table(TABLE_ROLE);
447
        $course_id_condition = '';
448
    }
449
450
    $current_roles = array();
451
    $sql = "SELECT * FROM $table_role $course_id_condition ";
452
    $result = Database::query($sql);
453
    while ($row = Database::fetch_array($result))
454
    {
455
        $roles[] = $row;
456
    }
457
458
    return $roles;
459
}
460
461
/**
462
* This function gets all the roles that are defined
463
* @param $content are we finding the roles for a user or a group (the database depends on it)
464
* @param $id the id of the user or group
465
* @param string	Deprecated parameter allowing use of 'platform' scope - the corresponding tables don't exist anymore so the scope is always set to 'course'
466
* @return array that contains the name of the roles the user has
467
* @todo consider having a separate table that contains only an id and a name of the role.
468
* @author Patrick Cool <[email protected]>, Ghent University
469
* @version 1.0
470
*/
471
function get_roles_permissions($content, $id, $scope = 'course')
472
{
473
    $course_id = api_get_course_int_id();
474
    if ($content == 'user') {
475
        $table = Database::get_course_table(TABLE_ROLE_USER);
476
        $id_field = 'user_id';
477
    }
478
479
    if ($content == 'group') {
480
        $table = Database::get_course_table(TABLE_ROLE_GROUP);
481
        $id_field = 'group_id';
482
    }
483
484
    // course roles or platform roles
485
    $scope = 'course';
486
    if ($scope == 'course') {
487
        $table_role = Database::get_course_table(TABLE_ROLE);
488
        $table_role_permissions = Database::get_course_table(TABLE_ROLE_PERMISSION);
489
490
        $role_condition = " role.c_id = $course_id AND role_permissions.c_id = $course_id AND ";
491
    }
492
493
    if ($scope == 'platform') {
494
        $table_role = Database::get_main_table(TABLE_ROLE);
495
        $table_role_permissions = Database::get_main_table(TABLE_ROLE_PERMISSION);
496
        $role_condition = '';
497
    }
498
499
    $sql = "
500
        SELECT *
501
        FROM
502
            " . $table." role_group_user,
503
            " . $table_role." role,
504
            " . $table_role_permissions." role_permissions
505
        WHERE
506
            role_group_user.c_id = $course_id AND
507
            $role_condition
508
            role_group_user.scope = '".$scope."' AND
509
            role_group_user." . $id_field." = '".$id."' AND
510
            role_group_user.role_id = role.role_id AND
511
            role.role_id = role_permissions.role_id";
512
513
    $result = Database::query($sql);
514
    $current_role_permissions = array();
515
    while ($row = Database::fetch_array($result)) {
516
        $current_role_permissions[$row['tool']][] = $row['action'];
517
    }
518
    return $current_role_permissions;
519
}
520
521
/**
522
* This function is called when we assign a role to a user or a group
523
* @param $content are we assigning a role to a group or a user
524
* @param $action we can grant a role to a group or user or revoke it
525
* @param $id the user_id of the user or the group_id of the group
526
* @param $role_id the id of the role we are giving to a user or a group.
527
* @author Patrick Cool <[email protected]>, Ghent University
528
*/
529
function assign_role($content, $action, $id, $role_id, $scope = 'course')
530
{
531
    $course_id = api_get_course_int_id();
532
    // Which database are we using (depending on the $content parameter)
533
    if ($content == 'user') {
534
        $table = Database::get_course_table(TABLE_ROLE_USER);
535
        $id_field = 'user_id';
536
    } elseif ($content == 'group') {
537
        $table = Database::get_course_table(TABLE_ROLE_GROUP);
538
        $id_field = 'group_id';
539
    } else {
540
        return  get_lang('Error');
541
    }
542
543
    // grating a right
544 View Code Duplication
    if ($action == 'grant') {
545
        $sql = "INSERT INTO $table (c_id, role_id, scope, $id_field) VALUES ($course_id, '".Database::escape_string($role_id)."','".Database::escape_string($scope)."','".Database::escape_string($id)."')";
546
        $result = Database::query($sql);
547
        if ($result) {
548
            $result_message = get_lang('RoleGranted');
549
        }
550
    }
551
552 View Code Duplication
    if ($action == 'revoke') {
553
        $sql = "DELETE FROM $table WHERE c_id = $course_id AND $id_field = '".Database::escape_string($id)."' AND role_id='".Database::escape_string($role_id)."'";
554
        $result = Database::query($sql);
555
        if ($result) {
556
            $result_message = get_lang('RoleRevoked');
557
        }
558
    }
559
    return $result_message;
560
}
561
562
563
/**
564
 * This function merges permission arrays. Each permission array has the
565
 * following structure
566
 * a permission array has a tool contanst as a key and an array as a value.
567
 * This value array consists of all the permissions that are granted in that tool.
568
 */
569
function permission_array_merge($array1, $array2)
570
{
571
    foreach ($array2 as $tool => $permissions) {
572
        foreach ($permissions as $permissionkey => $permissionvalue) {
573
            $array1[$tool][] = $permissionvalue;
574
        }
575
    }
576
    return $array1;
577
}
578
579
function my_print_r($array)
580
{
581
    echo '<pre>';
582
    print_r($array);
583
    echo '</pre>';
584
}