Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezad.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezad.php 8615 2001-11-23 09:39:00Z br $
5 //
6 // Definition of eZAd class
7 //
8 // Created on: <22-Nov-2000 20:01:05 bf>
9 //
10 // This source file is part of Exponential Basic, publishing software.
11 //
12 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
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
40 // include_once( "classes/ezdb.php" );
41 // include_once( "classes/ezdatetime.php" );
42
43 // include_once( "ezimagecatalogue/classes/ezimage.php" );
44
45 class eZAd
46 {
53 function __construct( $id="" )
54 {
55 $this->ImageID = 0;
56
57 if ( $id != "" )
58 {
59 $this->ID = $id;
60 $this->get( $this->ID );
61 }
62 }
63
67 function store()
68 {
69 $db =& eZDB::globalDatabase();
70
71 $db->begin( );
72
73 $name = $db->escapeString( $this->Name );
74 $description = $db->escapeString( $this->Description );
75 $url = $db->escapeString( $this->URL );
76 $htmlbanner = $db->escapeString( $this->HTMLBanner );
77
78 if ( !isset( $this->ID ) )
79 {
80 $db->lock( "eZAd_Ad" );
81
82 $nextID = $db->nextID( "eZAd_Ad", "ID" );
83 $queryText = "INSERT INTO eZAd_Ad
84 ( ID,
85 Name,
86 Description,
87 ImageID,
88 IsActive,
89 URL,
90 ClickPrice,
91 ViewPrice,
92 HTMLBanner,
93 UseHTML )
94 VALUES
95 ( '$nextID',
96 '$name',
97 '$description',
98 '$this->ImageID',
99 '$this->IsActive',
100 '$url',
101 '$this->ClickPrice',
102 '$this->ViewPrice',
103 '$htmlbanner',
104 '$this->UseHTML' )
105 ";
106
107 $res = $db->query( $queryText );
108
109 $this->ID = $nextID;
110
111 $this->addPageView();
112 $db->unlock();
113 }
114 else
115 {
116 $res = $db->query( "UPDATE eZAd_Ad SET
117 Name='$name',
118 Description='$description',
119 ImageID='$this->ImageID',
120 IsActive='$this->IsActive',
121 URL='$url',
122 ClickPrice='$this->ClickPrice',
123 ViewPrice='$this->ViewPrice',
124 HTMLBanner='$htmlbanner',
125 UseHTML='$this->UseHTML'
126 WHERE ID='$this->ID'
127 " );
128 }
129
130
131 if ( $res == false )
132 $db->rollback( );
133 else
134 $db->commit();
135
136
137 return true;
138 }
139
143 function get( $id="" )
144 {
145 $db =& eZDB::globalDatabase();
146
147 $ret = false;
148
149 if ( $id != "" )
150 {
151 $db->array_query( $ad_array, "SELECT * FROM eZAd_Ad WHERE ID='$id'" );
152 if ( count( $ad_array ) > 1 )
153 {
154 die( "Error: Ad's with the same ID was found in the database. This shouldent happen." );
155 }
156 else if( count( $ad_array ) == 1 )
157 {
158 $this->ID =& $ad_array[0][$db->fieldName("ID")];
159 $this->Name =& $ad_array[0][$db->fieldName("Name")];
160 $this->Description =& $ad_array[0][$db->fieldName("Description")];
161 $this->IsActive =& $ad_array[0][$db->fieldName("IsActive")];
162 $this->URL =& $ad_array[0][$db->fieldName("URL")];
163 $this->ImageID =& $ad_array[0][$db->fieldName("ImageID")];
164 $this->ViewPrice =& $ad_array[0][$db->fieldName("ViewPrice")];
165 $this->ClickPrice =& $ad_array[0][$db->fieldName("ClickPrice")];
166 $this->HTMLBanner =& $ad_array[0][$db->fieldName("HTMLBanner")];
167 $this->UseHTML =& $ad_array[0][$db->fieldName("UseHTML")];
168
169 $ret = true;
170 }
171 }
172 return $ret;
173 }
174
178 function delete()
179 {
180 $db =& eZDB::globalDatabase();
181
182 if ( isset( $this->ID ) )
183 {
184 $db->query( "DELETE FROM eZAd_View WHERE AdID='$this->ID'" );
185 $db->query( "DELETE FROM eZAd_Click WHERE AdID='$this->ID'" );
186
187 $db->query( "DELETE FROM eZAd_AdCategoryLink WHERE AdID='$this->ID'" );
188 $db->query( "DELETE FROM eZAd_Ad WHERE ID='$this->ID'" );
189 }
190
191 return true;
192 }
193
197 function id()
198 {
199 return $this->ID;
200 }
201
205 function &name()
206 {
207 return htmlspecialchars( $this->Name );
208 }
209
213 function &description()
214 {
215 return htmlspecialchars( $this->Description );
216 }
217
221 function &url()
222 {
223 return $this->URL;
224 }
225
229 function &clickPrice()
230 {
231 return $this->ClickPrice;
232 }
233
237 function &viewPrice()
238 {
239 return $this->ViewPrice;
240 }
241
245 function isActive()
246 {
247 $ret = false;
248
249 if ( $this->IsActive == "1" )
250 {
251 $ret = true;
252 }
253 return $ret;
254 }
255
259 function useHTML()
260 {
261 $ret = false;
262
263 if ( $this->UseHTML == 1 )
264 {
265 $ret = true;
266 }
267 return $ret;
268 }
269
273 function &htmlBanner()
274 {
275 return $this->HTMLBanner;
276 }
277
281 function &viewStartDate()
282 {
283 $dateTime = new eZDateTime();
284 $dateTime->setTimeStamp( $this->ViewStartDate );
285
286 return $dateTime;
287 }
288
292 function &viewStopDate()
293 {
294 $dateTime = new eZDateTime();
295 $dateTime->setTimeStamp( $this->ViewStopDate );
296
297 return $dateTime;
298 }
299
303 function setName( $value )
304 {
305 $this->Name = $value;
306 }
307
311 function setDescription( $value )
312 {
313 $this->Description = $value;
314 }
315
319 function setURL( $value )
320 {
321 $this->URL = $value;
322 }
323
327 function setClickPrice( $value )
328 {
329 $this->ClickPrice = $value;
330 setType( $this->ClickPrice, "double" );
331 }
332
336 function setViewPrice( $value )
337 {
338 $this->ViewPrice = $value;
339 setType( $this->ViewPrice, "double" );
340 }
341
345 function setIsActive( $value )
346 {
347 if ( $value == true )
348 {
349 $this->IsActive = 1;
350 }
351 else
352 {
353 $this->IsActive = 0;
354 }
355 }
356
360 function setHTMLBanner( $value )
361 {
362 $this->HTMLBanner = $value;
363 }
364
368 function setUseHTML( $value )
369 {
370 if ( $value == true )
371 {
372 $this->UseHTML = 1;
373 }
374 else
375 {
376 $this->UseHTML = 0;
377 }
378 }
379
385 function &categories()
386 {
387 $db =& eZDB::globalDatabase();
388
389 $ret = array();
390 $db->array_query( $category_array, "SELECT * FROM
391 eZAd_AdCategoryLink
392 WHERE AdID='$this->ID'" );
393
394 foreach ( $category_array as $category )
395 {
396 $ret[] = new eZAdCategory( $category[$db->fieldName("CategoryID")] );
397 }
398
399 return $ret;
400 }
401
405 function removeFromCategories()
406 {
407 $db =& eZDB::globalDatabase();
408
409 $db->query( "DELETE FROM eZAd_AdCategoryLink
410 WHERE AdID='$this->ID'" );
411 }
412
416 function setImage( $value )
417 {
418 if ( is_a( $value, "eZImage" ) )
419 {
420 $db =& eZDB::globalDatabase();
421
422 $this->ImageID = $value->id();
423 }
424 }
425
431 function deleteImage( $value )
432 {
433 if ( is_a( $value, "eZImage" ) )
434 {
435 $db =& eZDB::globalDatabase();
436
437 $imageID = $value->id();
438
439 $image = new eZImage( $imageID );
440 $image->delete();
441 }
442 }
443
447 function image()
448 {
449 $db =& eZDB::globalDatabase();
450
451 $ret = false;
452 $img = new eZImage( );
453
454 if ( $img->get( $this->ImageID ) )
455 {
456 $ret = $img;
457 }
458
459 return $ret;
460 }
461
465 function addPageView( )
466 {
467 $db =& eZDB::globalDatabase();
468
469 $db->begin();
470
471 $date = new eZDate();
472 $date = $date->timestamp( true );
473 $db->lock( "eZAd_View" );
474
475 $db->array_query( $view_result, "SELECT * FROM
476 eZAd_View
477 WHERE AdID='$this->ID'" );
478 if ( count( $view_result ) == 0 )
479 {
480
481 $nextID = $db->nextID( "eZAd_View", "ID" );
482
483 // get the lowest
484 $db->array_query( $view_offset, "SELECT * FROM
485 eZAd_View
486 ORDER BY ViewOffsetCount" );
487
488 // set all offsets to 1.
489 $db->query( "UPDATE eZAd_View
490 SET ViewOffsetCount='1'" );
491
492 if ( count( $view_offset ) > 0 )
493 $offs = $view_offset[0][$db->fieldName("ViewOffsetCount")];
494 else
495 $offs = 1;
496
497 $timeStamp =& (new eZDateTime())->timeStamp( true );
498
499 $res = $db->query( "INSERT INTO eZAd_View
500 ( ID,
501 AdID,
502 ViewCount,
503 ViewOffsetCount,
504 ViewPrice,
505 Date )
506 VALUES
507 ( '$nextID',
508 '$this->ID',
509 '1',
510 '$offs',
511 '$this->ViewPrice',
512 '$timeStamp' )" );
513 }
514 else
515 {
516 $query = "UPDATE eZAd_View SET
517 ViewCount=(ViewCount + 1),
518 ViewOffsetCount=(ViewOffsetCount + 1),
519 ViewPrice=(ViewPrice + $this->ViewPrice)
520 WHERE AdID='$this->ID'";
521
522 $res = $db->query( $query );
523 }
524
525 $db->unlock();
526
527 if ( $res == false )
528 {
529 $db->rollback( );
530 }
531 else
532 {
533 $db->commit();
534 }
535
536 }
537
541 function viewCount( )
542 {
543 $db =& eZDB::globalDatabase();
544
545 $db->array_query( $view_result, "SELECT sum(ViewCount) as ViewCount FROM
546 eZAd_View
547 WHERE AdID='$this->ID'" );
548
549 return $view_result[0][$db->fieldName("ViewCount")];
550 }
551
555 function clickCount( )
556 {
557 $db =& eZDB::globalDatabase();
558
559 $db->array_query( $click_result, "SELECT count(*) AS Count FROM
560 eZAd_Click
561 WHERE AdID='$this->ID'" );
562
563 return $click_result[0][$db->fieldName("Count")];
564 }
565
566
570 function totalViewRevenue( )
571 {
572 $db =& eZDB::globalDatabase();
573
574 $db->array_query( $view_result, "SELECT SUM(ViewPrice) AS Revenue
575 FROM eZAd_View WHERE AdID='$this->ID'" );
576
577 return $view_result[0][$db->fieldName("Revenue")];
578 }
579
583 function totalClickRevenue( )
584 {
585 $db =& eZDB::globalDatabase();
586
587 // print( "SELECT SUM(ClickPrice) AS Revenue FROM eZAd_Click WHERE AdID='$this->ID'" );
588
589 $db->array_query( $click_result, "SELECT SUM(ClickPrice) AS Revenue FROM eZAd_Click WHERE AdID='$this->ID'" );
590
591 return $click_result[0][$db->fieldName("Revenue")];
592 }
593
594 var $ID;
595 var $Name;
596 var $Description;
597 var $ImageID;
598 var $URL;
599 var $ViewStartDate;
600 var $ClickPrice;
601 var $ViewPrice;
602
603 var $HTMLBanner;
604 var $UseHTML;
605
607 var $IsActive;
608
610 var $ViewRule;
611
613 var $URL;
614
615 }
616
617 ?>
$category
if( $Action=="Edit") $category
Definition: adedit.php:378
$dateTime
$dateTime
Definition: authorview.php:77
$date
$date
Definition: bugpreview.php:66
eZAdCategory
Definition: ezadcategory.php:44
eZAd
Definition: ezad.php:46
eZAd\viewPrice
& viewPrice()
Definition: ezad.php:237
eZAd\$HTMLBanner
$HTMLBanner
Definition: ezad.php:603
eZAd\addPageView
addPageView()
Definition: ezad.php:465
eZAd\$ImageID
$ImageID
Definition: ezad.php:597
eZAd\description
& description()
Definition: ezad.php:213
eZAd\store
store()
Definition: ezad.php:67
eZAd\setUseHTML
setUseHTML( $value)
Definition: ezad.php:368
eZAd\isActive
isActive()
Definition: ezad.php:245
eZAd\useHTML
useHTML()
Definition: ezad.php:259
eZAd\viewStopDate
& viewStopDate()
Definition: ezad.php:292
eZAd\$Description
$Description
Definition: ezad.php:596
eZAd\name
& name()
Definition: ezad.php:205
eZAd\$ViewStartDate
$ViewStartDate
Definition: ezad.php:599
eZAd\__construct
__construct( $id="")
Definition: ezad.php:53
eZAd\setName
setName( $value)
Definition: ezad.php:303
eZAd\setClickPrice
setClickPrice( $value)
Definition: ezad.php:327
eZAd\setViewPrice
setViewPrice( $value)
Definition: ezad.php:336
eZAd\$Name
$Name
Definition: ezad.php:595
eZAd\setIsActive
setIsActive( $value)
Definition: ezad.php:345
eZAd\$ViewRule
$ViewRule
Indicates if the banner should be viewed by date or by clicks.
Definition: ezad.php:610
eZAd\url
& url()
Definition: ezad.php:221
eZAd\totalClickRevenue
totalClickRevenue()
Definition: ezad.php:583
eZAd\setHTMLBanner
setHTMLBanner( $value)
Definition: ezad.php:360
eZAd\$IsActive
$IsActive
Indicates if the banner is active or not.
Definition: ezad.php:607
eZAd\image
image()
Definition: ezad.php:447
eZAd\$ClickPrice
$ClickPrice
Definition: ezad.php:600
eZAd\deleteImage
deleteImage( $value)
Definition: ezad.php:431
eZAd\$ViewPrice
$ViewPrice
Definition: ezad.php:601
eZAd\totalViewRevenue
totalViewRevenue()
Definition: ezad.php:570
eZAd\$ID
$ID
Definition: ezad.php:594
eZAd\setURL
setURL( $value)
Definition: ezad.php:319
eZAd\clickCount
clickCount()
Definition: ezad.php:555
eZAd\htmlBanner
& htmlBanner()
Definition: ezad.php:273
eZAd\categories
& categories()
Definition: ezad.php:385
eZAd\$UseHTML
$UseHTML
Definition: ezad.php:604
eZAd\setDescription
setDescription( $value)
Definition: ezad.php:311
eZAd\$URL
$URL
The URL to go to when the banner is clicked.
Definition: ezad.php:598
eZAd\viewCount
viewCount()
Definition: ezad.php:541
eZAd\id
id()
Definition: ezad.php:197
eZAd\clickPrice
& clickPrice()
Definition: ezad.php:229
eZAd\viewStartDate
& viewStartDate()
Definition: ezad.php:281
eZAd\setImage
setImage( $value)
Definition: ezad.php:416
eZAd\removeFromCategories
removeFromCategories()
Definition: ezad.php:405
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZDateTime
Definition: ezdatetime.php:55
eZDate
Definition: ezdate.php:46
eZImage
Definition: ezimage.php:95
$name
$name
Definition: companytypelist.php:194
$id
$id
Definition: companytypelist.php:193
$query
if(isset( $Year) &&!is_numeric( $Year)||isset( $Month) &&!is_numeric( $Month)) $query
Definition: entryexitpages.php:65
$db
$db
Definition: ezarticle/user/authorlist.php:53
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$res
$res
Definition: ezstats/admin/cron.php:45
$url
$url
Definition: messagereviewlist.php:153
Name
if($user) if(isset( $next) && $next)<?=isset($all_fields_error) &&$all_fields_error ?><?=isset($password_error) &&$password_error ?></p ><? endif;?>< form method="post">< table border="0" cellspacing="2" cellpadding="2" class="boxtext" style="font-size=13;">< tr >< td style="color:<?= isset( $error['first_name'] ) ?> First Name
Definition: step1.php:127
$category_array
$category_array
Definition: todoedit.php:604
$image
$image
Definition: user/articlelist.php:242
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.