recover_dropbox_files.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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('RecoverDropboxFiles'));
  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. Display::display_confirmation_message(get_lang('Recovered'));
  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 = array();
  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[] = array(
  37. $file['filename'],
  38. api_convert_and_format_date($file['upload_date']),
  39. Display::url(
  40. get_lang('Recover'), api_get_self().'?recover_id='.$file['id'],
  41. array('class' => 'btn btn-default')
  42. )
  43. );
  44. }
  45. }
  46. $headers = array(get_lang('FileName'), get_lang('UploadedDate'), get_lang('Action'));
  47. echo Display::table($headers, $rows);
  48. }
  49. Display::display_footer();