111 lines
1.8 KiB
C++
Executable File
111 lines
1.8 KiB
C++
Executable File
/*
|
|
* This file is a part of Winix
|
|
* and is not publicly distributed
|
|
*
|
|
* Copyright (c) 2008-2010, Tomasz Sowa
|
|
* All rights reserved.
|
|
*
|
|
*/
|
|
|
|
#include "content.h"
|
|
#include "../core/request.h"
|
|
#include "../core/error.h"
|
|
#include "../core/db.h"
|
|
#include "../core/data.h"
|
|
|
|
|
|
|
|
|
|
|
|
long Content::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 = data.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 = data.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 Content::PostFunDefault()
|
|
{
|
|
if( !request.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 )
|
|
RedirectTo(*request.dir_table.back());
|
|
else
|
|
log << log1 << "Content: PostFunDefaultItem: Error: " << request.status << logend;
|
|
}
|
|
|
|
|
|
|
|
|
|
void Content::FunDefault()
|
|
{
|
|
if( !request.HasWriteAccess(*request.dir_table.back()) )
|
|
{
|
|
request.status = WINIX_ERR_PERMISSION_DENIED;
|
|
return;
|
|
}
|
|
|
|
}
|
|
|
|
|