"comments" field parser/stripper fixed
[www.energie.vellum.cz.git] / objednavka.php
1 <?php $cvs_id='$Id$';
2
3         $mail_to="short@ucw.cz";
4
5         $head_css="
6 .red    { color: red; }
7 .italic { font-style: italic; }
8 .quote  { font-family: monospace; }
9 ";
10         include("common.php");
11
12 $out="stamp:\t".date("r")."\n";
13 $err=false;
14 $total=0;
15
16 foreach ($HTTP_POST_VARS as $key => $value) {
17         if (!ereg("^want_",$key))
18                 continue;
19         if (ereg("[^0-9]",$value)) {
20                 print("<h1 class=\"red\">Jako poèet je mo¾no povoleno zadat jen èíselnou hodnotu!</h1>\n"
21                                 ."<blockquote><p>Opravte prosím polo¾ku "
22                                 ."<span class=\"italic\">".htmlspecialchars($key)."</span>: "
23                                 ."<span class=\"quote\">".htmlspecialchars($value)."</span>"
24                                 ."</p></blockquote>\n");
25                 $err=true;
26                 continue;
27                 }
28         if (!$value)
29                 continue;
30         $out.="$key:\t$value\n";
31         $total+=$value;
32         }
33
34 if (!$err && !$total) {
35         print("<h1 class=\"red\">Musíte si objednat alespoò jeden èasopis, napi¹te 1 do dané polo¾ky!</h1>\n");
36         $err=true;
37         }
38
39 function out_addr($title,$pfx)
40 {
41         global $HTTP_POST_VARS;
42         $fields=array(
43                         "Název"  ,"name",
44                         "Ulice"  ,"ulice",
45                         "Mìsto"  ,"mesto",
46                         "PSÈ"    ,"psc",
47                         "IÈO"    ,"ico",
48                         "DIÈ"    ,"dic",
49                         "Kontakt","contakt",
50                         "Tel"    ,"tel",
51                         "Fax"    ,"fax",
52                         "e-mail" ,"mail",
53                         );
54
55         $r="";
56         $first=true;
57         while ($fields) {
58                 $pretty=array_shift($fields);
59                 $var=$pfx.array_shift($fields);
60                 if (!isset($HTTP_POST_VARS[$var]))
61                         continue;
62                 if (""==($value=trim($HTTP_POST_VARS[$var])))
63                         continue;
64                 if ($first) {
65                         $r.="$title\n";
66                         $first=false;
67                         }
68                 $r.="\t$pretty:\t$value\n";
69                 }
70         return($r);
71 }
72
73 if (""==($addr1=out_addr("Adresa pro vystavení a zaslání faktury","addr1_"))) {
74         print("<h1 class=\"red\">Nebyla zadána ¾ádná fakturaèní adresa!</h1>\n");
75         $err=true;
76         }
77 $out.=$addr1;
78 $out.=out_addr("Adresa pro zasílaní èasopisu"          ,"addr2_");
79
80 if (isset($HTTP_POST_VARS["comments"])) {
81         $comments=trim(ereg_replace("[\r\n]+","\n",$HTTP_POST_VARS["comments"]));
82         if (""!=$comments)
83                 $out.="Jiné sdélení:".ereg_replace("\n","\\0\t","\n".$comments)."\n";
84         }
85
86 // Data acquision error checking:
87
88 if ($err) {
89         print("<p>Nyní se prosím ");
90         if ($have_js)
91                 print("<input type=\"button\" value=\"");
92         print("vra»te zpìt");
93         if ($have_js)
94                 print("\" onclick=\"history.back()\" />");
95         else
96                 print(" (tlaèítkem "
97                                 ."&quot;<span class=\"quote\">Zpìt</span>&quot; èi "
98                                 ."&quot;<span class=\"quote\">Back</span>&quot; prohlí¾eèe)");
99         print(" na pøedchozí stránku a chybu zadaných dat opravte.</p>\n");
100         footer();
101         }
102
103 // Successful data acquisition, write&send:
104
105 $out_file=$out.str_repeat("-",78)."\n\n";
106 if (!($f=fopen("objednavka.txt","a")) || strlen($out_file)!=fputs($f,$out_file) || !fclose($f))
107         fatal("Nepodaøilo se zapsat objednávku");
108
109 // 5th mail argument is supported from PHP-4.0.5
110 if (!mail($mail_to,"EnergieWeb: objednavka",$out,
111 "From: EnergieWeb <$admin_mail>
112 Mime-Version: 1.0
113 Content-Type: text/plain; charset=iso-8859-2
114 Content-Disposition: inline
115 Content-Transfer-Encoding: 8bit
116 "))
117         fatal("Chyba pøi odesílání upozornìní na objednávku, data objednávky ji¾ ale byla úspì¹nì ulo¾ena");
118
119 ?>
120 <h1>Objednávka byla úspì¹nì pøijata</h1>
121 <p>V nejbli¾¹ích dnech Vám bude zaslána faktura a po jejím zaplacení i objedané zbo¾í.</p>
122 <p>Nyní se mù¾ete vrátit na <a href="<?php print(dirname($HTTP_SERVER_VARS["SCRIPT_NAME"])."/"); ?>">úvodní stránku</a>.</p>
123 <?php
124         footer();
125 ?>