Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezvoucherinformation.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezvoucherinformation.php 7943 2001-10-17 13:14:39Z ce $
5 //
6 // eZVoucherInformation class
7 //
8 // Christoffer A. Elo <ce@ez.no>
9 // Created on: <19-Jun-2001 17:41:06 ce>
10 //
11 // This source file is part of Exponential Basic, publishing software.
12 // Copyright (C) 1999-2001 eZ systems as
13 //
14 // This program is free software; you can redistribute it and/or
15 // modify it under the terms of the GNU General Public License
16 // as published by the Free Software Foundation; either version 2
17 // of the License, or (at your option) any later version.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
27 //
28
31
48 // include_once( "eztrade/classes/ezvoucher.php" );
49 // include_once( "eztrade/classes/ezpreorder.php" );
50 // include_once( "eztrade/classes/ezproduct.php" );
51
52 // include_once( "ezaddress/classes/ezonline.php" );
53
54 class eZVoucherInformation
55 {
56
63 function __construct( $id=-1 )
64 {
65 $this->VoucherID = 0;
66 $this->OnlineID = 0;
67 $this->ToAddressID = 0;
68 $this->FromAddressID = 0;
69 $this->PreOrderID = 0;
70
71 if ( is_array( $id ) )
72 {
73 $this->fill( $id );
74 }
75 else if ( $id != -1 )
76 {
77 $this->ID = $id;
78 $this->get( $this->ID );
79 }
80 }
81
85 function store()
86 {
87 $db =& eZDB::globalDatabase();
88 $db->begin();
89
90 $description =& $db->escapeString( $this->Description );
91 $toName =& $db->escapeString( $this->ToName );
92 $fromName =& $db->escapeString( $this->FromName );
93
94 if ( !isset( $this->ID ) )
95 {
96 $db->lock( "eZTrade_VoucherInformation" );
97 $nextID = $db->nextID( "eZTrade_VoucherInformation", "ID" );
98 $timeStamp =& (new eZDateTime())->timeStamp( true );
99
100 $res = $db->query( "INSERT INTO eZTrade_VoucherInformation
101 ( ID, VoucherID, OnlineID, ToAddressID, FromAddressID, Description, PreOrderID, MailMethod, FromName, ToName, FromOnlineID, Price, ProductID )
102 VALUES
103 ( '$nextID',
104 '$this->VoucherID',
105 '$this->OnlineID',
106 '$this->ToAddressID',
107 '$this->FromAddressID',
108 '$description',
109 '$this->PreOrderID',
110 '$this->MailMethod',
111 '$fromName',
112 '$toName',
113 '$this->FromOnlineID',
114 '$this->Price',
115 '$this->ProductID'
116 )
117 " );
118
119 $this->ID = $nextID;
120 }
121 elseif ( is_numeric( $this->ID ) )
122 {
123 $res = $db->query( "UPDATE eZTrade_VoucherInformation SET
124 VoucherID='$this->VoucherID',
125 OnlineID='$this->OnlineID',
126 ToAddressID='$this->ToAddressID',
127 FromAddressID='$this->FromAddressID',
128 Description='$description',
129 PreOrderID='$this->PreOrderID',
130 MailMethod='$this->MailMethod',
131 FromName='$toName',
132 ToName='$fromName',
133 FromOnlineID='$this->FromOnlineID',
134 Price='$this->Price',
135 ProductID='$this->ProductID'
136 WHERE ID='$this->ID'" );
137 }
138 $db->unlock();
139
140 if ( $res == false )
141 $db->rollback( );
142 else
143 $db->commit();
144
145 return true;
146 }
147
151 function delete( $catID=-1 )
152 {
153 if ( $catID == -1 )
154 $catID = $this->ID;
155
156 $db =& eZDB::globalDatabase();
157 $db->begin();
158
159 $res = $db->query( "DELETE FROM eZTrade_VoucherInformation WHERE ID='$this->ID'" );
160
161 if ( $ret == false )
162 $db->rollback( );
163 else
164 $db->commit();
165 }
166
172 function get( $id=-1 )
173 {
174 $db =& eZDB::globalDatabase();
175
176 $ret = false;
177 if ( $id != "" )
178 {
179 $db->array_query( $quizArray, "SELECT * FROM eZTrade_VoucherInformation WHERE ID='$id'",
180 0, 1 );
181 if( count( $quizArray ) == 1 )
182 {
183 $this->fill( $quizArray[0] );
184 $ret = true;
185 }
186 elseif( count( $quizArray ) == 1 )
187 {
188 $this->ID = 0;
189 }
190 }
191 return $ret;
192 }
193
197 function fill( $value )
198 {
199 $db =& eZDB::globalDatabase();
200 $this->ID = $value[$db->fieldName( "ID" )];
201 $this->Description = $value[$db->fieldName( "Description" )];
202 $this->OnlineID = $value[$db->fieldName( "OnlineID" )];
203 $this->AddressID = isset( $value[$db->fieldName( "AddressID" )] ) ? $value[$db->fieldName( "AddressID" )] : null;
204 $this->VoucherID = $value[$db->fieldName( "VoucherID" )];
205 $this->PreOrderID = $value[$db->fieldName( "PreOrderID" )];
206 $this->MailMethod = $value[$db->fieldName( "MailMethod" )];
207 $this->FromOnlineID = $value[$db->fieldName( "FromOnlineID" )];
208 $this->FromName = $value[$db->fieldName( "FromName" )];
209 $this->ToName = $value[$db->fieldName( "ToName" )];
210 $this->Price = $value[$db->fieldName( "Price" )];
211 $this->ProductID = $value[$db->fieldName( "ProductID" )];
212 }
213
219 function &getAll( $offset=0, $limit=20 )
220 {
221 $db =& eZDB::globalDatabase();
222
223 $returnArray = array();
224 $quizArray = array();
225
226 $db->array_query( $quizArray, "SELECT ID
227 FROM eZTrade_VoucherInformation
228 ORDER BY StartDate DESC",
229 array( "Limit" => $limit,
230 "Offset" => $offset ) );
231
232 for ( $i=0; $i < count($quizArray); $i++ )
233 {
234 $returnArray[$i] = new eZVoucherInformation( $quizArray[$i][$db->fieldName( "ID" )] );
235 }
236
237 return $returnArray;
238 }
239
243 function count()
244 {
245 $db =& eZDB::globalDatabase();
246 $ret = false;
247
248 $db->query_single( $result, "SELECT COUNT(ID) as Count
249 FROM eZTrade_VoucherInformation" );
250 $ret = $result[$db->fieldName( "Count" )];
251 return $ret;
252 }
253
257 function id()
258 {
259 return $this->ID;
260 }
261
265 function &description()
266 {
267 return htmlspecialchars( $this->Description );
268 }
269
273 function setDescription( &$value )
274 {
275 $this->Description = $value;
276 }
277
281 function &price()
282 {
283 return $this->Price;
284 }
285
289 function &toName()
290 {
291 return $this->ToName;
292 }
293
297 function &fromName()
298 {
299 return $this->FromName;
300 }
301
306 function &correctPrice( $calcVAT, &$product )
307 {
308 $inUser =& eZUser::currentUser();
309
310 $price = $this->Price;
311
312 $vatType =& $product->vatType();
313
314 if ( $calcVAT == true )
315 {
316 if ( $product->excludedVAT() )
317 {
318 $vatType =& $product->vatType();
319 $vat = 0;
320
321 if ( $vatType )
322 {
323 $vat =& $vatType->value();
324 }
325
326 $price = ( $price * $vat / 100 ) + $price;
327 }
328 }
329 else
330 {
331 if ( $product->includesVAT() )
332 {
333 $vatType =& $product->vatType();
334 $vat = 0;
335
336 if ( $vatType )
337 {
338 $vat =& $vatType->value();
339 }
340
341 $price = $price - ( $price / ( 100 + $vat ) ) * $vat;
342
343 }
344 }
345
346 return $price;
347 }
348
352 function setPrice( &$value )
353 {
354 $this->Price = $value;
355 }
356
360 function setToName( &$value )
361 {
362 $this->ToName = $value;
363 }
364
368 function setFromName( &$value )
369 {
370 $this->FromName = $value;
371 }
372
376 function setEmail( &$value )
377 {
378 if ( is_a( $value, "eZOnline" ) )
379 $this->OnlineID = $value->id();
380 else
381 $this->OnlineID = $value;
382 }
383
387 function setFromEmail( &$value )
388 {
389 if ( is_a( $value, "eZOnline" ) )
390 $this->FromOnlineID = $value->id();
391 else
392 $this->FromOnlineID = $value;
393 }
394
398 function setToAddress( &$value )
399 {
400 if ( is_a( $value, "eZAddress" ) )
401 $this->ToAddressID = $value->id();
402 else
403 $this->ToAddressID = $value;
404 }
405
409 function setFromAddress( &$value )
410 {
411 if ( is_a( $value, "eZAddress" ) )
412 $this->FromAddressID = $value->id();
413 else
414 $this->FromAddressID = $value;
415 }
416
420 function setProduct( &$value )
421 {
422 if ( is_a ( $value, "eZProduct" ) )
423 $this->ProductID = $value->id();
424 else
425 $this->ProductID = $value;
426 }
427
431 function setVoucher( &$value )
432 {
433 if ( is_a( $value, "eZVoucher" ) )
434 $this->VoucherID = $value->id();
435 else
436 $this->VoucherID = $value;
437 }
438
442 function setMailMethod( $value )
443 {
444 $this->MailMethod = $value;
445 }
446
450 function setPreOrder( &$value )
451 {
452 if ( is_a ( $value, "eZPreOrder" ) )
453 $this->PreOrderID = $value->id();
454 else
455 $this->PreOrderID = $value;
456 }
457
461 function online( $asObject=true )
462 {
463 if ( $asObject )
464 $ret = new eZOnline( $this->OnlineID );
465 else
466 $ret = $this->OnlineID;
467
468 return $ret;
469 }
470
474 function fromEmail( $asObject=true )
475 {
476 if ( $asObject )
477 $ret = new eZOnline( $this->FromOnlineID );
478 else
479 $ret = $this->FromOnlineID;
480
481 return $ret;
482 }
483
487 function toAddress( $asObject=true )
488 {
489 if ( $asObject )
490 $ret = new eZAddress( $this->ToAddressID );
491 else
492 $ret = $this->ToAddressID;
493
494 return $ret;
495 }
496
500 function fromAddress( $asObject=true )
501 {
502 if ( $asObject )
503 $ret = new eZAddress( $this->FromAddressID );
504 else
505 $ret = $this->FromAddressID;
506
507 return $ret;
508 }
509
513 function product( $asObject=true )
514 {
515 if ( $asObject )
516 $ret = new eZProduct( $this->ProductID );
517 else
518 $ret = $this->ProductID;
519
520 return $ret;
521 }
522
526 function voucher( $asObject=true )
527 {
528 if ( $asObject )
529 {
530 print( $this->VoucherID );
531 return new eZVoucher( $this->VoucherID );
532 }
533 else
534 return $this->VoucherID;
535 }
536
540 function mailMethod( )
541 {
542 return $this->MailMethod;
543 }
544
548 function preOrderID( $asObject=true )
549 {
550 if ( $asObject )
551 return eZPreOrderID( $this->PreOrderID );
552 else
553 return $this->PreOrderID;
554 }
555
559 function sendMail( )
560 {
561 if ( $this->MailMethod == 1 )
562 $this->sendEMail();
563 elseif ( $this->MailMethod == 2 )
564 $this->sendSMail();
565
566 return $this->Price;
567 }
568
573 function sendEMail()
574 {
575 $ini =& eZINI::instance( 'site.ini' );
576
577 $voucher =& $this->voucher();
578
579 $fromUser =& $this->fromEmail();
580
581 $Language = $ini->variable( "eZTradeMain", "Language" );
582
583 $t = new eZTemplate( "kernel/eztrade/user/" . $ini->variable( "eZTradeMain", "TemplateDir" ),
584 "kernel/eztrade/user/intl/", $Language, "voucheremail.php" );
585
586 $t->setAllStrings();
587
588 $t->set_file( "voucheremail", "voucheremail.tpl" );
589
590 $mail = new eZMail();
591
592 $t->set_var( "description", $this->description() );
593 $t->set_var( "from_name", $this->fromName() );
594 $t->set_var( "to_name", $this->toName() );
595 $t->set_var( "key_number", $voucher->keyNumber() );
596
597
598 $mailAddress = $this->online();
599
600 $mail->setTo( $mailAddress->url() );
601 $mail->setBody( $t->parse( "dummy", "voucheremail" ) );
602 $mail->setFrom( $fromUser->url() );
603 $mail->send();
604 }
605
606 var $ID;
607 var $Description;
608 var $PreOrderID;
609 var $OnlineID;
610 var $ToAddressID;
611 var $FromAddressID;
612 var $VoucherID;
613 var $MailMethod;
614 var $Price;
615 var $ToName;
616 var $FromName;
617 var $FromOnlineID;
618 var $ProductID;
619 var $AddressID;
620 }
621
622 ?>
$i
$i
Definition: admin/adlist.php:91
eZAddress
Definition: ezaddress.php:42
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZDateTime
Definition: ezdatetime.php:55
eZMail
Definition: ezmail.php:57
eZProduct
Definition: ezproduct.php:71
eZTemplate
Definition: eztemplate.php:107
eZUser\currentUser
static & currentUser()
Definition: ezuser.php:896
eZVoucherInformation
Definition: ezvoucherinformation.php:55
eZVoucherInformation\setToAddress
setToAddress(&$value)
Definition: ezvoucherinformation.php:398
eZVoucherInformation\setPreOrder
setPreOrder(&$value)
Definition: ezvoucherinformation.php:450
eZVoucherInformation\correctPrice
& correctPrice( $calcVAT, &$product)
Definition: ezvoucherinformation.php:306
eZVoucherInformation\mailMethod
mailMethod()
Definition: ezvoucherinformation.php:540
eZVoucherInformation\$Price
$Price
Definition: ezvoucherinformation.php:614
eZVoucherInformation\$MailMethod
$MailMethod
Definition: ezvoucherinformation.php:613
eZVoucherInformation\product
product( $asObject=true)
Definition: ezvoucherinformation.php:513
eZVoucherInformation\setFromAddress
setFromAddress(&$value)
Definition: ezvoucherinformation.php:409
eZVoucherInformation\setFromEmail
setFromEmail(&$value)
Definition: ezvoucherinformation.php:387
eZVoucherInformation\setDescription
setDescription(&$value)
Definition: ezvoucherinformation.php:273
eZVoucherInformation\__construct
__construct( $id=-1)
Definition: ezvoucherinformation.php:63
eZVoucherInformation\setPrice
setPrice(&$value)
Definition: ezvoucherinformation.php:352
eZVoucherInformation\setToName
setToName(&$value)
Definition: ezvoucherinformation.php:360
eZVoucherInformation\online
online( $asObject=true)
Definition: ezvoucherinformation.php:461
eZVoucherInformation\setEmail
setEmail(&$value)
Definition: ezvoucherinformation.php:376
eZVoucherInformation\$FromName
$FromName
Definition: ezvoucherinformation.php:616
eZVoucherInformation\voucher
voucher( $asObject=true)
Definition: ezvoucherinformation.php:526
eZVoucherInformation\$ID
$ID
Definition: ezvoucherinformation.php:606
eZVoucherInformation\$ToName
$ToName
Definition: ezvoucherinformation.php:615
eZVoucherInformation\toAddress
toAddress( $asObject=true)
Definition: ezvoucherinformation.php:487
eZVoucherInformation\fill
fill( $value)
Definition: ezvoucherinformation.php:197
eZVoucherInformation\$ToAddressID
$ToAddressID
Definition: ezvoucherinformation.php:610
eZVoucherInformation\price
& price()
Definition: ezvoucherinformation.php:281
eZVoucherInformation\$ProductID
$ProductID
Definition: ezvoucherinformation.php:618
eZVoucherInformation\$FromOnlineID
$FromOnlineID
Definition: ezvoucherinformation.php:617
eZVoucherInformation\fromAddress
fromAddress( $asObject=true)
Definition: ezvoucherinformation.php:500
eZVoucherInformation\$Description
$Description
Definition: ezvoucherinformation.php:607
eZVoucherInformation\sendMail
sendMail()
Definition: ezvoucherinformation.php:559
eZVoucherInformation\count
count()
Definition: ezvoucherinformation.php:243
eZVoucherInformation\store
store()
Definition: ezvoucherinformation.php:85
eZVoucherInformation\fromName
& fromName()
Definition: ezvoucherinformation.php:297
eZVoucherInformation\setVoucher
setVoucher(&$value)
Definition: ezvoucherinformation.php:431
eZVoucherInformation\$OnlineID
$OnlineID
Definition: ezvoucherinformation.php:609
eZVoucherInformation\$FromAddressID
$FromAddressID
Definition: ezvoucherinformation.php:611
eZVoucherInformation\$PreOrderID
$PreOrderID
Definition: ezvoucherinformation.php:608
eZVoucherInformation\$VoucherID
$VoucherID
Definition: ezvoucherinformation.php:612
eZVoucherInformation\description
& description()
Definition: ezvoucherinformation.php:265
eZVoucherInformation\setProduct
setProduct(&$value)
Definition: ezvoucherinformation.php:420
eZVoucherInformation\$AddressID
$AddressID
Definition: ezvoucherinformation.php:619
eZVoucherInformation\setMailMethod
setMailMethod( $value)
Definition: ezvoucherinformation.php:442
eZVoucherInformation\getAll
& getAll( $offset=0, $limit=20)
Definition: ezvoucherinformation.php:219
eZVoucherInformation\toName
& toName()
Definition: ezvoucherinformation.php:289
eZVoucherInformation\sendEMail
sendEMail()
Definition: ezvoucherinformation.php:573
eZVoucherInformation\preOrderID
preOrderID( $asObject=true)
Definition: ezvoucherinformation.php:548
eZVoucherInformation\id
id()
Definition: ezvoucherinformation.php:257
eZVoucherInformation\fromEmail
fromEmail( $asObject=true)
Definition: ezvoucherinformation.php:474
eZVoucherInformation\setFromName
setFromName(&$value)
Definition: ezvoucherinformation.php:368
eZVoucher
Definition: ezvoucher.php:54
$t
foreach( $Modules as $module) if(isset( $ItemInsert)) $t
Definition: classes/admin/linklist.php:168
$Language
$Language
Definition: classes/admin/linklist.php:65
$ini
$ini
Definition: classes/admin/linklist.php:64
$result
$result
Definition: companysearch.php:94
$id
$id
Definition: companytypelist.php:193
$db
$db
Definition: ezarticle/user/authorlist.php:53
$mail
$mail
Definition: ezbulkmail/admin/maillist.php:61
$limit
$limit
Definition: ezimagecatalogue/admin/imagelist.php:312
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$res
$res
Definition: ezstats/admin/cron.php:45
$offset
$offset
Definition: ezstats/admin/cron.php:51
$product
$product
Definition: homepage.php:202
$price
$price
Definition: pricegroupedit.php:39
$vat
foreach( $categoryArray as $catItem) $vat
Definition: productedit.php:1334
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.