<?php

class processMt {
 
 private $_options;
 private $_daemon;
 
 public function __construct(GeckaSMGdaemon $daemon, $options) {
  
  $this->_daemon = $daemon;
  $this->_options = $options;
 
 }
 
 public function run() {
  
  require_once 'Smg/Mt/Queue.php';
  
  $queue = new Smg_Mt_Queue ( $this->_options );
  
  /**
   * Mo en attente de traitement
   */
  $awaiting = $queue->ListAwaiting ();
  
  if ($awaiting) {
   
   $num = sizeof ( $awaiting );
   
   $this->_daemon->_logMessage ( $num . " MT awaiting" );
   
   
   foreach ( $awaiting as $mt ) {
    $this->_daemon->_logMessage ( "- MT #$mt->_id created on $mt->mt_dateCreated for " . $mt->DA  );
   
    require_once 'Smg/Socket/Mmg.php';
    $socket = new Smg_Socket_Mmg($this->_options['Config']->MMG->Server, 
            $this->_options['Config']->MMG->Port, 
            $this->_options['Config']->MMG->Url, 
            $this->_options['Config']->MMG->UserName, 
            $this->_options['Config']->MMG->Password, 
            $this->_options['Config']->MMG->SenderId,
            $this->_options['Config']->MMG->SSL);

    $this->_daemon->_logMessage ( "  - Sending MT ..." );
   
    $status = $socket->send($mt->getMmgInfos());
    if(!$status) {
     
     $nextsend = strtotime('+' . $this->_options['Config']->MT->delay_before_resend, time());
     $nextsend = date('Y-m-d H:i:s', $nextsend);
     $mt->setStatus($socket->errorCode);
     $mt->mt_dateNextSend = $nextsend;
     $mt->save();
     
     $this->_daemon->_logMessage ( "  - Failed!  (" . $socket->errorMessage . ")" );
     $this->_daemon->_logMessage ( "  - Retriyng in " . $this->_options['Config']->MT->delay_before_resend );
    }
    else {
     
     $mt->setStatus(1);
     $mt->mt_mmgid = $socket->MsgID;
     $mt->mt_dateShipped = $mt->mt_dateLastTrack = date('Y-m-d H:i:s', time());
     $mt->save();
    
     $this->_daemon->_logMessage ( "  - Done!" );
    }
    
   }
  
  }
 
 }

}


?>

Add a code snippet to your website: www.paste.org