Rev 1116 | Rev 1166 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1116 | Rev 1143 | ||
---|---|---|---|
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * OIDplus 2.0 |
4 | * OIDplus 2.0 |
5 | * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft |
5 | * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft |
6 | * |
6 | * |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | * you may not use this file except in compliance with the License. |
8 | * you may not use this file except in compliance with the License. |
9 | * You may obtain a copy of the License at |
9 | * You may obtain a copy of the License at |
10 | * |
10 | * |
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
12 | * |
12 | * |
13 | * Unless required by applicable law or agreed to in writing, software |
13 | * Unless required by applicable law or agreed to in writing, software |
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | * See the License for the specific language governing permissions and |
16 | * See the License for the specific language governing permissions and |
17 | * limitations under the License. |
17 | * limitations under the License. |
18 | */ |
18 | */ |
19 | 19 | ||
20 | namespace ViaThinkSoft\OIDplus; |
20 | namespace ViaThinkSoft\OIDplus; |
21 | 21 | ||
22 | // phpcs:disable PSR1.Files.SideEffects |
22 | // phpcs:disable PSR1.Files.SideEffects |
23 | \defined('INSIDE_OIDPLUS') or die; |
23 | \defined('INSIDE_OIDPLUS') or die; |
24 | // phpcs:enable PSR1.Files.SideEffects |
24 | // phpcs:enable PSR1.Files.SideEffects |
25 | 25 | ||
26 | class OIDplusPageRaEditContactData extends OIDplusPagePluginRa { |
26 | class OIDplusPageRaEditContactData extends OIDplusPagePluginRa { |
27 | 27 | ||
28 | /** |
28 | /** |
29 | * @param string $actionID |
29 | * @param string $actionID |
30 | * @param array $params |
30 | * @param array $params |
31 | * @return int[] |
31 | * @return array |
32 | * @throws OIDplusException |
32 | * @throws OIDplusException |
33 | */ |
33 | */ |
34 | public function action(string $actionID, array $params): array { |
34 | public function action(string $actionID, array $params): array { |
35 | if ($actionID == 'change_ra_data') { |
35 | if ($actionID == 'change_ra_data') { |
36 | _CheckParamExists($params, 'email'); |
36 | _CheckParamExists($params, 'email'); |
37 | 37 | ||
38 | $email = $params['email']; |
38 | $email = $params['email']; |
39 | 39 | ||
40 | if (!OIDplus::authUtils()->isRaLoggedIn($email) && !OIDplus::authUtils()->isAdminLoggedIn()) { |
40 | if (!OIDplus::authUtils()->isRaLoggedIn($email) && !OIDplus::authUtils()->isAdminLoggedIn()) { |
41 | throw new OIDplusException(_L('Authentication error. Please log in as admin, or as the RA to update its data.')); |
41 | throw new OIDplusException(_L('Authentication error. Please log in as admin, or as the RA to update its data.')); |
42 | } |
42 | } |
43 | 43 | ||
44 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($email)); |
44 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($email)); |
45 | if (!$res->any()) { |
45 | if (!$res->any()) { |
46 | throw new OIDplusException(_L('RA does not exist')); |
46 | throw new OIDplusException(_L('RA does not exist')); |
47 | } |
47 | } |
48 | 48 | ||
49 | OIDplus::logger()->log("[?WARN/!OK]RA($email)?/[?INFO/!OK]A?", "Changed RA '$email' contact data/details"); |
49 | OIDplus::logger()->log("[?WARN/!OK]RA($email)?/[?INFO/!OK]A?", "Changed RA '$email' contact data/details"); |
50 | 50 | ||
51 | if (isset($params['ra_name'])) |
51 | if (isset($params['ra_name'])) |
52 | OIDplus::db()->query("UPDATE ###ra SET ra_name = ? WHERE email = ?", array($params['ra_name'], $email)); |
52 | OIDplus::db()->query("UPDATE ###ra SET ra_name = ? WHERE email = ?", array($params['ra_name'], $email)); |
53 | if (isset($params['organization'])) |
53 | if (isset($params['organization'])) |
54 | OIDplus::db()->query("UPDATE ###ra SET organization = ? WHERE email = ?", array($params['organization'], $email)); |
54 | OIDplus::db()->query("UPDATE ###ra SET organization = ? WHERE email = ?", array($params['organization'], $email)); |
55 | if (isset($params['office'])) |
55 | if (isset($params['office'])) |
56 | OIDplus::db()->query("UPDATE ###ra SET office = ? WHERE email = ?", array($params['office'], $email)); |
56 | OIDplus::db()->query("UPDATE ###ra SET office = ? WHERE email = ?", array($params['office'], $email)); |
57 | if (isset($params['personal_name'])) |
57 | if (isset($params['personal_name'])) |
58 | OIDplus::db()->query("UPDATE ###ra SET personal_name = ? WHERE email = ?", array($params['personal_name'], $email)); |
58 | OIDplus::db()->query("UPDATE ###ra SET personal_name = ? WHERE email = ?", array($params['personal_name'], $email)); |
59 | if (isset($params['privacy'])) |
59 | if (isset($params['privacy'])) |
60 | OIDplus::db()->query("UPDATE ###ra SET privacy = ? WHERE email = ?", array($params['privacy'], $email)); |
60 | OIDplus::db()->query("UPDATE ###ra SET privacy = ? WHERE email = ?", array($params['privacy'], $email)); |
61 | if (isset($params['street'])) |
61 | if (isset($params['street'])) |
62 | OIDplus::db()->query("UPDATE ###ra SET street = ? WHERE email = ?", array($params['street'], $email)); |
62 | OIDplus::db()->query("UPDATE ###ra SET street = ? WHERE email = ?", array($params['street'], $email)); |
63 | if (isset($params['zip_town'])) |
63 | if (isset($params['zip_town'])) |
64 | OIDplus::db()->query("UPDATE ###ra SET zip_town = ? WHERE email = ?", array($params['zip_town'], $email)); |
64 | OIDplus::db()->query("UPDATE ###ra SET zip_town = ? WHERE email = ?", array($params['zip_town'], $email)); |
65 | if (isset($params['country'])) |
65 | if (isset($params['country'])) |
66 | OIDplus::db()->query("UPDATE ###ra SET country = ? WHERE email = ?", array($params['country'], $email)); |
66 | OIDplus::db()->query("UPDATE ###ra SET country = ? WHERE email = ?", array($params['country'], $email)); |
67 | if (isset($params['phone'])) |
67 | if (isset($params['phone'])) |
68 | OIDplus::db()->query("UPDATE ###ra SET phone = ? WHERE email = ?", array($params['phone'], $email)); |
68 | OIDplus::db()->query("UPDATE ###ra SET phone = ? WHERE email = ?", array($params['phone'], $email)); |
69 | if (isset($params['mobile'])) |
69 | if (isset($params['mobile'])) |
70 | OIDplus::db()->query("UPDATE ###ra SET mobile = ? WHERE email = ?", array($params['mobile'], $email)); |
70 | OIDplus::db()->query("UPDATE ###ra SET mobile = ? WHERE email = ?", array($params['mobile'], $email)); |
71 | if (isset($params['fax'])) |
71 | if (isset($params['fax'])) |
72 | OIDplus::db()->query("UPDATE ###ra SET fax = ? WHERE email = ?", array($params['fax'], $email)); |
72 | OIDplus::db()->query("UPDATE ###ra SET fax = ? WHERE email = ?", array($params['fax'], $email)); |
73 | 73 | ||
74 | OIDplus::db()->query("UPDATE ###ra SET updated = ".OIDplus::db()->sqlDate()." WHERE email = ?", array($email)); |
74 | OIDplus::db()->query("UPDATE ###ra SET updated = ".OIDplus::db()->sqlDate()." WHERE email = ?", array($email)); |
75 | 75 | ||
76 | return array("status" => 0); |
76 | return array("status" => 0); |
77 | } else { |
77 | } else { |
78 | return parent::action($actionID, $params); |
78 | return parent::action($actionID, $params); |
79 | } |
79 | } |
80 | } |
80 | } |
81 | 81 | ||
82 | /** |
82 | /** |
83 | * @param bool $html |
83 | * @param bool $html |
84 | * @return void |
84 | * @return void |
85 | */ |
85 | */ |
86 | public function init(bool $html=true) { |
86 | public function init(bool $html=true) { |
87 | // Nothing |
87 | // Nothing |
88 | } |
88 | } |
89 | 89 | ||
90 | /** |
90 | /** |
91 | * @param string $id |
91 | * @param string $id |
92 | * @param array $out |
92 | * @param array $out |
93 | * @param bool $handled |
93 | * @param bool $handled |
94 | * @return void |
94 | * @return void |
95 | * @throws OIDplusException |
95 | * @throws OIDplusException |
96 | */ |
96 | */ |
97 | public function gui(string $id, array &$out, bool &$handled) { |
97 | public function gui(string $id, array &$out, bool &$handled) { |
98 | if (explode('$',$id)[0] == 'oidplus:edit_ra') { |
98 | if (explode('$',$id)[0] == 'oidplus:edit_ra') { |
99 | $handled = true; |
99 | $handled = true; |
100 | 100 | ||
101 | $ra_email = explode('$',$id)[1]; |
101 | $ra_email = explode('$',$id)[1]; |
102 | 102 | ||
103 | $out['title'] = _L('Edit RA contact data'); |
103 | $out['title'] = _L('Edit RA contact data'); |
104 | $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png' : ''; |
104 | $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png' : ''; |
105 | 105 | ||
106 | if (!OIDplus::authUtils()->isRaLoggedIn($ra_email) && !OIDplus::authUtils()->isAdminLoggedIn()) { |
106 | if (!OIDplus::authUtils()->isRaLoggedIn($ra_email) && !OIDplus::authUtils()->isAdminLoggedIn()) { |
107 | $out['icon'] = 'img/error.png'; |
107 | $out['icon'] = 'img/error.png'; |
108 | $out['text'] = '<p>'._L('You need to <a %1>log in</a> as the requested RA %2.',OIDplus::gui()->link('oidplus:login$ra$'.$ra_email),'<b>'.htmlentities($ra_email).'</b>').'</p>'; |
108 | $out['text'] = '<p>'._L('You need to <a %1>log in</a> as the requested RA %2.',OIDplus::gui()->link('oidplus:login$ra$'.$ra_email),'<b>'.htmlentities($ra_email).'</b>').'</p>'; |
109 | return; |
109 | return; |
110 | } |
110 | } |
111 | 111 | ||
112 | $out['text'] = '<p>'._L('Your email address: %1','<b>'.htmlentities($ra_email).'</b>').'</p>'; |
112 | $out['text'] = '<p>'._L('Your email address: %1','<b>'.htmlentities($ra_email).'</b>').'</p>'; |
113 | 113 | ||
114 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($ra_email)); |
114 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($ra_email)); |
115 | if (!$res->any()) { |
115 | if (!$res->any()) { |
116 | $out['icon'] = 'img/error.png'; |
116 | $out['icon'] = 'img/error.png'; |
117 | $out['text'] = _L('RA "%1" does not exist','<b>'.htmlentities($ra_email).'</b>'); |
117 | $out['text'] = _L('RA "%1" does not exist','<b>'.htmlentities($ra_email).'</b>'); |
118 | return; |
118 | return; |
119 | } |
119 | } |
120 | $row = $res->fetch_array(); |
120 | $row = $res->fetch_array(); |
121 | 121 | ||
122 | $changeEMailPlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.102'); // OIDplusPageRaChangeEMail |
122 | $changeEMailPlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.102'); // OIDplusPageRaChangeEMail |
123 | if (!is_null($changeEMailPlugin) && OIDplus::config()->getValue('allow_ra_email_change')) { |
123 | if (!is_null($changeEMailPlugin) && OIDplus::config()->getValue('allow_ra_email_change')) { |
124 | $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:change_ra_email$'.$ra_email).'>'._L('Change email address').'</a></p>'; |
124 | $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:change_ra_email$'.$ra_email).'>'._L('Change email address').'</a></p>'; |
125 | } else { |
125 | } else { |
126 | $out['text'] .= '<p><abbr title="'._L('To change the email address, you need to contact the admin or superior RA. They will need to change the email address and invite you (with your new email address) again.').'">'._L('How to change the email address?').'</abbr></p>'; |
126 | $out['text'] .= '<p><abbr title="'._L('To change the email address, you need to contact the admin or superior RA. They will need to change the email address and invite you (with your new email address) again.').'">'._L('How to change the email address?').'</abbr></p>'; |
127 | } |
127 | } |
128 | 128 | ||
129 | // --- |
129 | // --- |
130 | 130 | ||
131 | $out['text'] .= '<p>'._L('Change basic information (public)').':</p> |
131 | $out['text'] .= '<p>'._L('Change basic information (public)').':</p> |
132 | <form id="raChangeContactDataForm" action="javascript:void(0);" onsubmit="return OIDplusPageRaEditContactData.raChangeContactDataFormOnSubmit();"> |
132 | <form id="raChangeContactDataForm" action="javascript:void(0);" onsubmit="return OIDplusPageRaEditContactData.raChangeContactDataFormOnSubmit();"> |
133 | <input type="hidden" id="email" value="'.htmlentities($ra_email).'"/> |
133 | <input type="hidden" id="email" value="'.htmlentities($ra_email).'"/> |
134 | <div><label class="padding_label">'._L('RA Name').':</label><input type="text" id="ra_name" value="'.htmlentities($row['ra_name']).'"/></div> |
134 | <div><label class="padding_label">'._L('RA Name').':</label><input type="text" id="ra_name" value="'.htmlentities($row['ra_name']).'"/></div> |
135 | <div><label class="padding_label">'._L('Organization').':</label><input type="text" id="organization" value="'.htmlentities($row['organization']).'"/></div> |
135 | <div><label class="padding_label">'._L('Organization').':</label><input type="text" id="organization" value="'.htmlentities($row['organization']).'"/></div> |
136 | <div><label class="padding_label">'._L('Office').':</label><input type="text" id="office" value="'.htmlentities($row['office']).'"/></div> |
136 | <div><label class="padding_label">'._L('Office').':</label><input type="text" id="office" value="'.htmlentities($row['office']).'"/></div> |
137 | <div><label class="padding_label">'._L('Person name').':</label><input type="text" id="personal_name" value="'.htmlentities($row['personal_name']).'"/></div> |
137 | <div><label class="padding_label">'._L('Person name').':</label><input type="text" id="personal_name" value="'.htmlentities($row['personal_name']).'"/></div> |
138 | <br> |
138 | <br> |
139 | <div><label class="padding_label">'._L('Privacy').'</label><input type="checkbox" id="privacy" value="" '.($row['privacy'] == 1 ? ' checked' : '').'/> <label for="privacy">'._L('Hide postal address and Phone/Fax/Mobile Numbers').'</label></div> |
139 | <div><label class="padding_label">'._L('Privacy').'</label><input type="checkbox" id="privacy" value="" '.($row['privacy'] == 1 ? ' checked' : '').'/> <label for="privacy">'._L('Hide postal address and Phone/Fax/Mobile Numbers').'</label></div> |
140 | <div><label class="padding_label">'._L('Street').':</label><input type="text" id="street" value="'.htmlentities($row['street']).'"/></div> |
140 | <div><label class="padding_label">'._L('Street').':</label><input type="text" id="street" value="'.htmlentities($row['street']).'"/></div> |
141 | <div><label class="padding_label">'._L('ZIP/Town').':</label><input type="text" id="zip_town" value="'.htmlentities($row['zip_town']).'"/></div> |
141 | <div><label class="padding_label">'._L('ZIP/Town').':</label><input type="text" id="zip_town" value="'.htmlentities($row['zip_town']).'"/></div> |
142 | <div><label class="padding_label">'._L('Country').':</label><input type="text" id="country" value="'.htmlentities($row['country']).'"/></div> |
142 | <div><label class="padding_label">'._L('Country').':</label><input type="text" id="country" value="'.htmlentities($row['country']).'"/></div> |
143 | <div><label class="padding_label">'._L('Phone').':</label><input type="text" id="phone" value="'.htmlentities($row['phone']).'"/></div> |
143 | <div><label class="padding_label">'._L('Phone').':</label><input type="text" id="phone" value="'.htmlentities($row['phone']).'"/></div> |
144 | <div><label class="padding_label">'._L('Mobile').':</label><input type="text" id="mobile" value="'.htmlentities($row['mobile']).'"/></div> |
144 | <div><label class="padding_label">'._L('Mobile').':</label><input type="text" id="mobile" value="'.htmlentities($row['mobile']).'"/></div> |
145 | <div><label class="padding_label">'._L('Fax').':</label><input type="text" id="fax" value="'.htmlentities($row['fax']).'"/></div> |
145 | <div><label class="padding_label">'._L('Fax').':</label><input type="text" id="fax" value="'.htmlentities($row['fax']).'"/></div> |
146 | <br><input type="submit" value="'._L('Change data').'"> |
146 | <br><input type="submit" value="'._L('Change data').'"> |
147 | </form><br><br>'; |
147 | </form><br><br>'; |
148 | 148 | ||
149 | $raBasePlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.1.1'); // OIDplusPagePublicRaBaseUtils |
149 | $raBasePlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.1.1'); // OIDplusPagePublicRaBaseUtils |
150 | if (!is_null($raBasePlugin)) { |
150 | if (!is_null($raBasePlugin)) { |
151 | $out['text'] .= '<p><a href="#" onclick="return OIDplusPagePublicRaBaseUtils.deleteRa('.js_escape($ra_email).',\'oidplus:system\')">'._L('Delete profile').'</a> '._L('(objects stay active)').'</p>'; |
151 | $out['text'] .= '<p><a href="#" onclick="return OIDplusPagePublicRaBaseUtils.deleteRa('.js_escape($ra_email).',\'oidplus:system\')">'._L('Delete profile').'</a> '._L('(objects stay active)').'</p>'; |
152 | } |
152 | } |
153 | } |
153 | } |
154 | } |
154 | } |
155 | 155 | ||
156 | /** |
156 | /** |
157 | * @param array $json |
157 | * @param array $json |
158 | * @param string|null $ra_email |
158 | * @param string|null $ra_email |
159 | * @param bool $nonjs |
159 | * @param bool $nonjs |
160 | * @param string $req_goto |
160 | * @param string $req_goto |
161 | * @return bool |
161 | * @return bool |
162 | * @throws OIDplusException |
162 | * @throws OIDplusException |
163 | */ |
163 | */ |
164 | public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool { |
164 | public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool { |
165 | if (!$ra_email) return false; |
165 | if (!$ra_email) return false; |
166 | if (!OIDplus::authUtils()->isRaLoggedIn($ra_email) && !OIDplus::authUtils()->isAdminLoggedIn()) return false; |
166 | if (!OIDplus::authUtils()->isRaLoggedIn($ra_email) && !OIDplus::authUtils()->isAdminLoggedIn()) return false; |
167 | 167 | ||
168 | if (file_exists(__DIR__.'/img/main_icon16.png')) { |
168 | if (file_exists(__DIR__.'/img/main_icon16.png')) { |
169 | $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png'; |
169 | $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png'; |
170 | } else { |
170 | } else { |
171 | $tree_icon = null; // default icon (folder) |
171 | $tree_icon = null; // default icon (folder) |
172 | } |
172 | } |
173 | 173 | ||
174 | $json[] = array( |
174 | $json[] = array( |
175 | 'id' => 'oidplus:edit_ra$'.$ra_email, |
175 | 'id' => 'oidplus:edit_ra$'.$ra_email, |
176 | 'icon' => $tree_icon, |
176 | 'icon' => $tree_icon, |
177 | 'text' => _L('Edit RA contact data') |
177 | 'text' => _L('Edit RA contact data') |
178 | ); |
178 | ); |
179 | 179 | ||
180 | return true; |
180 | return true; |
181 | } |
181 | } |
182 | 182 | ||
183 | /** |
183 | /** |
184 | * @param string $request |
184 | * @param string $request |
185 | * @return array|false |
185 | * @return array|false |
186 | */ |
186 | */ |
187 | public function tree_search(string $request) { |
187 | public function tree_search(string $request) { |
188 | return false; |
188 | return false; |
189 | } |
189 | } |
190 | } |
190 | } |
191 | 191 |