Rev 428 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
61 | daniel-mar | 1 | <?php |
2 | |||
3 | /* |
||
4 | * OIDplus 2.0 |
||
511 | daniel-mar | 5 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
61 | daniel-mar | 6 | * |
7 | * Licensed under the Apache License, Version 2.0 (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 |
||
10 | * |
||
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
||
12 | * |
||
13 | * Unless required by applicable law or agreed to in writing, software |
||
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
||
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
16 | * See the License for the specific language governing permissions and |
||
17 | * limitations under the License. |
||
18 | */ |
||
19 | |||
511 | daniel-mar | 20 | if (!defined('INSIDE_OIDPLUS')) die(); |
21 | |||
256 | daniel-mar | 22 | class OIDplusPageRaEditContactData extends OIDplusPagePluginRa { |
61 | daniel-mar | 23 | |
321 | daniel-mar | 24 | public function action($actionID, $params) { |
25 | if ($actionID == 'change_ra_data') { |
||
26 | $email = $params['email']; |
||
61 | daniel-mar | 27 | |
28 | if (!OIDplus::authUtils()::isRaLoggedIn($email) && !OIDplus::authUtils()::isAdminLoggedIn()) { |
||
360 | daniel-mar | 29 | throw new OIDplusException(_L('Authentication error. Please log in as admin, or as the RA to update its data.')); |
61 | daniel-mar | 30 | } |
31 | |||
261 | daniel-mar | 32 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($email)); |
236 | daniel-mar | 33 | if ($res->num_rows() == 0) { |
360 | daniel-mar | 34 | throw new OIDplusException(_L('RA does not exist')); |
61 | daniel-mar | 35 | } |
148 | daniel-mar | 36 | |
288 | daniel-mar | 37 | OIDplus::logger()->log("[?WARN/!OK]RA($email)?/[?INFO/!OK]A?", "Changed RA '$email' contact data/details"); |
61 | daniel-mar | 38 | |
261 | daniel-mar | 39 | OIDplus::db()->query("UPDATE ###ra ". |
61 | daniel-mar | 40 | "SET ". |
264 | daniel-mar | 41 | "updated = ".OIDplus::db()->sqlDate().", ". |
150 | daniel-mar | 42 | "ra_name = ?, ". |
43 | "organization = ?, ". |
||
44 | "office = ?, ". |
||
45 | "personal_name = ?, ". |
||
46 | "privacy = ?, ". |
||
47 | "street = ?, ". |
||
48 | "zip_town = ?, ". |
||
49 | "country = ?, ". |
||
50 | "phone = ?, ". |
||
51 | "mobile = ?, ". |
||
52 | "fax = ? ". |
||
53 | "WHERE email = ?", |
||
54 | array( |
||
321 | daniel-mar | 55 | $params['ra_name'], |
56 | $params['organization'], |
||
57 | $params['office'], |
||
58 | $params['personal_name'], |
||
59 | $params['privacy'], |
||
60 | $params['street'], |
||
61 | $params['zip_town'], |
||
62 | $params['country'], |
||
63 | $params['phone'], |
||
64 | $params['mobile'], |
||
65 | $params['fax'], |
||
150 | daniel-mar | 66 | $email |
67 | ) |
||
237 | daniel-mar | 68 | ); |
61 | daniel-mar | 69 | |
328 | daniel-mar | 70 | return array("status" => 0); |
321 | daniel-mar | 71 | } else { |
360 | daniel-mar | 72 | throw new OIDplusException(_L('Unknown action ID')); |
61 | daniel-mar | 73 | } |
74 | } |
||
75 | |||
75 | daniel-mar | 76 | public function init($html=true) { |
61 | daniel-mar | 77 | // Nothing |
78 | } |
||
79 | |||
80 | public function gui($id, &$out, &$handled) { |
||
81 | if (explode('$',$id)[0] == 'oidplus:edit_ra') { |
||
82 | $handled = true; |
||
281 | daniel-mar | 83 | |
84 | $ra_email = explode('$',$id)[1]; |
||
85 | |||
360 | daniel-mar | 86 | $out['title'] = _L('Edit RA contact data'); |
241 | daniel-mar | 87 | $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? OIDplus::webpath(__DIR__).'icon_big.png' : ''; |
61 | daniel-mar | 88 | |
89 | if (!OIDplus::authUtils()::isRaLoggedIn($ra_email) && !OIDplus::authUtils()::isAdminLoggedIn()) { |
||
90 | $out['icon'] = 'img/error_big.png'; |
||
360 | daniel-mar | 91 | $out['text'] = '<p>'._L('You need to <a %1>log in</a> as the requested RA %2.',OIDplus::gui()->link('oidplus:login'),'<b>'.htmlentities($ra_email).'</b>').'</p>'; |
281 | daniel-mar | 92 | return; |
93 | } |
||
61 | daniel-mar | 94 | |
360 | daniel-mar | 95 | $out['text'] = '<p>'._L('Your email address: %1','<b>'.htmlentities($ra_email).'</b>').'</p>'; |
61 | daniel-mar | 96 | |
281 | daniel-mar | 97 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($ra_email)); |
98 | if ($res->num_rows() == 0) { |
||
99 | $out['icon'] = 'img/error_big.png'; |
||
360 | daniel-mar | 100 | $out['text'] = _L('RA "%1" does not exist','<b>'.htmlentities($ra_email).'</b>'); |
281 | daniel-mar | 101 | return; |
102 | } |
||
103 | $row = $res->fetch_array(); |
||
61 | daniel-mar | 104 | |
380 | daniel-mar | 105 | $changeEMailPlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.102'); // OIDplusPageRaChangeEMail |
106 | if (!is_null($changeEMailPlugin) && OIDplus::config()->getValue('allow_ra_email_change')) { |
||
360 | daniel-mar | 107 | $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:change_ra_email$'.$ra_email).'>'._L('Change email address').'</a></p>'; |
281 | daniel-mar | 108 | } else { |
360 | daniel-mar | 109 | $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>'; |
281 | daniel-mar | 110 | } |
61 | daniel-mar | 111 | |
281 | daniel-mar | 112 | // --- |
61 | daniel-mar | 113 | |
360 | daniel-mar | 114 | $out['text'] .= '<p>'._L('Change basic information (public)').':</p> |
428 | daniel-mar | 115 | <form id="raChangeContactDataForm" action="javascript:void(0);" onsubmit="return raChangeContactDataFormOnSubmit();"> |
281 | daniel-mar | 116 | <input type="hidden" id="email" value="'.htmlentities($ra_email).'"/> |
360 | daniel-mar | 117 | <div><label class="padding_label">'._L('RA Name').':</label><input type="text" id="ra_name" value="'.htmlentities($row['ra_name']).'"/></div> |
118 | <div><label class="padding_label">'._L('Organization').':</label><input type="text" id="organization" value="'.htmlentities($row['organization']).'"/></div> |
||
119 | <div><label class="padding_label">'._L('Office').':</label><input type="text" id="office" value="'.htmlentities($row['office']).'"/></div> |
||
120 | <div><label class="padding_label">'._L('Person name').':</label><input type="text" id="personal_name" value="'.htmlentities($row['personal_name']).'"/></div> |
||
281 | daniel-mar | 121 | <br> |
360 | daniel-mar | 122 | <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> |
123 | <div><label class="padding_label">'._L('Street').':</label><input type="text" id="street" value="'.htmlentities($row['street']).'"/></div> |
||
124 | <div><label class="padding_label">'._L('ZIP/Town').':</label><input type="text" id="zip_town" value="'.htmlentities($row['zip_town']).'"/></div> |
||
125 | <div><label class="padding_label">'._L('Country').':</label><input type="text" id="country" value="'.htmlentities($row['country']).'"/></div> |
||
126 | <div><label class="padding_label">'._L('Phone').':</label><input type="text" id="phone" value="'.htmlentities($row['phone']).'"/></div> |
||
127 | <div><label class="padding_label">'._L('Mobile').':</label><input type="text" id="mobile" value="'.htmlentities($row['mobile']).'"/></div> |
||
128 | <div><label class="padding_label">'._L('Fax').':</label><input type="text" id="fax" value="'.htmlentities($row['fax']).'"/></div> |
||
129 | <br><input type="submit" value="'._L('Change data').'"> |
||
281 | daniel-mar | 130 | </form><br><br>'; |
131 | |||
360 | daniel-mar | 132 | $out['text'] .= '<p><a href="#" onclick="return deleteRa('.js_escape($ra_email).',\'oidplus:system\')">'._L('Delete profile').'</a> '._L('(objects stay active)').'</p>'; |
61 | daniel-mar | 133 | } |
134 | } |
||
135 | |||
106 | daniel-mar | 136 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
281 | daniel-mar | 137 | if (!$ra_email) return false; |
138 | if (!OIDplus::authUtils()::isRaLoggedIn($ra_email) && !OIDplus::authUtils()::isAdminLoggedIn()) return false; |
||
139 | |||
61 | daniel-mar | 140 | if (file_exists(__DIR__.'/treeicon.png')) { |
241 | daniel-mar | 141 | $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png'; |
61 | daniel-mar | 142 | } else { |
143 | $tree_icon = null; // default icon (folder) |
||
144 | } |
||
145 | |||
146 | $json[] = array( |
||
147 | 'id' => 'oidplus:edit_ra$'.$ra_email, |
||
148 | 'icon' => $tree_icon, |
||
360 | daniel-mar | 149 | 'text' => _L('Edit RA contact data') |
61 | daniel-mar | 150 | ); |
104 | daniel-mar | 151 | |
152 | return true; |
||
61 | daniel-mar | 153 | } |
108 | daniel-mar | 154 | |
155 | public function tree_search($request) { |
||
156 | return false; |
||
157 | } |
||
360 | daniel-mar | 158 | } |