diff --git a/core/request.cpp b/core/request.cpp index e556fd7..5abde35 100755 --- a/core/request.cpp +++ b/core/request.cpp @@ -86,6 +86,7 @@ void Request::Clear() item_tab.clear(); item.Clear(); dir_tab.clear(); + last_item = 0; is_item = false; function = 0; param_tab.clear(); diff --git a/core/request.h b/core/request.h index 82cbd36..052bdb0 100755 --- a/core/request.h +++ b/core/request.h @@ -107,9 +107,8 @@ struct Request // send as attachment (causing header: content-disposition: attachment) bool send_as_attachment; - // !! moze dolozyc pole Item * last_item - // i ono bedzie wskazywalo na albo item (jesli jest) albo na ostatni katalog - // ? + // this is a pointer either to the item (if exists) or to the last directory + Item * last_item; Request(); diff --git a/core/system.cpp b/core/system.cpp index 335b610..2e363cf 100755 --- a/core/system.cpp +++ b/core/system.cpp @@ -128,17 +128,15 @@ Item * pdir; void System::RedirectToLastDir() { - // !! dac sprawdzenie czy istnieje - RedirectTo( *request->dir_tab.back() ); + if( !request->dir_tab.empty() ) + RedirectTo( *request->dir_tab.back() ); } void System::RedirectToLastItem() { - if( request->is_item ) - RedirectTo(request->item); - else - RedirectTo( *request->dir_tab.back() );// !! dac sprawdzenie czy istnieje + if( request->last_item ) + RedirectTo( *request->last_item ); } diff --git a/functions/functionparser.cpp b/functions/functionparser.cpp index 74e287a..4ee0f42 100755 --- a/functions/functionparser.cpp +++ b/functions/functionparser.cpp @@ -58,6 +58,8 @@ void FunctionParser::ParseDirectories() ++get_index; } + + request->last_item = request->dir_tab.back(); } @@ -77,6 +79,8 @@ void FunctionParser::ParseItem() if( request->status == WINIX_ERR_OK ) { + request->last_item = &request->item; + if( request->role == Request::authorizer && request->item.auth == Item::auth_none ) { log << log1 << "FP: item.url: " << url << " exists but has not a static content (authorizer role)" << logend; diff --git a/functions/template.cpp b/functions/template.cpp index 567085c..d16a1a0 100755 --- a/functions/template.cpp +++ b/functions/template.cpp @@ -40,27 +40,64 @@ bool Template::HasAccess() } -void Template::EditTemplate(Item & item) +void Template::PutLog(Item & item) { - html_file = request->PostVar("template"); - TrimWhite(html_file); - request->status = db->EditTemplateItemById(item.id, html_file); + log << log3 << "Template: changed template for item.id: " << item.id << ", new template: "; - if( request->status == WINIX_ERR_OK ) - item.html_template = html_file; + if( item.html_template.empty() ) + log << "(taking from mount point)"; + else + log << item.html_template; + + log << logend; +} + + +void Template::CreateTemplateFileName(const std::string & index_str) +{ + int index = atoi(index_str.c_str()); + + if( index < 0 ) + { + html_template.clear(); + } + else + if( index == 0 ) + { + html_template = config->templates_index; + } + else + { + index -= 1; + Mount::ParamRow & par = system->mounts.pmount->param[Mount::par_html_template]; + + if( !par.defined || (size_t)index >= par.arg.size() ) + html_template.clear(); + else + html_template = par.arg[index]; + } +} + + +void Template::ChangeTemplate(Item & item) +{ + if( html_template != item.html_template ) + { + request->status = db->EditTemplateItemById(item.id, html_template); + + if( request->status == WINIX_ERR_OK ) + { + item.html_template = html_template; + PutLog(item); + } + } } void Template::MakePost() { - if( request->is_item ) - { - EditTemplate(request->item); - } - else - { - EditTemplate(*request->dir_tab.back()); - } + CreateTemplateFileName(request->PostVar("template")); + ChangeTemplate(*request->last_item); system->RedirectToLastItem(); } diff --git a/functions/template.h b/functions/template.h index ace9f19..641a8bb 100755 --- a/functions/template.h +++ b/functions/template.h @@ -28,8 +28,10 @@ public: private: - std::string html_file; - void EditTemplate(Item & item); + std::string html_template; + void CreateTemplateFileName(const std::string & index_str); + void ChangeTemplate(Item & item); + void PutLog(Item & item); }; diff --git a/html/error.html b/html/error.html index 920c320..f9e2c0b 100755 --- a/html/error.html +++ b/html/error.html @@ -1,10 +1,10 @@ - -[if-no winix_err_is "0"] -

- [if-one winix_is_err_in_locales] - [winix_err_msg_from_locales] - [else] - {winix_err_default} [winix_err_code] - [end] -

-[end] + +[if-no winix_err_is "0"] +

+ [if-one winix_is_err_in_locales] + [winix_err_msg_from_locales] + [else] + {winix_err_default} [winix_err_code] + [end] +

+[end] diff --git a/html/fun_chmod.html b/html/fun_chmod.html index e609eb5..ad08b5c 100755 --- a/html/fun_chmod.html +++ b/html/fun_chmod.html @@ -1,2 +1,2 @@ -[include "fun_priv.html"] - +[include "fun_priv.html"] + diff --git a/html/fun_chown.html b/html/fun_chown.html index 2e6bb56..071cdb0 100755 --- a/html/fun_chown.html +++ b/html/fun_chown.html @@ -1 +1 @@ -[include "fun_priv.html"] +[include "fun_priv.html"] diff --git a/html/fun_template.html b/html/fun_template.html index a46da64..a409d9a 100755 --- a/html/fun_template.html +++ b/html/fun_template.html @@ -1,61 +1,61 @@ -

{template_header}

- -[include "error.html"] - -

- -[if item_is] - - {template_info_file}: - - [if item_has_html_template] - [item_html_template] - [else] - {template_from_mount_point} - - [if mount_has_html_template] - ([mount_first_html_template]) - [else] - ([template_index]) - [end] - [end] - -[else] - - {template_info_dir}: - - [if dir_last_has_html_template] - [dir_last_html_template] - [else] - {template_from_mount_point} - - [if mount_has_html_template] - ([mount_first_html_template]) - [else] - ([template_index]) - [end] - [end] - -[end] - -

- - - - +

{template_header}

+ +[include "error.html"] + +

+ +[if item_is] + + {template_info_file}: + + [if item_has_html_template] + [item_html_template] + [else] + {template_from_mount_point} + + [if mount_has_html_template] + ([mount_first_html_template]) + [else] + ([template_index]) + [end] + [end] + +[else] + + {template_info_dir}: + + [if dir_last_has_html_template] + [dir_last_html_template] + [else] + {template_from_mount_point} + + [if mount_has_html_template] + ([mount_first_html_template]) + [else] + ([template_index]) + [end] + [end] + +[end] + +

+ + + +
{template_form_legend} - {template_form_info}: + {template_form_info}: - + + [# the first should be an empty string (value="") which means: a first template from the mount point] + [for template_tab] - [template_tab_file_name] + [end] diff --git a/html/fun_uname.html b/html/fun_uname.html index 736d1a2..71a9f2d 100755 --- a/html/fun_uname.html +++ b/html/fun_uname.html @@ -3,4 +3,4 @@ [include "error.html"] -

Winix [sys_ver_major].[sys_ver_minor].[sys_ver_revision]

+

Winix [sys_ver_major].[sys_ver_minor].[sys_ver_revision]

diff --git a/templates/template.cpp b/templates/template.cpp index d7ae5d3..fdaf86e 100755 --- a/templates/template.cpp +++ b/templates/template.cpp @@ -93,6 +93,11 @@ void template_tab(Info & i) } +void template_tab_index(Info & i) +{ + i.out << temp_index; +} + void template_tab_isdefault(Info & i) { diff --git a/templates/templates.cpp b/templates/templates.cpp index 7f4beee..555621b 100755 --- a/templates/templates.cpp +++ b/templates/templates.cpp @@ -460,6 +460,7 @@ void Templates::CreateFunctions() */ ezc_functions.Insert("template_index", template_index); ezc_functions.Insert("template_tab", template_tab); + ezc_functions.Insert("template_tab_index", template_tab_index); ezc_functions.Insert("template_tab_isdefault", template_tab_isdefault); ezc_functions.Insert("template_tab_file_name", template_tab_file_name); diff --git a/templates/templates.h b/templates/templates.h index b3611a4..616cb1c 100755 --- a/templates/templates.h +++ b/templates/templates.h @@ -418,6 +418,7 @@ namespace TemplatesFunctions */ void template_index(Info & i); void template_tab(Info & i); + void template_tab_index(Info & i); void template_tab_isdefault(Info & i); void template_tab_file_name(Info & i);