Browse Source

Merge branch '1.11.x' of github.com:chamilo/chamilo-lms into 1.11.x

Yannick Warnier 8 years ago
parent
commit
1545547f2d

+ 1 - 1
main/admin/configure_plugin.php

@@ -30,7 +30,6 @@ if (isset($pluginInfo['settings_form'])) {
     /** @var FormValidator $form */
     $form = $pluginInfo['settings_form'];
     if (isset($form)) {
-
         // We override the form attributes
         $attributes = array('action' => $currentUrl, 'method' => 'POST');
         $form->updateAttributes($attributes);
@@ -65,6 +64,7 @@ if (isset($form)) {
         );
 
         foreach ($values as $key => $value) {
+            $value = trim($value);
             api_add_setting(
                 $value,
                 Database::escape_string($pluginName . '_' . $key),

+ 0 - 1
main/admin/grade_models.php

@@ -39,7 +39,6 @@ if ($action === 'add') {
 
 $htmlHeadXtra[]= '<script>
 function plusItem(item) {
-    console.log(item);
     if (item != 1) {
 		document.getElementById(item).style.display = "inline";
     	document.getElementById("plus-"+item).style.display = "none";

+ 0 - 1
main/admin/user_edit.php

@@ -491,7 +491,6 @@ if ($form->validate()) {
                 $_FILES['picture']['name'],
                 $_FILES['picture']['tmp_name'],
                 $user['picture_crop_result']
-
             );
 		}
 

+ 1 - 1
main/admin/user_move_stats.php

@@ -225,7 +225,7 @@ if (isset($_REQUEST['load_ajax'])) {
                             $sql = "UPDATE $TBL_TRACK_E_LAST_ACCESS SET access_session_id = $new_session_id WHERE access_id = $id";
                             if ($debug) echo $sql;
                             $res = Database::query($sql);
-                            if ($debug) error_log(__FILE__ . ' +' . __LINE__ . ': ' . print_r($res, 1));
+                            if ($debug) var_dump($res);
                             $result_message[$TBL_TRACK_E_LAST_ACCESS]++;
                         }
                     }

+ 12 - 3
main/attendance/attendance_controller.php

@@ -100,10 +100,19 @@ class AttendanceController
                 if ($check) {
                     $attendance->set_name($_POST['title']);
                     $attendance->set_description($_POST['description']);
-                    $attendance->set_attendance_qualify_title($_POST['attendance_qualify_title']);
-                    $attendance->set_attendance_weight($_POST['attendance_weight']);
+                    if (isset($_POST['attendance_qualify_title'])) {
+                        $attendance->set_attendance_qualify_title(
+                            $_POST['attendance_qualify_title']
+                        );
+                    }
 
-                    $attendance->category_id = $_POST['category_id'];
+                    if (isset($_POST['attendance_weight'])) {
+                        $attendance->set_attendance_weight(
+                            $_POST['attendance_weight']
+                        );
+                    }
+
+                    $attendance->category_id = isset($_POST['category_id']) ? $_POST['category_id'] : '';
                     $link_to_gradebook = false;
                     if (isset($_POST['attendance_qualify_gradebook']) &&
                         $_POST['attendance_qualify_gradebook'] == 1

+ 4 - 1
main/blog/blog_admin.php

@@ -30,7 +30,10 @@ if (api_is_allowed_to_edit()) {
     // the learning path, we do not include the banner so we have to explicitly
     // include the stylesheet, which is normally done in the header
     if (empty($_GET['origin']) || $_GET['origin'] != 'learnpath') {
-        $interbreadcrumb[]= array ('url' => 'blog_admin.php?','name' => $nameTools);
+        $interbreadcrumb[] = array(
+            'url' => 'blog_admin.php?'.api_get_cidreq(),
+            'name' => $nameTools,
+        );
         $my_url='';
         if (isset($_GET['action']) && $_GET['action']=='add') {
             $current_section = get_lang('AddBlog');

+ 0 - 1
main/forum/forumfunction.inc.php

@@ -704,7 +704,6 @@ function store_forum($values, $courseInfo = array(), $returnId = false)
             'moderated'=> $values['moderated']['moderated'],
             'start_time' => !empty($values['start_time']) ? api_get_utc_datetime($values['start_time']) : null,
             'end_time' => !empty($values['end_time']) ? api_get_utc_datetime($values['end_time']) : null,
-            'forum_order'=> isset($new_max) ? $new_max : null,
             'session_id'=> $session_id,
             'lp_id' => isset($values['lp_id']) ? intval($values['lp_id']) : 0
         ];

+ 5 - 6
main/inc/ajax/admin.ajax.php

@@ -27,11 +27,9 @@ switch ($action) {
             }
         }
         break;
-
     case 'version':
         echo version_check();
         break;
-
     case 'get_extra_content':
         $blockName = isset($_POST['block']) ? Security::remove_XSS($_POST['block']) : null;
 
@@ -49,7 +47,6 @@ switch ($action) {
             $urlInfo = api_get_access_url($accessUrlId);
             $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $urlInfo['url']));
             $cleanUrl = str_replace('/', '-', $url);
-
             $newUrlDir = api_get_path(SYS_APP_PATH) . "home/$cleanUrl/admin/";
         } else {
             $newUrlDir = api_get_path(SYS_APP_PATH) . "home/admin/";
@@ -174,10 +171,12 @@ function check_system_version()
                 $version_info = $version;
             }
 
-            if ($system_version != $version_info) {
-                $output = '<br /><span style="color:red">' . get_lang('YourVersionNotUpToDate') . '. '.get_lang('LatestVersionIs').' <b>Chamilo '.$version_info.'</b>. '.get_lang('YourVersionIs').' <b>Chamilo '.$system_version. '</b>. '.str_replace('http://www.chamilo.org', '<a href="http://www.chamilo.org">http://www.chamilo.org</a>', get_lang('PleaseVisitOurWebsite')).'</span>';
+            if (version_compare($system_version, $version_info, '<=')) {
+                $output = '<span style="color:red">' . get_lang('YourVersionNotUpToDate') .'<br />
+                           '.get_lang('LatestVersionIs').' <b>Chamilo '.$version_info.'</b>.  <br />
+                           '.get_lang('YourVersionIs').' <b>Chamilo '.$system_version. '</b>.  <br />'.str_replace('http://www.chamilo.org', '<a href="http://www.chamilo.org">http://www.chamilo.org</a>', get_lang('PleaseVisitOurWebsite')).'</span>';
             } else {
-                $output = '<br /><span style="color:green">'.get_lang('VersionUpToDate').': Chamilo '.$version_info.'</span>';
+                $output = '<span style="color:green">'.get_lang('VersionUpToDate').': Chamilo '.$version_info.'</span>';
             }
         } else {
             $output = '<span style="color:red">' . get_lang('ImpossibleToContactVersionServerPleaseTryAgain') . '</span>';

+ 1 - 0
main/inc/lib/api.lib.php

@@ -821,6 +821,7 @@ function api_get_path($path = '', $configuration = [])
             $paths[$root_web][SYS_ARCHIVE_PATH] = $virtualChamilo[SYS_ARCHIVE_PATH].'/';
             $paths[$root_web][SYS_HOME_PATH] = $virtualChamilo[SYS_HOME_PATH].'/';
             $paths[$root_web][SYS_COURSE_PATH] = $virtualChamilo[SYS_COURSE_PATH].'/';
+            $paths[$root_web][SYS_UPLOAD_PATH] = $virtualChamilo[SYS_UPLOAD_PATH].'/';
         }
 
         $isInitialized[$root_web] = true;

+ 2 - 0
main/inc/lib/usermanager.lib.php

@@ -1677,6 +1677,7 @@ class UserManager
                 $userInfo = api_get_user_info($user_id);
             }
         }
+
         $imageWebPath = self::get_user_picture_path_by_id($user_id, 'web', $userInfo);
         $pictureWebFile = $imageWebPath['file'];
         $pictureWebDir = $imageWebPath['dir'];
@@ -1781,6 +1782,7 @@ class UserManager
         $path_info = self::getUserPicturePathById($user_id, 'system');
 
         $path = $path_info['dir'];
+
         // If this directory does not exist - we create it.
         if (!file_exists($path)) {
             mkdir($path, api_get_permissions_for_new_directories(), true);

+ 3 - 0
plugin/vchamilo/lang/english.php

@@ -108,4 +108,7 @@ $strings['DatabaseDescription'] = 'A new database will be created with that name
 $strings['RootWebExists'] = 'An instance with the same root web exists.';
 $strings['ImportInstance'] = 'Import instance';
 $strings['ConfigurationPath'] = 'Chamilo configuration path';
+$strings['UploadRealRoot'] = 'Upload files';
+$strings['DatabaseAccessShouldBeDifferentThanMasterChamilo'] = 'Database server should be different than the Chamilo master';
+
 

+ 1 - 1
plugin/vchamilo/lib/VChamiloPlugin.php

@@ -16,7 +16,7 @@ class VChamiloPlugin extends Plugin
      */
     public function __construct()
     {
-        parent::__construct('1.2', 'Valery Fremaux, Julio Montoya');
+        parent::__construct('1.3', 'Valery Fremaux, Julio Montoya');
     }
 
     /**

+ 83 - 58
plugin/vchamilo/lib/Virtual.php

@@ -42,9 +42,7 @@ class Virtual
 
         if ($result->rowCount()) {
             $data = $result->fetch();
-
             $excludes = array('id', 'name');
-
             $query = "SELECT * FROM settings_current WHERE subkey = 'vchamilo'";
             $virtualSettings = $connection->executeQuery($query);
             $virtualSettings = $virtualSettings->fetchAll();
@@ -52,9 +50,13 @@ class Virtual
             $homePath = '';
             $coursePath = '';
             $archivePath = '';
+            $uploadPath = '';
 
             foreach ($virtualSettings as $setting) {
                 switch ($setting['variable']) {
+                    case 'vchamilo_upload_real_root':
+                        $uploadPath = $setting['selected_value'];
+                        break;
                     case 'vchamilo_home_real_root':
                         $homePath = $setting['selected_value'];
                         break;
@@ -67,7 +69,7 @@ class Virtual
                 }
             }
 
-            if (empty($homePath) || empty($coursePath) || empty($archivePath)) {
+            if (empty($homePath) || empty($coursePath) || empty($archivePath) || empty($uploadPath)) {
                 echo 'Configure correctly the vchamilo plugin';
                 exit;
             }
@@ -84,6 +86,7 @@ class Virtual
                 $data['SYS_ARCHIVE_PATH'] = $archivePath.'/'.$data['slug'];
                 $data['SYS_HOME_PATH'] = $homePath.'/'.$data['slug'];
                 $data['SYS_COURSE_PATH'] = $coursePath.'/'.$data['slug'];
+                $data['SYS_UPLOAD_PATH'] = $uploadPath.'/'.$data['slug'];
 
                 $virtualChamilo = $data;
             } else {
@@ -588,11 +591,13 @@ class Virtual
         $coursePath = self::getConfig('vchamilo', 'course_real_root').$separator.$vchamilo->slug;
         $homePath = self::getConfig('vchamilo', 'home_real_root').$separator.$vchamilo->slug;
         $archivePath = self::getConfig('vchamilo', 'archive_real_root').$separator.$vchamilo->slug;
+        $uploadPath = self::getConfig('vchamilo', 'upload_real_root').$separator.$vchamilo->slug;
 
         // get the protocol free hostname
         Display::addFlash(
             Display::return_message("Copying {$templateDir}/data/courses => $coursePath")
         );
+
         copyDirTo(
             self::chopLastSlash($templateDir.'/data/courses'),
             self::chopLastSlash($coursePath),
@@ -618,6 +623,17 @@ class Virtual
             self::chopLastSlash($homePath),
             false
         );
+
+        // Upload
+        Display::addFlash(
+            Display::return_message("Copying {$templateDir}/data/upload => $uploadPath")
+        );
+
+        copyDirTo(
+            self::chopLastSlash($templateDir.'/data/upload'),
+            self::chopLastSlash($uploadPath),
+            false
+        );
     }
 
     /**
@@ -663,12 +679,19 @@ class Virtual
         if ($return === 'head') {
             $htmlHeadXtra[] = $str;
         }
+
         if ($return) {
             return $str;
         }
         echo $str;
     }
 
+    /**
+     * @param $file
+     * @param $component
+     * @param bool $return
+     * @return string
+     */
     public static function requireCss($file, $component, $return = false)
     {
         global $_configuration, $htmlHeadXtra;
@@ -722,16 +745,20 @@ class Virtual
 
         global $virtualChamilo;
         if (!isset($virtualChamilo)) {
-            api_not_allowed(true, 'You have to edit the configuration.php. Please check the readme file.');
+            api_not_allowed(
+                true,
+                'You have to edit the configuration.php. Please check the readme file.'
+            );
         }
 
         $coursePath = self::getConfig('vchamilo', 'course_real_root');
         $homePath = self::getConfig('vchamilo', 'home_real_root');
         $archivePath = self::getConfig('vchamilo', 'archive_real_root');
+        $uploadPath = self::getConfig('vchamilo', 'upload_real_root');
         $cmdSql = self::getConfig('vchamilo', 'cmd_mysql');
         $cmdMySql = self::getConfig('vchamilo', 'cmd_mysqldump');
 
-        if (empty($coursePath) || empty($homePath) || empty($archivePath) || empty($cmdSql)|| empty($cmdMySql)) {
+        if (empty($coursePath) || empty($homePath) || empty($uploadPath) || empty($archivePath) || empty($cmdSql) || empty($cmdMySql)) {
             api_not_allowed(true, 'You have to complete all plugin settings.');
         }
 
@@ -742,13 +769,21 @@ class Virtual
             $coursePath,
             $homePath,
             $archivePath,
+            $uploadPath,
             $templatePath
         ];
 
         foreach ($paths as $path) {
-            if (!is_writable($path)) {
+            $path = trim($path);
+            if (is_dir($path)) {
+                if (!is_writable($path)) {
+                    Display::addFlash(
+                        Display::return_message("Directory must have writable permissions: '$path'", 'warning')
+                    );
+                };
+            } else {
                 Display::addFlash(
-                    Display::return_message('Directory must have writable permissions: '.$path, 'warning')
+                    Display::return_message("Directory doesn't exist: '$path'", 'warning')
                 );
             }
         }
@@ -787,7 +822,6 @@ class Virtual
             );
 
             if ($getManager) {
-
                 return $manager;
             }
 
@@ -857,6 +891,12 @@ class Virtual
             $slug = $virtualInfo['slug'];
         } else {
             $slug = $data->slug = Virtual::getSlugFromUrl($data->root_web);
+            if (empty($slug)) {
+                Display::addFlash(
+                    Display::return_message('Cannot create slug from url: '.$data->root_web, 'error')
+                );
+                return ;
+            }
             Database::insert($tablename, (array) $data);
         }
 
@@ -867,7 +907,6 @@ class Virtual
         }
 
         // or we continue with physical creation
-
         self::createDirsFromSlug($slug);
 
         if (!$template) {
@@ -890,8 +929,10 @@ class Virtual
 
         $sitename = Database::escape_string($data->sitename);
         $institution = Database::escape_string($data->institution);
+
         $sqls[] = "UPDATE {$settingstable} SET selected_value = '{$sitename}' 
                    WHERE variable = 'siteName' AND category = 'Platform' ";
+
         $sqls[] = "UPDATE {$settingstable} SET selected_value = '{$institution}' 
                    WHERE variable = 'institution' AND category = 'Platform' ";
 
@@ -930,9 +971,11 @@ class Virtual
 
         $fromCoursePath = $data->course_path;
         $fromHomePath = $data->home_path;
+        $fromUploadPath = $data->upload_path;
 
         unset($data->course_path);
         unset($data->home_path);
+        unset($data->upload_path);
 
         $newDatabase = clone $data;
         $newDatabase->main_database = $newDatabase->import_to_main_database;
@@ -953,7 +996,6 @@ class Virtual
         $data->lastcron = 0;
         $data->lastcrongap = 0;
         $data->croncount = 0;
-        $template = '';
 
         $mainDatabase = api_get_configuration_value('main_database');
 
@@ -962,7 +1004,7 @@ class Virtual
                 Display::return_message('You cannot use the same database as the chamilo master', 'error')
             );
 
-            return ;
+            return false;
         }
 
         self::ctrace('Registering: '.$data->root_web);
@@ -978,19 +1020,14 @@ class Virtual
             );
             return false;
         } else {
-
             $connection = Virtual::getConnectionFromInstance($data);
-
             $statement = $connection->query('SELECT * FROM settings_current');
             $settings = $statement->fetchAll();
             $settings = array_column($settings, 'selected_value', 'variable');
-
             $institution = $settings['Institution'];
             $siteName = $settings['siteName'];
-
             $newDatabase->sitename = $siteName;
             $newDatabase->institution = $institution;
-
             $slug = $newDatabase->slug = $data->slug = Virtual::getSlugFromUrl($data->root_web);
             $id = Database::insert($table, (array) $newDatabase);
         }
@@ -999,6 +1036,10 @@ class Virtual
             throw new Exception('Was not registered');
         }
 
+        if (empty($slug)) {
+            throw new Exception('Slug is empty');
+        }
+
         self::createDirsFromSlug($slug);
         self::ctrace("Create database");
         Virtual::createDatabase($newDatabase);
@@ -1032,23 +1073,32 @@ class Virtual
 
         $coursePath = self::getConfig('vchamilo', 'course_real_root').'/'.$slug;
         $homePath = self::getConfig('vchamilo', 'home_real_root').'/'.$slug;
+        $uploadPath = self::getConfig('vchamilo', 'upload_real_root').'/'.$slug;
 
+        // Course
         self::ctrace("Copy from '$fromCoursePath' to backup '$coursePath' ");
-
         copyDirTo(
             self::chopLastSlash($fromCoursePath),
             self::chopLastSlash($coursePath),
             false
         );
 
+        // Home
         self::ctrace("Copy from '$fromHomePath' to backup '$homePath' ");
-
         copyDirTo(
             self::chopLastSlash($fromHomePath),
             self::chopLastSlash($homePath),
             false
         );
 
+        // Upload
+        self::ctrace("Copy from '$fromUploadPath' to backup '$uploadPath' ");
+        copyDirTo(
+            self::chopLastSlash($fromUploadPath),
+            self::chopLastSlash($uploadPath),
+            false
+        );
+
         self::ctrace("Finished");
     }
 
@@ -1062,7 +1112,6 @@ class Virtual
         $settings = $statement->fetchAll();
         $settings = array_column($settings, 'selected_value', 'variable');
         $settings['data_base'];
-
     }
 
     /**
@@ -1095,53 +1144,30 @@ class Virtual
         }
 
         $absAlternateHome = Virtual::getConfig('vchamilo', 'home_real_root');
+        $absAlternateArchive = Virtual::getConfig('vchamilo', 'archive_real_root');
+        $absAlternateUpload = Virtual::getConfig('vchamilo', 'upload_real_root');
+
         // absalternatehome is a vchamilo config setting that tells where the
         // real physical storage for home pages are.
         $homeDir = $absAlternateHome.'/'.$slug;
-
-        self::ctrace("Making home dir as $homeDir");
-
-        if (!is_dir($homeDir)) {
-            if (!mkdir($homeDir, 0777, true)) {
-                self::ctrace("Error creating home dir $homeDir \n");
-            }
-        }
-
-        // if real homedir IS NOT under chamilo install, link to it
-        // Seems not be necessary as we can globally link the whole Home container
-        /*
-        $standardlocation = $_configuration['root_sys'].'home/'.$home_folder; // where it should be
-        if ($homeDir != $standardlocation){
-            self::ctrace("Linking virtual home dir ");
-            if (!symlink($homeDir, $standardlocation)){
-                self::ctrace("could not link $standardlocation => $homeDir ");
-            }
-        }
-        */
-
-        // create archive
-        $absAlternateArchive = Virtual::getConfig('vchamilo', 'archive_real_root');
         $archiveDir = $absAlternateArchive.'/'.$slug;
+        $uploadDir = $absAlternateUpload.'/'.$slug;
 
-        self::ctrace("Making archive dir as $archiveDir ");
+        $dirs = [
+            $homeDir,
+            $archiveDir,
+            $uploadDir
+        ];
 
-        if (!is_dir($archiveDir)) {
-            if (!mkdir($archiveDir, 0777, true)) {
-                self::ctrace("Error creating archive dir $archiveDir\n");
-            }
-        }
+        foreach ($dirs as $dir) {
+            self::ctrace("Making dir as $dir");
 
-        // if real archivedir IS NOT under chamilo install, link to it
-        // Seems not be necessary as we can globally link the whole Home container
-        /*
-        $standardlocation = $_configuration['root_sys'].'archive/'.$archive_folder; // where it should be
-        if ($archiveDir != $standardlocation){
-            self::ctrace("Linking virtual archive dir ");
-            if (!symlink($archiveDir, $standardlocation)){
-                self::ctrace("could not link $standardlocation => $archiveDir ");
+            if (!is_dir($dir)) {
+                if (!mkdir($dir, 0777, true)) {
+                    self::ctrace("Error creating dir $dir \n");
+                }
             }
         }
-        */
     }
 
     /**
@@ -1181,7 +1207,6 @@ class Virtual
         $currentVersion = implode('.', [$versionParts[0], $versionParts[1], '0']);
 
         if (version_compare($version, $currentVersion, '<')) {
-
             return $version;
         }
 

+ 7 - 0
plugin/vchamilo/plugin.php

@@ -48,6 +48,7 @@ $form_settings = array(
     'course_real_root' => Virtual::getConfig('vchamilo', 'course_real_root', true),
     'archive_real_root' => Virtual::getConfig('vchamilo', 'archive_real_root', true),
     'home_real_root' => Virtual::getConfig('vchamilo', 'home_real_root', true),
+    'upload_real_root' => Virtual::getConfig('vchamilo', 'upload_real_root', true),
 );
 
 $form->setDefaults($form_settings);
@@ -79,6 +80,12 @@ $form->addElement(
     [$plugin->get_lang('homerealroot'), 'Example: '.api_get_path(SYS_PATH).'var/home/']
 );
 
+$form->addElement(
+    'text',
+    'upload_real_root',
+    [$plugin->get_lang('UploadRealRoot'), 'Example: '.api_get_path(SYS_PATH).'var/upload/']
+);
+
 $form->addElement('header', $plugin->get_lang('mysqlcmds'));
 $form->addElement('text', 'cmd_mysql', [$plugin->get_lang('mysqlcmd'), 'Example: /usr/bin/mysql']);
 $form->addElement('text', 'cmd_mysqldump', [$plugin->get_lang('mysqldumpcmd'), 'Example: /usr/bin/mysqldump']);

+ 2 - 2
plugin/vchamilo/views/editinstance.php

@@ -20,8 +20,8 @@ $registeronly = isset($_REQUEST['registeronly']) ? $_REQUEST['registeronly'] : 0
 $plugin = VChamiloPlugin::create();
 $thisurl = api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php';
 
-$coursePath = Virtual::getConfig('vchamilo', 'course_real_root');
-$homePath = Virtual::getConfig('vchamilo', 'home_real_root');
+/*$coursePath = Virtual::getConfig('vchamilo', 'course_real_root');
+$homePath = Virtual::getConfig('vchamilo', 'home_real_root');*/
 
 if ($id) {
     $mode = 'update';

+ 33 - 7
plugin/vchamilo/views/import.php

@@ -2,13 +2,13 @@
 /* For licensing terms, see /license.txt */
 
 $cidReset = true;
-
 require_once '../../../main/inc/global.inc.php';
 
 $interbreadcrumb[] = array('url' => 'manage.php', 'name' => get_lang('VChamilo'));
 
 // Security
 api_protect_admin_script();
+
 Virtual::checkSettings();
 
 $plugin = VChamiloPlugin::create();
@@ -36,6 +36,15 @@ $form->addElement(
 // Database name.
 $form->addText('main_database', [$plugin->get_lang('maindatabase')]);
 
+$form->addText(
+    'configuration_file',
+    [
+        $plugin->get_lang('ConfigurationPath'),
+        get_lang('Example').': /var/www/site/app/config/configuration.php'
+    ],
+    true
+);
+
 $form->addText(
     'course_path',
     [
@@ -54,6 +63,14 @@ $form->addText(
     true
 );
 
+$form->addText(
+    'upload_path',
+    [
+        $plugin->get_lang('UploadPath'),
+        get_lang('Example').': /var/www/site/virtual/var/upload'
+    ],
+    true
+);
 
 $form->addHeader(get_lang('To'));
 
@@ -73,7 +90,12 @@ $form->addElement(
 );
 
 // Database name.
-$form->addText('to_main_database', [$plugin->get_lang('maindatabase'), $plugin->get_lang('DatabaseDescription')]);
+$form->addText('to_main_database',
+    [
+        $plugin->get_lang('maindatabase'),
+        $plugin->get_lang('DatabaseDescription'),
+    ]
+);
 
 $form->addButtonSave($plugin->get_lang('savechanges'), 'submitbutton');
 $content = $form->returnForm();
@@ -83,8 +105,13 @@ if ($form->validate()) {
 
     $coursePath = $values['course_path'];
     $homePath = $values['home_path'];
+    $confFile = $values['configuration_file'];
 
-    if (is_dir($coursePath) && is_dir($homePath)) {
+    if (is_dir($coursePath) &&
+        is_dir($homePath) &&
+        file_exists($confFile) &&
+        is_readable($confFile)
+    ) {
         $currentHost = api_get_configuration_value('db_host');
         $currentDatabase = api_get_configuration_value('main_database');
         $currentUser = api_get_configuration_value('db_user');
@@ -94,11 +121,11 @@ if ($form->validate()) {
             $values['to_db_user'] !== $currentUser &&
             $values['to_db_password'] !== $currentPassword
         ) {
-
         } else {
             Display::addFlash(
                 Display::return_message(
-                    $plugin->get_lang('DatabaseAccessShouldBeDifferentThanMasterChamilo')
+                    $plugin->get_lang('DatabaseAccessShouldBeDifferentThanMasterChamilo'),
+                    'warning'
                 )
             );
         }
@@ -109,14 +136,13 @@ if ($form->validate()) {
         $vchamilo->db_password = $values['db_password'];
         $vchamilo->db_host = $values['db_host'];
         $vchamilo->root_web = $values['root_web'];
-
         $vchamilo->import_to_main_database = $values['to_main_database'];
         $vchamilo->import_to_db_user = $values['to_db_user'];
         $vchamilo->import_to_db_password = $values['to_db_password'];
         $vchamilo->import_to_db_host = $values['to_db_host'];
-
         $vchamilo->course_path = $values['course_path'];
         $vchamilo->home_path = $values['home_path'];
+        $vchamilo->upload_path = $values['upload_path'];
 
         Virtual::importInstance($vchamilo);
     }

+ 19 - 2
plugin/vchamilo/views/manage.controller.php

@@ -59,12 +59,13 @@ switch ($action) {
                 array('where' => array("root_web = '{$n->root_web}' " => array()))
             );
         }
+
         if ($todelete) {
             foreach ($todelete as $fooid => $instance) {
                 $slug = $instance['slug'];
 
                 if (empty($slug)) {
-                    continue;
+                   continue;
                 }
 
                 // Remove all files and eventual symlinks
@@ -90,6 +91,14 @@ switch ($action) {
                     removeDir($archivedir);
                 }
 
+                // Delete upload
+                if ($dir = Virtual::getConfig('vchamilo', 'upload_real_root')) {
+                    $dir = $dir.'/'.$slug;
+
+                    Display::addFlash(Display::return_message("Deleting $dir"));
+                    removeDir($dir);
+                }
+
                 $sql = "DELETE FROM {$table} WHERE id = ".$instance['id'];
                 Database::query($sql);
 
@@ -174,6 +183,7 @@ switch ($action) {
                 $coursePath = api_get_path(SYS_COURSE_PATH);
                 $homePath = api_get_path(SYS_HOME_PATH);
                 $archivePath = api_get_path(SYS_ARCHIVE_PATH);
+                $uploadPath = api_get_path(SYS_UPLOAD_PATH);
             } else {
                 // Get Vchamilo known record.
                 $vchamilo = Database::select('*', 'vchamilo', array('where' => array('root_web = ?' => array($wwwroot))), 'first');
@@ -181,10 +191,12 @@ switch ($action) {
                 $coursePath = Virtual::getConfig('vchamilo', 'course_real_root');
                 $homePath = Virtual::getConfig('vchamilo', 'home_real_root');
                 $archivePath = Virtual::getConfig('vchamilo', 'archive_real_root');
+                $uploadPath = Virtual::getConfig('vchamilo', 'upload_real_root');
 
                 $coursePath = $coursePath.'/'.$vchamilo->slug;
                 $homePath = $homePath.'/'.$vchamilo->slug;
                 $archivePath = $archivePath.'/'.$vchamilo->slug;
+                $uploadPath = $uploadPath.'/'.$vchamilo->slug;
             }
 
             $content = '';
@@ -232,6 +244,9 @@ switch ($action) {
             Display::addFlash(Display::return_message("Copying from '$coursePath' to '$absolute_datadir/courses' "));
             copyDirTo($coursePath, $absolute_datadir.'/courses/', false);
 
+            Display::addFlash(Display::return_message("Copying from '$uploadPath' to '$absolute_datadir/upload' "));
+            copyDirTo($uploadPath, $absolute_datadir.'/upload/', false);
+
             // Store original hostname and some config info for further database or filestore replacements.
             $FILE = fopen($backupDir.$separator.'manifest.php', 'w');
             fwrite($FILE, '<'.'?php ');
@@ -242,7 +257,8 @@ switch ($action) {
             // Every step was SUCCESS.
             if (empty($fullautomation)) {
                 Display::addFlash(
-                    Display::return_message($plugin->get_lang('successfinishedcapture'),
+                    Display::return_message(
+                        $plugin->get_lang('successfinishedcapture'),
                         'success'
                     )
                 );
@@ -317,6 +333,7 @@ switch ($action) {
                 $coursePath = Virtual::getConfig('vchamilo', 'course_real_root');
                 $homePath = Virtual::getConfig('vchamilo', 'home_real_root');
                 $archivePath = Virtual::getConfig('vchamilo', 'archive_real_root');
+                //$uploadPath = Virtual::getConfig('vchamilo', 'upload_real_root');
 
                 // Get instance archive
                 $archivepath = api_get_path(SYS_ARCHIVE_PATH, (array)$instance);