[ 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/ -> update_presel.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: update_presel.php,v 1.4 2005/12/01 15:33:25 rodolphe Exp $
  19   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/telephonie/script/update_presel.php,v $
  20   *
  21   *
  22   * Commandes des lignes par API
  23   *
  24   */
  25  require  ("../../master.inc.php");
  26  require_once DOL_DOCUMENT_ROOT."/telephonie/lignetel.class.php";
  27  
  28  $verbose = 0;
  29  
  30  for ($i = 1 ; $i < sizeof($argv) ; $i++)
  31  {
  32    if ($argv[$i] == "-v")
  33      {
  34        $verbose = 1;
  35      }
  36    if ($argv[$i] == "-vv")
  37      {
  38        $verbose = 2;
  39      }
  40    if ($argv[$i] == "-vvv")
  41      {
  42        $verbose = 3;
  43      }
  44  }
  45  
  46  
  47  $user = new User($db);
  48  $user->id = 1; // C'est sale je sais !
  49  
  50  $host          = CMD_PRESEL_WEB_HOST;
  51  $user_login    = CMD_PRESEL_WEB_USER;
  52  $user_passwd   = CMD_PRESEL_WEB_PASS;
  53  $user_contract = CMD_PRESEL_WEB_CONTRACT;
  54  
  55  /*
  56   * Lecture des lignes a commander
  57   *
  58   */
  59  $sql = "SELECT s.nom, s.idp as socid, s.address, s.cp, s.ville";
  60  $sql .= ", l.ligne, l.statut, l.rowid";
  61  
  62  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
  63  $sql .= " , ".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
  64  $sql .= " , ".MAIN_DB_PREFIX."telephonie_fournisseur as f";
  65  $sql .= " WHERE l.fk_soc = s.idp AND l.fk_fournisseur = f.rowid";
  66  $sql .= " AND f.rowid = 4";
  67  $sql .= " AND l.ligne='".$argv[1]."'";
  68  $sql .= " ORDER BY l.rowid DESC";
  69  
  70  $resql = $db->query($sql);
  71  $result = 1;
  72  if ($resql)
  73  {
  74    $i = 0;
  75    $num = $db->num_rows($resql);
  76    print "$num lignes\n";  
  77    while ($i < $num)
  78      {
  79        $obj = $db->fetch_object($resql);
  80      
  81        $lint = new LigneTel($db);
  82        $lint->fetch_by_id($obj->rowid);
  83  
  84        $result = UpdatePreselection($host, $user_login, $user_passwd, $lint, $num_abo);
  85       
  86        $i++;
  87      }
  88  }
  89  
  90  function UpdatePreselection($host, $user_login, $user_passwd, $lint, $id_person)
  91  {  
  92    global $verbose;
  93    dolibarr_syslog("UpdatePreselection($host, $user_login, ****, $ligne, $id_person)");
  94  
  95    $url = "/AzurApp_websvc_b3gdb/account.asmx/UpdatePreselection?";
  96  
  97    $url .= "user_login=".  $user_login;
  98    $url .= "&user_passwd=".$user_passwd;
  99    $url .= "&telnum=".$lint->numero;
 100    $url .= "&okCollecte=true";
 101    $url .= "&okPreselection=true";
 102  
 103    if ($verbose > 2)
 104      dolibarr_syslog("$host");
 105  
 106    if ($verbose > 2)
 107      dolibarr_syslog("$url");
 108  
 109    $fp = fsockopen($host, 80, $errno, $errstr, 30);
 110    if (!$fp)
 111      {
 112        dolibarr_syslog("$errstr ($errno)");
 113      }
 114    else
 115      {
 116        if ($verbose > 2)
 117      dolibarr_syslog("Socket Opened send data");
 118  
 119        $out = "GET $url HTTP/1.1\r\n";
 120        $out .= "Host: $host\r\n";
 121        $out .= "Connection: Close\r\n\r\n";
 122        
 123        fwrite($fp, $out);
 124        
 125        if ($verbose > 2)
 126      dolibarr_syslog("Data sent, waiting for response");
 127  
 128        $parse = 0;
 129        $result = "error";
 130  
 131        $fresult = "";
 132        
 133        while (!feof($fp))
 134      {
 135        $line = fgets($fp, 1024);
 136        
 137        if ($verbose > 2)
 138          dolibarr_syslog($line);
 139  
 140        if ($parse == 1)
 141          {
 142            preg_match('/^<string xmlns=".*">(.*)<\/string>$/', $line, $results);
 143            
 144            $result = $results[1];
 145            dolibarr_syslog($line);
 146            $parse = 0;
 147          }
 148        
 149        if (substr($line,0,38) == '<?xml version="1.0" encoding="utf-8"?>')
 150          {
 151            $parse = 1;
 152          }
 153  
 154        $fresult .= $line;
 155  
 156      }
 157        fclose($fp);
 158      }
 159    
 160    if ($verbose > 1)
 161      dolibarr_syslog("result = ".$result);
 162  
 163    if (substr($result,0,2) == "OK")
 164      {
 165        dolibarr_syslog("Presel OK  ".$lint->numero." ".$lint->support." id client ".$id_person." $result\n");
 166        return 0;
 167      }
 168    else
 169      {
 170        dolibarr_syslog("Presel ERR ".$lint->numero." ".$lint->support." id client ".$id_person." $result\n");
 171  
 172        $fp = fopen("/tmp/".$lint->numero.".presel","w");
 173        if ($fp)
 174      {
 175        fwrite($fp, $fresult);
 176        fclose($fp);
 177      }
 178  
 179        return -1;
 180      }
 181  }
 182  
 183  
 184  ?>


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