瀏覽代碼

WIP fix vchamilo plugin

jmontoyaa 9 年之前
父節點
當前提交
2474f5a91e

+ 1 - 0
plugin/vchamilo/install.php

@@ -18,6 +18,7 @@ $tablename = Database::get_main_table($table);
 $sql = "CREATE TABLE IF NOT EXISTS $tablename (
   `id` int(11) NOT NULL AUTO_INCREMENT,
   `sitename` varchar(80) NOT NULL,
+   slug varchar(255) NOT NULL,
   `institution` varchar(80) NOT NULL,
   `root_web` varchar(120),
   `db_host` varchar(80) NOT NULL,

+ 17 - 29
plugin/vchamilo/lib.php

@@ -1,5 +1,7 @@
 <?php
 
+use Cocur\Slugify\Slugify;
+
 require_once 'lib/bootlib.php';
 require_once 'lib/vchamilo_plugin.class.php';
 
@@ -225,21 +227,13 @@ function vchamilo_drop_databases(&$vchamilo)
  * @param    $outputfile        array        The variables to inject in setup template SQL.
  * @return    bool    If TRUE, loading database from template was sucessful, otherwise FALSE.
  */
-function vchamilo_create_databases($vchamilo, $cnx = null)
+function vchamilo_create_databases($vchamilo)
 {
     // availability of SQL commands
     $createstatement = 'CREATE DATABASE %DATABASE% DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ';
 
     $dbs = array($vchamilo->main_database);
 
-    if (!empty($vchamilo->statistics_database) && $vchamilo->main_database != $vchamilo->statistics_database){
-        $dbs[] = $vchamilo->statistics_database;
-    }
-
-    if (!empty($vchamilo->user_personal_database) && ($vchamilo->main_database != $vchamilo->user_personal_database) && ($vchamilo->statistics_database != $vchamilo->user_personal_database)){
-        $dbs[] = $vchamilo->user_personal_database;
-    }
-
     foreach($dbs as $adb){
         Display::addFlash(Display::return_message("Creating DB $adb"));
         $sql = str_replace('%DATABASE%', $adb, $createstatement);
@@ -429,8 +423,6 @@ function vchamilo_execute_db_sql(&$vchamilo, $bulkfile, $cnx = null, $vars=null,
  */
 function vchamilo_dump_databases($vchamilo, $outputfilerad)
 {
-    global $CFG;
-
     // Separating host and port, if sticked.
     if (strstr($vchamilo->db_host, ':') !== false){
         list($host, $port) = split(':', $vchamilo->db_host);
@@ -447,7 +439,7 @@ function vchamilo_dump_databases($vchamilo, $outputfilerad)
     }
 
     // Password.
-    if (!empty($vchamilo->db_password)){
+    if (!empty($vchamilo->db_password)) {
         $pass = "-p".escapeshellarg($vchamilo->db_password);
     }
 
@@ -456,21 +448,10 @@ function vchamilo_dump_databases($vchamilo, $outputfilerad)
     //if ($CFG->ostype == 'WINDOWS') {
     if (false) {
         $cmd_main = "-h{$host} -P{$port} -u{$vchamilo->db_user} {$pass} {$vchamilo->main_database}";
-        $cmds[] = $cmd_main . ' > ' . $outputfilerad.'_main.sql';
-
-        if ($vchamilo->statistics_database != $vchamilo->main_database){
-            $cmd_stats = "-h{$host} -P{$port} -u{$vchamilo->db_user} {$pass} {$vchamilo->statistics_database}";
-            $cmds[] = $cmd_stats . ' > ' . $outputfilerad.'_statistics.sql';
-        }
-
-        if (($vchamilo->user_personal_database != $vchamilo->main_database) && ($vchamilo->user_personal_database != $vchamilo->statistics_database)) {
-            $cmd_user = "-h{$host} -P{$port} -u{$vchamilo->db_user} {$pass} {$vchamilo->user_personal_database}";
-            $cmds[] = $cmd_user . ' > ' . $outputfilerad.'_user_personal.sql';
-        }
-
+        $cmds[] = $cmd_main . ' > ' . $outputfilerad;
     } else {
         $cmd_main = "-h{$host} -P{$port} -u{$vchamilo->db_user} {$pass} {$vchamilo->main_database}";
-        $cmds[] = $cmd_main . ' > ' . escapeshellarg($outputfilerad.'_main.sql');
+        $cmds[] = $cmd_main . ' > ' . escapeshellarg($outputfilerad);
     }
 
     $mysqldumpcmd = vchamilo_get_config('vchamilo', 'cmd_mysqldump', true);
@@ -500,17 +481,17 @@ function vchamilo_dump_databases($vchamilo, $outputfilerad)
             // Final command.
             $cmd = $pgm.' '.$cmd;
             // Prints log messages in the page and in 'cmd.log'.
-            if ($LOG = fopen(dirname($outputfilerad).'/cmd.log', 'a')){
+            /*if ($LOG = fopen(dirname($outputfilerad).'/cmd.log', 'a')){
                 fwrite($LOG, $cmd."\n");
-            }
+            }*/
 
             // Executes the SQL command.
             exec($cmd, $execoutput, $returnvalue);
-            if ($LOG){
+            /*if ($LOG){
                 foreach($execoutput as $execline) fwrite($LOG, $execline."\n");
                 fwrite($LOG, $returnvalue."\n");
                 fclose($LOG);
-            }
+            }*/
         }
     }
 
@@ -1204,4 +1185,11 @@ function param_filter_type($value, $type)
 
 function redirect($url) {
     header("Location: $url\n\n");
+}
+
+function vchamilo_get_slug_from_url($url)
+{
+    $slugify = new Slugify();
+    $urlInfo = parse_url($url);
+    return $slugify->slugify($urlInfo['host']);
 }

+ 6 - 7
plugin/vchamilo/plugin.php

@@ -19,13 +19,13 @@ global $_configuration;
 /* Plugin config */
 
 //the plugin title
-$plugin_info['title']       = 'Chamilo Virtualization';
+$plugin_info['title'] = 'Chamilo Virtualization';
 //the comments that go with the plugin
-$plugin_info['comment']     = "Holds chamilo virtualisation tools";
+$plugin_info['comment'] = "Holds chamilo virtualisation tools";
 //the plugin version
-$plugin_info['version']     = '1.0';
+$plugin_info['version'] = '1.0';
 //the plugin author
-$plugin_info['author']      = 'Valery Fremaux';
+$plugin_info['author'] = 'Valery Fremaux, Julio Montoya';
 
 
 /* Plugin optional settings */
@@ -59,8 +59,7 @@ $wwwroot = $_configuration['root_web'];
 
 //A simple select
 $options = array(0 => $plugininstance->get_lang('no'), 1 => $plugininstance->get_lang('yes'));
-$form->addElement('static', 'enable_vchamilo_manager', '<a href="'.api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php">'.$plugininstance->get_lang('manage_instances').'</a>');
-$form->addElement('static', 'sync_vchamilo_settings', '<a href="'.api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/syncparams.php">'.$plugininstance->get_lang('sync_settings').'</a>');
+$form->addlabel('', '<a href="'.api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php">'.$plugininstance->get_lang('manage_instances').'</a>');
 $form->addElement('header', $plugininstance->get_lang('enabling'));
 $form->addElement('select', 'enable_virtualisation', $plugininstance->get_lang('enable_virtualisation'), $options);
 $form->addElement('text', 'course_real_root', $plugininstance->get_lang('courserealroot'));
@@ -83,4 +82,4 @@ $form->addButtonSave($plugininstance->get_lang('Save'));
 $plugin_info['settings_form'] = $form;
 
 //set the templates that are going to be used
-$plugin_info['templates']   = array('template.tpl');
+$plugin_info['templates'] = array('template.tpl');

+ 26 - 27
plugin/vchamilo/views/editinstance.controller.php

@@ -13,8 +13,6 @@ if ($data->what == 'addinstance' || $data->what == 'registerinstance') {
     unset($data->testconnection);
     unset($data->testdatapath);
 
-    var_dump($data);exit;
-
     $registeronly = $data->registeronly;
     unset($data->registeronly);
     $data->lastcron = 0;
@@ -26,20 +24,31 @@ if ($data->what == 'addinstance' || $data->what == 'registerinstance') {
         unset($data->template);
     }
 
-    ctrace("Registering VChamilo ");
+    $mainDatabase = api_get_configuration_value('main_database');
+
+    if ($mainDatabase == $data->main_database) {
+        Display::addFlash(Display::return_message('You cannot use the same database as the chamilo master', 'error'));
+        return ;
+    }
+
+    ctrace("Registering VChamilo");
     $tablename = Database::get_main_table('vchamilo');
-    $sql = "SELECT * FROM $tablename WHERE root_web = '".Database::escape_string($data->root_web)."'";
+    $sql = "SELECT * FROM $tablename 
+            WHERE root_web = '".Database::escape_string($data->root_web)."'";
     $result = Database::query($sql);
 
     if (Database::num_rows($result)) {
-        $sql = "SELECT * FROM $tablename WHERE root_web = '".Database::escape_string($data->root_web)."'";
+        $sql = "SELECT * FROM $tablename 
+                WHERE root_web = '".Database::escape_string($data->root_web)."'";
         Database::update($tablename, $data, ['root_web = ?' => $data->root_web]);
-        //$DB->update_record('vchamilo', $data, 'root_web');
+        $virtualInfo = Database::fetch_array($result);
+        $slug = $virtualInfo['slug'];
     } else {
+        $slug = $data->slug = vchamilo_get_slug_from_url($data->root_web);
         Database::insert($tablename, (array) $data);
     }
 
-    if ($registeronly){
+    if ($registeronly) {
         // Stop it now.
         ctrace("Registering only. out.");
         vchamilo_redirect(api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php');
@@ -50,13 +59,7 @@ if ($data->what == 'addinstance' || $data->what == 'registerinstance') {
     // Create course directory for operations.
     // this is very important here (DO NOT USE api_get_path() !!) because storage may be remotely located
     $absalternatecourse = vchamilo_get_config('vchamilo', 'course_real_root');
-    if (!empty($absalternatecourse)) {
-        // this is the relocated case
-        $coursedir = str_replace('//', '/', $absalternatecourse.'/'.$data->course_folder);
-    } else {
-        // this is the standard local case
-        $coursedir = api_get_path(SYS_PATH).$data->course_folder;
-    }
+    $coursedir = $absalternatecourse.'/'.$slug;
 
     if (!is_dir($coursedir)) {
         ctrace("Creating physical course dir in $coursedir");
@@ -67,14 +70,15 @@ if ($data->what == 'addinstance' || $data->what == 'registerinstance') {
         fclose($INDEX);
 
         $HTACCESS = fopen($coursedir.'/.htaccess', 'w');
-        fputs($HTACCESS, vchamilo_get_htaccess_fragment($data->course_folder));
+        fputs($HTACCESS, vchamilo_get_htaccess_fragment($slug));
         fclose($HTACCESS);
     }
 
     // if real coursedir IS NOT under chamilo install, link to it
-    $standardlocation = str_replace('//', '/', $_configuration['root_sys'].'/'.$data->course_folder); // where it should be
+    /*$standardlocation = str_replace('//', '/', $_configuration['root_sys'].'/'.$data->course_folder); // where it should be
     ctrace("Checking course dir against standard $standardlocation ");
     ctrace("checking standard location : ".is_dir($standardlocation));
+
     if ($coursedir != $standardlocation) {
 
         // The standard location dir SHOULD NOT EXIST YET
@@ -86,7 +90,7 @@ if ($data->what == 'addinstance' || $data->what == 'registerinstance') {
         }
     } else {
         ctrace("Course dir in standard location");
-    }
+    }*/
 
     // create homedir
 
@@ -96,16 +100,15 @@ if ($data->what == 'addinstance' || $data->what == 'registerinstance') {
      * {LegacyHomeContainer} => {VChamiloSubcontainer} => {BrandedAccessUrlHome}
      *
      */
-
     $absalternatehome = vchamilo_get_config('vchamilo', 'home_real_root');
     // absalternatehome is a vchamilo config setting that tells where the
     // real physical storage for home pages are.
-    $homedir = str_replace('//', '/', $absalternatehome.'/'.$home_folder);
+    $homedir = str_replace('//', '/', $absalternatehome.'/'.$slug);
 
-    ctrace("Making home dir as $homedir ");
+    ctrace("Making home dir as $homedir");
 
     if (!is_dir($homedir)){
-        ctrace("Creating home dir ");
+        ctrace("Creating home dir");
         if (!mkdir($homedir, 0777, true)) {
             ctrace("Error creating home dir $homedir \n");
         }
@@ -127,16 +130,12 @@ if ($data->what == 'addinstance' || $data->what == 'registerinstance') {
 
     // create archive
     $absalternatearchive = vchamilo_get_config('vchamilo', 'archive_real_root');
-
-    $archivedir = str_replace('//', '/', $absalternatearchive.'/'.$archive_folder);
-    if (is_dir($archivedir)) {
-        $archivedir = $_configuration['root_sys'].'archive/'.$archive_folder;
-    }
+    $archivedir = $absalternatearchive.'/'.$slug;
 
     ctrace("Making archive dir as $archivedir ");
 
     if (!is_dir($archivedir)) {
-        ctrace("Creating archive dir ");
+        ctrace("Creating archive dir");
         if (!mkdir($archivedir, 0777, true)) {
             ctrace("Error creating archive dir $archivedir\n");
         }

+ 8 - 1
plugin/vchamilo/views/editinstance.php

@@ -15,10 +15,17 @@ $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_PLUGIN_PATH).'vchamilo/js/hos
 // get parameters
 $id = isset($_REQUEST['vid']) ? $_REQUEST['vid'] : '';
 $action = isset($_REQUEST['what']) ? $_REQUEST['what'] : '';
-$registeronly = @$_REQUEST['registeronly'];
+$registeronly = isset($_REQUEST['registeronly']) ? $_REQUEST['registeronly'] : 0;
 $plugininstance = VChamiloPlugin::create();
 $thisurl = api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php';
 
+$course_real_root = vchamilo_get_config('vchamilo', 'course_real_root');
+$homePath = vchamilo_get_config('vchamilo', 'home_real_root');
+
+if (empty($course_real_root) || empty($homePath)) {
+    api_not_allowed('You have to setup the course real root');
+}
+
 // security
 api_protect_admin_script();
 

+ 18 - 17
plugin/vchamilo/views/editinstance_form.php

@@ -383,23 +383,27 @@ class InstanceForm extends ChamiloForm
         $cform->applyFilter('sitename', 'trim');
 
         // Shortname.
-        $cform->addElement(
+        $elementInstitution = $cform->addElement(
             'text',
             'institution',
-            $this->_plugin->get_lang('institution'),
-            ($this->_mode == 'edit' ? 'disabled="disabled" ' : '')
+            $this->_plugin->get_lang('institution')
         );
+
         $cform->applyFilter('institution', 'trim');
 
         // Host's name.
-        $cform->addElement(
+        $elementWeb = $cform->addElement(
             'text',
             'root_web',
-            $this->_plugin->get_lang('rootweb'),
-            ($this->_mode == 'edit' ? 'disabled="disabled" ' : '')
+            $this->_plugin->get_lang('rootweb')
         );
         $cform->applyFilter('root_web', 'trim');
 
+        if ($this->_mode == 'update') {
+            $elementInstitution->freeze();
+            $elementWeb->freeze();
+        }
+
         /*
          * Database fieldset.
          */
@@ -428,15 +432,15 @@ class InstanceForm extends ChamiloForm
         //$cform->addElement('text', 'table_prefix', $this->_plugin->get_lang('tableprefix'));
 
         // Db's prefix.
-        $cform->addElement('text', 'db_prefix', $this->_plugin->get_lang('dbprefix'));
-        $cform->addElement('header', $this->_plugin->get_lang('datalocation'));
+        //$cform->addElement('text', 'db_prefix', $this->_plugin->get_lang('dbprefix'));
+        //$cform->addElement('header', $this->_plugin->get_lang('datalocation'));
 
-        $cform->addElement(
+        /*$cform->addElement(
             'text',
             'course_folder',
             $this->_plugin->get_lang('coursefolder'),
             array('id' => 'id_vdatapath')
-        );
+        );*/
 
         // Button for testing database connection.
         $cform->addElement(
@@ -451,7 +455,7 @@ class InstanceForm extends ChamiloForm
         );
 
         // Button for testing datapath.
-        $cform->addElement(
+        /*$cform->addElement(
             'button',
             'testdatapath',
             $this->_plugin->get_lang('testdatapath'),
@@ -460,7 +464,7 @@ class InstanceForm extends ChamiloForm
             'default',
             '',
             'onclick="opendatapathpopup(\''.$_configuration['root_web'].'\'); return true;"'
-        );
+        );*/
 
         /*
          * Template selection.
@@ -496,13 +500,13 @@ class InstanceForm extends ChamiloForm
                 null,
                 'client'
             );
-            $cform->addRule(
+            /*$cform->addRule(
                 'course_folder',
                 $this->_plugin->get_lang('coursefolderinputerror'),
                 'required',
                 null,
                 'client'
-            );
+            );*/
         }
     }
 
@@ -516,9 +520,6 @@ class InstanceForm extends ChamiloForm
         global $plugininstance;
 
         $errors = array();
-        if (!preg_match('/^courses[_-]/', $data['course_folder'])){
-            $errors['course_folder'] = $plugininstance->get_lang('errormuststartwithcourses');
-        }
 
         $tablename = Database::get_main_table('vchamilo');
         $vchamilo = Database::select(

+ 62 - 88
plugin/vchamilo/views/manage.controller.php

@@ -53,6 +53,7 @@ if ($action == 'enableinstances') {
 if ($action == 'fulldeleteinstances') {
 
     Display::addFlash(Display::return_message("Destroying instance"));
+
     // Removes everything.
     if (empty($automation)) {
         $vidlist = implode("','", $_REQUEST['vids']);
@@ -62,6 +63,7 @@ if ($action == 'fulldeleteinstances') {
     }
 
     foreach ($todelete as $fooid => $instance) {
+        $slug = $instance['slug'];
 
         Display::addFlash(Display::return_message("Dropping instance databases"));
         vchamilo_drop_databases($instance);
@@ -69,62 +71,33 @@ if ($action == 'fulldeleteinstances') {
         // Remove all files and eventual symlinks
 
         $absalternatecourse = vchamilo_get_config('vchamilo', 'course_real_root');
-        if (!empty($absalternatecourse)){
-            // this is the relocated case
-            $coursedir = str_replace('//', '/', $absalternatecourse.'/'.$instance->course_folder);
-        } else {
-            // this is the standard local case
-            $coursedir = api_get_path(SYS_PATH).$instance->course_folder;
-        }
-        $standardlocation = str_replace('//', '/', $_configuration['root_sys'].'/'.$instance->course_folder); // where it should be
+        $coursedir = $absalternatecourse.$slug;
 
         Display::addFlash(Display::return_message("Deleting $coursedir"));
-        removeDir($coursedir);
-        if (is_link($standardlocation)) {
-            unlink($standardlocation);
-        }
-
-        preg_match('#https?://([^\.]+)#', $instance->root_web, $matches);
-        $home_folder = $matches[1];
-        $archive_folder = $matches[1]; // prepare it now
 
-        if ($absalternatehome = vchamilo_get_config('vchamilo', 'home_real_root')){
-            $homedir = str_replace('//', '/', $absalternatehome.'/'.$home_folder);
-        } else {
-            $homedir = api_get_path(SYS_PATH).'home/'.$home_folder;
-        }
-        $standardlocation = $_configuration['root_sys'].'home/'.$home_folder; // where it should be
+        if ($absalternatehome = vchamilo_get_config('vchamilo', 'home_real_root')) {
+            $homedir = str_replace('//', '/', $absalternatehome.'/'.$slug);
 
-        Display::addFlash(Display::return_message("Deleting $homedir"));
-        removeDir($homedir);
-        if (is_link($standardlocation)) {
-            unlink($standardlocation);
+            Display::addFlash(Display::return_message("Deleting $homedir"));
+            removeDir($homedir);
         }
 
         // delete archive
-        if($absalternatearchive = vchamilo_get_config('vchamilo', 'archive_real_root')){
-            $archivedir = str_replace('//', '/', $absalternatearchive.'/'.$archive_folder);
-        } else {
-            $archivedir = $_configuration['root_sys'].'archive/'.$archive_folder;
-        }
-        $standardlocation = $_configuration['root_sys'].'archive/'.$archive_folder; // where it should be
+        if ($absalternatearchive = vchamilo_get_config('vchamilo', 'archive_real_root')){
+            $archivedir = str_replace('//', '/', $absalternatearchive.'/'.$slug);
 
-        Display::addFlash(Display::return_message("Deleting $archivedir"));
-        removeDir($archivedir);
-        if (is_link($standardlocation)) {
-            unlink($standardlocation);
+            Display::addFlash(Display::return_message("Deleting $archivedir"));
+            removeDir($archivedir);
         }
-        echo '</pre>';
 
         Display::addFlash(Display::return_message("Removing vchamilo record"));
         $sql = "DELETE FROM {$table} WHERE id = {$instance->id}";
         Database::query($sql);
     }
-
-    // vchamilo_redirect($_configuration['root_web'].'/plugin/vchamilo/views/manage.php');
 }
+
 if ($action == 'snapshotinstance') {
-    $interbreadcrumb[]=array('url' => 'manage.php','name' => get_lang('VChamilo'));
+    $interbreadcrumb[] = array('url' => 'manage.php', 'name' => get_lang('VChamilo'));
 
     $vid = isset($_REQUEST['vid']) ? $_REQUEST['vid'] : '';
     if ($vid) {
@@ -132,43 +105,34 @@ if ($action == 'snapshotinstance') {
         $vhost = (object)array_pop($vhosts);
     } else {
         $vhost = (object)$_configuration;
+        $vhost->slug = vchamilo_get_slug_from_url($vhost->root_web);
+        $vhost->id = 0;
     }
 
     // Parsing url for building the template name.
     $wwwroot = $vhost->root_web;
     $vchamilostep = isset($_REQUEST['step']) ? $_REQUEST['step'] : '';
-    preg_match('#https?://([^/]+)#', $wwwroot, $matches);
-    $hostname = $matches[1];
 
     // Make template directory (files and SQL).
     $separator = DIRECTORY_SEPARATOR;
-    $templatefoldername = 'plugin'.$separator.'vchamilo'.$separator.'templates';
-    $relative_datadir = $templatefoldername.$separator.$hostname.'_vchamilodata';
-    $absolute_datadir = $_configuration['root_sys'].$relative_datadir;
-    $relative_sqldir = $templatefoldername.$separator.$hostname.'_sql';
-    $absolute_sqldir = $_configuration['root_sys'].$separator.$relative_sqldir;
-    $absolute_templatesdir = $_configuration['root_sys'].$templatefoldername;
-
-    if (preg_match('/ /', $absolute_sqldir)) {
-        $erroritem = new StdClass();
-        $erroritem->message = $plugininstance->get_lang('errorspacesinpath');
-        vchamilo_print_error(array($erroritem));
-    }
 
-    if (!is_dir($absolute_templatesdir)){
-        mkdir($absolute_templatesdir, 0777, true);
+    $backupDir = $_configuration['root_sys'].'plugin'.$separator.'vchamilo'.$separator.'templates'.$separator.$vhost->slug.$separator;
+
+    $absolute_datadir = $backupDir.'data';
+    $absolute_sqldir = $backupDir.'dump.sql';
+
+    if (!is_dir($backupDir)) {
+        mkdir($backupDir, 0777, true);
     }
 
     if ($vchamilostep == 0) {
         // Create directories, if necessary.
-        if (!is_dir($absolute_datadir)){
+        if (!is_dir($absolute_datadir)) {
             mkdir($absolute_datadir, 0777, true);
-            mkdir($absolute_datadir.'/archive', 0777, true);
+            //mkdir($absolute_datadir.'/archive', 0777, true);
             mkdir($absolute_datadir.'/home', 0777, true);
         }
-        if (!is_dir($absolute_sqldir)) {
-            mkdir($absolute_sqldir, 0777, true);
-        }
+
         if (empty($fullautomation)) {
             $actionurl = $_configuration['root_web'].'/plugin/vchamilo/views/manage.php';
             $content = '<form name"single" action="'.$actionurl.'">';
@@ -191,27 +155,32 @@ if ($action == 'snapshotinstance') {
             $vchamilostep = 1;
         }
     }
+
     if ($vchamilostep >= 1) {
         if ($wwwroot == $_configuration['root_web']) {
             // Make fake Vchamilo record.
             $vchamilo = vchamilo_make_this();
-            $vcoursepath = api_get_path(SYS_COURSE_PATH);
-            $vhomepath = api_get_path(SYS_HOME_PATH);
-            $varchivepath = api_get_path(SYS_ARCHIVE_PATH);
+            $coursePath = api_get_path(SYS_COURSE_PATH);
+            $homePath = api_get_path(SYS_HOME_PATH);
+            $archivePath = api_get_path(SYS_ARCHIVE_PATH);
         } else {
             // Get Vchamilo known record.
-            $vchamilos = Database::select('*', 'vchamilo', array('where' => array('root_web = ?' => array($wwwroot))));
-            $vchamilo = (object)array_pop($vchamilos);
-            $vcoursepath = api_get_path(SYS_COURSE_PATH, (array)$vchamilo);
-            $vhomepath = api_get_path(SYS_HOME_PATH, (array)$vchamilo);
-            $varchivepath = api_get_path(SYS_ARCHIVE_PATH, (array)$vchamilo);
+            $vchamilo = Database::select('*', 'vchamilo', array('where' => array('root_web = ?' => array($wwwroot))), 'first');
+            $vchamilo = (object) $vchamilo;
+            $coursePath = vchamilo_get_config('vchamilo', 'course_real_root');
+            $homePath = vchamilo_get_config('vchamilo', 'home_real_root');
+            $archivePath = vchamilo_get_config('vchamilo', 'archive_real_root');
+
+            $coursePath = $coursePath.'/'.$vchamilo->slug;
+            $homePath = $homePath.'/'.$vchamilo->slug;
+            $archivePath = $archivePath.'/'.$vchamilo->slug;
         }
 
         $content = '';
         if ($vchamilostep == 1) {
             // Auto dump the databases in a master template folder.
-            // this will create three files : chamilo_master_main.sql, chamilo_master_statistics.sql, chamilo_master_user_personal.sql
-            $errors = vchamilo_dump_databases($vchamilo, $absolute_sqldir.$separator.'chamilo_master');
+            // this will create three files : dump.sql
+            $errors = vchamilo_dump_databases($vchamilo, $absolute_sqldir);
 
             if (empty($fullautomation)) {
                 if(!empty($errors)) {
@@ -227,6 +196,10 @@ if ($action == 'snapshotinstance') {
 
                     $message = $plugininstance->get_lang('vchamilosnapshot2');
 
+                    Display::addFlash(
+                        Display::return_message('mysql dump: '.$absolute_sqldir)
+                    );
+
                     $content .= '<form name"single" action="'.$actionurl.'">';
                     $content .= '<input type="hidden" name="what" value="snapshotinstance" />';
                     $content .= '<input type="hidden" name="vid" value="'.$vhost->id.'" />';
@@ -245,20 +218,20 @@ if ($action == 'snapshotinstance') {
             }
         }
 
-        Display::addFlash(Display::return_message("Copying from $vcoursepath to $absolute_datadir "));
-        copyDirTo($vcoursepath, $absolute_datadir, false);
-        Display::addFlash(Display::return_message("Copying from $varchivepath to {$absolute_datadir}/archive "));
-        copyDirTo($varchivepath, $absolute_datadir.'/archive', false);
-        Display::addFlash(Display::return_message("Copying from $vhomepath to {$absolute_datadir}/home "));
-        copyDirTo($vhomepath, $absolute_datadir.'/home', false);
+        Display::addFlash(Display::return_message("Copying from $homePath to {$absolute_datadir}/home "));
+        copyDirTo($homePath, $absolute_datadir.'/home/', false);
 
+        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 $archivePath to {$absolute_datadir}/archive "));
+        copyDirTo($varchivepath, $absolute_datadir.'/archive', false);*/
 
         // Store original hostname and some config info for further database or filestore replacements.
-        $FILE = fopen($absolute_sqldir.$separator.'manifest.php', 'w');
+        $FILE = fopen($backupDir.$separator.'manifest.php', 'w');
         fwrite($FILE, '<'.'?php ');
         fwrite($FILE, "\$templatewwwroot = '".$wwwroot."';\n");
-        fwrite($FILE, "\$templatevdbprefix = '".$vhost->table_prefix."';\n ");
-        fwrite($FILE, "\$coursefolder = '".$vhost->course_folder."';\n ");
+        //fwrite($FILE, "\$templatevdbprefix = '".$vhost->table_prefix."';\n ");
+        //fwrite($FILE, "\$coursefolder = '".$vhost->course_folder."';\n ");
         fwrite($FILE, '?'.'>');
         fclose($FILE);
 
@@ -301,25 +274,26 @@ if ($action == 'clearcache') {
             }
         }
     } else {
-        $toclear = Database::select('*', 'vchamilo', array('where' => array("root_web = '{$n->root_web}' " => array())));
+        $toclear = Database::select(
+            '*',
+            'vchamilo',
+            array('where' => array("root_web = '{$n->root_web}' " => array()))
+        );
     }
 
-    echo '<pre>';
     foreach ($toclear as $fooid => $instance) {
-
         if ($fooid == 0) {
-            echo ("Clearing master template cache \n");
+            Display::addFlash(Display::return_message("Clearing master template cache"));
         } else {
-            echo ("Clearing instance template cache \n");
+            Display::addFlash(Display::return_message("Clearing instance template cache"));
         }
 
         // Get instance archive
-        $archivepath = api_get_path(SYS_ARCHIVE_PATH, TO_SYS, (array)$instance);
+        $archivepath = api_get_path(SYS_ARCHIVE_PATH, (array)$instance);
         $templatepath = $archivepath.'twig';
-        echo ("Deleting $templatepath \n");
+        Display::addFlash(Display::return_message("Deleting $templatepath \n"));
         removeDir($templatepath);
     }
-    echo '</pre>';
 }
 
 if ($action == 'setconfigvalue') {

+ 46 - 6
plugin/vchamilo/views/manage.php

@@ -67,23 +67,61 @@ foreach ($instances as $instance) {
     $cmd .= '&nbsp;<a href="'.$thisurl.'?what=snapshotinstance&vid='.$instance->id.'" title="'.$plugininstance->get_lang('snapshotinstance').'">
         <img src="'.$plugininstance->pix_url('snapshot').'" /></a>';
 
-    if (!$instance->visible){
+    if (!$instance->visible) {
         $cmd .= '<a href="'.$thisurl.'?what=fulldeleteinstances&vids[]='.$instance->id.'" title="'.$plugininstance->get_lang('destroyinstances').'">
         <img src="'.$plugininstance->pix_url('delete').'" /></a>';
     } else {
         $cmd .= '<a href="'.$thisurl.'?what=deleteinstances&vids[]='.$instance->id.'" title="'.$plugininstance->get_lang('deleteinstances').'">
         <img src="'.$plugininstance->pix_url('delete').'" /></a>';
     }
+    
 
     $crondate = ($instance->lastcron) ? date('r', $instance->lastcron) : '';
-    $data = array($checkbox, $sitelink, $instance->institution, $instance->root_web, $instance->db_host, $instance->course_folder, $status, $crondate, $cmd);
+    $data = array(
+        $checkbox,
+        $sitelink,
+        $instance->institution,
+        Display::url($instance->root_web, $instance->root_web),
+        $instance->db_host,
+        $instance->slug,
+        $status,
+        $crondate,
+        $cmd,
+    );
     $attrs = array('center' => 'left');
     $table->addRow($data, $attrs, 'td');
     $i++;
 }
 
+$items = [
+    [
+        'url' => $thisurl.'?what=newinstance',
+        'content' => $plugininstance->get_lang('newinstance')
+    ],
+    [
+        'url' => $thisurl.'?what=instance&registeronly=1',
+        'content' => $plugininstance->get_lang('registerinstance')
+    ],
+    [
+        'url' => $thisurl.'?what=snapshotinstance&vid=0',
+        'content' => $plugininstance->get_lang('snapshotmaster')
+    ],
+    [
+        'url' => $thisurl.'?what=clearcache&vid=0',
+        'content' => $plugininstance->get_lang('clearmastercache')
+    ],
+    [
+        'url' => api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/syncparams.php',
+        'content' => $plugininstance->get_lang('sync_settings')
+    ],
+    [
+        'url' => api_get_path(WEB_CODE_PATH).'admin/configure_plugin.php?name=vchamilo',
+        'content' => get_lang('Settings')
+    ]
+];
+
+$content .=  Display::actions($items);
 $content .=  '<form action="'.$thisurl.'">';
-
 $content .=  $table->toHtml();
 
 $selectionoptions = array('<option value="0" selected="selected">'.$plugininstance->get_lang('choose').'</option>');
@@ -94,9 +132,11 @@ $selectionoptions[] = '<option value="clearcache">'.$plugininstance->get_lang('c
 $selectionoptions[] = '<option value="setconfigvalue">'.$plugininstance->get_lang('setconfigvalue').'</option>';
 $selectionaction = '<select name="what" onchange="this.form.submit()">'.implode('', $selectionoptions).'</select>';
 
-$content .=  '<div class"vchamilo-right"><div></div><div><a href="javascript:selectallhosts()">'.$plugininstance->get_lang('selectall').'</a> - <a href="javascript:deselectallhosts()">'.$plugininstance->get_lang('selectnone').'</a> - <a href="'.$thisurl.'?what=newinstance">'.$plugininstance->get_lang('newinstance').'</a> - <a href="'.$thisurl.'?what=instance&registeronly=1">'.$plugininstance->get_lang('registerinstance').'</a>&nbsp; - '.$plugininstance->get_lang('withselection').' '.$selectionaction.'</div></div>';
-$content .=  '<div class"vchamilo-right"><div> <a href="'.$thisurl.'?what=snapshotinstance&vid=0">'.$plugininstance->get_lang('snapshotmaster').' <img src="'.$plugininstance->pix_url('snapshot').'" /></a></div>';
-$content .=  '<div class"vchamilo-right"><div> <a href="'.$thisurl.'?what=clearcache&vid=0">'.$plugininstance->get_lang('clearmastercache').'</a></div></div>';
+$content .=  '<div class"vchamilo-right"><div></div><div>
+<a href="javascript:selectallhosts()">'.$plugininstance->get_lang('selectall').'</a> - 
+<a href="javascript:deselectallhosts()">'.$plugininstance->get_lang('selectnone').'</a> - 
+&nbsp; - '.$plugininstance->get_lang('withselection').' '.$selectionaction.'</div></div>';
+
 $content .=  '</form>';
 
 $actions = '';

+ 2 - 1
plugin/vchamilo/views/syncparams.php

@@ -62,7 +62,8 @@ $message = '';
 
 $message = require_js('ajax.js', 'vchamilo', true);
 
-$tpl = new Template(get_lang('VChamilo'), true, true, false, true, false);
+$interbreadcrumb[] = array('url' => 'manage.php', 'name' => get_lang('VChamilo'));
+$tpl = new Template($plugininstance->get_lang('sync_settings'), true, true, false, true, false);
 $tpl->assign('actions', $actions);
 $tpl->assign('message', $message);
 $tpl->assign('content', $content);