Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezcompany.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezcompany.php 9529 2002-05-14 11:17:05Z jhe $
5 //
6 // Definition of eZProduct 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
44 //require "ezphputils.php";
45
46 // include_once( "ezaddress/classes/ezaddress.php" );
47 // include_once( "ezcontact/classes/ezcompanytype.php" );
48 // include_once( "ezaddress/classes/ezphone.php" );
49 // include_once( "classes/ezimagefile.php" );
50 // include_once( "ezimagecatalogue/classes/ezimage.php" );
51 // include_once( "classes/ezdate.php" );
52
53 class eZCompany
54 {
61 function __construct( $id= -1 )
62 {
63 $this->CreatorID = 0;
64
65 if ( is_numeric( $id ) and $id > -1 )
66 {
67 $this->ID = $id;
68 $this->get( $this->ID );
69 }
70 }
71
75 function store()
76 {
77 $db =& eZDB::globalDatabase();
78 $db->begin();
79
80 $name = $db->escapeString( $this->Name );
81 $comment = $db->escapeString( $this->Comment );
82 $type = $this->ContactType == "ezperson" ? 2 : 1;
83
84 if ( !isset( $this->ID ) or !is_numeric( $this->ID ) )
85 {
86 $db->lock( "eZContact_Company" );
87 $this->ID = $db->nextID( "eZContact_Company", "ID" );
88 $res[] = $db->query( "INSERT INTO eZContact_Company
89 (ID,
90 Name,
91 Comment,
92 CompanyNo,
93 ContactID,
94 ContactType,
95 CreatorID)
96 VALUES
97 ('$this->ID',
98 '$name',
99 '$comment',
100 '$this->CompanyNo',
101 '$this->ContactID',
102 '$type',
103 '$this->CreatorID')" );
104 $db->unlock();
105 $name = strtolower( $name );
106 $res[] = $db->query( "INSERT INTO eZContact_CompanyIndex
107 (CompanyID, Value, Type)
108 VALUES
109 ('$this->ID', '$name', '0')" );
110 }
111 else
112 {
113 $res[] = $db->query( "UPDATE eZContact_Company SET
114 Name='$name',
115 Comment='$comment',
116 CompanyNo='$this->CompanyNo',
117 ContactID='$this->ContactID',
118 ContactType='$type',
119 CreatorID='$this->CreatorID'
120 WHERE ID='$this->ID'" );
121 $name = strtolower( $name );
122 $res[] = $db->query( "UPDATE eZContact_CompanyIndex SET
123 Value='$name'
124 WHERE CompanyID='$this->ID' AND Type='0'" );
125 }
126 eZDB::finish( $res, $db );
127
128 return true;
129 }
130
134 function delete( $id = false )
135 {
136 $db =& eZDB::globalDatabase();
137
138 if ( !$id )
139 $id = $this->ID;
140
141 $db->begin();
142 if ( isset( $id ) && is_numeric( $id ) )
143 {
144 // Delete real world addresses
145
146 $db->array_query( $address_array, "SELECT eZContact_CompanyAddressDict.AddressID AS DID
147 FROM eZAddress_Address, eZContact_CompanyAddressDict
148 WHERE eZAddress_Address.ID=eZContact_CompanyAddressDict.AddressID
149 AND eZContact_CompanyAddressDict.CompanyID='$id' " );
150
151 foreach ( $address_array as $addressItem )
152 {
153 $addressDictID = $addressItem[ $db->fieldName( "DID" ) ];
154 eZAddress::delete( $addressDictID );
155 }
156
157 $res[] = $db->query( "DELETE FROM eZContact_CompanyAddressDict WHERE CompanyID='$id'" );
158
159 // Delete phone numbers.
160
161 $db->array_query( $phone_array, "SELECT eZContact_CompanyPhoneDict.PhoneID AS DID
162 FROM eZAddress_Phone, eZContact_CompanyPhoneDict
163 WHERE eZAddress_Phone.ID=eZContact_CompanyPhoneDict.PhoneID
164 AND eZContact_CompanyPhoneDict.CompanyID='$id' " );
165
166 foreach ( $phone_array as $phoneItem )
167 {
168 $phoneDictID = $phoneItem[ $db->fieldName( "DID" ) ];
169 eZPhone::delete( $phoneDictID );
170 }
171 $res[] = $db->query( "DELETE FROM eZContact_CompanyPhoneDict WHERE CompanyID='$id'" );
172
173 // Delete online address.
174
175 $db->array_query( $online_array, "SELECT eZContact_CompanyOnlineDict.OnlineID AS DID
176 FROM eZAddress_Online, eZContact_CompanyOnlineDict
177 WHERE eZAddress_Online.ID=eZContact_CompanyOnlineDict.OnlineID
178 AND eZContact_CompanyOnlineDict.CompanyID='$id' " );
179
180 foreach ( $online_array as $onlineItem )
181 {
182 $onlineDictID = $onlineItem[ $db->fieldName( "DID" ) ];
183 eZPhone::delete( $onlineDictID );
184 }
185
186 $res[] = $db->query( "DELETE FROM eZContact_CompanyOnlineDict WHERE CompanyID='$id'" );
187 $res[] = $db->query( "DELETE FROM eZContact_CompanyTypeDict WHERE CompanyID='$id'" );
188 $res[] = $db->query( "DELETE FROM eZContact_Company WHERE ID='$id'" );
189 $res[] = $db->query( "DELETE FROM eZContact_CompanyPersonDict WHERE CompanyID='$id'" );
190 $res[] = $db->query( "DELETE FROM eZContact_CompanyIndex WHERE CompanyID='$id'" );
191 $db->array_query( $res_array, "SELECT ID FROM eZTrade_Order WHERE CompanyID='$id'" );
192 // include_once( "eztrade/classes/ezorder.php" );
193 foreach ( $res_array as $order )
194 {
195 $orderObject = new eZOrder( $order[$db->fieldName( "ID" )] );
196 $orderObject->delete();
197 }
198 }
199 eZCompany::removePersons( $id );
200 eZDB::finish( $res, $db );
201
202 return true;
203 }
204
205
209 function get( $id = -1 )
210 {
211 $db =& eZDB::globalDatabase();
212 $ret = false;
213
214 if ( $id != "" )
215 {
216 $db->array_query( $company_array, "SELECT * FROM eZContact_Company WHERE ID='$id'" );
217 if ( count( $company_array ) > 1 )
218 {
219 die( "Error: More than one company with the same id was found. " );
220 }
221 elseif ( count( $company_array ) == 1 )
222 {
223 $this->ID = $company_array[0][$db->fieldName( "ID" )];
224 $this->Name = $company_array[0][$db->fieldName( "Name" )];
225 $this->Comment = $company_array[0][$db->fieldName( "Comment" )];
226 $this->CreatorID = $company_array[0][$db->fieldName( "CreatorID" )];
227 $this->CompanyNo = $company_array[0][$db->fieldName( "CompanyNo" )];
228 $this->ContactID = $company_array[0][$db->fieldName( "ContactID" )];
229 $type = $company_array[0][$db->fieldName( "ContactType" )];
230 $this->ContactType = $type == 2 ? "ezperson" : "ezuser";
231 $ret = true;
232 }
233 }
234 return $ret;
235 }
236
241 static public function exists( $id )
242 {
243 $db =& eZDB::globalDatabase();
244 $ret = false;
245 $db->array_query( $qry_array, "SELECT ID FROM eZContact_Company WHERE ID='$id'", 0, 1 );
246 if ( count( $qry_array ) == 1 )
247 $ret = true;
248 return $ret;
249 }
250
256 function &getAll( )
257 {
258 $db =& eZDB::globalDatabase();
259
260 $company_array = array();
261 $return_array = array();
262
263 $db->array_query( $company_array, "SELECT ID FROM eZContact_Company ORDER BY Name" );
264
265 foreach ( $company_array as $companyItem )
266 {
267 $return_array[] = new eZCompany( $companyItem[$db->fieldName( "ID" )] );
268 }
269 return $return_array;
270 }
271
277 function &getByCategory( $categoryID, $offset = 0, $limit = -1, $order = "name" )
278 {
279 $db =& eZDB::globalDatabase();
280
281 $company_array = array();
282 $return_array = array();
283 $limit_array = array();
284
285 if ( $limit > 0 )
286 {
287 $limit_array = array( "Limit" => $limit, "Offset" => $offset );
288 }
289
290 $dir = "ASC";
291 if ( $order[0] == "-" )
292 {
293 $order = substr( $order, 1 );
294 $dir = "DESC";
295 }
296 else if ( $order[0] == "+" )
297 {
298 $order = substr( $order, 1 );
299 $dir = "ASC";
300 }
301 switch ( $order )
302 {
303 default:
304 print( "<br /><b>Unknown order type in eZCompany::getByCategory(), got \"$order\"</b><br />" );
305 case "name":
306 {
307 $order_text = "Name";
308 break;
309 }
310 case "id":
311 {
312 $order_text = "ID";
313 break;
314 }
315 }
316
317 $db->array_query( $company_array, "SELECT CompanyID FROM eZContact_CompanyTypeDict, eZContact_Company
318 WHERE eZContact_CompanyTypeDict.CompanyTypeID='$categoryID'
319 AND eZContact_Company.ID = eZContact_CompanyTypeDict.CompanyID
320 ORDER BY eZContact_Company.$order_text $dir", $limit_array );
321
322 foreach ( $company_array as $companyItem )
323 {
324 $return_array[] = new eZCompany( $companyItem[$db->fieldName( "CompanyID" )] );
325 }
326
327 return $return_array;
328 }
329
335 function countByCategory( $categoryID )
336 {
337 $db =& eZDB::globalDatabase();
338 $db->query_single( $company_array,
339 "SELECT count( CompanyID ) as Count
340 FROM eZContact_CompanyTypeDict, eZContact_Company
341 WHERE eZContact_CompanyTypeDict.CompanyTypeID='$categoryID'
342 AND eZContact_Company.ID = eZContact_CompanyTypeDict.CompanyID" );
343
344 return $company_array[$db->fieldName( "Count" )];
345 }
346
350 function &searchByCategory( $categoryID, $query )
351 {
352 $db =& eZDB::globalDatabase();
353
354 $query = $db->escapeString( $query );
355
356 $company_array = array();
357 $return_array = array();
358 if ( !empty( $query ) )
359 {
360 $db->array_query( $company_array, "
361 SELECT
362 Comp.ID
363 FROM
364 eZContact_CompanyTypeDict as Dict,
365 eZContact_Company as Comp
366 WHERE
367 Comp.Name LIKE '%$query%'
368 AND
369 Dict.CompanyTypeID = '$categoryID'
370 AND
371 Comp.ID = Dict.CompanyID
372 ORDER BY Name" );
373
374 foreach ( $company_array as $companyItem )
375 {
376 $return_array[] = new eZCompany( $companyItem[$db->fieldName( "ID" )] );
377 }
378 }
379 return $return_array;
380 }
381
382
386 public static function &search( $query )
387 {
388 $db =& eZDB::globalDatabase();
389
390 $query = $db->escapeString( strtolower( $query ) );
391
392 $company_array = array();
393 $return_array = array();
394
395 $queryString = "SELECT CompanyID FROM eZContact_CompanyIndex
396 WHERE (Value LIKE '%$query%')
397 GROUP BY CompanyID";
398
399 $db->array_query( $company_array, $queryString );
400
401 foreach ( $company_array as $companyItem )
402 {
403 $return_array[] = new eZCompany( $companyItem[$db->fieldName( "CompanyID" )] );
404 }
405 return $return_array;
406 }
407
408
412 function removeCategories()
413 {
414 $db =& eZDB::globalDatabase();
415 $db->begin();
416
417 $res[] = $db->query( "DELETE FROM eZContact_CompanyTypeDict
418 WHERE CompanyID='$this->ID'" );
419 eZDB::finish( $res, $db );
420 }
421
425 function categories( $companyID = false, $as_object = true, $limit = -1 )
426 {
427 if ( !$companyID )
428 $companyID = $this->ID;
429
430 $return_array = array();
431 $db =& eZDB::globalDatabase();
432
433 if ( $limit != -1 )
434 {
435 $limit_array = array( "Limit" => $limit );
436 }
437
438 $db->array_query( $categories_array, "SELECT CompanyTypeID
439 FROM eZContact_CompanyTypeDict
440 WHERE CompanyID='$companyID'",
441 $limit );
442
443 foreach ( $categories_array as $categoriesItem )
444 {
445 if ( $as_object )
446 $return_array[] = new eZCompanyType( $categoriesItem[$db->fieldName( "CompanyTypeID" )] );
447 else
448 $return_array[] =& $categoriesItem[$db->fieldName( "CompanyTypeID" )];
449 }
450 return $return_array;
451 }
452
453
457 function &addresses( $companyID = false )
458 {
459 if ( !$companyID )
460 $companyID = $this->ID;
461
462 $return_array = array();
463 $db =& eZDB::globalDatabase();
464
465 $db->array_query( $address_array, "SELECT CAD.AddressID
466 FROM eZContact_CompanyAddressDict AS CAD, eZAddress_Address AS A,
467 eZAddress_AddressType as AT
468 WHERE CAD.AddressID = A.ID AND A.AddressTypeID = AT.ID
469 AND CAD.CompanyID='$companyID' AND AT.Removed=0" );
470
471 foreach ( $address_array as $addressItem )
472 {
473 $return_array[] = new eZAddress( $addressItem[$db->fieldName( "AddressID" )] );
474 }
475
476 return $return_array;
477 }
478
482 function addAddress( &$address )
483 {
484 $ret = false;
485 $db =& eZDB::globalDatabase();
486 if ( is_a( $address, "eZAddress" ) )
487 {
488 $addressID = $address->id();
489 $db->begin();
490
491 $res[] = $db->query( "INSERT INTO eZContact_CompanyAddressDict
492 (CompanyID, AddressID)
493 VALUES
494 ('$this->ID', '$addressID')" );
495 eZDB::finish( $res, $db );
496
497 $ret = true;
498 }
499 return $ret;
500 }
501
505 function removeAddresses()
506 {
507 $db =& eZDB::globalDatabase();
508
509 $db->array_query( $address_array, "SELECT AddressID FROM eZContact_CompanyAddressDict
510 WHERE CompanyID='$this->ID' " );
511
512 foreach ( $address_array as $addressItem )
513 {
514 $addressID =& $addressItem[$db->fieldName( "AddressID" )];
515 eZAddress::delete( $addressID );
516 }
517 $db->begin();
518 $res[] = $db->query( "DELETE FROM eZContact_CompanyAddressDict WHERE CompanyID='$this->ID'" );
519 eZDB::finish( $res, $db );
520 }
521
525 function &phones( $companyID = false )
526 {
527 if ( !$companyID )
528 $companyID = $this->ID;
529
530 $return_array = array();
531 $db =& eZDB::globalDatabase();
532
533 $db->array_query( $phone_array, "SELECT CPD.PhoneID
534 FROM eZContact_CompanyPhoneDict AS CPD, eZAddress_Phone AS P,
535 eZAddress_PhoneType AS PT
536 WHERE CPD.PhoneID = P.ID AND P.PhoneTypeID = PT.ID
537 AND CPD.CompanyID='$companyID' AND PT.Removed=0" );
538
539 foreach ( $phone_array as $phoneItem )
540 {
541 $return_array[] = new eZPhone( $phoneItem[$db->fieldName( "PhoneID" )] );
542 }
543
544 return $return_array;
545 }
546
550 function addPhone( &$phone )
551 {
552 $ret = false;
553 $db =& eZDB::globalDatabase();
554 $db->begin();
555 if ( is_a( $phone, "eZPhone" ) )
556 {
557 $phoneID =& $phone->id();
558 $phoneno = strtolower( $phone->number() );
559
560 $res[] = $db->query( "INSERT INTO eZContact_CompanyPhoneDict
561 (CompanyID, PhoneID)
562 VALUES
563 ('$this->ID', '$phoneID')" );
564
565 $res[] = $db->query( "INSERT INTO eZContact_CompanyIndex
566 (CompanyID, Value, Type)
567 VALUES
568 ('$this->ID', '$phoneno', '1')" );
569 $ret = true;
570 }
571 eZDB::finish( $res, $db );
572 return $ret;
573 }
574
578 function removePhones()
579 {
580 $db =& eZDB::globalDatabase();
581 $db->begin();
582 $db->array_query( $phone_array, "SELECT PhoneID FROM
583 eZContact_CompanyPhoneDict WHERE CompanyID='$this->ID' " );
584
585 foreach ( $phone_array as $phoneItem )
586 {
587 $phoneID =& $phoneItem[$db->fieldName( "PhoneID" )];
588 eZPhone::delete( $phoneID );
589 }
590 $res[] = $db->query( "DELETE FROM eZContact_CompanyPhoneDict WHERE CompanyID='$this->ID'" );
591 $res[] = $db->query( "DELETE FROM eZContact_CompanyIndex WHERE CompanyID='$this->ID' AND Type='1'" );
592 eZDB::finish( $res, $db );
593 }
594
598 function &onlines( $onlineID = false )
599 {
600 if ( !$onlineID )
601 $onlineID = $this->ID;
602
603 $return_array = array();
604 $db =& eZDB::globalDatabase();
605
606 $db->array_query( $online_array, "SELECT COD.OnlineID
607 FROM eZContact_CompanyOnlineDict AS COD, eZAddress_Online AS O,
608 eZAddress_OnlineType AS OT
609 WHERE COD.OnlineID = O.ID AND O.OnlineTypeID = OT.ID
610 AND COD.CompanyID='$this->ID' AND OT.Removed=0" );
611
612 foreach ( $online_array as $onlineItem )
613 {
614 $return_array[] = new eZOnline( $onlineItem[$db->fieldName( "OnlineID" )] );
615 }
616
617 return $return_array;
618 }
619
623 function addOnline( &$online )
624 {
625 $ret = false;
626 $db =& eZDB::globalDatabase();
627 $db->begin();
628
629 if ( is_a( $online, "eZOnline" ) )
630 {
631 $onlineID =& $online->id();
632 $url = strtolower( $online->url() );
633 $res[] = $db->query( "INSERT INTO eZContact_CompanyOnlineDict
634 (CompanyID, OnlineID)
635 VALUES
636 ('$this->ID', '$onlineID')" );
637 $res[] = $db->query( "INSERT INTO eZContact_CompanyIndex
638 (CompanyID, Value, Type)
639 VALUES
640 ('$this->ID', '$url', '2')" );
641 $ret = true;
642 }
643 eZDB::finish( $res, $db );
644 return $ret;
645 }
646
650 function removeOnlines()
651 {
652 $db =& eZDB::globalDatabase();
653 $db->begin();
654 $db->array_query( $online_array, "SELECT OnlineID FROM eZContact_CompanyOnlineDict
655 WHERE CompanyID='$this->ID' " );
656
657 foreach ( $online_array as $onlineItem )
658 {
659 $onlineID =& $onlineItem[$db->fieldName( "OnlineID" )];
660 eZOnline::delete( $onlineID );
661 }
662
663 $res[] = $db->query( "DELETE FROM eZContact_CompanyOnlineDict WHERE CompanyID='$this->ID'" );
664 $res[] = $db->query( "DELETE FROM eZContact_CompanyIndex WHERE CompanyID='$this->ID' AND Type='2'" );
665 eZDB::finish( $res, $db );
666 }
667
671 function addImage( &$image )
672 {
673 $ret = false;
674 $db =& eZDB::globalDatabase();
675 $db->begin();
676 if ( is_a( $image, "eZImage" ) )
677 {
678 $imageID =& $image->id();
679
680 $res[] = $db->query( "INSERT INTO eZContact_CompanyImageDict
681 (CompanyID, ImageID)
682 VALUES
683 ('$this->ID', '$imageID')" );
684 }
685 eZDB::finish( $res, $db );
686 }
687
691 function &images()
692 {
693 $db =& eZDB::globalDatabase();
694
695 $return_array = array();
696 $image_array = array();
697
698 $db->array_query( $image_array, "SELECT ImageID FROM eZContact_CompanyImageDict WHERE CompanyID='$this->ID'" );
699
700 for ( $i = 0; $i < count( $image_array ); $i++ )
701 {
702 $return_array[$i] = new eZImage( $image_array[$i][$db->fieldName( "ImageID" )], false );
703 }
704
705 return $return_array;
706 }
707
711 function removeImages()
712 {
713 $db =& eZDB::globalDatabase();
714 $db->begin();
715 $res[] = $db->query( "DELETE FROM eZContact_CompanyImageDefinition WHERE CompanyID='$this->ID'" );
716 eZDB::finish( $res, $db );
717 }
718
722 static public function logoImage( $id = false )
723 {
724 if ( !$id )
725 $id = 0;
726
727 $ret = false;
728 $db =& eZDB::globalDatabase();
729
730 $db->array_query( $res_array, "SELECT * FROM eZContact_CompanyImageDefinition
731 WHERE CompanyID='$id'" );
732
733 if ( count( $res_array ) == 1 )
734 {
735 if ( $res_array[0][$db->fieldName( "LogoImageID" )] != "NULL"
736 and $res_array[0][$db->fieldName( "LogoImageID" )] != "0" )
737 {
738 $ret = new eZImage( $res_array[0][$db->fieldName( "LogoImageID" )], false );
739 }
740 }
741 return $ret;
742 }
743
749 function setLogoImage( &$image, $id = false )
750 {
751 if ( !$id )
752 $id = $this->ID;
753
754 if ( is_a( $image, "eZImage" ) )
755 {
756 $db =& eZDB::globalDatabase();
757 $db->begin();
758
759 $imageID =& $image->id();
760
761 $db->array_query( $res_array, "SELECT COUNT(*) AS Number FROM eZContact_CompanyImageDefinition
762 WHERE CompanyID='$id'" );
763
764 if ( $res_array[0][ $db->fieldName( "Number" ) ] == "1" )
765 {
766 $res[] = $db->query( "UPDATE eZContact_CompanyImageDefinition
767 SET
768 LogoImageID='$imageID'
769 WHERE
770 CompanyID='$id'" );
771 }
772 else
773 {
774 $res[] = $db->query( "INSERT INTO eZContact_CompanyImageDefinition
775 (CompanyID, LogoImageID)
776 VALUES
777 ('$id', '$imageID')" );
778 }
779 eZDB::finish( $res, $db );
780 }
781 }
782
786 function deleteImage( $id = false )
787 {
788 if ( !$id )
789 $id = $this->ID;
790
791 $db =& eZDB::globalDatabase();
792 $db->begin();
793 $res[] = $db->query( "UPDATE eZContact_CompanyImageDefinition
794 SET CompanyImageID='0' WHERE CompanyID='$id'" );
795 eZDB::finish( $res, $db );
796 }
797
801 function deleteLogo( $id = false )
802 {
803 if ( !$id )
804 $id = $this->ID;
805 $db =& eZDB::globalDatabase();
806 $db->begin();
807 $res[] = $db->query( "UPDATE eZContact_CompanyImageDefinition
808 SET LogoImageID='0' WHERE CompanyID='$id'" );
809 eZDB::finish( $res, $db );
810 }
811
812
818 function setCompanyImage( &$image, $id = false )
819 {
820 if ( !$id )
821 $id = $this->ID;
822
823 if ( is_a( $image, "eZImage" ) )
824 {
825 $db =& eZDB::globalDatabase();
826 $db->begin();
827
828 $imageID =& $image->id();
829
830 $db->array_query( $res_array, "SELECT COUNT(*) AS Number FROM eZContact_CompanyImageDefinition
831 WHERE CompanyID='$id'" );
832
833 if ( $res_array[0][$db->fieldName( "Number" )] == "1" )
834 {
835 $res[] = $db->query( "UPDATE eZContact_CompanyImageDefinition
836 SET
837 CompanyImageID='$imageID'
838 WHERE
839 CompanyID='$id'" );
840 }
841 else
842 {
843 $res[] = $db->query( "INSERT INTO eZContact_CompanyImageDefinition
844 (CompanyID, CompanyImageID)
845 VALUES
846 ('$id', '$imageID')" );
847 }
848 eZDB::finish( $res, $db );
849 }
850 }
851
852
856 static public function companyImage( $id = false )
857 {
858 if ( !$id )
859 $id = 0;
860 $ret = false;
861 $db =& eZDB::globalDatabase();
862
863 $db->array_query( $res_array, "SELECT * FROM eZContact_CompanyImageDefinition
864 WHERE CompanyID='$id'" );
865
866 if ( count( $res_array ) == 1 )
867 {
868 if ( $res_array[0][$db->fieldName( "CompanyImageID" )] != "NULL"
869 and $res_array[0][$db->fieldName( "CompanyImageID" )] != "0" )
870 {
871 $ret = new eZImage( $res_array[0][$db->fieldName( "CompanyImageID" )], false );
872 }
873 }
874
875 return $ret;
876 }
877
878
882 function setName( $value )
883 {
884 $this->Name = $value;
885 }
886
890 function setComment( $value )
891 {
892 $this->Comment = $value;
893 }
894
898 function setCreatorID( &$user )
899 {
900 if ( is_a( $user, "eZUser" ) )
901 {
902 $userID =& $user->id();
903 $this->CreatorID = $userID;
904 }
905 }
906
910 function setCompanyNo( $value )
911 {
912 $this->CompanyNo = $value;
913 }
914
918 function id()
919 {
920 return $this->ID;
921 }
922
926 function name()
927 {
928 return $this->Name;
929 }
930
934 function creatorID()
935 {
936 return $this->CreatorID;
937 }
938
942 function comment()
943 {
944 return $this->Comment;
945 }
946
950 function companyNo()
951 {
952 return $this->CompanyNo;
953 }
954
955
959 function setContact( $value )
960 {
961 $this->ContactID = $value;
962 $this->ContactType = "ezuser";
963 }
964
968 function contact()
969 {
970 return $this->ContactID;
971 $this->ContactType = "ezuser";
972 }
973
977 function setPersonContact( $value )
978 {
979 $this->ContactID = $value;
980 $this->ContactType = "ezperson";
981 }
982
986 function contactType()
987 {
988 return $this->ContactType;
989 }
990
991 /*
992 Henter ut alle firma i databasen hvor en eller flere tilh�rende personer
993 inneholder s�kestrengen.
994 */
995 function &searchByPerson( $query )
996 {
997 $db =& eZDB::globalDatabase();
998 $query = $db->escapeString( $query );
999 $company_array = array();
1000 $return_array = array();
1001
1002 $db->array_query( $company_array,
1003 "SELECT eZContact_Company.ID as ID
1004 FROM eZContact_Company, eZContact_Person
1005 WHERE ((eZContact_Person.FirstName LIKE '%$query%' OR eZContact_Person.LastName LIKE '%$query%')
1006 AND eZContact_Company.ID=eZContact_Person.Company) GROUP BY eZContact_Company.ID ORDER BY eZContact_Company.ID" );
1007
1008 foreach ( $company_array as $companyItem )
1009 {
1010 $return_array[] = new eZCompany( $companyItem[$db->fieldName( "ID" )] );
1011 }
1012 return $return_array;
1013 }
1014
1018 function &projectState()
1019 {
1020 $ret = "";
1021
1022 $db =& eZDB::globalDatabase();
1023
1024 $checkQuery = "SELECT ProjectID FROM eZContact_CompanyProjectDict WHERE CompanyID='$this->ID'";
1025 $db->array_query( $array, $checkQuery, 0, 1 );
1026
1027 if ( count( $array ) == 1 )
1028 {
1029 $ret =& $array[0][$db->fieldName( "ProjectID" )];
1030 }
1031
1032 return $ret;
1033 }
1034
1038 function setProjectState( $value )
1039 {
1040 $db =& eZDB::globalDatabase();
1041 $db->begin();
1042 $res[] = $db->query( "DELETE FROM eZContact_CompanyProjectDict WHERE CompanyID='$this->ID'" );
1043
1044 if ( is_numeric( $value ) )
1045 {
1046 if ( $value > 0 )
1047 {
1048 $checkQuery = "INSERT INTO eZContact_CompanyProjectDict
1049 (CompanyID, ProjectID)
1050 VALUES
1051 ('$this->ID', '$value')";
1052 $res[] = $db->query( $checkQuery );
1053 }
1054 }
1055 eZDB::finish( $res, $db );
1056 }
1057
1061 function removePersons( $companyid = false )
1062 {
1063 $db =& eZDB::globalDatabase();
1064 if ( !$companyid )
1065 $companyid = $this->ID;
1066
1067 $res[] = $db->query( "DELETE FROM eZContact_CompanyPersonDict
1068 WHERE CompanyID='$companyid'" );
1069 eZDB::finish( $res, $db );
1070 }
1071
1075 function addPerson( $personid, $companyid = false )
1076 {
1077 $db =& eZDB::globalDatabase();
1078 if ( is_a( $personid, "eZPerson" ) )
1079 $personid = $personid->id();
1080 if ( !$companyid )
1081 $companyid = $this->ID;
1082
1083 $db->begin();
1084
1085 $res[] = $db->query( "DELETE FROM eZContact_CompanyPersonDict
1086 WHERE CompanyID='$companyid' AND PersonID='$personid'" );
1087 $res[] = $db->query( "INSERT INTO eZContact_CompanyPersonDict
1088 (PersonID, CompanyID)
1089 VALUES
1090 ('$personid', '$companyid')" );
1091 eZDB::finish( $res, $db );
1092
1093 }
1094
1098 function personCount( $id = false )
1099 {
1100 if ( !$id )
1101 $id = $this->ID;
1102 $db =& eZDB::globalDatabase();
1103 $db->query_single( $arr, "SELECT count( PersonID ) AS Count
1104 FROM eZContact_CompanyPersonDict
1105 WHERE CompanyID='$id'" );
1106 return $arr[$db->fieldName( "Count" )];
1107 }
1108
1112 static public function persons( $id = false, $as_object = true, $limit = -1, $offset = 0 )
1113 {
1114 if ( !$id )
1115 $id = $this->ID;
1116 if ( $limit >= 0 )
1117 {
1118 $limit_array = array( "Limit" => $limit, "Offset" => $offset );
1119 }
1120 else
1121 $limit_array = false;
1122 $db =& eZDB::globalDatabase();
1123 $db->array_query( $arr, "SELECT CPD.PersonID
1124 FROM eZContact_CompanyPersonDict AS CPD, eZContact_Person AS P
1125 WHERE CPD.CompanyID='$id' AND CPD.PersonID=P.ID
1126 ORDER BY P.LastName, P.FirstName", $limit_array );
1127 $ret = array();
1128 if ( $as_object )
1129 {
1130 foreach ( $arr as $row )
1131 {
1132 $ret[] = new eZPerson( $row[ $db->fieldName( "PersonID" ) ] );
1133 }
1134 }
1135 else
1136 {
1137 foreach ( $arr as $row )
1138 {
1139 $ret[] = $row[ $db->fieldName( "PersonID" ) ];
1140 }
1141 }
1142 return $ret;
1143 }
1144
1148 function addViewHit( $company_id = false )
1149 {
1150 if ( !$company_id )
1151 $company_id = $this->ID;
1152 $db =& eZDB::globalDatabase();
1153 $timestamp = (new eZDateTime())->timeStamp( true );
1154 $db->array_query( $qry_array, "SELECT ID FROM eZContact_CompanyView
1155 WHERE Date='$timestamp' AND
1156 CompanyID='$company_id'", 0, 1 );
1157 if ( count( $qry_array ) == 1 )
1158 {
1159 $id = $qry_array[0][$db->fieldName( "ID" )];
1160 $res[] = $db->query( "UPDATE eZContact_CompanyView
1161 SET Count=Count+1, Date='$timestamp'
1162 WHERE ID='$id'" );
1163 }
1164 else
1165 {
1166 $db->lock( "eZContact_CompanyView" );
1167 $nextID = $db->nextID( "eZContact_CompanyView", "ID" );
1168 $res[] = $db->query( "INSERT INTO eZContact_CompanyView
1169 (ID, CompanyID, Count, Date)
1170 VALUES
1171 ('$nextID', '$company_id', '1', '$timestamp')" );
1172 $db->unlock();
1173 }
1174 eZDB::finish( $res, $db );
1175 }
1176
1180 function totalViewCount()
1181 {
1182 $db =& eZDB::globalDatabase();
1183 $db->query_single( $row, "SELECT sum( Count ) AS Count FROM eZContact_CompanyView
1184 WHERE CompanyID='$this->ID'" );
1185 return $row[$db->fieldName( "Count" )];
1186 }
1187
1195 function &yearViewCounts( $year = false )
1196 {
1197 $ret = array();
1198 if ( is_bool( $year ) )
1199 {
1200 $date = new eZDate();
1201 $year = $date->year();
1202 }
1203 for ( $i = 0; $i < 12; $i++ )
1204 {
1205 $month_num = $i + 1;
1206 $date = new eZDate( $year, $month_num, 1 );
1207 $count = $this->viewCount( $date, "month" );
1208 $month = array( "count" => $count,
1209 "month" => $month_num );
1210 $ret[] = $month;
1211 }
1212 return $ret;
1213 }
1214
1219 function viewCount( $date = false, $type = "day" )
1220 {
1221 if ( is_bool( $date ) )
1222 $date = new eZDate();
1223 $year = $date->year();
1224 $month = $date->month();
1225 if ( $month < 10 )
1226 $month = "0" . $month;
1227 $day = $date->day();
1228 if ( $day < 10 )
1229 $day = "0" . $day;
1230 switch ( $type )
1231 {
1232 case "year":
1233 {
1234 $date = "$year-%";
1235 break;
1236 }
1237 case "month":
1238 {
1239 $date = $year . "-" . $month . "-%";
1240 break;
1241 }
1242 default:
1243 case "day":
1244 {
1245 $date = "$year-$month-$day";
1246 break;
1247 }
1248 }
1249 $db =& eZDB::globalDatabase();
1250 $db->query_single( $row, "SELECT sum( Count ) as Count, count( Count ) as Num
1251 FROM eZContact_CompanyView
1252 WHERE CompanyID='$this->ID' AND
1253 Date LIKE '$date'" );
1254 if ( $row[$db->fieldName( "Num" )] == 0 )
1255 return false;
1256 return $row[$db->fieldName( "Count" )];
1257 }
1258
1259 var $ID;
1260 var $CreatorID;
1261 var $Name;
1262 var $Comment;
1263 var $Online;
1264 var $ContactID;
1265 var $PersonContactID;
1266 var $CompanyNo;
1267 var $ContactType;
1268 }
1269
1270 ?>
$i
$i
Definition: admin/adlist.php:91
$day
else $day
Definition: appointmentedit.php:665
$year
else $year
Definition: appointmentedit.php:655
$userID
else $userID
Definition: appointmentedit.php:121
$month
else $month
Definition: appointmentedit.php:660
$date
$date
Definition: bugpreview.php:66
$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
eZCompany\addPerson
addPerson( $personid, $companyid=false)
Definition: ezcompany.php:1075
eZCompany\$ID
$ID
Definition: ezcompany.php:1259
eZCompany\$ContactID
$ContactID
Definition: ezcompany.php:1264
eZCompany\setCreatorID
setCreatorID(&$user)
Definition: ezcompany.php:898
eZCompany\onlines
& onlines( $onlineID=false)
Definition: ezcompany.php:598
eZCompany\setName
setName( $value)
Definition: ezcompany.php:882
eZCompany\addPhone
addPhone(&$phone)
Definition: ezcompany.php:550
eZCompany\$PersonContactID
$PersonContactID
Definition: ezcompany.php:1265
eZCompany\addViewHit
addViewHit( $company_id=false)
Definition: ezcompany.php:1148
eZCompany\totalViewCount
totalViewCount()
Definition: ezcompany.php:1180
eZCompany\searchByCategory
& searchByCategory( $categoryID, $query)
Definition: ezcompany.php:350
eZCompany\removeImages
removeImages()
Definition: ezcompany.php:711
eZCompany\addresses
& addresses( $companyID=false)
Definition: ezcompany.php:457
eZCompany\addOnline
addOnline(&$online)
Definition: ezcompany.php:623
eZCompany\$Comment
$Comment
Definition: ezcompany.php:1262
eZCompany\getAll
& getAll()
Definition: ezcompany.php:256
eZCompany\$Online
$Online
Definition: ezcompany.php:1263
eZCompany\setLogoImage
setLogoImage(&$image, $id=false)
Definition: ezcompany.php:749
eZCompany\addAddress
addAddress(&$address)
Definition: ezcompany.php:482
eZCompany\$CompanyNo
$CompanyNo
Definition: ezcompany.php:1266
eZCompany\$CreatorID
$CreatorID
Definition: ezcompany.php:1260
eZCompany\persons
static persons( $id=false, $as_object=true, $limit=-1, $offset=0)
Definition: ezcompany.php:1112
eZCompany\search
static & search( $query)
Definition: ezcompany.php:386
eZCompany\contactType
contactType()
Definition: ezcompany.php:986
eZCompany\store
store()
Definition: ezcompany.php:75
eZCompany\exists
static exists( $id)
Definition: ezcompany.php:241
eZCompany\setProjectState
setProjectState( $value)
Definition: ezcompany.php:1038
eZCompany\categories
categories( $companyID=false, $as_object=true, $limit=-1)
Definition: ezcompany.php:425
eZCompany\setPersonContact
setPersonContact( $value)
Definition: ezcompany.php:977
eZCompany\setCompanyImage
setCompanyImage(&$image, $id=false)
Definition: ezcompany.php:818
eZCompany\countByCategory
countByCategory( $categoryID)
Definition: ezcompany.php:335
eZCompany\getByCategory
& getByCategory( $categoryID, $offset=0, $limit=-1, $order="name")
Definition: ezcompany.php:277
eZCompany\logoImage
static logoImage( $id=false)
Definition: ezcompany.php:722
eZCompany\deleteLogo
deleteLogo( $id=false)
Definition: ezcompany.php:801
eZCompany\id
id()
Definition: ezcompany.php:918
eZCompany\viewCount
viewCount( $date=false, $type="day")
Definition: ezcompany.php:1219
eZCompany\$Name
$Name
Definition: ezcompany.php:1261
eZCompany\companyImage
static companyImage( $id=false)
Definition: ezcompany.php:856
eZCompany\searchByPerson
& searchByPerson( $query)
Definition: ezcompany.php:995
eZCompany\images
& images()
Definition: ezcompany.php:691
eZCompany\removeCategories
removeCategories()
Definition: ezcompany.php:412
eZCompany\__construct
__construct( $id=-1)
Definition: ezcompany.php:61
eZCompany\removePersons
removePersons( $companyid=false)
Definition: ezcompany.php:1061
eZCompany\creatorID
creatorID()
Definition: ezcompany.php:934
eZCompany\deleteImage
deleteImage( $id=false)
Definition: ezcompany.php:786
eZCompany\setCompanyNo
setCompanyNo( $value)
Definition: ezcompany.php:910
eZCompany\name
name()
Definition: ezcompany.php:926
eZCompany\setComment
setComment( $value)
Definition: ezcompany.php:890
eZCompany\contact
contact()
Definition: ezcompany.php:968
eZCompany\companyNo
companyNo()
Definition: ezcompany.php:950
eZCompany\removePhones
removePhones()
Definition: ezcompany.php:578
eZCompany\addImage
addImage(&$image)
Definition: ezcompany.php:671
eZCompany\comment
comment()
Definition: ezcompany.php:942
eZCompany\setContact
setContact( $value)
Definition: ezcompany.php:959
eZCompany\phones
& phones( $companyID=false)
Definition: ezcompany.php:525
eZCompany\yearViewCounts
& yearViewCounts( $year=false)
Definition: ezcompany.php:1195
eZCompany\removeOnlines
removeOnlines()
Definition: ezcompany.php:650
eZCompany\$ContactType
$ContactType
Definition: ezcompany.php:1267
eZCompany\personCount
personCount( $id=false)
Definition: ezcompany.php:1098
eZCompany\projectState
& projectState()
Definition: ezcompany.php:1018
eZCompany\removeAddresses
removeAddresses()
Definition: ezcompany.php:505
eZDB\finish
static finish(&$resultArray, &$db)
Definition: ezdb.php:204
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZDateTime
Definition: ezdatetime.php:55
eZDate
Definition: ezdate.php:46
eZImage
Definition: ezimage.php:95
eZOrder
Definition: ezorder.php:52
eZPerson
Definition: ezperson.php:43
eZPhone
Definition: ezphone.php:39
eZPhone\delete
delete( $id=false)
Definition: ezphone.php:87
$type
$type
Definition: classes/admin/linkselect.php:220
$name
$name
Definition: companytypelist.php:194
$id
$id
Definition: companytypelist.php:193
$companyid
$companyid
Definition: consultationview.php:119
$personid
$personid
Definition: consultationview.php:120
$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
$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
$dir
$dir
Definition: ezsitemanager/admin/filelist.php:87
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$timestamp
$timestamp
Definition: ezstats/admin/cron.php:35
$res
$res
Definition: ezstats/admin/cron.php:45
$offset
$offset
Definition: ezstats/admin/cron.php:51
$url
$url
Definition: messagereviewlist.php:153
$count
$count
Definition: onlinetypelist.php:108
$order
$order
Definition: productreport.php:182
$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
$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+.