public function run()
 {
     onapp_debug(__METHOD__);
     global $_ALIASES, $_SCREEN_IDS;
     $route = onapp_get_arg('route');
     onapp_debug('route => ' . $route);
     if (array_key_exists($route, $_SCREEN_IDS)) {
         $method_name = $_SCREEN_IDS[$route]['method'];
         $class_name = $_SCREEN_IDS[$route]['class'];
     } else {
         if (is_null($route)) {
             onapp_debug('$route is null!, Redirecting :' . ONAPP_BASE_URL . '/' . $_ALIASES[ONAPP_DEFAULT_ALIAS]);
             onapp_redirect(ONAPP_BASE_URL . '/' . $_ALIASES[ONAPP_DEFAULT_ALIAS]);
         } else {
             onapp_debug('There is no such page, Redirecting Base Url');
             trigger_error('There is no such page => ' . ONAPP_BASE_URL . $route);
             $_SESSION['message'] = 'THERE_IS_NO_SUCH_PAGE';
             onapp_redirect(ONAPP_BASE_URL);
         }
     }
     $file_path = ONAPP_PATH . ONAPP_DS . 'controllers' . ONAPP_DS . ONAPP_CONTROLLERS . ONAPP_DS . strtolower('c_' . $class_name . '') . '.php';
     if (file_exists($file_path)) {
         require_once "{$file_path}";
     } else {
         onapp_die("Could not find file {$file_path}");
     }
     onapp_debug("ONAPP_Controller->run: args => " . print_r(array('route' => $route, 'file' => $file_path, 'class' => $class_name, 'method' => $method_name), true));
     $new_class = new $class_name();
     $new_class->{$method_name}();
 }
 /**
  * Initializes php error levels and frontend error levels arrays
  * Displays index log settings page
  *
  * @param string error message
  * @param string success or other message
  * @return void
  */
 private function show_template_view($message = NULL)
 {
     onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__);
     onapp_permission('roles');
     $params = array('title' => onapp_string($this->config['title']), 'log_levels_frontend' => onapp_get_frontend_errors(), 'php_error_levels' => onapp_get_php_errors(), 'message' => onapp_string($message), 'config' => parse_ini_file(ONAPP_PATH . ONAPP_DS . 'config.ini'), 'template' => $this->config['template'], 'info_title' => onapp_string($this->config['info_title']), 'info_body' => onapp_string($this->config['info_body']));
     if ($this->config['template'] == NULL) {
         onapp_die('No config[template] exists');
     }
     onapp_show_template('configuration_view', $params);
 }
 /**
  * Displays mail template edit page
  *
  * @return void
  */
 public function show_template_edit()
 {
     onapp_debug(__METHOD__);
     $event = onapp_get_arg('event');
     $file_name = onapp_get_arg('file_name');
     $events_directory = ONAPP_PATH . ONAPP_DS . 'events' . ONAPP_DS;
     $path = $events_directory . $event . ONAPP_DS . 'mail' . ONAPP_DS . $file_name;
     $handle = @fopen($path, "r");
     if ($handle) {
         while (($buffer = fgets($handle, 4096)) !== false) {
             if (preg_match("/^:from:/", $buffer)) {
                 $template_info['from'] = trim(str_replace(':from:', '', $buffer));
             } elseif (preg_match("/^:from_name:/", $buffer)) {
                 $template_info['from_name'] = trim(str_replace(':from_name:', '', $buffer));
             } elseif (preg_match("/^:to:/", $buffer)) {
                 $template_info['to'] = trim(str_replace(':to:', '', $buffer));
             } elseif (preg_match("/^:subject:/", $buffer)) {
                 $template_info['subject'] = trim(str_replace(':subject:', '', $buffer));
             } elseif (!preg_match('/^:/', $buffer)) {
                 $template_info['message'] .= $buffer;
             } elseif (preg_match('/^:copy/', $buffer)) {
                 $template_info['copy'] = trim(str_replace(':copy:', '', $buffer));
             } elseif (preg_match('/^:template_name/', $buffer)) {
                 $template_info['template_name'] = trim(str_replace(':template_name:', '', $buffer));
             }
         }
     } else {
         onapp_die('Unable to open file ' . $path);
     }
     //print('<pre>'); print_r($template_info); die();
     $events_list = onapp_scan_dir($events_directory);
     sort($events_list, SORT_STRING);
     $params = array('classes_fields' => $this->get_classes_fields(), 'events_list' => $events_list, 'event' => $event, 'file_name' => $file_name, 'template_info' => $template_info, 'title' => onapp_string('EDIT_EMAIL_TEMPLATE'), 'info_title' => onapp_string('EDIT_EMAIL_TEMPLATE'), 'info_body' => onapp_string('EDIT_EMAIL_TEMPLATE_INFO'));
     onapp_show_template('emailTemplates_edit', $params);
 }
/**
 * Gets the list of file names in target directory
 *
 * @param string path to directory
 * @return array list of file names in this directory
 */
function onapp_scan_dir($path)
{
    if (count(scandir($path)) == 2) {
        return;
    }
    onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__);
    if ($handle = opendir($path)) {
        while (false !== ($file = readdir($handle))) {
            if (!is_dir($file) && $file != 'index.html') {
                $files_list[] = $file;
            }
        }
    } else {
        onapp_die('Unable to scan directory =><br /> ' . $path . '<br /> Check permissions');
    }
    closedir($handle);
    return $files_list;
}