/[dolibarr]/dolibarr/htdocs/telephonie/script/commande_presel_statut.php
ViewVC logotype

Diff of /dolibarr/htdocs/telephonie/script/commande_presel_statut.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by rodolphe, Thu Oct 20 11:08:35 2005 UTC revision 1.2 by rodolphe, Thu Oct 20 13:27:07 2005 UTC
# Line 31  $host          = CMD_PRESEL_WEB_HOST; Line 31  $host          = CMD_PRESEL_WEB_HOST;
31  $user_login    = CMD_PRESEL_WEB_USER;  $user_login    = CMD_PRESEL_WEB_USER;
32  $user_passwd   = CMD_PRESEL_WEB_PASS;  $user_passwd   = CMD_PRESEL_WEB_PASS;
33    
34  dolibarr_syslog($GLOBALS["argv"][0]." Lecture des lignes");  _log($GLOBALS["argv"][0]." Lecture des lignes", LOG_NOTICE);
35    
36  $sql = "SELECT rowid,ligne";  $sql = "SELECT rowid,ligne";
37  $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_societe_ligne";  $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_societe_ligne";
# Line 50  if ($resql) Line 50  if ($resql)
50  }  }
51  else  else
52  {  {
53    dolibarr_syslog($GLOBALS["argv"][0]." Erreur lecture liste des lignes");    _log($GLOBALS["argv"][0]." Erreur lecture liste des lignes", LOG_ERR);
54    exit(1);    exit(1);
55  }  }
56    
57  if (sizeof($ids) == 0)  if (sizeof($ids) == 0)
58  {  {
59    dolibarr_syslog($GLOBALS["argv"][0]. " Aucune lignes à traiter - fin");    _log($GLOBALS["argv"][0]. " Aucune lignes à traiter - fin", LOG_NOTICE);
60    exit(0);    exit(0);
61  }  }
62    
# Line 106  function GetPreselection_byRef($db, $hos Line 106  function GetPreselection_byRef($db, $hos
106  {    {  
107    foreach($ids as $cli)    foreach($ids as $cli)
108      {      {
109        $fp = fsockopen($host, 80, $errno, $errstr, 30);        _log("$cli Debut Traitement ligne", LOG_NOTICE);
110    
111          $fp = @fsockopen($host, 80, $errno, $errstr, 30);
112        if (!$fp)        if (!$fp)
113          {          {
114            dolibarr_syslog("$errstr ($errno)");            _log("Impossible de se connecter au server $errstr ($errno)", LOG_ERR);
115          }          }
116        else        else
117          {          {
118              $ligne_numero = "";
119              $ligne_service = "";
120              $ligne_presel = "";
121    
122            //GetPreselection_byRef              //GetPreselection_byRef  
123            $url = "/AzurApp_websvc_b3gdb/account.asmx/GetPreselection_byRef?";            $url = "/AzurApp_websvc_b3gdb/account.asmx/GetPreselection_byRef?";
124    
# Line 147  function GetPreselection_byRef($db, $hos Line 153  function GetPreselection_byRef($db, $hos
153                    preg_match('/PreSelection_Statut="([\S]*)"/i', $line, $array);                    preg_match('/PreSelection_Statut="([\S]*)"/i', $line, $array);
154                    $ligne_presel = $array[1];                    $ligne_presel = $array[1];
155                                        
156                    dolibarr_syslog(print $ligne_numero." ".$ligne_service." / ".$ligne_presel);                    _log($ligne_numero." ".$ligne_service." / ".$ligne_presel,LOG_NOTICE);
157                  }                                      }
158    
159                  if (preg_match("/<Error .* \/>/",$line))
160                    {            
161                      $array = array();
162                      preg_match('/libelle="(.*)" xmlns:d4p1/', $line, $array);
163                      _log($cli . " ErreurAPI ".$array[1], LOG_ERR);
164                    }
165              }              }
166            fclose($fp);            fclose($fp);
167    
168            $situation_key = "$ligne_service / $ligne_presel";            if ($ligne_numero && $ligne_service && $ligne_presel)
   
           $sql = "SELECT max(date_traitement), situation";  
           $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_commande_retour";  
           $sql .= " WHERE fk_fournisseur = 4";  
           $sql .= " AND cli = '".$ligne_numero."'";  
           $sql .= " GROUP BY cli;";  
   
           $resql = $db->query($sql);  
   
           if ($resql)  
169              {              {
170                $num = $db->num_rows($resql);  
171                $insert = 0;                $situation_key = "$ligne_service / $ligne_presel";
172                if ($num == 0)            
173                  $sql = "SELECT max(date_traitement), situation";
174                  $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_commande_retour";
175                  $sql .= " WHERE fk_fournisseur = 4";
176                  $sql .= " AND cli = '".$ligne_numero."'";
177                  $sql .= " GROUP BY cli;";
178                  
179                  $resql = $db->query($sql);
180                  
181                  if ($resql)
182                  {                  {
183                    $insert = 1;                    $num = $db->num_rows($resql);
184                      $insert = 0;
185                      if ($num == 0)
186                        {
187                          $insert = 1;
188                        }
189                      else
190                        {
191                          $row = $db->fetch_row($resql);
192                          if ($row[1] <> $situation_key)
193                            {
194                              $insert = 1;
195                            }
196                        }
197                  }                  }
198                else                else
199                  {                  {
200                    $row = $db->fetch_row($resql);                    _log("$cli lecture etat de ligne ERREUR", LOG_ERR);
201                    if ($row[1] <> $situation_key)                  }
202                  
203                  if ($insert == 1)
204                    {
205                      $sql = "INSERT INTO ".MAIN_DB_PREFIX."telephonie_commande_retour";
206                      $sql .= " (cli,mode,date_traitement,situation,fk_fournisseur) ";
207                      $sql .= " VALUES ('$ligne_numero','PRESELECTION',now(),'$situation_key',4);";
208                      
209                      $resql = $db->query($sql);
210                      
211                      _log("$cli log etat de la ligne", LOG_NOTICE);
212                      
213                      if ($resql)
214                      {                      {
215                        $insert = 1;                        _log("$cli log etat de la ligne SUCCESS", LOG_NOTICE);
216                        }
217                      else
218                        {
219                          _log("$cli log etat de la ligne ERREUR", LOG_ERR);
220                      }                      }
221                  }                  }
222              }              }
223            else            else
224              {              {
225                dolibarr_syslog("Erreur lecture etat de ligne");                _log("$cli ERREUR impossible de récupérer les infos", LOG_ERR);
226              }              }
227              _log("$cli Fin Traitement ligne", LOG_NOTICE);
228            }
229        }
230    }
231    
232            if ($insert == 1)  function _log($message, $level)
233              {  {
               $sql = "INSERT INTO ".MAIN_DB_PREFIX."telephonie_commande_retour";  
               $sql .= " (cli,mode,date_traitement,situation,fk_fournisseur) ";  
               $sql .= " VALUES ('$ligne_numero','PRESELECTION',now(),'$situation_key',4);";  
   
               $resql = $db->query($sql);  
   
               if ($resql)  
                 {  
                     
                 }  
               else  
                 {  
                   dolibarr_syslog("Error 43");  
                 }  
             }  
234    
235          }    if ($level == LOG_ERR)
236        {
237          openlog("dolibarr", LOG_PID | LOG_PERROR, LOG_LOCAL3);
238        }
239      else
240        {
241          openlog("dolibarr", LOG_PID, LOG_LOCAL3);
242      }      }
243      syslog($level, $message);
244    
245      closelog();
246  }  }
247    
248  ?>  ?>

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26