115 lines
1.8 KiB
C++
Executable File
115 lines
1.8 KiB
C++
Executable File
/*
|
|
* This file is a part of Winix
|
|
* and is not publicly distributed
|
|
*
|
|
* Copyright (c) 2010-2014, Tomasz Sowa
|
|
* All rights reserved.
|
|
*
|
|
*/
|
|
|
|
#include "template.h"
|
|
#include "core/misc.h"
|
|
|
|
|
|
|
|
namespace Winix
|
|
{
|
|
|
|
|
|
namespace Fun
|
|
{
|
|
|
|
Template::Template()
|
|
{
|
|
fun.url = L"template";
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Template::HasAccess()
|
|
{
|
|
if( config->template_only_root_use_template_fun )
|
|
{
|
|
// only root is allowed to change the template
|
|
return (cur->session->puser && cur->session->puser->super_user);
|
|
}
|
|
|
|
|
|
if( cur->request->is_item )
|
|
return system->HasWriteAccess(cur->request->item);
|
|
else
|
|
return system->HasWriteAccess(*cur->request->dir_tab.back());
|
|
}
|
|
|
|
|
|
void Template::PutLog(Item & item)
|
|
{
|
|
log << log3 << "Template: changed template for item.id: " << item.id << ", new template: ";
|
|
|
|
if( item.html_template.empty() )
|
|
log << "(taking from mount point)";
|
|
else
|
|
log << item.html_template;
|
|
|
|
log << logend;
|
|
}
|
|
|
|
|
|
void Template::CreateTemplateFileName(const std::wstring & index_str)
|
|
{
|
|
int index = Toi(index_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[system->mounts.MountParHtmlTemplate()];
|
|
|
|
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 )
|
|
{
|
|
cur->request->status = db->EditTemplateItemById(item.id, html_template);
|
|
|
|
if( cur->request->status == WINIX_ERR_OK )
|
|
{
|
|
item.html_template = html_template;
|
|
PutLog(item);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void Template::MakePost()
|
|
{
|
|
CreateTemplateFileName(cur->request->PostVar(L"template"));
|
|
ChangeTemplate(*cur->request->last_item);
|
|
|
|
system->RedirectToLastItem();
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
} // namespace Winix
|
|
|