recover_dropbox_files.php 1.7 KB

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