WIP vchamilo plugin

Adding warning message, choose one template by default, fix UI, block access to users.
ofaj
jmontoyaa 9 years ago
parent c023e350c3
commit 8e21d121a2
  1. 57
      plugin/vchamilo/lib.php
  2. 8
      plugin/vchamilo/plugin.php
  3. 11
      plugin/vchamilo/views/editinstance.controller.php
  4. 4
      plugin/vchamilo/views/editinstance.php
  5. 31
      plugin/vchamilo/views/editinstance_form.php
  6. 44
      plugin/vchamilo/views/manage.controller.php
  7. 2
      plugin/vchamilo/views/manage.php

@ -65,18 +65,21 @@ function vchamilo_hook_configuration(&$_configuration)
if ($result->rowCount()) {
$data = $result->fetch();
foreach ($data as $key => $value){
if (!in_array($key, $excludes)) {
$_configuration[$key] = $value;
// Only load if is visible
if ($data['visible']) {
foreach ($data as $key => $value) {
if (!in_array($key, $excludes)) {
$_configuration[$key] = $value;
}
$_configuration['virtual'] = $data['root_web'].'/';
}
$_configuration['virtual'] = $data['root_web'].'/';
}
$data['SYS_ARCHIVE_PATH'] = $homePath.'/'.$data['slug'];
$data['SYS_HOME_PATH'] = $coursePath.'/'.$data['slug'];
$data['SYS_COURSE_PATH'] = $archivePath.'/'.$data['slug'];
$data['SYS_ARCHIVE_PATH'] = $homePath.'/'.$data['slug'];
$data['SYS_HOME_PATH'] = $coursePath.'/'.$data['slug'];
$data['SYS_COURSE_PATH'] = $archivePath.'/'.$data['slug'];
$VCHAMILO = $data;
$VCHAMILO = $data;
}
} else {
//die ("VChamilo : No configuration for this host. May be faked.");
die ("VChamilo : Could not fetch virtual chamilo configuration");
@ -339,8 +342,9 @@ function vchamilo_load_db_template($vchamilo, $template)
// @see http://stackoverflow.com/questions/10028925/call-a-program-via-shell-exec-with-utf-8-text-input
exec($import, $output, $return);
Display::addFlash(Display::return_message(implode("\n", $output)."\n"));
if (!empty($output)) {
Display::addFlash(Display::return_message(implode("\n", $output)."\n"));
}
return true;
}
@ -556,7 +560,7 @@ function vchamilo_make_this()
* Get available templates for defining a new virtual host.
* @return array The available templates, or EMPTY array.
*/
function vchamilo_get_available_templates($addEmptyTemplate = true)
function vchamilo_get_available_templates()
{
global $_configuration;
global $plugininstance;
@ -576,9 +580,9 @@ function vchamilo_get_available_templates($addEmptyTemplate = true)
// Retrieves template(s) name(s). Should be hostnames.
$templates = [];
if ($addEmptyTemplate) {
/*if ($addEmptyTemplate) {
$templates = array('' => $plugininstance->get_lang('emptysite'));
}
}*/
$template = vchamilo_get_config('vchamilo', 'default_template');
@ -656,8 +660,6 @@ function vchamilo_load_files_from_template($vchamilo, $template)
$vhomepath = api_get_path(SYS_HOME_PATH, (array)$vchamilo);
$varchivepath = api_get_path(SYS_ARCHIVE_PATH, (array)$vchamilo);
Display::addFlash(Display::return_message("archiveapth : $varchivepath"));
// Rename some dirs top match instance requirements
$manifest = vchamilo_get_vmanifest($template);
if ($manifest) {
@ -1209,4 +1211,27 @@ function vchamilo_get_slug_from_url($url)
$slugify = new Slugify();
$urlInfo = parse_url($url);
return $slugify->slugify($urlInfo['host']);
}
/**
* Check if all settings are complete
*/
function vchamilo_check_settings()
{
$enabled = vchamilo_get_config('vchamilo', 'enable_virtualisation');
if (empty($enabled)) {
api_not_allowed(true, 'Plugin is not enabled');
}
$coursePath = vchamilo_get_config('vchamilo', 'course_real_root');
$homePath = vchamilo_get_config('vchamilo', 'home_real_root');
$archivePath = vchamilo_get_config('vchamilo', 'archive_real_root');
$cmdSql = vchamilo_get_config('vchamilo', 'cmd_mysql');
$cmdMySql = vchamilo_get_config('vchamilo', 'cmd_mysqldump');
if (empty($coursePath) || empty($homePath) || empty($archivePath) || empty($cmdSql)|| empty($cmdMySql)) {
api_not_allowed(true, 'You have to complete all plugin settings.');
}
}

@ -6,9 +6,9 @@
* @author Julio Montoya <gugli100@gmail.com>
*/
require_once(api_get_path(LIBRARY_PATH).'plugin.class.php');
require_once(api_get_path(SYS_PLUGIN_PATH).'vchamilo/lib/vchamilo_plugin.class.php');
require_once(api_get_path(SYS_PLUGIN_PATH).'vchamilo/lib.php');
require_once api_get_path(LIBRARY_PATH).'plugin.class.php';
require_once api_get_path(SYS_PLUGIN_PATH).'vchamilo/lib/vchamilo_plugin.class.php';
require_once api_get_path(SYS_PLUGIN_PATH).'vchamilo/lib.php';
global $_configuration;
@ -59,7 +59,7 @@ $wwwroot = $_configuration['root_web'];
//A simple select
$options = array(0 => $plugininstance->get_lang('no'), 1 => $plugininstance->get_lang('yes'));
$form->addlabel('', '<a href="'.api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php">'.
$form->addlabel('', '<a class="btn btn-primary" 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);

@ -112,8 +112,7 @@ if ($data->what == 'addinstance' || $data->what == 'registerinstance') {
ctrace("Making home dir as $homedir");
if (!is_dir($homedir)){
ctrace("Creating home dir");
if (!is_dir($homedir)) {
if (!mkdir($homedir, 0777, true)) {
ctrace("Error creating home dir $homedir \n");
}
@ -138,7 +137,6 @@ if ($data->what == 'addinstance' || $data->what == 'registerinstance') {
ctrace("Making archive dir as $archivedir ");
if (!is_dir($archivedir)) {
ctrace("Creating archive dir");
if (!mkdir($archivedir, 0777, true)) {
ctrace("Error creating archive dir $archivedir\n");
}
@ -170,17 +168,18 @@ if ($data->what == 'addinstance' || $data->what == 'registerinstance') {
vchamilo_load_files_from_template($data, $template);
}
ctrace("Fixing records");
// pluging in site name institution
$settingstable = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
$settingstable = $data->main_database.'.settings_current';
$accessurltable = $data->main_database.'.access_url';
$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' ";
$accessurltable = Database::get_main_table(TABLE_MAIN_ACCESS_URL);
$sqls[] = "UPDATE {$accessurltable} SET url = '{$data->root_web}' WHERE id = '1' ";
foreach ($sqls as $sql) {

@ -25,10 +25,6 @@ $thisurl = api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php';
$coursePath = vchamilo_get_config('vchamilo', 'course_real_root');
$homePath = vchamilo_get_config('vchamilo', 'home_real_root');
if (empty($coursePath) || empty($homePath)) {
api_not_allowed(true, 'You have to setup the course real root');
}
if ($id) {
$mode = 'update';
} else {

@ -57,31 +57,6 @@ abstract class ChamiloForm
return $this->_mode == 'add';
}
/**
* Use this method to a cancel and submit button to the end of your form. Pass a param of false
* if you don't want a cancel button in your form. If you have a cancel button make sure you
* check for it being pressed using is_cancelled() and redirecting if it is true before trying to
* get data with get_data().
*
* @param boolean $cancel whether to show cancel button, default true
* @param string $submitlabel label for submit button, defaults to get_string('savechanges')
*/
public function add_action_buttons($cancel = true, $submitlabel = null, $cancellabel = null)
{
// TODO : refine lang fetch to effective global strings.
if (is_null($submitlabel)) {
$submitlabel = get_lang('save');
}
if (is_null($cancellabel)) {
$submitlabel = get_lang('cancel');
}
$cform =& $this->_form;
$cform->addButtonSave($submitlabel, 'submitbutton');
}
/**
* Return submitted data if properly submitted or returns NULL if validation fails or
* if there is no submitted data.
@ -455,11 +430,9 @@ class InstanceForm extends ChamiloForm
}
}
$submitstr = $this->_plugin->get_lang('savechanges');
$this->add_action_buttons(true, $submitstr);
// Rules for the add mode.
$cform->addButtonSave($this->_plugin->get_lang('savechanges'), 'submitbutton');
// Rules
$cform->addRule('sitename', $this->_plugin->get_lang('sitenameinputerror'), 'required', null, 'client');
$cform->addRule(
'institution',

@ -8,6 +8,8 @@ if (!defined('CHAMILO_INTERNAL')) {
die('You cannot use this script this way');
}
$vidlist = isset($_REQUEST['vids']) ? implode("','", array_map('intval', $_REQUEST['vids'])) : '';
if ($action == 'newinstance' || $action == 'instance') {
$registeronly = $_REQUEST['registeronly'];
vchamilo_redirect(api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/editinstance.php?registeronly='.$registeronly);
@ -19,29 +21,32 @@ if ($action == 'editinstance' || $action == 'updateinstance') {
}
if ($action == 'deleteinstances' || $action == 'disableinstances') {
if (!empty($vidlist)) {
Display::addFlash(Display::return_message("Disabling instance"));
// Make it not visible.
Display::addFlash(Display::return_message("Disabling instance"));
// Make it not visible.
$vidlist = implode("','", $_REQUEST['vids']);
$sql = "UPDATE $table SET visible = 0 WHERE id IN ('$vidlist')";
Database::query($sql);
$sql = "UPDATE $table SET visible = 0 WHERE id IN ('$vidlist')";
Database::query($sql);
}
vchamilo_redirect(api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php');
}
if ($action == 'enableinstances') {
Display::addFlash(Display::return_message("Enabling instance"));
$vidlist = implode("','", $_REQUEST['vids']);
$sql = " UPDATE $table SET visible = 1 WHERE id IN ('$vidlist') ";
Database::query($sql);
if (!empty($vidlist)) {
Display::addFlash(Display::return_message("Enabling instance"));
$sql = " UPDATE $table SET visible = 1 WHERE id IN ('$vidlist') ";
Database::query($sql);
}
vchamilo_redirect(api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php');
}
if ($action == 'fulldeleteinstances') {
$todelete = [];
// Removes everything.
if (empty($automation)) {
$vidlist = implode("','", $_REQUEST['vids']);
$todelete = Database::select('*', 'vchamilo', array('where' => array("id IN ('$vidlist')" => array())));
if (!empty($vidlist)) {
$todelete = Database::select('*', 'vchamilo', array('where' => array("id IN ('$vidlist')" => array())));
}
} else {
$todelete = Database::select('*', 'vchamilo', array('where' => array("root_web = '{$n->root_web}' " => array())));
}
@ -49,19 +54,18 @@ if ($action == 'fulldeleteinstances') {
foreach ($todelete as $fooid => $instance) {
$slug = $instance['slug'];
Display::addFlash(Display::return_message("Removing instance: ".$instance->root_web));
Display::addFlash(Display::return_message("Removing instance: ".$instance['root_web']));
vchamilo_drop_databases($instance);
// Remove all files and eventual symlinks
$absalternatecourse = vchamilo_get_config('vchamilo', 'course_real_root');
$coursedir = $absalternatecourse.$slug;
Display::addFlash(Display::return_message("Deleting $coursedir"));
if ($absalternatehome = vchamilo_get_config('vchamilo', 'home_real_root')) {
$homedir = str_replace('//', '/', $absalternatehome.'/'.$slug);
$homedir = $absalternatehome.'/'.$slug;
Display::addFlash(Display::return_message("Deleting $homedir"));
removeDir($homedir);
@ -69,7 +73,7 @@ if ($action == 'fulldeleteinstances') {
// delete archive
if ($absalternatearchive = vchamilo_get_config('vchamilo', 'archive_real_root')) {
$archivedir = str_replace('//', '/', $absalternatearchive.'/'.$slug);
$archivedir = $absalternatearchive.'/'.$slug;
Display::addFlash(Display::return_message("Deleting $archivedir"));
removeDir($archivedir);
@ -260,12 +264,9 @@ if ($action == 'snapshotinstance') {
}
if ($action == 'clearcache') {
Display::addFlash(Display::return_message("Clearing cache"));
// Removes cache directory.
if (empty($automation)) {
if (array_key_exists('vids', $_REQUEST)) {
$vidlist = implode("','", $_REQUEST['vids']);
$toclear = Database::select('*', 'vchamilo', array('where' => array("id IN ('$vidlist')" => array())));
} else {
$vid = isset($_REQUEST['vid']) ? $_REQUEST['vid'] : 0;
@ -287,9 +288,8 @@ if ($action == 'clearcache') {
foreach ($toclear as $fooid => $instance) {
if ($fooid == 0) {
Display::addFlash(Display::return_message("Clearing master template cache"));
$templatepath = api_get_path(SYS_ARCHIVE_PATH).'twig';
Display::addFlash(Display::return_message("Deleting cache $templatepath \n"));
Display::addFlash(Display::return_message("Deleting master cache $templatepath \n"));
removeDir($templatepath);
} else {
$coursePath = vchamilo_get_config('vchamilo', 'course_real_root');
@ -302,7 +302,6 @@ if ($action == 'clearcache') {
Display::addFlash(Display::return_message("Deleting cache $templatepath \n"));
removeDir($templatepath);
}
}
}
@ -316,7 +315,6 @@ if ($action == 'setconfigvalue') {
}
$select .= '</select>';
$vidlist = isset($_REQUEST['vids']) ? implode("','", $_REQUEST['vids']) : '';
if (empty($vidlist)) {
api_not_allowed(true, 'No virtual chamilo selected');
}

@ -8,6 +8,8 @@ require_once api_get_path(SYS_PLUGIN_PATH).'vchamilo/lib/vchamilo_plugin.class.p
// security
api_protect_admin_script();
vchamilo_check_settings();
$action = isset($_GET['what']) ? $_GET['what'] : '';
define('CHAMILO_INTERNAL', true);

Loading…
Cancel
Save