the first part of reimplementing has been done
now we have app object and singletons are only: log logn plugin and app git-svn-id: svn://ttmath.org/publicrep/winix/trunk@628 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
114
functions/default.cpp
Executable file
114
functions/default.cpp
Executable file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "default.h"
|
||||
|
||||
|
||||
|
||||
namespace Fun
|
||||
{
|
||||
|
||||
Default::Default()
|
||||
{
|
||||
fun.url = "default";
|
||||
}
|
||||
|
||||
|
||||
long Default::PostFunDefaultParsePath()
|
||||
{
|
||||
Item * pdir, * pdir2;
|
||||
long defaultid = -1;
|
||||
|
||||
std::string * path = request->PostVar("defaultitem");
|
||||
|
||||
|
||||
if( path && !path->empty() )
|
||||
{
|
||||
std::string dir, file;
|
||||
Dirs::SplitPath(*path, dir, file);
|
||||
|
||||
pdir = system->dirs.GetDir(dir);
|
||||
|
||||
if( !pdir )
|
||||
throw Error(WINIX_ERR_INCORRECT_DIR);
|
||||
|
||||
if( file.empty() )
|
||||
{
|
||||
defaultid = pdir->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
// checking whether the file is a directory too (the method SplitPath does not check it)
|
||||
pdir2 = system->dirs.GetDir(file, pdir->id);
|
||||
|
||||
if( !pdir2 )
|
||||
{
|
||||
defaultid = db->GetFileId(pdir->id, file);
|
||||
|
||||
if( defaultid == -1 )
|
||||
throw Error(WINIX_ERR_NO_ITEM);
|
||||
}
|
||||
else
|
||||
{
|
||||
// file is a directory
|
||||
defaultid = pdir2->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return defaultid;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Default::MakePost()
|
||||
{
|
||||
if( !system->HasWriteAccess(*request->dir_table.back()) )
|
||||
{
|
||||
request->status = WINIX_ERR_PERMISSION_DENIED;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
long defaultid = PostFunDefaultParsePath();
|
||||
request->status = db->EditDefaultItem(request->dir_table.back()->id, defaultid);
|
||||
|
||||
if( request->status == WINIX_ERR_OK )
|
||||
request->dir_table.back()->default_item = defaultid;
|
||||
}
|
||||
catch(const Error & e)
|
||||
{
|
||||
request->status = e;
|
||||
}
|
||||
|
||||
|
||||
if( request->status == WINIX_ERR_OK )
|
||||
system->RedirectTo(*request->dir_table.back());
|
||||
else
|
||||
log << log1 << "Content: PostFunDefaultItem: Error: " << request->status << logend;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Default::MakeGet()
|
||||
{
|
||||
if( !system->HasWriteAccess(*request->dir_table.back()) )
|
||||
{
|
||||
request->status = WINIX_ERR_PERMISSION_DENIED;
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
} // namespace
|
Reference in New Issue
Block a user