Default für SMTP-Verbindungen ist "keine Verschlüsselung"
[kivitendo-erp.git] / peppershop / Picture.php
1 <?php
2
3
4 class picture {
5
6     var $smallwidth = 150;
7     var $bigwidth = 800;
8     var $original = true;
9     var $err = false;
10
11     function picture($ERPhost,$ERPuser,$ERPpass,$ERPimgdir,$SHOPhost,$SHOPuser,$SHOPpass,$SHOPimgdir,$err) {
12         $this->ERPftphost = $ERPhost;
13         $this->ERPftpuser = $ERPuser;
14         $this->ERPftppwd = $ERPpass;
15         $this->ERPimgdir = $ERPimgdir;
16         $this->SHOPftphost = $SHOPhost;
17         $this->SHOPftpuser = $SHOPuser;
18         $this->SHOPftppwd = $SHOPpass;
19         $this->SHOPimgdir = $SHOPimgdir;
20         $this->err = $err;
21     }
22
23     function copyImage($id,$image,$typ) {
24         if ( !$this->fromERP($image) ) return false;
25         if ( !$this->mkbilder() ) return false;
26         return $this->toShop($id,$typ);
27     }
28
29     function mkbilder() {
30         if ( !class_exists("Imagick") ) { $this->err->out("Imagick-Extention nicht installiert",true); return false; };
31         $handle = new Imagick();
32         if ( !$handle->readImage("./tmp/tmp.file_org") ) return false;
33         $d = $handle->getImageGeometry();
34         if ( $d["width"]<$d["height"] ) {
35             $faktor = $d["height"]/$d["width"];
36         } else {
37             $faktor = $d["width"]/$d["height"];
38         }
39         $smallheight = floor($this->smallwidth*$faktor);
40         $handle->thumbnailImage($this->smallwidth, $smallheight, true);
41         $rc = $handle->writeImage( "./tmp/tmp.file_small");
42         if ( !$this->original ) {
43             $handle->readImage("./tmp/tmp.file_org");
44             $bigheight = floor($this->bigwidth * $faktor);
45             $handle->thumbnailImage( $this->bigwidth, $bigheight,true);
46             return $handle->writeImage( "./tmp/tmp.file_org");
47         }
48         return $rc;
49     }
50
51     function fromERP($image) {
52         if ( $this->ERPftphost == 'localhost' ) {
53             exec("cp $this->ERPimgdir/$image ./tmp/tmp.file_org",$aus,$rc2);
54             if ( $rc2>0 ) { $this->err->out("[Downloadfehler: $image]",true); return false; };
55         } else {
56             $conn_id = ftp_connect($this->ERPftphost);
57             $rc = @ftp_login($conn_id,$this->ERPftpuser,$this->ERPftppwd);
58             $src = $this->ERPimgdir."/".$image;
59             $upload = @ftp_get($conn_id,"tmp/tmp.file_org","$src",FTP_BINARY);
60             if ( !$upload ) { $this->err->out("[Ftp Downloadfehler! $image]",true); return false; };
61             ftp_quit($conn_id);
62         }
63         $this->image = $image;
64         return true;
65     }
66
67     function toShop($id,$typ) {
68         $grpic = $id."_gr.".$typ;
69         $klpic = $id."_kl.".$typ;
70         if ( $this->SHOPftphost == 'localhost' ) {
71             exec("cp ./tmp/tmp.file_org $this->SHOPimgdir/$grpic",$aus,$rc1);
72             exec("cp ./tmp/tmp.file_small $this->SHOPimgdir/$klpic",$aus,$rc2);
73             if ( $rc1>0 || $rc2>0 ) { $this->err->out("[Uploadfehler: $this->image / $grpic]",true); return false; };
74         } else {
75             $conn_id = ftp_connect($this->SHOPftphost);
76             @ftp_login($conn_id,$this->SHOPftpuser,$this->SHOPftppwd);
77             @ftp_chdir($conn_id,$this->SHOPimgdir);
78             $upload = @ftp_put($conn_id,$this->SHOPimgdir."/$grpic","tmp/tmp.file_org",FTP_BINARY);
79             if ( !$upload ) { $this->err->out("[Ftp Uploadfehler! $grpic]",true); return false; };
80             $upload = @ftp_put($conn_id,$this->SHOPimgdir."/$klpic","tmp/tmp.file_small",FTP_BINARY);
81             if ( !$upload ) { $this->err->out("[Ftp Uploadfehler! $klpic]",true); return false; };
82             @ftp_quit($conn_id);
83         }
84         return true;
85     }
86
87
88 }
89 ?>