[ 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/ -> commande_presel_statut.php (source)

   1  <?PHP
   2  /* Copyright (C) 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: commande_presel_statut.php,v 1.7 2005/12/05 13:35:19 rodolphe Exp $
  19   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/telephonie/script/commande_presel_statut.php,v $
  20   *
  21   *
  22   * Recupération des fichiers CDR
  23   *
  24   */
  25  require  ("../../master.inc.php");
  26  _log($GLOBALS["argv"][0]." Start", LOG_NOTICE);
  27  require_once DOL_DOCUMENT_ROOT."/telephonie/lignetel.class.php";
  28  require_once (DOL_DOCUMENT_ROOT."/lib/dolibarrmail.class.php");
  29  
  30  set_time_limit(0);
  31  
  32  $host          = CMD_PRESEL_WEB_HOST;
  33  $user_login    = CMD_PRESEL_WEB_USER;
  34  $user_passwd   = CMD_PRESEL_WEB_PASS;
  35  
  36  _log($GLOBALS["argv"][0]." Lecture des lignes", LOG_NOTICE);
  37  
  38  $sql = "SELECT rowid,ligne";
  39  $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_societe_ligne";
  40  $sql .= " WHERE fk_fournisseur = 4";
  41  $sql .= " AND statut = 2;";
  42  
  43  $resql = $db->query($sql);
  44  
  45  if ($resql)
  46  {
  47    $ids = array();
  48    while ($row = $db->fetch_row($resql))
  49      {
  50        array_push($ids, $row[1]);
  51      }
  52  }
  53  else
  54  {
  55    _log($GLOBALS["argv"][0]." Erreur lecture liste des lignes", LOG_ERR);
  56    exit(1);
  57  }
  58  
  59  if (sizeof($ids) == 0)
  60  {
  61    _log($GLOBALS["argv"][0]. " Aucune lignes à traiter - fin", LOG_NOTICE);
  62    exit(0);
  63  }
  64  
  65  $lignes = array();
  66  for ($i = 0 ; $i < 10 ; $i++)
  67    $lignes[$i] = array();
  68  
  69  foreach ($ids as $id)
  70  {
  71    $idx = substr($id, -1);
  72    array_push($lignes[$idx], $id);
  73  }
  74  
  75  $childrenTotal = 10;
  76  $childrenNow = 0;
  77  
  78  while ( $childrenNow < $childrenTotal )
  79  {
  80    $pid = pcntl_fork();
  81    
  82    if ( $pid == -1 )
  83      {
  84        die( "error\n" );
  85      }
  86    elseif ( $pid  )
  87      {
  88        // Père
  89        $childrenNow++;
  90      }
  91    else
  92      {
  93        if (sizeof($lignes[$childrenNow]))
  94      {
  95        // Fils
  96        GetPreselection_byRef($db, $host, $user_login, $user_passwd, $lignes[$childrenNow]);
  97      }
  98        exit(0);
  99      }
 100  }
 101  
 102  /*
 103   * Fonctions
 104   *
 105   */
 106  
 107  function GetPreselection_byRef($db, $host, $user_login, $user_passwd, $ids)
 108  {  
 109  
 110    $user = new User($db);
 111    $user->id = 1;
 112  
 113    foreach($ids as $cli)
 114      {
 115        _log("$cli Debut Traitement ligne", LOG_NOTICE);
 116  
 117        $fp = @fsockopen($host, 80, $errno, $errstr, 30);
 118        if (!$fp)
 119      {
 120        _log("Impossible de se connecter au server $errstr ($errno)", LOG_ERR);
 121      }
 122        else
 123      {
 124        $ligne_numero = "";
 125        $ligne_service = "";
 126        $ligne_presel = "";
 127  
 128        //GetPreselection_byRef  
 129        $url = "/AzurApp_websvc_b3gdb/account.asmx/GetPreselection_byRef?";
 130  
 131        $url .= "user_login=".  $user_login;
 132        $url .= "&user_passwd=".$user_passwd;
 133        $url .= "&telnum=".$cli;
 134  
 135        $out = "GET $url HTTP/1.1\r\n";
 136        $out .= "Host: $host\r\n";
 137        $out .= "Connection: Close\r\n\r\n";
 138        
 139        fwrite($fp, $out);
 140        
 141        while (!feof($fp))
 142          {
 143            $line = fgets($fp, 1024);
 144  
 145            if (preg_match("/<Preselection .* \/>/",$line))
 146          {          
 147            $results = split(" ",trim($line));
 148            //print_r($results);
 149            
 150            $array = array();
 151            preg_match('/telnum="([0123456789]*)"/', $line, $array);
 152            $ligne_numero = $array[1];
 153            
 154            $array = array();
 155            preg_match('/Service_Statut="([\S]*)"/i', $line, $array);
 156            $ligne_service = $array[1];
 157            
 158            $array = array();
 159            preg_match('/PreSelection_Statut="([\S]*)"/i', $line, $array);
 160            $ligne_presel = $array[1];
 161            
 162            _log($ligne_numero." ".$ligne_service." / ".$ligne_presel,LOG_NOTICE);
 163          }
 164  
 165            if (preg_match("/<Error .* \/>/",$line))
 166          {          
 167            $array = array();
 168            preg_match('/libelle="(.*)" xmlns:d4p1/', $line, $array);
 169            _log($cli . " ErreurAPI ".$array[1], LOG_ERR);
 170          }
 171          }
 172        fclose($fp);
 173  
 174        if ($ligne_numero)// && $ligne_service && $ligne_presel)
 175          {
 176            $situation_key = "$ligne_service / $ligne_presel";
 177        
 178            $sql = "SELECT date_traitement, situation";
 179            $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_commande_retour";
 180            $sql .= " WHERE fk_fournisseur = 4";
 181            $sql .= " AND cli = '".$ligne_numero."'";
 182            $sql .= " ORDER BY date_traitement DESC LIMIT 1;";
 183            
 184            $resql = $db->query($sql);
 185            
 186            if ($resql)
 187          {
 188            $num = $db->num_rows($resql);
 189            $insert = 0;
 190            if ($num == 0)
 191              {
 192                $insert = 1;
 193              }
 194            else
 195              {
 196                $row = $db->fetch_row($resql);
 197                if (trim($row[1]) <> trim($situation_key))
 198              {
 199                $insert = 1;
 200              }
 201              }
 202          }
 203            else
 204          {
 205            _log("$cli lecture etat de ligne ERREUR", LOG_ERR);
 206          }
 207            
 208            _log("$cli log etat de la ligne", LOG_NOTICE);
 209            if ($insert == 1)
 210          {
 211            $sql = "INSERT INTO ".MAIN_DB_PREFIX."telephonie_commande_retour";
 212  
 213            if ($situation_key == 'TRAITE_OK / EN_COURS')
 214              {
 215                $sql .= " (cli,mode,date_traitement,situation,fk_fournisseur,traite) ";
 216                $sql .= " VALUES ('$ligne_numero','PRESELECTION',now(),'$situation_key',4,1);";
 217              }
 218            elseif ($situation_key == 'ATTENTE / EN_COURS')
 219              {
 220                $sql .= " (cli,mode,date_traitement,situation,fk_fournisseur,traite) ";
 221                $sql .= " VALUES ('$ligne_numero','PRESELECTION',now(),'$situation_key',4,1);";
 222              }
 223            elseif ($situation_key == 'TRAITE_OK / TRAITE_OK')
 224              {
 225                $sql .= " (cli,mode,date_traitement,situation,fk_fournisseur,traite) ";
 226                $sql .= " VALUES ('$ligne_numero','PRESELECTION',now(),'$situation_key',4,1);";
 227              }
 228            else
 229              {
 230                $sql .= " (cli,mode,date_traitement,situation,fk_fournisseur) ";
 231                $sql .= " VALUES ('$ligne_numero','PRESELECTION',now(),'$situation_key',4);";
 232              }
 233  
 234            $resql = $db->query($sql);
 235                      
 236            if ($resql)
 237              {
 238                _log("$cli log etat de la ligne SUCCESS", LOG_NOTICE);
 239  
 240                if ($situation_key == 'TRAITE_OK / TRAITE_OK')
 241              {
 242                $ligne = new LigneTel($db);
 243    
 244                if ($ligne->fetch($cli) == 1)
 245                  {
 246                    if ($ligne->statut == 2)
 247                  {
 248                    $statut = 3;
 249                    $date_mise_service = strftime(time());
 250                    $datea = $db->idate($date_mise_service);
 251                    
 252                    if ($ligne->set_statut($user, $statut, $datea) <> 0)
 253                      {
 254                        $error++;
 255                        print "ERROR\n";
 256                      }
 257                  }
 258                  }
 259                else
 260                  {
 261                    print "Erreur de lecture\n";
 262                  }
 263              }
 264  
 265                if ($situation_key == 'TRAITE_OK / ATTENTE')
 266              {
 267                $ligne = new LigneTel($db);
 268    
 269                if ($ligne->fetch($cli) == 1)
 270                  {
 271                    if ($ligne->statut == 2)
 272                  {
 273                    $statut = 7;
 274                    $date_mise_service = strftime(time());
 275                    $datea = $db->idate($date_mise_service);
 276                    
 277                    if ($ligne->set_statut($user, $statut, $datea) <> 0)
 278                      {
 279                        $error++;
 280                        print "ERROR\n";
 281                      }
 282                  }
 283                  }
 284                else
 285                  {
 286                    print "Erreur de lecture\n";
 287                  }
 288              }
 289  
 290              }
 291            else
 292              {
 293                _log("$cli log etat de la ligne ERREUR", LOG_ERR);
 294              }
 295          }
 296            else
 297          {
 298            _log("$cli log etat de la ligne IDENTIQUE", LOG_NOTICE);
 299          }
 300          }
 301        else
 302          {
 303            _log("$cli ERREUR impossible de récupérer les infos", LOG_ERR);
 304          }
 305        _log("$cli Fin Traitement ligne", LOG_NOTICE);
 306      }
 307      }
 308  }
 309  
 310  function _log($message, $level)
 311  {
 312  
 313    if ($level == LOG_ERR)
 314      {
 315        openlog("dolibarr", LOG_PID | LOG_PERROR, LOG_LOCAL3);
 316      }
 317    else
 318      {
 319        openlog("dolibarr", LOG_PID, LOG_LOCAL3);
 320      }
 321    syslog($level, $message);
 322  
 323    closelog();
 324  }
 325  
 326  ?>


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