fill_all.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /* For license terms, see /license.txt */
  3. /**
  4. * This script contains calls to the various filling scripts that allow a
  5. * demo presenter to fill his Dokeos with demo data.
  6. * This script is locked against execution from the browser, to avoid malicious
  7. * insertion on production portals.
  8. * To execute, you need the PHP5 Command Line Interface (CLI) to be installed
  9. * on your system and t launch this script manually using: php5 fill_all.php
  10. * @author Yannick Warnier <yannick.warnier@dokeos.com>
  11. */
  12. $incdir = __DIR__.'/../../main/inc/';
  13. require $incdir.'global.inc.php';
  14. /**
  15. * Code logic
  16. */
  17. //Avoid execution if not from the command line
  18. if (PHP_SAPI != 'cli') { die('This demo-data filling script can only be run from the command line. Please launch it from the command line using: php5 fill_all.php. To enable it from your browser (very highly dangerous), remove the first line of code from the "logic" section of this file.'); }
  19. $eol = PHP_EOL;
  20. $output = '';
  21. $files = scandir(__DIR__);
  22. foreach ($files as $file) {
  23. if (substr($file, 0, 1) == '.' or substr($file, 0, 5) != 'fill_') {
  24. ;
  25. } else {
  26. if ($file == basename(__FILE__)) {
  27. //skip, this is the current file
  28. } else {
  29. $output .= $eol.'Reading file: '.$file.$eol;
  30. require_once $file;
  31. $function = basename($file, '.php');
  32. if (function_exists($function)) {
  33. $output .= $eol.'Executing function '.$function.$eol;
  34. $function();
  35. } else {
  36. //function not found
  37. }
  38. }
  39. }
  40. }
  41. /**
  42. * Display
  43. */
  44. echo $output.$eol;
  45. echo "Done all$eol";