| @@ 392-436 (lines=45) @@ | ||
| 389 | $app->redirect($app->urlFor('login')); |
|
| 390 | } |
|
| 391 | ||
| 392 | if ((isset($_POST['archive']) && isset($_POST['displayname']) && strlen($_POST['displayname'])) || |
|
| 393 | (isset($_POST['archive_old']) && isset($_POST['snapshot']))) { |
|
| 394 | ||
| 395 | // realizar los cambios en una transacción |
|
| 396 | ORM::get_db()->beginTransaction(); |
|
| 397 | ||
| 398 | if (isset($_POST['archive'])) { |
|
| 399 | // crear snapshot |
|
| 400 | $snapshot = ORM::for_table('snapshot')->create(); |
|
| 401 | $snapshot->set('organization_id', $organization['id']); |
|
| 402 | $snapshot->set('display_name', $_POST['displayname']); |
|
| 403 | $snapshot->set('order_nr', getLastSnapshotOrder($organization['id']) + 1000); |
|
| 404 | $ok = $snapshot->save(); |
|
| 405 | } |
|
| 406 | else { |
|
| 407 | // recuperar snapshot |
|
| 408 | $snapshot = ORM::for_table('snapshot')-> |
|
| 409 | where('organization_id', $organization['id'])-> |
|
| 410 | where('id', $_POST['snapshot'])-> |
|
| 411 | find_one(); |
|
| 412 | ||
| 413 | if (!$snapshot) { |
|
| 414 | $app->redirect($app->urlFor('login')); |
|
| 415 | } |
|
| 416 | ||
| 417 | $ok = true; |
|
| 418 | } |
|
| 419 | ||
| 420 | // archivar carpetas |
|
| 421 | $ok = $ok && archiveFolders($organization['id'], $snapshot['id'], $_POST['item']); |
|
| 422 | ||
| 423 | // borrar eventos completados |
|
| 424 | $ok = $ok && deleteAllCompletedEvents($organization['id']); |
|
| 425 | ||
| 426 | if ($ok) { |
|
| 427 | $app->flash('save_ok', 'ok'); |
|
| 428 | ORM::get_db()->commit(); |
|
| 429 | ||
| 430 | $app->redirect($app->urlFor('tree')); |
|
| 431 | } |
|
| 432 | else { |
|
| 433 | $app->flash('save_error', 'ok'); |
|
| 434 | ORM::get_db()->rollback(); |
|
| 435 | } |
|
| 436 | } |
|
| 437 | ||
| 438 | $items = getAutoCleaningFolders($organization['id']); |
|
| 439 | $snapshots = getSnapshots($organization['id']); |
|
| @@ 481-525 (lines=45) @@ | ||
| 478 | $lastUrl = $app->urlFor('frontpage'); |
|
| 479 | } |
|
| 480 | ||
| 481 | if ((isset($_POST['archive']) && isset($_POST['displayname']) && strlen($_POST['displayname'])) || |
|
| 482 | (isset($_POST['archive_old']) && isset($_POST['snapshot']))) { |
|
| 483 | ||
| 484 | // realizar los cambios en una transacción |
|
| 485 | ORM::get_db()->beginTransaction(); |
|
| 486 | ||
| 487 | if (isset($_POST['archive'])) { |
|
| 488 | // crear snapshot |
|
| 489 | $snapshot = ORM::for_table('snapshot')->create(); |
|
| 490 | $snapshot->set('organization_id', $organization['id']); |
|
| 491 | $snapshot->set('display_name', $_POST['displayname']); |
|
| 492 | $snapshot->set('order_nr', getLastSnapshotOrder($organization['id']) + 1000); |
|
| 493 | $ok = $snapshot->save(); |
|
| 494 | } |
|
| 495 | else { |
|
| 496 | // recuperar snapshot |
|
| 497 | $snapshot = ORM::for_table('snapshot')-> |
|
| 498 | where('organization_id', $organization['id'])-> |
|
| 499 | where('id', $_POST['snapshot'])-> |
|
| 500 | find_one(); |
|
| 501 | ||
| 502 | if (!$snapshot) { |
|
| 503 | $app->redirect($app->urlFor('login')); |
|
| 504 | } |
|
| 505 | ||
| 506 | $ok = true; |
|
| 507 | } |
|
| 508 | ||
| 509 | // archivar carpetas |
|
| 510 | $ok = $ok && archiveDeliveriesFromFolder($organization['id'], $snapshot['id'], $id, $_POST['item']); |
|
| 511 | ||
| 512 | // borrar eventos completados |
|
| 513 | $ok = $ok && deleteCompletedEventsForFolder($organization['id'], $id); |
|
| 514 | ||
| 515 | if ($ok) { |
|
| 516 | $app->flash('save_ok', 'ok'); |
|
| 517 | ORM::get_db()->commit(); |
|
| 518 | ||
| 519 | $app->redirect($lastUrl); |
|
| 520 | } |
|
| 521 | else { |
|
| 522 | $app->flash('save_error', 'ok'); |
|
| 523 | ORM::get_db()->rollback(); |
|
| 524 | } |
|
| 525 | } |
|
| 526 | ||
| 527 | $items = getDeliveriesFromFolderNotInSnapshot($organization['id'], $id); |
|
| 528 | $snapshots = getSnapshots($organization['id']); |
|