forms
[ class tree: forms ] [ index: forms ] [ all elements ]

Source for file ContactForm.class.php

Documentation is available at ContactForm.class.php

  1. <?php
  2. /**
  3.  * For including this file you have to define the constant "CLASSPATH".
  4.  * Because every include in the framework depends on the CLASSPATH definition.
  5.  * The CLASSPATH means the relative path to the folder that contains the
  6.  * framework GilliGan.
  7.  *
  8.  * @package forms
  9.  */
  10. if!defined"CLASSPATH" ) )
  11. {
  12.   echo "<h3>You have to define the constant CLASSPATH!</h3>\n";
  13.   echo "Example: define( 'CLASSPATH', '../path/to/classes/' );\n";
  14.   exit();
  15. }
  16.  
  17. /**
  18.  * Including the basic class to define html forms.
  19.  */
  20. require_onceCLASSPATH."forms/HTMLForm.class.php" );
  21. /**
  22.  * Including a set of regular expressions defined in contants.
  23.  */
  24. require_onceCLASSPATH."RegExpConstants.inc.php" );
  25. /**
  26.  * Including a set of regular expressions defined in contants.
  27.  */
  28. require_onceCLASSPATH."communication/EMail.class.php" );
  29.  
  30. /**
  31.  * A class to generate contact forms. After submit there will be generate a
  32.  * plaintext email to a recipient.
  33.  * You also can use this class for an object of an e-mail, with all its
  34.  * necessary information.
  35.  * If you add an e-mail address as target, you should know that you can do it in
  36.  * two different ways. You can only declare a plain e-mail address such as
  37.  * "nobody@nowhere.no" or you can additionally declare some Information such as
  38.  * name of the receiver. In this case you have to enclose the e-mail address
  39.  * in brackets like "<>". The full example is
  40.  * "\"Firstname Surname\" <nobody@nowhere.no>".
  41.  *
  42.  * @package   forms
  43.  * @version   0.2.0
  44.  * @since     0.4.5.6
  45.  * @author    Daniel Plücken <daniel@debakel.net>
  46.  * @license   http://www.gnu.org/copyleft/lesser.html
  47.  *             GNU Lesser General Public License
  48.  * @copyright Copyright (C) 2003 Daniel Plücken <daniel@debakel.net>
  49.  *
  50.  *  This library is free software; you can redistribute it and/or
  51.  *  modify it under the terms of the GNU Lesser General Public
  52.  *  License as published by the Free Software Foundation; either
  53.  *  version 2.1 of the License.
  54.  *
  55.  *  This library is distributed in the hope that it will be useful,
  56.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  57.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  58.  *  GNU Lesser General Public License for more details.
  59.  *
  60.  *  You should have received a copy of the GNU Lesser General
  61.  *  Public License along with this library; if not, write to the
  62.  *  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  63.  *  Boston, MA 02111-1307 USA
  64.  */
  65. class ContactForm extends HTMLForm
  66. {
  67.     /**
  68.      * Reference to the email-object which should be send.
  69.      * 
  70.      * @var    EMail  $email_obj 
  71.      * @access public
  72.      */
  73.     var $email_obj = "";
  74.  
  75.  
  76.  
  77.     /**
  78.      * Constructor
  79.      *
  80.      * @version 1.1
  81.      * @since   0.1.0
  82.      * @author  Daniel Plücken <daniel@debakel.net>
  83.      * @access  public
  84.      * @param   string $email 
  85.      * @param   string $name 
  86.      * @param   string $onSubmitOrder 
  87.      * @param   string $targetFile 
  88.      * @param   string $method 
  89.      */
  90.     function ContactForm(
  91.                           $email,
  92.                           $name          "DP_form",
  93.                           $onSubmitOrder "",
  94.                           $targetFile    "",
  95.                           $method        "POST"
  96.                         )
  97.     {
  98.       $this->email_obj = new EMail$email );
  99.       $this->HTMLForm$name$onSubmitOrder$targetFile$method );
  100.     }
  101.  
  102.  
  103.  
  104.     /**
  105.      * Returns the stored email.
  106.      *
  107.      * @version 1.1
  108.      * @since   0.1.0
  109.      * @author  Daniel Plücken <daniel@debakel.net>
  110.      * @access  public
  111.      * @return  string 
  112.      */
  113.     function getTargetEmail()
  114.     return $this->email_obj->getTargetEmail()}
  115.  
  116.  
  117.  
  118.     /**
  119.      * Stores the email where the message should be send.
  120.      *
  121.      * @version 1.0
  122.      * @since   0.1.0
  123.      * @author  Daniel Plücken <daniel@debakel.net>
  124.      * @access  public
  125.      * @param   string $string 
  126.      * @return  void 
  127.      */
  128.     function setTargetEmail$string )
  129.     $this->email_obj->setTargetEmail$string )}
  130.  
  131.  
  132.  
  133.     /**
  134.      * Adds an email to the array of emails where the message should be send in
  135.      * copy.
  136.      *
  137.      * @version 1.1
  138.      * @since   0.1.8
  139.      * @author  Daniel Plücken <daniel@debakel.net>
  140.      * @access  public
  141.      * @param   string $string 
  142.      * @return  void 
  143.      */
  144.     function addTargetEmailCopy$string )
  145.     $this->email_obj->addTargetEmailCopy$string )}
  146.  
  147.  
  148.  
  149.     /**
  150.      * Stores the emails where the message should be send in copy.
  151.      *
  152.      * @version 1.1
  153.      * @since   0.1.8
  154.      * @author  Daniel Plücken <daniel@debakel.net>
  155.      * @access  public
  156.      * @param   array  $array 
  157.      * @return  void 
  158.      */
  159.     function setTargetEmailCopyArray$array )
  160.     $this->email_obj->setTargetEmailCopyArray$array )}
  161.  
  162.  
  163.  
  164.     /**
  165.      * Adds an email to the array of emails where the message should be send in
  166.      * blind copy.
  167.      *
  168.      * @version 1.1
  169.      * @since   0.1.8
  170.      * @author  Daniel Plücken <daniel@debakel.net>
  171.      * @access  public
  172.      * @param   string $string 
  173.      * @return  void 
  174.      */
  175.     function addTargetEmailBlindCopy$string )
  176.     $this->email_obj->addTargetEmailBlindCopy$string )}
  177.  
  178.  
  179.  
  180.     /**
  181.      * Stores the emails where the message should be send in blind copy.
  182.      *
  183.      * @version 1.1
  184.      * @since   0.1.8
  185.      * @author  Daniel Plücken <daniel@debakel.net>
  186.      * @access  public
  187.      * @param   array  $array 
  188.      * @return  void 
  189.      */
  190.     function setTargetEmailBlindCopyArray$array )
  191.     $this->email_obj->setTargetEmailBlindCopyArray$array )}
  192.  
  193.  
  194.  
  195.     /**
  196.      * Sends the email with values of the form to the addressee stored in
  197.      * $this->target_email.
  198.      *
  199.      * @version 1.1
  200.      * @since   0.1.8
  201.      * @author  Daniel Plücken <daniel@debakel.net>
  202.      * @access  public
  203.      * @param   string  $sender_email 
  204.      * @param   string  $subject 
  205.      * @param   string  $content 
  206.      * @return  boolean 
  207.      */
  208.     function send$sender_email$subject$content "" )
  209.     return $this->email_obj->send$sender_email$subject$content )}
  210.  
  211.  
  212.  
  213.     /**
  214.      * Generates the sourcecode to build this object and returns it.
  215.      *
  216.      * @version 1.0
  217.      * @since   0.1.2
  218.      * @author  Daniel Plücken <daniel@debakel.net>
  219.      * @access  public
  220.      * @return  string 
  221.      */
  222.     function getPHPSource()
  223.     {
  224.       // Setting layout table
  225.       if!empty$this->layoutTable ) )
  226.         $out $this->layoutTable->getPHPSource()."\n\n";
  227.       
  228.       for$i 0$i count$this->formItems )$i++ )
  229.         $out .= $this->formItems[$i]->getPHPSource()."\n\n";
  230.       
  231.       $out .= "\x24targetemail = \"".$this->getTargetEmail()."\";\n";
  232.       $out .= "\x24formname = \"".$this->getName()."\";\n";
  233.       /*
  234.       $out .= !empty( $this->getSubmitOrder() )
  235.                     ? "\x24onSubmitOrder = \"".$this->getSubmitOrder()."\";\n"
  236.                     : "";
  237.       $out .= !empty( $this->getTargetFile() )
  238.                     ? "\x24targetFile    = \"".$this->getTargetFile()."\";\n"
  239.                     : "";
  240.       $out .= !empty( $this->getMethod() )
  241.                     ? "\x24method        = \"".$this->getMethod()."\";\n"
  242.                     : ""; */
  243.       
  244.       $out .= "\x24form = new ContactForm(\n"
  245.                    ."                          \x24targetemail,\n"
  246.                    ."                          \x24name,\n"
  247.                    ."                          \x24onSubmitOrder,\n"
  248.                    ."                          \x24targetFile,\n"
  249.                    ."                          \x24method \n"
  250.                    ."                       );\n\n";
  251.       $out .= $this->getItemPHPSource();
  252.       
  253.       return $out;
  254.     }
  255.  
  256.  
  257.  
  258.     /**
  259.      * Returns a generated string based on the Attributes of this HTML-Object.
  260.      *
  261.      * @version 1.0
  262.      * @since   0.1.0
  263.      * @author  Daniel Plücken <daniel@debakel.net>
  264.      * @access  public
  265.      * @param   HTMLTable $obj_ref  A reference of a table by dint of the form
  266.      *                               should be formatted. The form items will be
  267.      *                               placed in the table where the string "[item]"
  268.      *                               appears.
  269.      * @param   boolean   $php_code Is this parameter true, the form will be
  270.      *                               returned as the source-php-code of this
  271.      *                               object.
  272.      * @return  string 
  273.      */
  274.     function get()
  275.     {
  276.        $param func_get_args();
  277.        
  278.        $out  "";
  279.        if(
  280.            strtoupper$param[2== "POST"
  281.         || strtoupper$param[2== "GET"
  282.          )
  283.        {
  284.           for$i 0$i count$this->formItems )$i++ )
  285.              switchget_class$this->formItems[$i) )
  286.              {
  287.                 case "resetsubmitbutton":
  288.                      $tmp $this->formItems[$i]->getNameOfSubmitButton();
  289.                      break;
  290.                 case "htmlsubmitbutton":
  291.                      $tmp $this->formItems[$i]->getName();
  292.                      break;
  293.                 case "htmlresetbutton":
  294.                      break;
  295.                 default:
  296.                      $tmpItNa[$this->formItems[$i]->getName();
  297.                      break;
  298.              }
  299.           
  300.           $out .= "<?php\n";
  301.           $out .= "if( !empty( \x24_".strtoupper$param[2)
  302.                              ."['".$tmp."'] ) )\n";
  303.           $out .= "{\n";
  304.           $out .= "   \x24mailbody = \"\";\n";
  305.           $out .= "   \x24date = date( \"d.m.Y\", mktime( 0, 0, 0, "
  306.                         ."date( \"m\" ), date( \"d\" ), date( \"Y\" ) ) );\n";
  307.           $out .= "   \x24ip   = getenv( \"REMOTE_ADDR\" );\n";
  308.           $out .= "   \x24host = gethostbyaddr( \x24ip );\n\n";
  309.           $out .= "   \x24mailbody .= \"IP: \".\x24host.\" "
  310.                                       ."Datum:\".\x24date.\"\\n\";\n\n";
  311.           for$i 0$i count$tmpItNa )$i++ )
  312.           {
  313.              $out .= "   if( !empty( \x24_".strtoupper$param[2)
  314.                                    ."['".$tmpItNa[$i]."'] ) )\n";
  315.              $out .= "      \x24mailbody .= \"".PlainTextFormatter
  316.                                         ::firstToUpper$tmpItNa[$i).": \""
  317.                                           .".\x24_".strtoupper$param[2)
  318.                                     ."['".$tmpItNa[$i]."'].\"\\n\";\n";
  319.           }
  320.           
  321.           $out .= "\n   \x24receiver = \"".$this->targetEmail."\";\n";
  322.           $out .= "   \x24subject  = \"".$this->subject."\";\n\n";
  323.           $out .= "   \x24res = mail( \x24receiver, "
  324.                                     ."\x24subject, "
  325.                                     ."\x24mailbody );\n\n";
  326.           $out .= "   if( \x24res )\n";
  327.           $out .= "   { # eMail erfolgreich versendet\n";
  328.           $out .= "?>\n";
  329.           $out .= "       Vielen Dank f&uuml;r Ihre Mitteilung.<br>\n";
  330.           $out .= "       Wir werden uns umgehend bei Ihnen melden.\n";
  331.           $out .= "<?php\n";
  332.           $out .= "   }  # ENDE eMail erfolgreich versendet\n";
  333.           $out .= "   else\n";
  334.           $out .= "   { # falls eMail nicht versendet werden konnte\n";
  335.           $out .= "?>\n";
  336.           $out .= "       Leider ist ein &uuml;bertragungsfehler beim "
  337.                         ."versenden Ihrer Mitteilung aufgetreten.<br>\n";
  338.           $out .= "       Bitte versuchen Sie es erneut.<br><br>\n";
  339.           $out .= "       <a href=\"javascript:document.history.back();\">"
  340.                         ."zur&uuml;ck</a>\n";
  341.           $out .= "<?php\n";
  342.           $out .= "   } # ENDE falls eMail nicht versendet werden konnte\n";
  343.           $out .= "}\n";
  344.           $out .= "else\n";
  345.           $out .= "{\n";
  346.           $out .= "?>\n";
  347.        }
  348.        
  349.        # normal form
  350.        $out .= parent::get$param[0]$param[1]$param[2);
  351.        
  352.        if(
  353.            strtoupper$param[2== "POST"
  354.         || strtoupper$param[2== "GET"
  355.          )
  356.        {
  357.           $out .= "<?php\n";
  358.           $out .= "}\n";
  359.           $out .= "?>\n";
  360.        }
  361.        
  362.        return $out;
  363.     }
  364. // End of class ContactForm
  365. ?>

Documentation generated on Thu, 05 Jun 2008 19:10:27 +0200 by phpDocumentor 1.4.1