- Updated task editing template to handle default status for new tasks and corrected variable names. - Enhanced work time reporting by rounding time to the nearest quarter hour and adjusting amount formatting. - Introduced TasksController to manage task-related operations, including status resolution and email notifications. - Added TaskAttachmentRepository for handling task attachments, including upload, rename, and delete functionalities. - Implemented WorkTimeRepository to fetch clients with unsettled tasks and calculate total work time. - Created unit tests for TasksController and TaskAttachmentRepository to ensure functionality and correctness.
647 lines
20 KiB
PHP
647 lines
20 KiB
PHP
<?
|
|
namespace controls;
|
|
class Tasks
|
|
{
|
|
static public function task_change_dates() {
|
|
global $mdb;
|
|
|
|
$response = [ 'status' => 'error', 'msg' => 'Podczas zmiany daty wystąpił błąd. Proszę spróbować ponownie.' ];
|
|
|
|
if ( \factory\Tasks::task_change_dates( \S::get( 'task_id' ), \S::get( 'date_start' ), \S::get( 'date_end' ) ) )
|
|
$response = [ 'status' => 'success', 'msg' => 'Data została zmieniona.' ];
|
|
|
|
echo json_encode( $response );
|
|
exit;
|
|
}
|
|
|
|
static public function task_delete() {
|
|
global $user;
|
|
|
|
if ( !$user ) {
|
|
header( 'Location: /logowanie' );
|
|
exit;
|
|
}
|
|
|
|
$response = [ 'status' => 'error', 'msg' => 'Podczas usuwania zadania wystąpił błąd. Proszę spróbować ponownie.' ];
|
|
|
|
if ( \factory\Tasks::task_delete( \S::get( 'task_id' ) ) )
|
|
$response = [ 'status' => 'success', 'msg' => 'Zadanie zostało usunięte.' ];
|
|
|
|
echo json_encode( $response );
|
|
exit;
|
|
}
|
|
|
|
static public function main_view_by_ajax()
|
|
{
|
|
global $user;
|
|
|
|
$show_tasks_closed = \S::get_session( 'tasks_closed' );
|
|
$show_tasks_bulk = \S::get_session( 'tasks_bulk' );
|
|
$show_tasks_to_review = \S::get_session( 'tasks_to_review' );
|
|
|
|
$open_task_id = \factory\Tasks::get_open_task_id( $user['id'] );
|
|
$projects = \S::get( 'projects' );
|
|
$users = \S::get( 'users' );
|
|
|
|
if ( $projects )
|
|
\S::set_session( 'selected_projects', $projects );
|
|
else
|
|
\S::set_session( 'selected_projects', null );
|
|
|
|
if ( $users )
|
|
\S::set_session( 'selected_users', $users );
|
|
else
|
|
\S::set_session( 'selected_users', null );
|
|
|
|
$show_tasks_closed = \S::get_session( 'tasks_closed' ) ? \S::get_session( 'tasks_closed' ) : 'hide';
|
|
$show_tasks_bulk = \S::get_session( 'tasks_bulk' );
|
|
$show_tasks_to_review = \S::get_session( 'tasks_to_review' );
|
|
|
|
echo json_encode( [
|
|
'tasks_new' => \Tpl::view( 'tasks/main_view_by_ajax', [
|
|
'tasks' => \factory\Tasks::get_tasks( 0, $user['id'], $projects, $users ),
|
|
'user' => $user,
|
|
'statuses' => \factory\Tasks::get_statuses(),
|
|
'open_task_id' => $open_task_id
|
|
] ),
|
|
'tasks_to_review' => \Tpl::view( 'tasks/main_view_by_ajax', [
|
|
'tasks' => $show_tasks_to_review == 'hide' ? null : \factory\Tasks::get_tasks( 1, $user['id'], $projects, $users ),
|
|
'user' => $user,
|
|
'statuses' => \factory\Tasks::get_statuses(),
|
|
'open_task_id' => $open_task_id
|
|
] ),
|
|
'tasks_closed' => \Tpl::view( 'tasks/main_view_by_ajax', [
|
|
'tasks' => $show_tasks_closed == 'hide' ? null : \factory\Tasks::get_tasks( 2, $user['id'], $projects, $users ),
|
|
'user' => $user,
|
|
'statuses' => \factory\Tasks::get_statuses(),
|
|
'open_task_id' => $open_task_id
|
|
] ),
|
|
'tasks_bulk' => \Tpl::view( 'tasks/main_view_by_ajax', [
|
|
'tasks' => $show_tasks_bulk == 'hide' ? null : \factory\Tasks::get_tasks( 3, $user['id'], $projects, $users ),
|
|
'user' => $user,
|
|
'statuses' => \factory\Tasks::get_statuses(),
|
|
'open_task_id' => $open_task_id
|
|
] ),
|
|
'tasks_to_do' => \Tpl::view( 'tasks/main_view_by_ajax', [
|
|
'tasks' => \factory\Tasks::get_tasks( 5, $user['id'], $projects, $users ),
|
|
'user' => $user,
|
|
'statuses' => \factory\Tasks::get_statuses(),
|
|
'open_task_id' => $open_task_id
|
|
] ),
|
|
'tasks_gantt' => \factory\Tasks::get_tasks_gantt( $user['id'], $projects, $users ),
|
|
] );
|
|
exit;
|
|
}
|
|
|
|
static public function main_view()
|
|
{
|
|
global $user;
|
|
|
|
if ( \S::get( 'tasks_closed' ) == 'hide' )
|
|
{
|
|
\S::set_session( 'tasks_closed', 'hide' );
|
|
header( 'Location: /tasks/main_view/' );
|
|
exit;
|
|
}
|
|
|
|
if ( \S::get( 'tasks_closed' ) == 'show' )
|
|
{
|
|
\S::set_session( 'tasks_closed', 'show' );
|
|
header( 'Location: /tasks/main_view/' );
|
|
exit;
|
|
}
|
|
|
|
if ( \S::get( 'tasks_bulk' ) == 'hide' )
|
|
{
|
|
\S::set_session( 'tasks_bulk', 'hide' );
|
|
header( 'Location: /tasks/main_view/' );
|
|
exit;
|
|
}
|
|
|
|
if ( \S::get( 'tasks_bulk' ) == 'show' )
|
|
{
|
|
\S::set_session( 'tasks_bulk', 'show' );
|
|
header( 'Location: /tasks/main_view/' );
|
|
exit;
|
|
}
|
|
|
|
// tasks_to_review
|
|
if ( \S::get( 'tasks_to_review' ) == 'hide' )
|
|
{
|
|
\S::set_session( 'tasks_to_review', 'hide' );
|
|
header( 'Location: /tasks/main_view/' );
|
|
exit;
|
|
}
|
|
|
|
if ( \S::get( 'tasks_to_review' ) == 'show' )
|
|
{
|
|
\S::set_session( 'tasks_to_review', 'show' );
|
|
header( 'Location: /tasks/main_view/' );
|
|
exit;
|
|
}
|
|
|
|
$show_tasks_closed = \S::get_session( 'tasks_closed' ) ? \S::get_session( 'tasks_closed' ) : 'hide';
|
|
$show_tasks_bulk = \S::get_session( 'tasks_bulk' );
|
|
$show_tasks_to_review = \S::get_session( 'tasks_to_review' );
|
|
|
|
// get default filtr
|
|
if ( !\S::get_session( 'fresh_load' ) ) {
|
|
$default_filtr = \factory\Tasks::get_default_filtr( $user['id'] );
|
|
if ( $default_filtr )
|
|
{
|
|
if ( !\S::get_session( 'selected_projects' ) and $default_filtr['projects'] )
|
|
\S::set_session( 'selected_projects', explode( ',', $default_filtr['projects'] ) );
|
|
|
|
if ( !\S::get_session( 'selected_users' ) and $default_filtr['users'] )
|
|
\S::set_session( 'selected_users', explode( ',', $default_filtr['users'] ) );
|
|
}
|
|
\S::set_session( 'fresh_load', true );
|
|
}
|
|
|
|
return \Tpl::view( 'tasks/main_view', [
|
|
'tasks_new' => \factory\Tasks::get_tasks( 0, $user['id'], \S::get_session( 'selected_projects' ), \S::get_session( 'selected_users' ) ),
|
|
'tasks_to_review' => $show_tasks_to_review == 'hide' ? null : \factory\Tasks::get_tasks( 1, $user['id'], \S::get_session( 'selected_projects' ), \S::get_session( 'selected_users' ) ),
|
|
'tasks_closed' => $show_tasks_closed == 'hide' ? null : \factory\Tasks::get_tasks( 2, $user['id'], \S::get_session( 'selected_projects' ), \S::get_session( 'selected_users' ) ), // zakończone
|
|
'tasks_bulk' => $show_tasks_bulk == 'hide' ? null : \factory\Tasks::get_tasks( 3, $user['id'], \S::get_session( 'selected_projects' ), \S::get_session( 'selected_users' ) ), // opłaty
|
|
'tasks_to_do' => \factory\Tasks::get_tasks( 5, $user['id'], \S::get_session( 'selected_projects' ), \S::get_session( 'selected_users' ) ), // do zrobienia
|
|
'user' => $user,
|
|
'statuses' => \factory\Tasks::get_statuses(),
|
|
'open_task_id' => \factory\Tasks::get_open_task_id( $user['id'] ),
|
|
'projects' => \factory\Projects::user_projects( $user['id'] ),
|
|
'selected_projects' => \S::get_session( 'selected_projects' ),
|
|
'selected_users' => \S::get_session( 'selected_users' ),
|
|
'tasks_filtrs' => \factory\Tasks::get_filtrs( $user['id'] ),
|
|
'show_tasks_closed' => $show_tasks_closed,
|
|
'show_tasks_bulk' => $show_tasks_bulk,
|
|
'show_tasks_to_review' => $show_tasks_to_review,
|
|
'users' => \factory\Users::users_list(),
|
|
'tasks_gantt' => \factory\Tasks::get_tasks_gantt( $user['id'], \S::get_session( 'selected_projects' ), \S::get_session( 'selected_users' ) ),
|
|
'selected_gantt_users' => \S::get_session( 'selected_gantt_users' )
|
|
] );
|
|
}
|
|
|
|
static public function action_change_status() {
|
|
global $user;
|
|
|
|
if ( !$user )
|
|
{
|
|
header( 'Location: /logowanie' );
|
|
exit;
|
|
}
|
|
|
|
$response = [ 'status' => 'error', 'msg' => 'Podczas zmiany statusu czynności wystąpił błąd. Proszę spróbować ponownie.' ];
|
|
|
|
if ( \factory\Tasks::action_change_status( \S::get( 'action_id' ), \S::get( 'status' ) ) )
|
|
$response = [ 'status' => 'ok', 'msg' => 'Status czynności został zmieniony.' ];
|
|
|
|
echo json_encode( $response );
|
|
exit;
|
|
}
|
|
|
|
static public function comment_delete() {
|
|
global $user;
|
|
|
|
if ( !$user ) {
|
|
header( 'Location: /logowanie' );
|
|
exit;
|
|
}
|
|
|
|
$response = [ 'status' => 'error', 'msg' => 'Podczas usuwania komentarza wystąpił błąd. Proszę spróbować ponownie.' ];
|
|
|
|
if ( \factory\Tasks::comment_delete( \S::get( 'comment_id' ) ) )
|
|
$response = [ 'status' => 'ok', 'msg' => 'Komentarz został usunięty.' ];
|
|
|
|
echo json_encode( $response );
|
|
exit;
|
|
}
|
|
|
|
static public function comment_save()
|
|
{
|
|
global $user;
|
|
|
|
if ( !$user )
|
|
{
|
|
header( 'Location: /logowanie' );
|
|
exit;
|
|
}
|
|
|
|
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania komentarza wystąpił błąd. Proszę spróbować ponownie.' ];
|
|
|
|
if ( $id = \factory\Tasks::comment_save( \S::get( 'task_id' ), $user['id'], \S::get( 'text' ) ) )
|
|
{
|
|
\factory\Tasks::clear_task_opened( \S::get( 'task_id' ) );
|
|
$response = [ 'status' => 'ok', 'msg' => 'Komentarz został zapisany.', 'id' => $id ];
|
|
}
|
|
|
|
echo json_encode( $response );
|
|
exit;
|
|
}
|
|
|
|
static public function action_delete()
|
|
{
|
|
global $user;
|
|
|
|
if ( !$user )
|
|
{
|
|
header( 'Location: /logowanie' );
|
|
exit;
|
|
}
|
|
|
|
$response = [ 'status' => 'error', 'msg' => 'Podczas usuwania czynności wystąpił błąd. Proszę spróbować ponownie.' ];
|
|
|
|
if ( \factory\Tasks::action_delete( \S::get( 'action_id' ) ) )
|
|
$response = [ 'status' => 'ok', 'msg' => 'Czynność została usunięta.' ];
|
|
|
|
echo json_encode( $response );
|
|
exit;
|
|
}
|
|
|
|
static public function action_save()
|
|
{
|
|
global $user;
|
|
|
|
if ( !$user )
|
|
{
|
|
header( 'Location: /logowanie' );
|
|
exit;
|
|
}
|
|
|
|
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania czynności wystąpił błąd. Proszę spróbować ponownie.' ];
|
|
|
|
if ( $id = \factory\Tasks::action_save( \S::get( 'task_id' ), \S::get( 'text' ) ) )
|
|
{
|
|
\factory\Tasks::clear_task_opened( \S::get( 'task_id' ) );
|
|
$response = [ 'status' => 'ok', 'msg' => 'Czynność została zapisana.', 'id' => $id ];
|
|
}
|
|
|
|
echo json_encode( $response );
|
|
exit;
|
|
}
|
|
|
|
// Zapisanie kolejności zadań
|
|
static public function tasks_order_save()
|
|
{
|
|
global $mdb;
|
|
|
|
foreach ( \S::get( 'tasks_order' ) as $key => $val ) {
|
|
$mdb -> update( 'tasks', [ 'o' => $key ], [ 'id' => $val ] );
|
|
}
|
|
exit;
|
|
}
|
|
|
|
static public function send_email_task_change_status( $task_id )
|
|
{
|
|
$task = \factory\Tasks::task_details( $task_id );
|
|
|
|
$statuses = \factory\Tasks::get_statuses();
|
|
|
|
if ( $task['status_change_mail'] ) {
|
|
\S::send_email(
|
|
'biuro@project-pro.pl',
|
|
'crmPRO - zmieniono status zadania',
|
|
'<p>Witaj<br/>zmieniono status zadania <b>' . $task['name'] . ' - ' . \factory\Crm::get_client_name( (int)$task['client_id'] ) . '</b> na <b>' . $statuses[ $task['status'] ] . '</b>.</p>' .
|
|
'<p>' . html_entity_decode( $task['text'] ) . '</p>' .
|
|
'<p>Pozdrawiamy<br/>Zespół crmPRO.pl</p>'
|
|
);
|
|
}
|
|
}
|
|
|
|
static public function task_change_project() {
|
|
global $mdb;
|
|
|
|
if ( $mdb -> update( 'tasks', [ 'project_id' => \S::get( 'project_id' ) ], [ 'id' => \S::get( 'task_id' ) ] ) ) {
|
|
echo json_encode( [ 'status' => 'success' ] );
|
|
} else {
|
|
echo json_encode( [ 'status' => 'error' ] );
|
|
}
|
|
exit;
|
|
}
|
|
|
|
static public function task_change_priority() {
|
|
global $mdb;
|
|
|
|
if ( $mdb -> update( 'tasks', [ 'priority' => \S::get( 'priority' ) ], [ 'id' => \S::get( 'task_id' ) ] ) ) {
|
|
echo json_encode( [ 'status' => 'success' ] );
|
|
} else {
|
|
echo json_encode( [ 'status' => 'error' ] );
|
|
}
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* @deprecated Use \Controllers\TasksController::taskChangeStatus() instead.
|
|
*/
|
|
static public function task_change_status()
|
|
{
|
|
return \Controllers\TasksController::taskChangeStatus();
|
|
}
|
|
|
|
static public function task_end()
|
|
{
|
|
global $user;
|
|
|
|
if ( !$user )
|
|
return json_encode( [ 'status' => 'error' ] );
|
|
|
|
echo json_encode( \factory\Tasks::task_end( \S::get( 'task_id' ), $user['id'] ) );
|
|
exit;
|
|
}
|
|
|
|
static public function task_start()
|
|
{
|
|
global $user;
|
|
|
|
if ( !$user )
|
|
return json_encode( [ 'status' => 'error' ] );
|
|
|
|
echo json_encode( \factory\Tasks::task_start( \S::get( 'task_id' ), $user['id'] ) );
|
|
exit;
|
|
}
|
|
|
|
static public function task_edit()
|
|
{
|
|
global $user;
|
|
|
|
if ( !$user )
|
|
{
|
|
header( 'Location: /logowanie' );
|
|
exit;
|
|
}
|
|
|
|
$task = \factory\Tasks::task_details( \S::get( 'task_id' ) );
|
|
$task['status'] = \Controllers\TasksController::resolveTaskStatusForForm( $task );
|
|
|
|
return \Tpl::view( 'tasks/task_edit', [
|
|
'projects' => \factory\Projects::user_projects( $user['id'] ),
|
|
'priorities' => \factory\Tasks::$priorities,
|
|
'task' => $task,
|
|
'parent_tasks' => \factory\Tasks::parent_tasks( $user['id'] ),
|
|
'users' => \factory\Users::users_list(),
|
|
'clients' => \factory\Crm::get_client_list(),
|
|
'user' => $user
|
|
] );
|
|
}
|
|
static public function task_save()
|
|
{
|
|
global $user;
|
|
|
|
if ( !$user )
|
|
{
|
|
header( 'Location: /logowanie' );
|
|
exit;
|
|
}
|
|
|
|
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania zadania wystąpił błąd. Proszę spróbować ponownie.' ];
|
|
$values = \S::json_to_array( \S::get( 'values' ) );
|
|
$status = \Controllers\TasksController::resolveTaskStatusForSave( $values );
|
|
|
|
if ( $id = \factory\Tasks::task_save(
|
|
$values['id'], null, $user['id'], $values['name'], $values['text'], $values['date_start'], $values['date_end'], $values['project_id'], $values['client_id'], $values['pay_rate'], $values['reminders_interval'], $values['recursively'], $values['frequency'], $values['period'], $values['users'], null, null, $values['send_email_notification'], $values['status_change_mail'], false, $status, $values['show_in_calendar'], $values['priority']
|
|
) )
|
|
{
|
|
\factory\Tasks::clear_task_opened( $id );
|
|
$response = [ 'status' => 'ok', 'msg' => 'Zadanie zostało zapisane.', 'id' => $id ];
|
|
}
|
|
|
|
echo json_encode( $response );
|
|
exit;
|
|
}
|
|
static public function task_popup()
|
|
{
|
|
global $user;
|
|
|
|
if ( !$user )
|
|
{
|
|
header( 'Location: /logowanie' );
|
|
exit;
|
|
}
|
|
|
|
$attachments_repository = new \Domain\Tasks\TaskAttachmentRepository();
|
|
|
|
\factory\Tasks::set_task_opened_by_user( \S::get( 'task_id' ), $user['id'] );
|
|
|
|
echo \Tpl::view( 'tasks/task_popup', [
|
|
'task' => \factory\Tasks::task_details( \S::get( 'task_id' ), $user['id'] ),
|
|
'task_works' => \factory\Tasks::task_works( \S::get( 'task_id' ) ),
|
|
'task_attachments' => $attachments_repository -> listByTaskId( \S::get( 'task_id' ) ),
|
|
'user' => $user,
|
|
'statuses' => \factory\Tasks::get_statuses(),
|
|
'projects' => \factory\Projects::user_projects( $user['id'] )
|
|
] );
|
|
exit;
|
|
}
|
|
|
|
static public function task_attachment_upload()
|
|
{
|
|
global $user;
|
|
|
|
if ( !$user )
|
|
{
|
|
header( 'Location: /logowanie' );
|
|
exit;
|
|
}
|
|
|
|
$files_input = isset( $_FILES['attachments'] ) ? $_FILES['attachments'] : ( isset( $_FILES['attachment'] ) ? $_FILES['attachment'] : null );
|
|
if ( !$files_input )
|
|
{
|
|
echo json_encode( [ 'status' => 'error', 'msg' => 'Nie przesłano plików.' ] );
|
|
exit;
|
|
}
|
|
|
|
$repository = new \Domain\Tasks\TaskAttachmentRepository();
|
|
$files = self::normalize_uploads_array( $files_input );
|
|
|
|
if ( !count( $files ) )
|
|
{
|
|
echo json_encode( [ 'status' => 'error', 'msg' => 'Brak poprawnych plików do wysłania.' ] );
|
|
exit;
|
|
}
|
|
|
|
$failed = [];
|
|
$success = 0;
|
|
foreach ( $files as $file )
|
|
{
|
|
$result = $repository -> upload( \S::get( 'task_id' ), $user['id'], $file );
|
|
if ( $result['status'] == 'success' )
|
|
$success++;
|
|
else
|
|
$failed[] = isset( $file['name'] ) ? $file['name'] : 'plik';
|
|
}
|
|
|
|
if ( $success and !count( $failed ) )
|
|
echo json_encode( [ 'status' => 'success', 'msg' => 'Dodano załączniki.' ] );
|
|
elseif ( $success and count( $failed ) )
|
|
echo json_encode( [ 'status' => 'partial', 'msg' => 'Część plików dodano, część się nie powiodła.' ] );
|
|
else
|
|
echo json_encode( [ 'status' => 'error', 'msg' => 'Nie udało się dodać załączników.' ] );
|
|
|
|
exit;
|
|
}
|
|
|
|
static private function normalize_uploads_array( $files_input )
|
|
{
|
|
if ( !is_array( $files_input ) or !isset( $files_input['name'] ) )
|
|
return [];
|
|
|
|
if ( !is_array( $files_input['name'] ) )
|
|
return [ $files_input ];
|
|
|
|
$normalized = [];
|
|
foreach ( $files_input['name'] as $i => $name )
|
|
{
|
|
$normalized[] = [
|
|
'name' => $name,
|
|
'type' => isset( $files_input['type'][$i] ) ? $files_input['type'][$i] : null,
|
|
'tmp_name' => isset( $files_input['tmp_name'][$i] ) ? $files_input['tmp_name'][$i] : null,
|
|
'error' => isset( $files_input['error'][$i] ) ? $files_input['error'][$i] : UPLOAD_ERR_NO_FILE,
|
|
'size' => isset( $files_input['size'][$i] ) ? $files_input['size'][$i] : 0
|
|
];
|
|
}
|
|
|
|
return $normalized;
|
|
}
|
|
|
|
static public function task_attachment_delete()
|
|
{
|
|
global $user;
|
|
|
|
if ( !$user )
|
|
{
|
|
header( 'Location: /logowanie' );
|
|
exit;
|
|
}
|
|
|
|
$repository = new \Domain\Tasks\TaskAttachmentRepository();
|
|
$result = $repository -> delete( \S::get( 'attachment_id' ), $user['id'] );
|
|
|
|
if ( $result )
|
|
echo json_encode( [ 'status' => 'success' ] );
|
|
else
|
|
echo json_encode( [ 'status' => 'error' ] );
|
|
exit;
|
|
}
|
|
|
|
static public function task_attachment_rename()
|
|
{
|
|
global $user;
|
|
|
|
if ( !$user )
|
|
{
|
|
header( 'Location: /logowanie' );
|
|
exit;
|
|
}
|
|
|
|
$repository = new \Domain\Tasks\TaskAttachmentRepository();
|
|
$result = $repository -> rename( \S::get( 'attachment_id' ), \S::get( 'title' ) );
|
|
|
|
if ( $result )
|
|
echo json_encode( [ 'status' => 'success' ] );
|
|
else
|
|
echo json_encode( [ 'status' => 'error' ] );
|
|
exit;
|
|
}
|
|
|
|
static public function filtr_save_form() {
|
|
echo json_encode( [
|
|
'status' => 'success',
|
|
'title' => 'Zapisz filtr',
|
|
'popup_content' => \Tpl::view( 'tasks/filtr_save_form', [
|
|
'projects' => \S::get( 'projects' ),
|
|
'users' => \S::get( 'users' )
|
|
] )
|
|
] );
|
|
exit;
|
|
}
|
|
|
|
static public function filtr_save() {
|
|
global $user;
|
|
|
|
if ( !$user )
|
|
{
|
|
header( 'Location: /logowanie' );
|
|
exit;
|
|
}
|
|
|
|
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania filtru wystąpił błąd. Proszę spróbować ponownie.' ];
|
|
|
|
if ( \factory\Tasks::filtr_save( $user['id'], \S::get( 'name' ), \S::get( 'projects' ), \S::get( 'users' ), \S::get( 'is_default' ) ) )
|
|
$response = [ 'status' => 'success', 'msg' => 'Filtr został zapisany.' ];
|
|
|
|
echo json_encode( $response );
|
|
exit;
|
|
}
|
|
|
|
static public function filtr_update() {
|
|
global $user;
|
|
|
|
if ( !$user ) {
|
|
header( 'Location: /logowanie' );
|
|
exit;
|
|
}
|
|
|
|
$response = [ 'status' => 'error', 'msg' => 'Podczas aktualizacji filtru wystąpił błąd. Proszę spróbować ponownie.' ];
|
|
|
|
if ( \factory\Tasks::filtr_update( \S::get( 'filtr_id' ), \S::get( 'projects' ), \S::get( 'users' ) ) )
|
|
$response = [ 'status' => 'success', 'msg' => 'Filtr został zaktualizowany.' ];
|
|
|
|
echo json_encode( $response );
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* @deprecated Use \Controllers\TasksController::workTime() instead.
|
|
*/
|
|
static public function work_time()
|
|
{
|
|
return \Controllers\TasksController::workTime();
|
|
}
|
|
|
|
static public function change_task_work_date_start() {
|
|
$result = \factory\Tasks::change_task_work_date_start( \S::get( 'task_work_id' ), \S::get( 'date_start' ) );
|
|
exit;
|
|
}
|
|
|
|
static public function change_task_work_date_end() {
|
|
$result = \factory\Tasks::change_task_work_date_end( \S::get( 'task_work_id' ), \S::get( 'date_end' ) );
|
|
exit;
|
|
}
|
|
|
|
static public function work_delete() {
|
|
|
|
if ( \factory\Tasks::work_delete( \S::get( 'work_id' ) ) )
|
|
echo json_encode( [ 'status' => 'success' ] );
|
|
else
|
|
echo json_encode( [ 'status' => 'error' ] );
|
|
exit;
|
|
}
|
|
|
|
static public function filtr_set_default() {
|
|
global $user;
|
|
|
|
if ( !$user ) {
|
|
header( 'Location: /logowanie' );
|
|
exit;
|
|
}
|
|
|
|
$response = [ 'status' => 'error', 'msg' => 'Podczas ustawiania domyślnego filtru wystąpił błąd. Proszę spróbować ponownie.' ];
|
|
|
|
if ( \factory\Tasks::filtr_set_default( $user['id'], \S::get( 'filtr_id' ) ) )
|
|
$response = [ 'status' => 'success', 'msg' => 'Filtr został ustawiony jako domyślny.' ];
|
|
|
|
echo json_encode( $response );
|
|
exit;
|
|
}
|
|
|
|
static function filtr_get() {
|
|
$filtr = \factory\Tasks::filtr_details( \S::get( 'filtr_id' ) );
|
|
|
|
echo json_encode( [
|
|
'status' => 'success',
|
|
'projects' => $filtr['projects'],
|
|
'users' => $filtr['users']
|
|
] );
|
|
exit;
|
|
}
|
|
}
|
|
|