Source for file bookcontact.php

Documentation is available at bookcontact.php

  1. <?php
  2. /**
  3. * Let the user either log in or fill in a contact form to make a booking.
  4. *
  5. @author     Stuart Prescott
  6. @copyright  Copyright Stuart Prescott
  7. @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  8. @version    $Id: bookcontact.php,v 1.7 2007/02/05 23:36:50 themill Exp $
  9. @package    Bumblebee
  10. @subpackage Actions
  11. *
  12. *  path (bumblebee root)/inc/actions/bookcontact.php
  13. */
  14.  
  15. /** Load ancillary functions */
  16. require_once 'inc/typeinfo.php';
  17.  
  18. require_once 'inc/bb/configreader.php';
  19.  
  20. /** uses the login class for the login form */
  21. require_once 'inc/actions/login.php';
  22. /** date/time handline */
  23. require_once 'inc/date.php';
  24.  
  25. /**
  26. * Let the user either log in or fill in a contact form to make a booking.
  27. @package    Bumblebee
  28. @subpackage Actions
  29. */
  30. class ActionBookContact extends ActionAction {
  31.  
  32.   /**
  33.   * Initialising the class
  34.   *
  35.   * @param  BumblebeeAuth $auth  Authorisation object
  36.   * @param  array $pdata   extra state data from the call path
  37.   * @return void nothing
  38.   */
  39.   function ActionBookContact($auth$PDATA{
  40.     parent::ActionAction($auth$PDATA);
  41.     $this->mungeInputData();
  42.   }
  43.  
  44.   function go({
  45.     if (isset($this->PD['contactme']&& $this->readOnly{
  46.       $this->sendContactRequest();
  47.     else {
  48.       // show both a contact form and a change-user form
  49.       $this->showContactLoginForm();
  50.     }
  51.   }
  52.  
  53.   function sendContactRequest({
  54.     if ($this->sendEmail()) {
  55.       echo '<div>'
  56.           .T_('Thank you for your enquiry; it will be dealt with soon.')
  57.           .'</div>';
  58.     else {
  59.       echo '<div>'
  60.           .T_('I\'m sorry, I couldn\'t send your request. Please try again or contact the system administrator directly.')
  61.           .'</div>';
  62.     }
  63.   }
  64.  
  65.   function sendEmail({
  66.     $conf ConfigReader::getInstance();
  67.     $instrument quickSQLSelect('instruments''id'$this->PD['contact-instrid']);
  68.     $emails array();
  69.     if (empty($instrument['supervisors'])) {
  70.       $emails[0$conf->AdminEmail;
  71.     else {
  72.       foreach(preg_split('/,\s*/'$instrument['supervisors']as $username{
  73.         preDump($username);
  74.         $user quickSQLSelect('users''username'$username);
  75.         $emails[$user['email'];
  76.       }
  77.     }
  78.  
  79.     $eol "\r\n";
  80.     $from $instrument['name'].' '.$conf->value('instruments''emailFromName')
  81.             .' <'.$conf->value('main''SystemEmail').'>';
  82.     $replyto $this->PD['contact-name'].' <'.$this->PD['contact-email'].'>';
  83.     $to   join($emails',');
  84.     srand(time());
  85.     $id   '<bumblebee-'.time().'-'.rand().'@'.$_SERVER['SERVER_NAME'].'>';
  86.  
  87.     $headers  'From: '.$from .$eol;
  88.     $headers .= 'Reply-To: '.$replyto.$eol;
  89.     $headers .= 'Message-id: ' .$id .$eol;
  90.     $subject $instrument['name']': '($conf-value('instruments''emailSubject')
  91.                     ? $conf->value('instruments''emailSubject''Instrument booking notification');
  92.     $message $this->_getEmailText($this->PD);
  93.  
  94.     $ok mail($to$subject$message$headers);
  95.  
  96.     return $ok;
  97.  
  98.   }
  99.  
  100.   function _getEmailText($data{
  101.     $conf ConfigReder::getInstance();
  102.     $fh fopen($conf->value('instruments''emailRequestTemplate')'r');
  103.     $txt fread($fhfilesize($conf->value('instruments''emailRequestTemplate')));
  104.     fclose($fh);
  105.     $replace array(
  106.             '/__instrumentname__/'      => $data['contact-instrument'],
  107.             '/__start__/'               => $data['contact-start'],
  108.             '/__finish__/'              => $data['contact-stop'],
  109.             '/__name__/'                => $data['contact-name'],
  110.             '/__email__/'               => $data['contact-email'],
  111.             '/__phone__/'               => $data['contact-phone'],
  112.             '/__organisation__/'        => $data['contact-organisation'],
  113.             '/__comments__/'            => $data['contact-comments'],
  114.             '/__host__/'                => makeAbsURL()
  115.                     );
  116.     $txt preg_replace(array_keys($replace),
  117.                         array_values($replace),
  118.                         $txt);
  119.     return $txt;
  120.   }
  121.  
  122.  
  123.   function showContactLoginForm({
  124.     echo '<p>'
  125.         .T_('Please login to continue or use this form to send us an email to request the instrument')
  126.         .'</p>';
  127.  
  128.     echo '<fieldset>';
  129.     echo '<h2>Login details</h2>';
  130.     $data $this->PD;
  131.     $data['changeuser']=1;
  132.     echo '<input type="hidden" name="changeuser" value="1" />';
  133.     echo '<input type="hidden" name="forceaction" value="book" />';
  134.     echo '</fieldset>';
  135.  
  136.     echo '<br /><br />';
  137.     echo formEnd();
  138.     echo formStart(makeURL('bookcontact')$auth->makeValidationTag()'contactform'false);
  139.  
  140.     echo '<fieldset>';
  141.     echo '<h2>Contact us</h2>';
  142.     $this->printContactForm();
  143.     echo '</fieldset>';
  144.  
  145.     echo '<br /><br />';
  146.   }
  147.  
  148.   function printContactForm({
  149.     $instrument $this->PD['instrid'];
  150.     $row quickSQLSelect('instruments''id'$instrument);
  151.     $start new SimpleDate($this->PD['startticks']);
  152.     $stop  new SimpleDate($this->PD['stopticks']);
  153.  
  154.     printf ('<input type="hidden" name="contact-instrid" value="%s" />'$instrument);
  155.     print  '<table>';
  156.     printf ('<tr><td>%s</td><td><input type="text" name="contact-name" /></td></tr>'T_('Name'));
  157.     printf ('<tr><td>%s</td><td><input type="text" name="contact-email" /></td></tr>'T_('Email address'));
  158.     printf ('<tr><td>%s</td><td><input type="text" name="contact-phone" /></td></tr>'T_('Phone'));
  159.     printf ('<tr><td>%s</td><td><input type="text" name="contact-organisation" /></td></tr>'T_('Organisation'));
  160.     printf ('<tr><td>%s</td><td><input type="hidden" name="contact-instrument" value="%s" />%s</td></tr>'T_('Instrument')$row['longname']$row['longname']);
  161.     printf ('<tr><td>%s</td><td><input type="hidden" name="contact-start" value="%s" />%s</td></tr>'T_('Start time')$start->datetimestring()$start->datetimestring());
  162.     printf ('<tr><td>%s</td><td><input type="hidden" name="contact-stop" value="%s" />%s</td></tr>'T_('Finish')$stop->datetimestring()$stop->datetimestring());
  163.     printf ('<tr><td>%s</td><td><textarea rows="10" cols="40" name="contact-comments"></textarea></td></tr>'T_('Comments'));
  164.     printf ('<tr><td></td><td><input type="submit" name="contactme" value="%s" /></td></tr>'T_('Send requeset'));
  165.     print '</table>';
  166.   }
  167.  
  168.  
  169. // class ActionView
  170.  
  171. ?>

Documentation generated on Tue, 06 Mar 2007 10:00:46 +0000 by phpDocumentor 1.3.0