2008-12-30 02:05:03 +01:00
|
|
|
/*
|
2010-02-28 01:08:10 +01:00
|
|
|
* This file is a part of Winix
|
2008-12-30 02:05:03 +01:00
|
|
|
* and is not publicly distributed
|
|
|
|
*
|
2010-02-28 22:33:06 +01:00
|
|
|
* Copyright (c) 2008-2010, Tomasz Sowa
|
2008-12-30 02:05:03 +01:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "templates.h"
|
2010-08-10 18:12:50 +02:00
|
|
|
#include "core/misc.h"
|
|
|
|
#include "functions/functions.h"
|
2008-12-30 02:05:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
namespace TemplatesFunctions
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void dir(Info & i)
|
|
|
|
{
|
2010-08-10 22:43:38 +02:00
|
|
|
for(size_t a=0 ; a<request->dir_tab.size() ; ++a)
|
2008-12-30 02:05:03 +01:00
|
|
|
{
|
2010-08-10 22:43:38 +02:00
|
|
|
HtmlEscape(i.out, request->dir_tab[a]->url);
|
2008-12-30 02:05:03 +01:00
|
|
|
i.out << '/';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-16 01:37:00 +01:00
|
|
|
void dir_without_slash(Info & i)
|
|
|
|
{
|
2010-08-10 22:43:38 +02:00
|
|
|
for(size_t a=0 ; a<request->dir_tab.size() ; ++a)
|
2010-02-16 01:37:00 +01:00
|
|
|
{
|
2010-08-10 22:43:38 +02:00
|
|
|
HtmlEscape(i.out, request->dir_tab[a]->url);
|
2010-02-16 01:37:00 +01:00
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
if( a < request->dir_tab.size()-1 )
|
2010-02-16 01:37:00 +01:00
|
|
|
i.out << '/';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-05 21:44:49 +02:00
|
|
|
void dir_parent(Info & i)
|
|
|
|
{
|
2010-08-10 22:43:38 +02:00
|
|
|
if( request->dir_tab.empty() )
|
2010-06-05 21:44:49 +02:00
|
|
|
return;
|
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
for(size_t a=0 ; a<request->dir_tab.size()-1 ; ++a)
|
2010-06-05 21:44:49 +02:00
|
|
|
{
|
2010-08-10 22:43:38 +02:00
|
|
|
HtmlEscape(i.out, request->dir_tab[a]->url);
|
2010-06-05 21:44:49 +02:00
|
|
|
i.out << '/';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void dir_parent_without_slash(Info & i)
|
|
|
|
{
|
2010-08-10 22:43:38 +02:00
|
|
|
if( request->dir_tab.empty() )
|
2010-06-05 21:44:49 +02:00
|
|
|
return;
|
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
for(size_t a=0 ; a<request->dir_tab.size()-1 ; ++a)
|
2010-06-05 21:44:49 +02:00
|
|
|
{
|
2010-08-10 22:43:38 +02:00
|
|
|
HtmlEscape(i.out, request->dir_tab[a]->url);
|
2010-06-05 21:44:49 +02:00
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
if( request->dir_tab.size()>=2 && a<request->dir_tab.size()-2 )
|
2010-06-05 21:44:49 +02:00
|
|
|
i.out << '/';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-05 22:29:06 +02:00
|
|
|
//!! moze wystarczy sprawdzac tylko ostatni katalog?
|
|
|
|
// bo inaczej i tak bylo by 'access denied'
|
2009-01-14 21:11:12 +01:00
|
|
|
void dir_can_read_exec(Info & i)
|
|
|
|
{
|
|
|
|
bool result = true;
|
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
for(size_t a=0 ; a<request->dir_tab.size() ; ++a)
|
2009-01-14 21:11:12 +01:00
|
|
|
{
|
2010-08-10 22:43:38 +02:00
|
|
|
if( !system->HasReadExecAccess(*request->dir_tab[a]) )
|
2009-01-14 21:11:12 +01:00
|
|
|
{
|
|
|
|
result = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-30 23:07:46 +02:00
|
|
|
i.res = result;
|
2009-01-14 21:11:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-05 22:29:06 +02:00
|
|
|
void dir_can_write(Info & i)
|
|
|
|
{
|
2010-08-10 22:43:38 +02:00
|
|
|
i.res = system->HasWriteAccess(*request->dir_tab.back());
|
2009-06-05 22:29:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void dir_can_remove(Info & i)
|
|
|
|
{
|
|
|
|
bool result = true;
|
|
|
|
|
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
if( request->dir_tab.size() == 1 )
|
2009-06-05 22:29:06 +02:00
|
|
|
{
|
|
|
|
// rm for the root dir
|
|
|
|
// only the superuser can do it
|
2010-08-10 18:12:50 +02:00
|
|
|
if( !request->session->puser || !request->session->puser->super_user )
|
2009-06-05 22:29:06 +02:00
|
|
|
result = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-08-10 22:43:38 +02:00
|
|
|
Item * last_but_one_dir = *(--(--request->dir_tab.end()));
|
2009-06-05 22:29:06 +02:00
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
if( !system->HasWriteAccess(*last_but_one_dir) )
|
2009-06-05 22:29:06 +02:00
|
|
|
result = false;
|
|
|
|
}
|
|
|
|
|
2010-05-30 23:07:46 +02:00
|
|
|
i.res = result;
|
2009-06-05 22:29:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void dir_can_use_emacs(Info & i)
|
|
|
|
{
|
2010-08-10 18:12:50 +02:00
|
|
|
i.res = functions->fun_emacs.HasAccess();
|
2009-06-05 22:29:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void dir_can_use_mkdir(Info & i)
|
|
|
|
{
|
2010-08-10 18:12:50 +02:00
|
|
|
i.res = functions->fun_mkdir.HasAccess();
|
2009-06-05 22:29:06 +02:00
|
|
|
}
|
2009-01-14 21:11:12 +01:00
|
|
|
|
2008-12-30 02:05:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
static std::vector<Item*> dir_childs_table;
|
|
|
|
static size_t dir_childs_index;
|
2010-08-10 18:12:50 +02:00
|
|
|
// request->id is never 0 and we can start dir_childs_reqid from 0
|
2008-12-30 02:05:03 +01:00
|
|
|
static size_t dir_childs_reqid = 0;
|
|
|
|
|
2010-06-05 21:44:49 +02:00
|
|
|
// is the first directory the parent ('..')
|
|
|
|
static bool dir_childs_has_parent;
|
2008-12-30 02:05:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
void dir_childs_tab(Info & i)
|
|
|
|
{
|
2010-08-10 18:12:50 +02:00
|
|
|
if( dir_childs_reqid != request->id )
|
2008-12-30 02:05:03 +01:00
|
|
|
{
|
2010-08-10 18:12:50 +02:00
|
|
|
dir_childs_reqid = request->id;
|
2008-12-30 02:05:03 +01:00
|
|
|
dir_childs_table.clear();
|
2010-06-05 21:44:49 +02:00
|
|
|
dir_childs_has_parent = false;
|
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
if( !request->dir_tab.empty() )
|
2010-06-05 21:44:49 +02:00
|
|
|
{
|
2010-08-10 22:43:38 +02:00
|
|
|
if( request->dir_tab.size() >= 2 && i.par == "with_parent")
|
2010-06-05 21:44:49 +02:00
|
|
|
{
|
2010-08-10 22:43:38 +02:00
|
|
|
Item * dir_up = request->dir_tab[request->dir_tab.size()-2];
|
2010-06-05 21:44:49 +02:00
|
|
|
dir_childs_table.push_back(dir_up);
|
|
|
|
dir_childs_has_parent = true;
|
|
|
|
}
|
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
system->dirs.GetDirChilds(request->dir_tab.back()->id, dir_childs_table);
|
2010-06-05 21:44:49 +02:00
|
|
|
}
|
2008-12-30 02:05:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
dir_childs_index = i.iter;
|
2010-05-30 23:07:46 +02:00
|
|
|
i.res = dir_childs_index < dir_childs_table.size();
|
2008-12-30 02:05:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-05 21:44:49 +02:00
|
|
|
// is this child a parent ('..')
|
|
|
|
void dir_childs_is_parent(Info & i)
|
|
|
|
{
|
|
|
|
i.res = (dir_childs_has_parent && dir_childs_index == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-30 02:05:03 +01:00
|
|
|
void dir_childs_tab_url(Info & i)
|
|
|
|
{
|
|
|
|
if( dir_childs_index < dir_childs_table.size() )
|
|
|
|
HtmlEscape(i.out, dir_childs_table[dir_childs_index]->url);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-02-22 23:52:09 +01:00
|
|
|
void dir_childs_tab_privileges(Info & i)
|
|
|
|
{
|
|
|
|
if( dir_childs_index < dir_childs_table.size() )
|
2010-08-10 22:43:38 +02:00
|
|
|
i.out << "0" << std::setbase(8)
|
|
|
|
<< dir_childs_table[dir_childs_index]->privileges
|
|
|
|
<< std::setbase(10);
|
2010-02-22 23:52:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void dir_childs_tab_user(Info & i)
|
|
|
|
{
|
|
|
|
if( dir_childs_index < dir_childs_table.size() )
|
|
|
|
{
|
|
|
|
long user_id = dir_childs_table[dir_childs_index]->user_id;
|
2010-08-10 18:12:50 +02:00
|
|
|
User * puser = system->users.GetUser(user_id);
|
2010-02-22 23:52:09 +01:00
|
|
|
|
|
|
|
if( puser )
|
|
|
|
HtmlEscape(i.out, puser->name);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
i.out << "~";
|
|
|
|
|
|
|
|
if( !dir_childs_table[dir_childs_index]->guest_name.empty() )
|
|
|
|
HtmlEscape(i.out, dir_childs_table[dir_childs_index]->guest_name);
|
|
|
|
else
|
|
|
|
i.out << "guest"; // !! dodac do konfiga
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void dir_childs_tab_group(Info & i)
|
|
|
|
{
|
|
|
|
if( dir_childs_index < dir_childs_table.size() )
|
|
|
|
{
|
|
|
|
long group_id = dir_childs_table[dir_childs_index]->group_id;
|
2010-08-10 18:12:50 +02:00
|
|
|
Group * pgroup = system->groups.GetGroup(group_id);
|
2010-02-22 23:52:09 +01:00
|
|
|
|
|
|
|
if( pgroup )
|
|
|
|
HtmlEscape(i.out, pgroup->name);
|
|
|
|
else
|
|
|
|
i.out << group_id;
|
|
|
|
}
|
|
|
|
}
|
2008-12-30 02:05:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static size_t dir_index;
|
|
|
|
|
|
|
|
|
|
|
|
void dir_tab(Info & i)
|
|
|
|
{
|
|
|
|
dir_index = i.iter;
|
2010-08-10 22:43:38 +02:00
|
|
|
i.res = dir_index < request->dir_tab.size();
|
2008-12-30 02:05:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void dir_tab_url(Info & i)
|
|
|
|
{
|
2010-08-10 22:43:38 +02:00
|
|
|
if( dir_index < request->dir_tab.size() )
|
|
|
|
HtmlEscape(i.out, request->dir_tab[dir_index]->url);
|
2008-12-30 02:05:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void dir_tab_link(Info & i)
|
|
|
|
{
|
2010-08-10 18:12:50 +02:00
|
|
|
i.out << config->base_url;
|
2008-12-30 02:05:03 +01:00
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
for(size_t a = 0 ; a <= dir_index && a < request->dir_tab.size() ; ++a)
|
2008-12-30 02:05:03 +01:00
|
|
|
{
|
2010-08-10 22:43:38 +02:00
|
|
|
HtmlEscape(i.out, request->dir_tab[a]->url);
|
2008-12-30 02:05:03 +01:00
|
|
|
i.out << '/';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-31 19:28:12 +01:00
|
|
|
static Item dir_last_default_item;
|
|
|
|
static size_t dir_last_default_item_reqid = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void dir_last_default_item_init()
|
|
|
|
{
|
2010-08-10 18:12:50 +02:00
|
|
|
if( dir_last_default_item_reqid == request->id )
|
2008-12-31 19:28:12 +01:00
|
|
|
return;
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
dir_last_default_item_reqid = request->id;
|
2008-12-31 19:28:12 +01:00
|
|
|
|
|
|
|
dir_last_default_item.Clear();
|
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
if( request->dir_tab.empty() )
|
2008-12-31 19:28:12 +01:00
|
|
|
return;
|
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
long default_item = request->dir_tab.back()->default_item;
|
2008-12-31 19:28:12 +01:00
|
|
|
|
|
|
|
if( default_item == -1 )
|
|
|
|
return;
|
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
std::vector<Item> item_tab; // !! tymczasowo, nie bedzie tego po zmianie interfejsu dla Db
|
|
|
|
db->GetItem(item_tab, default_item);
|
2008-12-31 19:28:12 +01:00
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
if( item_tab.empty() )
|
2008-12-31 19:28:12 +01:00
|
|
|
return;
|
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
dir_last_default_item = item_tab[0];
|
2008-12-31 19:28:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void dir_last_default_item_dir(Info & i)
|
|
|
|
{
|
|
|
|
dir_last_default_item_init();
|
|
|
|
|
|
|
|
std::string path;
|
|
|
|
|
|
|
|
if( dir_last_default_item.parent_id != -1 )
|
2010-08-10 18:12:50 +02:00
|
|
|
if( system->dirs.MakePath(dir_last_default_item.parent_id, path) )
|
2008-12-31 19:28:12 +01:00
|
|
|
HtmlEscape(i.out, path);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void dir_last_default_item_url(Info & i)
|
|
|
|
{
|
|
|
|
dir_last_default_item_init();
|
|
|
|
|
|
|
|
HtmlEscape(i.out, dir_last_default_item.url);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-05 22:29:06 +02:00
|
|
|
void dir_last_subject(Info & i)
|
|
|
|
{
|
2010-08-10 22:43:38 +02:00
|
|
|
HtmlEscape(i.out, request->dir_tab.back()->subject);
|
2009-06-05 22:29:06 +02:00
|
|
|
}
|
|
|
|
|
2009-06-07 04:40:27 +02:00
|
|
|
|
|
|
|
void dir_last_user(Info & i)
|
|
|
|
{
|
2010-08-10 22:43:38 +02:00
|
|
|
User * puser = system->users.GetUser(request->dir_tab.back()->user_id);
|
2009-06-07 04:40:27 +02:00
|
|
|
|
|
|
|
if( puser )
|
|
|
|
HtmlEscape(i.out, puser->name);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
i.out << "~";
|
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
if( !request->dir_tab.back()->guest_name.empty() )
|
|
|
|
HtmlEscape(i.out, request->dir_tab.back()->guest_name);
|
2009-06-07 04:40:27 +02:00
|
|
|
else
|
|
|
|
i.out << "guest"; // !! dodac do konfiga
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-08 21:02:16 +01:00
|
|
|
void dir_last_url(Info & i)
|
|
|
|
{
|
2010-08-10 22:43:38 +02:00
|
|
|
HtmlEscape(i.out, request->dir_tab.back()->url);
|
2010-08-02 20:36:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void dir_last_url_is(Info & i)
|
|
|
|
{
|
2010-08-10 22:43:38 +02:00
|
|
|
i.res = request->dir_tab.back()->url == i.par;
|
2010-02-08 21:02:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-07 04:40:27 +02:00
|
|
|
void dir_last_date_creation(Info & i)
|
|
|
|
{
|
2010-08-10 22:43:38 +02:00
|
|
|
tm * ptm = &request->dir_tab.back()->date_creation;
|
2009-06-07 04:40:27 +02:00
|
|
|
|
|
|
|
i.out << DateToStr(ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void dir_last_date_modification(Info & i)
|
|
|
|
{
|
2010-08-10 22:43:38 +02:00
|
|
|
tm * ptm = &request->dir_tab.back()->date_modification;
|
2009-06-07 04:40:27 +02:00
|
|
|
|
|
|
|
i.out << DateToStr(ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void dir_last_dates_equal(Info & i)
|
|
|
|
{
|
2010-08-10 22:43:38 +02:00
|
|
|
tm * ptm1 = &request->dir_tab.back()->date_creation;
|
|
|
|
tm * ptm2 = &request->dir_tab.back()->date_modification;
|
2009-06-07 04:40:27 +02:00
|
|
|
|
2010-05-30 23:07:46 +02:00
|
|
|
i.res = ptm1->tm_year == ptm2->tm_year &&
|
|
|
|
ptm1->tm_mon == ptm2->tm_mon &&
|
|
|
|
ptm1->tm_mday == ptm2->tm_mday &&
|
|
|
|
ptm1->tm_hour == ptm2->tm_hour &&
|
|
|
|
ptm1->tm_min == ptm2->tm_min &&
|
|
|
|
ptm1->tm_sec == ptm2->tm_sec;
|
2009-06-07 04:40:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-13 22:04:57 +02:00
|
|
|
void dir_last_html_template(Info & i)
|
|
|
|
{
|
|
|
|
HtmlEscape(i.out, request->dir_tab.back()->html_template);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void dir_last_has_html_template(Info & i)
|
|
|
|
{
|
|
|
|
i.res = !request->dir_tab.back()->html_template.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-30 02:05:03 +01:00
|
|
|
|
2009-01-14 21:11:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2009-06-05 22:29:06 +02:00
|
|
|
|
|
|
|
|
2008-12-30 02:05:03 +01:00
|
|
|
} // namespace TemplatesFunctions
|
|
|
|
|
|
|
|
|
|
|
|
|