2010-08-10 18:12:50 +02:00
|
|
|
/*
|
|
|
|
* This file is a part of Winix
|
2014-10-04 20:04:03 +02:00
|
|
|
* and is distributed under the 2-Clause BSD licence.
|
|
|
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2014-02-12 17:30:49 +01:00
|
|
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
2010-08-10 18:12:50 +02:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2014-10-04 20:04:03 +02:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
2010-08-10 18:12:50 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "createticket.h"
|
2010-09-29 23:24:34 +02:00
|
|
|
#include "functions/functions.h"
|
2011-01-05 22:24:11 +01:00
|
|
|
#include "sessiondata.h"
|
2012-09-16 01:34:25 +02:00
|
|
|
#include "pluginmsg.h"
|
2011-01-05 22:24:11 +01:00
|
|
|
|
2014-02-12 17:30:49 +01:00
|
|
|
namespace Winix
|
|
|
|
{
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
|
|
|
|
|
2010-09-29 23:24:34 +02:00
|
|
|
namespace Ticket
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
|
|
|
|
2010-09-29 23:24:34 +02:00
|
|
|
|
2010-12-06 01:25:46 +01:00
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
CreateTicket::CreateTicket()
|
|
|
|
{
|
2010-11-21 01:19:17 +01:00
|
|
|
fun.url = L"createticket";
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-29 23:24:34 +02:00
|
|
|
void CreateTicket::SetTDb(TDb * ptdb)
|
|
|
|
{
|
|
|
|
tdb = ptdb;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CreateTicket::SetTicketInfo(TicketInfo * pinfo)
|
|
|
|
{
|
|
|
|
ticket_info = pinfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-01-05 22:24:11 +01:00
|
|
|
bool CreateTicket::HasAccess()
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->request->is_item || !system->HasWriteAccess(*cur->request->dir_tab.back()) )
|
2010-08-10 18:12:50 +02:00
|
|
|
return false;
|
|
|
|
|
2012-01-16 11:12:38 +01:00
|
|
|
if( cur->mount->type != ticket_info->mount_type_ticket )
|
2010-08-10 18:12:50 +02:00
|
|
|
return false;
|
|
|
|
|
2011-01-05 22:24:11 +01:00
|
|
|
return true;
|
|
|
|
}
|
2010-08-10 18:12:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2011-01-05 22:24:11 +01:00
|
|
|
void CreateTicket::AddTicket(Ticket & ticket, Item & item)
|
|
|
|
{
|
2011-01-24 00:23:24 +01:00
|
|
|
ticket.file_id = item.id;
|
2011-01-23 15:15:30 +01:00
|
|
|
cur->request->status = tdb->AddTicket(ticket);
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->request->status == WINIX_ERR_OK )
|
2011-01-05 22:24:11 +01:00
|
|
|
{
|
|
|
|
// sending notification
|
2011-01-26 13:45:38 +01:00
|
|
|
notify_msg.code = WINIX_NOTIFY_CODE_ADD;
|
2011-01-05 22:24:11 +01:00
|
|
|
notify_msg.template_index = ticket_info->template_index;
|
2011-08-18 01:09:47 +02:00
|
|
|
notify_msg.dir_link = config->url_proto;
|
2012-04-22 20:23:44 +02:00
|
|
|
notify_msg.dir_link += config->base_url;// !! IMPROVE ME what about subdomains?
|
2011-01-05 22:24:11 +01:00
|
|
|
system->dirs.MakePath(item.parent_id, notify_msg.dir_link, false);
|
|
|
|
notify_msg.item_link = notify_msg.dir_link;
|
|
|
|
notify_msg.item_link += item.url;
|
|
|
|
|
|
|
|
system->notify.ItemChanged(notify_msg);
|
2013-10-10 13:59:21 +02:00
|
|
|
|
|
|
|
// sending a message
|
2018-11-21 18:51:15 +01:00
|
|
|
plugin->Call(WINIX_PL_TICKET_ADDED_NEW, &ticket, &item);
|
2011-01-05 22:24:11 +01:00
|
|
|
}
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-29 23:24:34 +02:00
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2011-01-05 22:24:11 +01:00
|
|
|
void CreateTicket::Submit(Ticket & ticket, Item & item)
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
2011-01-05 22:24:11 +01:00
|
|
|
if( functions->CheckAbuse() )
|
|
|
|
return;
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2011-01-05 22:24:11 +01:00
|
|
|
functions->SetUser(item);
|
2012-01-25 00:03:36 +01:00
|
|
|
item.privileges = system->NewFilePrivileges();
|
2011-01-23 15:15:30 +01:00
|
|
|
item.parent_id = cur->request->dir_tab.back()->id;
|
2012-09-16 01:34:25 +02:00
|
|
|
|
2018-11-21 18:51:15 +01:00
|
|
|
plugin->Call(WINIX_PL_TICKET_PREPARE_TO_ADD_TICKET, &item, &ticket);
|
2012-09-16 01:34:25 +02:00
|
|
|
|
2011-01-05 22:24:11 +01:00
|
|
|
// adding without notificating
|
2011-01-23 15:15:30 +01:00
|
|
|
cur->request->status = system->AddFile(item, false);
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->request->status == WINIX_ERR_OK )
|
2011-01-05 22:24:11 +01:00
|
|
|
AddTicket(ticket, item);
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->request->status == WINIX_ERR_OK )
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
2010-09-29 23:24:34 +02:00
|
|
|
log << log2 << "CreateTicket: added a new ticket" << logend;
|
2011-01-24 00:23:24 +01:00
|
|
|
RemoveTmpTicket();
|
2012-09-14 01:12:48 +02:00
|
|
|
ticket_info->MakeRedirectIfPossible(item);
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-29 23:24:34 +02:00
|
|
|
log << log1 << "CreateTicket: problem with adding a new ticket, error code: "
|
2011-01-23 15:15:30 +01:00
|
|
|
<< cur->request->status << logend;
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-01-24 00:23:24 +01:00
|
|
|
void CreateTicket::RemoveTmpTicket()
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
2011-01-05 22:24:11 +01:00
|
|
|
SessionData * session_data = reinterpret_cast<SessionData*>(
|
2011-01-23 15:15:30 +01:00
|
|
|
cur->session->plugin_data.Get(ticket_info->plugin_id) );
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
long dir_id = cur->request->dir_tab.back()->id;
|
2011-01-05 22:24:11 +01:00
|
|
|
session_data->create_ticket_map.erase(dir_id);
|
2012-01-17 23:54:41 +01:00
|
|
|
session_data->create_space_map.erase(dir_id);
|
2011-01-05 22:24:11 +01:00
|
|
|
}
|
2010-08-10 18:12:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2011-01-05 22:24:11 +01:00
|
|
|
Ticket & CreateTicket::PrepareTicket()
|
|
|
|
{
|
|
|
|
SessionData * session_data = reinterpret_cast<SessionData*>(
|
2011-01-23 15:15:30 +01:00
|
|
|
cur->session->plugin_data.Get(ticket_info->plugin_id) );
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2012-01-17 23:54:41 +01:00
|
|
|
bool is_new;
|
2011-01-23 15:15:30 +01:00
|
|
|
long dir_id = cur->request->dir_tab.back()->id;
|
2012-01-17 23:54:41 +01:00
|
|
|
Ticket & ticket = session_data->GetTicket(dir_id, session_data->create_ticket_map, &is_new);
|
|
|
|
ticket_info->create_new_ticket = is_new;
|
2011-01-05 22:24:11 +01:00
|
|
|
|
|
|
|
return ticket;
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-17 23:54:41 +01:00
|
|
|
PT::Space & CreateTicket::PrepareSpace()
|
2011-01-24 00:23:24 +01:00
|
|
|
{
|
|
|
|
SessionData * session_data = reinterpret_cast<SessionData*>(
|
|
|
|
cur->session->plugin_data.Get(ticket_info->plugin_id) );
|
|
|
|
|
|
|
|
long dir_id = cur->request->dir_tab.back()->id;
|
2012-01-21 13:29:44 +01:00
|
|
|
PT::Space & new_space = session_data->GetNewSpace(dir_id, session_data->create_space_map);
|
2011-01-24 00:23:24 +01:00
|
|
|
|
2012-01-21 13:29:44 +01:00
|
|
|
return new_space;
|
2011-01-24 00:23:24 +01:00
|
|
|
}
|
|
|
|
|
2011-01-05 22:24:11 +01:00
|
|
|
|
|
|
|
void CreateTicket::MakePost()
|
|
|
|
{
|
|
|
|
ticket_info->Clear();
|
|
|
|
ticket_info->FindCurrentConf();
|
|
|
|
|
2012-01-17 23:54:41 +01:00
|
|
|
Ticket & ticket = PrepareTicket();
|
|
|
|
PT::Space & meta = PrepareSpace();
|
|
|
|
Item & item = cur->request->item;
|
2011-01-05 22:24:11 +01:00
|
|
|
ticket_info->ticket = &ticket;
|
2012-01-16 11:12:38 +01:00
|
|
|
ticket_info->item = &item;
|
2011-01-05 22:24:11 +01:00
|
|
|
|
2013-05-06 09:23:44 +02:00
|
|
|
bool file_was_deleted;
|
|
|
|
|
|
|
|
ticket_info->ReadTicketParams(ticket, false, meta, file_was_deleted);
|
2011-01-05 22:24:11 +01:00
|
|
|
functions->ReadItem(item, Item::file);
|
|
|
|
|
2012-01-17 23:54:41 +01:00
|
|
|
ticket_info->CopyTicketSpace(meta, item);
|
|
|
|
|
2013-05-06 09:23:44 +02:00
|
|
|
if( !cur->request->IsPostVar(L"fileuploadsubmit") && !file_was_deleted )
|
2012-09-14 01:12:48 +02:00
|
|
|
{
|
2011-01-05 22:24:11 +01:00
|
|
|
Submit(ticket, item);
|
2012-09-15 01:48:39 +02:00
|
|
|
ticket_info->ticket = ticket_info->GetEmptyTicket(); // ticket was deleted by Submit() method -- RemoveTmpTicket() was used
|
2012-09-14 01:12:48 +02:00
|
|
|
}
|
2011-01-05 22:24:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-10-19 02:31:20 +02:00
|
|
|
void CreateTicket::MakeGet()
|
|
|
|
{
|
2011-01-05 22:24:11 +01:00
|
|
|
ticket_info->Clear();
|
2010-10-19 02:31:20 +02:00
|
|
|
ticket_info->FindCurrentConf();
|
2011-01-05 22:24:11 +01:00
|
|
|
|
2012-01-17 23:54:41 +01:00
|
|
|
Ticket & ticket = PrepareTicket();
|
|
|
|
PT::Space & meta = PrepareSpace();
|
2011-01-05 22:24:11 +01:00
|
|
|
ticket_info->ticket = &ticket;
|
2012-01-16 11:12:38 +01:00
|
|
|
ticket_info->item = &cur->request->item;
|
2012-01-17 23:54:41 +01:00
|
|
|
|
2012-01-21 13:29:44 +01:00
|
|
|
// copy meta info to display correctly new files
|
|
|
|
ticket_info->CopyTicketSpace(meta, cur->request->item);
|
2010-10-19 02:31:20 +02:00
|
|
|
}
|
2010-08-10 18:12:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace
|
2014-02-12 17:30:49 +01:00
|
|
|
|
|
|
|
} // namespace Winix
|
|
|
|
|