HEX
Server: Apache/2.2.15 (CentOS)
System: Linux ip-10-0-2-146.eu-west-1.compute.internal 2.6.32-754.35.1.el6.centos.plus.x86_64 #1 SMP Sat Nov 7 11:33:42 UTC 2020 x86_64
User: root (0)
PHP: 5.6.40
Disabled: NONE
Upload Files
File: /www/exchange0old/auws/client/group_upload.php
<?php
  include('api_upload.php');
  class Group_upload extends Api_upload
  {
      function test()
      {
          if (!file_exists('invoices.csv'))
          {
              $this->setError('invoices.csv doesn\'t exist');
              return FALSE;
          }
          
          if ((($handle=fopen('invoices.csv','r'))=== FALSE) OR (($header=fgetcsv($handle,0,';'))===FALSE)) 
          {
              $this->setError('Can not open invoices.csv');
              return FALSE;
          }
          
          $fields=$this->getFields();
          $fields=array_flip($fields['invoiceData']);
          
          foreach($header as $index=>$field)
          {
              $fields[$field]=$index;
          }
          $fields=array_flip($fields);
          
          $xml=$originatorId=$apiKey='';
          
          while (($invoice = fgetcsv($handle,0, ";")) !== FALSE)
          {
              $invoice_data=array();
              foreach($invoice as $index=>$value)
              {
                  if (in_array($fields[$index],array('originatorId','apiKey')))
                  {
                      if (($originatorId!='') AND ($originatorId!=$value) AND ($fields[$index]=='originatorId'))
                      {
                          $this->setError('Possible to upload data only for 1 originator');
                          return FALSE;
                      }
                      $$fields[$index]=$value;
                      continue;
                  }
                  
                  if ($fields[$index]=='invoicePDF')
                  {
                      $value=base64_encode(file_get_contents($value));
                  }
                  
                  $invoice_data[]='<'.$fields[$index].'>'.$value.'</'.$fields[$index].'>';
              }
              $xml.='<invoiceData>'.implode("\r\n",$invoice_data).'</invoiceData>'."\r\n";
          }
          fclose($handle);
          $fields=array_flip($fields);
          
          $xml='<?xml version="1.0" encoding="UTF-8"?>
                <invoiceBatch>
                    <originatorId>'.$originatorId.'</originatorId>
                    <apiKey>'.$apiKey.'</apiKey>'.
                    $xml.
                '</invoiceBatch>';
          
          return htmlentities($this->get_data(array('xmlData'=>$xml)));
      }
  }
  
  $test= new Group_upload();
  if (!$result=$test->test())
  {
      exit('Error - '.$test->getError());
  }
  
  echo '<pre>'.$result.'</pre>';
?>