From a5a19fd672bc0b8113d620669b557f17dccd343a Mon Sep 17 00:00:00 2001
From: Christian Schneider
Date: Thu, 26 Oct 2006 13:35:12 +0000
Subject: Moved itools to live branch
---
fax.class | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 127 insertions(+)
create mode 100644 fax.class
(limited to 'fax.class')
diff --git a/fax.class b/fax.class
new file mode 100644
index 0000000..a9d8132
--- /dev/null
+++ b/fax.class
@@ -0,0 +1,127 @@
+
+ * Example:
+ *
+ */
+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 = "
+ * die("Invalid fax number '$faxnumber'\n");
+ *
+ * $fax = new it_fax("faxtest-$USER", $faxnumber,, $faxid,, 'Kommentar',, IT_FAX_PRIORITY_HIGH);
+ * $fax->add_body("<html><body><h1>Ultrafax Test</h1>Dies ist ein Ultrafaxtest abgeschickt von $USER@gna.ch</body></html>", IT_MAIL_HTML);
+ * $fax->send();
+ *
$text"; + + 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 */ + +?> -- cgit v1.2.3