Source files of fsfe.org, pdfreaders.org, freeyourandroid.org, ilovefs.org, drm.info, and test.fsfe.org. Contribute: https://fsfe.org/contribute/web/
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

promotion.php 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <?php
  2. function eval_xml_template($template, $data) {
  3. $dir = dirname(__FILE__) . '/../templates';
  4. $result = file_get_contents("$dir/$template");
  5. foreach ($data as $key => $value)
  6. $result = preg_replace("/<tpl name=\"$key\"><\/tpl>/", $value, $result);
  7. $result = preg_replace("/<tpl name=\"[^\"]*\"><\/tpl>/", '', $result);
  8. return $result;
  9. }
  10. function gen_alnum($digits){
  11. $alphabet = '0123456789abcdefghijklmnopqrstuvwxyz';
  12. $ret = '';
  13. for ($digits; $digits > 0; $digits--) {
  14. $ret .= substr($alphabet, rand(0,35), 1);
  15. }
  16. return $ret;
  17. }
  18. function relay_donation($orderID) {
  19. $name = $_POST['name'];
  20. $email = $_POST['mail'];
  21. $amount100 = $_POST['donate'] * 100;
  22. $language = $_POST['language'];
  23. $lang = substr($language, 0, 2);
  24. $PSPID = "40F00871";
  25. $TP = "https://fsfe.org/donate/tmpl-concardis.$lang.html";
  26. $acceptURL = "https://fsfe.org/donate/thankyou.$lang.html";
  27. $cancelURL = "https://fsfe.org/donate/cancel.$lang.html";
  28. $salt = "Only4TestingPurposes";
  29. $shasum = strtoupper(sha1(
  30. "ACCEPTURL=$acceptURL$salt".
  31. "AMOUNT=$amount100$salt".
  32. "CANCELURL=$cancelURL$salt".
  33. //"CN=$name$salt".
  34. //"COM=Donation$salt".
  35. "CURRENCY=EUR$salt".
  36. "EMAIL=$email$salt".
  37. "LANGUAGE=$language$salt".
  38. "ORDERID=$orderID$salt".
  39. "PMLISTTYPE=2$salt".
  40. "PSPID=$PSPID$salt".
  41. "TP=$TP$salt"
  42. ));
  43. echo eval_xml_template('concardis_relay.en.html', array(
  44. 'PSPID' => '<input type="hidden" name="PSPID" value="'.$PSPID.'">',
  45. 'orderID' => '<input type="hidden" name="orderID" value="'.$orderID.'">',
  46. 'amount' => '<input type="hidden" name="amount" value="'.$amount100.'">',
  47. //'currency' => '<input type="hidden" name="currency" value="EUR">',
  48. 'language' => '<input type="hidden" name="language" value="'.$language.'">',
  49. //'CN' => '<input type="hidden" name="CN" value="'.$name.'">',
  50. 'EMAIL' => '<input type="hidden" name="EMAIL" value="'.$email.'">',
  51. 'TP' => '<input type="hidden" name="TP" value="'.$TP.'">',
  52. //'PMListType' => '<input type="hidden" name="PMListType" value="2">',
  53. 'accepturl' => '<input type="hidden" name="accepturl" value="'.$acceptURL.'">',
  54. 'cancelurl' => '<input type="hidden" name="cancelurl" value="'.$cancelURL.'">',
  55. 'SHASign' => '<input type="hidden" name="SHASign" value="'.$shasum.'">'
  56. ));
  57. }
  58. function send_mail ( $to, $from, $subject, $msg, $bcc = NULL, $att = NULL, $att_type = NULL, $att_name = NULL ) {
  59. $headers = "From: $from\n";
  60. if ( isset( $bcc )) { $headers .= "Bcc: $bcc" . "\n"; }
  61. $headers .= "X-OTRS-Queue: Shipping::Promo Material Orders\n";
  62. if ( isset( $_POST["donationID"])) {
  63. $headers .= "X-OTRS-DynamicField-OrderID: " . $_POST["donationID"] . "\n";
  64. $headers .= "X-OTRS-DynamicField-OrderAmount: " . $_POST["donate"] . "\n";
  65. }
  66. $headers .= "X-OTRS-DynamicField-OrderLanguage: " . $_POST["language"] . "\n";
  67. $headers .= "X-OTRS-DynamicField-OrderState: order\n";
  68. $headers .= "X-OTRS-DynamicField-PromoMaterialCountry: " . $countrycode . "\n";
  69. $headers .= "X-OTRS-DynamicField-PromoMaterialLanguages: " . implode(',', $_POST['languages']) . "\n";
  70. if ( $att ) {
  71. $separator = md5( time());
  72. $att_f = chunk_split( base64_encode( $att ));
  73. $headers .= "MIME-Version: 1.0\n";
  74. $headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"\n";
  75. $headers .= "Content-Transfer-Encoding: 7bit";
  76. // message
  77. $message = "This is a MIME encoded message.\n\n";
  78. // text
  79. $message .= "--".$separator."\n";
  80. $message .= "Content-Type: text/plain; charset=\"UTF-8\"\n";
  81. $message .= "Content-Transfer-Encoding: 8bit\n\n";
  82. $message .= $msg."\n";
  83. // attachment
  84. $message .= "--".$separator."\n";
  85. $message .= "Content-Type: $att_type; name=\"$att_name\"\n";
  86. $message .= "Content-Transfer-Encoding: base64\n";
  87. $message .= "Content-Disposition: attachment\n\n";
  88. $message .= $att_f."\n";
  89. // end of message
  90. $message .= "--".$separator."--";
  91. } else {
  92. $headers .= "Content-Type: text/plain; charset=UTF-8\n";
  93. $headers .= "Content-Transfer-Encoding: 8bit";
  94. $message = $msg;
  95. }
  96. return mail( $to, $subject, $message, $headers );
  97. }
  98. $lang = $_POST['language'];
  99. # Sanity checks (*very* sloppy input validation)
  100. if (empty($_POST['lastname']) ||
  101. empty($_POST['mail']) ||
  102. empty($_POST['street']) ||
  103. empty($_POST['zip']) ||
  104. empty($_POST['city']) ||
  105. empty($_POST['country']) ||
  106. empty($_POST['packagetype']) ||
  107. !empty($_POST['address']) ) {
  108. header("Location: http://fsfe.org/contribute/spreadtheword-ordererror.$lang.html");
  109. exit();
  110. }
  111. # Without this, escapeshellarg() will eat non-ASCII characters.
  112. setlocale(LC_CTYPE, "en_US.UTF-8");
  113. # $_POST["country"] has values like "DE|Germany", so split this string
  114. $countrycode = explode('|', $_POST["country"])[0];
  115. $countryname = explode('|', $_POST["country"])[1];
  116. if ($_POST['packagetype'] == 'default') {
  117. $subject = "Standard promotion material order";
  118. } else {
  119. $subject = "Custom promotion material order";
  120. }
  121. $msg = "Please send me promotional material:\n".
  122. "First Name: {$_POST['firstname']}\n".
  123. "Last Name: {$_POST['lastname']}\n".
  124. "EMail: {$_POST['mail']}\n".
  125. "\n".
  126. "Address:\n".
  127. "{$_POST['firstname']} " . "{$_POST['lastname']}\n";
  128. if (!empty($_POST['org'])) {
  129. $msg .= "{$_POST['org']}\n";
  130. }
  131. $msg .= "{$_POST['street']}\n".
  132. "{$_POST['zip']} "."{$_POST['city']}\n".
  133. "{$countryname}\n".
  134. "\n".
  135. "Specifics of the Order:\n";
  136. # Default or custom package?
  137. if ($_POST['packagetype'] == 'default') {
  138. $msg .= "Default package: Something from everything listed here, depending on size, language selection and availability.\n";
  139. } else {
  140. $msg .= "Custom package:\n".
  141. "{$_POST['specifics']}\n";
  142. }
  143. $languages = implode(',',$_POST['languages']);
  144. $msg .= "\n".
  145. "Preferred language(s) (if available):\n".
  146. "{$languages}\n".
  147. "\n".
  148. "The material is going to be used for:\n".
  149. "{$_POST['usage']}\n".
  150. "\n".
  151. "Comments:\n".
  152. "{$_POST['comment']}\n";
  153. if (isset($_POST['donate']) && ($_POST['donate'] > 0)) {
  154. $_POST['donationID'] = "DAFSPCK".gen_alnum(5);
  155. $msg .= "\n\nThe orderer choose to make a Donation of {$_POST['donate']} Euro.\n".
  156. "Please do not assume that this donation has been made until you receive\n".
  157. "confirmation from Concardis for the order: {$_POST['donationID']}";
  158. }
  159. # Generate letter to be sent along with the material
  160. $odtfill = $_SERVER["DOCUMENT_ROOT"] . "/cgi-bin/odtfill";
  161. $template = $_SERVER["DOCUMENT_ROOT"] . "/templates/promotionorder.odt";
  162. $outfile = "/tmp/promotionorder.odt";
  163. $name = $_POST['firstname'] . " " . $_POST['lastname'];
  164. $address = "";
  165. if (!empty($_POST['org'])) {
  166. $address .= $_POST['org'] . "\\n";
  167. }
  168. $address .= $_POST['street'] . "\\n" .
  169. $_POST['zip'] . " " . $_POST['city'] . "\\n" .
  170. $countryname;
  171. $name = escapeshellarg($name);
  172. $address = escapeshellarg($address);
  173. shell_exec("$odtfill $template $outfile Name=$name Address=$address Name=$name");
  174. $test = send_mail ("contact@fsfe.org", $_POST['firstname'] . " " . $_POST['lastname'] . " <" . $_POST['mail'] . ">", $subject, $msg, NULL, file_get_contents($outfile), "application/vnd.oasis.opendocument.text", "letter.odt");
  175. if (isset($_POST['donate']) && ($_POST['donate'] > 0)) {
  176. relay_donation($_POST['donationID']);
  177. } else {
  178. header("Location: http://fsfe.org/contribute/spreadtheword-orderthanks.$lang.html");
  179. }
  180. ?>