diff --git a/plugin/vchamilo/install.php b/plugin/vchamilo/install.php index a34bc3da06..fde3c0bb55 100644 --- a/plugin/vchamilo/install.php +++ b/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, diff --git a/plugin/vchamilo/lib.php b/plugin/vchamilo/lib.php index 3039a3498d..cd190752cc 100644 --- a/plugin/vchamilo/lib.php +++ b/plugin/vchamilo/lib.php @@ -1,5 +1,7 @@ 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']); } \ No newline at end of file diff --git a/plugin/vchamilo/plugin.php b/plugin/vchamilo/plugin.php index 3960a1e4e3..6c5635a3c7 100644 --- a/plugin/vchamilo/plugin.php +++ b/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', ''.$plugininstance->get_lang('manage_instances').''); -$form->addElement('static', 'sync_vchamilo_settings', ''.$plugininstance->get_lang('sync_settings').''); +$form->addlabel('', ''.$plugininstance->get_lang('manage_instances').''); $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'); diff --git a/plugin/vchamilo/views/editinstance.controller.php b/plugin/vchamilo/views/editinstance.controller.php index 093ef7b336..add323ed95 100644 --- a/plugin/vchamilo/views/editinstance.controller.php +++ b/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"); } diff --git a/plugin/vchamilo/views/editinstance.php b/plugin/vchamilo/views/editinstance.php index 68b9d669c4..b17ac340e7 100644 --- a/plugin/vchamilo/views/editinstance.php +++ b/plugin/vchamilo/views/editinstance.php @@ -15,10 +15,17 @@ $htmlHeadXtra[] = '