Source for file emaillist.php

Documentation is available at emaillist.php

  1. <?php
  2. /**
  3. * email lists for instrument users
  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$
  9. @package    Bumblebee
  10. @subpackage Actions
  11. *
  12. *  path (bumblebee root)/inc/actions/emaillist.php
  13. */
  14.  
  15. /** Load ancillary functions */
  16. require_once 'inc/typeinfo.php';
  17.  
  18. /** TextBox object */
  19. require_once 'inc/formslib/textfield.php';
  20. /** CheckBox object */
  21. require_once 'inc/formslib/checkbox.php';
  22. /** CheckBoxTableList object */
  23. require_once 'inc/formslib/checkboxtablelist.php';
  24. /** db interrogation list object */
  25. require_once 'inc/formslib/dblist.php';
  26. /** form object */
  27. require_once 'inc/formslib/nondbrow.php';
  28. /** export status codes and formats */
  29. require_once 'inc/export/exporttypes.php';
  30. /** parent object */
  31. require_once 'inc/actions/actionaction.php';
  32.  
  33.  
  34. /**
  35. * Generate a list of email addresses for users of particular instruments
  36. *
  37. * An Action to find out what instruments the lists should be prepared for
  38. * and then return the email list.
  39. * Designed to be use as a per instrument "announce" list.
  40. *
  41. @todo //TODO: should this class should be split some more, with some of the details abstracted?
  42. @package    Bumblebee
  43. @subpackage Actions
  44. */
  45. class ActionEmailList extends ActionAction {
  46.   /**
  47.   * forces SQL errors to be fatal
  48.   * @var    boolean 
  49.   */
  50.   var $fatal_sql = 1;
  51.  
  52.   /**
  53.   * Initialising the class
  54.   *
  55.   * @param  BumblebeeAuth $auth  Authorisation object
  56.   * @param  array $pdata   extra state data from the call path
  57.   * @return void nothing
  58.   */
  59.   function ActionEmailList($auth$pdata{
  60.     parent::ActionAction($auth$pdata);
  61.     $this->mungeInputData();
  62.   }
  63.  
  64.   function go({
  65.     if (isset($this->PD['selectlist'])) {
  66.       $this->selectLists();
  67.     else {
  68.       $this->returnLists();
  69.     }
  70.   }
  71.  
  72.   /**
  73.   * Generate an HTML form for the user to select which email lists should be used
  74.   *
  75.   * - do DB look-ups on what instruments exist
  76.   * - construct a table of checkboxes to allow the user to select the lists
  77.   *
  78.   * @return void nothing
  79.   */
  80.   function selectLists({
  81.     $selectRow new nonDBRow('listselect'T_('Select email lists'),
  82.               T_('Select which email lists you want to return'));
  83.     $select new CheckBoxTableList(T_('Instrument')T_('Select which instrument to view'));
  84.     $hidden new TextField('instrument');
  85.     $select->addFollowHidden($hidden);
  86.     $announce new CheckBox('announce'T_('Announce'));
  87.     $select->addCheckBox($announce);
  88.     $unbook new CheckBox('unbook'T_('Unbook'));
  89.     $select->addCheckBox($unbook);
  90.     //$select->numSpareCols = 1;
  91.     $select->connectDB('instruments'array('id''name''longname'));
  92.     $select->setFormat('id''%s'array('name')" %50.50s"array('longname'));
  93.     $select->addSelectAllFooter(true);
  94.     $selectRow->addElement($select);
  95.     $separator new TextField('separator'T_('Value separator'),
  96.                 T_('Separates the returned values so you can paste them into your email client'));
  97.     $separator->defaultValue ',';
  98.     $separator->setattr(array('size' => '2'));
  99.     $selectRow->addElement($separator);
  100.     echo $selectRow->displayInTable(4);
  101.     echo '<input type="hidden" name="selectlist" value="1" />';
  102.     echo '<input type="submit" name="submit" value="'.T_('Select').'" />';
  103.   }
  104.  
  105.  
  106.   /**
  107.   * Generate the email lists
  108.   *
  109.   * - work out which instruments the user has requested for inclusion
  110.   * - construct an SQL query to get the email list
  111.   * - return the formatted data to the user
  112.   *
  113.   * @return void nothing
  114.   */
  115.   function returnLists({
  116.     $where array('0');  //start the WHERE with 0 in case nothing was selected (always get valid SQL)
  117.     $namebase 'Instrument-';
  118.     for ($j=0isset($this->PD[$namebase.$j.'-row'])$j++{
  119.       $instr issetSet($this->PD,$namebase.$j.'-instrument');
  120.       //echo "$j ($instr) => ($unbook, $announce)<br />";
  121.       if (issetSet($this->PD,$namebase.$j.'-announce')) {
  122.         $where[='(permissions.instrid='.qw($instr).' AND permissions.announce='.qw(1).')' ;
  123.       }
  124.       if (issetSet($this->PD,$namebase.$j.'-unbook')) {
  125.         $where['(permissions.instrid='.qw($instr).' AND permissions.unbook='.qw(1).')' ;
  126.       }
  127.     }
  128.     #echo "Gathering email addresses: $q<br />";
  129.     $fields array(new sqlFieldName('email''Email Address'));
  130.     $restriction 'users.deleted<>1 AND (' .join($where' OR ')')';  //don't return deleted users
  131.     $list new DBList('permissions'$fields$restrictiontrue);
  132.     $list->join[(array('table' => 'users''condition' => 'users.id=permissions.userid'));
  133.     $list->setFormat('%s'array('email'));
  134.     $list->fill();
  135.     if (count($list->data== 0{
  136.       echo '<p>No email addresses found</p>';
  137.     else {
  138.       $list->formatList();
  139.       $this->PD['separator'stripslashes($this->PD['separator']);
  140.       if ($this->PD['separator'== '\n'{
  141.         $this->PD['separator'"\n";
  142.       elseif ($this->PD['separator'== '\t'{
  143.         $this->PD['separator'"\t";
  144.       }
  145.       echo join(array_xssqw($list->formatdata)xssqw($this->PD['separator']).'<br />');
  146.     }
  147.   }
  148.  
  149. }
  150. ?>

Documentation generated on Tue, 06 Mar 2007 10:01:24 +0000 by phpDocumentor 1.3.0