WIP: Fix VChamilo plugin

ofaj
jmontoyaa 10 years ago
parent b024e8dd8d
commit acbba687ae
  1. 1
      main/inc/lib/api.lib.php
  2. 2
      plugin/vchamilo/install.php
  3. 30
      plugin/vchamilo/lib.php
  4. 23
      plugin/vchamilo/lib/vchamilo_plugin.class.php
  5. 58
      plugin/vchamilo/views/editinstance.controller.php
  6. 5
      plugin/vchamilo/views/editinstance.php
  7. 26
      plugin/vchamilo/views/editinstance_form.php
  8. 36
      plugin/vchamilo/views/manage.controller.php
  9. 1
      plugin/vchamilo/views/manage.php
  10. 13
      plugin/vchamilo/views/manage.testcnx.php
  11. 15
      plugin/vchamilo/views/manage.testdatapath.php

@ -714,7 +714,6 @@ function api_get_path($path = '', $configuration = [])
$configuration['code_append'] = 'main';
// Web server base and system server base.
if (!array_key_exists($root_web, $isInitialized)) {
// process absolute global roots
if (!empty($configuration)) {

@ -31,7 +31,7 @@ $sql = "CREATE TABLE IF NOT EXISTS $tablename (
`visible` int(1),
`lastcrongap` int(11),
`lastcron` int(11),
`croncount` int(11)
`croncount` int(11),
PRIMARY KEY (`id`)
) DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
";

@ -14,10 +14,12 @@ function vchamilo_hook_configuration(&$_configuration)
// provides an effective value for the virtual root_web based on domain analysis
vchamilo_get_hostname($_configuration);
$plugin = VChamiloPlugin::create();
//$plugin = VChamiloPlugin::create();
// We are on physical chamilo. Let original config play
if ($_configuration['root_web'] == $_configuration['vchamilo_web_root'].'/'){
$virtualChamiloWebRoot = $_configuration['vchamilo_web_root'].'/';
if ($_configuration['root_web'] == $virtualChamiloWebRoot){
$VCHAMILO = 'main';
return;
}
@ -28,26 +30,20 @@ function vchamilo_hook_configuration(&$_configuration)
$connection = vchamilo_boot_connection($_configuration);
$table = 'vchamilo';
$query = "
SELECT * FROM $table WHERE root_web = '{$_configuration['vchamilo_web_root']}'
";
$query = "SELECT * FROM $table WHERE root_web = '$virtualChamiloWebRoot'";
$result = $connection->executeQuery($query);
$excludes = array('id', 'name');
if ($result->rowCount()) {
$data = $result->fetchAll();
$data = $result->fetch();
foreach($data as $key => $value){
foreach ($data as $key => $value){
if (!in_array($key, $excludes)){
$_configuration[$key] = $value;
}
// take first domain fragment as radical
$arr = preg_replace('#https?://#', '', $_configuration['vchamilo_name']);
$domain = explode('.', $arr);
$vchamilo_radical = array_shift($domain);
$VCHAMILO = $vchamilo_radical;
$_configuration['virtual'] = $data['root_web'].'/';
$VCHAMILO = $data['root_web'];
}
} else {
//die ("VChamilo : No configuration for this host. May be faked.");
@ -56,9 +52,8 @@ function vchamilo_hook_configuration(&$_configuration)
}
/**
*
*
*/
* @param array $_configuration
*/
function vchamilo_get_hostname(&$_configuration)
{
if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) &&
@ -108,7 +103,7 @@ function vchamilo_boot_connection(&$_configuration)
'host' => $_configuration['db_host'],
'user' => $_configuration['db_user'],
'password' => $_configuration['db_password'],
'dbname' => $_configuration['main_database'],
'dbname' => isset($_configuration['main_database']) ? $_configuration['main_database'] : '',
// Only relevant for pdo_sqlite, specifies the path to the SQLite database.
'path' => isset($_configuration['db_path']) ? $_configuration['db_path'] : '',
// Only relevant for pdo_mysql, pdo_pgsql, and pdo_oci/oci8,
@ -131,6 +126,7 @@ function vchamilo_redirect($url) {
} else {
header('location: ' . api_get_path(WEB_PATH).$url);
}
exit;
}
function vchamilo_get_htaccess_fragment($course_folder)

@ -14,28 +14,36 @@ require_once vchamilo_boot_api_get_path($_configuration) . 'plugin.class.php';
*/
class VChamiloPlugin extends Plugin
{
/**
* VChamiloPlugin constructor.
*/
public function __construct()
{
parent::__construct('1.2', 'Valery Fremaux, Julio Montoya');
}
/**
*
* @return VChamiloPlugin
*/
static function create()
public static function create()
{
static $result = null;
return $result ? $result : $result = new self();
}
function get_name()
public function get_name()
{
return 'vchamilo';
}
protected function __construct()
/**
* @param $pixname
* @param int $size
* @return string
*/
public function pix_url($pixname, $size = 16)
{
parent::__construct('1.1', 'Valery Fremaux');
}
function pix_url($pixname, $size = 16){
global $_configuration;
if (file_exists($_configuration['root_sys'].'/plugin/vchamilo/pix/'.$pixname.'.png')){
@ -49,6 +57,5 @@ class VChamiloPlugin extends Plugin
}
return $_configuration['root_web'].'/main/img/icons/'.$size.'/'.$pixname.'.png';
}
}

@ -13,6 +13,8 @@ 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;
@ -48,7 +50,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)){
if (!empty($absalternatecourse)) {
// this is the relocated case
$coursedir = str_replace('//', '/', $absalternatecourse.'/'.$data->course_folder);
} else {
@ -77,7 +79,6 @@ if ($data->what == 'addinstance' || $data->what == 'registerinstance') {
// The standard location dir SHOULD NOT EXIST YET
assert(!is_dir($standardlocation));
ctrace("Linking virtual coursedir ");
chdir(dirname($standardlocation));
if (!symlink($coursedir, basename($coursedir))) {
@ -96,22 +97,10 @@ if ($data->what == 'addinstance' || $data->what == 'registerinstance') {
*
*/
preg_match('#https?://([^\.]+)#', $data->root_web, $matches);
$home_folder = $matches[1];
$archive_folder = $matches[1]; // prepare it now but use it later
if ($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);
} else {
// homedir is the home container at install level. This may contains
// in reality home subdirs from branding suburls.
// In straight installs, this should be located as a hostname subrouted
// dir in home dir of the chamilo install.
// In delocated installs (clustered installations), the root 'home' directory
// may be a symbolic link to a delocated path.
$homedir = api_get_path(SYS_PATH).'home/'.$home_folder;
}
$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);
ctrace("Making home dir as $homedir ");
@ -137,9 +126,10 @@ if ($data->what == 'addinstance' || $data->what == 'registerinstance') {
*/
// create archive
if($absalternatearchive = vchamilo_get_config('vchamilo', 'archive_real_root')){
$archivedir = str_replace('//', '/', $absalternatearchive.'/'.$archive_folder);
} else {
$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;
}
@ -168,11 +158,10 @@ if ($data->what == 'addinstance' || $data->what == 'registerinstance') {
if (!$template) {
// Create empty database for install
ctrace("Creating databases (empty) ");
ctrace("Creating databases (empty)");
vchamilo_create_databases($data);
} else {
// deploy template database
// Deploy template database
ctrace("Creating databases from template $template ");
vchamilo_create_databases($data);
ctrace("Loading data template $template ");
@ -185,24 +174,22 @@ if ($data->what == 'addinstance' || $data->what == 'registerinstance') {
// pluging in site name institution
$settingstable = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
$sitename = str_replace("'", "''", $data->sitename);
$institution = str_replace("'", "''", $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' ";
$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' ";
$sqls[] = "UPDATE {$accessurltable} SET url = '{$data->root_web}' WHERE id = '1' ";
foreach ($sqls as $sql) {
Database::query($sql);
}
ctrace("Finished. ");
ctrace("Finished");
//if (!$automation) {
echo '<a href="'.api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php'.'">Continue</a>';
// vchamilo_redirect(api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php');
die;
//}
echo '<a class="btn btn-primary" href="'.api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php'.'">Continue</a>';
// vchamilo_redirect(api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php');
die;
}
if ($data->what == 'updateinstance') {
@ -221,5 +208,6 @@ if ($data->what == 'updateinstance') {
unset($data->vid);
Database::update('vchamilo', (array) $data, array('id = ?' => $id), true);
Display::addFlash(Display::return_message(get_lang('Updated')));
vchamilo_redirect(api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php');
}

@ -1,5 +1,6 @@
<?php
$cidReset = true;
define('CHAMILO_INTERNAL', true);
global $plugininstance;
@ -53,7 +54,9 @@ if ($id) {
$content = $form->return_form();
$tpl = new Template(get_lang('VChamilo'), true, true, false, true, false);
$interbreadcrumb[] = array('url' => 'manage.php', 'name' => get_lang('VChamilo'));
$tpl = new Template(get_lang('Instances'), true, true, false, true, false);
$tpl->assign('actions', $actions);
$tpl->assign('message', $message);
$tpl->assign('content', $content);

@ -78,15 +78,8 @@ abstract class ChamiloForm
}
$cform =& $this->_form;
if ($cancel) {
//when two elements we need a group
$buttonarray = array();
$buttonarray[] = &$cform->createElement('submit', 'submitbutton', $submitlabel);
$cform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
} else {
//no group needed
$cform->addElement('submit', 'submitbutton', $submitlabel);
}
$cform->addButtonSave($submitlabel, 'submitbutton');
}
/**
@ -374,9 +367,6 @@ class InstanceForm extends ChamiloForm
$cform = $this->_form;
// Settings variables.
$size_input_text_big = 'size="60"';
/*
* Host's id.
*/
@ -439,15 +429,13 @@ class InstanceForm extends ChamiloForm
// Db's prefix.
$cform->addElement('text', 'db_prefix', $this->_plugin->get_lang('dbprefix'));
$cform->addElement('header', $this->_plugin->get_lang('datalocation'));
// Path for "moodledata".
$cform->addElement(
'text',
'course_folder',
$this->_plugin->get_lang('coursefolder'),
array('size' => $size_input_text_big, 'id' => 'id_vdatapath')
array('id' => 'id_vdatapath')
);
// Button for testing database connection.
@ -455,6 +443,10 @@ class InstanceForm extends ChamiloForm
'button',
'testconnection',
$this->_plugin->get_lang('testconnection'),
'check',
'default',
'default',
'',
'onclick="opencnxpopup(\''.$_configuration['root_web'].'\'); return false;"'
);
@ -463,6 +455,10 @@ class InstanceForm extends ChamiloForm
'button',
'testdatapath',
$this->_plugin->get_lang('testdatapath'),
'check',
'default',
'default',
'',
'onclick="opendatapathpopup(\''.$_configuration['root_web'].'\'); return true;"'
);

@ -63,8 +63,7 @@ if ($action == 'fulldeleteinstances') {
foreach ($todelete as $fooid => $instance) {
echo "<pre>";
echo ("Dropping instance databases \n");
Display::addFlash(Display::return_message("Dropping instance databases"));
vchamilo_drop_databases($instance);
// Remove all files and eventual symlinks
@ -79,7 +78,7 @@ if ($action == 'fulldeleteinstances') {
}
$standardlocation = str_replace('//', '/', $_configuration['root_sys'].'/'.$instance->course_folder); // where it should be
echo ("Deleting $coursedir \n");
Display::addFlash(Display::return_message("Deleting $coursedir"));
removeDir($coursedir);
if (is_link($standardlocation)) {
unlink($standardlocation);
@ -96,7 +95,7 @@ if ($action == 'fulldeleteinstances') {
}
$standardlocation = $_configuration['root_sys'].'home/'.$home_folder; // where it should be
echo ("Deleting $homedir \n");
Display::addFlash(Display::return_message("Deleting $homedir"));
removeDir($homedir);
if (is_link($standardlocation)) {
unlink($standardlocation);
@ -110,27 +109,22 @@ if ($action == 'fulldeleteinstances') {
}
$standardlocation = $_configuration['root_sys'].'archive/'.$archive_folder; // where it should be
echo ("Deleting $archivedir \n");
Display::addFlash(Display::return_message("Deleting $archivedir"));
removeDir($archivedir);
if (is_link($standardlocation)) {
unlink($standardlocation);
}
echo '</pre>';
echo ("Removing vchamilo record \n");
$sql = "
DELETE FROM
{$table}
WHERE
id = {$instance->id}
";
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'));
$vid = isset($_REQUEST['vid']) ? $_REQUEST['vid'] : '';
if ($vid) {
@ -181,11 +175,11 @@ if ($action == 'snapshotinstance') {
$content .= '<input type="hidden" name="what" value="snapshotinstance" />';
$content .= '<input type="hidden" name="vid" value="'.$vhost->id.'" />';
$content .= '<input type="hidden" name="step" value="1" />';
$content .= '<input type="submit" name="go_btn" value="'.$plugininstance->get_lang('continue').'" />';
$content .= '<input type="submit" class="btn btn-primary" name="go_btn" value="'.$plugininstance->get_lang('continue').'" />';
$content .= '</form>';
$content .= '</div>';
$tpl = new Template(get_lang('VChamilo'), true, true, false, true, false);
$tpl = new Template(get_lang('Snapshot'), true, true, false, true, false);
$tpl->assign('actions', '');
$tpl->assign('message', $plugininstance->get_lang('vchamilosnapshot1'));
$tpl->assign('content', $content);
@ -237,11 +231,11 @@ if ($action == 'snapshotinstance') {
$content .= '<input type="hidden" name="what" value="snapshotinstance" />';
$content .= '<input type="hidden" name="vid" value="'.$vhost->id.'" />';
$content .= '<input type="hidden" name="step" value="2" />';
$content .= '<input type="submit" name="go_btn" value="'.$plugininstance->get_lang('continue').'" />';
$content .= '<input class="btn btn-primary" type="submit" name="go_btn" value="'.$plugininstance->get_lang('continue').'" />';
$content .= '</form>';
}
$tpl = new Template(get_lang('VChamilo'), true, true, false, true, false);
$tpl = new Template(get_lang('Snapshot'), true, true, false, true, false);
$tpl->assign('actions', '');
$tpl->assign('message', $message);
$tpl->assign('content', $content);
@ -269,15 +263,15 @@ if ($action == 'snapshotinstance') {
fclose($FILE);
// Every step was SUCCESS.
if (empty($fullautomation)){
Display::addFlash($plugininstance->get_lang('successfinishedcapture'));
if (empty($fullautomation)) {
Display::addFlash(Display::return_message($plugininstance->get_lang('successfinishedcapture'), 'success'));
$actionurl = $_configuration['root_web'].'/plugin/vchamilo/views/manage.php';
$content .= '<form name"single" action="'.$actionurl.'">';
$content .= '<input type="submit" name="go_btn" value="'.$plugininstance->get_lang('backtoindex').'" />';
$content .= '<input class="btn btn-primary" type="submit" name="go_btn" value="'.$plugininstance->get_lang('backtoindex').'" />';
$content .= '</form>';
$tpl = new Template(get_lang('VChamilo'), true, true, false, true, false);
$tpl = new Template(get_lang('Snapshot'), true, true, false, true, false);
$tpl->assign('actions', '');
$tpl->assign('message', $plugininstance->get_lang('vchamilosnapshot3'));
$tpl->assign('content', $content);

@ -1,5 +1,6 @@
<?php
$cidReset = true;
require_once '../../../main/inc/global.inc.php';
require_once api_get_path(SYS_PLUGIN_PATH).'vchamilo/lib.php';
require_once api_get_path(SYS_PLUGIN_PATH).'vchamilo/lib/vchamilo_plugin.class.php';

@ -8,19 +8,18 @@
*/
// Loading configuration.
require_once('../../../main/inc/global.inc.php');
require_once($_configuration['root_sys'].'/local/classes/mootochamlib.php');
require_once($_configuration['root_sys'].'/local/classes/database.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 '../../../main/inc/global.inc.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';
$plugininstance = VChamiloPlugin::create();
// Retrieve parameters for database connection test.
$database = array();
$database['db_host'] = $_REQUEST['vdbhost'];
$database['db_user'] = $_REQUEST['vdblogin'];
$database['db_host'] = $_REQUEST['vdbhost'];
$database['db_user'] = $_REQUEST['vdblogin'];
$database['db_password'] = $_REQUEST['vdbpass'];
$database['root_sys'] = api_get_path(SYS_PATH);
// Works, but need to improve the style...
if (vchamilo_boot_connection($database, false)) {

@ -8,14 +8,9 @@
*/
// Loading configuration.
require_once('../../../main/inc/global.inc.php');
require_once($_configuration['root_sys'].'/local/classes/mootochamlib.php');
require_once($_configuration['root_sys'].'/local/classes/database.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 $DB;
$DB = new DatabaseManager();
require_once '../../../main/inc/global.inc.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';
$plugininstance = VChamiloPlugin::create();
@ -49,7 +44,7 @@ if (is_dir($coursedir)) {
}
echo stripslashes($coursedir);
} else {
if (mkdir($coursedir, 02777, true)) {
if (@mkdir($coursedir, 02777, true)) {
echo '<div class="success">'.$plugininstance->get_lang('datapathcreated').'</div>';
} else {
echo '<div class="error">'.$plugininstance->get_lang('couldnotcreatedataroot').'</div>';
@ -61,5 +56,5 @@ echo "</p>";
$closestr = $plugininstance->get_lang('closewindow');
echo "<center>";
echo "<input type=\"button\" name=\"close\" value=\"$closestr\" onclick=\"self.close();\" />";
echo "<input class='btn' type=\"button\" name=\"close\" value=\"$closestr\" onclick=\"self.close();\" />";
echo "</center>";

Loading…
Cancel
Save