[ Index ]

PHP Cross Reference of Mambo 4.6.5

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

title

Body

[close]

/components/com_contact/ -> contact.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  // load the html drawing class
  21  require_once( $mainframe->getPath( 'front_html' ) );
  22  require_once( $mainframe->getPath( 'class' ) );
  23  
  24  class contactUserControllers {
  25      var $manager = '';
  26      var $user = '';
  27      var $op = '';
  28      var $con_id = 0;
  29      var $contact_id = 0;
  30      var $catid = 0;
  31      var $Itemid = 0;
  32  
  33  	function contactUserControllers ($manager) {
  34          $this->manager = $manager;
  35          $this->user = mamboCore::get('currentUser');
  36          $this->op = mosGetParam($_REQUEST, 'op', '');
  37          $this->con_id = mosGetParam( $_REQUEST ,'con_id', 0 );
  38          $this->contact_id = mosGetParam( $_REQUEST ,'contact_id', 0 );
  39          $this->catid = mosGetParam( $_REQUEST ,'catid', 0 );
  40          $this->Itemid = mamboCore::get('Itemid');
  41      }
  42  
  43  	function sendmail () {
  44  
  45          global $mosConfig_usecaptcha;
  46  
  47          $captcha_success = 0;
  48          if ($mosConfig_usecaptcha == '1') {
  49  
  50              mos_session_start();
  51  
  52              $spamstop = mosGetParam( $_POST, 'spamstop', '' );
  53  
  54              if(isset($_SESSION['captcha_code']) && ($_SESSION['captcha_code'] != "") && ($_SESSION['captcha_code'] == $spamstop)) {
  55                  $captcha_success = 1; // success
  56              } else {
  57                  $captcha_success = 2; // fail
  58              }
  59  
  60          }
  61  
  62          if ($captcha_success != '2') {
  63  
  64              $contact = new mosContact();
  65              $contact->load($this->con_id);
  66  
  67              $default = mamboCore::get('mosConfig_sitename').' '.T_('Enquiry');
  68              $email = mosGetParam( $_POST, 'email', '' );
  69              $text = mosGetParam( $_POST, 'text', '' );
  70              $name = mosGetParam( $_POST, 'name', '' );
  71              $subject = mosGetParam( $_POST, 'subject', $default );
  72              $email_copy = mosGetParam( $_POST, 'email_copy', 0 );
  73  
  74              if (!$email OR !$text OR !$this->is_email($email) OR $this->has_emailheaders($text) OR $this->has_newlines($email) OR $this->has_newlines($name) OR $this->has_newlines($subject) OR !isset($_SERVER['HTTP_USER_AGENT']) OR $_SERVER['REQUEST_METHOD'] != 'POST') {
  75                  echo "<script>alert (\"".T_('Please make sure the form is complete and valid.')."\"); window.history.go(-1);</script>";
  76                  exit(0);
  77              }
  78              $prefix = sprintf( T_('This is an enquiry e-mail via %s from:'), mamboCore::get('mosConfig_live_site') );
  79              $text = $prefix ."\n". $name. ' <'. $email .'>' ."\n\n". $text;
  80  
  81              mosMail( $email, $name , $contact->email_to, mamboCore::get('mosConfig_fromname') .': '. $subject, $text );
  82  
  83              if ( $email_copy ) {
  84                  $copy_text = sprintf( T_('The following is a copy of the message you sent to %s via %s '), $contact->name, mamboCore::get('mosConfig_sitename') );
  85                  $copy_text = $copy_text ."\n\n". $text .'';
  86                  $copy_subject = sprintf(T_('Copy of: %s'),$subject);
  87                  mosMail( mamboCore::get('mosConfig_mailfrom'), mamboCore::get('mosConfig_fromname'), $email, $copy_subject, $copy_text );
  88              }
  89              echo '<script type="text/javascript">alert(\''.T_('Thank you for your e-mail ').$name.'\');';
  90              echo 'document.location.href=\''.str_replace( '&amp;', '&',sefRelToAbs( 'index.php?option=com_contact&Itemid='. $this->Itemid .'&task=view&contact_id='.$this->con_id )).'\'</script>';
  91          } else {
  92              echo "<SCRIPT> alert('Incorrect Security Code'); window.history.go(-1);</SCRIPT>";
  93          }
  94      }
  95  
  96      /**
  97      * Check field contains an email address:
  98      * Returns false if text is not an email address
  99      */
 100  	function is_email($email){
 101          return preg_match("/^[A-Z0-9._%-]+@[A-Z0-9.-]+.[A-Z]{2,4}$/i", $email );
 102      }
 103  
 104      /**
 105      * Check single-line inputs:
 106      * Returns true if text contains newline character
 107      */
 108  	function has_newlines($text) {
 109         return preg_match("/(%0A|%0D|\n+|\r+)/i", $text);
 110      }
 111  
 112      /**
 113      * Check multi-line inputs:
 114      * Returns true if text contains newline followed by
 115      * email-header specific string
 116      */
 117  	function has_emailheaders($text) {
 118         return preg_match("/(%0A|%0D|\n+|\r+)(content-type:|to:|cc:|bcc:)/i", $text);
 119      }
 120  
 121  }
 122  
 123  class contact_lister_Controller extends contactUserControllers {
 124  
 125  	function lister () {
 126          $categories = &mosContact::getCategories($this->user);
 127          $count = count($categories);
 128          if ($count == 0 OR ($count == 1 AND $categories[0]->numlinks == 1)) {
 129              // No or one category that qualifies
 130              $this->contact_id = $count == 1 ? $categories[0]->minimum : 0;
 131              $controller = new contact_view_Controller ($this->manager);
 132              $controller->view();
 133              if ($this->op == 'sendmail') $this->sendmail();
 134              return;
 135          }
 136          $rows = array();
 137          $currentcat =& new stdClass();
 138          // Parameters
 139          $menuhandler = mosMenuHandler::getInstance();
 140          $menu =& $menuhandler->getMenuByID($this->Itemid);
 141          $params =& $this->makeParams ($menu->params, $menu->name);
 142          // page header
 143          $currentcat->header = $params->get( 'header' );
 144          // Path to images
 145          $path = mamboCore::get('mosConfig_live_site').'/images/stories/';
 146          $currentcat->descrip = '';
 147          $currentcat->img = '';
 148          if ( $this->catid ) {
 149              $params->set( 'type', 'category' );
 150              // url links info for category
 151              $rows = mosContact::getContacts($this->catid, $this->user);
 152              // current category info
 153              foreach ($categories as $category) {
 154                  if ($category->id == $this->catid) {
 155                      $currentcat =& $category;
 156                      // show description
 157                      $currentcat->descrip = $currentcat->description;
 158                      // page image
 159                      $currentcat->img = $path . $currentcat->image;
 160                      $currentcat->align = $currentcat->image_position;
 161                      // page header
 162                      if ( @$currentcat->name <> '' ) $currentcat->header .= ' - '.$currentcat->name;
 163                      break;
 164                  }
 165              }
 166          }
 167          else {
 168              $params->set( 'type', 'section' );
 169              // show description
 170              if ( $params->get( 'description' ) ) $currentcat->descrip = $params->get( 'description_text' );
 171              // page image
 172              if ( $params->get( 'image' ) <> -1 ) {
 173                  $currentcat->img = $path . $params->get( 'image' );
 174                  $currentcat->align = $params->get( 'image_align' );
 175              }
 176          }
 177          // used to show table rows in alternating colours
 178          $tabclass = array( 'sectiontableentry1', 'sectiontableentry2' );
 179          HTML_contact::displaylist( $categories, $rows, $this->catid, $currentcat, $params, $tabclass );
 180          if ($this->op == 'sendmail') $this->sendmail();
 181      }
 182  
 183      function &makeParams ($rawparams, $name) {
 184          $params =& new mosParameters( $rawparams );
 185          $params->def( 'page_title', 1 );
 186          $params->def( 'header', $name );
 187          $params->def( 'pageclass_sfx', '' );
 188          $params->def( 'headings', 1 );
 189          $params->def( 'back_button', mamboCore::get('mosConfig_back_button') );
 190          $params->def( 'description_text', T_('The Contact list for this Website.') );
 191          $params->def( 'image', -1 );
 192          $params->def( 'image_align', 'right' );
 193          $params->def( 'other_cat_section', 1 );
 194          // Category List Display control
 195          $params->def( 'other_cat', 1 );
 196          $params->def( 'cat_description', 1 );
 197          $params->def( 'cat_items', 1 );
 198          // Table Display control
 199          $params->def( 'headings', 1 );
 200          $params->def( 'position', '1' );
 201          $params->def( 'email', '0' );
 202          $params->def( 'phone', '1' );
 203          $params->def( 'fax', '1' );
 204          $params->def( 'telephone', '1' );
 205          return $params;
 206      }
 207  
 208  }
 209  
 210  class contact_view_Controller extends contactUserControllers {
 211  
 212  	function view () {
 213          $database = mamboDatabase::getInstance();
 214          $query = "SELECT a.*, a.id AS value, CONCAT_WS( ' - ', a.name, a.con_position ) AS text"
 215          . "\n FROM #__contact_details AS a"
 216          . "\n LEFT JOIN #__categories AS cc ON cc.id = a.catid"
 217          . "\n WHERE a.published = '1'"
 218          . "\n AND cc.published = '1'"
 219          . "\n AND a.access <=". $this->user->gid
 220          . "\n AND cc.access <=". $this->user->gid
 221          . "\n ORDER BY a.default_con DESC, a.ordering ASC"
 222          ;
 223          $database->setQuery( $query );
 224          $list = $database->loadObjectList();
 225          $count = count($list);
 226          if ($count == 0) {
 227              $params =& new mosParameters('');
 228              $params->def( 'back_button', mamboCore::get( 'mosConfig_back_button' ) );
 229              HTML_contact::nocontact( $params );
 230              return;
 231          }
 232          if ( $this->contact_id == 0 ) $this->contact_id = $list[0]->id;
 233          foreach ($list as $cont) {
 234              if ($cont->id == $this->contact_id) {
 235                  $contact =& $cont;
 236                  break;
 237              }
 238          }
 239          if (!isset($contact)) {
 240              echo T_('You are not authorized to view this resource.');
 241              return;
 242          }
 243          // creates dropdown select list
 244          $contact->select = mosHTML::selectList( $list, 'contact_id', 'class="inputbox" onchange="ViewCrossReference(this);"', 'value', 'text', $this->contact_id );
 245          // Adds parameter handling
 246          $params =& $this->makeParams ( $contact->params );        
 247                  
 248          // load mambot params info
 249          $query = "SELECT id FROM #__mambots WHERE element = 'mosemailcloak' AND folder = 'content'";
 250          $database->setQuery( $query );
 251          $id     = $database->loadResult();
 252          $mambot = new mosMambot( $database );
 253          $mambot->load( $id );
 254          $params2 =& $this->makeParams ( $mambot->params );
 255          
 256          if ( $contact->email_to AND $params->get( 'email' )) {
 257              // email cloacking
 258              $contact->email = mosHTML::emailCloaking( $contact->email_to, $params2->get( 'mode' ) );
 259          }
 260          // loads current template for the pop-up window
 261          $pop = mosGetParam( $_REQUEST, 'pop', 0 );
 262          if ( $pop ) {
 263              $params->set( 'popup', 1 );
 264              $params->set( 'back_button', 0 );
 265          }
 266          if ( $params->get( 'email_description' ) ) $params->set( 'email_description', $params->get( 'email_description_text' ) );
 267          else $params->set( 'email_description', '' );
 268  
 269          // needed to control the display of the Address marker
 270          $temp = $params->get( 'street_address' )
 271          . $params->get( 'suburb' )
 272          . $params->get( 'state' )
 273          . $params->get( 'country' )
 274          . $params->get( 'postcode' )
 275          ;
 276          $params->set( 'address_check', $temp );
 277  
 278          // determines whether to use Text, Images or nothing to highlight the different info groups
 279          $this->groupMarking($params);
 280          // params from menu item
 281          $menuhandler = mosMenuHandler::getInstance();
 282          $menu =& $menuhandler->getMenuByID($this->Itemid);
 283          $menu_params =& new mosParameters( $menu->params );
 284  
 285          $menu_params->def( 'page_title', 1 );
 286          $menu_params->def( 'header', $menu->name );
 287          $menu_params->def( 'pageclass_sfx', '' );
 288  
 289          HTML_contact::viewcontact( $contact, $params, $count, $list, $menu_params );
 290      }
 291  
 292      function &makeParams ($rawparams) {
 293          $params =& new mosParameters( $rawparams );
 294          $params->set( 'page_title', 0 );
 295          $params->def( 'pageclass_sfx', '' );
 296          $params->def( 'back_button', mamboCore::get( 'mosConfig_back_button' ) );
 297          $params->def( 'print', !mamboCore::get( 'mosConfig_hidePrint' ) );
 298          $params->def( 'name', '1' );
 299          $params->def( 'email', '0' );
 300          $params->def( 'street_address', '1' );
 301          $params->def( 'suburb', '1' );
 302          $params->def( 'state', '1' );
 303          $params->def( 'country', '1' );
 304          $params->def( 'postcode', '1' );
 305          $params->def( 'telephone', '1' );
 306          $params->def( 'fax', '1' );
 307          $params->def( 'misc', '1' );
 308          $params->def( 'image', '1' );
 309          $params->def( 'email_description', '1' );
 310          $params->def( 'email_description_text', T_('Send an Email to this Contact:') );
 311          $params->def( 'email_form', '1' );
 312          $params->def( 'email_copy', '1' );
 313          // global print|pdf|email
 314          $params->def( 'icons', mamboCore::get( 'mosConfig_icons' ) );
 315          // contact only icons
 316          $params->def( 'contact_icons', 0 );
 317          $params->def( 'icon_address', '' );
 318          $params->def( 'icon_email', '' );
 319          $params->def( 'icon_telephone', '' );
 320          $params->def( 'icon_fax', '' );
 321          $params->def( 'icon_misc', '' );
 322          $params->def( 'drop_down', '0' );
 323          $params->def( 'vcard', '1' );
 324          return $params;
 325      }
 326  
 327  	function groupMarking (&$params) {
 328          switch ( $params->get( 'contact_icons' ) ) {
 329              case 1:
 330              // text
 331                  $params->set( 'marker_address', T_('Address: ') );
 332                  $params->set( 'marker_email', T_('Email: ') );
 333                  $params->set( 'marker_telephone', T_('Telephone: ') );
 334                  $params->set( 'marker_fax', T_('Fax: ') );
 335                  $params->set( 'marker_misc', T_('Information: ') );
 336                  $params->set( 'column_width', '100px' );
 337                  break;
 338              case 2:
 339              // none
 340                  $params->set( 'marker_address', '' );
 341                  $params->set( 'marker_email', '' );
 342                  $params->set( 'marker_telephone', '' );
 343                  $params->set( 'marker_fax', '' );
 344                  $params->set( 'marker_misc', '' );
 345                  $params->set( 'column_width', '0px' );
 346                  break;
 347              default:
 348              // icons
 349                  $mainframe = mosMainFrame::getInstance();
 350                  $image1 = $mainframe->ImageCheck( 'con_address.png', '/images/M_images/', $params->get( 'icon_address' ) );
 351                  $image2 = $mainframe->ImageCheck( 'emailButton.png', '/images/M_images/', $params->get( 'icon_email' ) );
 352                  $image3 = $mainframe->ImageCheck( 'con_tel.png', '/images/M_images/', $params->get( 'icon_telephone' ) );
 353                  $image4 = $mainframe->ImageCheck( 'con_fax.png', '/images/M_images/', $params->get( 'icon_fax' ) );
 354                  $image5 = $mainframe->ImageCheck( 'con_info.png', '/images/M_images/', $params->get( 'icon_misc' ) );
 355                  $params->set( 'marker_address', $image1 );
 356                  $params->set( 'marker_email', $image2 );
 357                  $params->set( 'marker_telephone', $image3 );
 358                  $params->set( 'marker_fax', $image4 );
 359                  $params->set( 'marker_misc', $image5 );
 360                  $params->set( 'column_width', '40px' );
 361                  break;
 362          }
 363      }
 364  
 365  }
 366  
 367  class contact_vcard_Controller extends contactUserControllers {
 368  
 369  	function vcard () {
 370          $contact = new mosContact();
 371          $contact->load($this->contact_id);
 372          $params = new mosParameters($contact->params);
 373          if (!$params->get('vcard')) {
 374              echo "<script>alert (\"".T_('There are no vCards available for download.')."\"); window.history.go(-1);</script>";
 375              exit(0);
 376          }
 377          $name = explode(' ', $contact->name);
 378          $firstname = $name[0];
 379          unset($name[0]);
 380          $last = count($name);
 381          if (isset($name[$last])) {
 382              $surname = $name[$last];
 383              unset($name[$last]);
 384          }
 385          else $surname = '';
 386          $middlename = trim (implode(' ', $name));
 387  
 388          $v     = new MambovCard();
 389          $v->setPhoneNumber( $contact->telephone, 'PREF;WORK;VOICE' );
 390          $v->setPhoneNumber( $contact->fax, 'WORK;FAX' );
 391          $v->setName( $surname, $firstname, $middlename, '' );
 392          $v->setAddress( '', '', $contact->address, $contact->suburb, $contact->state, $contact->postcode, $contact->country, 'WORK;POSTAL' );
 393          $v->setEmail( $contact->email_to );
 394          $v->setNote( $contact->misc );
 395          $v->setURL( mamboCore::get('mosConfig_live_site'), 'WORK' );
 396          $v->setTitle( $contact->con_position );
 397          $v->setOrg( mamboCore::get('mosConfig_sitename') );
 398  
 399          $filename    = str_replace( ' ', '_', $contact->name );
 400          $v->setFilename( $filename );
 401  
 402          $output     = $v->getVCard( mamboCore::get('mosConfig_sitename') );
 403          $filename = $v->getFileName();
 404  
 405          // header info for page
 406          header( 'Content-Disposition: attachment; filename='. $filename );
 407          header( 'Content-Length: '. strlen( $output ) );
 408          header( 'Connection: close' );
 409          header( 'Content-Type: text/x-vCard; name='. $filename );
 410  
 411          print $output;
 412          //mosRedirect('index.php');
 413      }
 414  
 415  }
 416  
 417  $alternatives = array ();
 418  $admin =& new mosComponentUserManager ('contact', 'task', $alternatives, 'lister', T_('Contact Us'), $version);
 419  
 420  ?>