コード例 #1
0
    function make_table($where = '', $template = '', $make_template = false, $table_direction = 'horizontal')
    {
        $db_table = $this->table;
        $vars = is_array($this->template_vars) ? $this->template_vars : array();
        if ($this->edit_enabled && $this->enable_events) {
            if (isset($_GET['editoptions']) && !$this->options_editor) {
                return $this->edit_options();
            }
            if (isset($_GET['delete'])) {
                $this->delete_entry();
            }
            if ($_GET['edit']) {
                return $this->make_form($_GET['edit']);
            }
            if (isset($_POST['edit_id'])) {
                $this->db_insert($_POST['edit_id']);
            }
            if (isset($_REQUEST['reentry'])) {
                return $this->make_form($_POST['edit_id'] ? $_POST['edit_id'] : $this->last_insert_id);
            }
            if (isset($_GET['new'])) {
                return $this->make_form();
            }
        }
        if ($this->enable_events) {
            if (isset($_GET['getSuggestions'])) {
                return $this->getSuggestions();
            }
        }
        if (isset($_GET['img'])) {
            $this->img_thumb();
        }
        if (isset($this->result_array)) {
            $result = $this->result_array;
        } else {
            $order_by = $this->order_by ? $this->order_by : 'id';
            if ($_GET['dir'] == 'desc') {
                $order_dir = 'DESC';
            } else {
                if ($_GET['dir'] == 'asc') {
                    $order_dir = 'ASC';
                } else {
                    $order_dir = $this->order_dir ? $this->order_dir : 'ASC';
                }
            }
            if ($_GET['results_per_page']) {
                $results_per_page = $this->results_per_page = $_GET['results_per_page'];
                setcookie($this->results_per_page_cookie_name, $_GET['results_per_page'], 10000000000.0, '/');
            } else {
                if ($_COOKIE[$this->results_per_page_cookie_name]) {
                    $results_per_page = $this->results_per_page = $_COOKIE[$this->results_per_page_cookie_name];
                } else {
                    $results_per_page = $this->results_per_page;
                }
            }
            $results_per_page = General::input_clean($results_per_page, true);
            $start_by = $_GET['start'] ? $_GET['start'] : ($_GET['start'] = 0);
            $start_by = General::input_clean($start_by, true);
            foreach ($this->enable_search_for as $col) {
                if ($_GET[$col]) {
                    $value = General::input_clean($_GET[$col], true);
                    $search_method = $this->cols_array[$col]['search_method'] ? $this->cols_array[$col]['search_method'] : $this->search_method;
                    switch ($search_method) {
                        case '=':
                        case '<':
                        case '>':
                        case '>=':
                        case '<=':
                        case 'LIKE':
                            $where[] = "`{$col}` {$search_method} '{$value}'";
                            break;
                        case 'LIKE %.%':
                            $where[] = "`{$col}` LIKE '%{$value}%'";
                            break;
                        case 'LIKE %.':
                            $where[] = "`{$col}` LIKE '%{$value}'";
                            break;
                        case 'LIKE .%':
                            $where[] = "`{$col}` LIKE '{$value}%'";
                            break;
                    }
                }
            }
            $where = $where ? "WHERE " . implode($this->search_combine, $where) : '';
            $group_by = $this->group_by ? "GROUP BY `{$this->group_by}`" : '';
            $order = $_GET['order'] ? rawurldecode($_GET['order']) : $order_by;
            $order = General::input_clean($order, true);
            if ($this->sql == '') {
                $sql = "SELECT * FROM `{$db_table}` {$where} {$group_by} ORDER BY `{$order}` {$order_dir}";
            } else {
                $sql = $this->sql;
            }
            $num_rows = $this->num_rows = $this->connection->db_num_rows($sql);
            if (!$results_per_page) {
                $results_per_page = $this->results_per_page = $num_rows;
            }
            if ($results_per_page || $start_by) {
                $num_rows = $this->num_rows = $this->connection->db_num_rows($sql);
                if (!isset($_GET['allresults'])) {
                    $sql .= " LIMIT {$start_by},{$results_per_page}";
                }
            }
            /*if ($this->last_insert_id)
            		{
            			$sql = "SELECT * FROM `$db_table` $group_by ORDER BY `$order` $order_dir";
            			$result = $this->result = $this->connection->db_assoc($sql);
            			for ($i = 0;$i<count($result);$i++)
            			{
            				if ($result[$i]['id'] == $this->last_insert_id)
            				{
            					$start_by = floor($i/$this->results_per_page) * $this->results_per_page;
            					if ($start_by == $this->results_per_page) $start_by = 0;
            					$url = SELF_URL.'?start='.$start_by.'&'.$this->GET_2_url(array('start'));
            					$url = html_entity_decode($url);
            					if (isset($_GET['noframe'])) $url .= '&noframe';
            					$url .= '#entry'.$this->last_insert_id;
            					header("Location: $url");
            					exit;
            				}
            			}
            		}*/
            $result = $this->result = $this->connection->db_assoc($sql);
        }
        // now we have the result and can do things with it
        if (isset($_GET['export'])) {
            $this->export($result, 'id');
        }
        if (!$template || $make_template) {
            $head = '';
            $loop = '';
            $alt_col = '';
            $colspan = 0;
            foreach ($this->cols_array as $key => $col) {
                if ($key == 'id') {
                    continue;
                }
                $type = $this->cols_array[$key]['type'];
                $button = '{' . $key . '_sort}';
                if ($type != 'ignore' && $type != 'hidden') {
                    $head .= "<th>{$button}</th>\n";
                    $loop .= "<td class=\"{$alt_col}{If:alt_row}\">{If:{$key}}</td>\n";
                    $alt_col = $alt_col !== '' ? '' : 'alt_col';
                    ++$colspan;
                }
            }
            $loop .= "<td class=\"{$alt_col}{If:alt_row}\">{If:edit_btns}</td>\n";
            $loop = "<tr id=\"entry{id}\">\n{$loop}</tr>\n";
            $search = count($this->enable_search_for) ? $this->search_form() : '';
            $export_button = $this->show_export ? '<a href=\\"{SELF_URL}?export&amp;allresults&amp;{If:export_get_vars}\\"><img src=\\"/RheinaufCMS/System/Scaffold/icon_excel_doc.gif\\" alt=\\"Excel\\" title=\\"Ergebnisse als Excel-Tabelle speichern\\" /></a>' : '';
            $new_template = '';
            $new_template .= '
<!--PAGE_BROWSER-->
<form method="get" action="{SELF_URL}" onsubmit="httpRequestSubmit(this);return false;">

{IfNotEmpty:prev_url(<a href="[prev_url]" class="button" onclick="httpRequestGET(\'[prev_url]&amp;noframe\',setContent);return false">Zurück</a>)}
{IfNotEmpty:next_url(<a href="[next_url]" class="button" onclick="httpRequestGET(\'[next_url]&amp;noframe\',setContent);return false">Weiter</a>)}
&nbsp;&nbsp;&nbsp;{If:new_btn}
&nbsp;&nbsp;&nbsp;{num_entries} Einträge auf {num_pages} Seiten
&nbsp;&nbsp;&nbsp;Zeige <input type="text" size="2" name="results_per_page" id="results_per_page" value="{results_per_page}" style="text-align:center"/> Einträge pro Seite
<input type="submit" value="Aktualisieren" />

{If:results_per_page_get_vars}
</form>
<!--/PAGE_BROWSER-->';
            $colspan_minus1 = $colspan - 1;
            $new_template .= "\r\n<!--PRE-->\r\n{$search}\r\n<table>\r\n<thead>\r\n<tr><td colspan=\"{$colspan_minus1}\">{page_browser}</td>\r\n<td>{$export_button} </td></tr>\r\n{IfNotEmpty:pagination(<tr><td colspan=\"{$colspan}\">Seite [pagination]</td></tr>)}\r\n<tr>{$head}</tr>\r\n</thead>\r\n<tbody>\r\n<!--/PRE-->\r\n<!--NO_RESULTS-->\r\n<tr><td colspan=\"{$colspan}\">Keine Einträge gefunden<td></tr>\r\n<!--/NO_RESULTS-->\r\n";
            $new_template .= "<!--LOOP-->\n{$loop}\n<!--/LOOP-->\n";
            $new_template .= "<!--POST-->\n</tbody><tfoot><tr><td colspan=\"{$colspan}\">{If:new_btn}</td></tr></tfoot></table>\n<!--/POST-->\n";
            if ($make_template) {
                RheinaufFile::write_file($template, $new_template);
            }
            $template = $new_template;
        }
        $template = new Template($template);
        $return_string = '';
        foreach ($this->enable_search_for as $search_field) {
            $vars[$search_field . "_search_value"] = $_GET[$search_field];
            $vars['filter_get_vars'] = $this->GET_2_input(array_merge($this->enable_search_for, array('start')));
        }
        if ($this->edit_enabled) {
            $icons['new'] = Html::img('/Libraries/Icons/16x16/edit_add.png', '');
            $vars['new_btn'] = Html::a(SELF_URL . '?new&amp;' . $this->GET_2_url(), $icons['new'] . 'Eintrag hinzufügen', array('title' => 'Eintrag hinzufügen', 'class' => 'button'));
        }
        $vars['set_filters'] = $this->get_filters("&");
        $vars['export_get_vars'] = $this->GET_2_url();
        $vars['num_pages'] = $pages = $this->get_pages();
        $vars['num_entries'] = $num_rows;
        $vars['prev_url'] = ($prev = $this->prev_link()) ? SELF_URL . '?' . $prev . '&amp;' . $this->GET_2_url('start') : '';
        $vars['next_url'] = ($next = $this->next_link()) ? SELF_URL . '?' . $next . '&amp;' . $this->GET_2_url('start') : '';
        $vars['this_page'] = $this->get_page();
        $vars['results_per_page_get_vars'] = $this->GET_2_input('results_per_page');
        $vars['results_per_page'] = $results_per_page;
        $vars['page_browser'] = $template->parse_template('PAGE_BROWSER', $vars);
        $vars['pagination'] = $this->pagination();
        foreach ($this->cols_array as $key => $value) {
            $name = $this->cols_array[$key]['name'];
            if ($_GET['order'] == $key) {
                if ($_GET['dir'] == 'asc') {
                    $name .= '&#x25B2;';
                } else {
                    $name .= '&#x25BC;';
                }
                //down
                $dir = $_GET['dir'] == 'desc' ? 'asc' : 'desc';
            } else {
                if (!isset($_GET['order']) && $key == $this->order_by) {
                    if ($this->order_dir == 'ASC') {
                        $name .= '&#x25B2;';
                        // up
                        $dir = 'desc';
                    } else {
                        $name .= '&#x25BC;';
                        //down
                        $dir = 'asc';
                    }
                } else {
                    $dir = $this->order_dir == 'ASC' ? 'asc' : 'desc';
                }
            }
            $vars[$key . '_sort'] = $this->make_btn_link(SELF_URL . '?' . $this->GET_2_url(array('order', 'dir')) . '&amp;order=' . rawurlencode($key) . '&amp;dir=' . $dir, $name, array('class' => 'button', 'style' => 'display:block'));
        }
        $return_string .= $template->parse_template('PRE', $vars);
        $alternatig_rows = 0;
        foreach ($result as $entry) {
            $entry = array_merge($vars, $entry);
            foreach ($entry as $key => $value) {
                $entry[$key . '_name'] = $this->cols_array[$key]['name'];
                if ($this->cols_array[$key]['options'] && ($this->cols_array[$key]['type'] == 'check' || $this->cols_array[$key]['type'] == 'radio' || $this->cols_array[$key]['type'] == 'select')) {
                    $options[$key] = $this->get_options($this->cols_array[$key]['options'], $this->cols_array[$key]['options_sort'], $this->cols_array[$key]['options_insert_id']);
                    $v = explode('&delim;', $value);
                    $v = General::trim_array($v);
                    $value = array();
                    foreach ($v as $k) {
                        if ($options[$key][$k]) {
                            $value[] = $options[$key][$k];
                        } else {
                            $value[] = $k;
                        }
                    }
                    $value = count($value) ? implode(', ', $value) : '';
                }
                if ($this->cols_array[$key]['type'] == 'timestamp') {
                    $value = intval(Date::unify_timestamp($value)) != '0' ? Date::timestamp2datum($value, $this->datumsformat ? $this->datumsformat : 'tag_kurz') : '';
                }
                if ($this->cols_array[$key]['type'] == 'upload') {
                    $value = rawurlencode($value);
                } elseif ($this->cols_array[$key]['type'] != 'textarea') {
                    $value = htmlspecialchars($value);
                }
                if ($this->cols_array[$key]['type'] == 'textarea' && !$this->cols_array[$key]['html']) {
                    $value = nl2br(htmlspecialchars($value));
                }
                if ($this->cols_array[$key]['max_length'] && strlen($value) > $this->cols_array[$key]['max_length']) {
                    $value = General::clip_words($value, $this->cols_array[$key]['max_length']);
                }
                if ($transform = $this->cols_array[$key]['transform']) {
                    if (is_callable($transform)) {
                        $value = $transform($key, $value);
                    } else {
                        eval($transform);
                    }
                }
                $entry[$key] = $value;
            }
            if ($this->edit_enabled) {
                $icons['edit'] = Html::img('/Libraries/Icons/16x16/edit.png', '');
                $icons['delete'] = Html::img('/Libraries/Icons/16x16/cancel.png', '');
                $entry['edit_btn_url'] = SELF_URL . '?edit=' . $entry['id'] . '&amp;' . $this->GET_2_url();
                $entry['delete_btn_url'] = SELF_URL . '?delete=' . $entry['id'] . '&amp;' . $this->GET_2_url('delete', 'noframe');
                $btns['edit'] = Html::a($entry['edit_btn_url'], $icons['edit'], array('title' => 'Eintrag bearbeiten'));
                $btns['delete'] = Html::a($entry['delete_btn_url'], $icons['delete'], array('title' => 'Eintrag löschen', 'onclick' => 'return delete_confirm(this,\'' . $entry['id'] . '\')'));
                $entry['edit_btn'] = $btns['edit'];
                $entry['delete_btn'] = $btns['delete'];
                $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;
        }
        if (!count($result)) {
            $return_string .= $template->parse_template('NO_RESULTS', $vars);
        }
        $return_string .= $template->parse_template('POST', $vars);
        return $return_string;
    }
コード例 #2
0
 function next_dates()
 {
     $show_sql = "SELECT * FROM `{$this->db_table}` WHERE `DTSTART` >= '" . Date::now() . "' AND `CLASS` = 'PUBLIC' ORDER BY `DTSTART` ASC LIMIT 0,{$this->num_show_next_dates}";
     $vars = array();
     $template = new Template(INSTALL_PATH . '/Module/Kalender/Templates/NextDates.template.html');
     $return = $template->parse_template('PRE', $vars);
     $entries = $this->connection->db_assoc($show_sql);
     foreach ($entries as $entry) {
         $date = $entry['DTSTART'];
         $entry['start_tag'] = Date::tag($date);
         $entry['start_num_monat'] = Date::monat($date);
         $entry['start_monat'] = Date::month_name($entry['start_num_monat'], 'kurz');
         $entry['start_jahr'] = Date::jahr($date);
         $date = $entry['DTEND'];
         if ($date) {
             $entry['end_tag'] = Date::tag($date);
             $entry['end_num_monat'] = Date::monat($date);
             $entry['end_monat'] = Date::month_name($entry['end_num_monat'], 'kurz');
             $entry['end_jahr'] = Date::jahr($date);
         }
         $entry['clip'] = General::clip_words($entry['SUMMARY'], 50);
         $return .= $template->parse_template('LOOP', $entry);
     }
     $return .= $template->parse_template('POST', $vars);
     return $return;
 }
コード例 #3
0
 function make_table($sql = '', $template = '')
 {
     $db_table = $this->table;
     $vars = is_array($this->template_vars) ? $this->template_vars : array();
     $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'] : 0;
     if ($sql == '') {
         $sql = "SELECT * FROM `{$db_table}` ORDER BY `{$order_by}` {$order_dir}";
     }
     $vars['pages'] = $this->get_pages($sql);
     $vars['page'] = $this->get_page();
     if ($results_per_page || $start_by) {
         if (!$this->num_rows) {
             $num_rows = $this->num_rows = $this->connection->db_num_rows($sql);
         } else {
             $num_rows = $this->num_rows;
         }
         if (!$results_per_page) {
             $results_per_page = $num_rows;
         }
         $sql .= " LIMIT {$start_by},{$results_per_page}";
     }
     $result = $this->connection->db_assoc($sql);
     $template = new Template($template);
     $vars['next_link'] = ($next = $this->next_link()) ? "?{$next}" : '';
     $vars['next_link'] .= $this->room && $vars['next_link'] ? "&amp;room=" . $this->room : '';
     $vars['prev_link'] = ($prev = $this->prev_link()) ? "?{$prev}" : '';
     $vars['prev_link'] .= $this->room && $vars['prev_link'] ? "&amp;room=" . $this->room : '';
     $return_string = '';
     $return_string .= $template->parse_template('PRE', $vars);
     $alternatig_rows = 0;
     $loop_count = 0;
     $einzel = 0;
     $row = '';
     for ($i = 0; $i < ($count = count($result)); $i++) {
         $loop_count++;
         $result[$i] = array_merge($vars, $result[$i]);
         foreach ($result[$i] as $key => $value) {
             if (is_array($this->cols_array[$key]['options'])) {
                 $result[$i][$key] = $this->cols_array[$key]['options'][$value];
             }
             if ($this->cols_array[$key]['type'] == 'timestamp') {
                 $result[$i][$key] = intval(Date::unify_timestamp($value)) != '0' ? Date::timestamp2datum($value, $this->datumsformat ? $this->datumsformat : 'tag_kurz') : '';
             }
             if ($this->cols_array[$key]['type'] == 'upload') {
                 $result[$i][$key] = rawurlencode($value);
             } elseif (!$this->cols_array[$key]['html']) {
                 $result[$i][$key] = htmlspecialchars($value);
             }
         }
         $result[$i]['Dateiname'] = rawurlencode($result[$i]['Dateiname']);
         $result[$i]['Titelbild'] = rawurlencode($result[$i]['Titelbild']);
         $result[$i]['clip_name'] = General::clip_words($result[$i]['Name'], 22);
         $room = $_GET['room'] ? $_GET['room'] : $result[$i]['RoomId'];
         $result[$i]['einzel_link'] = SELF . '?room=' . $room . '&amp;start=' . $_GET['start'];
         if (!$this->exhibition_room_selection) {
             $result[$i]['einzel_link'] .= '&amp;Einzelansicht=' . $einzel;
         }
         $result[$i]['alt_row'] = ' alt_row_' . $alternatig_rows;
         $row .= $template->parse_template('LOOP', $result[$i]);
         if ($loop_count == 4 || $i == $count - 1) {
             if ($i == $count - 1) {
                 for ($j = $loop_count; $j < 4; $j++) {
                     $row .= '<td class="gal_element">&nbsp;</td>';
                 }
             }
             $return_string .= '<tr>' . $row . '</tr>';
             $row = '';
             $loop_count = 0;
         }
         $alternatig_rows = $alternatig_rows == 1 ? 0 : 1;
         //$einzel = ($einzel == $this->results_per_page-1) ? 0 : $einzel++;
         $einzel++;
     }
     $return_string .= $template->parse_template('POST', $vars);
     return $return_string;
 }