ActionApps PHP Cross Reference Groupware Applications

Source: /central/include/actions.php3 - 352 lines - 12739 bytes - Summary - Text - Print

Description: File contains definitions of functions which corresponds with actions on Item Manager page (admin/index.php3) - manipulates with central_confs

   1  <?php
   2  /**
   3   * File contains definitions of functions which corresponds with actions
   4   * on Item Manager page (admin/index.php3) - manipulates with central_confs
   5   *
   6   * Should be included to other scripts (admin/index.php3)
   7   *
   8   *   Move central_conf to app/hold/trash based on param
   9   *  @param $status    static function parameter defined in manager action
  10   *                   in this case it holds bin number, where the central_confs should go
  11   *  @param $item_arr array, where keys are unpacked ids of items prefixed by
  12   *                   'x' character (javascript purposes only)
  13   *  @param $akce_param additional parameter for the action - not used here
  14   *
  15   *
  16   * PHP versions 4 and 5
  17   *
  18   * LICENSE: This program is free software; you can redistribute it and/or modify
  19   * it under the terms of the GNU General Public License as published by
  20   * the Free Software Foundation; either version 2 of the License, or
  21   * (at your option) any later version.
  22   *
  23   * This program is distributed in the hope that it will be useful,
  24   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  26   * GNU General Public License for more details.
  27   *
  28   * You should have received a copy of the GNU General Public License
  29   * along with this program (LICENSE); if not, write to the Free Software
  30   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  31   *
  32   * @version   $Id: actions.php3 2404 2007-05-09 15:10:58Z honzam $
  33   * @author    Honza Malik <honza.malik@ecn.cz>
  34   * @license   http://opensource.org/licenses/gpl-license.php GNU Public License
  35   * @copyright Copyright (C) 1999, 2000 Association for Progressive Communications
  36   * @link      http://www.apc.org/ APC
  37   *
  38  */
  39  
  40  require_once  AA_INC_PATH."linkcheck.class.php3";
  41  require_once  AA_INC_PATH."optimize.class.php3";
  42  
  43  /** AA_Manageraction_Central_Linkcheck - checks if the AA are acessible */
  44  class AA_Manageraction_Central_Linkcheck extends AA_Manageraction {
  45  
  46      /** Name of this Manager's action */
  47      function getName() {
  48          return _m('Check the AA availability');
  49      }
  50  
  51      /** main executive function
  52      * @param $param       - not used
  53      * @param $item_arr    - array of id of AA records to check
  54      * @param $akce_param  - not used
  55      */
  56      function perform(&$manager, &$state, $item_arr, $akce_param) {
  57          $item_ids = array_keys($item_arr);
  58  
  59          if (count($item_ids)<1) {
  60              return false;                                     // OK - no error
  61          }
  62  
  63          $db  = getDB();
  64          $SQL = "SELECT * FROM central_conf WHERE id IN ('".join_and_quote("','",$item_ids)."')";
  65          $db->tquery($SQL);
  66          $results[] = array('<b>'._m('AA (Organization)').'</b>', '<b>'._m('URL').'</b>', '<b>'._m('Status code').'</b>', '<b>'._m('Description').'</b>');
  67          $linkcheck = new linkcheck();
  68  
  69          while ($db->next_record()) {
  70              $url       = $db->f('AA_HTTP_DOMAIN'). $db->f('AA_BASE_DIR'). "view.php3";
  71              $status    = $linkcheck->check_url($url);
  72              $results[] = array($db->f('ORG_NAME'), $url, $status['code'], $status['comment']);
  73          }
  74  
  75          freeDB($db);
  76          return GetHtmlTable($results). "<br>";                                     // OK - no error
  77      }
  78  
  79      /** Checks if the user have enough permission to perform the action */
  80      function isPerm(&$manager) {
  81          return  IsSuperadmin();
  82      }
  83  }
  84  
  85  /** AA_Manageraction_Central_Sqlupdate - Runs sql_update.php3 script on selected
  86   *  AAs
  87   */
  88  class AA_Manageraction_Central_Sqlupdate extends AA_Manageraction {
  89  
  90      /** sql_update action - dotest|update*/
  91      var $update_action;
  92  
  93      /** Constructor - fills the information about the optimize method */
  94      function AA_Manageraction_Central_Sqlupdate($id, $action) {
  95          $this->update_action  = $action;
  96          parent::AA_Manageraction($id);
  97      }
  98  
  99      /** Name of this Manager's action */
 100      function getName() {
 101          return _m('Update DB (sql_update)'). ' - '.  $this->update_action;
 102      }
 103  
 104      /** main executive function
 105      * @param $param       - not used
 106      * @param $item_arr    - array of id of AA records to check
 107      * @param $akce_param  - not used
 108      */
 109      function perform(&$manager, &$state, $item_arr, $akce_param) {
 110          $item_ids = array_keys($item_arr);
 111  
 112          if (count($item_ids)<1) {
 113              return false;                                     // OK - no error
 114          }
 115          set_time_limit(360);
 116          $db  = getDB();
 117  
 118          $SQL = "SELECT * FROM central_conf WHERE id IN ('".join_and_quote("','",$item_ids)."')";
 119          $db->tquery($SQL);
 120          $ret = '';
 121          while ($db->next_record()) {
 122              $params   = 'dbpw5='.substr($db->f('db_pwd'),0,5).'&silent=1&fire=1&'.$this->update_action.'=1';
 123              $file     = $db->f('AA_HTTP_DOMAIN'). $db->f('AA_BASE_DIR'). "service/sql_update.php?$params";
 124              $response = file_get_contents($file);
 125              $status   = substr($response,0,3);
 126              $toggle   = '{htmltoggle:&gt;&gt;:'.AA_Stringexpand::quoteColons($file).':&lt;&lt;:'. AA_Stringexpand::quoteColons($response).'}';
 127              $ret     .= AA_Stringexpand::unalias($status.' '.$toggle);
 128          }
 129          freeDB($db);
 130          return $ret;                                     // OK - no error
 131      }
 132  
 133      /** Checks if the user have enough permission to perform the action */
 134      function isPerm(&$manager) {
 135          return IsSuperadmin();
 136      }
 137  }
 138  
 139  /** AA_Manageraction - Item manager actions. Just create new class and assign
 140   *  it to your manager
 141   */
 142  class AA_Manageraction_Central_MoveItem extends AA_Manageraction {
 143  
 144      /** specifies, to which bin the move should be performed */
 145      var $to_bin;
 146  
 147      /** Constructor - fills the information about the target bin */
 148      function AA_Manageraction_Central_MoveItem($id, $to_bin) {
 149          $this->to_bin = $to_bin;
 150          parent::AA_Manageraction($id);
 151      }
 152  
 153      /** Name of this Manager's action */
 154      function getName() {
 155          switch($this->to_bin) {
 156              case 1: return _m('Move to Active');
 157              case 2: return _m('Move to Holding bin');
 158              case 3: return _m('Move to Trash');
 159          }
 160          return "";
 161      }
 162  
 163      /** main executive function
 164      * @param $param       - not used
 165      * @param $item_arr    - array of id of AA records to check
 166      * @param $akce_param  - not used
 167      */
 168      function perform(&$manager, &$state, $item_arr, $akce_param) {
 169          $item_ids = array_keys($item_arr);
 170  
 171          if ($item_ids) {
 172              $SQL = "UPDATE central_conf SET status_code = '".$this->to_bin."'
 173                       WHERE id IN ('".join_and_quote("','",$item_ids)."')";
 174              tryQuery($SQL);
 175          }
 176          return false;                                     // OK - no error
 177      }
 178  
 179      /** Checks if the user have enough permission to perform the action */
 180      function isPerm(&$manager) {
 181          $current_bin     =  $manager->getBin();
 182  
 183          /** for acces to Central you have to be superadmin */
 184          if (!IsSuperadmin()) {
 185              return false;
 186          }
 187  
 188          switch($this->to_bin) {
 189              case 1: return ($current_bin != 'app' ) AND
 190                             ($current_bin != 'appb') AND
 191                             ($current_bin != 'appc');
 192                      // Folder2 is Holding bin - prepared for more than three bins
 193              case 2: return ($current_bin != 'hold');
 194                      // Folder3 is Trash
 195              case 3: return ($current_bin != 'trash');
 196          }
 197      }
 198  }
 199  
 200  /** AA_Manageraction_Central_DeleteTrash - Handler for DeleteTrash switch
 201   *  Delete all AAs in the trash bin
 202   */
 203  class AA_Manageraction_Central_DeleteTrash extends AA_Manageraction {
 204  
 205      /** specifies, if we have to delete only items specified in $item_arr
 206       *  otherwise delete all items in Trash
 207       *  With $selected=true  it is used as "action" of manager
 208       *  With $selected=false it is used as "switch" of manager (left menu)
 209       */
 210      var $selected;
 211  
 212      /** Constructor - fills the information about the target bin */
 213      function AA_Manageraction_Central_DeleteTrash($id, $selected=false) {
 214          $this->selected = $selected;
 215          parent::AA_Manageraction($id);
 216      }
 217  
 218      /** Name of this Manager's action */
 219      function getName() {
 220          return _m('Remove (delete from database)');
 221      }
 222  
 223      /** main executive function
 224       *  @param $param       'selected' if we have to delete only items specified
 225       *                      in $item_arr - otherwise delete all items in Trash
 226       *  @param $item_arr    Items to delete (if 'selected' is $param)
 227       *  @param $akce_param  Not used
 228       */
 229      function perform(&$manager, &$state, $item_arr, $akce_param) {
 230          if ( !isSuperadmin() ) {    // permission to delete items?
 231              return _m("You have not permissions to remove items");
 232          }
 233  
 234          $wherein = '';
 235  
 236          // restrict the deletion only to selected items
 237          if ($this->selected) {
 238              if (!is_array($item_ids)) {
 239                  return false;
 240              }
 241  
 242              $items_to_delete = array();
 243              $item_ids        = array_keys($item_arr);
 244              if (count($items_to_delete) < 1) {
 245                  return false;
 246              }
 247              $wherein = " AND id IN ('".join_and_quote("','", $items_to_delete)."')";
 248          }
 249  
 250          $db = getDB();
 251  
 252          // now we ask, which items we have to delete. We are checking the items even
 253          // it is specified in $item_arr - for security reasons - we can delete only
 254          // items in current slice and in trash
 255          $db->query("SELECT id FROM central_conf WHERE status_code=3 $wherein");
 256          $items_to_delete = array();
 257          while ( $db->next_record() ) {
 258              $items_to_delete[] = $db->f("id");
 259          }
 260          if (count($items_to_delete) < 1) {
 261              freeDB($db);
 262              return;
 263          }
 264  
 265          // delete content of all fields
 266          // don't worry about fed fields - content is copied
 267          $wherein = "IN ('".join_and_quote("','", $items_to_delete)."')";
 268          $db->query("DELETE FROM central_conf WHERE id ".$wherein);
 269          freeDB($db);
 270      }
 271  
 272      /** Checks if the user have enough permission to perform the action */
 273      function isPerm(&$manager) {
 274          // if we want to use it as "action" (not "switch"), then we should be in trash bin
 275          return (IsSuperadmin() AND (!$this->selected OR ($manager->getBin() == 'trash')));
 276      }
 277  }
 278  
 279  
 280  /** AA_Manageraction_Central_Tab - Swith to another bin in Manager */
 281  class AA_Manageraction_Central_Tab extends AA_Manageraction {
 282  
 283      /** specifies, to which bin we want to switch */
 284      var $to_bin;
 285  
 286      /** Constructor - fills the information about the target bin */
 287      function AA_Manageraction_Central_Tab($id, $to_bin) {
 288          $this->to_bin = $to_bin;
 289          parent::AA_Manageraction($id);
 290      }
 291  
 292      /** main executive function - Handler for Tab switch - switch between bins */
 293      function perform(&$manager, &$state, $item_arr, $akce_param) {
 294          $manager->setBin($this->to_bin);
 295          $manager->go2page(1);
 296      }
 297  
 298      /** Checks if the user have enough permission to perform the action */
 299      function isPerm(&$manager) {
 300          return IsSuperadmin();
 301      }
 302  }
 303  
 304  
 305  
 306  /** Call remote AA_Optimize_* function
 307   *
 308   */
 309  class AA_Manageraction_Central_Optimize extends AA_Manageraction {
 310  
 311      /** class to be executed in remote AA */
 312      var $optimize_class;
 313  
 314      /** method to be called in optimize_class */
 315      var $optimize_method;
 316  
 317      /** Constructor - fills the information about the optimize method */
 318      function AA_Manageraction_Central_Optimize($id, $class, $method) {
 319          $this->optimize_class  = $class;
 320          $this->optimize_method = $method;
 321          parent::AA_Manageraction($id);
 322      }
 323  
 324      /** Name of this Manager's action */
 325      function getName() {
 326          return call_user_func(array($this->optimize_class, 'name')). ' - '.  $this->optimize_method;
 327      }
 328  
 329      /** main executive function
 330      * @param $param       - not used
 331      * @param $item_arr    - array of id of AA records to check
 332      * @param $akce_param  - not used
 333      */
 334      function perform(&$manager, &$state, $item_arr, $akce_param) {
 335          $ret    = array();
 336          $aa_ids = array_keys($item_arr);
 337  
 338          foreach ($aa_ids as $aa_id) {
 339              $aa = AA_Actionapps::getActionapps($aa_id);
 340              $ret[] = $aa->doOptimize($this->optimize_class, $this->optimize_method);
 341          }
 342          return join('<br>', $ret);   // @todo we should rewrite outputs from AA_Manageraction to some standard messages() system
 343      }
 344  
 345      /** Checks if the user have enough permission to perform the action */
 346      function isPerm(&$manager) {
 347          return IsSuperadmin();
 348      }
 349  }
 350  
 351  
 352  ?>

title

Description

title

Description

title

Description

title

title

Body