Source for file contact.php

Documentation is available at contact.php

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

Documentation generated on Mon, 05 May 2008 16:18:13 +0400 by phpDocumentor 1.4.0