ActionApps PHP Cross Reference Groupware Applications

Source: /central/responder.php - 191 lines - 6146 bytes - Summary - Text - Print

   1  <?php
   2  //$Id: se_csv_import.php3 2290 2006-07-27 15:10:35Z honzam $
   3  /*
   4  Copyright (C) 1999, 2000 Association for Progressive Communications
   5  http://www.apc.org/
   6  
   7      This program is free software; you can redistribute it and/or modify
   8      it under the terms of the GNU General Public License as published by
   9      the Free Software Foundation; either version 2 of the License, or
  10      (at your option) any later version.
  11  
  12      This program is distributed in the hope that it will be useful,
  13      but WITHOUT ANY WARRANTY; without even the implied warranty of
  14      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15      GNU General Public License for more details.
  16  
  17      You should have received a copy of the GNU General Public License
  18      along with this program (LICENSE); if not, write to the Free Software
  19      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  20  */
  21  
  22  // anonymous authentication - locauth calls extauthnobody
  23  if ($free) {
  24      $nobody = true;
  25  }
  26  
  27  require_once dirname(__FILE__). "/include/init_central.php";
  28  
  29  /** AA_Responder base class - defines some useful common methods
  30   */
  31  class AA_Responder extends AA_Object {
  32  
  33      function run()    { return new AA_Response();}
  34  
  35      /** by default only superadmins are allowed to perform remote operations */
  36      function isPerm() { return IsSuperadmin(); }
  37  
  38      function name()   { return str_replace('AA_Responder_', '', __CLASS__); }
  39  }
  40  
  41  /** Used for autentication
  42   *  @return Session ID
  43   */
  44  class AA_Responder_Get_Sessionid extends AA_Responder {
  45  
  46      function AA_Responder_Get_Sessionid($param=null) {}
  47  
  48      /** every authenticated user can get his/her session_id */
  49      function isPerm() { return true; }
  50  
  51      function run() {
  52          global $sess;
  53          return new AA_Response($sess->id);
  54      }
  55  }
  56  
  57  /** @return array of informations about AA - org_name, domaun */
  58  class AA_Responder_Get_Aaname extends AA_Responder {
  59      function AA_Responder_Get_Aaname($param=null) {}
  60  
  61      function run() {
  62          return new AA_Response(array('org_name'=>ORG_NAME, 'domain'=>AA_HTTP_DOMAIN));
  63      }
  64  }
  65  
  66  /** @return array of informations about AA - org_name, domain */
  67  class AA_Responder_Get_Modules extends AA_Responder {
  68      /** array of module types to get */
  69      var $types;
  70  
  71      function AA_Responder_Get_Modules($param=null) {
  72          $this->types = is_array($param['types']) ? $param['types'] : array();
  73      }
  74  
  75      function run() {
  76          $type_sql = (count($this->types) == 0) ? '' : CVarset::sqlin('type', $this->types) . ' AND ';
  77          $modules  = GetTable2Array("SELECT id, name FROM module WHERE $type_sql deleted != '1' ORDER BY type, priority, name", "unpack:id", 'name');
  78          return new AA_Response($modules);
  79      }
  80  }
  81  
  82  /** @return structure which define all the definition of the slice (like slice
  83   *  properties, fields, views, ...). It is returned for all the slices in array
  84   */
  85  class AA_Responder_Get_Module_Defs extends AA_Responder {
  86      var $ids;
  87      var $limited;  // array - limits the sended definitions
  88      var $type;     // module type
  89  
  90      function AA_Responder_Get_Module_Defs($param) {
  91          $this->ids     = is_array($param['ids']) ? $param['ids'] : array();
  92          $this->limited = is_array($param['limited']) ? $param['limited'] : array();
  93          $this->type    = $param['type'];
  94      }
  95  
  96      function run() {
  97          $ret        = array();
  98          $class_name = 'AA_Module_Definition_'. $this->type;
  99          foreach ( $this->ids as $sid ) {
 100              $ret[$sid] = new $class_name;
 101              $ret[$sid]->loadForId($sid, $this->limited);
 102          }
 103          return new AA_Response($ret);
 104      }
 105  }
 106  
 107  /** @return structure which define all the definition of the slice (like slice
 108   *  properties, fields, views, ...). It is returned for all the slices in array
 109   */
 110  class AA_Responder_Do_Synchronize extends AA_Responder {
 111      var $sync_commands;
 112  
 113      function AA_Responder_Do_Synchronize($param) {
 114          $this->sync_commands = is_array($param['sync']) ? $param['sync'] : array();
 115      }
 116  
 117      function run() {
 118          $ret = array();
 119          $slice_id_cache = array();
 120          foreach ( $this->sync_commands as $serialized_command ) {
 121              $cmd = unserialize($serialized_command);
 122              $ret[] = $cmd->doAction();
 123          }
 124          return new AA_Response($ret);
 125      }
 126  }
 127  
 128  /** @return imports the slice to the database */
 129  class AA_Responder_Do_Import_Module_Chunk extends AA_Responder {
 130      var $definition_chunk;
 131  
 132      function AA_Responder_Do_Import_Module_Chunk($param) {
 133          $this->definition_chunk = $param['definition_chunk'];
 134      }
 135  
 136      function run() {
 137          $ret[] = $this->definition_chunk->importModuleChunk();
 138          return new AA_Response($ret);
 139      }
 140  }
 141  
 142  page_open(array("sess" => "AA_CP_Session", "auth" => "AA_CP_Auth"));
 143  
 144  // anonymous login
 145  if ($nobody) {
 146      $_POST['username'] = $free;
 147      $_POST['password'] = $freepwd;
 148      $auth->auth["uid"] = $auth->auth_validatelogin();
 149      if ( !$auth->auth["uid"] ) {
 150          AA_Response::error(_m("Either your username or your password is not valid."), 1);  // 1 - _m("Either your username or your password is not valid.");
 151          exit;
 152      }
 153  }
 154  
 155  $request = null;
 156  
 157  // we use primarily POST, but manager class actions needs to send GET request
 158  if ( $_POST['request'] ) {
 159      $request = AA_Request::decode($_POST['request']);
 160  //    if (!strpos($_POST['request'], 'Get_Sessionid')) {
 161  //        huhl('yy', $request, $request->params['sync'][0], unserialize($request->params['sync'][0]));
 162  //        exit;
 163  //    }
 164  //
 165  
 166  }
 167  
 168  if ( !is_object($request)) {
 169      AA_Response::error(_m("No request sent for responder.php"), 102);  // error code > 0
 170      exit;
 171  }
 172  
 173  $responder = AA_Object::factoryByName('AA_Responder_', $request->getCommand(), $request->getParameters());
 174  if ( empty($responder) ) {
 175      AA_Response::error(_m("Bad request sent for responder.php - %1", array($request->getCommand())), 103);  // error code > 0
 176      exit;
 177  }
 178  
 179  if (!$responder->isPerm()) {
 180      AA_Response::error(_m("You don't have permissions to run %1.", array($responder->name())), 101);  // error code > 0
 181      exit;
 182  }
 183  
 184  $response = $responder->run();
 185  page_close();
 186  
 187  $response->respond();
 188  exit;
 189  
 190  
 191  ?>

title

Description

title

Description

title

Description

title

title

Body