Subversion Repositories oidplus

Rev

Rev 264 | Rev 296 | Go to most recent revision | Blame | Compare with Previous | 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. require_once __DIR__ . '/includes/oidplus.inc.php';
  21.  
  22. OIDplus::init(false);
  23.  
  24. header('Content-Type:application/json; charset=utf-8');
  25.  
  26. try {
  27.         OIDplus::db()->transaction_begin();
  28.         $handled = false;
  29.  
  30.         // Action:     (actions defined by plugins)
  31.         // Method:     GET / POST
  32.         // Parameters: ...
  33.         // Outputs:    ...
  34.         foreach (OIDplus::getPagePlugins() as $plugin) {
  35.                 $plugin->action($handled);
  36.                 if ($handled) break;
  37.         }
  38.  
  39.         // Action:     get_description
  40.         // Method:     GET / POST
  41.         // Parameters: id
  42.         // Outputs:    JSON
  43.         if (isset($_REQUEST["action"]) && ($_REQUEST['action'] == 'get_description')) {
  44.                 // This code is the very base functionality (load content page) and therefore won't be in a plugin
  45.                 $handled = true;
  46.                 if (!isset($_REQUEST['id'])) throw new OIDplusException("Invalid args");
  47.                 try {
  48.                         $out = OIDplus::gui()::generateContentPage($_REQUEST['id']);
  49.                 } catch(Exception $e) {
  50.                         $out = array();
  51.                         $out['title'] = 'Error';
  52.                         $out['icon'] = 'img/error_big.png';
  53.                         $out['text'] = $e->getMessage();
  54.                 }
  55.                 echo json_encode($out);
  56.         }
  57.  
  58.         // === jsTree ===
  59.  
  60.         // Action:     tree_search
  61.         // Method:     GET / POST
  62.         // Parameters: search
  63.         // Outputs:    JSON
  64.         if (isset($_REQUEST["action"]) && ($_REQUEST['action'] == 'tree_search')) {
  65.                 // This code is the very base functionality (menu handling)
  66.                 $handled = true;
  67.                 if (!isset($_REQUEST['search'])) throw new OIDplusException("Invalid args");
  68.  
  69.                 $found = false;
  70.                 foreach (OIDplus::getPagePlugins() as $plugin) {
  71.                         $res = $plugin->tree_search($_REQUEST['search']);
  72.                         if ($res) {
  73.                                 echo json_encode($res);
  74.                                 $found = true;
  75.                                 break;
  76.                         }
  77.                 }
  78.  
  79.                 if (!$found) {
  80.                         echo json_encode(array());
  81.                 }
  82.         }
  83.  
  84.         // Action:     tree_load
  85.         // Method:     GET / POST
  86.         // Parameters: id; goto (optional)
  87.         // Outputs:    JSON
  88.         if (isset($_REQUEST["action"]) && ($_REQUEST['action'] == 'tree_load')) {
  89.                 // This code is the very base functionality (menu handling)
  90.                 $handled = true;
  91.                 if (!isset($_REQUEST['id'])) throw new OIDplusException("Invalid args");
  92.                 $json = OIDplus::menuUtils()->json_tree($_REQUEST['id'], isset($_REQUEST['goto']) ? $_REQUEST['goto'] : '');
  93.                 echo $json;
  94.         }
  95.  
  96.         if (!$handled) {
  97.                 throw new OIDplusException('Invalid action ID');
  98.         }
  99.  
  100.         OIDplus::db()->transaction_commit();
  101. } catch (Exception $e) {
  102.         try {
  103.                 OIDplus::db()->transaction_rollback();
  104.         } catch (Exception $e1) {
  105.         }
  106.  
  107.         $ary = array();
  108.         $ary['error'] = $e->getMessage();
  109.         $out = json_encode($ary);
  110.  
  111.         if ($out === false) {
  112.                 // Some modules (like ODBC) might output non-UTF8 data
  113.                 $ary['error'] = utf8_encode($e->getMessage());
  114.                 $out = json_encode($ary);
  115.         }
  116.  
  117.         die($out);
  118. }
  119.  
  120. # ---
  121.  
  122. function _ra_change_rec($id, $old_ra, $new_ra) {
  123.         OIDplus::db()->query("update ###objects set ra_email = ?, updated = ".OIDplus::db()->sqlDate()." where id = ? and ifnull(ra_email,'') = ?", array($new_ra, $id, $old_ra));
  124.  
  125.         $res = OIDplus::db()->query("select id from ###objects where parent = ? and ifnull(ra_email,'') = ?", array($id, $old_ra));
  126.         while ($row = $res->fetch_array()) {
  127.                 _ra_change_rec($row['id'], $old_ra, $new_ra);
  128.         }
  129. }
  130.