/**
  * Creates a new mail template
  *
  * @global array $_ALIASES menu page aliases
  * @return void
  */
 private function create()
 {
     global $_ALIASES;
     onapp_debug(__METHOD__);
     $template = onapp_get_arg('template');
     if (is_null($template)) {
         $this->show_template_create();
     } else {
         $content = ":template_name:  " . $template['_template_name'] . "\n" . ":from: " . $template['_from'] . "\n" . ":from_name:" . $template['_from_name'] . "\n" . ":to:" . $template['_to'] . "\n" . ":copy:  " . $template['_copy'] . "\n" . ":subject: " . $template['_subject'] . "\n" . "" . "\n" . $template['_message'] . "\n            ";
         $path = ONAPP_PATH . ONAPP_DS . 'events' . ONAPP_DS . $template['_new_event'] . ONAPP_DS . 'mail' . ONAPP_DS . 'mail';
         $k = 1;
         while (file_exists($path . $k)) {
             $k++;
         }
         $written = onapp_file_write($content, NULL, $path . $k);
         if ($written) {
             $_SESSION['message'] = 'TEMPLATE_HAS_BEEN_CREATED_SUCCESSFULLY';
             onapp_redirect(ONAPP_BASE_URL . '/' . $_ALIASES['email_templates'] . '?action=view');
         } else {
             $error = onapp_string('TEMPLATE_HAS_NOT_BEEN_CREATED_CHECK_EVENTS_FOLDER_PERMISSIONS');
             trigger_error($error);
             $this->show_template_view($error);
         }
     }
 }
/**
 * Adds onapp error message.
 *
 * @param string $message Error message from error_get_last function
 *
 * @return void
 *
 */
function onapp_error_reporting($error)
{
    $error_levels = onapp_get_php_errors();
    if (ONAPP_LOG_LEVEL_PHP < $error['type'] || is_null($error)) {
        return;
    }
    $error_type = in_array($error['type'], array_keys($error_levels)) ? $error_levels[$error['type']] : "ERROR ID " . $error['type'];
    if ($error !== NULL && isset($_SESSION['log_id'])) {
        if (is_null($error['file']) && is_null($error['line'])) {
            $msg = '[' . $_SESSION['log_id'] . "] : [{$error_type}] : " . $error['message'];
        } else {
            $msg = '[' . $_SESSION['log_id'] . "] : [{$error_type}] in " . $error['file'] . ' on line ' . $error['line'] . ' \'' . $error['message'] . '\'';
        }
        onapp_file_write($msg, 'error');
        onapp_file_write($msg, 'frontend');
    }
}