corrade-http-templates – Blame information for rev

Subversion Repositories:
Rev:
Rev Author Line No. Line
2 eva 1 <?php
2  
3 ###########################################################################
4 ## Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 ##
5 ###########################################################################
6 ## This is a script that removes a Corrade group. ##
7 ###########################################################################
8  
9 ###########################################################################
10 ## GET POST VARIABLES ##
11 ###########################################################################
12  
13 if(!isset($_POST['group'])) return -1;
14  
15 ###########################################################################
16 ## CONFIGURATION ##
17 ###########################################################################
18  
19 # The path to the configuration.
20 include_once('config.php');
21  
22 ###########################################################################
23 ## INTERNALS ##
24 ###########################################################################
25  
26 # This function searches for a Corrade group and deletes it.
27 # The JSON must contain "Name" set to the name of the group and "UUID"
28 # set to the UUID of the group to be deleted.
29 function RemoveCorradeGroup($domDocument, $JSONdata) {
30 $JSONdata = json_decode($JSONdata);
31 $groups = $domDocument->getElementsByTagName('Groups');
32 if($groups->length == 0) return $domDocument;
33 foreach($groups[0]->getElementsByTagName('Group') as $group) {
34 if(
35 $group->getElementsByTagName('Name')[0]->nodeValue !=
36 $JSONdata->Name &&
37 $group->getElementsByTagName('UUID')[0]->
38 getElementsByTagName('Guid')[0]->nodeValue !=
39 $JSONdata->UUID
40 ) continue;
41 $groups[0]->removeChild($group);
42 break;
43 }
44 return $domDocument;
45 }
46  
47 # This function checks whether a Corrade group by name and UUID exists.
48 # The JSON must contain "Name" set to the name of the group and "UUID"
49 # set to the UUID of the group to be searched.
50 function DoesCorradeGroupExist($domDocument, $JSONdata) {
51 $JSONdata = json_decode($JSONdata);
52 $groups = $domDocument->getElementsByTagName('Groups');
53 if($groups->length == 0) return false;
54 foreach($groups[0]->getElementsByTagName('Group') as $group) {
55 if(
56 $group->getElementsByTagName('Name')[0]-> nodeValue ==
57 $JSONdata->Name &&
58 $group->getElementsByTagName('UUID')[0]->
59 getElementsByTagName('Guid')[0]->nodeValue ==
60 $JSONdata->UUID
61 ) return true;
62 }
63 return false;
64 }
65  
66 ###########################################################################
67 ## DEMO ##
68 ###########################################################################
69  
70 ####
71 # I. Read the configuration file.
72 $doc = new DomDocument("1.0");
73 # This is needed to preserve the indenting of Corrade.ini
74 $doc->formatOutput = true;
75 $doc->preserveWhiteSpace = false;
76 $doc->load('Corrade.ini');
77  
78 ####
79 # II. Delete a group if it exists.
80 switch(DoesCorradeGroupExist($doc, $_POST['group'])) {
81 case true: # only remove the group if it exists
82 $doc = RemoveCorradeGroup($doc, $_POST['group']);
83 break;
84 default: # the group does not exist - panic!
85 break;
86 }
87  
88 ####
89 # III. Save the configuration file.
90 $doc->save('Corrade.ini');
91  
92  
93 ?>