[ Index ]
 

Code source de Joomla 1.0.13

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

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

   1  <?php
   2  /**

   3  * @version $Id: contact.php 5072 2006-09-15 16:24:06Z friesengeist $

   4  * @package Joomla

   5  * @subpackage Contact

   6  * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.

   7  * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php

   8  * Joomla! is free software. This version may have been modified pursuant

   9  * to the GNU General Public License, and as distributed it includes or

  10  * is derivative of works licensed under the GNU General Public License or

  11  * other free or open source software licenses.

  12  * See COPYRIGHT.php for copyright notices and details.

  13  */
  14  
  15  // no direct access

  16  defined( '_VALID_MOS' ) or die( 'Restricted access' );
  17  
  18  // load the html drawing class

  19  require_once( $mainframe->getPath( 'front_html' ) );
  20  require_once( $mainframe->getPath( 'class' ) );
  21  
  22  $mainframe->setPageTitle( _CONTACT_TITLE );
  23  
  24  //Load Vars

  25  $op            = strval( mosGetParam( $_REQUEST, 'op', '' ) );
  26  $con_id     = intval( mosGetParam( $_REQUEST ,'con_id', 0 ) );
  27  $contact_id = intval( mosGetParam( $_REQUEST ,'contact_id', 0 ) );
  28  $catid         = intval( mosGetParam( $_REQUEST ,'catid', 0 ) );
  29  
  30  switch( $op ) {
  31      case 'sendmail':
  32          sendmail( $con_id, $option );
  33          break;
  34  }
  35  
  36  switch( $task ) {
  37      case 'view':
  38          contactpage( $contact_id );
  39          break;
  40  
  41      case 'vcard':
  42          vCard( $contact_id );
  43          break;
  44  
  45      default:
  46          listContacts( $option, $catid );
  47          break;
  48  }
  49  
  50  
  51  function listContacts( $option, $catid ) {
  52      global $mainframe, $database, $my;
  53      global $mosConfig_live_site;
  54      global $Itemid;
  55  
  56      /* Query to retrieve all categories that belong under the contacts section and that are published. */

  57      $query = "SELECT *, COUNT( a.id ) AS numlinks"
  58      . "\n FROM #__categories AS cc"
  59      . "\n LEFT JOIN #__contact_details AS a ON a.catid = cc.id"
  60      . "\n WHERE a.published = 1"
  61      . "\n AND cc.section = 'com_contact_details'"
  62      . "\n AND cc.published = 1"
  63      . "\n AND a.access <= " . (int) $my->gid
  64      . "\n AND cc.access <= " . (int) $my->gid
  65      . "\n GROUP BY cc.id"
  66      . "\n ORDER BY cc.ordering"
  67      ;
  68      $database->setQuery( $query );
  69      $categories = $database->loadObjectList();
  70  
  71      $count = count( $categories );
  72  
  73      if ( ( $count < 2 ) && ( @$categories[0]->numlinks == 1 ) ) {
  74          // if only one record exists loads that record, instead of displying category list

  75          contactpage( $option, 0 );
  76      } else {
  77          $rows         = array();
  78          $currentcat = NULL;
  79  
  80          // Parameters

  81          $menu = $mainframe->get( 'menu' );
  82          $params = new mosParameters( $menu->params );
  83  
  84          $params->def( 'page_title',         1 );
  85          $params->def( 'header',             $menu->name );
  86          $params->def( 'pageclass_sfx',         '' );
  87          $params->def( 'headings',             1 );
  88          $params->def( 'back_button',         $mainframe->getCfg( 'back_button' ) );
  89          $params->def( 'description_text',     _CONTACTS_DESC );
  90          $params->def( 'image',                 -1 );
  91          $params->def( 'image_align',         'right' );
  92          $params->def( 'other_cat_section',     1 );
  93          // Category List Display control

  94          $params->def( 'other_cat',             1 );
  95          $params->def( 'cat_description',     1 );
  96          $params->def( 'cat_items',             1 );
  97          // Table Display control

  98          $params->def( 'headings',             1 );
  99          $params->def( 'position',             1 );
 100          $params->def( 'email',                 0 );
 101          $params->def( 'phone',                 1 );
 102          $params->def( 'fax',                 1 );
 103          $params->def( 'telephone',             1 );
 104  
 105          if( $catid == 0 ) {
 106              $catid = $params->get( 'catid', 0 );
 107          }
 108  
 109          if ( $catid ) {
 110              $params->set( 'type', 'category' );
 111          } else {
 112              $params->set( 'type', 'section' );
 113          }
 114  
 115          if ( $catid ) {
 116              // url links info for category

 117              $query = "SELECT *"
 118              . "\n FROM #__contact_details"
 119              . "\n WHERE catid = " . (int) $catid
 120              . "\n AND published =1"
 121              . "\n AND access <= " . (int) $my->gid
 122              . "\n ORDER BY ordering"
 123              ;
 124              $database->setQuery( $query );
 125              $rows = $database->loadObjectList();
 126  
 127              // current category info

 128              $query = "SELECT id, name, description, image, image_position"
 129              . "\n FROM #__categories"
 130              . "\n WHERE id = " . (int) $catid
 131              . "\n AND published = 1"
 132              . "\n AND access <= " . (int) $my->gid
 133              ;
 134              $database->setQuery( $query );
 135              $database->loadObject( $currentcat );
 136  
 137              /*

 138              Check if the category is published or if access level allows access

 139              */
 140              if (!$currentcat->name) {
 141                  mosNotAuth();
 142                  return;
 143              }
 144          }
 145  
 146          // page description

 147          $currentcat->descrip = '';
 148          if( isset($currentcat->description) && ($currentcat->description != '') ) {
 149              $currentcat->descrip = $currentcat->description;
 150          } else if ( !$catid ) {
 151              // show description

 152              if ( $params->get( 'description' ) ) {
 153                  $currentcat->descrip = $params->get( 'description_text' );
 154              }
 155          }
 156  
 157          // page image

 158          $currentcat->img = '';
 159          $path = $mosConfig_live_site .'/images/stories/';
 160          if ( isset($currentcat->image) && ($currentcat->image != '') ) {
 161              $currentcat->img = $path . $currentcat->image;
 162              $currentcat->align = $currentcat->image_position;
 163          } else if ( !$catid ) {
 164              if ( $params->get( 'image' ) != -1 ) {
 165                  $currentcat->img = $path . $params->get( 'image' );
 166                  $currentcat->align = $params->get( 'image_align' );
 167              }
 168          }
 169  
 170          // page header

 171          $currentcat->header = '';
 172          if ( isset($currentcat->name) && ($currentcat->name != '') ) {
 173              $currentcat->header = $params->get( 'header' ) .' - '. $currentcat->name;
 174          } else {
 175              $currentcat->header = $params->get( 'header' );
 176          }
 177  
 178          // used to show table rows in alternating colours

 179          $tabclass = array( 'sectiontableentry1', 'sectiontableentry2' );
 180  
 181          HTML_contact::displaylist( $categories, $rows, $catid, $currentcat, $params, $tabclass );
 182      }
 183  }
 184  
 185  
 186  function contactpage( $contact_id ) {
 187      global $mainframe, $database, $my, $Itemid;
 188  
 189      $query = "SELECT a.id AS value, CONCAT_WS( ' - ', a.name, a.con_position ) AS text, a.catid, cc.access AS cat_access"
 190      . "\n FROM #__contact_details AS a"
 191      . "\n LEFT JOIN #__categories AS cc ON cc.id = a.catid"
 192      . "\n WHERE a.published = 1"
 193      . "\n AND cc.published = 1"
 194      . "\n AND a.access <= " . (int) $my->gid
 195      . "\n ORDER BY a.default_con DESC, a.ordering ASC"
 196      ;
 197      $database->setQuery( $query );
 198      $checks = $database->loadObjectList();
 199  
 200      $count = count( $checks );
 201      if ($count) {
 202          if ($contact_id < 1) {
 203              $contact_id = $checks[0]->value;
 204          }
 205  
 206          $query = "SELECT a.*, cc.access AS cat_access"
 207          . "\n FROM #__contact_details AS a"
 208          . "\n LEFT JOIN #__categories AS cc ON cc.id = a.catid"
 209          . "\n WHERE a.published = 1"
 210          . "\n AND a.id = " . (int) $contact_id
 211          . "\n AND a.access <= " . (int) $my->gid
 212          ;
 213          $database->SetQuery($query);
 214          $contacts = $database->LoadObjectList();
 215  
 216          if (!$contacts){
 217              echo _NOT_AUTH;
 218              return;
 219          }
 220          $contact = $contacts[0];    
 221              
 222          /*

 223          * check whether category access level allows access

 224          */
 225          if ( $contact->cat_access > $my->gid ) {    
 226              mosNotAuth();  
 227              return;
 228          }
 229  
 230          $list = array();
 231          foreach ( $checks as $check ) {
 232              if ( $check->catid == $contact->catid ) {
 233                  $list[] = $check;
 234              }
 235          }        
 236          // creates dropdown select list

 237          $contact->select = mosHTML::selectList( $list, 'contact_id', 'class="inputbox" onchange="ViewCrossReference(this);"', 'value', 'text', $contact_id );
 238  
 239          // Adds parameter handling

 240          $params = new mosParameters( $contact->params );
 241  
 242          $params->set( 'page_title',             0 );
 243          $params->def( 'pageclass_sfx',             '' );
 244          $params->def( 'back_button',             $mainframe->getCfg( 'back_button' ) );
 245          $params->def( 'print',                     !$mainframe->getCfg( 'hidePrint' ) );
 246          $params->def( 'name',                     1 );
 247          $params->def( 'email',                     0 );
 248          $params->def( 'street_address',         1 );
 249          $params->def( 'suburb',                 1 );
 250          $params->def( 'state',                     1 );
 251          $params->def( 'country',                 1 );
 252          $params->def( 'postcode',                 1 );
 253          $params->def( 'telephone',                 1 );
 254          $params->def( 'fax',                     1 );
 255          $params->def( 'misc',                     1 );
 256          $params->def( 'image',                     1 );
 257          $params->def( 'email_description',         1 );
 258          $params->def( 'email_description_text', _EMAIL_DESCRIPTION );
 259          $params->def( 'email_form',             1 );
 260          $params->def( 'email_copy',             0 );
 261          // global pront|pdf|email

 262          $params->def( 'icons',                     $mainframe->getCfg( 'icons' ) );
 263          // contact only icons

 264          $params->def( 'contact_icons',             0 );
 265          $params->def( 'icon_address',             '' );
 266          $params->def( 'icon_email',             '' );
 267          $params->def( 'icon_telephone',         '' );
 268          $params->def( 'icon_fax',                 '' );
 269          $params->def( 'icon_misc',                 '' );
 270          $params->def( 'drop_down',                 0 );
 271          $params->def( 'vcard',                     0 );
 272  
 273  
 274          if ( $contact->email_to && $params->get( 'email' )) {
 275              // email cloacking

 276              $contact->email = mosHTML::emailCloaking( $contact->email_to );
 277          }
 278  
 279          // loads current template for the pop-up window

 280          $pop = intval( mosGetParam( $_REQUEST, 'pop', 0 ) );
 281          if ( $pop ) {
 282              $params->set( 'popup', 1 );
 283              $params->set( 'back_button', 0 );
 284          }
 285  
 286          if ( $params->get( 'email_description' ) ) {
 287              $params->set( 'email_description', $params->get( 'email_description_text' ) );
 288          } else {
 289              $params->set( 'email_description', '' );
 290          }
 291  
 292          // needed to control the display of the Address marker

 293          $temp = $params->get( 'street_address' )
 294          . $params->get( 'suburb' )
 295          . $params->get( 'state' )
 296          . $params->get( 'country' )
 297          . $params->get( 'postcode' )
 298          ;
 299          $params->set( 'address_check', $temp );
 300  
 301          // determines whether to use Text, Images or nothing to highlight the different info groups

 302          switch ( $params->get( 'contact_icons' ) ) {
 303              case 1:
 304              // text

 305                  $params->set( 'marker_address', _CONTACT_ADDRESS );
 306                  $params->set( 'marker_email', _CONTACT_EMAIL );
 307                  $params->set( 'marker_telephone', _CONTACT_TELEPHONE );
 308                  $params->set( 'marker_fax', _CONTACT_FAX );
 309                  $params->set( 'marker_misc', _CONTACT_MISC );
 310                  $params->set( 'column_width', '100' );
 311                  break;
 312              case 2:
 313              // none

 314                  $params->set( 'marker_address', '' );
 315                  $params->set( 'marker_email', '' );
 316                  $params->set( 'marker_telephone', '' );
 317                  $params->set( 'marker_fax', '' );
 318                  $params->set( 'marker_misc', '' );
 319                  $params->set( 'column_width', '0' );
 320                  break;
 321              default:
 322              // icons

 323                  $image1 = mosAdminMenus::ImageCheck( 'con_address.png', '/images/M_images/', $params->get( 'icon_address' ), '/images/M_images/', _CONTACT_ADDRESS, _CONTACT_ADDRESS );
 324                  $image2 = mosAdminMenus::ImageCheck( 'emailButton.png', '/images/M_images/', $params->get( 'icon_email' ), '/images/M_images/', _CONTACT_EMAIL, _CONTACT_EMAIL );
 325                  $image3 = mosAdminMenus::ImageCheck( 'con_tel.png', '/images/M_images/', $params->get( 'icon_telephone' ), '/images/M_images/', _CONTACT_TELEPHONE, _CONTACT_TELEPHONE );
 326                  $image4 = mosAdminMenus::ImageCheck( 'con_fax.png', '/images/M_images/', $params->get( 'icon_fax' ), '/images/M_images/', _CONTACT_FAX, _CONTACT_FAX );
 327                  $image5 = mosAdminMenus::ImageCheck( 'con_info.png', '/images/M_images/', $params->get( 'icon_misc' ), '/images/M_images/', _CONTACT_MISC, _CONTACT_MISC );
 328                  $params->set( 'marker_address', $image1 );
 329                  $params->set( 'marker_email', $image2 );
 330                  $params->set( 'marker_telephone', $image3 );
 331                  $params->set( 'marker_fax', $image4 );
 332                  $params->set( 'marker_misc', $image5 );
 333                  $params->set( 'column_width', '40' );
 334                  break;
 335          }
 336  
 337          // params from menu item

 338          $menu             = $mainframe->get( 'menu' );
 339          $menu_params     = new mosParameters( $menu->params );
 340  
 341          $menu_params->def( 'page_title', 1 );
 342          $menu_params->def( 'header', $menu->name );
 343          $menu_params->def( 'pageclass_sfx', '' );
 344  
 345          HTML_contact::viewcontact( $contact, $params, $count, $list, $menu_params );
 346      } else {
 347          $params = new mosParameters( '' );
 348          $params->def( 'back_button', $mainframe->getCfg( 'back_button' ) );
 349          HTML_contact::nocontact( $params );
 350      }
 351  }
 352  
 353  
 354  function sendmail( $con_id, $option ) {
 355      global $mainframe, $database, $Itemid;
 356      global $mosConfig_sitename, $mosConfig_live_site, $mosConfig_mailfrom, $mosConfig_fromname, $mosConfig_db;
 357  
 358      // simple spoof check security

 359      josSpoofCheck(1);    
 360      
 361      $query = "SELECT *"
 362      . "\n FROM #__contact_details"
 363      . "\n WHERE id = " . (int) $con_id
 364      ;
 365      $database->setQuery( $query );
 366      $contact     = $database->loadObjectList();
 367  
 368      if (count( $contact ) > 0) {
 369          $default     = $mosConfig_sitename.' '. _ENQUIRY;
 370          $email         = strval( mosGetParam( $_POST, 'email',         '' ) );
 371          $text         = strval( mosGetParam( $_POST, 'text',             '' ) );
 372          $name         = strval( mosGetParam( $_POST, 'name',             '' ) );
 373          $subject     = strval( mosGetParam( $_POST, 'subject',         $default ) );
 374          $email_copy = strval( mosGetParam( $_POST, 'email_copy',     0 ) );
 375  
 376          $menu             = $mainframe->get( 'menu' );
 377          $mparams         = new mosParameters( $menu->params );        
 378          $bannedEmail     = $mparams->get( 'bannedEmail',     '' );        
 379          $bannedSubject     = $mparams->get( 'bannedSubject',     '' );        
 380          $bannedText     = $mparams->get( 'bannedText',         '' );        
 381          $sessionCheck     = $mparams->get( 'sessionCheck',     1 );
 382          
 383          // check for session cookie

 384          if  ( $sessionCheck ) {        
 385              // Session Cookie `name`

 386              $sessionCookieName     = mosMainFrame::sessionCookieName();        
 387              // Get Session Cookie `value`

 388              $sessioncookie         = mosGetParam( $_COOKIE, $sessionCookieName, null );            
 389              
 390              if ( !(strlen($sessioncookie) == 32 || $sessioncookie == '-') ) {
 391                  mosErrorAlert( _NOT_AUTH );
 392              }
 393          }            
 394          
 395          // Prevent form submission if one of the banned text is discovered in the email field

 396          if ( $bannedEmail ) {
 397              $bannedEmail = explode( ';', $bannedEmail );
 398              foreach ($bannedEmail as $value) {
 399                  if ( stristr($email, $value) ) {
 400                      mosErrorAlert( _NOT_AUTH );
 401                  }
 402              }
 403          }
 404          // Prevent form submission if one of the banned text is discovered in the subject field        

 405          if ( $bannedSubject ) {
 406              $bannedSubject = explode( ';', $bannedSubject );
 407              foreach ($bannedSubject as $value) {
 408                  if ( stristr($subject, $value) ) {
 409                      mosErrorAlert( _NOT_AUTH );
 410                  }
 411              }
 412          }
 413          // Prevent form submission if one of the banned text is discovered in the text field        

 414          if ( $bannedText ) {
 415              $bannedText = explode( ';', $bannedText );
 416              foreach ($bannedText as $value) {
 417                  if ( stristr($text, $value) ) {
 418                      mosErrorAlert( _NOT_AUTH );
 419                  }
 420              }
 421          }
 422          
 423          // test to ensure that only one email address is entered

 424          $check = explode( '@', $email );
 425          if ( strpos( $email, ';' ) || strpos( $email, ',' ) || strpos( $email, ' ' ) || count( $check ) > 2 ) {
 426              mosErrorAlert( _CONTACT_MORE_THAN );
 427          }
 428          
 429          if ( !$email || !$text || ( JosIsValidEmail( $email ) == false ) ) {
 430              mosErrorAlert( _CONTACT_FORM_NC );
 431          }
 432          $prefix = sprintf( _ENQUIRY_TEXT, $mosConfig_live_site );
 433          $text     = $prefix ."\n". $name. ' <'. $email .'>' ."\n\n". stripslashes( $text );
 434      
 435          $success = mosMail( $email, $name , $contact[0]->email_to, $mosConfig_fromname .': '. $subject, $text );
 436          if (!$success) {
 437              mosErrorAlert( _CONTACT_FORM_NC );
 438          }
 439      
 440          // parameter check

 441          $params = new mosParameters( $contact[0]->params );        
 442          $emailcopyCheck = $params->get( 'email_copy', 0 );
 443              
 444          // check whether email copy function activated

 445          if ( $email_copy && $emailcopyCheck ) {
 446              $copy_text = sprintf( _COPY_TEXT, $contact[0]->name, $mosConfig_sitename );
 447              $copy_text = $copy_text ."\n\n". $text .'';
 448              $copy_subject = _COPY_SUBJECT . $subject;
 449              
 450              $success = mosMail( $mosConfig_mailfrom, $mosConfig_fromname, $email, $copy_subject, $copy_text );
 451              if (!$success) {
 452                  mosErrorAlert( _CONTACT_FORM_NC );
 453              }
 454          }
 455          
 456          $link = sefRelToAbs( 'index.php?option=com_contact&task=view&contact_id='. $contact[0]->id .'&Itemid='. $Itemid );
 457  
 458          mosRedirect( $link, _THANK_MESSAGE );
 459      }
 460  }
 461  
 462  function vCard( $id ) {
 463      global $database;
 464      global $mosConfig_sitename, $mosConfig_live_site;
 465  
 466      $contact    = new mosContact( $database );
 467      $contact->load( (int)$id );    
 468      $params = new mosParameters( $contact->params );
 469      
 470      $show = $params->get( 'vcard', 0 );    
 471      if ( $show ) {    
 472      // check to see if VCard option hsa been activated

 473          $name     = explode( ' ', $contact->name );
 474          $count     = count( $name );
 475      
 476          // handles conversion of name entry into firstname, surname, middlename distinction

 477          $surname    = '';
 478          $middlename    = '';
 479      
 480          switch( $count ) {
 481              case 1:
 482                  $firstname        = $name[0];
 483                  break;
 484      
 485              case 2:
 486                  $firstname         = $name[0];
 487                  $surname        = $name[1];
 488                  break;
 489      
 490              default:
 491                  $firstname         = $name[0];
 492                  $surname        = $name[$count-1];
 493                  for ( $i = 1; $i < $count - 1 ; $i++ ) {
 494                      $middlename    .= $name[$i] .' ';
 495                  }
 496                  break;
 497          }
 498          $middlename    = trim( $middlename );
 499      
 500          $v     = new MambovCard();
 501      
 502          $v->setPhoneNumber( $contact->telephone, 'PREF;WORK;VOICE' );
 503          $v->setPhoneNumber( $contact->fax, 'WORK;FAX' );
 504          $v->setName( $surname, $firstname, $middlename, '' );
 505          $v->setAddress( '', '', $contact->address, $contact->suburb, $contact->state, $contact->postcode, $contact->country, 'WORK;POSTAL' );
 506          $v->setEmail( $contact->email_to );
 507          $v->setNote( $contact->misc );
 508          $v->setURL( $mosConfig_live_site, 'WORK' );
 509          $v->setTitle( $contact->con_position );
 510          $v->setOrg( $mosConfig_sitename );
 511      
 512          $filename    = str_replace( ' ', '_', $contact->name );
 513          $v->setFilename( $filename );
 514      
 515          $output     = $v->getVCard( $mosConfig_sitename );
 516          $filename     = $v->getFileName();
 517      
 518          // header info for page

 519          header( 'Content-Disposition: attachment; filename='. $filename );
 520          header( 'Content-Length: '. strlen( $output ) );
 521          header( 'Connection: close' );
 522          header( 'Content-Type: text/x-vCard; name='. $filename );    
 523          header( 'Cache-Control: store, cache' );
 524          header( 'Pragma: cache' );
 525      
 526          print $output;
 527      } else {
 528          mosNotAuth();  
 529          return;
 530      }
 531  }
 532  ?>


Généré le : Wed Nov 21 14:43:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics