added: to Rm function:

bool Rm::RemoveFileOrSymlink(long item_id, bool check_access)
added: in ticket plugin: possibility to remove a file/image
       (not finished yet)




git-svn-id: svn://ttmath.org/publicrep/winix/trunk@924 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2013-05-06 07:23:44 +00:00
parent 0e9eb30b5d
commit 1c401eae3b
11 changed files with 125 additions and 21 deletions

View File

@ -2,7 +2,7 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2012, Tomasz Sowa
* Copyright (c) 2008-2013, Tomasz Sowa
* All rights reserved.
*
*/
@ -214,6 +214,38 @@ return RemoveFile(item);
}
bool Rm::RemoveFileOrSymlink(long item_id, bool check_access)
{
bool result = false;
// selecting files, symlinks and directories
rm_by_id_iq.SetAll(false, false);
rm_by_id_iq.sel_parent_id = true;
rm_by_id_iq.sel_type = true;
rm_by_id_iq.sel_url = true;
rm_by_id_iq.sel_file = true;
rm_by_id_iq.sel_user_id = true;
rm_by_id_iq.sel_group_id = true;
rm_by_id_iq.sel_privileges = true;
rm_by_id_iq.sel_meta = true;
rm_by_id_iq.WhereId(item_id);
if( db->GetItem(rm_by_id_item, rm_by_id_iq) == WINIX_ERR_OK )
{
if( rm_by_id_item.type == Item::file || rm_by_id_item.type == Item::symlink )
{
result = RemoveFileOrSymlink(rm_by_id_item, check_access);
}
else
{
log << log2 << "Rm: I cannot remove file or symlink, item_id: " << item_id
<< " is a directory" << logend;
}
}
return result;
}
// for other uses (plugins etc)
bool Rm::RemoveItemById(long item_id, bool check_access)

View File

@ -2,7 +2,7 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010-2012, Tomasz Sowa
* Copyright (c) 2010-2013, Tomasz Sowa
* All rights reserved.
*
*/
@ -31,6 +31,7 @@ public:
void RemoveDirTree(Item & dir, bool remove_this_dir, bool check_access = true);
// removing either a file or a symlink
bool RemoveFileOrSymlink(long item_id, bool check_access = true);
bool RemoveFileOrSymlink(Item & item, bool check_access = true);
// removing either a directory or a symlink or a file

View File

@ -48,7 +48,10 @@
[if ticket_tab_type_is "images"]
[for ticket_tab_file_tab]
<img src="[doc_base_url][ticket_tab_file_tab_path]/-/thumb" alt="[ticket_tab_file_tab_path]" height="150">
<div class="winix_create_ticket_file_row">
<img src="[doc_base_url][ticket_tab_file_tab_path]/-/thumb" alt="[ticket_tab_file_tab_path]" height="150">
<input type="submit" name="ticketdeletefile_[ticket_tab_file_tab_itemid]" value="{ticket_delete_file}">
</div>
[end]
<input size="30" type="file" name="ticketparam[ticket_tab_param_id]" multiple>
@ -60,7 +63,11 @@
[if ticket_tab_file_tab]
<ul>
[for ticket_tab_file_tab]
<li><a href="[doc_base_url][ticket_tab_file_tab_path]/download">[ticket_tab_file_tab_path]</a></li>
<li>
<a href="[doc_base_url][ticket_tab_file_tab_path]/download">[ticket_tab_file_tab_path]</a>
[# !! CHECK ME how this look like -- css was not set]
<input type="submit" name="ticketdeletefile_[ticket_tab_file_tab_itemid]" value="{ticket_delete_file}">
</li>
[end]
</ul>
[end]

View File

@ -281,6 +281,7 @@ ticket_info_expected = Expected in
ticket_info_progress = Progress
ticket_reply_in_this_thread = Replay in this thread
ticket_value_not_set = this ticket doesn't have such a value yet
ticket_delete_file = Delete
template_header = Template

View File

@ -301,6 +301,8 @@ ticket_info_expected = Oczekiwany w
ticket_info_progress = Postęp prac
ticket_reply_in_this_thread = Odpowiedz w tym wątku
ticket_value_not_set = to zgłoszenie nie ma jeszcze ustawionej tej wartości
ticket_delete_file = Usuń
template_header = Szablon
template_info_file = Bieżący szablon dla tego pliku

View File

@ -2,7 +2,7 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2012, Tomasz Sowa
* Copyright (c) 2008-2013, Tomasz Sowa
* All rights reserved.
*
*/
@ -157,12 +157,14 @@ void CreateTicket::MakePost()
ticket_info->ticket = &ticket;
ticket_info->item = &item;
ticket_info->ReadTicketParams(ticket, false, meta);
bool file_was_deleted;
ticket_info->ReadTicketParams(ticket, false, meta, file_was_deleted);
functions->ReadItem(item, Item::file);
ticket_info->CopyTicketSpace(meta, item);
if( !cur->request->IsPostVar(L"fileuploadsubmit") )
if( !cur->request->IsPostVar(L"fileuploadsubmit") && !file_was_deleted )
{
Submit(ticket, item);
ticket_info->ticket = ticket_info->GetEmptyTicket(); // ticket was deleted by Submit() method -- RemoveTmpTicket() was used

View File

@ -2,7 +2,7 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2012, Tomasz Sowa
* Copyright (c) 2008-2013, Tomasz Sowa
* All rights reserved.
*
*/
@ -209,12 +209,13 @@ void EditTicket::MakePost()
}
else
{
ticket_info->ReadTicketParams(ticket, false, meta);
bool file_was_deleted;
ticket_info->ReadTicketParams(ticket, false, meta, file_was_deleted);
functions->ReadItem(item, Item::file);
ticket_info->CopyTicketSpace(meta, item);
if( !cur->request->IsPostVar(L"fileuploadsubmit") )
if( !cur->request->IsPostVar(L"fileuploadsubmit") && !file_was_deleted )
{
Submit(ticket, item);
ticket_info->ticket = ticket_info->GetEmptyTicket(); // ticket was deleted by Submit() method -- RemoveTmpTicket() was used

View File

@ -86,7 +86,7 @@ void SessionData::RemoveAllStaleFiles(PT::Space & new_space, PT::Space & old_spa
{
if( new_file_tab[n] < old_file_tab[o] )
{
fun_rm->RemoveItemById(new_file_tab[n], false);
fun_rm->RemoveFileOrSymlink(new_file_tab[n], false);
n += 1;
}
else
@ -103,7 +103,7 @@ void SessionData::RemoveAllStaleFiles(PT::Space & new_space, PT::Space & old_spa
while( n < new_file_tab.size() )
{
fun_rm->RemoveItemById(new_file_tab[n], false);
fun_rm->RemoveFileOrSymlink(new_file_tab[n], false);
n += 1;
}
}

View File

@ -298,13 +298,9 @@ void ticket_param_value_for_param_id(Info & i)
for( ; conf_index < space.spaces.size() ; ++conf_index)
{
log << log1 << "analizuje: " << space.spaces[conf_index]->Text(L"name") << logend;
if( space.spaces[conf_index]->name == L"param" &&
space.spaces[conf_index]->Int(L"id") == id )
{
log << log1 << "znalazlem: " << space.spaces[conf_index]->Text(L"name") << logend;
value_for_param_id.Clear();
value_for_param_id.is_param = true;
value_for_param_id.config_par = space.spaces[conf_index];

View File

@ -2,7 +2,7 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010-2012, Tomasz Sowa
* Copyright (c) 2010-2013, Tomasz Sowa
* All rights reserved.
*
*/
@ -17,6 +17,8 @@
#include "pluginmsg.h"
#include "sessiondata.h"
namespace Ticket
{
@ -473,18 +475,76 @@ void TicketInfo::ReadTicketParam(long param_id, const PostFile & value, PT::Spac
void TicketInfo::ReadTicketParams(Ticket & ticket, bool clear_ticket, PT::Space & meta)
bool TicketInfo::DeleteTicketFile(Ticket & ticket, long file_id, PT::Space & meta)
{
for(size_t i=0 ; i<meta.spaces.size() ; ++i)
{
PT::Space & param = *meta.spaces[i];
if( param.name == L"param" )
{
for(size_t z=0 ; z<param.spaces.size() ; ++z)
{
PT::Space & file = *param.spaces[z];
if( file.name == L"file" )
{
if( file.Long(L"itemid") == file_id )
{
param.RemoveSpace(z);
// !! IMPROVE ME
// temporarily we delete the file here
// but it should be really deleted when the user will press
// the submit button
//functions->fun_rm.RemoveFileOrSymlink(file_id, true);
return true;
}
}
}
}
}
return false;
}
void TicketInfo::ReadTicketParams(Ticket & ticket, bool clear_ticket, PT::Space & meta, bool & file_was_deleted)
{
PostTab::iterator i;
PostFileTab::iterator i2;
file_was_deleted = false;
if( clear_ticket )
ticket.Clear();
// !! IMPROVE ME move me somewhere
std::wstring ticket_delete_prefix = L"ticketdeletefile_";
for(i=cur->request->post_tab.begin() ; i!=cur->request->post_tab.end() ; ++i)
{
// !! CHECKME why ticket_form_prefix is in the global config?
// (this is a plugin variable)
if( IsSubString(config->ticket_form_prefix, i->first) )
ReadTicketParam(ticket, Tol(i->first.c_str() + config->ticket_form_prefix.size()), i->second, meta);
{
long param_id = Tol(i->first.c_str() + config->ticket_form_prefix.size());
ReadTicketParam(ticket, param_id, i->second, meta);
}
if( IsSubString(ticket_delete_prefix, i->first) )
{
long file_id = Tol(i->first.c_str() + ticket_delete_prefix.size());
if( DeleteTicketFile(ticket, file_id, meta) )
{
file_was_deleted = true;
}
}
}
for(i2=cur->request->post_file_tab.begin() ; i2!=cur->request->post_file_tab.end() ; ++i2)

View File

@ -2,7 +2,7 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010-2012, Tomasz Sowa
* Copyright (c) 2010-2013, Tomasz Sowa
* All rights reserved.
*
*/
@ -99,7 +99,7 @@ public:
void ReadTicketConf(bool skip_existing_configs = false);
void FindCurrentConf(long dir_id);
void FindCurrentConf();
void ReadTicketParams(Ticket & ticket, bool clear_ticket, PT::Space & meta);
void ReadTicketParams(Ticket & ticket, bool clear_ticket, PT::Space & meta, bool & file_was_deleted);
void RemoveTicket(long file_id);
void CopyTicketSpace(PT::Space & ticket_space, Item & item);
@ -156,6 +156,8 @@ private:
void ReadTicketParam(PT::Space & space, Ticket & ticket, long param_id, const std::wstring & value, PT::Space & meta);
void ReadTicketParam(Ticket & ticket, long param_id, const std::wstring & value, PT::Space & meta);
void ReadTicketParam(long param_id, const PostFile & value, PT::Space & meta);
bool DeleteTicketFile(Ticket & ticket, long file_id, PT::Space & meta);
};