|
28 | 28 | */ |
29 | 29 |
|
30 | 30 | if (!defined('GLPI_ROOT')) { |
31 | | - die("Sorry. You can't access directly to this file"); |
| 31 | + die("Sorry. You can't access directly to this file"); |
32 | 32 | } |
33 | 33 |
|
34 | 34 | /** |
35 | 35 | * Class PluginAddressingProfile |
36 | 36 | */ |
37 | | -class PluginAddressingProfile extends Profile { |
| 37 | +class PluginAddressingProfile extends Profile |
| 38 | +{ |
| 39 | + public static $rightname = "profile"; |
| 40 | + |
| 41 | + public static function getAllRights() |
| 42 | + { |
| 43 | + $rights = [ |
| 44 | + ['itemtype' => 'PluginAddressingAddressing', |
| 45 | + 'label' => __('Generate reports', 'addressing'), |
| 46 | + 'field' => 'plugin_addressing'], |
| 47 | + ['itemtype' => 'PluginAddressingAddressing', |
| 48 | + 'label' => __('Use ping on equipment form', 'addressing'), |
| 49 | + 'field' => 'plugin_addressing_use_ping_in_equipment']]; |
| 50 | + return $rights; |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Show profile form |
| 55 | + * |
| 56 | + * @param $items_id integer id of the profile |
| 57 | + * @param $target value url of target |
| 58 | + * |
| 59 | + * @return nothing |
| 60 | + **/ |
| 61 | + public function showForm($profiles_id = 0, $openform = true, $closeform = true) |
| 62 | + { |
| 63 | + echo "<div class='firstbloc'>"; |
| 64 | + if (($canedit = Session::haveRightsOr(self::$rightname, [CREATE, UPDATE, PURGE])) |
| 65 | + && $openform) { |
| 66 | + $profile = new Profile(); |
| 67 | + echo "<form method='post' action='".$profile->getFormURL()."'>"; |
| 68 | + } |
| 69 | + |
| 70 | + $profile = new Profile(); |
| 71 | + $profile->getFromDB($profiles_id); |
| 72 | + |
| 73 | + $rights = [ |
| 74 | + ['itemtype' => 'PluginAddressingAddressing', |
| 75 | + 'label' => __('Generate reports', 'addressing'), |
| 76 | + 'field' => 'plugin_addressing']]; |
| 77 | + |
| 78 | + $profile->displayRightsChoiceMatrix($rights, ['canedit' => $canedit, |
| 79 | + 'default_class' => 'tab_bg_2', |
| 80 | + 'title' => __('General')]); |
| 81 | + |
| 82 | + echo "<table class='tab_cadre_fixehov'>"; |
| 83 | + |
| 84 | + $effective_rights = ProfileRight::getProfileRights( |
| 85 | + $profiles_id, |
| 86 | + ['plugin_addressing_use_ping_in_equipment'] |
| 87 | + ); |
| 88 | + echo "<tr class='tab_bg_2'>"; |
| 89 | + echo "<td width='20%'>".__('Use ping on equipment form', 'addressing')."</td>"; |
| 90 | + echo "<td colspan='5'>"; |
| 91 | + Html::showCheckbox(['name' => '_plugin_addressing_use_ping_in_equipment[1_0]', |
| 92 | + 'checked' => $effective_rights['plugin_addressing_use_ping_in_equipment']]); |
| 93 | + echo "</td></tr>\n"; |
| 94 | + echo "</table>"; |
| 95 | + |
| 96 | + if ($canedit |
| 97 | + && $closeform) { |
| 98 | + echo "<div class='center'>"; |
| 99 | + echo Html::hidden('id', ['value' => $profiles_id]); |
| 100 | + echo Html::submit(_sx('button', 'Save'), ['name' => 'update', 'class' => 'btn btn-primary']); |
| 101 | + echo "</div>\n"; |
| 102 | + Html::closeForm(); |
| 103 | + } |
| 104 | + echo "</div>"; |
| 105 | + } |
| 106 | + |
| 107 | + public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) |
| 108 | + { |
| 109 | + if ($item->getType() == 'Profile') { |
| 110 | + if ($item->getField('interface') == 'central') { |
| 111 | + return _n('IP Adressing', 'IP Adressing', 2, 'addressing'); |
| 112 | + } |
| 113 | + return ''; |
| 114 | + } |
| 115 | + return ''; |
| 116 | + } |
| 117 | + |
| 118 | + |
| 119 | + public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) |
| 120 | + { |
| 121 | + if ($item->getType() == 'Profile') { |
| 122 | + $profile = new self(); |
| 123 | + $ID = $item->getField('id'); |
| 124 | + //In case there's no right for this profile, create it |
| 125 | + self::addDefaultProfileInfos( |
| 126 | + $item->getID(), |
| 127 | + ['plugin_addressing' => 0, |
| 128 | + 'plugin_addressing_use_ping_in_equipment' => 0] |
| 129 | + ); |
| 130 | + $profile->showForm($ID); |
| 131 | + } |
| 132 | + return true; |
| 133 | + } |
38 | 134 |
|
39 | | - static $rightname = "profile"; |
40 | | - |
41 | | - static function getAllRights() { |
42 | | - $rights = [ |
43 | | - ['itemtype' => 'PluginAddressingAddressing', |
44 | | - 'label' => __('Generate reports', 'addressing'), |
45 | | - 'field' => 'plugin_addressing'], |
46 | | - ['itemtype' => 'PluginAddressingAddressing', |
47 | | - 'label' => __('Use ping on equipment form', 'addressing'), |
48 | | - 'field' => 'plugin_addressing_use_ping_in_equipment']]; |
49 | | - return $rights; |
50 | | - } |
51 | 135 |
|
52 | 136 | /** |
53 | | - * Show profile form |
54 | | - * |
55 | | - * @param $items_id integer id of the profile |
56 | | - * @param $target value url of target |
57 | | - * |
58 | | - * @return nothing |
| 137 | + * @param $profile |
59 | 138 | **/ |
60 | | - function showForm($profiles_id = 0, $openform = true, $closeform = true) { |
61 | | - |
62 | | - echo "<div class='firstbloc'>"; |
63 | | - if (($canedit = Session::haveRightsOr(self::$rightname, [CREATE, UPDATE, PURGE])) |
64 | | - && $openform) { |
65 | | - $profile = new Profile(); |
66 | | - echo "<form method='post' action='".$profile->getFormURL()."'>"; |
67 | | - } |
68 | | - |
69 | | - $profile = new Profile(); |
70 | | - $profile->getFromDB($profiles_id); |
71 | | - |
72 | | - $rights = [ |
73 | | - ['itemtype' => 'PluginAddressingAddressing', |
74 | | - 'label' => __('Generate reports', 'addressing'), |
75 | | - 'field' => 'plugin_addressing']]; |
76 | | - |
77 | | - $profile->displayRightsChoiceMatrix($rights, ['canedit' => $canedit, |
78 | | - 'default_class' => 'tab_bg_2', |
79 | | - 'title' => __('General')]); |
80 | | - |
81 | | - echo "<table class='tab_cadre_fixehov'>"; |
82 | | - |
83 | | - $effective_rights = ProfileRight::getProfileRights($profiles_id, |
84 | | - ['plugin_addressing_use_ping_in_equipment']); |
85 | | - echo "<tr class='tab_bg_2'>"; |
86 | | - echo "<td width='20%'>".__('Use ping on equipment form', 'addressing')."</td>"; |
87 | | - echo "<td colspan='5'>"; |
88 | | - Html::showCheckbox(['name' => '_plugin_addressing_use_ping_in_equipment[1_0]', |
89 | | - 'checked' => $effective_rights['plugin_addressing_use_ping_in_equipment']]); |
90 | | - echo "</td></tr>\n"; |
91 | | - echo "</table>"; |
92 | | - |
93 | | - if ($canedit |
94 | | - && $closeform) { |
95 | | - echo "<div class='center'>"; |
96 | | - echo Html::hidden('id', ['value' => $profiles_id]); |
97 | | - echo Html::submit(_sx('button', 'Save'), ['name' => 'update', 'class' => 'btn btn-primary']); |
98 | | - echo "</div>\n"; |
99 | | - Html::closeForm(); |
100 | | - } |
101 | | - echo "</div>"; |
102 | | - } |
103 | | - |
104 | | - function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { |
105 | | - |
106 | | - if ($item->getType() == 'Profile') { |
107 | | - if ($item->getField('interface') == 'central') { |
108 | | - return _n('IP Adressing', 'IP Adressing', 2, 'addressing'); |
109 | | - } |
110 | | - return ''; |
111 | | - } |
112 | | - return ''; |
113 | | - } |
114 | | - |
115 | | - |
116 | | - static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { |
117 | | - |
118 | | - if ($item->getType() == 'Profile') { |
119 | | - $profile = new self(); |
120 | | - $ID = $item->getField('id'); |
121 | | - //In case there's no right for this profile, create it |
122 | | - self::addDefaultProfileInfos($item->getID(), |
123 | | - ['plugin_addressing' => 0, |
124 | | - 'plugin_addressing_use_ping_in_equipment' => 0]); |
125 | | - $profile->showForm($ID); |
126 | | - } |
127 | | - return true; |
128 | | - } |
129 | | - |
130 | | - |
131 | | - /** |
132 | | - * @param $profile |
133 | | - **/ |
134 | | - static function addDefaultProfileInfos($profiles_id, $rights) { |
135 | | - $profileRight = new ProfileRight(); |
136 | | - $dbu = new DbUtils(); |
137 | | - foreach ($rights as $right => $value) { |
138 | | - if (!$dbu->countElementsInTable('glpi_profilerights', |
139 | | - ["profiles_id" => $profiles_id, |
140 | | - "name" => $right])) { |
141 | | - $myright['profiles_id'] = $profiles_id; |
142 | | - $myright['name'] = $right; |
143 | | - $myright['rights'] = $value; |
144 | | - $profileRight->add($myright); |
145 | | - |
146 | | - //Add right to the current session |
147 | | - $_SESSION['glpiactiveprofile'][$right] = $value; |
148 | | - } |
149 | | - } |
150 | | - } |
151 | | - |
152 | | - /** |
153 | | - * @param $ID integer |
154 | | - */ |
155 | | - static function createFirstAccess($profiles_id) { |
| 139 | + public static function addDefaultProfileInfos($profiles_id, $rights) |
| 140 | + { |
| 141 | + $profileRight = new ProfileRight(); |
| 142 | + $dbu = new DbUtils(); |
| 143 | + foreach ($rights as $right => $value) { |
| 144 | + if (!$dbu->countElementsInTable( |
| 145 | + 'glpi_profilerights', |
| 146 | + ["profiles_id" => $profiles_id, |
| 147 | + "name" => $right] |
| 148 | + )) { |
| 149 | + $myright['profiles_id'] = $profiles_id; |
| 150 | + $myright['name'] = $right; |
| 151 | + $myright['rights'] = $value; |
| 152 | + $profileRight->add($myright); |
| 153 | + |
| 154 | + //Add right to the current session |
| 155 | + $_SESSION['glpiactiveprofile'][$right] = $value; |
| 156 | + } |
| 157 | + } |
| 158 | + } |
156 | 159 |
|
157 | | - self::addDefaultProfileInfos($profiles_id, |
158 | | - ['plugin_addressing' => ALLSTANDARDRIGHT, |
159 | | - 'plugin_addressing_use_ping_in_equipment' => '1']); |
160 | | - } |
| 160 | + /** |
| 161 | + * @param $ID integer |
| 162 | + */ |
| 163 | + public static function createFirstAccess($profiles_id) |
| 164 | + { |
| 165 | + self::addDefaultProfileInfos( |
| 166 | + $profiles_id, |
| 167 | + ['plugin_addressing' => ALLSTANDARDRIGHT, |
| 168 | + 'plugin_addressing_use_ping_in_equipment' => '1'] |
| 169 | + ); |
| 170 | + } |
161 | 171 |
|
162 | 172 |
|
163 | | - /** |
164 | | - * Initialize profiles |
165 | | - */ |
166 | | - static function initProfile() { |
167 | | - global $DB; |
| 173 | + /** |
| 174 | + * Initialize profiles |
| 175 | + */ |
| 176 | + public static function initProfile() |
| 177 | + { |
| 178 | + global $DB; |
168 | 179 |
|
169 | | - foreach ($DB->request("SELECT * |
| 180 | + foreach ($DB->request("SELECT * |
170 | 181 | FROM `glpi_profilerights` |
171 | 182 | WHERE `profiles_id`='".$_SESSION['glpiactiveprofile']['id']."' |
172 | 183 | AND `name` LIKE '%plugin_addressing%'") as $prof) { |
173 | | - $_SESSION['glpiactiveprofile'][$prof['name']] = $prof['rights']; |
174 | | - } |
175 | | - } |
176 | | - |
177 | | - static function migrateProfiles() { |
178 | | - global $DB; |
179 | | - |
180 | | - if (!$DB->tableExists('glpi_plugin_addressing_profiles')) { |
181 | | - return true; |
182 | | - } |
183 | | - $dbu = new DbUtils(); |
184 | | - $profiles = $dbu->getAllDataFromTable('glpi_plugin_addressing_profiles'); |
185 | | - foreach ($profiles as $id => $profile) { |
186 | | - switch ($profile['addressing']) { |
187 | | - case 'r' : |
188 | | - $value = READ; |
189 | | - break; |
190 | | - case 'w': |
191 | | - $value = ALLSTANDARDRIGHT; |
192 | | - break; |
193 | | - case 0: |
194 | | - default: |
195 | | - $value = 0; |
196 | | - break; |
197 | | - } |
198 | | - self::addDefaultProfileInfos($profile['profiles_id'], ['plugin_addressing' => $value]); |
199 | | - self::addDefaultProfileInfos($profile['profiles_id'], |
200 | | - ['plugin_addressing_use_ping_in_equipment' |
201 | | - => $profile['use_ping_in_equipment']]); |
202 | | - } |
203 | | - } |
204 | | - |
205 | | - |
206 | | - static function removeRightsFromSession() { |
207 | | - foreach (self::getAllRights() as $right) { |
208 | | - if (isset($_SESSION['glpiactiveprofile'][$right['field']])) { |
209 | | - unset($_SESSION['glpiactiveprofile'][$right['field']]); |
210 | | - } |
211 | | - } |
212 | | - } |
213 | | - |
| 184 | + if (isset($_SESSION['glpiactiveprofile'])) { |
| 185 | + $_SESSION['glpiactiveprofile'][$prof['name']] = $prof['rights']; |
| 186 | + } |
| 187 | + } |
| 188 | + } |
| 189 | + |
| 190 | + public static function migrateProfiles() |
| 191 | + { |
| 192 | + global $DB; |
| 193 | + |
| 194 | + if (!$DB->tableExists('glpi_plugin_addressing_profiles')) { |
| 195 | + return true; |
| 196 | + } |
| 197 | + $dbu = new DbUtils(); |
| 198 | + $profiles = $dbu->getAllDataFromTable('glpi_plugin_addressing_profiles'); |
| 199 | + foreach ($profiles as $id => $profile) { |
| 200 | + switch ($profile['addressing']) { |
| 201 | + case 'r' : |
| 202 | + $value = READ; |
| 203 | + break; |
| 204 | + case 'w': |
| 205 | + $value = ALLSTANDARDRIGHT; |
| 206 | + break; |
| 207 | + case 0: |
| 208 | + default: |
| 209 | + $value = 0; |
| 210 | + break; |
| 211 | + } |
| 212 | + self::addDefaultProfileInfos($profile['profiles_id'], ['plugin_addressing' => $value]); |
| 213 | + self::addDefaultProfileInfos( |
| 214 | + $profile['profiles_id'], |
| 215 | + ['plugin_addressing_use_ping_in_equipment' |
| 216 | + => $profile['use_ping_in_equipment']] |
| 217 | + ); |
| 218 | + } |
| 219 | + } |
| 220 | + |
| 221 | + |
| 222 | + public static function removeRightsFromSession() |
| 223 | + { |
| 224 | + foreach (self::getAllRights() as $right) { |
| 225 | + if (isset($_SESSION['glpiactiveprofile'][$right['field']])) { |
| 226 | + unset($_SESSION['glpiactiveprofile'][$right['field']]); |
| 227 | + } |
| 228 | + } |
| 229 | + } |
214 | 230 | } |
0 commit comments