[ Index ]

PHP Cross Reference of Mambo 4.6.5

[ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/components/com_contact/ -> contact.class.php (source)

   1  <?php
   2  /**
   3  * @package Mambo
   4  * @subpackage Contact
   5  * @author Mambo Foundation Inc see README.php
   6  * @copyright (C) 2000 - 2009 Mambo Foundation Inc.
   7  * See COPYRIGHT.php for copyright notices and details.
   8  * @license GNU/GPL Version 2, see LICENSE.php
   9  *
  10  * Redistributions of files must retain the above copyright notice.
  11  *
  12  * Mambo is free software; you can redistribute it and/or
  13  * modify it under the terms of the GNU General Public License
  14  * as published by the Free Software Foundation; version 2 of the License.
  15  */
  16  
  17  /** ensure this file is being included by a parent file */
  18  defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
  19  
  20  include_once ( $mosConfig_absolute_path .'/includes/vcard.class.php' );
  21      
  22  class mosContact extends mosDBTable {
  23      /** @var int Primary key */
  24      var $id=null;
  25      /** @var string */
  26      var $name=null;
  27      /** @var string */
  28      var $con_position=null;
  29      /** @var string */
  30      var $address=null;
  31      /** @var string */
  32      var $suburb=null;
  33      /** @var string */
  34      var $state=null;
  35      /** @var string */
  36      var $country=null;
  37      /** @var string */
  38      var $postcode=null;
  39      /** @var string */
  40      var $telephone=null;
  41      /** @var string */
  42      var $fax=null;
  43      /** @var string */
  44      var $misc=null;
  45      /** @var string */
  46      var $image=null;
  47      /** @var string */
  48      var $imagepos=null;
  49      /** @var string */
  50      var $email_to=null;
  51      /** @var int */
  52      var $default_con=null;
  53      /** @var int */
  54      var $published=null;
  55      /** @var int */
  56      var $checked_out=null;
  57      /** @var datetime */
  58      var $checked_out_time=null;
  59      /** @var int */
  60      var $ordering=null;
  61      /** @var string */
  62      var $params=null;
  63      /** @var int A link to a registered user */
  64      var $user_id=null;
  65      /** @var int A link to a category */
  66      var $catid=null;
  67      /** @var int */
  68      var $access=null;
  69  
  70      /**
  71      * @param database A database connector object
  72      */
  73  	function mosContact() {
  74          $database = mamboDatabase::getInstance();
  75          $this->mosDBTable( '#__contact_details', 'id', $database );
  76      }
  77  
  78  	function check() {
  79          $this->default_con = intval( $this->default_con );
  80          return true;
  81      }
  82      
  83      function &getCategories ($user) {
  84          static $contact_cats = '';
  85          if (!is_array($contact_cats)) {
  86              $database = mamboDatabase::getInstance();
  87              /* Query to retrieve all categories that belong under the contacts section and that are published. */
  88              $query = "SELECT cc.*,a.catid, COUNT(a.id) AS numlinks, MIN(a.id) as minimum"
  89              . "\n FROM #__categories AS cc"
  90              . "\n LEFT JOIN #__contact_details AS a ON a.catid = cc.id"
  91              . "\n WHERE a.published='1'"
  92              . "\n AND cc.section='com_contact_details'"
  93              . "\n AND cc.published='1'"
  94              . "\n AND a.access <= '". $user->gid ."'"
  95              . "\n AND cc.access <= '". $user->gid ."'"
  96              . "\n GROUP BY cc.id"
  97              . "\n ORDER BY cc.ordering"
  98              ;
  99              $database->setQuery( $query );
 100              $contact_cats = $database->loadObjectList();
 101              if (!$contact_cats) $contact_cats = array();
 102          }
 103          return $contact_cats;
 104      }
 105      
 106      function &getContacts ($catid, $user) {
 107          $database = mamboDatabase::getInstance();
 108          $query = "SELECT *"
 109          . "\n FROM #__contact_details"
 110          . "\n WHERE catid = '". $catid."'"
 111           . "\n AND published='1'"
 112           . "\n AND access <= '". $user->gid ."'"
 113          . "\n ORDER BY ordering"
 114          ;
 115          $contacts = $database->doSQLget($query, 'mosContact');
 116          return $contacts;
 117      }
 118  }
 119  
 120  /**
 121  * @package Mambo
 122  * class needed to extend vcard class and to correct minor errors
 123  */
 124  class MambovCard extends vCard {
 125  
 126      // needed to fix bug in vcard class
 127  	function setName( $family='', $first='', $additional='', $prefix='', $suffix='' ) {
 128          $this->properties["N"]     = "$family;$first;$additional;$prefix;$suffix";
 129          $this->setFormattedName( trim( "$prefix $first $additional $family $suffix" ) );
 130      }
 131  
 132      // needed to fix bug in vcard class
 133  	function setAddress( $postoffice='', $extended='', $street='', $city='', $region='', $zip='', $country='', $type='HOME;POSTAL' ) {
 134          // $type may be DOM | INTL | POSTAL | PARCEL | HOME | WORK or any combination of these: e.g. "WORK;PARCEL;POSTAL"
 135          $key     = 'ADR';
 136          if ( $type != '' ) {
 137              $key    .= ';'. $type;
 138          }
 139          $key.= ';ENCODING=QUOTED-PRINTABLE';
 140          $this->properties[$key] = encode( $extended ) .';'. encode( $street ) .';'. encode( $city ) .';'. encode( $region) .';'. encode( $zip ) .';'. encode( $country );
 141      }
 142  
 143      // added ability to set filename
 144  	function setFilename( $filename ) {
 145          $this->filename = $filename .'.vcf';
 146      }    
 147  
 148      // added ability to set position/title
 149  	function setTitle( $title ) {
 150          $title     = trim( $title );
 151          $this->properties['TITLE']     = $title;
 152      }
 153  
 154      // added ability to set organisation/company
 155  	function setOrg( $org ) {
 156          $org     = trim( $org );
 157          $this->properties['ORG']     = $org;
 158      }
 159  
 160  	function getVCard( $sitename ) {
 161          $text     = "BEGIN:VCARD\r\n";
 162          $text     .= "VERSION:2.1\r\n";
 163          foreach( $this->properties as $key => $value ) {
 164              $text    .= "$key:$value\r\n";
 165          }
 166          $text    .= "REV:" .date("Y-m-d") ."T". date("H:i:s"). "Z\r\n";
 167          $text    .= "MAILER: ".sprintf(T_('Mambo vCard for %s'),$sitename) ."\r\n";
 168          $text    .= "END:VCARD\r\n";
 169          return $text;
 170      }
 171      
 172  }
 173  
 174  ?>