manage.testdatapath.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Tests presence of course directories.
  4. *
  5. * @package vchamilo
  6. * @category plugin
  7. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL
  8. */
  9. // Loading configuration.
  10. require_once '../../../main/inc/global.inc.php';
  11. require_once api_get_path(SYS_PLUGIN_PATH).'vchamilo/lib/vchamilo_plugin.class.php';
  12. require_once api_get_path(SYS_PLUGIN_PATH).'vchamilo/lib.php';
  13. api_protect_admin_script();
  14. $plugininstance = VChamiloPlugin::create();
  15. // Retrieve parameters for database connection test.
  16. $dataroot = $_REQUEST['dataroot'];
  17. $absalternatecourse = vchamilo_get_config('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">'.$plugininstance->get_lang('datapathnotavailable').'</div>';
  37. } else {
  38. echo '<div class="success">'.$plugininstance->get_lang('datapathavailable').'</div>';
  39. }
  40. echo stripslashes($coursedir);
  41. } else {
  42. if (@mkdir($coursedir, 02777, true)) {
  43. echo '<div class="success">'.$plugininstance->get_lang('datapathcreated').'</div>';
  44. } else {
  45. echo '<div class="error">'.$plugininstance->get_lang('couldnotcreatedataroot').'</div>';
  46. }
  47. echo stripslashes($coursedir);
  48. }
  49. echo "</p>";
  50. $closestr = $plugininstance->get_lang('closewindow');
  51. echo "<center>";
  52. echo "<input class='btn' type=\"button\" name=\"close\" value=\"$closestr\" onclick=\"self.close();\" />";
  53. echo "</center>";