diff --git a/app/Migrations/Schema/V110/Version20151101082200.php b/app/Migrations/Schema/V110/Version20151101082200.php index a140f6a97b..328fed355c 100644 --- a/app/Migrations/Schema/V110/Version20151101082200.php +++ b/app/Migrations/Schema/V110/Version20151101082200.php @@ -30,6 +30,16 @@ class Version20151101082200 extends AbstractMigrationChamilo $this->addSql("ALTER TABLE session MODIFY session_category_id INT NULL"); $this->addSql("UPDATE session SET session_category_id = NULL WHERE session_category_id NOT IN (SELECT id FROM session_category)"); + + $table = $schema->getTable('session_rel_course_rel_user'); + if ($table->hasForeignKey('FK_720167E91D79BD3')) { + $this->addSql("ALTER TABLE session_rel_course_rel_user DROP FOREIGN KEY FK_720167E91D79BD3"); + } + + $table = $schema->getTable('session_rel_course'); + if ($table->hasForeignKey('FK_12D110D391D79BD3')) { + $this->addSql("ALTER TABLE session_rel_course DROP FOREIGN KEY FK_12D110D391D79BD3"); + } } /** diff --git a/app/Migrations/Schema/V110/Version20151101082300.php b/app/Migrations/Schema/V110/Version20151101082300.php index 476ad1edc4..de4d7c6cc7 100644 --- a/app/Migrations/Schema/V110/Version20151101082300.php +++ b/app/Migrations/Schema/V110/Version20151101082300.php @@ -27,25 +27,33 @@ class Version20151101082300 extends AbstractMigrationChamilo $accessUrlRelCourse->addForeignKeyConstraint('access_url', ['access_url_id'], ['id']); $accessUrlRelCourse->addForeignKeyConstraint('course', ['c_id'], ['id']); - $schema->renameTable('class', 'class_item'); + if ($schema->hasTable('class')) { + $schema->renameTable('class', 'class_item'); + } - $classUser = $schema->getTable('class_user'); - $classUser->getColumn('class_id')->setUnsigned(false); - $classUser->getColumn('user_id')->setUnsigned(false); + if ($schema->hasTable('class_user')) { + $classUser = $schema->getTable('class_user'); + $classUser->getColumn('class_id')->setUnsigned(false); + $classUser->getColumn('user_id')->setUnsigned(false); + } $course = $schema->getTable('course'); $course->getColumn('course_type_id')->setUnsigned(false); $course->addForeignKeyConstraint('room', ['room_id'], ['id']); - $courseRelClass = $schema->getTable('course_rel_class'); - $courseRelClass->getColumn('class_id')->setUnsigned(false)->setType(Type::getType(Type::INTEGER)); + if ($schema->hasTable('course_rel_class')) { + $courseRelClass = $schema->getTable('course_rel_class'); + $courseRelClass->getColumn('class_id')->setUnsigned(false)->setType(Type::getType(Type::INTEGER)); + } $courseRelUser = $schema->getTable('course_rel_user'); $courseRelUser->addForeignKeyConstraint('course', ['c_id'], ['id']); $courseRelUser->addForeignKeyConstraint('user', ['user_id'], ['id']); - $courseType = $schema->getTable('course_type'); - $courseType->getColumn('id')->setUnsigned(false); + if ($schema->hasTable('course_type')) { + $courseType = $schema->getTable('course_type'); + $courseType->getColumn('id')->setUnsigned(false); + } $schema->getTable('c_announcement')->addIndex(['c_id']); $schema->getTable('c_announcement_attachment')->addIndex(['c_id']); diff --git a/main/inc/lib/add_course.lib.inc.php b/main/inc/lib/add_course.lib.inc.php index 1eaf4475fb..f93523de2a 100755 --- a/main/inc/lib/add_course.lib.inc.php +++ b/main/inc/lib/add_course.lib.inc.php @@ -201,14 +201,13 @@ class AddCourse public static function get_course_tables() { $tables = array(); - + $tables[] = 'item_property'; $tables[] = 'tool'; $tables[] = 'tool_intro'; $tables[] = 'group_info'; $tables[] = 'group_category'; $tables[] = 'group_rel_user'; $tables[] = 'group_rel_tutor'; - $tables[] = 'item_property'; $tables[] = 'userinfo_content'; $tables[] = 'userinfo_def'; $tables[] = 'course_description'; diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php index 4bb79b3b84..c1190b5a30 100755 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -2238,10 +2238,10 @@ class CourseManager } // Cleaning groups - $groups = GroupManager::get_groups(); + $groups = GroupManager::get_groups($courseId); if (!empty($groups)) { $groupList = array_column($groups, 'id'); - GroupManager::delete_groups($groupList); + GroupManager::delete_groups($groupList, $course['code']); } // Cleaning c_x tables diff --git a/main/inc/lib/document.lib.php b/main/inc/lib/document.lib.php index 8b63fbb620..78c28dc48e 100755 --- a/main/inc/lib/document.lib.php +++ b/main/inc/lib/document.lib.php @@ -747,7 +747,8 @@ class DocumentManager public static function get_all_document_folders( $_course, $to_group_id = 0, - $can_see_invisible = false + $can_see_invisible = false, + $getInvisibleList = false ) { $TABLE_ITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY); $TABLE_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT); @@ -778,7 +779,7 @@ class DocumentManager $session_id = api_get_session_id(); $condition_session = api_get_session_condition($session_id, true, false, 'docs.session_id'); $show_users_condition = ""; - if (api_get_setting('show_users_folders') == 'false') { + if (api_get_setting('show_users_folders') === 'false') { $show_users_condition = " AND docs.path NOT LIKE '%shared_folder%'"; } @@ -797,7 +798,7 @@ class DocumentManager $groupCondition AND docs.path NOT LIKE '%shared_folder%' AND docs.path NOT LIKE '%_DELETED_%' AND - last.visibility <> 2 + last.visibility <> 2 $condition_session "; } else { $sql = "SELECT DISTINCT docs.id, path @@ -810,10 +811,10 @@ class DocumentManager docs.c_id = {$_course['real_id']} ) WHERE - docs.filetype = 'folder' AND + docs.filetype = 'folder' AND docs.path NOT LIKE '%_DELETED_%' AND $groupCondition AND - last.visibility <> 2 + last.visibility <> 2 $show_users_condition $condition_session "; } $result = Database::query($sql); @@ -841,29 +842,44 @@ class DocumentManager return false; } } else { + // No invisible folders // Condition for the session $session_id = api_get_session_id(); $condition_session = api_get_session_condition($session_id, true, false, 'docs.session_id'); + + $visibilityCondition = 'last.visibility = 1'; + $fileType = "docs.filetype = 'folder' AND"; + if ($getInvisibleList) { + $visibilityCondition = 'last.visibility = 0'; + $fileType = ''; + } + //get visible folders $sql = "SELECT DISTINCT docs.id, path FROM $TABLE_ITEMPROPERTY AS last, $TABLE_DOCUMENT AS docs WHERE docs.id = last.ref AND - docs.filetype = 'folder' AND + $fileType last.tool = '" . TOOL_DOCUMENT . "' AND $groupCondition AND - last.visibility = 1 + $visibilityCondition $condition_session AND last.c_id = {$_course['real_id']} AND docs.c_id = {$_course['real_id']} "; $result = Database::query($sql); + $visibleFolders = array(); while ($row = Database::fetch_array($result, 'ASSOC')) { $visibleFolders[$row['id']] = $row['path']; } + if ($getInvisibleList) { + + return $visibleFolders; + } + // Condition for the session $session_id = api_get_session_id(); $condition_session = api_get_session_condition($session_id, true, false, 'docs.session_id'); @@ -902,6 +918,7 @@ class DocumentManager } } + //if both results are arrays -> //calculate the difference between the 2 arrays -> only visible folders are left :) if (is_array($visibleFolders) && is_array($invisibleFolders)) { $document_folders = array_diff($visibleFolders, $invisibleFolders); @@ -2828,12 +2845,6 @@ class DocumentManager $upload_ok = process_uploaded_file($files[$fileKey], $show_output); if ($upload_ok) { - // File got on the server without problems, now process it - if ($title) { - $titleAndExt = explode('.', $files[$fileKey]['name']); - $ext = end($titleAndExt); - $files[$fileKey]['name'] = $title.'.'.$ext; - } $new_path = handle_uploaded_document( $course_info, $files[$fileKey], @@ -2896,6 +2907,10 @@ class DocumentManager } }*/ + if (!empty($title)) { + $params['title'] = $title; + } + if (!empty($comment)) { $params['comment'] = trim($comment); } @@ -4534,6 +4549,7 @@ class DocumentManager file_exists($documentData['absolute_path']) ) { $mp3FilePath = self::convertWavToMp3($documentData['absolute_path']); + error_log($mp3FilePath); if (!empty($mp3FilePath) && file_exists($mp3FilePath)) { diff --git a/main/inc/lib/groupmanager.lib.php b/main/inc/lib/groupmanager.lib.php index 68be503460..e1fd95f5b4 100755 --- a/main/inc/lib/groupmanager.lib.php +++ b/main/inc/lib/groupmanager.lib.php @@ -61,12 +61,12 @@ class GroupManager /** * @return array */ - public static function get_groups() + public static function get_groups($courseId = null) { $table_group = Database :: get_course_table(TABLE_GROUP); - $course_id = api_get_course_int_id(); + $courseId = !empty($courseId) ? (int) $courseId : api_get_course_int_id(); - $sql = "SELECT * FROM $table_group WHERE c_id = $course_id "; + $sql = "SELECT * FROM $table_group WHERE c_id = $courseId "; $result = Database::query($sql); return Database::store_result($result, 'ASSOC'); } @@ -775,7 +775,7 @@ class GroupManager while ($group = Database::fetch_object($res)) { $groups_to_delete[] = $group->id; } - self :: delete_groups($groups_to_delete); + self::delete_groups($groups_to_delete, $course_code); } $sql = "DELETE FROM $table_group_cat WHERE c_id = $course_id AND id='".$cat_id."'"; diff --git a/src/Chamilo/CoreBundle/Component/Editor/Driver/CourseDriver.php b/src/Chamilo/CoreBundle/Component/Editor/Driver/CourseDriver.php index 68983ff47a..87cca32c56 100644 --- a/src/Chamilo/CoreBundle/Component/Editor/Driver/CourseDriver.php +++ b/src/Chamilo/CoreBundle/Component/Editor/Driver/CourseDriver.php @@ -12,6 +12,8 @@ namespace Chamilo\CoreBundle\Component\Editor\Driver; class CourseDriver extends Driver implements DriverInterface { public $name = 'CourseDriver'; + public $visibleFiles = []; + private $coursePath; /** * Setups the folder @@ -21,15 +23,15 @@ class CourseDriver extends Driver implements DriverInterface $userId = api_get_user_id(); $userInfo = api_get_user_info(); $sessionId = api_get_session_id(); - $courseInfo = $this->connector->course; if (!empty($courseInfo)) { - $coursePath = api_get_path(SYS_COURSE_PATH); $courseDir = $courseInfo['directory'] . '/document'; $baseDir = $coursePath . $courseDir; + $this->coursePath = $baseDir; + // Creates shared folder if (!file_exists($baseDir . '/shared_folder')) { @@ -80,8 +82,9 @@ class CourseDriver extends Driver implements DriverInterface //$code = $this->connector->course->getCode(); $courseCode = $this->connector->course['code']; $alias = $courseCode.' '.get_lang('Documents'); + $userId = api_get_user_id(); - return array( + $config = array( 'driver' => 'CourseDriver', 'path' => $this->getCourseDocumentSysPath(), 'URL' => $this->getCourseDocumentRelativeWebPath(), @@ -95,9 +98,55 @@ class CourseDriver extends Driver implements DriverInterface 'write' => false, 'hidden' => true, 'locked' => false - ), + ) ) ); + + $folders = \DocumentManager::get_all_document_folders($this->connector->course, null, false, true); + if (!empty($folders)) { + foreach ($folders as $folder) { + //$folder = str_replace('-', "", $folder); + //\/ + $config['attributes'][] = [ + 'pattern' => '!'.$folder.'!', + 'read' => false, + 'write' => false, + 'hidden' => true, + 'locked' => false + ]; + } + } + + // Blocking all groups + + // hide all groups folders + $config['attributes'][] = [ + 'pattern' => '!_groupdocs_!', + 'read' => false, + 'write' => false, + 'hidden' => true, + 'locked' => false + ]; + + + // Allow only the groups I have access + $allGroups = \GroupManager::getAllGroupPerUserSubscription($userId); + if (!empty($allGroups)) { + foreach ($allGroups as $groupInfo) { + $groupId = $groupInfo['iid']; + if (\GroupManager::user_has_access($userId, $groupId, \GroupManager::GROUP_TOOL_DOCUMENTS)) { + $config['attributes'][] = [ + 'pattern' => '!'.$groupInfo['secret_directory'].'!', + 'read' => true, + 'write' => false, + 'hidden' => false, + 'locked' => false + ]; + } + } + } + + return $config; } return array(); @@ -165,13 +214,11 @@ class CourseDriver extends Driver implements DriverInterface { $this->setConnectorFromPlugin(); - if ($this->allow()) { + if ($this->allowToEdit()) { // upload file by elfinder. $result = parent::upload($fp, $dst, $name, $tmpname); - $name = $result['name']; - $filtered = \URLify::filter($result['name'], 80, '', true); if (strcmp($name, $filtered) != 0) { @@ -198,7 +245,6 @@ class CourseDriver extends Driver implements DriverInterface $result['name'] ); } - //error_log(print_r($this->error(),1)); return $result; } @@ -215,7 +261,7 @@ class CourseDriver extends Driver implements DriverInterface //parent::rm($hash); $this->setConnectorFromPlugin(); - if ($this->allow()) { + if ($this->allowToEdit()) { $path = $this->decode($hash); $stat = $this->stat($path); @@ -244,10 +290,65 @@ class CourseDriver extends Driver implements DriverInterface public function allow() { //if ($this->connector->security->isGranted('ROLE_ADMIN')) { - return - isset($this->connector->course) && - !empty($this->connector->course) && - !api_is_anonymous() - ; + + if (api_is_anonymous()) { + + return false; + } + + if (isset($this->connector->course) && !empty($this->connector->course)) { + + return true; + } + + return false; + } + + /** + * Allow to upload/delete folder or files + * + * @return bool + */ + public function allowToEdit() + { + $allow = $this->allow(); + + return $allow && api_is_allowed_to_edit(null, true); } + + /** + * @param string $attr + * @param string $path + * @param $data + * @param CourseDriver $volume + */ + /*public function access($attr, $path, $data, $volume) + { + if ($path == $this->coursePath) { + + return true; + } + + $allowToEdit = $this->allowToEdit(); + if ($allowToEdit) { + return true; + } + + $path = str_replace($this->coursePath, '', $path); + $documentId = \DocumentManager::get_document_id($this->connector->course, $path); + + if ($documentId) { + + $result = \DocumentManager::is_visible_by_id( + $documentId, + $this->connector->course, + api_get_session_id(), + api_get_user_id() + ); + return false; + } + + return false; + + }*/ } diff --git a/src/Chamilo/CoreBundle/Component/Editor/Toolbar.php b/src/Chamilo/CoreBundle/Component/Editor/Toolbar.php index 8e9407e631..c9b0956d4f 100644 --- a/src/Chamilo/CoreBundle/Component/Editor/Toolbar.php +++ b/src/Chamilo/CoreBundle/Component/Editor/Toolbar.php @@ -49,7 +49,8 @@ class Toolbar array_merge( $this->getDefaultPlugins(), $this->getPlugins(), - $this->getConditionalPlugins()) + $this->getConditionalPlugins() + ) ); return