1<?php
2
3/**
4 * Calculates a new random ticket number.
5 *
6 * @param digits number of digits the ticket number should have.
7 *
8 * @return ticket number.
9 */
10function ticketNumber($digits) {
11	$result = "";
12	for ($index = 0; $index < $digits; $index++) {
13		$random = (rand()%9);
14		$result = $result.$random;
15	}
16	return $result;
17}
18
19/**
20 * Prepares text for HTML display.
21 *
22 * @param text Text to display.
23 * @return HTML.
24 */
25function prepareHTML( $text )
26{
27	$text = str_replace('\n', '<br/>', $text );
28	//Replace special chars
29	$text = str_replace('�', '&auml;', $text );
30	$text = str_replace('�', '&Auml;', $text );
31	$text = str_replace('�', '&ouml;', $text );
32	$text = str_replace('�', '&Ouml;', $text );
33	$text = str_replace('�', '&szlig;', $text );
34	$text = str_replace('�', '&uuml;', $text );
35	$text = str_replace('�', '&Uuml;', $text );
36	$text = str_replace('\n', '<br />', $text );
37	return $text;
38}
39
40/**
41 * Prepares text for mail sending.
42 *
43 * @param text text to send via mail.
44 * @param prepared mail.
45 */
46function prepareMail( $text )
47{
48	//Replace special chars
49	$text = str_replace('�', 'ae', $text );
50	$text = str_replace('�', 'Ae', $text );
51	$text = str_replace('�', 'oe', $text );
52	$text = str_replace('�', 'Oe', $text );
53	$text = str_replace('�', 'ue', $text );
54	$text = str_replace('�', 'Ue', $text );
55	$text = str_replace('\n', '<br />', $text );
56	return $text;
57}
58
59// Calculate a new ticket number
60
61$ticket = $data['abbreviation'].ticketNumber(5);
62
63$template = @file_get_contents(DOKU_PLUGIN.'onlineordering/template_'.$conf['lang'].'.txt');
64
65// Replace parameters
66$template = str_replace('{title}', $form['title'], $template);
67$template = str_replace('{firstname}', $form['firstname'], $template);
68$template = str_replace('{lastname}', $form['lastname'], $template);
69$template = str_replace('{postcode}', $form['postcode'], $template);
70$template = str_replace('{street}', $form['street'], $template);
71$template = str_replace('{place}', $form['place'], $template);
72$template = str_replace('{country}', $form['country'], $template);
73$template = str_replace('{remarks}', $form['remarks'], $template);
74
75$template = str_replace('{ticket}', $ticket, $template);
76$template = str_replace('{nr_tickets}', $form['tickets'], $template);
77
78$template = str_replace('{item_name}', $data['item_name'], $template);
79$template = str_replace('{currency}', $data['currency'], $template);
80$template = str_replace('{price}', number_format($data['price'],2,',','.'), $template);
81
82$bank_account = $data['bank_account'];
83if ( !isset($bank_account) ) {
84    $bank_account = $this->getConf('bank_account');
85}
86$template = str_replace('{bank_account}', $bank_account, $template);
87
88$porto = $this->_get_porto( $data, $form['country'] );
89$total_price = ($data['price'] * $form['tickets']) + $porto;
90
91
92$template = str_replace('{porto}', number_format($porto,2,',','.'), $template);
93$template = str_replace('{total_price}', number_format($total_price,2,',','.'), $template);
94
95$date = date("d-m-Y");
96$time = date("H:m");
97
98$datetime = $date.' '.$time;
99
100$template = str_replace('{date}', $date, $template);
101$template = str_replace('{time}', $time, $template);
102$template = str_replace('{datetime}', $datetime, $template);
103
104$template = str_replace('{signature}', $this->getConf('signature'), $template);
105
106$mail = prepareMail( $template );
107
108// Prepare email
109$subject = "Online ordering of ".$data['item_name'];
110
111// Get the sender_email from the parameters
112$sender_email = $data['sender_email'];
113if ( !isset( $sender_email))
114{
115    // Get the sender_email from the configuration
116    $sender_email = $this->getConf('sender_email');
117}
118
119// Make the from
120$from = 'From: ';
121// Get the sender name
122$sender_name = $data['sender_name'];
123if ( !isset( $sender_name ) ) {
124    $sender_name = $this->getConf('sender_name');
125}
126if ( isset( $sender_name ) )
127{
128    $from .= '"'.$sender_name.'" ';
129}
130// Add the email
131$from .= '<'.$sender_email.'>\r\n';
132// Make a header
133$header  = 'MIME-Version: 1.0' . "\r\n";
134$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
135
136// Make the recipient address
137$recipient = '"'.$form['firstname'].' '.$form['lastname'].'" <'.$form['email'].'>';
138
139// Get the cc email from the parameters
140$email_cc = $data['email_cc'];
141if ( !isset( $email_cc ) ) {
142    // Get the cc email from the configuration
143    $email_cc = $this->getConf("email_cc");
144}
145
146if ( isset( $email_cc ) ) {
147    $email_cc = str_replace(', ', ',', $email_cc );
148    // Add blind copies
149    $header .= "BCC: ".$email_cc."\r\n";
150}
151
152$result = @mail($recipient, $subject, $mail, $header.$from);
153if ($result) {
154    $output .= '<p>';
155    $output .= '<b>'.$this->getLang('thank_you_for_ordering').'</b><br /><br />';
156
157    $sent_notice = str_replace('{email}', $form['email'], $this->getLang('sent_notice'));
158    $sent_notice = str_replace('{name}', $form['firstname'].' '.$form['lastname'], $sent_notice );
159
160    $output .= $sent_notice.':<br /><br />';
161    $output .= '<code>';
162	$output .= prepareHTML( $template );
163	$output .= '</code>';
164	$output .= '</p>';
165
166}
167else {
168    $form['stage'] = 0;
169    @include('order_form.php');
170    $output = '<div id="onlineordering_error">'.str_replace('{email}', $form['email'], $this->getLang('send_failure')).'</div>'.$output;
171}
172
173?>