diff --git a/functions/rm.cpp b/functions/rm.cpp index efab476..140d2bb 100755 --- a/functions/rm.cpp +++ b/functions/rm.cpp @@ -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) diff --git a/functions/rm.h b/functions/rm.h index f6abbf6..bf6cd92 100755 --- a/functions/rm.h +++ b/functions/rm.h @@ -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 diff --git a/html/fun_createticket.html b/html/fun_createticket.html index 6032ff2..6f97cfd 100755 --- a/html/fun_createticket.html +++ b/html/fun_createticket.html @@ -48,7 +48,10 @@ [if ticket_tab_type_is "images"] [for ticket_tab_file_tab] - [ticket_tab_file_tab_path] +
+ [ticket_tab_file_tab_path] + +
[end] @@ -60,7 +63,11 @@ [if ticket_tab_file_tab] [end] diff --git a/locale/en b/locale/en index b7abcdd..310f375 100755 --- a/locale/en +++ b/locale/en @@ -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 diff --git a/locale/pl b/locale/pl index 68f587c..4e3eca1 100755 --- a/locale/pl +++ b/locale/pl @@ -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 diff --git a/plugins/ticket/createticket.cpp b/plugins/ticket/createticket.cpp index 7f07856..892e891 100755 --- a/plugins/ticket/createticket.cpp +++ b/plugins/ticket/createticket.cpp @@ -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 diff --git a/plugins/ticket/editticket.cpp b/plugins/ticket/editticket.cpp index 458a890..aba6bfc 100755 --- a/plugins/ticket/editticket.cpp +++ b/plugins/ticket/editticket.cpp @@ -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 diff --git a/plugins/ticket/sessiondata.cpp b/plugins/ticket/sessiondata.cpp index d73f595..5a2df72 100755 --- a/plugins/ticket/sessiondata.cpp +++ b/plugins/ticket/sessiondata.cpp @@ -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; } } diff --git a/plugins/ticket/templates.cpp b/plugins/ticket/templates.cpp index b52c205..b51bb55 100755 --- a/plugins/ticket/templates.cpp +++ b/plugins/ticket/templates.cpp @@ -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]; diff --git a/plugins/ticket/ticketinfo.cpp b/plugins/ticket/ticketinfo.cpp index 6558a53..cc7368e 100755 --- a/plugins/ticket/ticketinfo.cpp +++ b/plugins/ticket/ticketinfo.cpp @@ -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 ; ifun_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) diff --git a/plugins/ticket/ticketinfo.h b/plugins/ticket/ticketinfo.h index c780621..1d36fe6 100755 --- a/plugins/ticket/ticketinfo.h +++ b/plugins/ticket/ticketinfo.h @@ -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); + };