manage.testdatapath.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Tests presence of course directories.
  5. *
  6. * @package vchamilo
  7. * @category plugin
  8. *
  9. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL
  10. */
  11. // Loading configuration.
  12. require_once __DIR__.'/../../../main/inc/global.inc.php';
  13. api_protect_admin_script();
  14. $plugin = VChamiloPlugin::create();
  15. // Retrieve parameters for database connection test.
  16. $dataroot = $_REQUEST['dataroot'];
  17. $absalternatecourse = Virtual::getConfig('vchamilo', 'course_real_root');
  18. if (!empty($absalternatecourse)) {
  19. // this is the relocated case
  20. $coursedir = str_replace('//', '/', $absalternatecourse.'/'.$dataroot);
  21. } else {
  22. // this is the standard local case
  23. $coursedir = api_get_path(SYS_PATH).$dataroot;
  24. }
  25. if (is_dir($coursedir)) {
  26. $DIR = opendir($coursedir);
  27. $cpt = 0;
  28. $hasfiles = false;
  29. while (($file = readdir($DIR)) && !$hasfiles) {
  30. if (!preg_match("/^\\./", $file)) {
  31. $hasfiles = true;
  32. }
  33. }
  34. closedir($DIR);
  35. if ($hasfiles) {
  36. echo '<div class="error">'.$plugin->get_lang('datapathnotavailable').'</div>';
  37. } else {
  38. echo '<div class="success">'.$plugin->get_lang('datapathavailable').'</div>';
  39. }
  40. echo stripslashes($coursedir);
  41. } else {
  42. if (@mkdir($coursedir, 02777, true)) {
  43. echo '<div class="success">'.$plugin->get_lang('datapathcreated').'</div>';
  44. } else {
  45. echo '<div class="error">'.$plugin->get_lang('couldnotcreatedataroot').'</div>';
  46. }
  47. echo stripslashes($coursedir);
  48. }
  49. echo "</p>";
  50. $closestr = $plugin->get_lang('closewindow');
  51. echo "<center>";
  52. echo "<input class='btn' type=\"button\" name=\"close\" value=\"$closestr\" onclick=\"self.close();\" />";
  53. echo "</center>";