<?php
require_once 'lib/nusoap.php';
require_once 'lib/moneycurrency.class.php';
require_once 'conf.php';
class Auction{
var $soap;
var $sesja=array();
var $katBookOther = 46349;
var $katTestWebApi = 1821;
var $aukcja = array(
'sku' => 0,
'tytul' => "arbuzy11", //fid - 1
'kategoria' => 46349, //fid - 2
'czas_trwania' => 1, //fid - 4 //0,1,2,3
'sztuk' => 1, //fid - 5
'cena' => "10.00", //fid - 8
'kraj' => 1, //fid - 9
'trans' => 1, //fid - 12 //0-seller 1-buyer
'forma_trans' => 52, //fid - 13 //1-postal service 2-priority 3-bouth 4- kurier
'platnosc' => 1, //fid - 14 //nie moge ustawic
'special' => 2, //fid - 15 //0- nic 2-miniaturka
'zdjecie' => "", //fid - 16
'opis' => "to jest produkt", //fid - 24
'koszt_trans' => "5.50", //fid - 25
'ups' => "",
'waga' => "",
'isbn' => ""
);
//////////////////////////////Funkcja zmienia dolary na zlotowki/////////////
function getToPln($oldPrice){
$api = new MoneyAPI;
$from = constant('MYCURRENCY');
$want = 'PLN';
$total = $oldPrice;
$stream = $api->open() or die('Unable to locate stream!');
return $api->convert($stream, $from, $want, $total, false, 4);
}
function endAuction($squ){
$params = array(
'session-handle' => $this->sesja['session-handle-part'],
'finish-item-id' => $this->getId($squ),
'finish-item-all-bids' => 1,
'finish-cancel-reason' => 'Przedmiot sprzedany w innym serwisie'
);
if(doFinishAuction($params)) delFromSqu($params(finish-item-id));
}
/////////////////////////Funkcja wystaw jedna aukcje/////////////
function sell( array $data , $soap ){
if($data[14]==0)$this->andAuction($data[0]); //if quantity 0 remove from allegro
else{
$this->aukcja['sku']=$data[0];
$this->aukcja['tytul']=$this->getTitle($data[1],$data[2]);
$this->aukcja['kategoria']=$this->getCategory($data[6]);
$this->aukcja['cena']=$data[15];
$file = ''; //link to photo
$this->aukcja['zdjecie'] = base64_encode(implode ( "", file ( $file ) )) ;
if($this->aukcja['zdjecie']==null)
$this->aukcja['special']=0;
if($data[14]!='')
$this->aukcja['sztuk']=$data[14];
if($data[32]!='')
$this->aukcja['ups']=$data[32];
if($data[31]!='')
$this->aukcja['waga']=$data[31];
if($data[7]!='')
$this->aukcja['isbn']=$data[7];
//echo $this->aukcja['opis'];
$cena = $this->getToPln($this->aukcja['cena']);
$param=array();
$param[0]=array('fid'=>1, 'fvalue-string'=>$this->aukcja['tytul']); //tytul
$param[1]=array('fid'=>2, 'fvalue-int'=>$this->aukcja['kategoria']);
$param[2]=array('fid'=>4, 'fvalue-int'=>$this->aukcja['czas_trwania']); // czas trwania w dn
$param[3]=array('fid'=>5, 'fvalue-int'=>$this->aukcja['sztuk']);
$param[4]=array('fid'=>8, 'fvalue-int'=>'', 'fvalue-float'=>$cena);
$param[5]=array('fid'=>9, 'fvalue-int'=>$this->aukcja['kraj']);
$param[6]=array('fid'=>10, 'fvalue-int'=>0);
$param[7]=array('fid'=>11, 'fvalue-string'=>'Nowy Jork' );
$param[8]=array('fid'=>12, 'fvalue-int'=>$this->aukcja['trans']);
$param[9]=array('fid'=>13, 'fvalue-int'=>$this->aukcja['forma_trans']);
$param[10]=array('fid'=>14, 'fvalue-string'=>'string', 'fvalue-int'=>$this->aukcja['platnosc']);
$param[11]=array('fid'=>15, 'fvalue-int'=>$this->aukcja['special'] );
$param[12]=array('fid'=>16, 'fvalue-image'=> $this->aukcja['zdjecie'] );
$param[13]=array('fid'=>24, 'fvalue-string'=>$this->getDesc($data) );
$param[14]=array('fid'=>25, 'fvalue-float'=>constant('SHIPCOST'));
$param[15]=array('fid'=>27, 'fvalue-string'=>'description of delivery');
//sklep //0-public auction, 1-id
//unset($data);
$parameters = array($this->sesja['session-handle-part'], $param, 0, 1);
$item=$soap->call('doNewAuctionExt',$parameters);
//unset($parameters[1]);
$err = $soap->getError();
if ($err) {
// Display the error
echo '<p><b>Selling item sku: '.$aukcja['sku'].' error: ' . $err . '</b></p>';
return false;
// At this point, you know the call that follows will fail
}
echo $item["item-id"];
}
}
//////////////////////////Funkcja zwraca kategorie///////////////
function getCategory($opis){
$book = "Books";
if($opis == $book)
return $this->katTestWebApi;
}
//////////////////////////Funnkcja tworzy tytul aukcji///////////
function getTitle($author,$title){
if((strlen($author)+strlen($title))<47) return $title.', '.$author;
else
if(strlen($title)<45){
$l=strlen($title);
$r=50-$l;
return $title.', '.substr($author,0,$r).'..';
}
else{
return substr($title,0,50);
}
}
//////////////////////////Funnkcja tworzy html do opis///////////
function getDesc(array $data){
//$imgSize = $this->getImgSize($data[0]);
//<tr><td><img src='http://system.42md.com/image.php?a=".$data[0]."' width='".$imgSize['width']."' hight='".$imgSize['hight']."'></td><td VALIGN='top' style='padding:20px; text-valign:top;'>
return "<table width='90%' style='padding:20px 20px 20px 100px; font-family:Arial; color:grey;'>
<tr><td VALIGN='top' ><img width='100px', hight='150px', src='http://system.42md.com/image.php?a=".$data[0]."'></td>
<td>
<p>here is my description</p>
</td></tr>
</table>";
}
//////////////////////////////////Konstruktor///////////////////
function Auction(nusoap_client $soap , array $sesja){
if(($soap==null)||($sesja==null))return false;
$this->soap = $soap;
$this->sesja = $sesja;
}
} /////////////////////////////end of the class//////////////////
?>