manage.testdatapath.php 1.7 KB

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