finddoc.php 955 B

12345678910111213141516171819202122232425262728
  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 ".$_GET['doc']."<br />";
  15. }
  16. $courses_list = CourseManager::get_courses_list();
  17. foreach ($courses_list as $course) {
  18. //echo '<pre>'.print_r($course['db_name'],1).'</pre>';
  19. $title = Database::escape_string($_GET['doc']);
  20. $td = Database::get_course_table(TABLE_DOCUMENT,$course['db_name']);
  21. $sql = "SELECT id, path FROM $td WHERE path LIKE '%$title%' or title LIKE '%$title%'";
  22. $res = Database::query($sql);
  23. if (Database::num_rows($res)>0) {
  24. while ($row = Database::fetch_array($res)) {
  25. echo "Found doc ".$row['id']."-> ".$row['path']." in course ".$course['code']."<br />";
  26. }
  27. }
  28. }