Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezmailfolder.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezmailfolder.php 7641 2001-10-03 08:44:34Z fh $
5 //
6 // eZMailFolder class
7 //
8 // Created on: <20-Mar-2001 18:29:11 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
38 // include_once( "ezuser/classes/ezuser.php" );
39 // include_once( "classes/INIFile.php" );
40
41 /* DEFINES */
42 define( "USER", 0 );
43 define( "INBOX", 1 );
44 define( "DRAFTS", 2 );
45 define( "SENT", 3 );
46 define( "TRASH", 4 );
47
48 class eZMailFolder
49 {
53 function __construct( $id="", $fetch=true )
54 {
55 // default value
56 $this->IsPublished = "false";
57
58 if ( $id != "" )
59 {
60 $this->ID = $id;
61 $this->get( $this->ID );
62 }
63 }
64
68 function delete( $id = -1 )
69 {
70 $db =& eZDB::globalDatabase();
71
72 if ( $id == -1 )
73 $id = $this->ID;
74
75 $db->query( "DELETE FROM eZMail_Folder WHERE ID='$id'" );
76
77 $mail = eZMailFolder::mail( "subject", 0, 10000, $id );
78 foreach ( $mail as $mailItem )
79 $mailItem->delete();
80 }
81
85 function store()
86 {
87 $db =& eZDB::globalDatabase();
88
89 $name = $db->escapeString( $this->Name );
90 $db->begin();
91 if ( !isset( $this->ID ) )
92 {
93 $db->lock( "eZMail_Folder" );
94 $nextID = $db->nextID( "eZMail_Folder", "ID" );
95
96 $result = $db->query( "INSERT INTO eZMail_Folder (ID, UserID, ParentID, Name, FolderType )
97 VALUES (
98 '$nextID',
99 '$this->UserID',
100 '$this->ParentID',
101 '$name',
102 '$this->FolderType' )
103 " );
104 $db->unlock();
105 $this->ID = $nextID;
106
107 }
108 else
109 {
110 $result = $db->query( "UPDATE eZMail_Folder SET
111 UserID='$this->UserID',
112 ParentID='$this->ParentID',
113 Name='$name',
114 FolderType='$this->FolderType'
115 WHERE ID='$this->ID'
116 " );
117 }
118
119 if ( $result == false )
120 $db->rollback( );
121 else
122 $db->commit();
123
124 return true;
125 }
126
130 function get( $id="" )
131 {
132 $db =& eZDB::globalDatabase();
133 $ret = false;
134
135 if ( $id != "" )
136 {
137 $db->array_query( $account_array, "SELECT * FROM eZMail_Folder WHERE ID='$id'" );
138 if ( count( $account_array ) > 1 )
139 {
140 die( "Error: Mail folders with the same ID was found in the database. This should not happen." );
141 }
142 else if ( count( $account_array ) == 1 )
143 {
144
145 $this->ID = $account_array[0][ $db->fieldName("ID") ];
146 $this->UserID = $account_array[0][ $db->fieldName("UserID") ];
147 $this->ParentID = $account_array[0][ $db->fieldName("ParentID") ];
148 $this->Name = $account_array[0][ $db->fieldName("Name") ];
149 $this->FolderType = $account_array[0][ $db->fieldName("FolderType") ];
150
151 $ret = true;
152 }
153 }
154 return $ret;
155 }
156
160 function id()
161 {
162 return $this->ID;
163 }
164
168 function userID()
169 {
170 return $this->UserID;
171 }
172
176 function setUser( $value )
177 {
178 if ( is_a( $value, "eZUser" ) )
179 $value = $value->id();
180
181 $this->UserID = $value;
182 }
183
187 function name()
188 {
189 return $this->Name;
190 }
191
195 function setName( $value )
196 {
197 $this->Name = $value;
198 }
199
203 function parentID()
204 {
205 return $this->ParentID;
206 }
207
211 function setParent( $value )
212 {
213 $this->ParentID = $value;
214 }
215
225 function folderType()
226 {
227 return $this->FolderType;
228 }
229
239 function setFolderType( $value )
240 {
241 $this->FolderType = $value;
242 }
243
247 function addMail( $mail, $removeFromOld = true )
248 {
249 if ( is_a( $mail, "eZMail" ) )
250 $mail = $mail->id();
251
252 $db =& eZDB::globalDatabase();
253 $db->begin();
254 if ( $removeFromOld == true )
255 $results[] = $db->query( "DELETE FROM eZMail_MailFolderLink WHERE MailID='$mail'" );
256
257 $query = "INSERT INTO eZMail_MailFolderLink ( FolderID, MailID ) VALUES
258 ( '$this->ID', '$mail' )";
259
260 $results[] = $db->query( $query );
261 $res = in_array( false, $results ) ? false : true;
262
263 if ( $res == false )
264 {
265 $db->rollback( );
266 return false;
267 }
268 else
269 $db->commit();
270
271 return true;
272 }
273
277 function removeMail( $mail )
278 {
279 if ( is_a( $mail, "eZMail" ) )
280 {
281 $mailID = $mail->id();
282 $query = "DELETE FROM eZMail_MailFolderLink
283 WHERE FolderID='$this->ID' AND MailID='$mailID'";
284
285 $db =& eZDB::globalDatabase();
286 $db->query( $query );
287 }
288 }
289
295 function getByParent( $parent )
296 {
297 if ( is_a( $parent, "eZMailFolder" ) )
298 {
299 $db =& eZDB::globalDatabase();
300
301 $return_array = array();
302 $folder_array = array();
303
304 $parentID = $parent->id();
305
306 $db->array_query( $category_array, "SELECT ID, Name FROM eZMail_Folder
307 WHERE ParentID='$parentID'
308 ORDER BY Name" );
309
310 for ( $i=0; $i < count($category_array); $i++ )
311 {
312 $return_array[$i] = new eZMailFolder( $folder_array[$i][$db->fieldName("ID")], 0 );
313 }
314
315 return $return_array;
316 }
317 else
318 {
319 return 0;
320 }
321 }
322
328 static public function getByUser( $user = false, $withSpecialFolders=false, $parentFolder = -1 )
329 {
330 if ( !is_a( $user, "eZUser" ) )
331 $user =& eZUser::currentUser();
332
333 $noSpecial = "";
334 if ( $withSpecialFolders == false )
335 {
336 $noSpecial = "AND FolderType='0'";
337 }
338 $parentFolderSQL = "";
339 if ( $parentFolder != -1 )
340 $parentFolderSQL = "AND ParentID='$parentFolder'";
341
342 $return_array = array();
343 $res = array();
344 $userid = $user->id();
345 $database =& eZDB::globalDatabase();
346 $query = "SELECT ID FROM eZMail_Folder WHERE UserID='$userid' $noSpecial $parentFolderSQL";
347 $database->array_query( $res, $query );
348
349 for ( $i=0; $i < count($res); $i++ )
350 {
351 $return_array[$i] = new eZMailFolder( $res[$i][$database->fieldName("ID")] );
352 }
353
354 return $return_array;
355 }
356
357 /*
358 Creates a tree of the folders for the current user.
359 */
360 static public function &getTree( $parentID=0, $level=0 )
361 {
362 $folderList = eZMailFolder::getByUser( false, false, $parentID );
363
364 $tree = array();
365 $level++;
366 foreach ( $folderList as $folder )
367 {
368 // array_push( $tree, array( new eZMailFolder( $folder->id() ), $level ) );
369 array_push( $tree, array( $folder->id(), $folder->name(), $level ) );
370
371 if ( $folder != 0 )
372 {
373 $tree = array_merge( $tree, eZMailFolder::getTree( $folder->id(), $level ) );
374 }
375 }
376 return $tree;
377 }
378
379
386 function &mail( $sortmode="subject_asc", $offset=0, $limit=50, $folderID = -1 )
387 {
388 if ( $folderID == -1 )
389 $folderID = $this->ID;
390
391 $orderBySQL = "Mail.UDate ASC";
392 switch( $sortmode )
393 {
394 case "subject_asc" : $orderBySQL = "Mail.Subject ASC"; break;
395 case "subject_desc" : $orderBySQL = "Mail.Subject DESC"; break;
396 case "date_asc" : $orderBySQL = "Mail.UDate ASC"; break;
397 case "date_desc" : $orderBySQL = "Mail.UDate DESC"; break;
398 case "from_asc" : $orderBySQL = "Mail.FromField ASC"; break;
399 case "from_desc" : $orderBySQL = "Mail.FromField DESC"; break;
400 case "size_asc" : $orderBySQL = "Mail.Size ASC"; break;
401 case "size_desc" : $orderBySQL = "Mail.Size DESC"; break;
402 }
403
404 $db =& eZDB::globalDatabase();
405 $query = "SELECT Mail.ID FROM eZMail_Mail AS Mail, eZMail_MailFolderLink AS Link
406 WHERE Mail.ID=Link.MailID AND Link.FolderID='$folderID'
407 ORDER BY $orderBySQL";
408
409 $mail_array = array();
410 $return_array = array();
411 $db->array_query( $mail_array, $query, array( "Limit" => $limit, "Offset" => $offset ) );
412 for ( $i=0; $i < count($mail_array); $i++ )
413 {
414 $return_array[$i] = new eZMail( $mail_array[$i][$db->fieldName("ID")] );
415 }
416
417 return $return_array;
418 }
419
423 function mailCount()
424 {
425 $db =& eZDB::globalDatabase();
426 $query = "SELECT Count( Mail.ID ) as Count FROM eZMail_Mail AS Mail, eZMail_MailFolderLink AS Link
427 WHERE Mail.ID=Link.MailID AND Link.FolderID='$this->ID'";
428 $db->query_single( $result, $query );
429 return $result[$db->fieldName("Count")];
430 }
431
435 function deleteAll()
436 {
437 $db =& eZDB::globalDatabase();
438 $query = "SELECT Mail.ID FROM eZMail_Mail AS Mail, eZMail_MailFolderLink AS Link
439 WHERE Mail.ID=Link.MailID AND Link.FolderID='$this->ID'";
440
441 $db->array_query( $mail_array, $query );
442 for ( $i=0; $i < count($mail_array); $i++ )
443 eZMail::delete( $mail_array[$i][$db->fieldName("ID")] );
444 }
445
450 function count( $unreadOnly = false, $folderID =-1 )
451 {
452 $db =& eZDB::globalDatabase();
453
454 if ( $folderID == -1 )
455 $folderID = $this->ID;
456
457 $unreadSQL = "";
458 if ( $unreadOnly == true )
459 $unreadSQL = "AND Mail.Status='0'";
460
461 $db->query_single( $res, "SELECT count( Mail.ID ) as Count from eZMail_Mail as Mail,
462 eZMail_MailFolderLink as Link
463 WHERE Mail.ID=Link.MailID AND Link.FolderID='$folderID' $unreadSQL" );
464 return $res[$db->fieldName("Count")];
465 }
466
467 /*
468 \static
469
470 Returns the requested special folder of the current user or the user specified. Valid folders are:
471 INBOX
472 SENT
473 DRAFTS
474 TRASH
475 If the folder does not exist it will be created. If the creation should fail the function returns false.
476 */
477 static public function getSpecialFolder( $specialType, $user=false )
478 {
479 if ( !is_a( $user, "eZUser" ) )
480 $user =& eZUser::currentUser();
481
482 $userid = $user->id();
483
484 if ( $userid == 0 )
485 return false;
486
487 $db =& eZDB::globalDatabase();
488 $db->query_single( $res, "SELECT ID FROM eZMail_Folder WHERE FolderType='$specialType' AND UserID='$userid'" );
489
490 // echo $res[$db->fieldName( "ID" )];
491 if ( $res && $res[$db->fieldName( "ID" )] != "" )
492 return new eZMailFolder( $res[$db->fieldName( "ID" )] );
493
494 $ini =& eZINI::instance( 'site.ini' );
495 $Language = $ini->variable( "eZMailMain", "Language" );
496 $folderNameIni = new eZINI( "kernel/ezmail/user/intl/" . $Language . "/folderlist.php.ini" );
497 switch( $specialType )
498 {
499 case 1 :
500 $folderName = $folderNameIni->variable( "strings", "inbox" );
501 break;
502 case 2 :
503 $folderName = $folderNameIni->variable( "strings", "sent" );
504 break;
505 case 3 :
506 $folderName = $folderNameIni->variable( "strings", "drafts" );
507 break;
508 case 4 :
509 $folderName = $folderNameIni->variable( "strings", "trash" );
510 break;
511 default:
512 return false;
513 break;
514 }
515
516 $db->begin();
517 $db->lock( "eZMail_Folder" );
518 $nextID = $db->nextID( "eZMail_Folder", "ID" );
519
520 $result = $db->query( "INSERT INTO eZMail_Folder (ID, FolderType, UserID, ParentID, Name )
521 VALUES (
522 '$nextID',
523 '$specialType',
524 '$userid',
525 '0',
526 '$folderName' )
527 " );
528
529 $db->unlock();
530 if ( $result == false )
531 {
532 $db->rollback( );
533 return false;
534 }
535 else
536 $db->commit();
537
538 return new eZMailFolder( $nextID );
539 }
540
545 function isChild( $folderID, $check_for_self = false )
546 {
547 $return_value = false;
548 $db =& eZDB::globalDatabase();
549
550 if ( is_a( $folderID, "eZMailFolder" ) )
551 $folderID = $folderID->id();
552
553 if ( $check_for_self == true && $folderID == $this->ID )
554 return true;
555
556 while ( $folderID != 0 )
557 {
558 $db->query_single( $result, "SELECT ParentID FROM eZMail_Folder WHERE ID='$folderID'" );
559 $folderID = $result[$db->fieldName("ParentID")];
560 if ( $folderID == $this->ID )
561 return true;
562 }
563 return $return_value;
564 }
565
571 static public function isOwner( $user, $folderID )
572 {
573 if ( is_a( $user, "eZUser" ) )
574 $user = $user->id();
575
576 $db =& eZDB::globalDatabase();
577 $db->query_single( $res, "SELECT UserID from eZMail_Folder WHERE ID='$folderID'" );
578 if ( $res[$db->fieldName( "UserID" )] == $user )
579 return true;
580
581 return false;
582 }
583
584
585 var $ID;
586 var $UserID;
587 var $ParentID;
588 var $Name;
589 var $FolderType=0;
590 var $IsPublished;
591 }
592
593 ?>
$i
$i
Definition: admin/adlist.php:91
$level
$level
Definition: admin/message.php:106
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZINI
Reads and writes .ini style configuration files.
eZMailFolder
Definition: ezmailfolder.php:49
eZMailFolder\name
name()
Definition: ezmailfolder.php:187
eZMailFolder\$IsPublished
$IsPublished
Definition: ezmailfolder.php:590
eZMailFolder\addMail
addMail( $mail, $removeFromOld=true)
Definition: ezmailfolder.php:247
eZMailFolder\getByUser
static getByUser( $user=false, $withSpecialFolders=false, $parentFolder=-1)
Definition: ezmailfolder.php:328
eZMailFolder\parentID
parentID()
Definition: ezmailfolder.php:203
eZMailFolder\$FolderType
$FolderType
Definition: ezmailfolder.php:589
eZMailFolder\userID
userID()
Definition: ezmailfolder.php:168
eZMailFolder\getByParent
getByParent( $parent)
Definition: ezmailfolder.php:295
eZMailFolder\count
count( $unreadOnly=false, $folderID=-1)
Definition: ezmailfolder.php:450
eZMailFolder\$UserID
$UserID
Definition: ezmailfolder.php:586
eZMailFolder\isChild
isChild( $folderID, $check_for_self=false)
Definition: ezmailfolder.php:545
eZMailFolder\folderType
folderType()
Definition: ezmailfolder.php:225
eZMailFolder\setFolderType
setFolderType( $value)
Definition: ezmailfolder.php:239
eZMailFolder\setParent
setParent( $value)
Definition: ezmailfolder.php:211
eZMailFolder\$Name
$Name
Definition: ezmailfolder.php:588
eZMailFolder\deleteAll
deleteAll()
Definition: ezmailfolder.php:435
eZMailFolder\mailCount
mailCount()
Definition: ezmailfolder.php:423
eZMailFolder\__construct
__construct( $id="", $fetch=true)
Definition: ezmailfolder.php:53
eZMailFolder\mail
& mail( $sortmode="subject_asc", $offset=0, $limit=50, $folderID=-1)
Definition: ezmailfolder.php:386
eZMailFolder\getSpecialFolder
static getSpecialFolder( $specialType, $user=false)
Definition: ezmailfolder.php:477
eZMailFolder\id
id()
Definition: ezmailfolder.php:160
eZMailFolder\$ParentID
$ParentID
Definition: ezmailfolder.php:587
eZMailFolder\removeMail
removeMail( $mail)
Definition: ezmailfolder.php:277
eZMailFolder\store
store()
Definition: ezmailfolder.php:85
eZMailFolder\getTree
static & getTree( $parentID=0, $level=0)
Definition: ezmailfolder.php:360
eZMailFolder\setName
setName( $value)
Definition: ezmailfolder.php:195
eZMailFolder\$ID
$ID
Definition: ezmailfolder.php:585
eZMailFolder\setUser
setUser( $value)
Definition: ezmailfolder.php:176
eZMailFolder\isOwner
static isOwner( $user, $folderID)
Definition: ezmailfolder.php:571
eZMail
Definition: ezmail.php:57
eZMail\delete
delete( $id=-1)
Definition: ezmail.php:87
eZUser\currentUser
static & currentUser()
Definition: ezuser.php:896
$Language
$Language
Definition: classes/admin/linklist.php:65
$ini
$ini
Definition: classes/admin/linklist.php:64
$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
$tree
$tree
Definition: ezad/admin/categoryedit.php:172
$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
$folderList
foreach( $pathArray as $path) $folderList
Definition: ezfilemanager/admin/browse.php:126
$folder
if(!isset( $FolderID)) $folder
Definition: ezfilemanager/admin/browse.php:74
$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
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+.