recover_dropbox_files.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. require_once 'dropbox_init.inc.php';
  4. $file_tbl = Database::get_course_table(TABLE_DROPBOX_FILE);
  5. $person_tbl = Database::get_course_table(TABLE_DROPBOX_PERSON);
  6. $course_id = api_get_course_int_id();
  7. $user_id = api_get_user_id();
  8. $session_id = api_get_session_id();
  9. if (empty($course_id)) {
  10. api_not_allowed();
  11. }
  12. if (!api_is_allowed_to_session_edit(false, true)) {
  13. api_not_allowed();
  14. }
  15. echo Display::page_subheader(get_lang('Recover dropbox files'));
  16. if (isset($_GET['recover_id']) && !empty($_GET['recover_id'])) {
  17. $recover_id = intval($_GET['recover_id']);
  18. $sql = "INSERT INTO $person_tbl VALUES('$course_id', $recover_id, $user_id)";
  19. $result = Database::query($sql);
  20. if ($result) {
  21. echo Display::return_message(get_lang('Recovered'), 'confirm');
  22. }
  23. }
  24. $sql = "SELECT * FROM $file_tbl
  25. WHERE c_id = $course_id AND session_id = $session_id";
  26. $result = Database::query($sql);
  27. if (Database::num_rows($result)) {
  28. $files = Database::store_result($result);
  29. $rows = [];
  30. foreach ($files as $file) {
  31. //Check if I have this file:
  32. $sql = "SELECT * FROM $person_tbl
  33. WHERE c_id = $course_id AND user_id = $user_id AND file_id = {$file['id']}";
  34. $result_person = Database::query($sql);
  35. if (Database::num_rows($result_person) == 0) {
  36. $rows[] = [
  37. $file['filename'],
  38. api_convert_and_format_date($file['upload_date']),
  39. Display::url(
  40. get_lang('Recover'),
  41. api_get_self().'?recover_id='.$file['id'],
  42. ['class' => 'btn btn-default']
  43. ),
  44. ];
  45. }
  46. }
  47. $headers = [
  48. get_lang('Filename'),
  49. get_lang('Date of upload'),
  50. get_lang('Action'),
  51. ];
  52. echo Display::table($headers, $rows);
  53. }
  54. Display::display_footer();