';
$course_attempt_name = '__XxTestxX__';
$course_dir = $app['path.courses'].$course_attempt_name;
// Just in case.
if (is_file($course_dir.'/test.txt')) {
unlink($course_dir.'/test.txt');
}
if (is_dir($course_dir)) {
rmdir($course_dir);
}
$perms_dir = array(0777, 0755, 0775, 0770, 0750, 0700);
$perms_fil = array(0666, 0644, 0664, 0660, 0640, 0600);
$course_test_was_created = false;
$dir_perm_verified = 0777;
foreach ($perms_dir as $perm) {
$r = @mkdir($course_dir, $perm);
if ($r === true) {
$dir_perm_verified = $perm;
$course_test_was_created = true;
break;
}
}
$fil_perm_verified = 0666;
$file_course_test_was_created = false;
if (is_dir($course_dir)) {
foreach ($perms_fil as $perm) {
if ($file_course_test_was_created == true) {
break;
}
$r = touch($course_dir.'/test.php', $perm);
if ($r === true) {
$fil_perm_verified = $perm;
if (check_course_script_interpretation($course_dir, $course_attempt_name, 'test.php')) {
$file_course_test_was_created = true;
}
}
}
}
@unlink($course_dir.'/test.php');
@rmdir($course_dir);
$app['session']->set('permissions_for_new_directories', decoct($dir_perm_verified));
$app['session']->set('permissions_for_new_files', decoct($fil_perm_verified));
$dir_perm = Display::label('0'.decoct($dir_perm_verified), 'info');
$file_perm = Display::label('0'.decoct($fil_perm_verified), 'info');
$course_test_was_created = ($course_test_was_created == true && $file_course_test_was_created == true) ? Display::label(translate('Yes'), 'success') : Display::label(translate('No'), 'important');
$html .= '
[chamilo]/config |
'.check_writable_root_path('config/').' |
[chamilo]/data |
'.check_writable_root_path('data').' |
[chamilo]/logs |
'.check_writable_root_path('logs').' |
'.translate('CourseTestWasCreated').' |
'.$course_test_was_created.' |
'.translate('PermissionsForNewDirs').' |
'.$dir_perm.' |
'.translate('PermissionsForNewFiles').' |
'.$file_perm.' |
';
$html .= '
';
$html .= '
';
$html .= '';
$error = false;
// First, attempt to set writing permissions if we don't have them yet
$perm = $app['session']->get('permissions_for_new_directories');
$perm_file = $app['session']->get('permissions_for_new_files');
$notwritable = array();
$checked_writable = api_get_path(SYS_CONFIG_PATH);
if (!is_writable($checked_writable)) {
$notwritable[] = $checked_writable;
@chmod($checked_writable, $perm);
}
$checked_writable = api_get_path(SYS_DATA_PATH);
if (!is_writable($checked_writable)) {
$notwritable[] = $checked_writable;
@chmod($checked_writable, $perm);
}
$checked_writable = api_get_path(SYS_DEFAULT_COURSE_DOCUMENT_PATH).'images/';
if (!is_writable($checked_writable)) {
$notwritable[] = $checked_writable;
@chmod($checked_writable, $perm);
}
$checked_writable = api_get_path(SYS_ARCHIVE_PATH);
if (!is_writable($checked_writable)) {
$notwritable[] = $checked_writable;
@chmod($checked_writable, $perm);
}
$checked_writable = api_get_path(SYS_LOG_PATH);
if (!is_writable($checked_writable)) {
$notwritable[] = $checked_writable;
@chmod($checked_writable, $perm);
}
/*$checked_writable = api_get_path(SYS_COURSE_PATH);
if (!is_writable($checked_writable)) {
$notwritable[] = $checked_writable;
@chmod($checked_writable, $perm);
}*/
if ($course_test_was_created == false || $file_course_test_was_created == false) {
$error = true;
}
/*$checked_writable = api_get_path(SYS_PATH).'home/';
if (!is_writable($checked_writable)) {
$notwritable[] = realpath($checked_writable);
@chmod($checked_writable, $perm);
}*/
/*$checked_writable = api_get_path(CONFIGURATION_PATH).'configuration.php';
if (file_exists($checked_writable) && !is_writable($checked_writable)) {
$notwritable[] = $checked_writable;
@chmod($checked_writable, $perm_file);
}*/
// Second, if this fails, report an error
// The user would have to adjust the permissions manually
if (count($notwritable) > 0) {
$html .= '