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