diff options
Diffstat (limited to 'it_fax.class')
-rw-r--r-- | it_fax.class | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/it_fax.class b/it_fax.class new file mode 100644 index 0000000..a9d8132 --- /dev/null +++ b/it_fax.class @@ -0,0 +1,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 */ + +?> |