Subversion Repositories oidplus

Rev

Rev 428 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

  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.                         $email = $params['email'];
  27.  
  28.                         if (!OIDplus::authUtils()::isRaLoggedIn($email) && !OIDplus::authUtils()::isAdminLoggedIn()) {
  29.                                 throw new OIDplusException(_L('Authentication error. Please log in as admin, or as the RA to update its data.'));
  30.                         }
  31.  
  32.                         $res = OIDplus::db()->query("select * from ###ra where email = ?", array($email));
  33.                         if ($res->num_rows() == 0) {
  34.                                 throw new OIDplusException(_L('RA does not exist'));
  35.                         }
  36.  
  37.                         OIDplus::logger()->log("[?WARN/!OK]RA($email)?/[?INFO/!OK]A?", "Changed RA '$email' contact data/details");
  38.  
  39.                         OIDplus::db()->query("UPDATE ###ra ".
  40.                                 "SET ".
  41.                                 "updated = ".OIDplus::db()->sqlDate().", ".
  42.                                 "ra_name = ?, ".
  43.                                 "organization = ?, ".
  44.                                 "office = ?, ".
  45.                                 "personal_name = ?, ".
  46.                                 "privacy = ?, ".
  47.                                 "street = ?, ".
  48.                                 "zip_town = ?, ".
  49.                                 "country = ?, ".
  50.                                 "phone = ?, ".
  51.                                 "mobile = ?, ".
  52.                                 "fax = ? ".
  53.                                 "WHERE email = ?",
  54.                                 array(
  55.                                         $params['ra_name'],
  56.                                         $params['organization'],
  57.                                         $params['office'],
  58.                                         $params['personal_name'],
  59.                                         $params['privacy'],
  60.                                         $params['street'],
  61.                                         $params['zip_town'],
  62.                                         $params['country'],
  63.                                         $params['phone'],
  64.                                         $params['mobile'],
  65.                                         $params['fax'],
  66.                                         $email
  67.                                 )
  68.                         );
  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');
  87.                         $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? OIDplus::webpath(__DIR__).'icon_big.png' : '';
  88.  
  89.                         if (!OIDplus::authUtils()::isRaLoggedIn($ra_email) && !OIDplus::authUtils()::isAdminLoggedIn()) {
  90.                                 $out['icon'] = 'img/error_big.png';
  91.                                 $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>';
  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));
  98.                         if ($res->num_rows() == 0) {
  99.                                 $out['icon'] = 'img/error_big.png';
  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 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.  
  132.                         $out['text'] .= '<p><a href="#" onclick="return deleteRa('.js_escape($ra_email).',\'oidplus:system\')">'._L('Delete profile').'</a> '._L('(objects stay active)').'</p>';
  133.                 }
  134.         }
  135.  
  136.         public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
  137.                 if (!$ra_email) return false;
  138.                 if (!OIDplus::authUtils()::isRaLoggedIn($ra_email) && !OIDplus::authUtils()::isAdminLoggedIn()) return false;
  139.  
  140.                 if (file_exists(__DIR__.'/treeicon.png')) {
  141.                         $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png';
  142.                 } else {
  143.                         $tree_icon = null; // default icon (folder)
  144.                 }
  145.  
  146.                 $json[] = array(
  147.                         'id' => 'oidplus:edit_ra$'.$ra_email,
  148.                         'icon' => $tree_icon,
  149.                         'text' => _L('Edit RA contact data')
  150.                 );
  151.  
  152.                 return true;
  153.         }
  154.  
  155.         public function tree_search($request) {
  156.                 return false;
  157.         }
  158. }