recover_dropbox_files.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 WHERE c_id = $course_id AND session_id = $session_id";
  25. $result = Database::query($sql);
  26. if (Database::num_rows($result)) {
  27. $files = Database::store_result($result);
  28. $rows = array();
  29. foreach ($files as $file) {
  30. //Check if I have this file:
  31. $sql = "SELECT * FROM $person_tbl WHERE c_id = $course_id AND user_id = $user_id AND file_id = {$file['id']}";
  32. $result_person = Database::query($sql);
  33. if (Database::num_rows($result_person) == 0 ) {
  34. $rows[] = array(
  35. $file['filename'],
  36. api_convert_and_format_date($file['upload_date']),
  37. Display::url(get_lang('Recover'), api_get_self().'?recover_id='.$file['id'], array('class' => 'btn'))
  38. );
  39. }
  40. }
  41. $headers = array(get_lang('Filename'), get_lang('UploadedDate'), get_lang('Action'));
  42. echo Display::table($headers, $rows);
  43. }
  44. Display::display_footer();