Rev 1293 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1293 | Rev 1294 | ||
---|---|---|---|
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 array $params |
29 | * @param array $params |
30 | * @return array |
30 | * @return array |
31 | * @throws OIDplusException |
31 | * @throws OIDplusException |
32 | */ |
32 | */ |
33 | private function action_Update(array $params): array { |
33 | private function action_Update(array $params): array { |
34 | _CheckParamExists($params, 'email'); |
34 | _CheckParamExists($params, 'email'); |
35 | 35 | ||
36 | $email = $params['email']; |
36 | $email = $params['email']; |
37 | 37 | ||
38 | if (!OIDplus::authUtils()->isRaLoggedIn($email) && !OIDplus::authUtils()->isAdminLoggedIn()) { |
38 | if (!OIDplus::authUtils()->isRaLoggedIn($email) && !OIDplus::authUtils()->isAdminLoggedIn()) { |
39 | throw new OIDplusException(_L('Authentication error. Please log in as admin, or as the RA to update its data.'), null, 401); |
39 | throw new OIDplusException(_L('Authentication error. Please log in as admin, or as the RA to update its data.'), null, 401); |
40 | } |
40 | } |
41 | 41 | ||
42 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($email)); |
42 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($email)); |
43 | if (!$res->any()) { |
43 | if (!$res->any()) { |
44 | throw new OIDplusException(_L('RA does not exist')); |
44 | throw new OIDplusException(_L('RA does not exist')); |
45 | } |
45 | } |
46 | 46 | ||
47 | OIDplus::logger()->log("V2:[OK/WARN]RA(%1)+[OK/INFO]A", "Changed RA '%1' contact data/details", $email); |
47 | OIDplus::logger()->log("V2:[OK/WARN]RA(%1)+[OK/INFO]A", "Changed RA '%1' contact data/details", $email); |
48 | 48 | ||
49 | if (isset($params['ra_name'])) |
49 | if (isset($params['ra_name'])) |
50 | OIDplus::db()->query("UPDATE ###ra SET ra_name = ? WHERE email = ?", array($params['ra_name'], $email)); |
50 | OIDplus::db()->query("UPDATE ###ra SET ra_name = ? WHERE email = ?", array($params['ra_name'], $email)); |
51 | if (isset($params['organization'])) |
51 | if (isset($params['organization'])) |
52 | OIDplus::db()->query("UPDATE ###ra SET organization = ? WHERE email = ?", array($params['organization'], $email)); |
52 | OIDplus::db()->query("UPDATE ###ra SET organization = ? WHERE email = ?", array($params['organization'], $email)); |
53 | if (isset($params['office'])) |
53 | if (isset($params['office'])) |
54 | OIDplus::db()->query("UPDATE ###ra SET office = ? WHERE email = ?", array($params['office'], $email)); |
54 | OIDplus::db()->query("UPDATE ###ra SET office = ? WHERE email = ?", array($params['office'], $email)); |
55 | if (isset($params['personal_name'])) |
55 | if (isset($params['personal_name'])) |
56 | OIDplus::db()->query("UPDATE ###ra SET personal_name = ? WHERE email = ?", array($params['personal_name'], $email)); |
56 | OIDplus::db()->query("UPDATE ###ra SET personal_name = ? WHERE email = ?", array($params['personal_name'], $email)); |
57 | if (isset($params['privacy'])) |
57 | if (isset($params['privacy'])) |
58 | OIDplus::db()->query("UPDATE ###ra SET privacy = ? WHERE email = ?", array($params['privacy'] == 'true', $email)); |
58 | OIDplus::db()->query("UPDATE ###ra SET privacy = ? WHERE email = ?", array(oidplus_is_true($params['privacy']), $email)); |
59 | if (isset($params['street'])) |
59 | if (isset($params['street'])) |
60 | OIDplus::db()->query("UPDATE ###ra SET street = ? WHERE email = ?", array($params['street'], $email)); |
60 | OIDplus::db()->query("UPDATE ###ra SET street = ? WHERE email = ?", array($params['street'], $email)); |
61 | if (isset($params['zip_town'])) |
61 | if (isset($params['zip_town'])) |
62 | OIDplus::db()->query("UPDATE ###ra SET zip_town = ? WHERE email = ?", array($params['zip_town'], $email)); |
62 | OIDplus::db()->query("UPDATE ###ra SET zip_town = ? WHERE email = ?", array($params['zip_town'], $email)); |
63 | if (isset($params['country'])) |
63 | if (isset($params['country'])) |
64 | OIDplus::db()->query("UPDATE ###ra SET country = ? WHERE email = ?", array($params['country'], $email)); |
64 | OIDplus::db()->query("UPDATE ###ra SET country = ? WHERE email = ?", array($params['country'], $email)); |
65 | if (isset($params['phone'])) |
65 | if (isset($params['phone'])) |
66 | OIDplus::db()->query("UPDATE ###ra SET phone = ? WHERE email = ?", array($params['phone'], $email)); |
66 | OIDplus::db()->query("UPDATE ###ra SET phone = ? WHERE email = ?", array($params['phone'], $email)); |
67 | if (isset($params['mobile'])) |
67 | if (isset($params['mobile'])) |
68 | OIDplus::db()->query("UPDATE ###ra SET mobile = ? WHERE email = ?", array($params['mobile'], $email)); |
68 | OIDplus::db()->query("UPDATE ###ra SET mobile = ? WHERE email = ?", array($params['mobile'], $email)); |
69 | if (isset($params['fax'])) |
69 | if (isset($params['fax'])) |
70 | OIDplus::db()->query("UPDATE ###ra SET fax = ? WHERE email = ?", array($params['fax'], $email)); |
70 | OIDplus::db()->query("UPDATE ###ra SET fax = ? WHERE email = ?", array($params['fax'], $email)); |
71 | 71 | ||
72 | OIDplus::db()->query("UPDATE ###ra SET updated = ".OIDplus::db()->sqlDate()." WHERE email = ?", array($email)); |
72 | OIDplus::db()->query("UPDATE ###ra SET updated = ".OIDplus::db()->sqlDate()." WHERE email = ?", array($email)); |
73 | 73 | ||
74 | return array("status" => 0); |
74 | return array("status" => 0); |
75 | } |
75 | } |
76 | 76 | ||
77 | /** |
77 | /** |
78 | * @param string $actionID |
78 | * @param string $actionID |
79 | * @param array $params |
79 | * @param array $params |
80 | * @return array |
80 | * @return array |
81 | * @throws OIDplusException |
81 | * @throws OIDplusException |
82 | */ |
82 | */ |
83 | public function action(string $actionID, array $params): array { |
83 | public function action(string $actionID, array $params): array { |
84 | if ($actionID == 'change_ra_data') { |
84 | if ($actionID == 'change_ra_data') { |
85 | return $this->action_Update($params); |
85 | return $this->action_Update($params); |
86 | } else { |
86 | } else { |
87 | return parent::action($actionID, $params); |
87 | return parent::action($actionID, $params); |
88 | } |
88 | } |
89 | } |
89 | } |
90 | 90 | ||
91 | /** |
91 | /** |
92 | * @param bool $html |
92 | * @param bool $html |
93 | * @return void |
93 | * @return void |
94 | */ |
94 | */ |
95 | public function init(bool $html=true) { |
95 | public function init(bool $html=true) { |
96 | // Nothing |
96 | // Nothing |
97 | } |
97 | } |
98 | 98 | ||
99 | /** |
99 | /** |
100 | * @param string $id |
100 | * @param string $id |
101 | * @param array $out |
101 | * @param array $out |
102 | * @param bool $handled |
102 | * @param bool $handled |
103 | * @return void |
103 | * @return void |
104 | * @throws OIDplusException |
104 | * @throws OIDplusException |
105 | */ |
105 | */ |
106 | public function gui(string $id, array &$out, bool &$handled) { |
106 | public function gui(string $id, array &$out, bool &$handled) { |
107 | if (explode('$',$id)[0] == 'oidplus:edit_ra') { |
107 | if (explode('$',$id)[0] == 'oidplus:edit_ra') { |
108 | $handled = true; |
108 | $handled = true; |
109 | 109 | ||
110 | $ra_email = explode('$',$id)[1]; |
110 | $ra_email = explode('$',$id)[1]; |
111 | 111 | ||
112 | $out['title'] = _L('Edit RA contact data'); |
112 | $out['title'] = _L('Edit RA contact data'); |
113 | $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png' : ''; |
113 | $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png' : ''; |
114 | 114 | ||
115 | if (!OIDplus::authUtils()->isRaLoggedIn($ra_email) && !OIDplus::authUtils()->isAdminLoggedIn()) { |
115 | if (!OIDplus::authUtils()->isRaLoggedIn($ra_email) && !OIDplus::authUtils()->isAdminLoggedIn()) { |
116 | throw new OIDplusHtmlException(_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>'), $out['title'], 401); |
116 | throw new OIDplusHtmlException(_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>'), $out['title'], 401); |
117 | } |
117 | } |
118 | 118 | ||
119 | $out['text'] = '<p>'._L('Your email address: %1','<b>'.htmlentities($ra_email).'</b>').'</p>'; |
119 | $out['text'] = '<p>'._L('Your email address: %1','<b>'.htmlentities($ra_email).'</b>').'</p>'; |
120 | 120 | ||
121 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($ra_email)); |
121 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($ra_email)); |
122 | if (!$res->any()) { |
122 | if (!$res->any()) { |
123 | throw new OIDplusHtmlException(_L('RA "%1" does not exist','<b>'.htmlentities($ra_email).'</b>'), $out['title']); |
123 | throw new OIDplusHtmlException(_L('RA "%1" does not exist','<b>'.htmlentities($ra_email).'</b>'), $out['title']); |
124 | } |
124 | } |
125 | $row = $res->fetch_array(); |
125 | $row = $res->fetch_array(); |
126 | 126 | ||
127 | $changeEMailPlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.102'); // OIDplusPageRaChangeEMail |
127 | $changeEMailPlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.102'); // OIDplusPageRaChangeEMail |
128 | if (!is_null($changeEMailPlugin) && OIDplus::config()->getValue('allow_ra_email_change')) { |
128 | if (!is_null($changeEMailPlugin) && OIDplus::config()->getValue('allow_ra_email_change')) { |
129 | $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:change_ra_email$'.$ra_email).'>'._L('Change email address').'</a></p>'; |
129 | $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:change_ra_email$'.$ra_email).'>'._L('Change email address').'</a></p>'; |
130 | } else { |
130 | } else { |
131 | $out['text'] .= '<p><b>'._L('How to change the email address?').'</b> '._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.').'</p>'; |
131 | $out['text'] .= '<p><b>'._L('How to change the email address?').'</b> '._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.').'</p>'; |
132 | } |
132 | } |
133 | 133 | ||
134 | // --- |
134 | // --- |
135 | 135 | ||
136 | $out['text'] .= '<p>'._L('Change basic information (public)').':</p> |
136 | $out['text'] .= '<p>'._L('Change basic information (public)').':</p> |
137 | <form id="raChangeContactDataForm" action="javascript:void(0);" onsubmit="return OIDplusPageRaEditContactData.raChangeContactDataFormOnSubmit();"> |
137 | <form id="raChangeContactDataForm" action="javascript:void(0);" onsubmit="return OIDplusPageRaEditContactData.raChangeContactDataFormOnSubmit();"> |
138 | <input type="hidden" id="email" value="'.htmlentities($ra_email).'"/> |
138 | <input type="hidden" id="email" value="'.htmlentities($ra_email).'"/> |
139 | <div><label class="padding_label">'._L('RA Name').':</label><input type="text" id="ra_name" value="'.htmlentities($row['ra_name']??'').'"/></div> |
139 | <div><label class="padding_label">'._L('RA Name').':</label><input type="text" id="ra_name" value="'.htmlentities($row['ra_name']??'').'"/></div> |
140 | <div><label class="padding_label">'._L('Organization').':</label><input type="text" id="organization" value="'.htmlentities($row['organization']??'').'"/></div> |
140 | <div><label class="padding_label">'._L('Organization').':</label><input type="text" id="organization" value="'.htmlentities($row['organization']??'').'"/></div> |
141 | <div><label class="padding_label">'._L('Office').':</label><input type="text" id="office" value="'.htmlentities($row['office']??'').'"/></div> |
141 | <div><label class="padding_label">'._L('Office').':</label><input type="text" id="office" value="'.htmlentities($row['office']??'').'"/></div> |
142 | <div><label class="padding_label">'._L('Person name').':</label><input type="text" id="personal_name" value="'.htmlentities($row['personal_name']??'').'"/></div> |
142 | <div><label class="padding_label">'._L('Person name').':</label><input type="text" id="personal_name" value="'.htmlentities($row['personal_name']??'').'"/></div> |
143 | <br> |
143 | <br> |
144 | <div><label class="padding_label">'._L('Privacy').'</label><input type="checkbox" id="privacy" value="" '.($row['privacy'] == 'true' ? ' checked' : '').'/> <label for="privacy">'._L('Hide postal address and Phone/Fax/Mobile Numbers').'</label></div> |
144 | <div><label class="padding_label">'._L('Privacy').'</label><input type="checkbox" id="privacy" value="" '.(oidplus_is_true($row['privacy'] ?? false) ? ' checked' : '').'/> <label for="privacy">'._L('Hide postal address and Phone/Fax/Mobile Numbers').'</label></div> |
145 | <div><label class="padding_label">'._L('Street').':</label><input type="text" id="street" value="'.htmlentities($row['street']??'').'"/></div> |
145 | <div><label class="padding_label">'._L('Street').':</label><input type="text" id="street" value="'.htmlentities($row['street']??'').'"/></div> |
146 | <div><label class="padding_label">'._L('ZIP/Town').':</label><input type="text" id="zip_town" value="'.htmlentities($row['zip_town']??'').'"/></div> |
146 | <div><label class="padding_label">'._L('ZIP/Town').':</label><input type="text" id="zip_town" value="'.htmlentities($row['zip_town']??'').'"/></div> |
147 | <div><label class="padding_label">'._L('Country').':</label><input type="text" id="country" value="'.htmlentities($row['country']??'').'"/></div> |
147 | <div><label class="padding_label">'._L('Country').':</label><input type="text" id="country" value="'.htmlentities($row['country']??'').'"/></div> |
148 | <div><label class="padding_label">'._L('Phone').':</label><input type="text" id="phone" value="'.htmlentities($row['phone']??'').'"/></div> |
148 | <div><label class="padding_label">'._L('Phone').':</label><input type="text" id="phone" value="'.htmlentities($row['phone']??'').'"/></div> |
149 | <div><label class="padding_label">'._L('Mobile').':</label><input type="text" id="mobile" value="'.htmlentities($row['mobile']??'').'"/></div> |
149 | <div><label class="padding_label">'._L('Mobile').':</label><input type="text" id="mobile" value="'.htmlentities($row['mobile']??'').'"/></div> |
150 | <div><label class="padding_label">'._L('Fax').':</label><input type="text" id="fax" value="'.htmlentities($row['fax']??'').'"/></div> |
150 | <div><label class="padding_label">'._L('Fax').':</label><input type="text" id="fax" value="'.htmlentities($row['fax']??'').'"/></div> |
151 | <br><input type="submit" value="'._L('Change data').'"> |
151 | <br><input type="submit" value="'._L('Change data').'"> |
152 | </form><br><br>'; |
152 | </form><br><br>'; |
153 | 153 | ||
154 | $raBasePlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.1.1'); // OIDplusPagePublicRaBaseUtils |
154 | $raBasePlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.1.1'); // OIDplusPagePublicRaBaseUtils |
155 | if (!is_null($raBasePlugin)) { |
155 | if (!is_null($raBasePlugin)) { |
156 | $out['text'] .= '<p><a href="#" onclick="return OIDplusPagePublicRaBaseUtils.deleteRa('.js_escape($ra_email).',\'oidplus:system\')">'._L('Delete profile').'</a> '._L('(objects stay active)').'</p>'; |
156 | $out['text'] .= '<p><a href="#" onclick="return OIDplusPagePublicRaBaseUtils.deleteRa('.js_escape($ra_email).',\'oidplus:system\')">'._L('Delete profile').'</a> '._L('(objects stay active)').'</p>'; |
157 | } |
157 | } |
158 | } |
158 | } |
159 | } |
159 | } |
160 | 160 | ||
161 | /** |
161 | /** |
162 | * @param array $json |
162 | * @param array $json |
163 | * @param string|null $ra_email |
163 | * @param string|null $ra_email |
164 | * @param bool $nonjs |
164 | * @param bool $nonjs |
165 | * @param string $req_goto |
165 | * @param string $req_goto |
166 | * @return bool |
166 | * @return bool |
167 | * @throws OIDplusException |
167 | * @throws OIDplusException |
168 | */ |
168 | */ |
169 | public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool { |
169 | public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool { |
170 | if (!$ra_email) return false; |
170 | if (!$ra_email) return false; |
171 | if (!OIDplus::authUtils()->isRaLoggedIn($ra_email) && !OIDplus::authUtils()->isAdminLoggedIn()) return false; |
171 | if (!OIDplus::authUtils()->isRaLoggedIn($ra_email) && !OIDplus::authUtils()->isAdminLoggedIn()) return false; |
172 | 172 | ||
173 | if (file_exists(__DIR__.'/img/main_icon16.png')) { |
173 | if (file_exists(__DIR__.'/img/main_icon16.png')) { |
174 | $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png'; |
174 | $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png'; |
175 | } else { |
175 | } else { |
176 | $tree_icon = null; // default icon (folder) |
176 | $tree_icon = null; // default icon (folder) |
177 | } |
177 | } |
178 | 178 | ||
179 | $json[] = array( |
179 | $json[] = array( |
180 | 'id' => 'oidplus:edit_ra$'.$ra_email, |
180 | 'id' => 'oidplus:edit_ra$'.$ra_email, |
181 | 'icon' => $tree_icon, |
181 | 'icon' => $tree_icon, |
182 | 'text' => _L('Edit RA contact data') |
182 | 'text' => _L('Edit RA contact data') |
183 | ); |
183 | ); |
184 | 184 | ||
185 | return true; |
185 | return true; |
186 | } |
186 | } |
187 | 187 | ||
188 | /** |
188 | /** |
189 | * @param string $request |
189 | * @param string $request |
190 | * @return array|false |
190 | * @return array|false |
191 | */ |
191 | */ |
192 | public function tree_search(string $request) { |
192 | public function tree_search(string $request) { |
193 | return false; |
193 | return false; |
194 | } |
194 | } |
195 | } |
195 | } |
196 | 196 |