function header($vars = array())
 {
     $rubr_enc = $this->system->path_encode($this->system->rubrik);
     if (RheinaufFile::is_file(DOCUMENT_ROOT . INSTALL_PATH . '/CSS/' . $rubr_enc . '.css')) {
         $vars['other_css'] .= '<link rel="stylesheet" href="/' . INSTALL_PATH . '/CSS/' . rawurlencode($rubr_enc) . '.css" media="screen" type="text/css" />';
     }
     return $this->template->parse_template('HEADER', $vars);
 }
	function Template($template)
	{
		if (@RheinaufFile::is_file($template)) $this->template = RheinaufFile::get_file($template);
		else $this->template = $template;
		if (@RheinaufFile::is_file($snippet_pfad = INSTALL_PATH.'/Templates/Snippets.html'))
		{
			$this->snippets = $this->get_all_parts(file_get_contents($snippet_pfad));
		}
	}
 function write_file()
 {
     $snippets = $this->connection->db_assoc("SELECT * FROM `{$this->db_table}`");
     $string = '';
     foreach ($snippets as $snippet) {
         $name = $snippet['Name'];
         $data = trim($snippet['Content']);
         $string .= "<!--{$name}-->\n{$data}\n<!--/{$name}-->\n";
     }
     RheinaufFile::write_file(INSTALL_PATH . '/Templates/Snippets.html', $string);
 }
 function header($vars = array())
 {
     $rubr_enc = $this->system->path_encode($this->system->rubrik);
     $seite_enc = $this->system->path_encode($this->system->seite);
     if (RheinaufFile::is_file(DOCUMENT_ROOT . INSTALL_PATH . "/CSS/{$rubr_enc}/{$seite_enc}.css")) {
         $vars['other_css'] .= '<link rel="stylesheet" href="' . "/CSS/{$rubr_enc}/{$seite_enc}.css" . '" media="screen" type="text/css" />';
     } else {
         if (RheinaufFile::is_file(DOCUMENT_ROOT . INSTALL_PATH . "/CSS/{$rubr_enc}.css")) {
             $vars['other_css'] .= '<link rel="stylesheet" href="' . "/CSS/{$rubr_enc}.css" . '" media="screen" type="text/css" />';
         }
     }
     return $this->template->parse_template('HEADER', $vars);
 }
 function ls($path = '')
 {
     $return = '';
     $list_dirs = RheinaufFile::dir_array($this->start_folder . $path, true);
     $ul = new HtmlList();
     natcasesort($list_dirs);
     foreach ($list_dirs as $dir) {
         $url = $path . '/' . $dir;
         $ul->add_li($this->dir_link($url, $dir) . $this->ls($url));
     }
     if (!$this->show_only_folders) {
         $list_files = RheinaufFile::dir_array($this->start_folder . $path, false);
         natcasesort($list_files);
         foreach ($list_files as $file) {
             $url = $path . '/' . $file;
             $ul->add_li($this->file_link($url, $file));
         }
     }
     return $ul->flush_list();
 }
 function frontend_module_table()
 {
     $this->frontend_not_installed = RheinaufFile::dir_array(INSTALL_PATH . '/Module', false, 'php');
     $return_string = '';
     $table = new Table(1);
     $table->add_caption('Frontend-Module');
     $installed_modules = array();
     foreach ($this->frontend_installed as $installed) {
         $installed_modules[] = $installed['Name'];
     }
     foreach ($this->frontend_not_installed as $not_installed) {
         $not_installed = preg_replace('#(.*?).php$#', "\$1", $not_installed);
         if (!in_array($not_installed, $installed_modules)) {
             $table->add_td(array('<em>' . $not_installed . '</em>' . Html::a('/Admin/Module?newfrontend=' . rawurlencode($not_installed), '&gt;&gt;', array('title' => 'Installieren'))));
         }
     }
     foreach ($this->frontend_installed as $installed) {
         $table->add_td(array($installed['Name']));
     }
     $this->return .= $table->flush_table();
 }
 function ls()
 {
     $return = '';
     if ($_GET['list']) {
         $array = split('/', $_GET['list']);
         array_pop($array);
         $return .= Html::a(SELF . '?list=' . implode('/', $array) . "#{$this->list_id}", 'Eine Ebene höher<br />');
     }
     $list_dirs = RheinaufFile::dir_array($this->start_folder . $this->list_path, true);
     natcasesort($list_dirs);
     for ($i = 0; $i < count($list_dirs); $i++) {
         $return .= Html::a(SELF . '?list=' . $this->list_path . '/' . $list_dirs[$i] . "#{$this->list_id}", $this->icons['folder'] . ' ' . $list_dirs[$i]) . '<br />';
     }
     $list_files = RheinaufFile::dir_array($this->start_folder . $this->list_path, false);
     natcasesort($list_files);
     for ($i = 0; $i < count($list_files); $i++) {
         $return .= $this->file_link($this->start_folder . $this->list_path . '/' . $list_files[$i], $list_files[$i]) . '<br />';
     }
     if (count($list_dirs) == 0 && count($list_files) == 0) {
         $return .= 'Verzeichnis ist leer';
     }
     return $return;
 }
 function move_uploaded_file($old_name, $new_name)
 {
     $old_name = RheinaufFile::get_enc($old_name);
     $new_name = RheinaufFile::get_enc($new_name);
     move_uploaded_file($old_name, $new_name);
 }
 function db_insert()
 {
     $insert_sql = 'REPLACE INTO `' . $this->table . '` (';
     $field_names = array();
     foreach ($this->cols_array as $key => $col) {
         $field_name = $key;
         $field_names[] = '`' . $field_name . '`';
     }
     $insert_sql .= implode(', ', $field_names);
     $insert_sql .= ") VALUES (";
     $field_values = array();
     foreach ($this->cols_array as $key => $col) {
         $field_value = $col['value'] ? $col['value'] : $_POST[rawurlencode($key)];
         $field_value = !strstr($field_value, '--') ? $field_value : '';
         $field_value = is_array($field_value) ? implode(', ', $field_value) : $field_value;
         if ($col['type'] == 'timestamp') {
             $t = Date::unify_timestamp($_POST[rawurlencode($key) . '_jahr'] . $_POST[rawurlencode($key) . '_monat'] . $_POST[rawurlencode($key) . '_tag'] . $_POST[rawurlencode($key) . '_stunde'] . $_POST[rawurlencode($key) . '_minute'] . '00');
             $field_value = $t;
         }
         if ($col['type'] == 'email') {
             $field_value = $_POST[rawurlencode($key) . '_name'];
             if ($_POST[rawurlencode($key) . '_mail']) {
                 $field_value .= ' <' . $_POST[rawurlencode($key) . '_mail'] . '>';
             }
         }
         if ($col['type'] == 'upload') {
             if ($_FILES[rawurlencode($key) . '_upload']['name']) {
                 if ($this->upload_folder) {
                     if (!RheinaufFile::is_dir($folder = $this->upload_path . $_POST[$this->upload_folder])) {
                         RheinaufFile::mkdir($folder);
                         RheinaufFile::chmod($folder, '777');
                     }
                     $upload_folder = $_POST[$this->upload_folder] . "/";
                 }
                 $file = $this->upload_path . $upload_folder . $_FILES[rawurlencode($key) . '_upload']['name'];
                 move_uploaded_file($_FILES[rawurlencode($key) . '_upload']['tmp_name'], $file);
                 RheinaufFile::chmod($file, '777');
                 $field_value = $upload_folder . $_FILES[rawurlencode($key) . '_upload']['name'];
             }
         }
         if ($key == 'id') {
             $field_value = $_POST['edit_id'] ? $_POST['edit_id'] : '';
         }
         $field_values[] = "'" . General::input_clean(rawurldecode($field_value), true) . "'";
     }
     $insert_sql .= implode(', ', $field_values) . ')';
     $this->connection->db_query($insert_sql);
 }
 function uninstall($module)
 {
     if (RheinaufFile::is_file(INSTALL_PATH . '/Module/' . $module . '/Install.php')) {
         include_once INSTALL_PATH . '/Module/' . $module . '/Install.php';
         $module .= 'Install';
     } else {
         include_once $module . '.php';
     }
     $class = new $module();
     if (method_exists($class, 'uninstall')) {
         $this->return .= $class->uninstall($this);
     }
 }
 function new_db_insert()
 {
     $uniqid = md5(uniqid(rand(), true));
     $schulname = General::input_clean($_POST['Schulname']);
     $plz = General::input_clean($_POST['PLZ']);
     $bilder_pfade = array();
     if ($_FILES['bild']['name'][0] != '') {
         $output_path = DOCUMENT_ROOT . INSTALL_PATH . '/Images/BuddyListe/' . $plz . '_' . $schulname . '/';
         if (!is_dir($output_path)) {
             RheinaufFile::mkdir($output_path);
             RheinaufFile::chmod($output_path, 777);
         }
         for ($i = 0; $i < count($_FILES['bild']); $i++) {
             if ($_FILES['bild']['error'][$i] == '0') {
                 $bild = new Bilder($_FILES['bild']['tmp_name'][$i], $output_path . $_FILES['bild']['name'][$i]);
                 $bild->scaleMaxX(200);
                 $bild->output();
                 $bilder_pfade[] = 'Images/BuddyListe/' . $plz . '_' . $schulname . '/' . $_FILES['bild']['name'][$i];
             }
         }
     }
     $insert_sql = 'INSERT INTO `RheinaufCMS>BuddyListe` ( `id` ,';
     $field_names = array();
     for ($i = 0; $i < count($this->fields); $i++) {
         $field_name = $this->fields[$i]['name'];
         $field_names[] = '`' . $field_name . '`';
     }
     $insert_sql .= implode(', ', $field_names);
     $insert_sql .= ",`Bilder`,`angenommen`,`uniqid`) VALUES ('',";
     $field_values = array();
     for ($i = 0; $i < count($this->fields); $i++) {
         $field_value = $_POST[rawurlencode($this->fields[$i]['name'])];
         $field_value = !strstr($field_value, '--') ? $field_value : '';
         $field_value = is_array($field_value) ? implode(', ', $field_value) : $field_value;
         $field_values[] = "'" . General::input_clean(rawurldecode($field_value), true) . "'";
     }
     $insert_sql .= implode(', ', $field_values) . ",'" . implode(';', $bilder_pfade) . "','0','{$uniqid}')";
     $this->connection->db_query($insert_sql);
 }
 function golive()
 {
     $rubrik = $this->path_encode($this->navi[$_GET['edit']]['Rubrik']);
     $seite = $this->path_encode($this->navi[$_GET['edit']]['Subnavi'][$_GET['edit_page']]['Seite']);
     $folder = INSTALL_PATH . "/Content/{$rubrik}/{$seite}/";
     if (RheinaufFile::is_file($folder . 'Arbeitsversion/content.html')) {
         RheinaufFile::copy($folder . 'Arbeitsversion/content.html', $folder . 'content.html');
     }
 }
 function copy($old_name, $new_name)
 {
     if (USE_FTP) {
         $old_file = file_get_contents($old_name);
         RheinaufFile::write_file($new_name, $old_file);
     } else {
         copy($old_name, $new_name);
     }
 }
 function create_tables()
 {
     include 'Config.inc.php';
     $sql_file = RheinaufFile::get_file('tables.sql');
     $connection = new RheinaufDB();
     $connection->debug = false;
     preg_match_all('/.*?[^(]*;/ms', $sql_file, $sql_queries);
     foreach ($sql_queries[0] as $query) {
         if (!$connection->db_query($query) || mysql_error()) {
             print 'Fehler beim Datenbankzugriff. Installation abgebrochen<br />' . mysql_error();
             return;
         }
     }
     $connection->db_query("INSERT INTO `RheinaufCMS>User` ( `Name`, `Login`, `Password`,   `Group`) \r\n\t\t\t\t\t\t\t\tVALUES ( '" . $_POST['admin_name'] . "', '" . $_POST['admin_name'] . "', '" . $_POST['admin_pass'] . "',   'Admin')");
     print 'Tabellen geschrieben<br />';
 }
	function Template($template)
	{
		if (@RheinaufFile::is_file($template)) $this->template = RheinaufFile::get_file($template);
		else $this->template = $template;
	}
 function make_table($sql = '', $template = '', $make_template = false)
 {
     $db_table = $this->table;
     $vars = is_array($this->template_vars) ? $this->template_vars : array();
     if ($this->edit_enabled) {
         if ($_GET['delete']) {
             $this->connection->db_query("DELETE FROM `{$db_table}` WHERE `id` = " . $_GET['delete']);
         }
     }
     $order_by = $this->order_by ? $this->order_by : 'id';
     $order_dir = $this->order_dir ? $this->order_dir : 'ASC';
     $results_per_page = $this->results_per_page ? $this->results_per_page : '';
     $start_by = $_GET['start'] ? $_GET['start'] : ($_GET['start'] = 0);
     if ($sql == '') {
         $sql = "SELECT * FROM `{$db_table}` ORDER BY `{$order_by}` {$order_dir}";
     }
     if ($results_per_page || $start_by) {
         $num_rows = $this->num_rows = $this->connection->db_num_rows($sql);
         if (!$results_per_page) {
             $results_per_page = $num_rows;
         }
         $sql .= " LIMIT {$start_by},{$results_per_page}";
     }
     $result = $this->connection->db_assoc($sql);
     if (!$template || $make_template) {
         $new_template = '';
         $new_template .= "<!--PRE-->\n<table>\n<!--/PRE-->\n<!--LOOP-->\n";
         foreach ($this->cols_array as $key => $col) {
             $type = $col['type'];
             $name = $col['name'];
             if ($type != 'ignore' && $type != 'hidden') {
                 $new_template .= "{IfNotEmpty:{$key}(<tr><td>{$name}</td><td>[{$key}]</td></tr>)}\n";
             }
         }
         $new_template .= "<!--/LOOP-->\n<!--POST-->\n</table>\n<!--/POST-->\n";
         if ($make_template) {
             RheinaufFile::write_file($template, $new_template);
         }
         $template = $new_template;
     }
     $template = new Template($template);
     $return_string = '';
     $return_string .= $template->parse_template('PRE', $vars);
     $alternatig_rows = 0;
     foreach ($result as $entry) {
         $month = Date::monat($entry['DTSTART']);
         if ($month_shown == $month) {
             $entry['MONTH_HEAD'] = '';
         } else {
             $entry['MONTH_HEAD'] = $this->monate[intval($month)] . ' ' . Date::jahr($entry['DTSTART']);
             $month_shown = $month;
         }
         foreach ($entry as $key => $value) {
             if (is_array($this->cols_array[$key]['options'])) {
                 $entry[$key] = $this->cols_array[$key]['options'][$value];
             }
             if ($this->cols_array[$key]['type'] == 'timestamp') {
                 $entry[$key] = intval(Date::unify_timestamp($value)) != '0' ? Date::timestamp2datum($value, $this->datumsformat ? $this->datumsformat : 'tag_kurz') : '';
             }
             if (!$this->cols_array[$key]['html']) {
                 $entry[$key] = Html::pcdata($entry[$key]);
             }
         }
         if ($this->edit_enabled) {
             $icons['edit'] = Html::img('/' . INSTALL_PATH . '/Classes/Admin/Icons/16x16/edit.png', '');
             $icons['delete'] = Html::img('/' . INSTALL_PATH . '/Classes/Admin/Icons/16x16/cancel.png', '');
             $btns['edit'] = Html::a(SELF . '?edit=' . $entry['id'], $icons['edit'], array('title' => 'Eintrag bearbeiten'));
             $btns['delete'] = Html::a(SELF . '?delete=' . $entry['id'], $icons['delete'], array('title' => 'Eintrag löschen', 'onclick' => 'return delete_confirm(\'' . $entry['id'] . '\')'));
             $entry['edit_btns'] .= implode(' ', $btns);
         }
         $entry['alt_row'] = ' alt_row_' . $alternatig_rows;
         $return_string .= $template->parse_template('LOOP', $entry);
         $alternatig_rows = $alternatig_rows == 1 ? 0 : 1;
     }
     $return_string .= $template->parse_template('POST', $vars);
     return $return_string;
 }
 function htaccess_update()
 {
     $navi = $this->navi;
     $htaccess = RheinaufFile::get_file(DOCUMENT_ROOT . '.htaccess');
     preg_match('!(.*?#--REWRITE_RULES--#).*?(#--/REWRITE_RULES--#.*?)!s', $htaccess, $matches);
     $closed_urls = "\n";
     $open_urls = "\n\n#Nach hinten offene URLs für Module mit beliebigen Unterseiten\n";
     $regex_esc = '?*+()^$|[].';
     $rubrik_key = 0;
     foreach ($navi as $entry) {
         $rubrik = addcslashes($this->path_encode($this->I18n_get_real($entry['Rubrik'])), $regex_esc);
         $page_key = 0;
         foreach ($entry['Subnavi'] as $sub_entry) {
             $seite = addcslashes($this->path_encode($this->I18n_get_real($sub_entry['Seite'])), $regex_esc);
             if ($seite == 'index') {
                 continue;
             }
             $page_key++;
             $closed_urls .= 'RewriteRule ^' . $rubrik . '/' . $seite . '/$ CMSinit.php?r=' . $rubrik_key . '&s=' . $page_key . '&%{QUERY_STRING} [L,NC]' . "\n";
             $open_urls .= 'RewriteRule ^' . $rubrik . '/' . $seite . ' CMSinit.php?r=' . $rubrik_key . '&s=' . $page_key . '&%{QUERY_STRING} [L,NC]' . "\n";
         }
         $closed_urls .= 'RewriteRule ^' . $rubrik . '/$ CMSinit.php?r=' . $rubrik_key . '&s=0&%{QUERY_STRING} [L,NC]' . "\n";
         $open_urls .= 'RewriteRule ^' . $rubrik . ' CMSinit.php?r=' . $rubrik_key . '&s=0&%{QUERY_STRING} [L,NC]' . "\n";
         $rubrik_key++;
     }
     $new_htaccess = $matches[1] . $closed_urls . $open_urls . $matches[2];
     RheinaufFile::write_file(DOCUMENT_ROOT . '.htaccess', $new_htaccess);
 }
 function maxscale($file)
 {
     $size = getimagesize($file);
     if ($size[0] > $this->max_scale['x'] || $size[1] > $this->max_scale['y']) {
         if (!class_exists('Bilder')) {
             include_once 'Bilder.php';
         }
         if (!is_writeable($file)) {
             RheinaufFile::chmod($file, '777');
         }
         $img = new Bilder($file, $file);
         if ($size[0] > $this->max_scale['x']) {
             $img->scaleMaxX($this->max_scale['x']);
         } else {
             $img->scaleMaxY($this->max_scale['y']);
         }
         $img->output();
     }
 }
 function htaccess_update()
 {
     $navi = $this->navi;
     $htaccess = RheinaufFile::get_file(DOCUMENT_ROOT . '.htaccess');
     preg_match('!(.*?#--REWRITE_RULES--#).*?(#--/REWRITE_RULES--#)!s', $htaccess, $matches);
     $new_htaccess = "\n";
     $regex_esc = '?*+()^$|[].';
     $rubrik_key = 0;
     foreach ($navi as $entry) {
         $rubrik = addcslashes($this->path_encode($this->I18n_get_real($entry['Rubrik'])), $regex_esc);
         $page_key = 0;
         foreach ($entry['Subnavi'] as $sub_entry) {
             $seite = addcslashes($this->path_encode($this->I18n_get_real($sub_entry['Seite'])), $regex_esc);
             $new_htaccess .= 'RewriteRule ^' . $rubrik . '/' . $seite . ' CMSinit.php?r=' . $rubrik_key . '&s=' . $page_key . ' [L,NC,QSA]' . "\n";
             $page_key++;
         }
         $new_htaccess .= 'RewriteRule ^' . $rubrik . ' CMSinit.php?r=' . $rubrik_key . '&s=0 [L,NC,QSA]' . "\n";
         $rubrik_key++;
     }
     $new_htaccess = $matches[1] . $new_htaccess . $matches[2];
     RheinaufFile::write_file(DOCUMENT_ROOT . '.htaccess', $new_htaccess);
 }
 function content_module($title, $module)
 {
     $vars['title'] = $title;
     $vars['navi'] = $this->navi_menu();
     if (preg_match('/(.*?)\\((.*?)\\)/', $module, $match)) {
         $module = $match[1];
         $args = $match[2];
     }
     if (!class_exists($module)) {
         include_once $module . '.php';
     }
     if (is_callable(array($module, 'class_init'))) {
         eval('$instance = new $module (' . $args . ');');
         $instance->class_init($this);
     } else {
         $instance = new $module($this);
     }
     if ($module != 'Login' && $this->require_valid_user) {
         // hier nochmal checken, falls Modul eine eigene User-Tabelle mitbringt
         if ($this->custom_user_table) {
             Login::check_login($this);
         }
         if (!$this->valid_user) {
             return;
         }
     }
     $instance_show = $instance->show();
     $vars['other_css'] = $this->other_css;
     if (isset($instance->other_css)) {
         $vars['other_css'] .= $instance->other_css;
     }
     if (isset($GLOBALS['other_css'])) {
         $vars['other_css'] .= $GLOBALS['other_css'];
     }
     $vars['scripts'] = $this->scripts;
     if (isset($instance->scripts)) {
         $vars['scripts'] .= $instance->scripts;
     }
     //deprecated
     if (isset($GLOBALS['scripts'])) {
         $vars['scripts'] .= $GLOBALS['scripts'];
     }
     // half deprecated
     if (isset($_GET['noframe']) || $this->noframe) {
         if (isset($instance->extern)) {
             $GLOBALS['INCLUDE_EXTERN'] = $instance->extern;
             return;
         }
         return $instance_show;
     }
     if (RheinaufFile::is_file(DOCUMENT_ROOT . INSTALL_PATH . '/Templates/' . $modul . '/template.html')) {
         $page = new Seite($this, DOCUMENT_ROOT . INSTALL_PATH . '/Templates/' . $modul . '/template.html');
     } else {
         $page = new Seite($this, $this->template ? $this->template : 'default');
     }
     if (isset($instance->extern)) {
         $GLOBALS['HEADER'] = $page->header($vars);
         $GLOBALS['FOOTER'] = $page->footer($vars);
         $GLOBALS['INCLUDE_EXTERN'] = $instance->extern;
         return;
     }
     $header = $page->header($vars);
     //	if ($modul!='Admin')
     //	{
     $content = new Template($instance_show);
     $content->system =& $this;
     $content->init_snippets();
     $content = $content->parse_template('', $vars);
     //	}
     //	else $content = $instance_show;
     $footer = $page->footer($vars);
     return $header . $content . $footer;
 }
 function get_names()
 {
     return RheinaufFile::dir_array(DOCUMENT_ROOT . INSTALL_PATH . $this->gal_path, false, '.jpg');
 }