Rev 148 | 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 | |||
112 | daniel-mar | 20 | if (!defined('IN_OIDPLUS')) die(); |
21 | |||
61 | daniel-mar | 22 | class OIDplusPageRaEditContactData extends OIDplusPagePlugin { |
23 | public function type() { |
||
24 | return 'ra'; |
||
25 | } |
||
26 | |||
27 | public function priority() { |
||
28 | return 100; |
||
29 | } |
||
30 | |||
31 | public function action(&$handled) { |
||
107 | daniel-mar | 32 | if (isset($_POST["action"]) && ($_POST["action"] == "change_ra_data")) { |
61 | daniel-mar | 33 | $handled = true; |
34 | |||
35 | $email = $_POST['email']; |
||
36 | |||
37 | if (!OIDplus::authUtils()::isRaLoggedIn($email) && !OIDplus::authUtils()::isAdminLoggedIn()) { |
||
107 | daniel-mar | 38 | die(json_encode(array("error" => 'Authentification error. Please log in as the RA to update its data.'))); |
61 | daniel-mar | 39 | } |
40 | |||
150 | daniel-mar | 41 | $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."ra where email = ?", array($email)); |
61 | daniel-mar | 42 | if (OIDplus::db()->num_rows($res) == 0) { |
107 | daniel-mar | 43 | die(json_encode(array("error" => 'RA does not exist'))); |
61 | daniel-mar | 44 | } |
148 | daniel-mar | 45 | |
115 | daniel-mar | 46 | OIDplus::logger()->log("RA($email)?/A?", "Changed RA '$email' contact data/details"); |
61 | daniel-mar | 47 | |
48 | if (!OIDplus::db()->query("UPDATE ".OIDPLUS_TABLENAME_PREFIX."ra ". |
||
49 | "SET ". |
||
50 | "updated = now(), ". |
||
150 | daniel-mar | 51 | "ra_name = ?, ". |
52 | "organization = ?, ". |
||
53 | "office = ?, ". |
||
54 | "personal_name = ?, ". |
||
55 | "privacy = ?, ". |
||
56 | "street = ?, ". |
||
57 | "zip_town = ?, ". |
||
58 | "country = ?, ". |
||
59 | "phone = ?, ". |
||
60 | "mobile = ?, ". |
||
61 | "fax = ? ". |
||
62 | "WHERE email = ?", |
||
63 | array( |
||
64 | $_POST['ra_name'], |
||
65 | $_POST['organization'], |
||
66 | $_POST['office'], |
||
67 | $_POST['personal_name'], |
||
68 | $_POST['privacy'], |
||
69 | $_POST['street'], |
||
70 | $_POST['zip_town'], |
||
71 | $_POST['country'], |
||
72 | $_POST['phone'], |
||
73 | $_POST['mobile'], |
||
74 | $_POST['fax'], |
||
75 | $email |
||
76 | ) |
||
77 | )) |
||
61 | daniel-mar | 78 | { |
107 | daniel-mar | 79 | die(json_encode(array("error" => OIDplus::db()->error()))); |
61 | daniel-mar | 80 | } |
81 | |||
107 | daniel-mar | 82 | echo json_encode(array("status" => 0)); |
61 | daniel-mar | 83 | } |
84 | } |
||
85 | |||
75 | daniel-mar | 86 | public function init($html=true) { |
61 | daniel-mar | 87 | // Nothing |
88 | } |
||
89 | |||
90 | public function cfgSetValue($name, $value) { |
||
91 | // Nothing |
||
92 | } |
||
93 | |||
94 | public function gui($id, &$out, &$handled) { |
||
95 | if (explode('$',$id)[0] == 'oidplus:edit_ra') { |
||
96 | $handled = true; |
||
97 | $out['title'] = 'Edit RA contact data'; |
||
148 | daniel-mar | 98 | $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? 'plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/icon_big.png' : ''; |
61 | daniel-mar | 99 | |
100 | $ra_email = explode('$',$id)[1]; |
||
101 | |||
102 | if (!OIDplus::authUtils()::isRaLoggedIn($ra_email) && !OIDplus::authUtils()::isAdminLoggedIn()) { |
||
103 | $out['icon'] = 'img/error_big.png'; |
||
107 | daniel-mar | 104 | $out['text'] .= '<p>You need to <a '.oidplus_link('oidplus:login').'>log in</a> as the requested RA <b>'.htmlentities($ra_email).'</b>.</p>'; |
61 | daniel-mar | 105 | } else { |
106 | $out['text'] .= '<p>Your email address: <b>'.htmlentities($ra_email).'</b>'; |
||
107 | |||
150 | daniel-mar | 108 | $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."ra where email = ?", array($ra_email)); |
61 | daniel-mar | 109 | if (OIDplus::db()->num_rows($res) == 0) { |
110 | $out['icon'] = 'img/error_big.png'; |
||
111 | $out['text'] = 'RA <b>'.htmlentities($ra_email).'</b> does not exist'; |
||
112 | return $out; |
||
113 | } |
||
114 | $row = OIDplus::db()->fetch_array($res); |
||
115 | |||
116 | if (OIDplus::config()->getValue('allow_ra_email_change')) { |
||
107 | daniel-mar | 117 | $out['text'] .= '<p><a '.oidplus_link('oidplus:change_ra_email$'.$ra_email).'>Change email address</a></p>'; |
61 | daniel-mar | 118 | } else { |
119 | $out['text'] .= '<p><abbr title="To change the email address, you need to contact the superior RA. They will need to change the email address and invite you (with your new email address) again.">How to change the email address?</abbr></p>'; |
||
120 | } |
||
121 | |||
122 | // --- |
||
123 | |||
124 | $out['text'] .= '<p>Change basic information (public):</p> |
||
125 | <form id="raChangeContactDataForm" onsubmit="return raChangeContactDataFormOnSubmit();"> |
||
126 | <input type="hidden" id="email" value="'.htmlentities($ra_email).'"/> |
||
127 | <label class="padding_label">RA Name:</label><input type="text" id="ra_name" value="'.htmlentities($row['ra_name']).'"/><br> |
||
128 | <label class="padding_label">Organization:</label><input type="text" id="organization" value="'.htmlentities($row['organization']).'"/><br> |
||
129 | <label class="padding_label">Office:</label><input type="text" id="office" value="'.htmlentities($row['office']).'"/><br> |
||
130 | <label class="padding_label">Person name:</label><input type="text" id="personal_name" value="'.htmlentities($row['personal_name']).'"/><br> |
||
131 | <br> |
||
132 | <label class="padding_label">Privacy</label><input type="checkbox" id="privacy" value="" '.($row['privacy'] == 1 ? ' checked' : '').'/> <label for="privacy">Hide postal address and Phone/Fax/Mobile Numbers</label><br> |
||
133 | <label class="padding_label">Street:</label><input type="text" id="street" value="'.htmlentities($row['street']).'"/><br> |
||
134 | <label class="padding_label">ZIP/Town:</label><input type="text" id="zip_town" value="'.htmlentities($row['zip_town']).'"/><br> |
||
135 | <label class="padding_label">Country:</label><input type="text" id="country" value="'.htmlentities($row['country']).'"/><br> |
||
136 | <label class="padding_label">Phone:</label><input type="text" id="phone" value="'.htmlentities($row['phone']).'"/><br> |
||
137 | <label class="padding_label">Mobile:</label><input type="text" id="mobile" value="'.htmlentities($row['mobile']).'"/><br> |
||
138 | <label class="padding_label">Fax:</label><input type="text" id="fax" value="'.htmlentities($row['fax']).'"/><br> |
||
139 | <input type="submit" value="Change data"> |
||
140 | </form><br><br>'; |
||
141 | |||
142 | $out['text'] .= '<p><a href="#" onclick="return deleteRa('.js_escape($ra_email).',\'oidplus:system\')">Delete your profile</a> (your objects stay active)</p>'; |
||
143 | } |
||
144 | } |
||
145 | } |
||
146 | |||
106 | daniel-mar | 147 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
61 | daniel-mar | 148 | if (file_exists(__DIR__.'/treeicon.png')) { |
148 | daniel-mar | 149 | $tree_icon = 'plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/treeicon.png'; |
61 | daniel-mar | 150 | } else { |
151 | $tree_icon = null; // default icon (folder) |
||
152 | } |
||
153 | |||
154 | $json[] = array( |
||
155 | 'id' => 'oidplus:edit_ra$'.$ra_email, |
||
156 | 'icon' => $tree_icon, |
||
157 | 'text' => 'Edit RA contact data' |
||
158 | ); |
||
104 | daniel-mar | 159 | |
160 | return true; |
||
61 | daniel-mar | 161 | } |
108 | daniel-mar | 162 | |
163 | public function tree_search($request) { |
||
164 | return false; |
||
165 | } |
||
61 | daniel-mar | 166 | } |
167 | |||
168 | OIDplus::registerPagePlugin(new OIDplusPageRaEditContactData()); |