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