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