====== Miscelaneous ====== The file ''include/utils.php'' provides a some additional functionality to the rest of the system. ===== HttpException ===== The class ''HttpException'' provides an interface to propagate errors that correspond to a HTTP status upstream into the view's pipeline. The ''HttpException'' constructor has the signature ''%%__construct($status=500, $message=null, $html_message=null, $code=0)%%'', where ''%%$status%%'' is the HTTP status code, ''%%$message%%'' is the plain text error message and ''%%$html_message%%'' is a HTML representation of the error message. The ''%%$code%%'' parameter corresponds to the ''%%$code%%'' parameter of the default ''%%Exception%%'' implementation. Please note that the ''%%$html_message%%'' should/will be rendered unescaped, so use this carefully. ===== get_committee_email ===== ''%%get_committee_email($login)%%'' is a simple function that turns a committee login into that committees email address. ===== send_mail ===== ''%%send_mail($from, $to, $body, $subject=null, array $headers=[])%%'' is a wrapper function for PHP's ''%%mail%%'' function. Its main goal is to remove some overhead of setting the right content-type headers. If no subject is provided, it also searches the body for a HTML '''' element and takes that as the subject. The following snippet shows how to use this function to send an email with a rendered template as body. <code php> $template = new Template('templates/email.phtml', $context); $success = send_mail( ADMIN_EMAIL, // Sender is the admin emailaddress filter_var($context['email'], FILTER_SANITIZE_EMAIL), // Receiver is grabbed from $context $template->render(), null, // Subject is set in the <title> attribute in the template ['Bcc: ' . ADMIN_EMAIL] // Add Bcc header to send a copy to the admins ); // Determine wether email has ben send succesfully if (!$success) throw new HttpException(500, 'An error occurred when sending an email.'); </code> ===== Template ===== The implementation of the ''Template'' class also resides in ''include/utils.php''. This has been extensively discussed [[documentation:rack:reference:templates|here]].