Subversion Repositories oidplus

Rev

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

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