Subversion Repositories oidplus

Rev

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