1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
<?php
/*
** $Id$
**
** ITools - the Internet Tools Library
**
** Copyright (C) 1995-2003 by the ITools Authors.
** This program is free software; you can redistribute it and/or
** modify it under the terms of either the GNU General Public License
** or the GNU Lesser General Public License, as published by the Free
** Software Foundation. See http://www.gnu.org/licenses/ for details.
*/
define('IT_FAX_PRIORITY_LOW', 207);
define('IT_FAX_PRIORITY_NORMAL', 127);
define('IT_FAX_PRIORITY_HIGH', 63);
/**
* Construct a fax message with body (plaintext and/or HTML) and
* send it. Also provides utility function to check phone number address
* validity.<br>
* <em>Example:</em><br>
* <code><nobr>
* if (!it_fax::check_number($faxnumber))<br>
* die("Invalid fax number '$faxnumber'\n");<br>
* <br>
* $fax = new it_fax("faxtest-$USER", $faxnumber,, $faxid,, 'Kommentar',, IT_FAX_PRIORITY_HIGH);<br>
* $fax->add_body("<html><body><h1>Ultrafax Test</h1>Dies ist ein Ultrafaxtest abgeschickt von $USER@gna.ch</body></html>", IT_MAIL_HTML);<br>
* $fax->send();<br>
* </nobr></code>
*/
class it_fax extends it_mail
{
/**
* Construct a new fax message. Body can be added later.
* @param $application Application name sending the fax
* @param $faxnumber Phone number to send fax to
* @param $faxid Optional unique identifier of this message application can set if it wants to track status later
* @param $comment Optional comment to be logged with fax message
* @param $priority Priority, one of IT_FAX_PRIORITY_LOW, IT_FAX_PRIORITY_NORMAL or IT_FAX_PRIORITY_HIGH
*/
function it_fax($application, $faxnumber, $faxid = '-', $comment = '', $priority = 0, $mailto = 'ultrafax@zhcs.rim.ch', $mailfrom = 'ultrafaxmaster@zhcs.rim.ch', $faxstatusto = '')
{
$faxnumber = ereg_replace('[^0-9]', '', $faxnumber);
if (!$priority)
$priority = IT_FAX_PRIORITY_NORMAL;
$signature = $this->_create_signature($application, $faxnumber, $faxid);
$this->it_mail(array('From' => $mailfrom, 'To' => $mailto, 'Subject' => "Fax Message from $application", 'X-Faxsender' => $application, 'X-Faxid' => $faxid, 'X-Faxnumber' => $faxnumber, 'X-Faxsignature' => $signature, 'X-Faxpriority' => $priority, 'X-Faxcomment' => ereg_replace("[\r\n\t ()]+", ' ', $comment), 'X-Faxstatus-To' => $faxstatusto));
}
/**
* Add body part to this fax message. Can be called repeatedly.
* @param $text Text to be added to fax message
* @param $type Type of text, one of IT_MAIL_HTML (default) or IT_MAIL_PLAIN
*/
function add_body($text, $type = IT_MAIL_HTML)
{
if ($type != IT_MAIL_HTML)
$text = "<pre>$text</pre>";
it_mail::add_body($text, IT_MAIL_HTML);
}
/**
* Check if given phone number is valid (very simplistic, currently allows
* 0 followed by any number of digits, e.g. 012345)
* @param $phonenumber phonenumber to be checked
* @return True if phone number seems to be valid
*/
function check_number($phonenumber)
{
return ereg('^0[0-9 ]+$', trim($phonenumber));
}
/**
* INTERNAL FUNCTION: Get signature session
* @return Session object to create/check signatures
*/
function _get_session()
{
$session = new it_session;
$session->set_secret('be55b53ac39445943d16aba1bfd8e515');
$session->set_cookiename('it_fax_cookie_never_exists');
$session->set_lifetime(30 * 86400); /* Almost forever: 30 days */
$session->init();
return $session;
}
/**
* INTERNAL FUNCTION: Get signature for this fax message parameters
* @param $application Application name sending the fax
* @param $faxnumber Phone number to send fax to
* @param $faxid Optional unique identifier of this message application can set if it wants to track status later
* @return Signature for this fax
*/
function _create_signature($application, $faxnumber, $faxid)
{
$session = it_fax::_get_session();
return $session->create_signature("$application|$faxnumber|$faxid");
}
/**
* INTERNAL FUNCTION: Check signature for this fax message parameters
* @param $signature Signature to check
* @param $application Application name sending the fax
* @param $faxnumber Phone number to send fax to
* @param $faxid Optional unique identifier of this message application can set if it wants to track status later
* @return True if signature ok, false otherwise
*/
function _check_signature($signature, $application, $faxnumber, $faxid)
{
$session = it_fax::_get_session();
return $session->check_signature("$application|$faxnumber|$faxid", $signature);
}
} /* End class it_fax */
?>
|