finddoc.php 936 B

123456789101112131415161718192021222324252627
  1. <?php
  2. /**
  3. * Script to find a document with a specific title or path in all courses
  4. */
  5. /**
  6. * Code init - comment die() call to enable
  7. */
  8. die();
  9. require '../../inc/global.inc.php';
  10. require_once '../../inc/lib/course.lib.php';
  11. if (empty($_GET['doc'])) {
  12. echo "To add a document name to search, add ?doc=abc to the URL";
  13. } else {
  14. echo "Received param ".Security::remove_XSS($_GET['doc'])."<br />";
  15. }
  16. $courses_list = CourseManager::get_courses_list();
  17. foreach ($courses_list as $course) {
  18. $title = Database::escape_string($_GET['doc']);
  19. $td = Database::get_course_table(TABLE_DOCUMENT);
  20. $sql = "SELECT id, path FROM $td WHERE c_id = ".$course['id']." AND path LIKE '%$title%' OR title LIKE '%$title%'";
  21. $res = Database::query($sql);
  22. if (Database::num_rows($res)>0) {
  23. while ($row = Database::fetch_array($res)) {
  24. echo "Found doc ".$row['id']."-> ".$row['path']." in course ".$course['code']."<br />";
  25. }
  26. }
  27. }