Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezbulkmailcategory.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezbulkmailcategory.php 8513 2001-11-19 11:29:38Z jhe $
5 //
6 // Definition of eZBulkMailCategory class
7 //
8 // Created on: <17-Apr-2001 11:17:57 fh>
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
39 // include_once( "classes/ezdb.php" );
40 // include_once( "ezbulkmail/classes/ezbulkmailsubscriptionaddress.php" );
41 // include_once( "ezbulkmail/classes/ezbulkmailusersubscripter.php" );
42 // include_once( "ezbulkmail/classes/ezbulkmail.php" );
43 // include_once( "ezbulkmail/classes/ezbulkmailcategorysettings.php" );
44 // include_once( "ezbulkmail/classes/ezbulkmailusercategorysettings.php" );
45
46 class eZBulkMailCategory
47 {
50 function __construct( $id=-1 )
51 {
52 $this->IsPublic = 0;
53 $this->IsSingleCategory = 0;
54
55 if ( $id != -1 )
56 {
57 $this->ID = $id;
58 $this->get( $this->ID );
59 }
60 }
61
65 function store()
66 {
67 $db =& eZDB::globalDatabase();
68 $db->begin();
69 $name = $db->escapeString( $this->Name );
70 $description = $db->escapeString( $this->Description );
71 if ( !isset( $this->ID ) )
72 {
73 $db->lock( "eZBulkMail_Category" );
74 $nextID = $db->nextID( "eZBulkMail_Category", "ID" );
75
76 $result = $db->query( "INSERT INTO eZBulkMail_Category
77 ( ID, Name, IsPublic, Description )
78 VALUES
79 ( '$nextID',
80 '$name',
81 '$this->IsPublic',
82 '$description'
83 ) " );
84 $this->ID = $nextID;
85 }
86 else
87 {
88 $result = $db->query( "UPDATE eZBulkMail_Category SET
89 Name='$name',
90 IsPublic='$this->IsPublic',
91 Description='$description'
92 WHERE ID='$this->ID'" );
93 }
94
95 $db->unlock();
96 if ( $result == false )
97 $db->rollback( );
98 else
99 $db->commit();
100 }
101
105 function delete( $id = -1 )
106 {
107 $db =& eZDB::globalDatabase();
108 $db->begin();
109
110 if ( $id == -1 )
111 $id = $this->ID;
112
113 // delete all mail from this category.
114 $bulkmail = eZBulkMailCategory::mail( 0, 0, true, $id );
115 foreach( $bulkmail as $mail )
116 {
117 $mail->delete();
118 }
119
120 // unsubscribe users of type eZUser
121 $results[] = $db->query( "DELETE FROM eZBulkMail_UserCategoryLink WHERE CategoryID='$id'" );
122 // unsubscribe password users.
123 $results[] = $db->query( "DELETE FROM eZBulkMail_SubscriptionLink WHERE CategoryID='$id'" );
124
125 // delete from BulkMailCategoryLink
126 $results[] = $db->query( "DELETE FROM eZBulkMail_MailCategoryLink WHERE CategoryID='$id'" );
127 // delete actual group entry
128 $results[] = $db->query( "DELETE FROM eZBulkMail_Category WHERE ID='$id'" );
129
130 $commit = true;
131 foreach ( $results as $result )
132 {
133 if ( $result == false )
134 $commit = false;
135 }
136 if ( $commit == false )
137 $db->rollback( );
138 else
139 $db->commit();
140 }
141
145 function get( $id=-1 )
146 {
147 $db =& eZDB::globalDatabase();
148
149 if ( $id != "" )
150 {
151 $db->array_query( $category_array, "SELECT * FROM eZBulkMail_Category WHERE ID='$id'" );
152 if ( count( $category_array ) > 1 )
153 {
154 die( "Error: Category's with the same ID was found in the database. This shouldent happen." );
155 }
156 else if ( count( $category_array ) == 1 )
157 {
158 $this->ID = $category_array[0][$db->fieldName( "ID" )];
159 $this->Name = $category_array[0][$db->fieldName( "Name" )];
160 $this->IsPublic = $category_array[0][$db->fieldName( "IsPublic" )];
161 $this->Description = $category_array[0][$db->fieldName( "Description" )];
162 }
163 }
164 }
165
169 function getByName( $name )
170 {
171 $db =& eZDB::globaldatabase();
172 $category_array = array();
173
174 $name =& $db->escapeString( $name );
175 $db->array_query( $category_array, "SELECT ID FROM eZBulkMail_Category WHERE Name='$name'" );
176
177 $return_value = false;
178 if ( count( $category_array ) == 1 )
179 $return_value = new eZBulkMailCategory( $category_array[0][$db->fieldName( "ID" )] );
180
181 return $return_value;
182 }
183
189 static public function getAll( $withPrivate = true )
190 {
191 $db =& eZDB::globaldatabase();
192 $return_array = array();
193 $category_array = array();
194
195 $privateSQL = "";
196 if ( $withPrivate == false )
197 $privateSQL = "WHERE IsPublic='1'";
198
199 $db->array_query( $category_array, "SELECT ID, Name FROM eZBulkMail_Category $privateSQL ORDER BY Name" );
200
201 for ( $i = 0; $i < count( $category_array ); $i++ )
202 {
203 $return_array[$i] = new eZBulkMailCategory( $category_array[$i][$db->fieldName( "ID" )] );
204 }
205 return $return_array;
206 }
207
211 function id()
212 {
213 return $this->ID;
214 }
215
219 function name( $html = true )
220 {
221 if ( $html )
222 return htmlspecialchars( $this->Name );
223 else
224 return $this->Name;
225 }
226
230 function description( $html = true )
231 {
232 if ( $html )
233 return htmlspecialchars( $this->Description );
234 else
235 return $this->Description;
236 }
237
241 function setName( $value )
242 {
243 $this->Name = $value;
244 }
245
249 function setDescription( $value )
250 {
251 $this->Description = $value;
252 }
253
257 function setIsPublic( $value )
258 {
259 $this->IsPublic = $value;
260 }
261
265 function isPublic( )
266 {
267 return $this->IsPublic;
268 }
269
273 function addGroupSubscription( $groupID )
274 {
275 $db =& eZDB::globalDatabase();
276 $db->begin();
277
278 if ( is_a( $groupID, "eZUserGroup" ) )
279 $groupID = $groupID->id();
280
281 $result = $db->query( "INSERT INTO eZBulkMail_GroupCategoryLink
282 (CategoryID, GroupID)
283 VALUES
284 ('$this->ID', '$groupID')" );
285
286 if ( $result == false )
287 $db->rollback( );
288 else
289 $db->commit();
290 }
291
295 function removeGroupSubscription( $group )
296 {
297 $db =& eZDB::globalDatabase();
298 $db->begin();
299
300 if ( is_a( $group, "eZUserGroup" ) )
301 {
302 $groupID = $group->id();
303 $result = $db->query( "DELETE FROM eZBulkMail_GroupCategoryLink WHERE CategoryID='$this->ID' AND GroupID='$groupID'" );
304 }
305 else if ( $group == true )
306 {
307 $result = $db->query( "DELETE FROM eZBulkMail_GroupCategoryLink WHERE CategoryID='$this->ID'" );
308 }
309 if ( $result == false )
310 $db->rollback( );
311 else
312 $db->commit();
313 }
314
319 function groupSubscriptions( $asObjects = true, $CategoryID = 0 )
320 {
321 $db =& eZDB::globalDatabase();
322
323 if ( $CategoryID == 0 )
324 $CategoryID = $this->ID;
325 $final_result = array();
326 $db->array_query( $result_array, "SELECT GroupID FROM eZBulkMail_GroupCategoryLink WHERE CategoryID='$CategoryID'" );
327 if ( count( $result_array ) > 0 )
328 {
329 foreach ( $result_array as $result )
330 $final_result[] = $asObjects ? new eZUserGroup( $result[$db->fieldName( "GroupID" )] ) : $result[$db->fieldName( "GroupID" )];
331 }
332 return $final_result;
333 }
334
339 function mail( $offset = 0, $limit = 50, $getDrafs = true, $id = -1 )
340 {
341 $db =& eZDB::globalDatabase();
342 $getDraftsSQL = "";
343
344 if( $id == -1 )
345 $id = $this->ID;
346
347 $return_array = array();
348 $mail_array = array();
349
350 if ( !$getDrafs )
351 {
352 $getDraftsSQL = "AND IsDraft = '0'";
353 }
354
355 $query = "SELECT eZBulkMail_Mail.ID AS MailID
356 FROM eZBulkMail_Mail, eZBulkMail_Category, eZBulkMail_MailCategoryLink
357 WHERE eZBulkMail_MailCategoryLink.MailID = eZBulkMail_Mail.ID
358 AND eZBulkMail_Category.ID = eZBulkMail_MailCategoryLink.CategoryID
359 AND eZBulkMail_Category.ID='$id'
360 $getDraftsSQL
361 GROUP BY eZBulkMail_Mail.ID";
362
363 if( $limit > 0 )
364 $db->array_query( $mail_array, $query, array( "Limit" => $limit, "Offset" => $offset ) );
365 else
366 $db->array_query( $mail_array, $query );
367
368 for ( $i = 0; $i < count( $mail_array ); $i++ )
369 {
370 $return_array[$i] = new eZBulkMail( $mail_array[$i][$db->fieldName( "MailID" )] );
371 }
372
373 return $return_array;
374 }
375
379 function mailCount()
380 {
381 $db =& eZDB::globalDatabase();
382
383 $db->query_single( $result, "
384 SELECT COUNT( eZBulkMail_Mail.ID ) AS Count
385 FROM eZBulkMail_Mail, eZBulkMail_MailCategoryLink
386 WHERE eZBulkMail_MailCategoryLink.CategoryID='$this->ID' AND eZBulkMail_Mail.ID=eZBulkMail_MailCategoryLink.MailID" );
387
388 return $result[$db->fieldName( "Count" )];
389 }
390
396 function subscribers( $asObject = true, $categoryID = 0 )
397 {
398 $db =& eZDB::globalDatabase();
399
400 if ( $categoryID == 0 )
401 $categoryID = $this->ID;
402 $subscribe_array = array();
403 $return_array = array();
404
405 $db->array_query( $subscribe_array, "SELECT ID, EMail FROM eZBulkMail_SubscriptionAddress, eZBulkMail_SubscriptionLink
406 WHERE eZBulkMail_SubscriptionAddress.ID=eZBulkMail_SubscriptionLink.AddressID
407 AND eZBulkMail_SubscriptionLink.CategoryID='$categoryID'" );
408
409 for ( $i = 0; $i < count( $subscribe_array ); $i++ )
410 {
411 if ( $asObject )
412 $return_array[$i] = new eZBulkMailSubscriptionAddress( $subscribe_array[$i][$db->fieldName( "ID" )], $this->ID );
413 else
414 $return_array[$i] = $subscribe_array[$i][$db->fieldName( "EMail" )];
415 }
416 return $return_array;
417 }
418
424 function subscribedUsers( $categoryID = 0 )
425 {
426 $db =& eZDB::globalDatabase();
427
428 if( $categoryID == 0 )
429 $categoryID = $this->ID;
430 $subscribe_array = array();
431 $return_array = array();
432 $db->array_query( $subscribe_array, "SELECT UserID FROM eZBulkMail_UserCategoryLink
433 WHERE CategoryID='$categoryID'" );
434
435 for ( $i = 0; $i < count( $subscribe_array ); $i++ )
436 {
437 $return_array[$i] = new eZBulkMailUserSubscripter( $subscribe_array[$i][$db->fieldName( "UserID" )], $this->ID );
438 }
439 return $return_array;
440 }
441
445 function subscriberCount()
446 {
447 $db =& eZDB::globalDatabase();
448
449 $db->query_single( $result, "SELECT COUNT( EMail ) as Count FROM eZBulkMail_SubscriptionAddress, eZBulkMail_SubscriptionLink
450 WHERE eZBulkMail_SubscriptionAddress.ID=eZBulkMail_SubscriptionLink.AddressID
451 AND eZBulkMail_SubscriptionLink.CategoryID='$this->ID'" );
452
453 $count = $result[$db->fieldName( "Count" )];
454 $result_array = array();
455 $db->array_query( $result_array, "SELECT GroupID FROM eZBulkMail_GroupCategoryLink WHERE CategoryID='$this->ID'" );
456 foreach ( $result_array as $result )
457 {
458 $count += count( eZUserGroup::users( $result["GroupID"] ) );
459 }
460 return $count;
461 }
462
467 function setSingleList( $value )
468 {
469 $db =& eZDB::globalDatabase();
470 $db->begin();
471
472 $result = $db->query( "UPDATE eZBulkMail_Category SET IsSingleCategory='0'" );
473 if ( $result == false )
474 $db->rollback( );
475 else
476 $db->commit();
477
478 if ( $value != false )
479 {
480 if ( is_a( $value, "eZBulkMailCategory" ) )
481 $value = $value->id();
482
483 $db->begin();
484 $result = $db->query( "UPDATE eZBulkMail_Category SET IsSingleCategory='1' WHERE ID='$value'" );
485 if ( $result == false )
486 $db->rollback( );
487 else
488 $db->commit();
489 }
490 }
491
496 static public function singleList( $asObject = true )
497 {
498 $db =& eZDB::globalDatabase();
499 $return_value = false;
500 $result_array = array();
501 $db->array_query( $result_array, "SELECT ID FROM eZBulkMail_Category WHERE IsSingleCategory='1'" );
502
503 if ( count( $result_array ) > 0 )
504 $return_value = ( $asObject == true ) ? new eZBulkMailCategory( $result_array[0][$db->fieldName( "ID" )] ) : $result_array[0][$db->fieldName( "ID" )];
505
506 return $return_value;
507 }
508
513 function settings( $address, $category=false )
514 {
515 if ( is_numeric ( $category ) )
516 $categoryID = $category;
517 else if ( is_a ( $category, "eZBulkMailCategory" ) )
518 $categoryID = $category->id();
519 else
520 $categoryID = $this->ID;
521
522 $ret = false;
523 if ( is_a ( $address, "eZBulkMailSubscriptionAddress" ) )
524 {
525 $db =& eZDB::globalDatabase();
526
527 $addressID = $address->id();
528 $db->array_query( $result_array, "SELECT ID FROM eZBulkMail_SubscriptionCategorySettings WHERE CategoryID='$categoryID' AND AddressID='$addressID'" );
529 $ret = $result_array[0][$db->fieldName("ID")];
530 if ( is_numeric ( $ret ) )
531 {
532 $ret = new eZBulkMailCategorySettings( $ret );
533 }
534 }
535 if ( is_a( $address, "eZBulkMailUserSubscripter" ) )
536 {
537 $db =& eZDB::globalDatabase();
538
539 $user = $address->user();
540
541 $userID = $user->id();
542
543 $db->array_query( $result_array, "SELECT ID FROM eZBulkMail_UserCategorySettings WHERE CategoryID='$categoryID' AND UserID='$userID'" );
544 $ret = $result_array[0][$db->fieldName("ID")];
545 if ( is_numeric ( $ret ) )
546 {
547 $ret = new eZBulkMailUserCategorySettings( $ret );
548 }
549 }
550
551 return $ret;
552 }
553
558 function addDelayMail( $address, $category, $delay, $mail )
559 {
560 if ( is_numeric ( $category ) )
561 $categoryID = $category;
562 else if ( is_a( $category, "eZBulkMailCategory" ) )
563 $categoryID = $category->id();
564 else
565 $categoryID = $this->ID;
566
567 if ( is_a( $mail, "eZBulkMail" ) )
568 $mailID = $mail->id();
569 else
570 return false;
571
572 $ret = false;
573 if ( is_a( $address, "eZBulkMailSubscriptionAddress" ) )
574 {
575 $db =& eZDB::globalDatabase();
576 $db->begin();
577
578 $addressID = $address->id();
579 $db->lock( "eZBulkMail_CategoryDelay" );
580 $nextID = $db->nextID( "eZBulkMail_CategoryDelay", "ID" );
581
582 $result = $db->query( "INSERT INTO eZBulkMail_CategoryDelay
583 ( ID, CategoryID, AddressID, Delay, MailID )
584 VALUES
585 ( '$nextID',
586 '$categoryID',
587 '$addressID',
588 '$delay',
589 '$mailID') " );
590
591 $db->unlock();
592 if ( $result == false )
593 $db->rollback( );
594 else
595 $db->commit();
596 }
597 else if ( is_a ( $address, "eZBulkMailUserSubscripter" ) )
598 {
599 $db =& eZDB::globalDatabase();
600 $db->begin();
601
602 $user = $address->user();
603 $userID = $user->id();
604 $db->lock( "eZBulkMail_UserCategoryDelay" );
605 $nextID = $db->nextID( "eZBulkMail_UserCategoryDelay", "ID" );
606
607 $result = $db->query( "INSERT INTO eZBulkMail_UserCategoryDelay
608 ( ID, CategoryID, UserID, Delay, MailID )
609 VALUES
610 ( '$nextID',
611 '$categoryID',
612 '$userID',
613 '$delay',
614 '$mailID' ) " );
615
616 $db->unlock();
617 if ( $result == false )
618 $db->rollback( );
619 else
620 $db->commit();
621 }
622
623 return $ret;
624 }
625
629 function addUserSubscription( $user )
630 {
631 $result = false;
632 if ( is_a( $user, "eZUser" ) )
633 {
634 $db =& eZDB::globalDatabase();
635 $db->begin();
636
637 $userID = $user->id();
638 $result = $db->query( "INSERT INTO eZBulkMail_UserCategoryLink
639 (CategoryID, UserID)
640 VALUES
641 ('$categoryID', '$userID') " );
642
643 if ( $result == false )
644 $db->rollback( );
645 else
646 $db->commit();
647 }
648 return $result;
649 }
650
651 var $ID;
652 var $Name;
653 var $Description;
654 var $IsPublic;
655 var $IsSingleCategory;
656 }
657
658 ?>
$category
if( $Action=="Edit") $category
Definition: adedit.php:378
$i
$i
Definition: admin/adlist.php:91
$CategoryID
$CategoryID
Definition: admin/articleedit.php:53
$group
$group
Definition: admin/articleedit.php:799
$userID
else $userID
Definition: appointmentedit.php:121
$Description
$Description
Definition: articlelistrss.php:38
$address
$address
Definition: checkout.php:588
eZBulkMailSubscriptionAddress
Definition: ezbulkmailsubscriptionaddress.php:40
eZBulkMailUserSubscripter
Definition: ezbulkmailusersubscripter.php:42
eZBulkMail
Definition: ezbulkmail.php:46
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZUserGroup
Definition: ezusergroup.php:66
eZUserGroup\users
static users( $GroupID=false, $order="Login", $search=false)
Definition: ezusergroup.php:291
$result
$result
Definition: companysearch.php:94
$results
$results
Definition: companysearch.php:81
$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
$mail_array
$mail_array
Definition: ezbug/admin/cron.php:42
$mail
$mail
Definition: ezbulkmail/admin/maillist.php:61
$groupID
$groupID
Definition: ezgroupeventcalendar/user/dayview.php:90
$limit
$limit
Definition: ezimagecatalogue/admin/imagelist.php:312
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$offset
$offset
Definition: ezstats/admin/cron.php:51
$count
$count
Definition: onlinetypelist.php:108
$Name
$Name
Definition: polledit.php:250
$categoryID
else $categoryID
Definition: productview.php:66
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
$user
$user
Definition: user/adlist.php:39
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.