[ Index ]
 

Code source de Dolibarr 2.0.1

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/htdocs/telephonie/script/ -> retour.php (source)

   1  <?PHP
   2  /* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
   3   *
   4   * This program is free software; you can redistribute it and/or modify
   5   * it under the terms of the GNU General Public License as published by
   6   * the Free Software Foundation; either version 2 of the License, or
   7   * (at your option) any later version.
   8   *
   9   * This program is distributed in the hope that it will be useful,
  10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12   * GNU General Public License for more details.
  13   *
  14   * You should have received a copy of the GNU General Public License
  15   * along with this program; if not, write to the Free Software
  16   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17   *
  18   * $Id: retour.php,v 1.4 2005/10/24 09:53:29 rodolphe Exp $
  19   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/telephonie/script/retour.php,v $
  20   *
  21   * Script d'import des retour
  22   */
  23  
  24  require  ("../../master.inc.php");
  25  
  26  $dir = DOL_DATA_ROOT."/telephonie/ligne/commande/retour/";
  27  $dirdone = DOL_DATA_ROOT."/telephonie/ligne/commande/retour/traite/";
  28  
  29  $dirback = DOL_DATA_ROOT."/telephonie/ligne/commande/retour/backup/";
  30  
  31  if (! file_exists($dirback))
  32  {
  33    umask(0);
  34    if (! @mkdir($dirback, 0755))
  35      {
  36        dolibarr_syslog("Erreur: creation '$dir'");
  37      }
  38  }
  39  
  40  
  41  $handle=opendir($dir);
  42  
  43  if ($verbose) dolibarr_syslog("Lecture repertoire $dir");
  44  
  45  while (($file = readdir($handle))!==false)
  46  {
  47    if (is_file($dir.$file))
  48      {
  49  
  50        if (is_readable($dir.$file))
  51      {
  52        
  53        if ($verbose) dolibarr_syslog("Lecture $file");      
  54        
  55        if (! file_exists($dirdone))
  56          {
  57            umask(0);
  58            if (! @mkdir($dirdone, 0755))
  59          {
  60            dolibarr_syslog("Erreur: creation '$dirdone'");
  61          }
  62          }
  63        
  64        /* 
  65         * On verifie que le fichier n'a pas déjà été traité
  66         */
  67        if (! file_exists($dirdone.$file))
  68          {
  69            if ( import_file($db, $dir, $file) == 0)
  70          {
  71            rename($dir.$file, $dirdone.$file);
  72          }
  73          }
  74        else
  75          {
  76            dolibarr_syslog("Le fichier $file a déjà été traité");
  77          }      
  78      }
  79        else
  80      {
  81        dolibarr_syslog("Erreur Lecture $file permissions insuffisante");
  82      }
  83      }
  84  }
  85  
  86  closedir($handle);
  87  
  88  /**
  89   *
  90   *
  91   *
  92   */
  93  
  94  Function import_file($db,$dir,$file)
  95  {
  96    $error = 0;
  97    $line = 0;
  98    $hf = fopen ($dir.$file, "r");
  99  
 100    if ($db->query("BEGIN"))
 101      {
 102  
 103        while (!feof($hf))
 104      {
 105        $cont = fgets($hf, 1024);
 106        
 107        $tabline = explode(";", $cont);
 108        
 109        if (substr($tabline, 0, 3) <> 'CLI')
 110          {
 111            if (sizeof($tabline) == 8)
 112          {
 113            $numero            = $tabline[0];
 114            $mode              = $tabline[1];
 115            $situation         = $tabline[2];
 116            $date_mise_service = $tabline[3];
 117            $date_resiliation  = $tabline[4];
 118            $motif_resiliation = $tabline[5];
 119            $commentaire       = $tabline[6];
 120            $fichier = $file;
 121            
 122            $sql = "INSERT INTO ".MAIN_DB_PREFIX."telephonie_commande_retour ";
 123            
 124            $sql .= " (cli,mode,situation,date_mise_service,date_resiliation,motif_resiliation,commentaire,fichier,fk_fournisseur) ";
 125            $sql .= " VALUES (";
 126            $sql .= "'$numero','$mode','$situation','$date_mise_service','$date_resiliation','$motif_resiliation','$commentaire','$fichier',1)";
 127            
 128            if (! $db->query($sql))
 129              {
 130                dolibarr_syslog("Erreur de traitement de ligne");
 131                dolibarr_syslog($db->error());
 132                $error++;
 133              }
 134          }      
 135          }
 136        $line++;
 137      }
 138  
 139        if ($error == 0)
 140      {      
 141        $db->query("COMMIT");
 142        dolibarr_syslog("COMMIT");
 143      }
 144        else
 145      {
 146        $db->query("ROLLBACK");
 147        dolibarr_syslog("ROLLBACK");
 148      }
 149        
 150      }
 151  
 152    fclose($hf);
 153  
 154    return $error;
 155  }


Généré le : Mon Nov 26 12:29:37 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics