Помощь с гостевой книгой
Tension MAN 20.06.2004 09:57
Вот код файла arc.html
Код:
@title[]
Архив гостиной
@content[]
^connect[
mysql://root@localhost/mmm?charset=cp1251_koi8]{
^use[/public_gb/scr.p]
$scroller[^scroller::create[
$.path_param[record]
$.table_count[^int:sql{SELECT COUNT(*) FROM gbnew }[$.default{0}]]
$.number_per_section[10]
$.section_per_page[10000]
$.type[page]
]]
$scroll[<br><span class="styleX">^scroller.draw[<< ; >>]</span><br>]
<b>$scroll</b>
<hr>
$gb[^table::sql{
SELECT * FROM gbnew
ORDER BY
id DESC
}[
$.limit($scroller.number_per_section)
$.offset($scroller.record_number-1)
]
]
}
^gb.menu{
}
Далее код файла, который упоминается в коде выше - scr.p (не знаю понадобится он или нет, и всё же...):
Код:
@CLASS
scroller
####
# Scroller.p - draws the [section|page|record number] navigation ruler of your table records
#
# Calling of current operator looks like this
# 1. first connect your scroller class by ^use[scroller.p] or @USE scroller.p
#
# 2. create scroller object by typing this row (parameters passed in hash)
# $scroller[^scroller::create[
# $.request[$form:fields]
# $.path_param[record]
# $.table_count[^your_table.count[]]
# $.number_per_section[25]
# $.section_per_page[5]
# $.type[page]
# ]
# ]
#
# Parameters Description:
# request - hash which contains fields with values
# path_param - name of request field which will pass the record number in the request query
# Example: $.path_param[record] -> the path will be: /path/?your_previous_params_if_any&record=
# WARNING! If you'll define the path_param, programm will override all params in request query with same name
# table_count - records count of table we want to scroll
# number_per_section - number of records per section
# section_per_page - number of sections per page
# type - scroller type, must be "page"(will display number of pages against records) or blank(will display number of records)
#
# 3. draw your ruler by typing this row
# ^scroller.draw[<;>; | ]
# < - previous navigation char
# > - next navigation char
# | - sections delimiter
# it will draw a navigation ruler of your table records
#
# 4. .select() current section records and .menu{} your table using code below(if you need to .menu{} any)
# $current_section[^your_table.select(^your_table.line[] >= $scroller.record_number && ^your_table.line[] <= ($scroller.record_number + $scroller.number_per_section - 1))]
# ^current_section.menu{
# .
# .
# .
# }
####
#######################################
## creates an object and defines navigation ruler of your table records
@create[params][path_param;field;value]
## checking params for defining
^if(!def $params || !($params is hash)){
^throw[parser.runtime;scroller;Defined none of parameters. Please, check your settings]
}
## link path creating and record number detecting
^if(def $params.path_param){
$path_param[$params.path_param]
$record_number(^form:$path_param.int(1))
}{
^throw[parser.runtime;scroller;Parameter ^$.path_param[] is undefined. Please, check your settings]
}
^if(def $params.request && $params.request is hash){
$path[?^params.request.foreach[field;value]{^if($field ne $path_param){$field=$value&^;}}$path_param=]
}{
$path[?^form:fields.foreach[field;value]{^if($field ne $path_param){$field=$value&^;}}$path_param=]
}
## number per section detecting
$number_per_section(^params.number_per_section.int(1))
^if($number_per_section <= 0){$number_per_section(1)}
## record number optimising
^if($record_number <=0){$record_number(1)}
$record_number($record_number\$number_per_section*$number_per_section)
^if($number_per_section != 1){^record_number.inc[]}
## section per page detecting and optimising
^if(def $params.section_per_page){
$section_per_page(^params.section_per_page.int(1))
^if($section_per_page <= 0){$section_per_page(1)}
}
## table count detecting
$table_count(^params.table_count.int(1))
## scroller type detecting
$type[$params.type]
## section limits defining
^if($section_per_page){
$first_number(($record_number\$number_per_section - $section_per_page\2)*$number_per_section)
^if($number_per_section != 1){^first_number.inc[]}
^if($first_number <= 0){$first_number(1)}
$section($section_per_page)
}{
$first_number(1)
^if($number_per_section == 1){
$section($table_count)
}{
$section(^math:ceiling($table_count/$number_per_section))
}
}
## detecting last section page - it must be equal to $number_per_section
^if(($number_per_section != 1 && $section_per_page || $section_per_page) && ^math:ceiling(($table_count-$first_number)/$number_per_section) < $section){
$first_number(($table_count-$number_per_section*($section_per_page-1))\$number_per_section*$number_per_section)
^if($number_per_section != 1){^first_number.inc[]}
^if($table_count%$number_per_section == 0 && $number_per_section != 1){^first_number.dec($number_per_section)}
}
## first section start position
^if($first_number <=0){$first_number(1)}
$second_number($first_number + $number_per_section - 1)
######## end of @create[] constructor ########
######## draw method - draws the ruler ########
## returns a navigation ruler
@draw[previous;next;delimeter][previous;next;delimeter;f1]
## previous link
^if($section_per_page && $first_number > 1){
^post_link[^eval($first_number - $number_per_section);^if(def $previous){^taint[html][$previous]}{<^;};$record_number;$path]
}
## scroller body
^for[f1](1;$section){
^if($first_number <= $table_count){
^if($number_per_section == 1){
^post_link[$first_number;$first_number;$record_number;$path]
}{
^if($type eq "page"){
^post_link[$first_number;^math:ceiling($first_number/$number_per_section);$record_number;$path]
}{
^if($second_number > $table_count){
^post_link[$first_number;^if($first_number != $table_count){<nobr>${first_number}-$table_count</nobr>}{$first_number};$record_number;$path]
}{
^post_link[$first_number;<nobr>${first_number}-$second_number</nobr>;$record_number;$path]
}
}
}
}
^first_number.inc($number_per_section)
^second_number.inc($number_per_section)
}{
## sections delimiter
^if($number_per_section != 1 && $type ne "page" && ($first_number - $number_per_section) <= $table_count){^if(def $delimeter){^taint[html][$delimeter]}{ | }}
}
## next link
^if($section_per_page && ($second_number - $number_per_section) < $table_count){
^post_link[^eval($second_number - $number_per_section + 1);^if(def $next){^taint[html][$next]}{>^;};$record_number;$path]
}
######## end of @draw[] method ########
######## link drawing method ########
## can be replaced by user to his/her needings
@post_link[first_number;text_link;record_number;path][first_number;text_link;record_number;path]
$pages[^eval($table_count\10)]
$www[^eval($pages - ^math:ceiling($first_number/$number_per_section) + 2)]
^if($record_number != $first_number){
$result[<a href="/gb/guestbook.html${path}$first_number">$www</a>]
}{
$result[<span style="background-color:#ffffff^; color:#426394^; padding:0 3 1 3">$www</span>]
}
######## end of @post_link operator ########
нужно чтобы на странице arc.html страницы были в разбиты по месяцам, ну типа:
Год 2003
Январь - 123, 124, 126.... 278 и т.д.
Февраль - 341, 342 и т.д.
...
...
Год 2004
....
Всем кому не лень - вперёд!
- Помощь с гостевой книгой, Tension MAN 20.06.2004 09:57