mattshepherd

Dagon Design PHP Mailer Test

Aug 31st, 2012
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 53.53 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. $path_to_css = 'dd-formmailer.css';
  5. $language = 'lang/English.php';
  6. $script_path = 'http://www.[redacted].com/upload/dd-formmailer.php';
  7. $path_contact_page = '';
  8. $recipients = 'mass@[redacted].com';
  9. $form_struct = '
  10.     type=text|class=fmtext|label=Name|fieldname=fm_name|max=100|req=true
  11.     type=text|class=fmtext|label=Email|fieldname=fm_email|max=100|req=true|ver=email
  12.     type=text|class=fmtext|label=Subject|fieldname=fm_subject|max=100|req=true
  13.     type=verify|class=fmverify|label=Verify
  14.     type=textarea|class=fmtextarea|label=Photo Description|fieldname=fm_message|max=1000|rows=6|req=true
  15.    type=file|class=|label=|fieldname=|[req=true]|[allowed=png,jpg,gif]
  16. ';
  17. $manual_form_code = '';
  18. $wrap_messages = TRUE;
  19. $attach_save = TRUE;
  20. $attach_path = '/home/[redacted]/webapps/shep/upload/photos/';
  21. $show_required = TRUE;
  22. $show_url = FALSE;
  23. $show_ip_hostname = TRUE;
  24. $sender_name = 'fm_name';
  25. $sender_email = 'fm_email';
  26. $email_subject = 'Contact: fm_subject';
  27. $max_file_size = 1000000; // in bytes
  28. $message_structure = '';
  29. $sent_message = '<p style="color:red">Thank you - your message has been sent.</p>';
  30. $auto_reply_name = '';
  31. $auto_reply_email = '';
  32. $auto_reply_subject = '';
  33. $auto_reply_message = '';
  34. $verify_method = 'off'; // 'off', 'basic', or 'recaptcha'
  35. $verify_background = 'F0F0F0';  // hex code for background color
  36. $verify_text = '005ABE';        // hex code for text color
  37. $force_type = '';  
  38. $save_to_file = TRUE;
  39. $save_email = TRUE;
  40. $save_path = 'data.txt';
  41. $save_delimiter = '|';
  42. $save_newlines = "<br>";
  43. $save_timestamp = "m-d-Y h:i:s A";
  44.  
  45.  
  46.  
  47. /*
  48. ** END OF OPTIONS
  49. */
  50.  
  51.  
  52. if (!defined('PHP_EOL')) define ('PHP_EOL', strtoupper(substr(PHP_OS,0,3) == 'WIN') ? "\r\n" : "\n");
  53.  
  54.  
  55. if (trim($path_contact_page) == '') {
  56.     $path_contact_page = $script_path;
  57. }
  58.  
  59. $verify_method = strtolower($verify_method);
  60.  
  61.  
  62. /* Convert hex color code to R, G, B */
  63. function ddfm_hex_to_rgb($h) {
  64.     $h = trim($h, "#");
  65.     $color = array();  
  66.     if (strlen($h) == 6) {
  67.         $color[] = (int)hexdec(substr($h, 0, 2));
  68.         $color[] = (int)hexdec(substr($h, 2, 2));
  69.         $color[] = (int)hexdec(substr($h, 4, 2));
  70.     } else if (strlen($h) == 3) {
  71.         $color[] = (int)hexdec(substr($h, 0, 1) . substr($h, 0, 1));
  72.         $color[] = (int)hexdec(substr($h, 1, 1) . substr($h, 1, 1));
  73.         $color[] = (int)hexdec(substr($h, 2, 1) . substr($h, 2, 1));
  74.     }
  75.     return $color;
  76. }
  77.  
  78.  
  79.  
  80. /* Handle requests for verification code */
  81. if (isset($_GET['v'])) {
  82.     if ($_GET['v'] == '1') {
  83.  
  84.         $this_domain = preg_replace("/^www\./", "", $_SERVER['HTTP_HOST']);
  85.  
  86.         // Choose image type
  87.         $type = '';
  88.         if (function_exists("imagegif")) {
  89.             $type = 'gif';
  90.         } else if (function_exists("imagejpeg")) {
  91.             $type = 'jpeg';
  92.         } else if (function_exists("imagepng")) {
  93.             $type = 'png';
  94.         }
  95.  
  96.         if (trim($force_type) != '') {
  97.             $type = $force_type;
  98.         }
  99.  
  100.         // Generate verification code
  101.         srand((double)microtime()*1000000);
  102.         $ddfmcode = substr(strtoupper(md5(rand(0, 999999999))), 2, 5);
  103.         $ddfmcode = str_replace("O", "A", $ddfmcode); // for clarity
  104.         $ddfmcode = str_replace("0", "B", $ddfmcode);
  105.         setcookie("ddfmcode", md5($ddfmcode), time()+3600, '/', '.' . $this_domain);
  106.  
  107.         // Generate image
  108.         header("Content-type: image/" . $type);
  109.         header("Cache-Control: no-store, no-cache, must-revalidate");
  110.         header("Cache-Control: post-check=0, pre-check=0", false);
  111.         header("Pragma: no-cache");
  112.         header("Expires: Mon, 1 Jan 2000 01:00:00 GMT"); // Date in the past
  113.         $image = imagecreate(60, 24);
  114.  
  115.         list($br, $bg, $bb) = ddfm_hex_to_rgb($verify_background);
  116.         list($rr, $rg, $rb) = ddfm_hex_to_rgb($verify_text);
  117.  
  118.         $background_color = imagecolorallocate($image, $br, $bg, $bb);
  119.         $text_color = imagecolorallocate($image, $rr, $rg, $rb);
  120.  
  121.         imagestring($image, 5, 8, 4, $ddfmcode, $text_color);
  122.  
  123.         switch ($type) {
  124.             case 'gif': imagegif($image); break;
  125.             case 'png': imagepng($image); break;
  126.             case 'jpeg': imagejpeg($image, NULL, 100); break;
  127.         }      
  128.         imagedestroy($image);
  129.  
  130.         exit();
  131.     }
  132. }
  133.  
  134.  
  135. // Load language settings
  136. @include_once($language);
  137.  
  138.  
  139. /* Check for GD support */
  140. function ddfm_check_gd_support() {
  141.     if (extension_loaded("gd") && (function_exists("imagegif") || function_exists("imagepng") || function_exists("imagejpeg"))) {
  142.         return TRUE;
  143.     } else {
  144.         return FALSE;
  145.     }
  146. }
  147.  
  148. /* Safe str_replace */
  149. function ddfm_str_replace($search, $replace, $subject) {
  150.     if (isset($search)) {
  151.         return str_replace($search, $replace, $subject);
  152.     } else {
  153.         return $subject;
  154.     }
  155. }
  156.  
  157. /* Check for valid URL */
  158. function ddfm_is_valid_url($link) {
  159.     if (strpos($link, "http://") === FALSE) {
  160.         $link = "http://" . $link;
  161.     }
  162.     $url_parts = @parse_url($link);
  163.     if (empty($url_parts["host"]))
  164.         return( false );
  165.     if (!empty($url_parts["path"])) {
  166.         $documentpath = $url_parts["path"];
  167.     } else {
  168.         $documentpath = "/";
  169.     }
  170.     if (!empty($url_parts["query"])) {
  171.         $documentpath .= "?" . $url_parts["query"];
  172.     }
  173.     $host = $url_parts["host"];
  174.     $port = $url_parts["port"];
  175.     if (empty($port))
  176.         $port = "80";
  177.     $socket = @fsockopen( $host, $port, $errno, $errstr, 30 );
  178.     if (!$socket) {
  179.         return(false);
  180.     } else  {
  181.         fwrite ($socket, "HEAD ".$documentpath." HTTP/1.0\r\nHost: $host\r\nUser-Agent: DDFMVerify\r\n\r\n");
  182.         $http_response = fgets( $socket, 22 );
  183.         if (ereg("200 OK", $http_response, $regs)) {
  184.             return(true);
  185.             fclose($socket);
  186.         } else {
  187.             return(false);
  188.         }
  189.     }
  190. }
  191.  
  192.  
  193. /* Check for valid email address */
  194. function dd_is_valid_email($email) {
  195.  
  196.     $validator = new EmailAddressValidator;
  197.     if ($validator->check_email_address($email)) {
  198.         return TRUE;
  199.     } else {
  200.         return FALSE;
  201.     }
  202. }
  203.  
  204.     /*
  205.         EmailAddressValidator Class
  206.         http://code.google.com/p/php-email-address-validation/
  207.  
  208.         Released under New BSD license
  209.         http://www.opensource.org/licenses/bsd-license.php
  210.     */
  211.  
  212.     class EmailAddressValidator {
  213.  
  214.         /**
  215.          * Check email address validity
  216.          * @param   strEmailAddress     Email address to be checked
  217.          * @return  True if email is valid, false if not
  218.          */
  219.          function check_email_address($strEmailAddress) {
  220.            
  221.             // If magic quotes is "on", email addresses with quote marks will
  222.             // fail validation because of added escape characters. Uncommenting
  223.             // the next three lines will allow for this issue.
  224.             //if (get_magic_quotes_gpc()) {
  225.             //    $strEmailAddress = stripslashes($strEmailAddress);
  226.             //}
  227.  
  228.             // Control characters are not allowed
  229.             if (preg_match('/[\x00-\x1F\x7F-\xFF]/', $strEmailAddress)) {
  230.                 return false;
  231.             }
  232.  
  233.             // Split it into sections using last instance of "@"
  234.             $intAtSymbol = strrpos($strEmailAddress, '@');
  235.             if ($intAtSymbol === false) {
  236.                 // No "@" symbol in email.
  237.                 return false;
  238.             }
  239.             $arrEmailAddress[0] = substr($strEmailAddress, 0, $intAtSymbol);
  240.             $arrEmailAddress[1] = substr($strEmailAddress, $intAtSymbol + 1);
  241.  
  242.             // Count the "@" symbols. Only one is allowed, except where
  243.             // contained in quote marks in the local part. Quickest way to
  244.             // check this is to remove anything in quotes.
  245.             $arrTempAddress[0] = preg_replace('/"[^"]+"/'
  246.                                              ,''
  247.                                              ,$arrEmailAddress[0]);
  248.             $arrTempAddress[1] = $arrEmailAddress[1];
  249.             $strTempAddress = $arrTempAddress[0] . $arrTempAddress[1];
  250.             // Then check - should be no "@" symbols.
  251.             if (strrpos($strTempAddress, '@') !== false) {
  252.                 // "@" symbol found
  253.                 return false;
  254.             }
  255.  
  256.             // Check local portion
  257.             if (!$this->check_local_portion($arrEmailAddress[0])) {
  258.                 return false;
  259.             }
  260.  
  261.             // Check domain portion
  262.             if (!$this->check_domain_portion($arrEmailAddress[1])) {
  263.                 return false;
  264.             }
  265.  
  266.             // If we're still here, all checks above passed. Email is valid.
  267.             return true;
  268.  
  269.         }
  270.  
  271.         /**
  272.          * Checks email section before "@" symbol for validity
  273.          * @param   strLocalPortion     Text to be checked
  274.          * @return  True if local portion is valid, false if not
  275.          */
  276.          function check_local_portion($strLocalPortion) {
  277.             // Local portion can only be from 1 to 64 characters, inclusive.
  278.             // Please note that servers are encouraged to accept longer local
  279.             // parts than 64 characters.
  280.             if (!$this->check_text_length($strLocalPortion, 1, 64)) {
  281.                 return false;
  282.             }
  283.             // Local portion must be:
  284.             // 1) a dot-atom (strings separated by periods)
  285.             // 2) a quoted string
  286.             // 3) an obsolete format string (combination of the above)
  287.             $arrLocalPortion = explode('.', $strLocalPortion);
  288.             for ($i = 0, $max = sizeof($arrLocalPortion); $i < $max; $i++) {
  289.                  if (!preg_match('.^('
  290.                                 .    '([A-Za-z0-9!#$%&\'*+/=?^_`{|}~-]'
  291.                                 .    '[A-Za-z0-9!#$%&\'*+/=?^_`{|}~-]{0,63})'
  292.                                 .'|'
  293.                                 .    '("[^\\\"]{0,62}")'
  294.                                 .')$.'
  295.                                 ,$arrLocalPortion[$i])) {
  296.                     return false;
  297.                 }
  298.             }
  299.             return true;
  300.         }
  301.  
  302.         /**
  303.          * Checks email section after "@" symbol for validity
  304.          * @param   strDomainPortion     Text to be checked
  305.          * @return  True if domain portion is valid, false if not
  306.          */
  307.          function check_domain_portion($strDomainPortion) {
  308.             // Total domain can only be from 1 to 255 characters, inclusive
  309.             if (!$this->check_text_length($strDomainPortion, 1, 255)) {
  310.                 return false;
  311.             }
  312.             // Check if domain is IP, possibly enclosed in square brackets.
  313.             if (preg_match('/^(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])'
  314.                .'(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}$/'
  315.                ,$strDomainPortion) ||
  316.                 preg_match('/^\[(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])'
  317.                .'(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}\]$/'
  318.                ,$strDomainPortion)) {
  319.                 return true;
  320.             } else {
  321.                 $arrDomainPortion = explode('.', $strDomainPortion);
  322.                 if (sizeof($arrDomainPortion) < 2) {
  323.                     return false; // Not enough parts to domain
  324.                 }
  325.                 for ($i = 0, $max = sizeof($arrDomainPortion); $i < $max; $i++) {
  326.                     // Each portion must be between 1 and 63 characters, inclusive
  327.                     if (!$this->check_text_length($arrDomainPortion[$i], 1, 63)) {
  328.                         return false;
  329.                     }
  330.                     if (!preg_match('/^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|'
  331.                        .'([A-Za-z0-9]+))$/', $arrDomainPortion[$i])) {
  332.                         return false;
  333.                     }
  334.                 }
  335.             }
  336.             return true;
  337.         }
  338.  
  339.         /**
  340.          * Check given text length is between defined bounds
  341.          * @param   strText     Text to be checked
  342.          * @param   intMinimum  Minimum acceptable length
  343.          * @param   intMaximum  Maximum acceptable length
  344.          * @return  True if string is within bounds (inclusive), false if not
  345.          */
  346.          function check_text_length($strText, $intMinimum, $intMaximum) {
  347.             // Minimum and maximum are both inclusive
  348.             $intTextLength = strlen($strText);
  349.             if (($intTextLength < $intMinimum) || ($intTextLength > $intMaximum)) {
  350.                 return false;
  351.             } else {
  352.                 return true;
  353.             }
  354.         }
  355.  
  356.     }
  357.  
  358.  
  359.  
  360.  
  361. /* Check for injection characters */
  362. function ddfm_injection_chars($s) {
  363.     return (eregi("\r", $s) || eregi("\n", $s) || eregi("%0a", $s) || eregi("%0d", $s)) ? TRUE : FALSE;
  364. }
  365.  
  366.  
  367. /* Make output safe for the browser */
  368. function ddfm_bsafe($input) {
  369.     return htmlspecialchars(stripslashes($input));
  370. }
  371.  
  372.  
  373.  
  374.  
  375. function ddfm_stripslashes($s) {
  376.     if (get_magic_quotes_gpc()) {
  377.         return stripslashes($s);
  378.     } else {
  379.         return $s;
  380.     }
  381. }
  382.  
  383.  
  384.  
  385. function ddfm_injection_test($str) {
  386.     $tests = array("/bcc\:/i", "/Content\-Type\:/i", "/Mime\-Version\:/i", "/cc\:/i", "/from\:/i", "/to\:/i", "/Content\-Transfer\-Encoding\:/i");
  387.     return preg_replace($tests, "", $str);
  388. }
  389.  
  390.  
  391.  
  392. function ddfm_send_mail($recipients, $sender_name, $sender_email, $email_subject, $email_msg, $attach_save, $attach_path, $attachments = false) {
  393.  
  394.     $extra_recips = '';
  395.  
  396.     // generate recipient data from list
  397.     if (strpos($recipients, '|')) {
  398.  
  399.         $rdata = array();
  400.         $ri = 0;
  401.         $rtmp = explode('|', $recipients);
  402.         foreach ($rtmp as $rd) {
  403.             if (trim($rd) != "") {
  404.                 list($m, $e) = (array)explode("=", trim($rd), 2);
  405.                 $rdata[$ri]['m'] = trim(strtolower($m));
  406.                 $rdata[$ri]['e'] = trim($e);
  407.                 $ri++;
  408.             }
  409.         }  
  410.  
  411.         rsort($rdata);
  412.  
  413.         $r_to = array();
  414.         $extra_recips = "";
  415.         foreach ($rdata as $r) {
  416.             if ($r['m'] == 'to') $r_to[] = $r['e'];
  417.             if ($r['m'] == 'cc') $extra_recips .= 'cc: ' . $r['e'] . PHP_EOL;      
  418.             if ($r['m'] == 'bcc') $extra_recips .= 'bcc: ' . $r['e'] . PHP_EOL;
  419.         }
  420.         $send_to = implode(', ', $r_to);
  421.    
  422.     } else {
  423.         $send_to = trim($recipients);
  424.     }
  425.  
  426.  
  427.     $sender_name = ddfm_injection_test($sender_name);
  428.     $sender_email = ddfm_injection_test($sender_email);
  429.     $email_subject = ddfm_injection_test($email_subject);
  430.    
  431.     if (function_exists('mb_encode_mimeheader')) {
  432.     $email_subject = mb_encode_mimeheader($email_subject, 'UTF-8', 'Q', '');
  433.     $sender_name = mb_encode_mimeheader($sender_name, 'UTF-8', 'Q', '');
  434.     }
  435.  
  436.  
  437.     if (trim($sender_name) == "") {
  438.         $sender_name = 'Anonymous';
  439.     }
  440.     if (trim($sender_email) == "") {
  441.         $sender_email = '[email protected]';
  442.     }
  443.     if (trim($email_subject) == "") {
  444.         $email_subject = 'Contact Form';
  445.     }
  446.  
  447.  
  448.     $mime_boundary = md5(time());
  449.  
  450.     $headers = '';
  451.     $msg = '';
  452.  
  453.  
  454.     $headers .= 'From: ' . $sender_name . ' <' . $sender_email . '>' . PHP_EOL;
  455.     $headers .= $extra_recips;
  456.     $headers .= 'Reply-To: ' . $sender_name . ' <' . $sender_email . '>' . PHP_EOL;
  457.     $headers .= 'Return-Path: ' . $sender_name . ' <' . $sender_email . '>' . PHP_EOL;
  458.     $headers .= "Message-ID: <" . time() . "ddfm@" . $_SERVER['SERVER_NAME'] . ">" . PHP_EOL;
  459.     $headers .= 'X-Sender-IP: ' . $_SERVER["REMOTE_ADDR"] . PHP_EOL;
  460.     $headers .= "X-Mailer: PHP v" . phpversion() . PHP_EOL;
  461.  
  462.     $headers .= 'MIME-Version: 1.0' . PHP_EOL;
  463. //  $headers .= 'Content-Type: multipart/related; boundary="' . $mime_boundary . '"';
  464.     $headers .= 'Content-Type: multipart/mixed; boundary="' . $mime_boundary . '"';
  465.  
  466.     $msg .= '--' . $mime_boundary . PHP_EOL;
  467.     $msg .= 'Content-Type: text/plain; charset="utf-8"' . PHP_EOL;
  468. //  $msg .= 'Content-Type: text/plain; charset="iso-8859-1"' . PHP_EOL;
  469.  
  470.     $msg .= 'Content-Transfer-Encoding: 8bit' . PHP_EOL . PHP_EOL;
  471.  
  472.     $msg .= $email_msg . PHP_EOL . PHP_EOL;
  473.  
  474.     if (count($attachments) > 0) {
  475.  
  476.         for ($i = 0; $i < count($attachments); $i++) {
  477.  
  478.             if (is_file($attachments[$i]['tmpfile'])) {
  479.  
  480.                 if ($attach_save) {
  481.  
  482.                     if (!rename($attachments[$i]['tmpfile'], $attach_path . $attachments[$i]['file'])) {
  483.                         echo 'Error saving file. Check your path and permissions. Stopping script.';
  484.                         exit();
  485.                     }
  486.  
  487.                 } else {
  488.  
  489.                     $handle = fopen($attachments[$i]['tmpfile'], 'rb');
  490.                     $f_contents = fread($handle, filesize($attachments[$i]['tmpfile']));
  491.                     $f_contents = chunk_split(base64_encode($f_contents));
  492.                     fclose($handle);       
  493.  
  494.                     $msg .= '--' . $mime_boundary . PHP_EOL;
  495.                     $msg .= 'Content-Type: application/octet-stream; name="' . $attachments[$i]['file'] . '"' . PHP_EOL;
  496.                     $msg .= 'Content-Transfer-Encoding: base64' . PHP_EOL;
  497.                     $msg .= 'Content-Disposition: attachment; filename="' . $attachments[$i]['file'] . '"' . PHP_EOL . PHP_EOL;
  498.                     $msg .= $f_contents . PHP_EOL . PHP_EOL;
  499.  
  500.                 }
  501.  
  502.             }
  503.        
  504.         }
  505.     }
  506.  
  507.     $msg .= '--' . $mime_boundary . '--' . PHP_EOL . PHP_EOL;
  508.  
  509.     @ini_set('sendmail_from', $sender_email);
  510.     $send_status = mail($send_to, $email_subject, $msg, $headers);
  511.     @ini_restore('sendmail_from');
  512.  
  513.     return $send_status;
  514. }
  515.  
  516.  
  517.  
  518.  
  519.  
  520. $form_input = array();
  521.  
  522.  
  523.  
  524.  
  525. // START of functions to show form output
  526.  
  527.  
  528. function ddfm_gen_html($item) {
  529.  
  530.     // type=html|text=
  531.  
  532.     $gen = $item['text'] . "\n";
  533.  
  534.     return $gen;
  535. }
  536.  
  537.  
  538.  
  539.  
  540.  
  541. function ddfm_gen_date($item) {
  542.  
  543.     // type=date|class=|label=|fieldname=|req=(TRUEFALSE)
  544.  
  545.     global $form_submitted, $form_input, $show_required;
  546.  
  547.  
  548.     $req_text = (($show_required) && ($item['req'] == 'true')) ? '<span class="required">' . DDFM_REQUIREDTAG . '</span> ' : '';
  549.  
  550.     $gen = "";
  551.     $gen .= '<p class="fieldwrap"><label for="' . $item['fieldname'] . '">' . $req_text . $item['label'] . '</label>';
  552.     $gen .= '<input class="' . $item['class'] . '" type="text" name="' . $item['fieldname'] . '" id="' . $item['fieldname'] . '" value="';
  553.  
  554.     if ($form_submitted) {
  555.         $gen .= ddfm_bsafe($form_input[$item['fieldname']]);
  556.     } else if (isset($item['default'])) {
  557.         $gen .= ddfm_bsafe($item['default']);
  558.     }
  559.  
  560.     $gen .= '" />';
  561.  
  562.     global $script_path;
  563.  
  564.     $i = strrpos($script_path, "/");
  565.     $tmp_path = substr($script_path, 0, $i);
  566.    
  567.     // $gen .= '<input type="button" value="select" onclick="displayDatePicker(\'' . $item['fieldname'] . '\', this);">';
  568.     $gen .= '<img src="' . rtrim($tmp_path, '/') . '/calendar.gif" alt=""  onclick="displayDatePicker(\'' . $item['fieldname'] . '\', this);" />';
  569.  
  570.  
  571.     $gen .='</p>' . "\n\n";
  572.  
  573.     return $gen;
  574. }
  575.  
  576.  
  577.  
  578. function ddfm_gen_text($item) {
  579.  
  580.     // type=text|class=|label=|fieldname=|max=|req=(TRUEFALSE)|[ver=]|[default=]
  581.  
  582.     global $form_submitted, $form_input, $show_required;
  583.  
  584.     $req_text = (($show_required) && ($item['req'] == 'true')) ? '<span class="required">' . DDFM_REQUIREDTAG . '</span> ' : '';
  585.  
  586.     $gen = "";
  587.     $gen .= '<p class="fieldwrap"><label for="' . $item['fieldname'] . '">' . $req_text . $item['label'] . '</label>';
  588.     $gen .= '<input class="' . $item['class'] . '" type="text" name="' . $item['fieldname'] . '" id="' . $item['fieldname'] . '" value="';
  589.  
  590.     if ($form_submitted) {
  591.         $gen .= ddfm_bsafe($form_input[$item['fieldname']]);
  592.     } else if (isset($item['default'])) {
  593.         $gen .= ddfm_bsafe($item['default']);
  594.     }
  595.  
  596.     $gen .= '" /></p>' . "\n\n";
  597.  
  598.     return $gen;
  599. }
  600.  
  601.  
  602.  
  603. function ddfm_gen_password($item) {
  604.  
  605.     // type=password|class=|label=|fieldname=|max=|req=(TRUEFALSE)|confirm=(TRUEFALSE)
  606.  
  607.     global $form_submitted, $form_input, $show_required;
  608.  
  609.     $req_text = (($show_required) && $item['req'] == 'true') ? '<span class="required">' . DDFM_REQUIREDTAG . '</span> ' : '';
  610.  
  611.     $gen = "";
  612.     $gen .= '<p class="fieldwrap"><label for="' . $item['fieldname'] . '">' . $req_text . $item['label'] . '</label>' . "\n";
  613.     $gen .= '<input class="' . $item['class'] . '" type="password" name="' . $item['fieldname'] . '" id="' . $item['fieldname'] . '" value="';
  614.     $gen .= '" /></p>' . "\n\n";
  615.  
  616.     if ($item['confirm'] == 'true') {
  617.  
  618.         // Duplicate field (add 'c' to end)
  619.         $gen .= '<p class="fieldwrap"><label for="' . $item['fieldname'] . 'c">' . $req_text . DDFM_CONFIRMPASS . ' ' . $item['label'] . '</label>' . "\n";
  620.         $gen .= '<input class="' . $item['class'] . '" type="password" name="' . $item['fieldname'] . 'c" id="' . $item['fieldname'] . 'c" value="';
  621.         $gen .= '" /></p>' . "\n\n";
  622.  
  623.     }
  624.  
  625.     return $gen;
  626. }
  627.  
  628.  
  629.  
  630. function ddfm_gen_textarea($item) {
  631.  
  632.     // type=textarea|class=|label=|fieldname=|max=|rows=|req=(TRUEFALSE)|[default=]
  633.  
  634.     global $form_submitted, $form_input, $show_required;
  635.  
  636.     $req_text = (($show_required) && $item['req'] == 'true') ? '<span class="required">' . DDFM_REQUIREDTAG . '</span> ' : '';
  637.  
  638.     $gen = "";
  639.     $gen .= '<p class="fieldwrap"><label for="' . $item['fieldname'] . '">' . $req_text . $item['label'] . '</label>' . "\n";
  640.     $gen .= '<textarea class="' . $item['class'] . '" name="' . $item['fieldname'] . '" cols="20" rows="' . $item['rows'] . '" id="' . $item['fieldname'] . '">';
  641.  
  642.     if ($form_submitted) {
  643.         $gen .= ddfm_bsafe($form_input[$item['fieldname']]);
  644.     } else if (isset($item['default'])) {
  645.         $gen .= ddfm_bsafe($item['default']);
  646.     }
  647.  
  648.     $gen .= '</textarea></p>' . "\n\n";
  649.  
  650.     return $gen;
  651. }
  652.  
  653.  
  654.  
  655. function ddfm_gen_widetextarea($item) {
  656.  
  657.     // type=widetextarea|class=|label=|fieldname=|max=|rows=|req=(TRUEFALSE)|[default=]
  658.  
  659.     global $form_submitted, $form_input, $show_required;
  660.  
  661.     $req_text = (($show_required) && $item['req'] == 'true') ? '<span class="required">' . DDFM_REQUIREDTAG . '</span> ' : '';
  662.  
  663.     $gen = "";
  664.     $gen .= '<p class="fieldwrap"><label for="' . $item['fieldname'] . '" class="fmtextlblwide">' . $req_text . $item['label'] . '</label>' . "\n";
  665.     $gen .= '<textarea class="' . $item['class'] . '" name="' . $item['fieldname'] . '" cols="20" rows="' . $item['rows'] . '" id="' . $item['fieldname'] . '">';
  666.  
  667.     if ($form_submitted) {
  668.         $gen .= ddfm_bsafe($form_input[$item['fieldname']]);
  669.     } else if (isset($item['default'])) {
  670.         $gen .= ddfm_bsafe($item['default']);
  671.     }
  672.  
  673.     $gen .= '</textarea></p>' . "\n\n";
  674.  
  675.     return $gen;
  676. }
  677.  
  678.  
  679.  
  680. function ddfm_gen_verify($item) {
  681.  
  682.     // type=verify|class=|label=
  683.  
  684.     global $verify_method, $show_required, $script_path;
  685.  
  686.     if ($verify_method != 'basic') return '';
  687.  
  688.     $req_text = ($show_required) ? '<span class="required">' . DDFM_REQUIREDTAG . '</span> ' : '';
  689.  
  690.     $gen = "";
  691.  
  692.     if (ddfm_check_gd_support()) {
  693.         $gen .= '<p class="fieldwrap"><label for="fm_verify">' . $req_text . $item['label'] . '</label>' . "\n";
  694.         $gen .= '<input class="'. $item['class'] . '" type="text" name="fm_verify" id="fm_verify" />' . "\n";
  695.         $gen .= '<img width="60" height="24" src="' . $script_path . '?v=1" alt="' . $item['label'] . '" title="' . $item['label'] . '" />';
  696.         $gen .= '</p>' . "\n\n";
  697.     }
  698.  
  699.     return $gen;
  700. }
  701.  
  702.  
  703. function ddfm_gen_fullblock($item) {
  704.  
  705.     // type=fullblock|class=|text=
  706.  
  707.     $gen = "";
  708.  
  709.     $gen .= '<div class="' . $item['class'] . '"><p class="fieldwrap">' . "\n";
  710.     $gen .= $item['text'] . "\n";
  711.     $gen .= '</p></div>' . "\n\n";
  712.  
  713.     return $gen;
  714. }
  715.  
  716.  
  717. function ddfm_gen_halfblock($item) {
  718.  
  719.     // type=halfblock|class=|text=
  720.  
  721.     $gen = "";
  722.  
  723.     $gen .= '<div class="' . $item['class'] . '"><p class="fieldwrap">' . "\n";
  724.     $gen .= $item['text'] . "\n";
  725.     $gen .= '</p></div>' . "\n\n";
  726.  
  727.     return $gen;
  728. }
  729.  
  730.  
  731. function ddfm_gen_openfieldset($item) {
  732.  
  733.     // type=openfieldset|legend=
  734.  
  735.     $gen = "";
  736.  
  737.     $gen .= '<fieldset><legend>' . ddfm_bsafe($item['legend']) . '</legend>' . "\n\n";
  738.  
  739.     return $gen;
  740. }
  741.  
  742.  
  743. function ddfm_gen_closefieldset($item) {
  744.  
  745.     // type=closefieldset
  746.  
  747.     $gen = "";
  748.  
  749.     $gen .= '</fieldset>' . "\n\n";
  750.  
  751.     return $gen;
  752. }
  753.  
  754.  
  755. function ddfm_gen_checkbox($item) {
  756.  
  757.     // type=checkbox|class=|label=|data=
  758.     //   (fieldname),(text),(CHECKED),(REQUIRED),
  759.     //   (fieldname),(text),(CHECKED),(REQUIRED),
  760.     //   (fieldname),(text),(CHECKED),(REQUIRED)
  761.  
  762.     global $form_submitted, $form_input, $show_required;
  763.    
  764.     // ### added following line, add by MG ###
  765.     $req_text = (($show_required) && $item['req'] == 'true') ? '<span class="required">' . DDFM_REQUIREDTAG . '</span> ' : '';
  766.  
  767.     $gen = "";
  768.  
  769.     // ### added $req_text to the following line, add by MG ###
  770.     $gen .= '<p class="fieldwrap"><label>' . $req_text . $item['label'] . '</label><span class="' . $item['class'] . '">' . "\n";
  771.    
  772.     $item['data'] = str_replace(",,", "C0mM@", $item['data']);
  773.     $data = explode(",", trim($item['data']));
  774.     $data = str_replace("C0mM@", ",", $data);
  775.  
  776.     for ($i = 0; $i < sizeof($data); $i+=4) {
  777.  
  778.         $req_text = (($show_required) && ($data[$i+3] == 'true')) ? ' <span class="required">' . DDFM_REQUIREDTAG . '</span>' : '';
  779.  
  780.         $gen .= '<input type="checkbox" name="' . $data[$i] . '" id="' . $data[$i] . '" value="' . $data[$i + 1] . '"';
  781.  
  782.         if ($form_submitted) {
  783.             if ((isset($form_input[$data[$i]])) && (trim($form_input[$data[$i]]) != '')) {
  784.                 $gen .= ' checked="checked"';
  785.             }
  786.         } else {
  787.             if ($data[$i + 2] == 'true') {
  788.                 $gen .= ' checked="checked"';
  789.             }
  790.         }
  791.  
  792.         $gen .= ' /><label for="' . $data[$i] . '" class="fmchecklabel">' . $data[$i + 1] . $req_text . '</label>' . "\n";
  793.         $gen .= '<br />';
  794.     }
  795.  
  796.     $gen .= '</span></p>' . "\n\n";
  797.  
  798.     return $gen;
  799. }
  800.  
  801.  
  802. function ddfm_gen_radio($item) {
  803.  
  804.     //  type=radio|class=|label=|fieldname=|req=|[default=]|data=
  805.     //    (text),(text),(text)
  806.  
  807.     global $form_submitted, $form_input, $show_required;
  808.  
  809.     $req_text = (($show_required) && ($item['req'] == 'true')) ? '<span class="required">' . DDFM_REQUIREDTAG . '</span> ' : '';
  810.  
  811.     $gen = "";
  812.  
  813.     $gen .= '<p class="fieldwrap"><label>' . $req_text . $item['label'] . '</label><span class="' . $item['class'] . '">' . "\n";
  814.    
  815.     $c = 1;
  816.  
  817.     $item['data'] = str_replace(",,", "C0mM@", $item['data']);
  818.     $data = explode(",", trim($item['data']));
  819.     $data = str_replace("C0mM@", ",", $data);
  820.    
  821.     for ($i = 0; $i < sizeof($data); $i++) {
  822.  
  823.         $gen .= '<input type="radio" name="' . $item['fieldname'] . '" id="' . $data[$i] . '" value="' . $data[$i] . '"';
  824.  
  825.         if ($form_submitted) {
  826.             if (trim($form_input[$item['fieldname']]) == $data[$i]) {
  827.                 $gen .= ' checked="checked"';
  828.             }
  829.         } else {
  830.             if ($c == $item['default']) {
  831.                 $gen .= ' checked="checked"';
  832.             }
  833.         }
  834.  
  835.         $gen .= ' /><label for="' . $data[$i] . '" class="fmradiolabel">' . $data[$i] . '</label>' . "\n";
  836.         $gen .= '<br />';
  837.  
  838.         $c++;
  839.     }
  840.  
  841.     $gen .= '</span></p>' . "\n\n";
  842.  
  843.     return $gen;
  844. }
  845.  
  846.  
  847.  
  848. function ddfm_gen_select($item) {
  849.  
  850.     //  type=select|class=|label=|fieldname=|multi=(TRUEFALSE)|data=
  851.     //    (#group),(text),(text),(#group),(text),(text)
  852.  
  853.     global $form_submitted, $form_input, $show_required;
  854.  
  855.     $req_text = (($show_required) && ($item['req'] == 'true')) ? '<span class="required">' . DDFM_REQUIREDTAG . '</span> ' : '';
  856.  
  857.     $gen = "";
  858.  
  859.     $gen .= '<p class="fieldwrap"><label>' . $req_text . $item['label'] . '</label><select class="' . $item['class'] . '" code id="' . $item['fieldname'] . '" name="' . $item['fieldname'];
  860.  
  861.     if ($item['multi'] == 'true') {
  862.         $gen .= '[]';
  863.     }
  864.  
  865.     $gen .= '"';
  866.  
  867.     if ($item['multi'] == 'true') {
  868.         $gen .= ' multiple="multiple"';
  869.     }
  870.  
  871.     $gen .= '>' . "\n";
  872.    
  873.     $c = 1;
  874.  
  875.     $og = FALSE;
  876.  
  877.     $item['data'] = str_replace(",,", "C0mM@", $item['data']);
  878.     $data = explode(",", trim($item['data']));
  879.     $data = str_replace("C0mM@", ",", $data);
  880.  
  881.     for ($i = 0; $i < sizeof($data); $i++) {
  882.  
  883.         if (substr($data[$i], 0, 1) == '#' ) {
  884.  
  885.             if ($og) {
  886.                 $gen .= '</optgroup>' . "\n";  
  887.             }
  888.             $gen .= '<optgroup label="' . ltrim($data[$i], '#') . '">' . "\n";
  889.             $og = TRUE;
  890.  
  891.         } else {
  892.  
  893.             $gen .= '<option';
  894.  
  895.             if ($form_submitted) {
  896.        
  897.                 if ($item['multi'] == 'true') {
  898.  
  899.                     foreach ((array)$form_input[$item['fieldname']] as $ii) {
  900.  
  901.                         if ($data[$i] == $ii) {
  902.                             $gen .= ' selected="selected"';
  903.                         }
  904.                     }
  905.            
  906.                 } else {
  907.  
  908.                     if (trim($form_input[$item['fieldname']]) == $data[$i]) {
  909.                         $gen .= ' selected="selected"';
  910.                     }
  911.  
  912.                 }
  913.             }
  914.  
  915.             $gen .= ' >' . $data[$i] . '</option>' . "\n";
  916.         }
  917.  
  918.         $c++;
  919.     }
  920.  
  921.     if ($og) {
  922.         $gen .= '</optgroup>' . "\n";  
  923.         $og = FALSE;
  924.     }
  925.  
  926.     $gen .= '</select></p>' . "\n\n";
  927.  
  928.     return $gen;
  929. }
  930.  
  931.  
  932. function ddfm_gen_file($item) {
  933.  
  934.     // type=file|class=|label=|fieldname=|req=(TRUEFALSE)|[allowed=1,2,3]
  935.  
  936.     global $form_submitted, $form_input, $show_required, $max_file_size;
  937.  
  938.     $req_text = (($show_required) && ($item['req'] == 'true')) ? '<span class="required">' . DDFM_REQUIREDTAG . '</span> ' : '';
  939.  
  940.     $gen = "";
  941.  
  942.     $gen .= '<p class="fieldwrap"><label for="' . $item['fieldname'] . '">' . $req_text . $item['label'] . '</label>' . "\n";
  943.     $gen .= '<input class="' . $item['class'] . '" type="file" name="' . $item['fieldname'] . '" id="' . $item['fieldname'] . '" ';
  944.     $gen .= ' /></p>' . "\n\n";
  945.  
  946.     return $gen;
  947. }
  948.  
  949.  
  950. function ddfm_gen_selrecip($item) {
  951.  
  952.     // type=selrecip|class=|label=|data=User1,[email protected],User2 etc..
  953.  
  954.     global $form_submitted, $form_input, $show_required;
  955.  
  956.     $req_text = ($show_required) ? '<span class="required">' . DDFM_REQUIREDTAG . '</span> ' : '';
  957.  
  958.     $gen = "";
  959.  
  960.     $gen .= '<p class="fieldwrap"><label>' . $req_text . $item['label'] . '</label><select class="' . $item['class'] . '" name="fm_selrecip">' . "\n";
  961.    
  962.  
  963.     $data = explode(",", trim($item['data']));
  964.  
  965.  
  966.     $gen .= '<option';
  967.     if ($form_submitted) {
  968.         if (trim($form_input['fm_selrecip']) == $data[0]) {
  969.             $gen .= ' selected="selected"';
  970.         }
  971.     }
  972.     $gen .= ' >' . $data[0] . '</option>' . "\n";
  973.  
  974.  
  975.  
  976.     for ($i = 1; $i < sizeof($data); $i+=2) {
  977.  
  978.         $gen .= '<option';
  979.  
  980.         if ($form_submitted) {
  981.             if (trim($form_input['fm_selrecip']) == $data[$i]) {
  982.                 $gen .= ' selected="selected"';
  983.             }
  984.         }
  985.  
  986.         $gen .= ' >' . $data[$i] . '</option>' . "\n";
  987.     }
  988.  
  989.     $gen .= '</select></p>' . "\n\n";
  990.  
  991.     return $gen;
  992.  
  993. }
  994.  
  995.  
  996. // END of functions to show form output
  997.  
  998.  
  999.    
  1000. /* Generate the script output */
  1001.  
  1002.  
  1003.         // convert $form_struct into array of strings
  1004.         $form_struct = (array)explode('<br />', nl2br(trim($form_struct)));
  1005.  
  1006.         // Prepare globals
  1007.         $form_submitted = FALSE;
  1008.  
  1009.         $message_sent = FALSE;
  1010.  
  1011.  
  1012.         // Prepare output
  1013.  
  1014.         $o = "\n\n\n" . '<!-- START of Dagon Design Formmailer output -->' . "\n\n";
  1015.  
  1016.  
  1017.  
  1018.         // Convert form structure to multi-dimensional array
  1019.  
  1020.         $fs_tmp1 = array();
  1021.         $fs_tmp2 = array();
  1022.         $fitem = 0;
  1023.  
  1024.         foreach ($form_struct as $fs) {
  1025.             if (trim($fs) != "") {
  1026.                 $fs_tmp1 = (array)explode("|", trim($fs));
  1027.                 foreach ($fs_tmp1 as $fs1) {
  1028.                     list($k, $v) = (array)explode("=", trim($fs1), 2); 
  1029.  
  1030.                     $fs_tmp2[$fitem][$k] = $v;
  1031.                 }          
  1032.             }
  1033.  
  1034.             $fitem++;
  1035.         }
  1036.         $form_struct = $fs_tmp2;
  1037.  
  1038.  
  1039.  
  1040.         // Make sure form structure is not missing empty keys
  1041.  
  1042.         $valid_keys = array('fieldname', 'type', 'req', 'label', 'max', 'ver', 'confirm', 'data', 'multi', 'allowed', 'default');
  1043.  
  1044.         for ($i = 0; $i < count($form_struct); $i++) {
  1045.             foreach ($valid_keys as $k) {
  1046.                 if (!isset($form_struct[$i][$k])) $form_struct[$i][$k] = NULL;
  1047.             }
  1048.         }
  1049.    
  1050.    
  1051.    
  1052.     // Do a quick check to make sure there are no duplicate field names
  1053.     $dd_unique_fields = array();
  1054.     $dd_unique_test = TRUE;
  1055.     foreach ($form_struct as $fs) {
  1056.         if ($dd_unique_test && ($fs['fieldname'] != NULL) && (in_array($fs['fieldname'], $dd_unique_fields))) {
  1057.             $dd_unique_test = FALSE;
  1058.         } else {
  1059.             $dd_unique_fields[] = $fs['fieldname'];
  1060.         }
  1061.     }
  1062.     if (!$dd_unique_test) {
  1063.         echo '<p>*** ERROR - You have duplicate fieldnames in your form structure ***</p>';
  1064.     }
  1065.    
  1066.  
  1067.  
  1068.     // Was form submitted?
  1069.  
  1070.     if (isset($_POST["form_submitted"])) {
  1071.  
  1072.  
  1073.  
  1074.         $form_submitted = TRUE;
  1075.  
  1076.         $mail_message = "";
  1077.         $csv = "";
  1078.        
  1079.  
  1080.         $orig_auto_reply_message = $auto_reply_message;
  1081.         $auto_reply_message = '';
  1082.                
  1083.         // make correct encoding in auto - sokai - BEGIN
  1084.         $mime_boundary = md5(time());
  1085.         $auto_reply_message .= '--' . $mime_boundary . PHP_EOL;
  1086.         $auto_reply_message .= 'Content-Type: text/plain; charset="utf-8"' . PHP_EOL;
  1087.         $auto_reply_message .= 'Content-Transfer-Encoding: 8bit' . PHP_EOL . PHP_EOL;
  1088.         // make correct encoding in auto - sokai - END
  1089.  
  1090.         $attached_files = array();
  1091.         $attached_index = 0;
  1092.  
  1093.         $sel_recip = NULL;
  1094.  
  1095.         $message_structure = trim($message_structure);
  1096.  
  1097.  
  1098.  
  1099.         $auto_reply_message .= $orig_auto_reply_message;
  1100.  
  1101.  
  1102.  
  1103.         unset($errors);
  1104.         $errors = array();
  1105.  
  1106.  
  1107.         if ($verify_method == 'recaptcha') {
  1108.             @include_once('recaptchalib.php');
  1109.             $privatekey = $re_private_key;
  1110.             $resp = recaptcha_check_answer ($privatekey,
  1111.                                 $_SERVER["REMOTE_ADDR"],
  1112.                                 $_POST["recaptcha_challenge_field"],
  1113.                                 $_POST["recaptcha_response_field"]);
  1114.             if (!$resp->is_valid) {
  1115.                 $errors[] = DDFM_INVALIDVER;
  1116.             }
  1117.         }
  1118.  
  1119.  
  1120.  
  1121.         // Get form input and put in array
  1122.  
  1123.         foreach ($_POST as $key => $i) {
  1124.  
  1125.             if ($key != "form_submitted") {
  1126.                 if (!is_array($i)) {
  1127.                     $form_input[strtolower($key)] = trim($i);
  1128.                 } else {
  1129.                     $form_input[strtolower($key)] = $i;
  1130.                 }
  1131.             }
  1132.  
  1133.         }
  1134.  
  1135.        
  1136.         $msg_field_sep = ': ';
  1137.         $msg_field_line_end = "\n\n";
  1138.  
  1139.  
  1140.         $fsindex = -1;
  1141.  
  1142.         // Validate input
  1143.         foreach ($form_struct as $fs) {
  1144.        
  1145.             if (!isset($form_input[$fs['fieldname']])) {
  1146.                 $form_input[$fs['fieldname']] = '';
  1147.             }
  1148.  
  1149.             $fsindex++;
  1150.  
  1151.             // check for fields used in vars
  1152.             if (isset($form_input[$fs['fieldname']])) {
  1153.                 $sender_name = ddfm_str_replace($fs['fieldname'], ddfm_stripslashes($form_input[$fs['fieldname']]), $sender_name);
  1154.                 $sender_email = ddfm_str_replace($fs['fieldname'], ddfm_stripslashes($form_input[$fs['fieldname']]), $sender_email);
  1155.                 $email_subject = ddfm_str_replace($fs['fieldname'], ddfm_stripslashes($form_input[$fs['fieldname']]), $email_subject);
  1156.             }
  1157.  
  1158.             switch ($fs['type']) {
  1159.            
  1160.                 case 'date':
  1161.  
  1162.                     // type=date|class=|label=|fieldname=|req=(TRUEFALSE)
  1163.  
  1164.                     $t = ddfm_stripslashes($form_input[$fs['fieldname']]);
  1165.  
  1166.                     if ((strtolower($fs['req']) == 'true') && ($t == "")) {
  1167.  
  1168.                         $errors[] = DDFM_MISSINGFIELD . " '" . $fs['label'] . "'";
  1169.  
  1170.                     } else if (ddfm_injection_chars($t)) {
  1171.  
  1172.                         $errors[] = DDFM_INVALIDINPUT . " '" . $fs['label'] . "'";
  1173.  
  1174.                     }
  1175.  
  1176.                     $csv .= str_replace($save_delimiter, ' ', $t) . $save_delimiter;
  1177.                     $mail_message .= $fs['label'] . $msg_field_sep . $t . $msg_field_line_end;
  1178.                     $message_structure = ddfm_str_replace($fs['fieldname'], $t, $message_structure);
  1179.                     $auto_reply_message = ddfm_str_replace($fs['fieldname'], $t, $auto_reply_message);
  1180.                     $sent_message = ddfm_str_replace($fs['fieldname'], ddfm_bsafe($t), $sent_message);
  1181.  
  1182.                     break;
  1183.  
  1184.                 case 'text':
  1185.  
  1186.                     // type=text|class=|label=|fieldname=|max=|req=(TRUEFALSE)|[ver=]|[default=]
  1187.  
  1188.                     $t = ddfm_stripslashes($form_input[$fs['fieldname']]);
  1189.  
  1190.                     if ((strtolower($fs['req']) == 'true') && ($t == "")) {
  1191.  
  1192.                         $errors[] = DDFM_MISSINGFIELD . " '" . $fs['label'] . "'";
  1193.  
  1194.                     } else if (strlen($t) > (int)$fs['max']) {
  1195.  
  1196.                         $errors[] = $fs['max'] . ' ' . DDFM_MAXCHARLIMIT . " '" . $fs['label'] . "'";
  1197.  
  1198.                     } else if (ddfm_injection_chars($t)) {
  1199.  
  1200.                         $errors[] = DDFM_INVALIDINPUT . " '" . $fs['label'] . "'";
  1201.  
  1202.                     } else  if ((strtolower($fs['ver']) == 'email') && ((strtolower($fs['req']) == "true") || ($t != ""))) {
  1203.  
  1204.                         if (!dd_is_valid_email($t)) $errors[] = DDFM_INVALIDEMAIL . " '" . $fs['label'] . "'";
  1205.  
  1206.                     } else if ((strtolower($fs['ver']) == 'url') && ((strtolower($fs['req']) == "true") || ($t != ""))) {
  1207.  
  1208.                         if (!ddfm_is_valid_url($t)) $errors[] = DDFM_INVALIDURL . " '" . $fs['label'] . "'";
  1209.  
  1210.                     }
  1211.  
  1212.                     $csv .= str_replace($save_delimiter, ' ', $t) . $save_delimiter;
  1213.                     $mail_message .= $fs['label'] . $msg_field_sep . $t . $msg_field_line_end;
  1214.                     $message_structure = ddfm_str_replace($fs['fieldname'], $t, $message_structure);
  1215.                     $auto_reply_message = ddfm_str_replace($fs['fieldname'], $t, $auto_reply_message);
  1216.                     $sent_message = ddfm_str_replace($fs['fieldname'], ddfm_bsafe($t), $sent_message);
  1217.                    
  1218.                    
  1219.                 break;
  1220.  
  1221.                 case 'password':
  1222.  
  1223.                     // type=password|class=|label=|fieldname=|max=|req=(TRUEFALSE)|confirm=(TRUEFALSE)
  1224.  
  1225.                     $t = ddfm_stripslashes($form_input[$fs['fieldname']]);
  1226.  
  1227.                     if ((strtolower($fs['req']) == 'true') && ($t == "")) {
  1228.  
  1229.                         $errors[] = DDFM_MISSINGFIELD . " '" . $fs['label'] . "'";
  1230.        
  1231.                     } else if (strlen($t) > (int)$fs['max']) {
  1232.  
  1233.                         $errors[] = $fs['max'] . ' ' . DDFM_MAXCHARLIMIT . " '" . $fs['label'] . "'";
  1234.  
  1235.                     } else if (ddfm_injection_chars($t)) {
  1236.  
  1237.                         $errors[] = DDFM_INVALIDINPUT . " '" . $fs['label'] . "'";
  1238.  
  1239.                     } else if (strtolower($fs['confirm']) == 'true') {
  1240.  
  1241.                         $tc = ddfm_stripslashes($form_input[$fs['fieldname']  . 'c']);
  1242.            
  1243.                         if ($t != $tc) $errors[] = DDFM_NOMATCH . " '" . $fs['label'] . "'";
  1244.  
  1245.                     }
  1246.  
  1247.                     $csv .= str_replace($save_delimiter, ' ', $t) . $save_delimiter;
  1248.                     $mail_message .= $fs['label'] . $msg_field_sep . $t . $msg_field_line_end;
  1249.                     $message_structure = ddfm_str_replace($fs['fieldname'], $t, $message_structure);
  1250.                     $auto_reply_message = ddfm_str_replace($fs['fieldname'], $t, $auto_reply_message);
  1251.                     $sent_message = ddfm_str_replace($fs['fieldname'], ddfm_bsafe($t), $sent_message);
  1252.  
  1253.  
  1254.                     break;
  1255.  
  1256.                 case 'textarea':
  1257.                 case 'widetextarea':
  1258.            
  1259.                     // type=textarea|class=|label=|fieldname=|max=|rows=|req=(TRUEFALSE)|[default=]
  1260.  
  1261.                     $t = ddfm_stripslashes($form_input[$fs['fieldname']]);
  1262.  
  1263.                     if ((strtolower($fs['req']) == 'true') && ($t == "")) {
  1264.  
  1265.                         $errors[] = DDFM_MISSINGFIELD . " '" . $fs['label'] . "'";
  1266.  
  1267.                     } else if (strlen($t) > (int)$fs['max']) {
  1268.            
  1269.                         $errors[] = $fs['max'] . ' ' . DDFM_MAXCHARLIMIT . " '" . $fs['label'] . "'";
  1270.  
  1271.                     }
  1272.  
  1273.                     $csv .= str_replace($save_delimiter, ' ', $t) . $save_delimiter;
  1274.                     $mail_message .= $fs['label'] . $msg_field_sep . $t . $msg_field_line_end;
  1275.                     $message_structure = ddfm_str_replace($fs['fieldname'], $t, $message_structure);
  1276.                     $auto_reply_message = ddfm_str_replace($fs['fieldname'], $t, $auto_reply_message);
  1277.                     $sent_message = ddfm_str_replace($fs['fieldname'], ddfm_bsafe($t), $sent_message);
  1278.  
  1279.  
  1280.                     break;             
  1281.  
  1282.                 case 'verify':
  1283.  
  1284.                     // type=verify|class=|label=
  1285.  
  1286.                     if ($verify_method == 'basic') {
  1287.  
  1288.                         $t = ddfm_stripslashes($form_input['fm_verify']);
  1289.  
  1290.                         if ($t == "") {
  1291.  
  1292.                             $errors[] = DDFM_MISSINGVER;
  1293.  
  1294.                         } else if (trim($_COOKIE["ddfmcode"]) == "") {
  1295.  
  1296.                             $errors[] = DDFM_NOVERGEN;
  1297.  
  1298.                         } else if ($_COOKIE["ddfmcode"] != md5(strtoupper($t))) {
  1299.  
  1300.                             $errors[] = DDFM_INVALIDVER;
  1301.  
  1302.                         }
  1303.  
  1304.                     }
  1305.  
  1306.                     break;
  1307.  
  1308.                 case 'checkbox':
  1309.  
  1310.                     //  type=checkbox|class=|label=|data=
  1311.                     //    (fieldname),(text),(CHECKED),(REQUIRED),
  1312.                     //    (fieldname),(text),(CHECKED),(REQUIRED),
  1313.                     //    (fieldname),(text),(CHECKED),(REQUIRED)
  1314.  
  1315.                     // ### following three lines edited in order to have commas in the values, add by MG ###
  1316.                     $fs['data'] = str_replace(",,", "C0mM@", $fs['data']);
  1317.                     $data = explode(",", trim($fs['data']));
  1318.                     $data = str_replace("C0mM@", ",", $data);
  1319.  
  1320.                     $tmp_msg = array();
  1321.                    
  1322.                     $checkBoxChecked = false; //### added by MG ###
  1323.  
  1324.                     for ($i = 0; $i < count($data); $i+=4) {
  1325.                        
  1326.                         $t = '';
  1327.                         if (isset($form_input[$data[$i]])) {
  1328.                             $t = ddfm_stripslashes(trim($form_input[$data[$i]]));
  1329.                         }
  1330.  
  1331.                         if ((strtolower($data[$i+3]) == 'true') && ($t == "")) {
  1332.                             $errors[] = DDFM_MISSINGFIELD . " '" . $fs['label'] . "'";
  1333.                         }
  1334.  
  1335.                         if ($t != "") {
  1336.                             $tmp_msg[] = $t;
  1337.                             $checkBoxChecked = true; //### added by MG ###
  1338.                         }
  1339.  
  1340.                         $message_structure = ddfm_str_replace($data[$i], $t, $message_structure);
  1341.                         $auto_reply_message = ddfm_str_replace($data[$i], $t, $auto_reply_message);
  1342.                         $sent_message = ddfm_str_replace($data[$i], ddfm_bsafe($t), $sent_message);
  1343.  
  1344.                     }
  1345.                    
  1346.                     // ### start of changes by MG ###
  1347.                     if ((strtolower($fs['req']) == 'true') && !$checkBoxChecked) {
  1348.                         $errors[] = DDFM_MISSINGFIELD . " '" . $fs['label'] . "'";
  1349.                     }
  1350.                     // ### end of changes by MG ###
  1351.  
  1352.                     $csv .= str_replace($save_delimiter, ' ', implode(', ', $tmp_msg)) . $save_delimiter;
  1353.                     $mail_message .= $fs['label'] . $msg_field_sep . implode(', ', $tmp_msg) . $msg_field_line_end;
  1354.  
  1355.                     break;
  1356.                
  1357.                 case 'radio':
  1358.  
  1359.                     //  type=radio|class=|label=|fieldname=|req=|[default=]|data=
  1360.                     //    (text),(text),(text),(text)
  1361.  
  1362.                     $t = ddfm_stripslashes(trim($form_input[$fs['fieldname']]));
  1363.  
  1364.                     if ((strtolower($fs['req']) == 'true') && ($t == "")) {
  1365.  
  1366.                         $errors[] = DDFM_MISSINGFIELD . " '" . $fs['label'] . "'";
  1367.  
  1368.                     }
  1369.  
  1370.                     $csv .= str_replace($save_delimiter, ' ', $t) . $save_delimiter;   
  1371.                     $mail_message .= $fs['label'] . $msg_field_sep . $t . $msg_field_line_end;
  1372.                     $message_structure = ddfm_str_replace($fs['fieldname'], $t, $message_structure);
  1373.                     $auto_reply_message = ddfm_str_replace($fs['fieldname'], $t, $auto_reply_message);
  1374.                     $sent_message = ddfm_str_replace($fs['fieldname'], ddfm_bsafe($t), $sent_message);
  1375.  
  1376.                     break;
  1377.  
  1378.                 case 'select':
  1379.  
  1380.                     //  type=select|class=|label=|fieldname=|multi=(TRUEFALSE)|data=
  1381.                     //    (#group),(text),(text),(#group),(text),(text)
  1382.  
  1383.                     $data = explode(",", trim($fs['data']));
  1384.  
  1385.                     if (strtolower($fs['multi']) != 'true') {              
  1386.  
  1387.                         $t = ddfm_stripslashes($form_input[$fs['fieldname']]);
  1388.                        
  1389.                         $first_item = $data[0];
  1390.  
  1391.                         if ((strtolower($fs['req']) == 'true') && (($t == "") || ($t == $first_item))) {
  1392.  
  1393.                             $errors[] = DDFM_MISSINGFIELD . " '" . $fs['label'] . "'";
  1394.  
  1395.                         }
  1396.                    
  1397.                         $csv .= str_replace($save_delimiter, ' ', $t) . $save_delimiter;
  1398.                         $mail_message .= $fs['label'] . $msg_field_sep . $t . $msg_field_line_end;
  1399.                         $message_structure = ddfm_str_replace($fs['fieldname'], $t, $message_structure);
  1400.                         $auto_reply_message = ddfm_str_replace($fs['fieldname'], $t, $auto_reply_message);
  1401.                         $sent_message = ddfm_str_replace($fs['fieldname'], ddfm_bsafe($t), $sent_message);
  1402.  
  1403.  
  1404.                     } else { // multi = true
  1405.    
  1406.                         $t = (array)$form_input[$fs['fieldname']];
  1407.  
  1408.                         if ((count($t) == 1) && ($t[0] == '')) {
  1409.                             unset($t[0]);
  1410.                         }
  1411.  
  1412.                         if ((strtolower($fs['req']) == 'true') && (count($t) == 0)) {
  1413.                             $errors[] = DDFM_MISSINGFIELD . " '" . $fs['label'] . "'";
  1414.                         }
  1415.                        
  1416.                         $tmp_msg = array();
  1417.  
  1418.                         foreach ($t as $tt) {
  1419.                             if ($tt != "") $tmp_msg[] = $tt;
  1420.                         }
  1421.  
  1422.                         $csv .= str_replace($save_delimiter, ' ', implode(', ', $tmp_msg)) . $save_delimiter;
  1423.                         $mail_message .= $fs['label'] . $msg_field_sep . implode(', ', $tmp_msg) . $msg_field_line_end;
  1424.                         $message_structure = ddfm_str_replace($fs['fieldname'], implode(', ', $tmp_msg), $message_structure);
  1425.                         $auto_reply_message = ddfm_str_replace($fs['fieldname'], implode(', ', $tmp_msg), $auto_reply_message);
  1426.                         $sent_message = ddfm_str_replace($fs['fieldname'], ddfm_bsafe(implode(', ', $tmp_msg)), $sent_message);
  1427.                
  1428.                     }
  1429.  
  1430.                     break;
  1431.  
  1432.                 case 'file':
  1433.  
  1434.                     // type=file|class=|label=|fieldname=|[req=]|[allowed=1,2,3]
  1435.  
  1436.                     if ((strtolower($fs['req']) == 'true') && (($_FILES[$fs['fieldname']]['name'] == ""))) {
  1437.                         $errors[] = DDFM_MISSINGFILE . " '" . $fs['label'] . "'";
  1438.                     }
  1439.                    
  1440.  
  1441.                     $allowed = array();
  1442.  
  1443.                     if (trim($fs['allowed']) != "") {
  1444.                         $allowed = (array)explode(",", trim(strtolower($fs['allowed'])));
  1445.                     }
  1446.  
  1447.                     if (($_FILES[$fs['fieldname']]['name'] != "") && ((int)$_FILES[$fs['fieldname']]['size'] == 0)) {
  1448.  
  1449.                             $errors[] = DDFM_FILETOOBIG . ' ' . $_FILES[$fs['fieldname']]['name'];
  1450.  
  1451.                     } else if ($_FILES[$fs['fieldname']]['tmp_name'] != "") {
  1452.  
  1453.                         if (($_FILES[$fs['fieldname']]['error'] == UPLOAD_ERR_OK) && ($_FILES[$fs['fieldname']]['size'] > 0)) {
  1454.  
  1455.                             $origfilename = $_FILES[$fs['fieldname']]['name'];
  1456.                             $filename = explode(".", $_FILES[$fs['fieldname']]['name']);
  1457.                             $filenameext = $filename[count($filename) - 1];
  1458.                             unset($filename[count($filename) - 1]);
  1459.                             $filename = implode(".", $filename);
  1460.                             $filename = substr($filename, 0, 15) . "." . $filenameext;
  1461.                             $file_ext_allow = TRUE;
  1462.  
  1463.                             if (count($allowed) > 0) {
  1464.  
  1465.                                 $file_ext_allow = FALSE;
  1466.                                
  1467.                                 for ($x = 0; $x < count($allowed); $x++) {
  1468.                                     if (strtolower($filenameext) == strtolower($allowed[$x])) {
  1469.                                         $file_ext_allow = TRUE;
  1470.                                     }
  1471.                                 }
  1472.                             }
  1473.                             if ($file_ext_allow) {
  1474.  
  1475.                                 if((int)$_FILES[$fs['fieldname']]['size'] < $max_file_size) {
  1476.  
  1477.                                     $attached_files[$attached_index]['file'] = $_FILES[$fs['fieldname']]['name'];
  1478.                                     $attached_files[$attached_index]['tmpfile'] = $_FILES[$fs['fieldname']]['tmp_name'];
  1479.                                     $attached_files[$attached_index]['content_type'] = $_FILES[$fs['fieldname']]['type'];
  1480.                                     $attached_index++;
  1481.  
  1482.                                     $csv .= str_replace($save_delimiter, ' ', $_FILES[$fs['fieldname']]['name']) . $save_delimiter;
  1483.                                    
  1484.                                     if (!$attach_save) {
  1485.                                         $mail_message .= DDFM_ATTACHED . $msg_field_sep . $_FILES[$fs['fieldname']]['name'] . $msg_field_line_end;
  1486.                                     } else {
  1487.                                         $mail_message .= $fs['label'] . $msg_field_sep . $_FILES[$fs['fieldname']]['name'] . $msg_field_line_end;
  1488.                                     }
  1489.                                    
  1490.                                     $message_structure = ddfm_str_replace($fs['fieldname'], $_FILES[$fs['fieldname']]['name'], $message_structure);
  1491.                                     $auto_reply_message = ddfm_str_replace($fs['fieldname'], $_FILES[$fs['fieldname']]['name'], $auto_reply_message);
  1492.                                     $sent_message = ddfm_str_replace($fs['fieldname'], $_FILES[$fs['fieldname']]['name'], $sent_message);                  
  1493.  
  1494.                                 } else {
  1495.                                     $errors[] = DDFM_FILETOOBIG . ' ' . $_FILES[$fs['fieldname']]['name'];
  1496.                                 }
  1497.                             } else {
  1498.                                 $errors[] = DDFM_INVALIDEXT . ' ' . $_FILES[$fs['fieldname']]['name'];
  1499.                             }
  1500.                         } else {
  1501.                             $errors[] = DDFM_UPLOADERR . ' ' . $_FILES[$fs['fieldname']]['name'];
  1502.                         }
  1503.                     }
  1504.  
  1505.  
  1506.                     /* handled above
  1507.                     $csv .= str_replace($save_delimiter, ' ', $_FILES[$fs['fieldname']]['name']) . $save_delimiter;
  1508.                     $mail_message .= $fs['label'] . $msg_field_sep . $_FILES[$fs['fieldname']]['name'] . $msg_field_line_end;
  1509.                     $message_structure = ddfm_str_replace($fs['fieldname'], $_FILES[$fs['fieldname']]['name'], $message_structure);
  1510.                     $auto_reply_message = ddfm_str_replace($fs['fieldname'], $_FILES[$fs['fieldname']]['name'], $auto_reply_message);
  1511.                     $sent_message = ddfm_str_replace($fs['fieldname'], $_FILES[$fs['fieldname']]['name'], $sent_message);
  1512.                     */
  1513.                    
  1514.                     break;
  1515.  
  1516.  
  1517.                 case 'selrecip':
  1518.  
  1519.                     //  type=selrecip|class=|label=|data=(select),User1,[email protected],User2 etc..
  1520.  
  1521.                     $data = explode(",", trim($fs['data']));
  1522.                    
  1523.                     $t = ddfm_stripslashes($form_input['fm_selrecip']);
  1524.  
  1525.                     if (($t == "") || ($t == $data[0])) {
  1526.  
  1527.                         $errors[] = DDFM_MISSINGFIELD . " '" . $fs['label'] . "'";
  1528.  
  1529.                     } else {
  1530.  
  1531.                         for ($i = 1; $i < count($data); $i+=2) {
  1532.  
  1533.                             if ($data[$i] == $t) {
  1534.                                 $sel_recip = trim($data[$i+1]);
  1535.                             }
  1536.                         }
  1537.  
  1538.                     }  
  1539.  
  1540.                     break;
  1541.  
  1542.             }
  1543.  
  1544.  
  1545.         }
  1546.  
  1547.  
  1548.  
  1549.         // make sure no un-used fieldnames are left in template
  1550.         foreach ($form_struct as $fs) {
  1551.             $message_structure = ddfm_str_replace($fs['fieldname'], '', $message_structure);
  1552.             $auto_reply_message = ddfm_str_replace($fs['fieldname'], '', $auto_reply_message);
  1553.             $sent_message = ddfm_str_replace($fs['fieldname'], '', $sent_message);
  1554.         }
  1555.  
  1556.  
  1557.  
  1558.         if (ddfm_injection_chars($sender_name)) $errors[] = DDFM_INVALIDINPUT;
  1559.         if (ddfm_injection_chars($sender_email)) $errors[] = DDFM_INVALIDINPUT;
  1560.         if (ddfm_injection_chars($email_subject)) $errors[] = DDFM_INVALIDINPUT;
  1561.  
  1562.  
  1563.  
  1564.  
  1565.        
  1566.         if ($errors) {
  1567.  
  1568.             $o .= '<div class="ddfmwrap"><div class="ddfmerrors">' . DDFM_ERRORMSG . '</div>';
  1569.             $o .= '<div class="errorlist">';
  1570.             foreach ($errors as $err) {
  1571.                 $o .= $err . '<br />';
  1572.             }
  1573.             $o .= '</div><div style="clear:both;"><!-- --></div></div>';
  1574.    
  1575.         } else {
  1576.  
  1577.             if ($wrap_messages) {
  1578.                 $mail_message = wordwrap($mail_message, 70);
  1579.             }
  1580.  
  1581.             if ($recipients == 'selrecip') {
  1582.                 $recipients = $sel_recip;
  1583.             }
  1584.  
  1585.             // if template exists, use it instead
  1586.             if (strlen(trim($message_structure)) > 0) {
  1587.                 $mail_message = $message_structure . "\n\n";
  1588.             }
  1589.  
  1590.             if ($show_ip_hostname) {
  1591.                 $mail_message .= 'IP: ' . $_SERVER['REMOTE_ADDR'] . "\n" . 'HOST: ' . gethostbyaddr($_SERVER['REMOTE_ADDR']) . "\n";
  1592.             }
  1593.  
  1594.  
  1595.             $sndmsg = TRUE;
  1596.             if (($save_to_file == TRUE) && ($save_email == FALSE)) {
  1597.                 $sndmsg = FALSE;
  1598.             }
  1599.            
  1600.             $csv = str_replace("\n", $save_newlines, $csv);
  1601.             $csv = str_replace("\r", '', $csv);
  1602.             $csv = substr($csv, 0, strlen($csv) - strlen($save_delimiter));
  1603.  
  1604.             if (trim($save_timestamp) != '') {
  1605.                 $csv = date($save_timestamp) . $save_delimiter . $csv;
  1606.             }
  1607.  
  1608.             if (is_writable($save_path)) {
  1609.                 $handle = fopen($save_path, 'a+');
  1610.                 fwrite($handle, $csv . "\n");
  1611.                 fclose($handle);
  1612.             }
  1613.  
  1614.  
  1615.             if ($show_url == TRUE) {
  1616.                 $mail_message .= "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  1617.             }
  1618.            
  1619.  
  1620.             if ($sndmsg == TRUE) {
  1621.  
  1622.                 if (ddfm_send_mail($recipients, $sender_name, $sender_email, $email_subject, $mail_message, $attach_save, $attach_path, $attached_files)) {
  1623.        
  1624.                     $o .= $sent_message;
  1625.    
  1626.                     $auto_reply_name = trim($auto_reply_name);
  1627.                     $auto_reply_email = trim($auto_reply_email);
  1628.                     $auto_reply_subject = trim($auto_reply_subject);
  1629.                     $auto_reply_message = trim($auto_reply_message);
  1630.    
  1631.                     if (($orig_auto_reply_message != "") && (trim($sender_email != ""))) {
  1632.    
  1633.                         $auto_reply_headers = '';
  1634.  
  1635.                         $auto_reply_headers .= 'From: ' . $auto_reply_name . ' <' . $auto_reply_email . '>' . PHP_EOL;
  1636.                         $auto_reply_headers .= 'Reply-To: ' . $auto_reply_name . ' <' . $auto_reply_email . '>' . PHP_EOL;
  1637.                         $auto_reply_headers .= 'Return-Path: ' . $auto_reply_name . ' <' . $auto_reply_email . '>' . PHP_EOL;;
  1638.                         $auto_reply_headers .= "Message-ID: <" . time() . "ddfm@" . $_SERVER['SERVER_NAME'] . ">" . PHP_EOL;
  1639.                         $auto_reply_headers .= 'X-Sender-IP: ' . $_SERVER["REMOTE_ADDR"] . PHP_EOL;
  1640.                         $auto_reply_headers .= "X-Mailer: PHP v" . phpversion() . PHP_EOL;
  1641.  
  1642.                         $auto_reply_headers .= 'MIME-Version: 1.0' . PHP_EOL;
  1643.                         $auto_reply_headers .= 'Content-Type: multipart/related; boundary="' . $mime_boundary . '"';
  1644.                         /*$auto_reply_headers .= 'Content-Type: text/plain; charset=utf-8';*/
  1645.                         // make correct encoding in auto - sokai - BEGIN
  1646.                         //$auto_reply_message .= PHP_EOL . PHP_EOL;
  1647.                         $auto_reply_message .= PHP_EOL . PHP_EOL . '--' . $mime_boundary . '--' . PHP_EOL . PHP_EOL;
  1648.                         // make correct encoding in auto - sokai - END
  1649.  
  1650.                         mail($sender_email, $auto_reply_subject, $auto_reply_message, $auto_reply_headers);
  1651.                     }
  1652.  
  1653.                     $message_sent = TRUE;
  1654.  
  1655.                     $_POST = array();
  1656.  
  1657.                 } else {
  1658.                     $o .= DDFM_SERVERERR;
  1659.                     $message_sent = FALSE;
  1660.                 }
  1661.  
  1662.             } else {
  1663.            
  1664.                 $o .= $sent_message;
  1665.            
  1666.             }
  1667.    
  1668.         }
  1669.  
  1670.  
  1671.     } // end of form submission processing
  1672.  
  1673.  
  1674.  
  1675.  
  1676.  
  1677.  
  1678.     // Generate form if message has not been sent
  1679.  
  1680.     if (!$message_sent) {  
  1681.  
  1682.  
  1683.         if ($verify_method == 'basic' && !ddfm_check_gd_support()) {
  1684.             $o .= DDFM_GDERROR;
  1685.         }
  1686.  
  1687.         if (trim($manual_form_code) == '') {    // ** Use normal form generation
  1688.        
  1689.             $o .= '<div class="ddfmwrap">';
  1690.             $o .= '<form class="ddfm" method="post" action="' . $path_contact_page . '" enctype="multipart/form-data">' . "\n\n";
  1691.    
  1692.             // Loop through form items
  1693.  
  1694.             foreach ($form_struct as $f_i) {
  1695.  
  1696.                 switch ($f_i['type']) {
  1697.  
  1698.                     case 'html':            $o .= ddfm_gen_html($f_i);              break;
  1699.                     case 'date':            $o .= ddfm_gen_date($f_i);              break;
  1700.                     case 'text':            $o .= ddfm_gen_text($f_i);              break;
  1701.                     case 'password':        $o .= ddfm_gen_password($f_i);          break;
  1702.                     case 'textarea':        $o .= ddfm_gen_textarea($f_i);          break;
  1703.                     case 'widetextarea':    $o .= ddfm_gen_widetextarea($f_i);      break;
  1704.                     case 'verify':          $o .= ddfm_gen_verify($f_i);            break;
  1705.                     case 'fullblock':       $o .= ddfm_gen_fullblock($f_i);         break;
  1706.                     case 'halfblock':       $o .= ddfm_gen_halfblock($f_i);         break;
  1707.                     case 'openfieldset':    $o .= ddfm_gen_openfieldset($f_i);      break;
  1708.                     case 'closefieldset':   $o .= ddfm_gen_closefieldset($f_i);     break;
  1709.                     case 'checkbox':        $o .= ddfm_gen_checkbox($f_i);          break;
  1710.                     case 'radio':           $o .= ddfm_gen_radio($f_i);             break;
  1711.                     case 'select':          $o .= ddfm_gen_select($f_i);            break;
  1712.                     case 'file':            $o .= ddfm_gen_file($f_i);              break;             
  1713.                     case 'selrecip':        $o .= ddfm_gen_selrecip($f_i);          break;
  1714.                 }
  1715.             }
  1716.  
  1717.             if ($verify_method == 'recaptcha') {
  1718.  
  1719.                 $o .= "<script>
  1720.                 var RecaptchaOptions = {
  1721.                 theme : 'white'
  1722.                 };
  1723.                 </script>";
  1724.  
  1725.                 @include_once('recaptchalib.php');
  1726.                 $publickey = $re_public_key;
  1727.  
  1728.                 $o .= '<div class="recaptcha"><div class="recaptcha-inner">';
  1729.                 $o .= recaptcha_get_html($publickey);
  1730.                 $o .= '</div></div>';
  1731.             }
  1732.  
  1733.             $o .= '<p><input type="hidden" name="MAX_FILE_SIZE" value="' . $max_file_size . '" /></p>' . "\n";
  1734.             $o .= '<div class="submit"><input type="submit" name="form_submitted" value="' . DDFM_SUBMITBUTTON . '" /></div>' . "\n\n";
  1735.  
  1736.             $o .= '<div class="credits">' . DDFM_CREDITS . ' <a href="http://www.dagondesign.com" title="Dagon Design">Dagon Design</a></div>' . "\n\n";
  1737.  
  1738.             $o .= '</form>';
  1739.             $o .= '</div>' . "\n\n";
  1740.  
  1741.         } else {
  1742.             // Use manual form code
  1743.  
  1744.             $o .= $manual_form_code;
  1745.  
  1746.         }
  1747.  
  1748.         // Form generation complete
  1749.  
  1750.     } // end of display form code
  1751.  
  1752.  
  1753.     $o .= '<!-- END of Dagon Design Formmailer output -->' . "\n\n\n";
  1754.  
  1755.  
  1756.  
  1757.  
  1758. /* Page Generation */
  1759.  
  1760.  
  1761. if ($standalone) {
  1762. // START OF PAGE HEADER
  1763. ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  1764. <html xmlns="http://www.w3.org/1999/xhtml">
  1765. <head profile="http://gmpg.org/xfn/11">
  1766. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  1767. <title>Townships Sun: Submit Photos</title>
  1768. <link rel="stylesheet" href="<?php echo $path_to_css; ?>" type="text/css" media="screen" />
  1769. <?php
  1770.  
  1771.     $i = strrpos($script_path, "/");
  1772.     $tmp_path = substr($script_path, 0, $i);
  1773.     $tmp_path = rtrim($tmp_path, '/');
  1774.  
  1775. ?>
  1776. <script type="text/javascript" src="<?php echo $tmp_path; ?>/date_chooser.js"></script>
  1777. </head>
  1778. <body>
  1779.  
  1780. <div align="center">
  1781. <div style="width: 380px; margin: 0 auto 0 auto; text-align:left;">
  1782. <img src="images/Sunlogo_500w.png">
  1783. <h1>Submit a photo</h1>
  1784. <p>Photos should be scanned at 300 dpi, with a width of 1500px on their longest side.</p>
  1785. <p>(If a file isn't at least 2 or 3 MB, odds are good you need to re-scan it).</p>
  1786. <p>Please include a description of the photo in the text box below.</p>
  1787. <p>Thanks for your interest!</p>
  1788.  
  1789. <?php
  1790. // END OF PAGE HEADER
  1791. }
  1792.  
  1793. // show script output
  1794. echo $o;
  1795.  
  1796. if ($standalone) {
  1797. // START OF PAGE FOOTER
  1798. ?>
  1799.  
  1800. </div>
  1801. </div>
  1802.  
  1803.  
  1804. </body>
  1805. </html>
  1806.  
  1807.  
  1808. <?php
  1809. // END OF PAGE FOOTER
  1810. }
  1811.  
  1812.  
  1813. ?>
Add Comment
Please, Sign In to add comment