[ Index ]
 

Code source de Plume CMS 1.2.2

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/manager/extinc/ -> class.xmlsql.php (source)

   1  <?php
   2  # ***** BEGIN LICENSE BLOCK *****
   3  # This file is part of DotClear.
   4  # Copyright (c) 2004 Olivier Meunier and contributors. All rights
   5  # reserved.
   6  #
   7  # DotClear 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  # DotClear 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 DotClear; if not, write to the Free Software
  19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  20  #
  21  # ***** END LICENSE BLOCK *****
  22  
  23  class xmlsql
  24  {
  25      var $job = array();
  26      var $xml;
  27      var $con;
  28      var $_action;
  29      var $_current_tag_cdata;
  30  
  31      var $_subtable = array(
  32          'test' => array(
  33              'sql' => NULL,
  34              'eq' => 'eq',
  35              'value' => NULL,
  36              'label' => NULL,
  37              'string' => NULL,
  38              'type' => 'err',
  39              'field' => 0 /*the field to test from the query array result. */
  40          ),
  41          'request' => array(
  42              'label' => NULL,
  43              'string' => NULL,
  44              'sql' => NULL
  45          )
  46      );
  47      
  48  	function xmlsql(&$con,$xml)
  49      {
  50          $this->xml = $xml;
  51          $this->con = $con;
  52          $this->_current_tag_cdata = '';
  53      }
  54  
  55  	function replace($needle,$str)
  56      {
  57          $this->xml = str_replace($needle,$str,$this->xml);
  58      }
  59      
  60  	function execute(&$checklist)
  61      {
  62          $this->_parse();
  63          
  64          foreach ($this->job as $k => $v)
  65          {
  66  
  67              $test = true;
  68              $ok = $err = '';
  69  
  70              # Si $test n'est pas faux et qu'on a un test SQL 
  71              if ($test !== false && $v['test']['sql'] != NULL && $v['test']['value'] != NULL)
  72              {
  73                  $req = $v['test']['sql'];
  74                  $ok = sprintf($v['test']['label'],$v['test']['string']);
  75  
  76                  if (($rs = $this->con->select($req)) === false)
  77                  {
  78                      $test = false;
  79                      $err = $this->con->error();
  80                  }
  81                  else
  82                  {
  83                      if ($v['test']['eq'] == 'neq') {
  84                          $test = $rs->f($v['test']['field']) != $v['test']['value'];
  85                      } else {
  86                          $test = $rs->f($v['test']['field']) == $v['test']['value'];
  87                      }
  88                      
  89                      if ($test == false && $v['test']['type'] == 'wrn') {
  90                          $test = NULL;
  91                      } elseif ($test == false) {
  92                          $err = sprintf($v['test']['label'], $v['test']['string']);
  93                      }
  94                  }
  95              }
  96              
  97              # Si le test est passé, on tente la requête
  98              if ($test === true)
  99              {
 100                  $ok = sprintf($v['request']['label'],$v['request']['string']);
 101                  
 102                  $req = $v['request']['sql'];
 103                  
 104                  if ($this->con->execute($req) === false) {
 105                      $test = false;
 106                      $err = sprintf($v['request']['label'],
 107                          $v['request']['string']).' - '.
 108                          $this->con->error();
 109                  } else {
 110                      $test = true;
 111                  }
 112                  
 113              }
 114              elseif ($err == '')
 115              {
 116                  $err = sprintf($v['request']['label'],$v['request']['string']);
 117              }
 118              
 119              $checklist->addItem($k,$test,$ok,$err);
 120          }
 121      }
 122      
 123  	function _parse()
 124      {
 125          $xp = xml_parser_create('ISO-8859-1');
 126          xml_parser_set_option($xp, XML_OPTION_CASE_FOLDING, false);
 127          xml_set_object($xp,$this);
 128          xml_set_element_handler($xp,'_openTag','_closeTag');
 129          xml_set_character_data_handler($xp, '_cdata');
 130          xml_parse($xp,$this->xml);
 131          xml_parser_free($xp);
 132      }
 133      
 134  	function _openTag($p,$tag,$attr)
 135      {
 136          if ($tag == 'action' && !empty($attr['id']))
 137          {
 138              $id = $this->_action = $attr['id'];
 139              $this->job[$id] = $this->_subtable;
 140              
 141              if (!empty($attr['label'])) {
 142                  $this->job[$id]['request']['label'] = __($attr['label']);
 143              }
 144              if (!empty($attr['string'])) {
 145                  $this->job[$id]['request']['string'] = $attr['string'];
 146              }
 147          }
 148          elseif($tag == 'test')
 149          {
 150              $id = $this->_action;
 151              
 152              if (!empty($attr['eq'])) {
 153                  $this->job[$id]['test']['eq'] = $attr['eq'];
 154              }
 155              if (!empty($attr['value'])) {
 156                  $this->job[$id]['test']['value'] = $attr['value'];
 157              }
 158              if (!empty($attr['label'])) {
 159                  $this->job[$id]['test']['label'] = __($attr['label']);
 160              }
 161              if (!empty($attr['string'])) {
 162                  $this->job[$id]['test']['string'] = $attr['string'];
 163              }
 164              if (!empty($attr['type'])) {
 165                  $this->job[$id]['test']['type'] = $attr['type'];
 166              }
 167              if (!empty($attr['field'])) {
 168                  $this->job[$id]['test']['field'] = (int) $attr['field'];
 169              }
 170          }
 171      }
 172      
 173  	function _closeTag($p,$tag)
 174      {
 175          if ($tag == 'action') {
 176              $this->job[$this->_action]['request']['sql'] = trim($this->_current_tag_cdata);
 177          }
 178          elseif ($tag == 'test') {
 179              $this->job[$this->_action]['test']['sql'] = trim($this->_current_tag_cdata);
 180          }
 181          $this->_current_tag_cdata = '';
 182      }
 183      
 184  	function _cdata($p,$cdata)
 185      {
 186          $this->_current_tag_cdata .= $cdata;
 187      }
 188  }
 189  
 190  ?>


Généré le : Mon Nov 26 11:57:01 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics