Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezperson.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezperson.php 8022 2001-10-23 13:31:24Z jhe $
5 //
6 // Definition of eZPerson class
7 //
8 // Created on: <09-Nov-2000 14:52:40 ce>
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
35 // include_once( "ezuser/classes/ezuser.php" );
36 // include_once( "classes/ezdb.php" );
37 // include_once( "classes/ezquery.php" );
38 // include_once( "ezaddress/classes/ezaddress.php" );
39 // include_once( "ezaddress/classes/ezphone.php" );
40 // include_once( "ezaddress/classes/ezonline.php" );
41
42 class eZPerson
43 {
50 function __construct( $id="" )
51 {
52 $this->ContactType = 0;
53 if ( !empty( $id ) )
54 {
55 $this->ID = $id;
56 $this->get( $this->ID );
57 }
58 }
59
63 function store()
64 {
65 $db =& eZDB::globalDatabase();
66 $db->begin();
67 $birth = "NULL";
68 if ( isset( $this->BirthDate ) and $this->BirthDate != "" )
69 $birth = "$this->BirthDate";
70 $firstname = $db->escapeString( $this->FirstName );
71 $lastname = $db->escapeString( $this->LastName );
72 $comment = $db->escapeString( $this->Comment );
73 if ( !isset( $this->ID ) )
74 {
75 $db->lock( "eZContact_Person" );
76 $this->ID = $db->nextID( "eZContact_Person", "ID" );
77 $res[] = $db->query( "INSERT INTO eZContact_Person
78 (ID,
79 FirstName,
80 LastName,
81 Comment,
82 BirthDate,
83 ContactTypeID,
84 ImageID)
85 VALUES
86 ('$this->ID',
87 '$firstname',
88 '$lastname',
89 '$comment',
90 '$birth',
91 '$this->ContactType',
92 '$this->ImageID')" );
93 $db->unlock();
94 $firstname = strtolower( $firstname );
95 $lastname = strtolower( $lastname );
96 $res[] = $db->query( "INSERT INTO eZContact_PersonIndex
97 (PersonID, Value, Type)
98 VALUES
99 ('$this->ID', '$firstname', '0')" );
100 $res[] = $db->query( "INSERT INTO eZContact_PersonIndex
101 (PersonID, Value, Type)
102 VALUES
103 ('$this->ID', '$lastname', '0')" );
104 }
105 else
106 {
107 $queryText = "UPDATE eZContact_Person SET
108 FirstName='$firstname',
109 LastName='$lastname',
110 Comment='$comment',
111 BirthDate=$birth,
112 ContactTypeID='$this->ContactType',
113 ImageID='$this->ImageID'
114 WHERE ID='$this->ID'";
115 $firstname = strtolower( $firstname );
116 $lastname = strtolower( $lastname );
117 $queryText = "UPDATE eZContact_PersonIndex SET
118 Value='$firstname'
119 WHERE PersonID='$this->ID' AND Type='0'";
120 // var_dump($queryText);
121 $res[] = $db->query( $queryText );
122 $res[] = $db->query( "UPDATE eZContact_PersonIndex SET
123 Value='$lastname'
124 WHERE PersonID='$this->ID' AND Type='0'" );
125 }
126 eZDB::finish( $res, $db );
127 }
128
129
133 static public function delete( $id = false )
134 {
135 $db =& eZDB::globalDatabase();
136 $db->begin();
137
138 if ( !$id )
139 $id = $this->ID;
140
141 if ( isset( $id ) && is_numeric( $id ) )
142 {
143 // Delete project state
144 eZPerson::setProjectState( false, $id );
145
146 // Delete real world addresses
147
148 $db->array_query( $address_array, "SELECT eZContact_PersonAddressDict.AddressID AS 'DID'
149 FROM eZAddress_Address, eZContact_PersonAddressDict
150 WHERE eZAddress_Address.ID=eZContact_PersonAddressDict.AddressID
151 AND eZContact_PersonAddressDict.PersonID='$id' " );
152
153 foreach ( $address_array as $addressItem )
154 {
155 $addressDictID = $addressItem[ $db->fieldName( "DID" ) ];
156 $res[] = $db->query( "DELETE FROM eZAddress_Address WHERE ID='$addressDictID'" );
157 }
158 $res[] = $db->query( "DELETE FROM eZContact_PersonAddressDict WHERE PersonID='$id'" );
159
160 // Delete phone numbers.
161
162 $db->array_query( $phone_array, "SELECT eZContact_PersonPhoneDict.PhoneID AS 'DID'
163 FROM eZAddress_Phone, eZContact_PersonPhoneDict
164 WHERE eZAddress_Phone.ID=eZContact_PersonPhoneDict.PhoneID
165 AND eZContact_PersonPhoneDict.PersonID='$id' " );
166
167 foreach ( $phone_array as $phoneItem )
168 {
169 $phoneDictID = $phoneItem["DID"];
170 $res[] = $db->query( "DELETE FROM eZAddress_Phone WHERE ID='$phoneDictID'" );
171 }
172 $res[] = $db->query( "DELETE FROM eZContact_PersonPhoneDict WHERE PersonID='$id'" );
173
174 // Delete online address.
175
176 $db->array_query( $online_array, "SELECT eZContact_PersonOnlineDict.OnlineID AS 'DID'
177 FROM eZAddress_Online, eZContact_PersonOnlineDict
178 WHERE eZAddress_Online.ID=eZContact_PersonOnlineDict.OnlineID
179 AND eZContact_PersonOnlineDict.PersonID='$id' " );
180
181 foreach ( $online_array as $onlineItem )
182 {
183 $onlineDictID = $onlineItem[ $db->fieldName( "DID" ) ];
184 $res[] = $db->query( "DELETE FROM eZAddress_Online WHERE ID='$onlineDictID'" );
185 }
186 $res[] = $db->query( "DELETE FROM eZContact_PersonOnlineDict WHERE PersonID='$id'" );
187 $res[] = $db->query( "DELETE FROM eZContact_CompanyPersonDict WHERE PersonID='$id'" );
188 $res[] = $db->query( "DELETE FROM eZContact_Person WHERE ID='$id'" );
189 $res[] = $db->query( "DELETE FROM eZContact_PersonIndex WHERE PersonID='$id'" );
190 $db->array_query( $res_array, "SELECT ID FROM eZTrade_Order WHERE PersonID='$id'" );
191 // include_once( "eztrade/classes/ezorder.php" );
192 foreach ( $res_array as $order )
193 {
194 $orderObject = new eZOrder( $order[$db->fieldName( "ID" )] );
195 $orderObject->delete();
196 }
197 }
198 eZDB::finish( $res, $db );
199 return true;
200 }
201
202
203 /*
204 Henter ut person med ID == $id
205 */
206 function get( $id )
207 {
208 $db =& eZDB::globalDatabase();
209 if ( $id != "" )
210 {
211 $db->array_query( $person_array, "SELECT * FROM eZContact_Person WHERE ID='$id'" );
212 if ( count( $person_array ) > 1 )
213 {
214 die( "Feil: Flere personer med samme ID funnet i database, dette skal ikke v�re mulig. " );
215 }
216 else if ( count( $person_array ) == 1 )
217 {
218 $this->ID = $person_array[ 0 ][ $db->fieldName( "ID" ) ];
219 $this->FirstName = $person_array[ 0 ][ $db->fieldName( "FirstName" ) ];
220 $this->LastName = $person_array[ 0 ][ $db->fieldName( "LastName" ) ];
221 $this->ContactType = $person_array[ 0 ][ $db->fieldName( "ContactTypeID" ) ];
222 $this->BirthDate = $person_array[ 0 ][ $db->fieldName( "BirthDate" ) ];
223 $this->Comment = $person_array[ 0 ][ $db->fieldName( "Comment" ) ];
224 $this->ImageID = $person_array[ 0 ][ $db->fieldName( "ImageID" ) ];
225 }
226 if ( $this->BirthDate == "NULL" )
227 unset( $this->BirthDate );
228 }
229 }
230
231 /*
232 Fetches the person with the USER ID == $id
233 */
234 function getByUserID( $id )
235 {
236 $db =& eZDB::globalDatabase();
237
238 $query = "SELECT PersonID FROM eZContact_UserPersonDict WHERE UserID='$id'";
239
240 $return_item = 0;
241
242 $db->array_query( $person_array, $query );
243 foreach ( $person_array as $personItem )
244 {
245 $return_item = new eZPerson( $personItem[ $db->fieldName( "PersonID" ) ], false );
246 }
247
248 return $return_item;
249 }
250
251 function getAllCount( $search_types = "", $cond = "all" )
252 {
253 $db =& eZDB::globalDatabase();
254
255 if ( empty( $search_types ) )
256 {
257 switch ( $cond )
258 {
259 case "standalone":
260 {
261 $qry = "SELECT Person.ID
262 FROM eZContact_Person AS Person LEFT JOIN eZContact_CompanyPersonDict AS Dict
263 ON Person.ID=Dict.PersonID WHERE Dict.CompanyID IS NULL
264 GROUP BY Person.ID";
265 $db->array_query( $person_array, $qry );
266 return count( $person_array );
267 break;
268 }
269 case "connected":
270 {
271 $qry = "SELECT Person.ID
272 FROM eZContact_Person AS Person LEFT JOIN eZContact_CompanyPersonDict AS Dict
273 ON Person.ID=Dict.PersonID WHERE Dict.CompanyID IS NOT NULL
274 GROUP BY Person.ID";
275 $db->array_query( $person_array, $qry );
276 return count( $person_array );
277 break;
278 }
279 case "all":
280 default:
281 {
282 $qry = "SELECT count( ID ) AS Count FROM eZContact_Person";
283 $db->query_single( $persons, $qry );
284 return $persons[ $db->fieldName( "Count" ) ];
285 break;
286 }
287 }
288 }
289 else
290 {
291 switch ( $cond )
292 {
293 case "standalone":
294 {
295 $cond_text = "Dict.CompanyID IS NULL AND";
296 break;
297 }
298 case "connected":
299 {
300 $cond_text = "Dict.CompanyID IS NOT NULL AND";
301 break;
302 }
303 case "all":
304 default:
305 {
306 $cond_text = "";
307 }
308 }
309 $query = new eZQuery( array( "A.FirstName", "A.LastName",
310 "C.Number",
311 "E.Street1", "E.Street2", "E.Place", "E.Zip",
312 "Online.Url" ), $search_types );
313 $qry = "SELECT A.ID AS ID FROM
314 eZContact_Person AS A LEFT JOIN eZContact_PersonPhoneDict as B
315 ON A.ID=B.PersonID LEFT JOIN eZAddress_Phone as C
316 ON B.PhoneID=C.ID LEFT JOIN eZContact_PersonAddressDict AS D
317 ON A.ID=D.PersonID LEFT JOIN eZAddress_Address AS E
318 ON D.AddressID=E.ID LEFT JOIN eZContact_PersonOnlineDict AS F
319 ON A.ID=F.PersonID LEFT JOIN eZAddress_Online AS Online
320 ON F.OnlineID=Online.ID LEFT JOIN eZContact_CompanyPersonDict AS Dict
321 ON A.ID=Dict.PersonID
322 WHERE $cond_text (" .
323 $query->buildQuery() .
324 ")
325 GROUP BY A.ID
326 ORDER BY A.LastName, A.FirstName";
327 $db->array_query( $persons, $qry );
328 return count( $persons );
329 }
330 }
331
335 function getAll( $search_types = "", $limit_index = 0, $limit = 1, $cond = "all")
336 {
337 $db =& eZDB::globalDatabase();
338 $person_array = 0;
339
340 if ( $limit >= 0 )
341 {
342 $limit_array = array( "Offset" => $limit_index, "Limit" => $limit );
343 }
344
345 if ( empty( $search_types ) )
346 {
347 switch ( $cond )
348 {
349 case "standalone":
350 {
351 $qry = "SELECT Person.ID
352 FROM eZContact_Person AS Person LEFT JOIN eZContact_CompanyPersonDict AS Dict
353 ON Person.ID=Dict.PersonID WHERE Dict.CompanyID IS NULL
354 GROUP BY Person.ID";
355 break;
356 }
357 case "connected":
358 {
359 $qry = "SELECT Person.ID
360 FROM eZContact_Person AS Person LEFT JOIN eZContact_CompanyPersonDict AS Dict
361 ON Person.ID=Dict.PersonID WHERE Dict.CompanyID IS NOT NULL
362 GROUP BY Person.ID";
363 break;
364 }
365 case "all":
366 default:
367 {
368 $qry = "SELECT ID FROM eZContact_Person ORDER BY LastName, FirstName";
369 break;
370 }
371 }
372 $db->array_query( $person_array, $qry, $limit_array );
373 }
374 else
375 {
376 switch ( $cond )
377 {
378 case "standalone":
379 {
380 $cond_text = "Dict.CompanyID IS NULL AND";
381 break;
382 }
383 case "connected":
384 {
385 $cond_text = "Dict.CompanyID IS NOT NULL AND";
386 break;
387 }
388 case "all":
389 default:
390 {
391 $cond_text = "";
392 }
393 }
394 $query = new eZQuery( array( "A.FirstName", "A.LastName",
395 "C.Number",
396 "E.Street1", "E.Street2", "E.Place", "E.Zip",
397 "Online.Url" ), $search_types );
398 $qry = "SELECT A.ID AS ID FROM
399 eZContact_Person AS A LEFT JOIN eZContact_PersonPhoneDict as B
400 ON A.ID=B.PersonID LEFT JOIN eZAddress_Phone as C
401 ON B.PhoneID=C.ID LEFT JOIN eZContact_PersonAddressDict AS D
402 ON A.ID=D.PersonID LEFT JOIN eZAddress_Address AS E
403 ON D.AddressID=E.ID LEFT JOIN eZContact_PersonOnlineDict AS F
404 ON A.ID=F.PersonID LEFT JOIN eZAddress_Online AS Online
405 ON F.OnlineID=Online.ID LEFT JOIN eZContact_CompanyPersonDict AS Dict
406 ON A.ID=Dict.PersonID
407 WHERE $cond_text (" .
408 $query->buildQuery() .
409 ")
410 GROUP BY A.ID
411 ORDER BY A.LastName, A.FirstName";
412 $db->array_query( $person_array, $qry, $limit_array );
413 }
414
415 $return_array = array();
416 foreach ( $person_array as $personItem )
417 {
418 $return_array[] = new eZPerson( $personItem[$db->fieldName( "ID" )] );
419 }
420 return $return_array;
421 }
422
426 static public function search( $query )
427 {
428 $db =& eZDB::globalDatabase();
429 $person_array = 0;
430 $return_array = array();
431
432 $query = $db->escapeString( strtolower( $query ) );
433
434 $queryString = "SELECT PersonID FROM eZContact_PersonIndex
435 WHERE Value LIKE '%$query%'
436 GROUP BY PersonID;";
437
438 $db->array_query( $person_array, $queryString );
439
440 foreach ( $person_array as $personItem )
441 {
442 $return_array[] = new eZPerson( $personItem[$db->fieldName( "PersonID" )] );
443 }
444 return $return_array;
445 }
446
450 function addresses()
451 {
452 $return_array = array();
453 $db =& eZDB::globalDatabase();
454
455 $PersonID = $this->ID;
456
457
458 $db->array_query( $address_array, "SELECT PAD.AddressID
459 FROM eZContact_PersonAddressDict AS PAD,
460 eZAddress_Address AS A,
461 eZAddress_AddressType AS AT
462 WHERE PAD.AddressID = A.ID
463 AND A.AddressTypeID = AT.ID
464 AND PAD.PersonID='$PersonID'
465 AND AT.Removed=0" );
466
467 foreach ( $address_array as $addressItem )
468 {
469 $return_array[] = new eZAddress( $addressItem[ $db->fieldName( "AddressID" ) ] );
470 }
471
472 return $return_array;
473 }
474
478 function addAddress( $address )
479 {
480 $ret = false;
481
482 $db =& eZDB::globalDatabase();
483 if ( is_a( $address, "eZAddress" ) )
484 {
485 $addressID = $address->id();
486
487 $checkQuery = "SELECT PersonID FROM eZContact_PersonAddressDict WHERE AddressID='$addressID'";
488
489 $db->array_query( $address_array, $checkQuery );
490
491 $count = count( $address_array );
492
493 if ( $count == 0 )
494 {
495 $db->begin();
496 $res[] = $db->query( "INSERT INTO eZContact_PersonAddressDict
497 (PersonID, AddressID)
498 VALUES
499 ('$this->ID', '$addressID')" );
500 eZDB::finish( $res, $db );
501 }
502 $ret = true;
503 }
504 return $ret;
505 }
506
510 function removeAddresses()
511 {
512 $db =& eZDB::globalDatabase();
513 $db->array_query( $address_array, "SELECT AddressID FROM eZContact_PersonAddressDict
514 WHERE PersonID='$this->ID'" );
515 foreach ( $address_array as $address )
516 {
517 $id = $address[ $db->fieldName( "AddressID" ) ];
518 eZAddress::delete( $id );
519 }
520 $db->begin();
521 $res[] = $db->query( "DELETE FROM eZContact_PersonAddressDict WHERE PersonID='$this->ID'" );
522 eZDB::finish( $res, $db );
523 }
524
528 function phones( $personID = false )
529 {
530 if ( !is_numeric( $personID ) )
531 $personID = $this->ID;
532
533 $return_array = array();
534 $db =& eZDB::globalDatabase();
535
536 $PersonID = $this->ID;
537
538 $db->array_query( $phone_array, "SELECT PPD.PhoneID
539 FROM eZContact_PersonPhoneDict AS PPD, eZAddress_Phone AS P,
540 eZAddress_PhoneType AS PT
541 WHERE PPD.PhoneID = P.ID AND P.PhoneTypeID = PT.ID
542 AND PersonID='$PersonID' AND PT.Removed=0" );
543
544 foreach ( $phone_array as $phoneItem )
545 {
546 $return_array[] = new eZPhone( $phoneItem[$db->fieldName( "PhoneID" )] );
547 }
548
549 return $return_array;
550 }
551
555 function addPhone( $phone )
556 {
557 $ret = false;
558
559 $db =& eZDB::globalDatabase();
560 if ( is_a( $phone, "eZPhone" ) )
561 {
562 $phoneID = $phone->id();
563
564 $checkQuery = "SELECT PersonID FROM eZContact_PersonPhoneDict WHERE PhoneID='$phoneID'";
565
566 $db->array_query( $phone_array, $checkQuery );
567
568 $count = count( $phone_array );
569 if ( $count == 0 )
570 {
571 $phoneno = strtolower( $phone->number() );
572 $db->begin();
573 $res[] = $db->query( "INSERT INTO eZContact_PersonPhoneDict
574 (PersonID, PhoneID)
575 VALUES
576 ('$this->ID', '$phoneID')" );
577 $res[] = $db->query( "INSERT INTO eZContact_PersonIndex
578 (PersonID, Value, Type)
579 VALUES
580 ('$this->ID', '$phoneno', '1')" );
581 eZDB::finish( $res, $db );
582 }
583
584 $ret = true;
585 }
586 return $ret;
587 }
588
592 function removePhones()
593 {
594 $db =& eZDB::globalDatabase();
595 $db->array_query( $phone_array, "SELECT PhoneID FROM
596 eZContact_PersonPhoneDict WHERE PersonID='$this->ID'" );
597 foreach ( $phone_array as $phone )
598 {
599 $id = $phone[ $db->fieldName( "PhoneID" ) ];
600 eZPhone::delete( $id );
601 }
602 $db->begin();
603 $res[] = $db->query( "DELETE FROM eZContact_PersonPhoneDict WHERE PersonID='$this->ID'" );
604 $res[] = $db->query( "DELETE FROM eZContact_PersonIndex WHERE PersonID='$this->ID' AND Type='1'" );
605 eZDB::finish( $res, $db );
606 }
607
611 function onlines()
612 {
613 $return_array = array();
614 $db =& eZDB::globalDatabase();
615
616 $PersonID = $this->ID;
617
618 $db->array_query( $online_array, "SELECT POD.OnlineID
619 FROM eZContact_PersonOnlineDict AS POD, eZAddress_Online AS O,
620 eZAddress_OnlineType AS OT
621 WHERE POD.OnlineID = O.ID AND O.OnlineTypeID = OT.ID
622 AND PersonID='$PersonID' AND OT.Removed=0" );
623
624 foreach ( $online_array as $onlineItem )
625 {
626 $return_array[] = new eZOnline( $onlineItem[$db->fieldName( "OnlineID" )] );
627 }
628
629 return $return_array;
630 }
631
635 function removeOnlines()
636 {
637 $db =& eZDB::globalDatabase();
638 $db->array_query( $online_array, "SELECT OnlineID FROM eZContact_PersonOnlineDict
639 WHERE PersonID='$this->ID'" );
640 foreach ( $online_array as $online )
641 {
642 $id = $online[$db->fieldName( "OnlineID" )];
643 eZOnline::delete( $id );
644 }
645 $db->begin();
646 $res[] = $db->query( "DELETE FROM eZContact_PersonOnlineDict WHERE PersonID='$this->ID'" );
647 $res[] = $db->query( "DELETE FROM eZContact_PersonIndex WHERE PersonID='$this->ID' AND Type='2'" );
648 eZDB::finish( $res, $db );
649
650 }
651
655 function emailAddress()
656 {
657 $onlines = $this->onlines();
658 if ( count( $onlines ) >= 1 )
659 {
660 $found_mail = false;
661 foreach ( $onlines as $online )
662 {
663 if ( $online->urlType() == "mailto" )
664 {
665 return $online->url();
666 }
667 }
668 }
669 return false;
670 }
671
675 function workPhone()
676 {
677 $phones = $this->phones( 0 );
678 if ( count( $phones ) >= 1 )
679 {
680 foreach ( $phones as $phone )
681 {
682 /* FIXME please, don't use contants!!! */
683 if ( $phone->phoneTypeID() == 4 ) // 4 = Work phone
684 {
685 return $phone->number();
686 }
687 }
688 }
689 return false;
690 }
691
695 function faxPhone()
696 {
697 $phones = $this->phones( 0 );
698 if ( count( $phones ) >= 1 )
699 {
700 foreach ( $phones as $phone )
701 {
702 /* FIXME please, don't use contants!!! */
703 if ( $phone->phoneTypeID() == 8 ) // 4 = Fax
704 {
705 return $phone->number();
706 }
707 }
708 }
709 return false;
710 }
711
716 function hasTitle( $companyID )
717 {
718 $db =& eZDB::globalDatabase();
719 $checkQuery = "SELECT Title FROM eZContact_CompanyPersonDict
720 WHERE CompanyID='$companyID' and PersonID='$this->ID'";
721
722 $title_array = array();
723
724 $db->array_query( $title_array, $checkQuery );
725
726 return count( $title_array ) > 0;
727 }
728
733 function title( $companyID )
734 {
735 $ret = false;
736
737 $db =& eZDB::globalDatabase();
738 $checkQuery = "SELECT Title FROM eZContact_CompanyPersonDict
739 WHERE CompanyID='$companyID' and PersonID='$this->ID'";
740
741 $title_array = array();
742
743 $db->array_query( $title_array, $checkQuery );
744
745 $title = false;
746
747 if ( count( $title_array ) == 1 )
748 {
749 $title = $title_array[0][$db->fieldName( "Title" )];
750 }
751 else
752 {
753 die( "eZPerson::title(): Found " . count( $title_array ) . " titles, expected 1" );
754 }
755 return $title;
756 }
757
761 function addOnline( $online )
762 {
763 $ret = false;
764
765 $db =& eZDB::globalDatabase();
766
767 if ( is_a( $online, "eZOnline" ) )
768 {
769 $onlineID = $online->id();
770
771 $checkQuery = "SELECT PersonID FROM eZContact_PersonOnlineDict WHERE OnlineID='$onlineID'";
772
773 $db->array_query( $online_array, $checkQuery );
774 $count = count( $online_array );
775
776 if ( $count == 0 )
777 {
778 $url = strtolower( $online->url() );
779 $db->begin();
780 $res[] = $db->query( "INSERT INTO eZContact_PersonOnlineDict
781 (PersonID, OnlineID)
782 VALUES
783 ('$this->ID', '$onlineID')" );
784 $res[] = $db->query( "INSERT INTO eZContact_PersonIndex
785 (PersonID, Value, Type)
786 VALUES
787 ('$this->ID', '$url', '2')" );
788 eZDB::finish( $res, $db );
789 }
790
791 $ret = true;
792 }
793 return $ret;
794 }
795
799 function user()
800 {
801 $return_array = array();
802 $db =& eZDB::globalDatabase();
803
804 $db->array_query( $user_array, "SELECT UserID
805 FROM eZContact_UserPersonDict
806 WHERE PersonID='$this->ID'" );
807
808 foreach ( $user_array as $userItem )
809 {
810 $return_array[] = new eZUser( $userItem[ $db->fieldName( "UserID" ) ] );
811 }
812
813 return $return_array;
814 }
815
819 function addUser( $user )
820 {
821 $ret = false;
822
823 $db =& eZDB::globalDatabase();
824
825 if ( is_a( $user, "eZUser" ) )
826 {
827 $userID = $user->id();
828
829 $checkQuery = "SELECT PersonID FROM eZContact_UserPersonDict WHERE UserID=$userID";
830 $db->array_query( $user_array, $checkQuery );
831
832 $count = count( $user_array );
833
834 if ( $count == 0 )
835 {
836 $db->begin();
837 $res[] = $db->query( "INSERT INTO eZContact_UserPersonDict
838 (PersonID, UserID)
839 VALUES
840 ('$this->ID', '$userID')" );
841 eZDB::finish( $res, $db );
842 }
843 $ret = true;
844 }
845 return $ret;
846 }
847
851 function setFirstName( $value )
852 {
853 $this->FirstName = $value;
854 }
855
859 function setLastName( $value )
860 {
861 $this->LastName = $value;
862 }
863
867 function setComment( $value )
868 {
869 $this->Comment = $value;
870 }
871
875 function setContact( $value )
876 {
877 $this->ContactType = $value;
878 }
879
883 function setBirthDay( $value )
884 {
885 $this->BirthDate = $value;
886 }
887
891 function setNoBirthDay()
892 {
893 unset( $this->BirthDate );
894 }
895
899 function id()
900 {
901 return $this->ID;
902 }
903
907 function name()
908 {
909 return $this->firstName() . " " . $this->lastName();
910 }
911
915 function firstName()
916 {
917 return $this->FirstName;
918 }
919
923 function lastName()
924 {
925 return $this->LastName;
926 }
927
931 function fullName()
932 {
933 return $this->FirstName . " " . $this->LastName;
934 }
935
939 function comment()
940 {
941 return $this->Comment;
942 }
943
947 function contact()
948 {
949 return $this->ContactType;
950 }
951
955 function projectState()
956 {
957 $ret = "";
958
959 $db =& eZDB::globalDatabase();
960
961 $checkQuery = "SELECT ProjectID FROM eZContact_PersonProjectDict WHERE PersonID='$this->ID'";
962 $db->array_query( $array, $checkQuery, 0, 1 );
963
964 if ( count( $array ) == 1 )
965 {
966 $ret = $array[0][ $db->fieldName( "ProjectID" ) ];
967 }
968
969 return $ret;
970 }
971
975 public function setProjectState( $value, $id = false )
976 {
977 if ( !$id )
978 $id = $this->ID;
979 $db =& eZDB::globalDatabase();
980 $db->begin();
981
982 $res[] = $db->query( "DELETE FROM eZContact_PersonProjectDict WHERE PersonID='$id'" );
983
984 if ( is_numeric( $value ) )
985 {
986 if ( $value > 0 )
987 {
988 $checkQuery = "INSERT INTO eZContact_PersonProjectDict
989 (PersonID, ProjectID)
990 VALUES
991 ('$id', '$value')";
992 $res[] = $db->query( $checkQuery );
993 }
994 }
995 eZDB::finish( $res, $db );
996 }
997
1001 function birthDate()
1002 {
1003 return $this->BirthDate;
1004 }
1005
1009 function hasBirthDate()
1010 {
1011 return isset( $this->BirthDate );
1012 }
1013
1014 function removeCompanies( $id = false )
1015 {
1016 if ( !$id )
1017 $id = $this->ID;
1018
1019 $db =& eZDB::globalDatabase();
1020 $res[] = $db->query( "DELETE FROM eZContact_CompanyPersonDict
1021 WHERE PersonID='$id'" );
1022 eZDB::finish( $res, $db );
1023 }
1024
1028 static public function companies( $id = false, $as_object = true )
1029 {
1030 if ( !$id )
1031 $id = 0;
1032
1033 $db =& eZDB::globalDatabase();
1034 $db->array_query( $arr,
1035 "SELECT CPD.CompanyID
1036 FROM eZContact_CompanyPersonDict AS CPD, eZContact_Company AS C
1037 WHERE CPD.PersonID='$id' AND CPD.CompanyID=C.ID
1038 ORDER BY C.Name" );
1039 $ret = array();
1040 if ( $as_object )
1041 {
1042 foreach ( $arr as $row )
1043 {
1044 $ret[] = new eZCompany( $row[ $db->fieldName( "CompanyID" ) ] );
1045 }
1046 }
1047 else
1048 {
1049 foreach ( $arr as $row )
1050 {
1051 $ret[] = $row[ $db->fieldName( "CompanyID" ) ];
1052 }
1053 }
1054 return $ret;
1055 }
1056
1062 function setImage( &$image, $id = false )
1063 {
1064 if ( !$id )
1065 $id = $this->ID;
1066
1067 if ( is_a( $image, "eZImage" ) )
1068 {
1069 $db =& eZDB::globalDatabase();
1070 $db->begin();
1071
1072 $imageID =& $image->id();
1073 $this->ImageID = $imageID;
1074
1075 $db->array_query( $res_array, "SELECT COUNT(*) AS Number FROM eZContact_PersonImageDefinition
1076 WHERE PersonID='$id'" );
1077
1078 if ( $res_array[0][ $db->fieldName( "Number" ) ] == "1" )
1079 {
1080 $res[] = $db->query( "UPDATE eZContact_PersonImageDefinition
1081 SET
1082 LogoImageID='$imageID'
1083 WHERE
1084 PersonID='$id'" );
1085 }
1086 else
1087 {
1088 $res[] = $db->query( "INSERT INTO eZContact_PersonImageDefinition
1089 (PersonID, LogoImageID)
1090 VALUES
1091 ('$id', '$imageID')" );
1092 }
1093 eZDB::finish( $res, $db );
1094 }
1095 }
1096
1100 static public function &image( $id = false )
1101 {
1102 if ( !$id )
1103 $id = 0;
1104
1105 $ret = false;
1106 $db =& eZDB::globalDatabase();
1107
1108 $db->array_query( $res_array, "SELECT * FROM eZContact_PersonImageDefinition
1109 WHERE PersonID='$id'" );
1110
1111 if ( count( $res_array ) == 1 )
1112 {
1113 if ( $res_array[0][$db->fieldName( "LogoImageID" )] != "NULL"
1114 and $res_array[0][$db->fieldName( "LogoImageID" )] != "0" )
1115 {
1116 $ret = new eZImage( $res_array[0][$db->fieldName( "LogoImageID" )], false );
1117 }
1118 }
1119 return $ret;
1120 }
1121
1125 function removeImage( $id = false )
1126 {
1127 if ( !$id )
1128 $id = $this->ID;
1129
1130 $db =& eZDB::globalDatabase();
1131 $db->begin();
1132 $res[] = $db->query( "UPDATE eZContact_PersonImageDefinition
1133 SET PersonImageID='0' WHERE PersonID='$id'" );
1134 eZDB::finish( $res, $db );
1135 }
1136
1137
1138 var $ID;
1139 var $FirstName;
1140 var $LastName;
1141 var $BirthDate;
1142 var $ContactType;
1143 var $Comment;
1144 var $ImageID;
1145 };
1146
1147 ?>
$userID
else $userID
Definition: appointmentedit.php:121
$address
$address
Definition: checkout.php:588
eZAddress
Definition: ezaddress.php:42
eZAddress\delete
static delete( $id=false)
Definition: ezaddress.php:176
eZCompany
Definition: ezcompany.php:54
eZDB\finish
static finish(&$resultArray, &$db)
Definition: ezdb.php:204
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZImage
Definition: ezimage.php:95
eZOrder
Definition: ezorder.php:52
eZPerson
Definition: ezperson.php:43
eZPerson\$LastName
$LastName
Definition: ezperson.php:1140
eZPerson\projectState
projectState()
Definition: ezperson.php:955
eZPerson\setProjectState
setProjectState( $value, $id=false)
Definition: ezperson.php:975
eZPerson\getByUserID
getByUserID( $id)
Definition: ezperson.php:234
eZPerson\$BirthDate
$BirthDate
Definition: ezperson.php:1141
eZPerson\contact
contact()
Definition: ezperson.php:947
eZPerson\firstName
firstName()
Definition: ezperson.php:915
eZPerson\$ID
$ID
Definition: ezperson.php:1138
eZPerson\$ImageID
$ImageID
Definition: ezperson.php:1144
eZPerson\removeAddresses
removeAddresses()
Definition: ezperson.php:510
eZPerson\$ContactType
$ContactType
Definition: ezperson.php:1142
eZPerson\hasTitle
hasTitle( $companyID)
Definition: ezperson.php:716
eZPerson\addresses
addresses()
Definition: ezperson.php:450
eZPerson\comment
comment()
Definition: ezperson.php:939
eZPerson\id
id()
Definition: ezperson.php:899
eZPerson\user
user()
Definition: ezperson.php:799
eZPerson\setFirstName
setFirstName( $value)
Definition: ezperson.php:851
eZPerson\addOnline
addOnline( $online)
Definition: ezperson.php:761
eZPerson\setComment
setComment( $value)
Definition: ezperson.php:867
eZPerson\store
store()
Definition: ezperson.php:63
eZPerson\setBirthDay
setBirthDay( $value)
Definition: ezperson.php:883
eZPerson\setNoBirthDay
setNoBirthDay()
Definition: ezperson.php:891
eZPerson\title
title( $companyID)
Definition: ezperson.php:733
eZPerson\setLastName
setLastName( $value)
Definition: ezperson.php:859
eZPerson\name
name()
Definition: ezperson.php:907
eZPerson\lastName
lastName()
Definition: ezperson.php:923
eZPerson\addAddress
addAddress( $address)
Definition: ezperson.php:478
eZPerson\removeImage
removeImage( $id=false)
Definition: ezperson.php:1125
eZPerson\__construct
__construct( $id="")
Definition: ezperson.php:50
eZPerson\setImage
setImage(&$image, $id=false)
Definition: ezperson.php:1062
eZPerson\$Comment
$Comment
Definition: ezperson.php:1143
eZPerson\removePhones
removePhones()
Definition: ezperson.php:592
eZPerson\getAllCount
getAllCount( $search_types="", $cond="all")
Definition: ezperson.php:251
eZPerson\workPhone
workPhone()
Definition: ezperson.php:675
eZPerson\hasBirthDate
hasBirthDate()
Definition: ezperson.php:1009
eZPerson\addUser
addUser( $user)
Definition: ezperson.php:819
eZPerson\birthDate
birthDate()
Definition: ezperson.php:1001
eZPerson\$FirstName
$FirstName
Definition: ezperson.php:1139
eZPerson\fullName
fullName()
Definition: ezperson.php:931
eZPerson\onlines
onlines()
Definition: ezperson.php:611
eZPerson\image
static & image( $id=false)
Definition: ezperson.php:1100
eZPerson\companies
static companies( $id=false, $as_object=true)
Definition: ezperson.php:1028
eZPerson\setContact
setContact( $value)
Definition: ezperson.php:875
eZPerson\removeCompanies
removeCompanies( $id=false)
Definition: ezperson.php:1014
eZPerson\removeOnlines
removeOnlines()
Definition: ezperson.php:635
eZPerson\phones
phones( $personID=false)
Definition: ezperson.php:528
eZPerson\faxPhone
faxPhone()
Definition: ezperson.php:695
eZPerson\emailAddress
emailAddress()
Definition: ezperson.php:655
eZPerson\addPhone
addPhone( $phone)
Definition: ezperson.php:555
eZPerson\getAll
getAll( $search_types="", $limit_index=0, $limit=1, $cond="all")
Definition: ezperson.php:335
eZPerson\search
static search( $query)
Definition: ezperson.php:426
eZPhone
Definition: ezphone.php:39
eZPhone\delete
delete( $id=false)
Definition: ezphone.php:87
eZQuery
Definition: ezquery.php:54
eZUser
Definition: ezuser.php:76
$id
$id
Definition: companytypelist.php:193
$persons
$persons
Definition: companyview.php:386
$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
$user_array
while( $tmpTime->isGreater( $stopTime)) $user_array
Definition: ezcalendar/user/dayview.php:495
$row
$row
Definition: ezcalendar/user/dayview.php:403
$limit_array
$limit_array
Definition: ezforum/user/messagelist.php:184
$limit
$limit
Definition: ezimagecatalogue/admin/imagelist.php:312
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$res
$res
Definition: ezstats/admin/cron.php:45
$url
$url
Definition: messagereviewlist.php:153
$count
$count
Definition: onlinetypelist.php:108
$order
$order
Definition: productreport.php:182
$user
$user
Definition: user/adlist.php:39
$image
$image
Definition: user/articlelist.php:242
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.