Rev 801 | Rev 1082 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 801 | Rev 1050 | ||
---|---|---|---|
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * OIDplus 2.0 |
4 | * OIDplus 2.0 |
5 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
5 | * Copyright 2019 - 2021 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 | if (!defined('INSIDE_OIDPLUS')) die(); |
20 | namespace ViaThinkSoft\OIDplus; |
21 | 21 | ||
22 | class OIDplusPageRaEditContactData extends OIDplusPagePluginRa { |
22 | class OIDplusPageRaEditContactData extends OIDplusPagePluginRa { |
23 | 23 | ||
24 | public function action($actionID, $params) { |
24 | public function action($actionID, $params) { |
25 | if ($actionID == 'change_ra_data') { |
25 | if ($actionID == 'change_ra_data') { |
26 | _CheckParamExists($params, 'email'); |
26 | _CheckParamExists($params, 'email'); |
27 | 27 | ||
28 | $email = $params['email']; |
28 | $email = $params['email']; |
29 | 29 | ||
30 | if (!OIDplus::authUtils()->isRaLoggedIn($email) && !OIDplus::authUtils()->isAdminLoggedIn()) { |
30 | if (!OIDplus::authUtils()->isRaLoggedIn($email) && !OIDplus::authUtils()->isAdminLoggedIn()) { |
31 | throw new OIDplusException(_L('Authentication error. Please log in as admin, or as the RA to update its data.')); |
31 | throw new OIDplusException(_L('Authentication error. Please log in as admin, or as the RA to update its data.')); |
32 | } |
32 | } |
33 | 33 | ||
34 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($email)); |
34 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($email)); |
35 | if (!$res->any()) { |
35 | if (!$res->any()) { |
36 | throw new OIDplusException(_L('RA does not exist')); |
36 | throw new OIDplusException(_L('RA does not exist')); |
37 | } |
37 | } |
38 | 38 | ||
39 | OIDplus::logger()->log("[?WARN/!OK]RA($email)?/[?INFO/!OK]A?", "Changed RA '$email' contact data/details"); |
39 | OIDplus::logger()->log("[?WARN/!OK]RA($email)?/[?INFO/!OK]A?", "Changed RA '$email' contact data/details"); |
40 | 40 | ||
41 | if (isset($params['ra_name'])) |
41 | if (isset($params['ra_name'])) |
42 | OIDplus::db()->query("UPDATE ###ra SET ra_name = ? WHERE email = ?", array($params['ra_name'], $email)); |
42 | OIDplus::db()->query("UPDATE ###ra SET ra_name = ? WHERE email = ?", array($params['ra_name'], $email)); |
43 | if (isset($params['organization'])) |
43 | if (isset($params['organization'])) |
44 | OIDplus::db()->query("UPDATE ###ra SET organization = ? WHERE email = ?", array($params['organization'], $email)); |
44 | OIDplus::db()->query("UPDATE ###ra SET organization = ? WHERE email = ?", array($params['organization'], $email)); |
45 | if (isset($params['office'])) |
45 | if (isset($params['office'])) |
46 | OIDplus::db()->query("UPDATE ###ra SET office = ? WHERE email = ?", array($params['office'], $email)); |
46 | OIDplus::db()->query("UPDATE ###ra SET office = ? WHERE email = ?", array($params['office'], $email)); |
47 | if (isset($params['personal_name'])) |
47 | if (isset($params['personal_name'])) |
48 | OIDplus::db()->query("UPDATE ###ra SET personal_name = ? WHERE email = ?", array($params['personal_name'], $email)); |
48 | OIDplus::db()->query("UPDATE ###ra SET personal_name = ? WHERE email = ?", array($params['personal_name'], $email)); |
49 | if (isset($params['privacy'])) |
49 | if (isset($params['privacy'])) |
50 | OIDplus::db()->query("UPDATE ###ra SET privacy = ? WHERE email = ?", array($params['privacy'], $email)); |
50 | OIDplus::db()->query("UPDATE ###ra SET privacy = ? WHERE email = ?", array($params['privacy'], $email)); |
51 | if (isset($params['street'])) |
51 | if (isset($params['street'])) |
52 | OIDplus::db()->query("UPDATE ###ra SET street = ? WHERE email = ?", array($params['street'], $email)); |
52 | OIDplus::db()->query("UPDATE ###ra SET street = ? WHERE email = ?", array($params['street'], $email)); |
53 | if (isset($params['zip_town'])) |
53 | if (isset($params['zip_town'])) |
54 | OIDplus::db()->query("UPDATE ###ra SET zip_town = ? WHERE email = ?", array($params['zip_town'], $email)); |
54 | OIDplus::db()->query("UPDATE ###ra SET zip_town = ? WHERE email = ?", array($params['zip_town'], $email)); |
55 | if (isset($params['country'])) |
55 | if (isset($params['country'])) |
56 | OIDplus::db()->query("UPDATE ###ra SET country = ? WHERE email = ?", array($params['country'], $email)); |
56 | OIDplus::db()->query("UPDATE ###ra SET country = ? WHERE email = ?", array($params['country'], $email)); |
57 | if (isset($params['phone'])) |
57 | if (isset($params['phone'])) |
58 | OIDplus::db()->query("UPDATE ###ra SET phone = ? WHERE email = ?", array($params['phone'], $email)); |
58 | OIDplus::db()->query("UPDATE ###ra SET phone = ? WHERE email = ?", array($params['phone'], $email)); |
59 | if (isset($params['mobile'])) |
59 | if (isset($params['mobile'])) |
60 | OIDplus::db()->query("UPDATE ###ra SET mobile = ? WHERE email = ?", array($params['mobile'], $email)); |
60 | OIDplus::db()->query("UPDATE ###ra SET mobile = ? WHERE email = ?", array($params['mobile'], $email)); |
61 | if (isset($params['fax'])) |
61 | if (isset($params['fax'])) |
62 | OIDplus::db()->query("UPDATE ###ra SET fax = ? WHERE email = ?", array($params['fax'], $email)); |
62 | OIDplus::db()->query("UPDATE ###ra SET fax = ? WHERE email = ?", array($params['fax'], $email)); |
63 | 63 | ||
64 | OIDplus::db()->query("UPDATE ###ra SET updated = ".OIDplus::db()->sqlDate()." WHERE email = ?", array($email)); |
64 | OIDplus::db()->query("UPDATE ###ra SET updated = ".OIDplus::db()->sqlDate()." WHERE email = ?", array($email)); |
65 | 65 | ||
66 | return array("status" => 0); |
66 | return array("status" => 0); |
67 | } else { |
67 | } else { |
68 | throw new OIDplusException(_L('Unknown action ID')); |
68 | throw new OIDplusException(_L('Unknown action ID')); |
69 | } |
69 | } |
70 | } |
70 | } |
71 | 71 | ||
72 | public function init($html=true) { |
72 | public function init($html=true) { |
73 | // Nothing |
73 | // Nothing |
74 | } |
74 | } |
75 | 75 | ||
76 | public function gui($id, &$out, &$handled) { |
76 | public function gui($id, &$out, &$handled) { |
77 | if (explode('$',$id)[0] == 'oidplus:edit_ra') { |
77 | if (explode('$',$id)[0] == 'oidplus:edit_ra') { |
78 | $handled = true; |
78 | $handled = true; |
79 | 79 | ||
80 | $ra_email = explode('$',$id)[1]; |
80 | $ra_email = explode('$',$id)[1]; |
81 | 81 | ||
82 | $out['title'] = _L('Edit RA contact data'); |
82 | $out['title'] = _L('Edit RA contact data'); |
83 | $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png' : ''; |
83 | $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png' : ''; |
84 | 84 | ||
85 | if (!OIDplus::authUtils()->isRaLoggedIn($ra_email) && !OIDplus::authUtils()->isAdminLoggedIn()) { |
85 | if (!OIDplus::authUtils()->isRaLoggedIn($ra_email) && !OIDplus::authUtils()->isAdminLoggedIn()) { |
86 | $out['icon'] = 'img/error.png'; |
86 | $out['icon'] = 'img/error.png'; |
87 | $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>'; |
87 | $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>'; |
88 | return; |
88 | return; |
89 | } |
89 | } |
90 | 90 | ||
91 | $out['text'] = '<p>'._L('Your email address: %1','<b>'.htmlentities($ra_email).'</b>').'</p>'; |
91 | $out['text'] = '<p>'._L('Your email address: %1','<b>'.htmlentities($ra_email).'</b>').'</p>'; |
92 | 92 | ||
93 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($ra_email)); |
93 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($ra_email)); |
94 | if (!$res->any()) { |
94 | if (!$res->any()) { |
95 | $out['icon'] = 'img/error.png'; |
95 | $out['icon'] = 'img/error.png'; |
96 | $out['text'] = _L('RA "%1" does not exist','<b>'.htmlentities($ra_email).'</b>'); |
96 | $out['text'] = _L('RA "%1" does not exist','<b>'.htmlentities($ra_email).'</b>'); |
97 | return; |
97 | return; |
98 | } |
98 | } |
99 | $row = $res->fetch_array(); |
99 | $row = $res->fetch_array(); |
100 | 100 | ||
101 | $changeEMailPlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.102'); // OIDplusPageRaChangeEMail |
101 | $changeEMailPlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.102'); // OIDplusPageRaChangeEMail |
102 | if (!is_null($changeEMailPlugin) && OIDplus::config()->getValue('allow_ra_email_change')) { |
102 | if (!is_null($changeEMailPlugin) && OIDplus::config()->getValue('allow_ra_email_change')) { |
103 | $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:change_ra_email$'.$ra_email).'>'._L('Change email address').'</a></p>'; |
103 | $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:change_ra_email$'.$ra_email).'>'._L('Change email address').'</a></p>'; |
104 | } else { |
104 | } else { |
105 | $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>'; |
105 | $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>'; |
106 | } |
106 | } |
107 | 107 | ||
108 | // --- |
108 | // --- |
109 | 109 | ||
110 | $out['text'] .= '<p>'._L('Change basic information (public)').':</p> |
110 | $out['text'] .= '<p>'._L('Change basic information (public)').':</p> |
111 | <form id="raChangeContactDataForm" action="javascript:void(0);" onsubmit="return OIDplusPageRaEditContactData.raChangeContactDataFormOnSubmit();"> |
111 | <form id="raChangeContactDataForm" action="javascript:void(0);" onsubmit="return OIDplusPageRaEditContactData.raChangeContactDataFormOnSubmit();"> |
112 | <input type="hidden" id="email" value="'.htmlentities($ra_email).'"/> |
112 | <input type="hidden" id="email" value="'.htmlentities($ra_email).'"/> |
113 | <div><label class="padding_label">'._L('RA Name').':</label><input type="text" id="ra_name" value="'.htmlentities($row['ra_name']).'"/></div> |
113 | <div><label class="padding_label">'._L('RA Name').':</label><input type="text" id="ra_name" value="'.htmlentities($row['ra_name']).'"/></div> |
114 | <div><label class="padding_label">'._L('Organization').':</label><input type="text" id="organization" value="'.htmlentities($row['organization']).'"/></div> |
114 | <div><label class="padding_label">'._L('Organization').':</label><input type="text" id="organization" value="'.htmlentities($row['organization']).'"/></div> |
115 | <div><label class="padding_label">'._L('Office').':</label><input type="text" id="office" value="'.htmlentities($row['office']).'"/></div> |
115 | <div><label class="padding_label">'._L('Office').':</label><input type="text" id="office" value="'.htmlentities($row['office']).'"/></div> |
116 | <div><label class="padding_label">'._L('Person name').':</label><input type="text" id="personal_name" value="'.htmlentities($row['personal_name']).'"/></div> |
116 | <div><label class="padding_label">'._L('Person name').':</label><input type="text" id="personal_name" value="'.htmlentities($row['personal_name']).'"/></div> |
117 | <br> |
117 | <br> |
118 | <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> |
118 | <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> |
119 | <div><label class="padding_label">'._L('Street').':</label><input type="text" id="street" value="'.htmlentities($row['street']).'"/></div> |
119 | <div><label class="padding_label">'._L('Street').':</label><input type="text" id="street" value="'.htmlentities($row['street']).'"/></div> |
120 | <div><label class="padding_label">'._L('ZIP/Town').':</label><input type="text" id="zip_town" value="'.htmlentities($row['zip_town']).'"/></div> |
120 | <div><label class="padding_label">'._L('ZIP/Town').':</label><input type="text" id="zip_town" value="'.htmlentities($row['zip_town']).'"/></div> |
121 | <div><label class="padding_label">'._L('Country').':</label><input type="text" id="country" value="'.htmlentities($row['country']).'"/></div> |
121 | <div><label class="padding_label">'._L('Country').':</label><input type="text" id="country" value="'.htmlentities($row['country']).'"/></div> |
122 | <div><label class="padding_label">'._L('Phone').':</label><input type="text" id="phone" value="'.htmlentities($row['phone']).'"/></div> |
122 | <div><label class="padding_label">'._L('Phone').':</label><input type="text" id="phone" value="'.htmlentities($row['phone']).'"/></div> |
123 | <div><label class="padding_label">'._L('Mobile').':</label><input type="text" id="mobile" value="'.htmlentities($row['mobile']).'"/></div> |
123 | <div><label class="padding_label">'._L('Mobile').':</label><input type="text" id="mobile" value="'.htmlentities($row['mobile']).'"/></div> |
124 | <div><label class="padding_label">'._L('Fax').':</label><input type="text" id="fax" value="'.htmlentities($row['fax']).'"/></div> |
124 | <div><label class="padding_label">'._L('Fax').':</label><input type="text" id="fax" value="'.htmlentities($row['fax']).'"/></div> |
125 | <br><input type="submit" value="'._L('Change data').'"> |
125 | <br><input type="submit" value="'._L('Change data').'"> |
126 | </form><br><br>'; |
126 | </form><br><br>'; |
127 | 127 | ||
128 | $out['text'] .= '<p><a href="#" onclick="return OIDplusPagePublicRaBaseUtils.deleteRa('.js_escape($ra_email).',\'oidplus:system\')">'._L('Delete profile').'</a> '._L('(objects stay active)').'</p>'; |
128 | $out['text'] .= '<p><a href="#" onclick="return OIDplusPagePublicRaBaseUtils.deleteRa('.js_escape($ra_email).',\'oidplus:system\')">'._L('Delete profile').'</a> '._L('(objects stay active)').'</p>'; |
129 | } |
129 | } |
130 | } |
130 | } |
131 | 131 | ||
132 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
132 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
133 | if (!$ra_email) return false; |
133 | if (!$ra_email) return false; |
134 | if (!OIDplus::authUtils()->isRaLoggedIn($ra_email) && !OIDplus::authUtils()->isAdminLoggedIn()) return false; |
134 | if (!OIDplus::authUtils()->isRaLoggedIn($ra_email) && !OIDplus::authUtils()->isAdminLoggedIn()) return false; |
135 | 135 | ||
136 | if (file_exists(__DIR__.'/img/main_icon16.png')) { |
136 | if (file_exists(__DIR__.'/img/main_icon16.png')) { |
137 | $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png'; |
137 | $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png'; |
138 | } else { |
138 | } else { |
139 | $tree_icon = null; // default icon (folder) |
139 | $tree_icon = null; // default icon (folder) |
140 | } |
140 | } |
141 | 141 | ||
142 | $json[] = array( |
142 | $json[] = array( |
143 | 'id' => 'oidplus:edit_ra$'.$ra_email, |
143 | 'id' => 'oidplus:edit_ra$'.$ra_email, |
144 | 'icon' => $tree_icon, |
144 | 'icon' => $tree_icon, |
145 | 'text' => _L('Edit RA contact data') |
145 | 'text' => _L('Edit RA contact data') |
146 | ); |
146 | ); |
147 | 147 | ||
148 | return true; |
148 | return true; |
149 | } |
149 | } |
150 | 150 | ||
151 | public function tree_search($request) { |
151 | public function tree_search($request) { |
152 | return false; |
152 | return false; |
153 | } |
153 | } |
154 | } |
154 | } |