WIP: Fix VChamilo plugin

ofaj
jmontoyaa 10 years ago
parent 557a618dad
commit 06f9976740
  1. 30
      main/inc/lib/api.lib.php
  2. 8
      main/inc/lib/database.lib.php
  3. 11
      plugin/vchamilo/ajax/service.php
  4. 3
      plugin/vchamilo/install.php
  5. 4
      plugin/vchamilo/js/host_form.js
  6. 157
      plugin/vchamilo/lib.php
  7. 2
      plugin/vchamilo/lib/bootlib.php
  8. 23
      plugin/vchamilo/views/editinstance.controller.php
  9. 13
      plugin/vchamilo/views/editinstance.php
  10. 188
      plugin/vchamilo/views/editinstance_form.php
  11. 79
      plugin/vchamilo/views/manage.controller.php
  12. 38
      plugin/vchamilo/views/manage.php
  13. 101
      plugin/vchamilo/views/syncparams.controller.php
  14. 38
      plugin/vchamilo/views/syncparams.php

@ -615,6 +615,8 @@ function api_get_path($path = '', $configuration = [])
}
$course_folder = 'courses/';
$root_sys = $_configuration['root_sys'];
// Resolve master hostname.
if (!empty($configuration) && array_key_exists('root_web', $configuration)) {
$root_web = $configuration['root_web'];
@ -694,11 +696,6 @@ function api_get_path($path = '', $configuration = [])
//static $isInitialized = [];
$isInitialized = [];
// Configuration data for all installed systems is unique.
if (empty($root_sys)) {
$root_sys = $configuration['root_sys'];
}
$loadNewConfig = false;
// To avoid that the api_get_access_url() function fails since global.inc.php also calls the main_api.lib.php
@ -711,25 +708,15 @@ function api_get_path($path = '', $configuration = [])
}
}
if (isset($configuration['course_folder'])) {
$course_folder = $configuration['course_folder'];
}
$configuration['code_append'] = isset($configuration['code_append']) ? $configuration['code_append'] : 'main';
$course_folder = isset($configuration['course_folder']) ? $configuration['course_folder'] : $course_folder;
$root_rel = isset($configuration['url_append']) ? $configuration['url_append'] : '';
if (preg_match('#https?://([^\.]+)#', $root_web, $matches)) {
$web_host = $matches[1];
} else {
die('malformed root_web url');
}
$configuration['code_append'] = 'main';
// Web server base and system server base.
$root_rel = isset($configuration['url_append']) ? $configuration['url_append'] : '';
$server_base_sys = preg_replace('@'.$root_rel.'$@', '', $root_sys); // No trailing slash.
if (!array_key_exists($root_web, $isInitialized)) {
// process absolute global roots
//$root_rel = $configuration['url_append'];
if (!empty($configuration)) {
$code_folder = $configuration['code_append'];
} else {
@ -846,13 +833,6 @@ function api_get_path($path = '', $configuration = [])
}
// Replacement of the present web server base with a slash '/'.
$path = preg_replace(VALID_WEB_SERVER_BASE, '/', $path);
} elseif (strpos($path, $server_base_sys) === 0) {
$path = preg_replace('@^'.$server_base_sys.'@', '', $path);
} elseif (strpos($path, '/') === 0) {
// Leading slash - we assume that this path is semi-absolute (REL),
// then path is left without furthes modifications.
} else {
return null; // Probably implementation of this case won't be needed.
}
// Path now is semi-absolute. It is convenient at this moment repeated slashes to be removed.

@ -127,8 +127,10 @@ class Database
* @param string $entityRootPath
*
* @throws \Doctrine\ORM\ORMException
*
* @return
*/
public function connect($params = array(), $sysPath = '', $entityRootPath = '')
public function connect($params = array(), $sysPath = '', $entityRootPath = '', $returnConnection = false)
{
$config = self::getDoctrineConfig($entityRootPath);
$config->setAutoGenerateProxyClasses(true);
@ -175,6 +177,10 @@ class Database
$listener = new \Gedmo\Sortable\SortableListener();
$entityManager->getEventManager()->addEventSubscriber($listener);
$connection = $entityManager->getConnection();
if ($returnConnection) {
return $connection;
}
$this->setConnection($connection);
$this->setManager($entityManager);

@ -1,14 +1,9 @@
<?php
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 '../../../main/inc/global.inc.php';
require_once api_get_path(SYS_PLUGIN_PATH).'vchamilo/lib/vchamilo_plugin.class.php';
global $DB;
$DB = new DatabaseManager();
$action = $_GET['what'];
$action = isset($_GET['what']) ? $_GET['what'] : '';
define('CHAMILO_INTERNAL', true);
$plugininstance = VChamiloPlugin::create();

@ -31,8 +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 ;
";

@ -2,7 +2,6 @@
* Pop-up testing connection with database.
*/
function opencnxpopup(webroot) {
// Inputted data.
var dbhost = document.getElementById('id_vdbhost').value;
var dblogin = document.getElementById('id_vdbuser').value;
@ -11,14 +10,11 @@ function opencnxpopup(webroot) {
// PHP file linked the pop-up, and name.
var url = webroot+"/plugin/vchamilo/views/manage.testcnx.php" + "?" + "vdbhost=" + dbhost + "&" + "vdblogin=" + dblogin
+ "&" + "vdbpass=" + dbpass;
// Pop-up's options.
var options = "width=500,height=300,toolbar=no,menubar=no,location=no,scrollbars=no,status=no";
// Opening the pop-up (title not working in Firefox).
var windowobj = window.open(url, '', options);
// Needed to be valid in IE.
// windowobj.document.title = vchamilo_testconnection;
}
/**

@ -24,35 +24,33 @@ function vchamilo_hook_configuration(&$_configuration)
// pre hook to chamilo main table and get alternate configuration.
// sure Database object is not set up. Soo use bootstrap connection
$side_cnx = vchamilo_boot_connection($_configuration, 'main');
/** @var \Doctrine\DBAL\Connection $connection */
$connection = vchamilo_boot_connection($_configuration);
$table = 'vchamilo';
$query = "
SELECT * FROM $table WHERE root_web = '{$_configuration['vchamilo_web_root']}'
";
$result = $connection->executeQuery($query);
$excludes = array('id', 'name');
$res = mysql_query($query, $side_cnx);
if ($res) {
if (mysql_num_rows($res)) {
$vchamilo = mysql_fetch_assoc($res);
foreach($vchamilo as $key => $value){
if (!in_array($key, $excludes)){
$_configuration[$key] = $value;
}
if ($result->rowCount()) {
$data = $result->fetchAll();
// take first domain fragment as radical
$arr = preg_replace('#https?://#', '', $_configuration['vchamilo_name']);
$domain = explode('.', $arr);
$vchamilo_radical = array_shift($domain);
$VCHAMILO = $vchamilo_radical;
foreach($data as $key => $value){
if (!in_array($key, $excludes)){
$_configuration[$key] = $value;
}
} else {
die ("VChamilo : No configuration for this host. May be faked.");
// take first domain fragment as radical
$arr = preg_replace('#https?://#', '', $_configuration['vchamilo_name']);
$domain = explode('.', $arr);
$vchamilo_radical = array_shift($domain);
$VCHAMILO = $vchamilo_radical;
}
} else {
//die ("VChamilo : No configuration for this host. May be faked.");
die ("VChamilo : Could not fetch virtual chamilo configuration");
}
}
@ -103,35 +101,28 @@ function vchamilo_get_hostname(&$_configuration)
* @param array $vchamilo
* @return a connection
*/
function vchamilo_boot_connection(&$_configuration, $binddb = false)
function vchamilo_boot_connection(&$_configuration)
{
// Important : force new link here
$mysql_side_cnx = mysql_connect(
$_configuration['db_host'],
$_configuration['db_user'],
$_configuration['db_password'],
true
$dbParams = array(
'driver' => 'pdo_mysql',
'host' => $_configuration['db_host'],
'user' => $_configuration['db_user'],
'password' => $_configuration['db_password'],
'dbname' => $_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,
'port' => isset($_configuration['db_port']) ? $_configuration['db_port'] : ''
);
if (!$mysql_side_cnx) {
// echo('Side connection failure with '.$_configuration['db_host'].', '.$_configuration['db_user'].', '.$_configuration['db_password']);
try {
$database = new \Database();
$connection = $database->connect($dbParams, $_configuration['root_sys'], $_configuration['root_sys'], true);
} catch (Exception $e) {
echo('Side connection failure with '.$_configuration['db_host'].', '.$_configuration['db_user'].', ******** ');
return false;
die();
}
mysql_set_charset('utf8', $mysql_side_cnx);
if (!empty($binddb)) {
if (!in_array($binddb, array('main'), true)) {
echo('Not a chamilo database. should be one of "main", "statistics" or "user_personal"');
mysql_close($mysql_side_cnx);
return false;
}
if (!mysql_select_db($_configuration[$binddb.'_database'], $mysql_side_cnx)) {
echo("vchamilo_make_connection : Database not found<br/>");
mysql_close($mysql_side_cnx);
return false;
}
}
return $mysql_side_cnx;
return $connection;
}
function vchamilo_redirect($url) {
@ -254,7 +245,7 @@ function vchamilo_create_databases($vchamilo, $cnx = null)
}
foreach($dbs as $adb){
ctrace("Creating DB $adb ");
Display::addFlash(Display::return_message("Creating DB $adb"));
$sql = str_replace('%DATABASE%', $adb, $createstatement);
Database::query($sql);
/*if(!$DB->execute_sql($sql)){
@ -278,18 +269,18 @@ function vchamilo_get_database_dump_cmd($vchamilodata)
$pgm = vchamilo_get_config('mysql_cmd');
// Checks the needed program.
ctrace("load_database_from_dump : checking database command");
if(!$pgm){
Display::addFlash(Display::return_message("load_database_from_dump : checking database command"));
if (!$pgm){
$pgm = '/usr/bin/mysql';
ctrace("Using default database command $pgm ");
Display::addFlash(Display::return_message("Using default database command $pgm "));
}
$phppgm = str_replace("\\", '/', $pgm);
$phppgm = str_replace("\"", '', $phppgm);
$pgm = str_replace("/", DIRECTORY_SEPARATOR, $pgm);
ctrace('load_database_from_dump : checking command is available');
if(!is_executable($phppgm)){
Display::addFlash(Display::return_message('load_database_from_dump : checking command is available'));
if (!is_executable($phppgm)){
print_error('databasecommanddoesnotmatchanexecutablefile');
return false;
}
@ -326,7 +317,7 @@ function vchamilo_load_db_template($vchamilo, $dbtemplate, $template){
$filerad = preg_replace('/_database$/', '', $dbtemplate);
$sqlfile = 'chamilo_master_'.$filerad.'.sql';
if(!$sqlcmd = vchamilo_get_database_dump_cmd($vchamilo)){
if (!$sqlcmd = vchamilo_get_database_dump_cmd($vchamilo)){
return false;
}
@ -336,7 +327,7 @@ function vchamilo_load_db_template($vchamilo, $dbtemplate, $template){
$import = $sqlcmd.$absolute_datadir.'/'.$sqlfile;
// Execute the command.
ctrace("load_database_from_dump : executing feeding sql as \n $import ");
Display::addFlash(Display::return_message("load_database_from_dump : executing feeding sql as \n $import "));
if (!defined('CLI_SCRIPT')){
putenv('LANG=en_US.utf-8');
@ -346,7 +337,8 @@ function vchamilo_load_db_template($vchamilo, $dbtemplate, $template){
exec($import, $output, $return);
ctrace(implode("\n", $output)."\n");
Display::addFlash(Display::return_message(implode("\n", $output)."\n"));
return true;
}
@ -439,7 +431,8 @@ function vchamilo_execute_db_sql(&$vchamilo, $bulkfile, $cnx = null, $vars=null,
* @param $outputfilerad string The output SQL file radical.
* @return bool If TRUE, dumping database was a success, otherwise FALSE.
*/
function vchamilo_dump_databases($vchamilo, $outputfilerad){
function vchamilo_dump_databases($vchamilo, $outputfilerad)
{
global $CFG;
// Separating host and port, if sticked.
@ -453,7 +446,7 @@ function vchamilo_dump_databases($vchamilo, $outputfilerad){
$pass = '';
$pgm = null;
if (empty($port)){
if (empty($port)) {
$port = 3306;
}
@ -464,7 +457,8 @@ function vchamilo_dump_databases($vchamilo, $outputfilerad){
// Making the commands for each database.
$cmds = array();
if ($CFG->ostype == 'WINDOWS'){
//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';
@ -481,25 +475,17 @@ function vchamilo_dump_databases($vchamilo, $outputfilerad){
} else {
$cmd_main = "-h{$host} -P{$port} -u{$vchamilo->db_user} {$pass} {$vchamilo->main_database}";
$cmds[] = $cmd_main . ' > ' . escapeshellarg($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 . ' > ' . escapeshellarg($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 . ' > ' . escapeshellarg($outputfilerad.'_user_personal.sql');
}
}
$mysqldumpcmd = vchamilo_get_config('vchamilo', 'cmd_mysqldump', true);
$pgm = (!empty($mysqldumpcmd)) ? stripslashes($mysqldumpcmd) : false ;
$pgm = !empty($mysqldumpcmd) ? stripslashes($mysqldumpcmd) : false ;
if(!$pgm){
if (!$pgm) {
$erroritem = new StdClass();
$erroritem->message = "Database dump command not available";
$erroritem->message = "Database dump command not available check here: ";
$url = api_get_path(WEB_CODE_PATH).'admin/configure_plugin.php?name=vchamilo';
$erroritem->message .= Display::url($url, $url);
return array($erroritem);
} else {
$phppgm = str_replace("\\", '/', $pgm);
@ -517,8 +503,6 @@ function vchamilo_dump_databases($vchamilo, $outputfilerad){
// Final command.
$cmd = $pgm.' '.$cmd;
// ctrace($cmd); // Be carefull there, this could divulgate DB password
// Prints log messages in the page and in 'cmd.log'.
if ($LOG = fopen(dirname($outputfilerad).'/cmd.log', 'a')){
fwrite($LOG, $cmd."\n");
@ -558,16 +542,14 @@ function vchamilo_make_this()
{
global $_configuration;
$thischamilo->root_web = $_configuration['root_web'];
$thisPortal = new stdClass();
$thisPortal->root_web = $_configuration['root_web'];
$thisPortal->db_host = $_configuration['db_host'];
$thisPortal->db_user = $_configuration['db_user'];
$thisPortal->db_password = $_configuration['db_password'];
$thisPortal->main_database = $_configuration['main_database'];
$thischamilo->db_host = $_configuration['db_host'];
$thischamilo->db_user = $_configuration['db_user'];
$thischamilo->db_password = $_configuration['db_password'];
$thischamilo->db_prefix = $_configuration['db_prefix'];
$thischamilo->main_database = $_configuration['main_database']; ;
$thischamilo->table_prefix = $_configuration['table_prefix'];
return $thischamilo;
return $thisPortal;
}
/**
@ -585,7 +567,7 @@ function vchamilo_get_available_templates()
$absolute_templatesdir = $_configuration['root_sys'].$templatefoldername;
// Scans the templates.
if(!is_dir($absolute_templatesdir)){
if (!is_dir($absolute_templatesdir)){
mkdir($absolute_templatesdir, 0777, true);
}
$dirs = glob($absolute_templatesdir.'/*');
@ -604,8 +586,8 @@ function vchamilo_get_available_templates()
return $templatesarray;
}
function vchamilo_print_error($errortrace, $return = false){
function vchamilo_print_error($errortrace, $return = false)
{
$str = '';
if (!empty($errortrace)){
$str .= '<div class="vchamilo-errors" style="border:1px solid #a0a0a0;background-color:#ffa0a0;padding:5px;font-size:10px">';
@ -619,7 +601,7 @@ function vchamilo_print_error($errortrace, $return = false){
}
if ($return) return $str;
echo $str;
Display::addFlash(Display::return_message($str));
}
/**
@ -639,6 +621,7 @@ function vchamilo_get_config($module, $key, $isplugin = true)
if ($result) {
return $result['selected_value'];
}
return false;
}
@ -670,9 +653,9 @@ function vchamilo_load_files_from_template($vchamilo, $template)
$originarchivedir = preg_replace('/https?:\/\//', '', $manifest->templatewwwroot);
$originhomedir = preg_replace('/https?:\/\//', '', $manifest->templatewwwroot);
ctrace("Copying {$absolute_template_datadir}/{$manifest->coursefolder} => $vcoursepath");
ctrace("Copying {$absolute_template_datadir}/archive/{$originarchivedir} => $varchivepath");
ctrace("Copying {$absolute_template_datadir}/home/{$originhomedir} => $vhomepath");
Display::addFlash(Display::return_message("Copying {$absolute_template_datadir}/{$manifest->coursefolder} => $vcoursepath"));
Display::addFlash(Display::return_message("Copying {$absolute_template_datadir}/archive/{$originarchivedir} => $varchivepath"));
Display::addFlash(Display::return_message("Copying {$absolute_template_datadir}/home/{$originhomedir} => $vhomepath"));
copyDirContentTo(chop_last_slash($absolute_template_datadir.'/'.$manifest->coursefolder), chop_last_slash($vcoursepath), false);
copyDirContentTo(chop_last_slash($absolute_template_datadir.'/archive/'.$originarchivedir), chop_last_slash($varchivepath), false);
@ -764,8 +747,8 @@ function get_config($module, $key = false, $isplugin = true) {
return $dyna_setting;
}
if(empty($config)){
ctrace("Wrap to static setting $module,$configkey ");
if (empty($config)) {
Display::addFlash(Display::return_message("Wrap to static setting $module,$configkey "));
if (array_key_exists($key, $static_settings)){
return $static_settings[$key];
}
@ -927,7 +910,7 @@ function mtrace($message){
function ctrace($str) {
if (!defined('CLI_SCRIPT')) echo "<pre>";
echo $str;
Display::addFlash(Display::return_message($str));
if (!defined('CLI_SCRIPT')) echo "</pre>";
}

@ -1,5 +1,5 @@
<?php
function vchamilo_boot_api_get_path(&$_configuration){
function vchamilo_boot_api_get_path(&$_configuration) {
return $_configuration['root_sys'].'main/inc/lib/';
}

@ -1,6 +1,6 @@
<?php
require_once(api_get_path(LIBRARY_PATH).'fileManage.lib.php');
require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
if (!defined('CHAMILO_INTERNAL')) die('You cannot use this script this way');
@ -117,7 +117,7 @@ if ($data->what == 'addinstance' || $data->what == 'registerinstance') {
if (!is_dir($homedir)){
ctrace("Creating home dir ");
if (!mkdir($homedir, 0777, true)){
if (!mkdir($homedir, 0777, true)) {
ctrace("Error creating home dir $homedir \n");
}
}
@ -147,7 +147,7 @@ if ($data->what == 'addinstance' || $data->what == 'registerinstance') {
if (!is_dir($archivedir)) {
ctrace("Creating archive dir ");
if(!mkdir($archivedir, 0777, true)) {
if (!mkdir($archivedir, 0777, true)) {
ctrace("Error creating archive dir $archivedir\n");
}
}
@ -183,9 +183,6 @@ if ($data->what == 'addinstance' || $data->what == 'registerinstance') {
ctrace("Fixing records");
// Builds a new database manager on new instance to operate records
// $NDB = new DatabaseManager($data);
// pluging in site name institution
$settingstable = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
$sitename = str_replace("'", "''", $data->sitename);
@ -201,11 +198,11 @@ if ($data->what == 'addinstance' || $data->what == 'registerinstance') {
ctrace("Finished. ");
if (!$automation) {
//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;
}
//}
}
if ($data->what == 'updateinstance') {
@ -217,12 +214,12 @@ if ($data->what == 'updateinstance') {
$data->lastcron = 0;
$data->lastcrongap = 0;
$data->croncount = 0;
$data->id = $data->vid;
$id = $data->vid;
unset($data->vid);
unset($data->testconnection);
unset($data->testdatapath);
unset($data->vid);
if (!$DB->update_record('vchamilo', $data, 'id')) {
error_log('Vchamilo update error');
}
Database::update('vchamilo', (array) $data, array('id = ?' => $id), true);
vchamilo_redirect(api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php');
}

@ -12,8 +12,8 @@ require_once api_get_path(SYS_PLUGIN_PATH).'vchamilo/views/editinstance_form.php
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_PLUGIN_PATH).'vchamilo/js/host_form.js" type="text/javascript" language="javascript"></script>';
// get parameters
$id = (int)($_REQUEST['vid']);
$action = $_REQUEST['what'];
$id = isset($_REQUEST['vid']) ? $_REQUEST['vid'] : '';
$action = isset($_REQUEST['what']) ? $_REQUEST['what'] : '';
$registeronly = @$_REQUEST['registeronly'];
$plugininstance = VChamiloPlugin::create();
$thisurl = api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php';
@ -24,7 +24,7 @@ api_protect_admin_script();
if ($id) {
$mode = 'update';
} else {
$mode = ($registeronly) ? 'register' : 'add' ;
$mode = $registeronly ? 'register' : 'add' ;
}
$form = new InstanceForm($plugininstance, $mode);
@ -33,11 +33,10 @@ $form->definition();
$actions = '';
$message = '';
if ($data = $form->get_data()) {
include(api_get_path(SYS_PLUGIN_PATH).'vchamilo/views/editinstance.controller.php');
include api_get_path(SYS_PLUGIN_PATH).'vchamilo/views/editinstance.controller.php';
}
if ($id){
// $vhost = $DB->get_record('vchamilo', array('id' => $id));
if ($id) {
$sql = "SELECT * FROM vchamilo WHERE id = $id";
$result = Database::query($sql);
$vhost = Database::fetch_array($result);
@ -54,7 +53,7 @@ if ($id){
$content = $form->return_form();
$tpl = new Template($tool_name, true, true, false, true, false);
$tpl = new Template(get_lang('VChamilo'), true, true, false, true, false);
$tpl->assign('actions', $actions);
$tpl->assign('message', $message);
$tpl->assign('content', $content);

@ -1,14 +1,26 @@
<?php
/**
* Class ChamiloForm
*/
abstract class ChamiloForm
{
protected $_form;
protected $_mode;
protected $_cancelurl;
protected $_customdata;
public $_definition_finalized;
public function __construct($mode, $returnurl, $cancelurl, $customdata)
/**
* ChamiloForm constructor.
* @param $mode
* @param $returnurl
* @param $cancelurl
* @param $customdata
*/
public function __construct($mode, $returnurl, $cancelurl, $customdata = [])
{
global $text_dir;
$this->_mode = $mode;
$this->_cancelurl = $cancelurl;
$this->_customdata = $customdata;
@ -18,25 +30,30 @@ abstract class ChamiloForm
$this->_form = new FormValidator($mode.'_instance', 'post', $returnurl, '', $attributes);
}
abstract function definition();
abstract function validation($data, $files = null);
public abstract function definition();
public abstract function validation($data, $files = null);
function validate() {
public function validate(
) {
return $this->_form->validate();
}
function display() {
public function display()
{
return $this->_form->display();
}
function definition_after_data(){
public function definition_after_data(){
}
function return_form(){
public function return_form()
{
return $this->_form->toHtml();
}
function is_in_add_mode(){
public function is_in_add_mode()
{
return $this->_mode == 'add';
}
@ -52,20 +69,19 @@ abstract class ChamiloForm
public function add_action_buttons($cancel = true, $submitlabel = null, $cancellabel = null)
{
// TODO : refine lang fetch to effective global strings.
if (is_null($submitlabel)){
if (is_null($submitlabel)) {
$submitlabel = get_lang('save');
}
if (is_null($cancellabel)){
if (is_null($cancellabel)) {
$submitlabel = get_lang('cancel');
}
$cform =& $this->_form;
if ($cancel){
if ($cancel) {
//when two elements we need a group
$buttonarray = array();
$buttonarray[] = &$cform->createElement('submit', 'submitbutton', $submitlabel);
//$buttonarray[] = &$cform->createElement('cancel', $cancellabel, $this->_cancelurl);
$cform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
} else {
//no group needed
@ -87,14 +103,13 @@ abstract class ChamiloForm
if ($this->is_submitted() and $this->is_validated()) {
$data = $cform->exportValues(null, $slashed);
unset($data['sesskey']); // we do not need to return sesskey
unset($data['_qf__'.$this->_formname]); // we do not need the submission marker too
if (empty($data)) {
return NULL;
return null;
} else {
return (object)$data;
}
} else {
return NULL;
return null;
}
}
@ -111,14 +126,13 @@ abstract class ChamiloForm
if ($this->is_submitted()) {
$data = $cform->exportValues(null, $slashed);
unset($data['sesskey']); // we do not need to return sesskey
unset($data['_qf__'.$this->_formname]); // we do not need the submission marker too
if (empty($data)) {
return NULL;
return null;
} else {
return (object)$data;
}
} else {
return NULL;
return null;
}
}
@ -147,6 +161,7 @@ abstract class ChamiloForm
}
}
}
return false;
}
@ -163,6 +178,7 @@ abstract class ChamiloForm
$this->_definition_finalized = true;
$this->definition_after_data();
}
return $this->validate_defined_fields();
}
@ -221,6 +237,7 @@ abstract class ChamiloForm
$validated = ($internal_val and $chamilo_val and $file_val);
}
return $validated;
}
@ -228,15 +245,16 @@ abstract class ChamiloForm
{
static $nosubmit = null; // one check is enough
if (!is_null($nosubmit)){
if (!is_null($nosubmit)) {
return $nosubmit;
}
$cform =& $this->_form;
$nosubmit = false;
if (!$this->is_submitted()){
if (!$this->is_submitted()) {
return false;
}
/*
foreach ($cform->_noSubmitButtons as $nosubmitbutton){
if (optional_param($nosubmitbutton, 0, PARAM_RAW)){
@ -278,6 +296,7 @@ abstract class ChamiloForm
// note: server side rules do not work for files - use custom verification in validate() instead
return true;
}
$errors = array();
$mform =& $this->_form;
@ -288,7 +307,9 @@ abstract class ChamiloForm
foreach ($_FILES as $elname=>$file) {
if ($mform->elementExists($elname) and $mform->getElementType($elname)=='file') {
$required = $mform->isElementRequired($elname);
if (!empty($this->_upload_manager->files[$elname]['uploadlog']) and empty($this->_upload_manager->files[$elname]['clear'])) {
if (!empty($this->_upload_manager->files[$elname]['uploadlog']) &&
empty($this->_upload_manager->files[$elname]['clear'])
) {
if (!$required and $file['error'] == UPLOAD_ERR_NO_FILE) {
// file not uploaded and not required - ignore it
continue;
@ -304,40 +325,57 @@ abstract class ChamiloForm
}
// return errors if found
if ($status and 0 == count($errors)){
if ($status && 0 == count($errors)) {
return true;
} else {
$files = array();
return $errors;
}
}
}
/**
* Class InstanceForm
*/
class InstanceForm extends ChamiloForm
{
public $_plugin;
/**
* InstanceForm constructor.
* @param $plugin
* @param string $mode
* @param null $returnurl
* @param null $cancelurl
*/
public function __construct($plugin, $mode = 'add', $returnurl = null, $cancelurl = null)
{
global $_configuration;
$this->_plugin = $plugin;
$returnurl = $_configuration['root_web'].'plugin/vchamilo/views/editinstance.php';
if ($mode == 'update') {
$returnurl = $_configuration['root_web'].'plugin/vchamilo/views/editinstance.php?vid='.intval($_GET['vid']);
}
$cancelurl = $_configuration['root_web'].'plugin/vchamilo/views/manage.php';
parent::__construct($mode, $returnurl, $cancelurl);
}
function definition()
/**
*
*/
public function definition()
{
global $_configuration;
$cform = $this->_form;
// Settings variables.
$size_input_text = 'size="30"';
$size_input_text_big = 'size="60"';
$size_input_text_big = 'size="60"';
/*
* Host's id.
@ -351,15 +389,25 @@ class InstanceForm extends ChamiloForm
*/
$cform->addElement('header', $this->_plugin->get_lang('hostdefinition'));
// Name.
$cform->addElement('text', 'sitename', $this->_plugin->get_lang('sitename'), $size_input_text);
$cform->addElement('text', 'sitename', $this->_plugin->get_lang('sitename'));
$cform->applyFilter('sitename', 'trim');
// Shortname.
$cform->addElement('text', 'institution', $this->_plugin->get_lang('institution'), ($this->mode == 'edit' ? 'disabled="disabled" ' : ''));
$cform->addElement(
'text',
'institution',
$this->_plugin->get_lang('institution'),
($this->_mode == 'edit' ? 'disabled="disabled" ' : '')
);
$cform->applyFilter('institution', 'trim');
// Host's name.
$cform->addElement('text', 'root_web', $this->_plugin->get_lang('rootweb'), ($this->mode == 'edit' ? 'disabled="disabled" ' : '').$size_input_text);
$cform->addElement(
'text',
'root_web',
$this->_plugin->get_lang('rootweb'),
($this->_mode == 'edit' ? 'disabled="disabled" ' : '')
);
$cform->applyFilter('root_web', 'trim');
/*
@ -376,31 +424,47 @@ class InstanceForm extends ChamiloForm
$cform->applyFilter('db_user', 'trim');
// Database password.
$cform->addElement('password', 'db_password', $this->_plugin->get_lang('dbpassword'), array('id' => 'id_vdbpassword'));
// Button for testing database connection.
$cform->addElement('button', 'testconnection', $this->_plugin->get_lang('testconnection'), 'onclick="opencnxpopup(\''.$_configuration['root_web'].'\'); return false;"');
$cform->addElement(
'password',
'db_password',
$this->_plugin->get_lang('dbpassword'),
array('id' => 'id_vdbpassword')
);
// Database name.
$cform->addElement('text', 'main_database', $this->_plugin->get_lang('maindatabase'));
// Table's prefix.
$cform->addElement('text', 'table_prefix', $this->_plugin->get_lang('tableprefix'));
//$cform->addElement('text', 'table_prefix', $this->_plugin->get_lang('tableprefix'));
// Db's prefix.
$cform->addElement('text', 'db_prefix', $this->_plugin->get_lang('dbprefix'));
/*
* data fieldset.
*/
$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'));
$cform->addElement(
'text',
'course_folder',
$this->_plugin->get_lang('coursefolder'),
array('size' => $size_input_text_big, 'id' => 'id_vdatapath')
);
// Button for testing database connection.
$cform->addElement(
'button',
'testconnection',
$this->_plugin->get_lang('testconnection'),
'onclick="opencnxpopup(\''.$_configuration['root_web'].'\'); return false;"'
);
// Button for testing datapath.
$cform->addElement('button', 'testdatapath', $this->_plugin->get_lang('testdatapath'), 'onclick="opendatapathpopup(\''.$_configuration['root_web'].'\'); return true;"');
$cform->addElement(
'button',
'testdatapath',
$this->_plugin->get_lang('testdatapath'),
'onclick="opendatapathpopup(\''.$_configuration['root_web'].'\'); return true;"'
);
/*
* Template selection.
@ -419,16 +483,39 @@ class InstanceForm extends ChamiloForm
$this->add_action_buttons(true, $submitstr, $cancelstr);
// Rules for the add mode.
if($this->is_in_add_mode()) {
if ($this->is_in_add_mode()) {
$cform->addRule('sitename', $this->_plugin->get_lang('sitenameinputerror'), 'required', null, 'client');
$cform->addRule('institution', $this->_plugin->get_lang('institutioninputerror'), 'required', null, 'client');
$cform->addRule(
'institution',
$this->_plugin->get_lang('institutioninputerror'),
'required',
null,
'client'
);
$cform->addRule('root_web', $this->_plugin->get_lang('rootwebinputerror'), 'required', null, 'client');
$cform->addRule('main_database', $this->_plugin->get_lang('databaseinputerror'), 'required', null, 'client');
$cform->addRule('course_folder', $this->_plugin->get_lang('coursefolderinputerror'), 'required', null, 'client');
$cform->addRule(
'main_database',
$this->_plugin->get_lang('databaseinputerror'),
'required',
null,
'client'
);
$cform->addRule(
'course_folder',
$this->_plugin->get_lang('coursefolderinputerror'),
'required',
null,
'client'
);
}
}
function validation($data, $files = null)
/**
* @param array $data
* @param null $files
* @return array
*/
public function validation($data, $files = null)
{
global $plugininstance;
@ -438,11 +525,18 @@ class InstanceForm extends ChamiloForm
}
$tablename = Database::get_main_table('vchamilo');
if($vchamilo = Database::select('*', $tablename, array('where' => array(' root_web = ? ' => array($data->root_web))))){
$vchamilo = Database::select(
'*',
$tablename,
array('where' => array(' root_web = ? ' => array($data['root_web']))),
'first'
);
if ($vchamilo && isset($data['vid']) && $data['vid'] != $vchamilo['id']) {
$errors['root_web'] = $plugininstance->get_lang('errorrootwebexists');
}
if(!empty($errors)){
if (!empty($errors)) {
return $errors;
}
}

@ -1,6 +1,6 @@
<?php
require_once(api_get_path(LIBRARY_PATH).'fileManage.lib.php');
require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
$table = Database::get_main_table('vchamilo');
@ -13,14 +13,14 @@ if ($action == 'newinstance' || $action == 'instance') {
vchamilo_redirect(api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/editinstance.php?registeronly='.$registeronly);
}
if ($action == 'editinstance') {
if ($action == 'editinstance' || $action == 'updateinstance') {
$vid = $_REQUEST['vid'];
vchamilo_redirect(api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/editinstance.php?vid='.$vid);
}
if ($action == 'deleteinstances' || $action == 'disableinstances') {
ctrace("Disabling instance");
Display::addFlash(Display::return_message("Disabling instance"));
// Make it not visible.
$vidlist = implode("','", $_REQUEST['vids']);
$sql = "
@ -36,7 +36,7 @@ if ($action == 'deleteinstances' || $action == 'disableinstances') {
}
if ($action == 'enableinstances') {
ctrace("Enabling instance");
Display::addFlash(Display::return_message("Enabling instance"));
$vidlist = implode("','", $_REQUEST['vids']);
$sql = "
UPDATE
@ -49,9 +49,10 @@ if ($action == 'enableinstances') {
Database::query($sql);
vchamilo_redirect(api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php');
}
if ($action == 'fulldeleteinstances') {
ctrace("Destroying instance");
Display::addFlash(Display::return_message("Destroying instance"));
// Removes everything.
if (empty($automation)) {
$vidlist = implode("','", $_REQUEST['vids']);
@ -131,7 +132,7 @@ if ($action == 'fulldeleteinstances') {
}
if ($action == 'snapshotinstance') {
$vid = $_REQUEST['vid'];
$vid = isset($_REQUEST['vid']) ? $_REQUEST['vid'] : '';
if ($vid) {
$vhosts = Database::select('*', 'vchamilo', array('where' => array('id = ?' => $vid)));
$vhost = (object)array_pop($vhosts);
@ -140,22 +141,21 @@ if ($action == 'snapshotinstance') {
}
// Parsing url for building the template name.
$wwwroot = $vhost->root_web;
$vchamilostep = $_REQUEST['step'];
$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 = api_get_path(SYS_PATH, CHAMILO_ARCHIVE_PATH).$separator.$templatefoldername; // can be problematic as self containing
$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)){
if (preg_match('/ /', $absolute_sqldir)) {
$erroritem = new StdClass();
$erroritem->message = $plugininstance->get_lang('errorspacesinpath');
vchamilo_print_error(array($erroritem));
@ -177,15 +177,15 @@ if ($action == 'snapshotinstance') {
}
if (empty($fullautomation)) {
$actionurl = $_configuration['root_web'].'/plugin/vchamilo/views/manage.php';
$content .= '<form name"single" action="'.$actionurl.'">';
$content = '<form name"single" action="'.$actionurl.'">';
$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 .= '</form>';
$content .= '</div>';
$tpl = new Template($tool_name, true, true, false, true, false);
$tpl = new Template(get_lang('VChamilo'), true, true, false, true, false);
$tpl->assign('actions', '');
$tpl->assign('message', $plugininstance->get_lang('vchamilosnapshot1'));
$tpl->assign('content', $content);
@ -196,7 +196,7 @@ if ($action == 'snapshotinstance') {
// continue next step
$vchamilostep = 1;
}
}
}
if ($vchamilostep >= 1) {
if ($wwwroot == $_configuration['root_web']) {
// Make fake Vchamilo record.
@ -213,6 +213,7 @@ if ($action == 'snapshotinstance') {
$varchivepath = api_get_path(SYS_ARCHIVE_PATH, (array)$vchamilo);
}
$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
@ -239,8 +240,8 @@ if ($action == 'snapshotinstance') {
$content .= '<input type="submit" name="go_btn" value="'.$plugininstance->get_lang('continue').'" />';
$content .= '</form>';
}
$tpl = new Template($tool_name, true, true, false, true, false);
$tpl = new Template(get_lang('VChamilo'), true, true, false, true, false);
$tpl->assign('actions', '');
$tpl->assign('message', $message);
$tpl->assign('content', $content);
@ -250,25 +251,13 @@ if ($action == 'snapshotinstance') {
}
}
// end of process
// copy chamilo data dirs and protect against copy recursion.
/*
echo "<pre>";
echo "copyDirTo($vcoursepath, $absolute_datadir, false);
copyDirTo($varchivepath, $absolute_datadir.'/archive, false);
copyDirTo($vhomepath, $absolute_datadir.'/home', false);";
echo "</pre>";
*/
echo "<pre>";
echo ("Copying from $vcoursepath to $absolute_datadir \n");
Display::addFlash(Display::return_message("Copying from $vcoursepath to $absolute_datadir "));
copyDirTo($vcoursepath, $absolute_datadir, false);
echo ("Copying from $varchivepath to {$absolute_datadir}/archive \n");
Display::addFlash(Display::return_message("Copying from $varchivepath to {$absolute_datadir}/archive "));
copyDirTo($varchivepath, $absolute_datadir.'/archive', false);
echo ("Copying from $vhomepath to {$absolute_datadir}/home \n");
Display::addFlash(Display::return_message("Copying from $vhomepath to {$absolute_datadir}/home "));
copyDirTo($vhomepath, $absolute_datadir.'/home', false);
echo "</pre>";
// Store original hostname and some config info for further database or filestore replacements.
$FILE = fopen($absolute_sqldir.$separator.'manifest.php', 'w');
@ -281,18 +270,14 @@ if ($action == 'snapshotinstance') {
// Every step was SUCCESS.
if (empty($fullautomation)){
$message_object->message = $plugininstance->get_lang('successfinishedcapture');
$message_object->style = 'notifysuccess';
Display::addFlash($plugininstance->get_lang('successfinishedcapture'));
// Save confirm message before redirection.
$_SESSION['confirm_message'] = $message_object;
$actionurl = $_configuration['root_web'].'/plugin/vchamilo/views/manage.php';
$content .= '<div>'.$message_object->message.'</div>';
$content .= '<form name"single" action="'.$actionurl.'">';
$content .= '<input type="submit" name="go_btn" value="'.$plugininstance->get_lang('backtoindex').'" />';
$content .= '</form>';
$tpl = new Template($tool_name, true, true, false, true, false);
$tpl = new Template(get_lang('VChamilo'), true, true, false, true, false);
$tpl->assign('actions', '');
$tpl->assign('message', $plugininstance->get_lang('vchamilosnapshot3'));
$tpl->assign('content', $content);
@ -305,7 +290,7 @@ if ($action == 'snapshotinstance') {
if ($action == 'clearcache') {
ctrace("Clearing cache");
Display::addFlash(Display::return_message("Clearing cache"));
// Removes cache directory.
if (empty($automation)) {
if (array_key_exists('vids', $_REQUEST)) {
@ -344,10 +329,6 @@ if ($action == 'clearcache') {
}
if ($action == 'setconfigvalue') {
if ($_REQUEST['confirm']) {
}
$select = '<select name="preset" onchange="setpreset(this.form, this)">';
$vars = $DB->get_records('settings_current', array(), 'id,variable,subkey', 'variable,subkey');
foreach($vars as $setting) {

@ -4,7 +4,7 @@ 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';
$action = $_GET['what'];
$action = isset($_GET['what']) ? $_GET['what'] : '';
define('CHAMILO_INTERNAL', true);
$plugininstance = VChamiloPlugin::create();
@ -12,7 +12,7 @@ $thisurl = api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php';
api_protect_admin_script();
//require_js('host_list.js', 'vchamilo');
require_js('host_list.js', 'vchamilo');
if ($action) {
require_once(api_get_path(SYS_PLUGIN_PATH).'vchamilo/views/manage.controller.php');
@ -33,7 +33,17 @@ $column = 0;
$row = 0;
// $table->set_additional_parameters($parameters);
$headers = array('', $plugininstance->get_lang('sitename'), $plugininstance->get_lang('institution'), $plugininstance->get_lang('rootweb'), $plugininstance->get_lang('dbhost'), $plugininstance->get_lang('coursefolder'), $plugininstance->get_lang('enabled'), $plugininstance->get_lang('lastcron'), '');
$headers = array(
'',
$plugininstance->get_lang('sitename'),
$plugininstance->get_lang('institution'),
$plugininstance->get_lang('rootweb'),
$plugininstance->get_lang('dbhost'),
$plugininstance->get_lang('coursefolder'),
$plugininstance->get_lang('enabled'),
$plugininstance->get_lang('lastcron'),
'',
);
$attrs = array('center' => 'left');
$table->addRow($headers, $attrs, 'th');
@ -44,18 +54,25 @@ foreach ($instances as $instance) {
$sitelink = '<a href="'.$instance->root_web.'" target="_blank">'.$instance->sitename.'</a>';
if ($instance->visible) {
$status = '<a href="'.$thisurl.'?what=disableinstances&vids[]='.$instance->id.'" ><img src="'.$plugininstance->pix_url('enabled').'" /></a>';
$status = '<a href="'.$thisurl.'?what=disableinstances&vids[]='.$instance->id.'" >
<img src="'.$plugininstance->pix_url('enabled').'" /></a>';
} else {
$status = '<a href="'.$thisurl.'?what=enableinstances&vids[]='.$instance->id.'" ><img src="'.$plugininstance->pix_url('disabled').'" /></a>';
$status = '<a href="'.$thisurl.'?what=enableinstances&vids[]='.$instance->id.'" >
<img src="'.$plugininstance->pix_url('disabled').'" /></a>';
}
$cmd = '&nbsp;<a href="'.$thisurl.'?what=editinstance&vid='.$instance->id.'" title="'.$plugininstance->get_lang('edit').'">
<img src="'.$plugininstance->pix_url('edit').'" /></a>';
$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){
$cmd = '<a href="'.$thisurl.'?what=fulldeleteinstances&vids[]='.$instance->id.'" title="'.$plugininstance->get_lang('destroyinstances').'"><img src="'.$plugininstance->pix_url('delete').'" /></a>';
$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>';
$cmd .= '<a href="'.$thisurl.'?what=deleteinstances&vids[]='.$instance->id.'" title="'.$plugininstance->get_lang('deleteinstances').'">
<img src="'.$plugininstance->pix_url('delete').'" /></a>';
}
$cmd .= '&nbsp;<a href="'.$thisurl.'?what=editinstance&vid='.$instance->id.'" title="'.$plugininstance->get_lang('edit').'"><img src="'.$plugininstance->pix_url('edit').'" /></a>';
$cmd .= '&nbsp;<a href="'.$thisurl.'?what=snapshotinstance&vid='.$instance->id.'" title="'.$plugininstance->get_lang('snapshotinstance').'"><img src="'.$plugininstance->pix_url('snapshot').'" /></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);
@ -79,13 +96,12 @@ $selectionaction = '<select name="what" onchange="this.form.submit()">'.implode(
$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 .= '</form>';
$actions = '';
$message = '';
$tpl = new Template($tool_name, true, true, false, true, false);
$tpl = new Template(get_lang('VChamilo'), true, true, false, true, false);
$tpl->assign('actions', $actions);
$tpl->assign('message', $message);
$tpl->assign('content', $content);

@ -1,57 +1,102 @@
<?php
$sql = "SELECT * FROM vchamilo";
$result = Database::query($sql);
$vchamilos = Database::store_result($result);
// propagate in all known vchamilos a setting
if ($action == 'syncall') {
$vchamilos = $DB->get_records('vchamilo', array());
$keys = array_keys($_REQUEST);
$selection = preg_grep('/sel_.*/', $keys);
foreach($selection as $selkey) {
$settingid = str_replace('sel_', '', $selkey);
foreach ($selection as $selkey) {
$settingId = str_replace('sel_', '', $selkey);
if (!is_numeric($settingid)) continue;
if (!is_numeric($settingId)) {
continue;
}
$value = $_REQUEST[$selkey];
$setting = $DB->get_record('settings_current', array('id' => $settingid));
$params = array('variable' => $setting->variable, 'subkey' => $setting->subkey, 'category' => $setting->category, 'access_url' => $setting->access_url);
foreach($vchamilos as $vcid => $chm) {
$DB->set_field('settings_current', 'selected_value', $value, $params, 'id', $chm->main_database);
$setting = api_get_settings_params_simple(array('id' => $settingId));
$params = array(
'title' => $setting['title'],
'variable' => $setting['variable'],
'subkey' => $setting['subkey'],
'category' => $setting['category'],
'access_url' => $setting['access_url'],
);
foreach ($vchamilos as $vcid => $chm) {
$table = $chm['main_database'].".settings_current ";
$sql = " SELECT * FROM $table
WHERE
variable = '{{$setting['variable']}}' AND
access_url = '{$setting['access_url']}'
";
$result = Database::query($sql);
if (Database::num_rows($result)) {
$sql = "UPDATE $table SET
selected_value = '$value'
WHERE id = $settingId";
Database::query($sql);
}
//$DB->set_field('settings_current', 'selected_value', $value, $params, 'id', $chm->main_database);
}
}
}
if ($action == 'syncthis') {
$settingid = $_GET['settingid'];
$vchamilos = $DB->get_records('vchamilo', array());
$settingId = isset($_GET['settingid']) ? $_GET['settingid'] : '';
if (is_numeric($settingid)) {
$delifempty = @$_REQUEST['del'];
if (is_numeric($settingId)) {
$delifempty = isset($_REQUEST['del']) ? $_REQUEST['del'] : '';
$value = $_REQUEST['value'];
// Getting the local setting record.
$setting = $DB->get_record('settings_current', array('id' => $settingid));
$params = array('variable' => $setting->variable, 'subkey' => $setting->subkey, 'category' => $setting->category, 'access_url' => $setting->access_url);
$setting = api_get_settings_params_simple(array('id' => $settingId));
$params = array(
'access_url_changeable' => $setting['access_url_changeable'],
'title' => $setting['title'],
'variable' => $setting['variable'],
'subkey' => $setting['subkey'],
'category' => $setting['category'],
'access_url' => $setting['access_url'],
);
$errors = '';
foreach ($vchamilos as $vcid => $chm) {
$table = $chm['main_database'].".settings_current";
if ($delifempty && empty($value)) {
$res = $DB->delete_records('settings_current', $params, $chm->main_database);
$sql = "DELETE FROM $table WHERE
selected_value = '$value' AND
variable = '{{$setting['variable']}}' AND
access_url = '{$setting['access_url']}'
";
Database::query($sql);
//$res = $DB->delete_records('settings_current', $params, $chm->main_database);
$case = "delete";
} else {
if ($remotesetting = $DB->get_record('settings_current', array('variable' => $setting->variable, 'subkey' => $setting->subkey), '*', $chm->main_database)) {
$value = str_replace("'", "''", $value); // Mysql protection
$res = $DB->set_field('settings_current', 'selected_value', $value, $params, 'id', $chm->main_database);
$case = "update";
$sql = " SELECT * FROM $table
WHERE
variable = '{{$setting['variable']}}' AND
subkey = '{$setting['subkey']}'
";
$result = Database::query($sql);
if (Database::num_rows($result)) {
$sql = "UPDATE $table SET
selected_value = '$value'
WHERE id = $settingId";
Database::query($sql);
} else {
$remotesetting = $setting;
$remotesetting->selected_value = str_replace("'", "''", $value);
unset($remotesetting->id);
$res = $DB->insert_record('settings_current', $remotesetting, $chm->main_database);
$case = "insert";
Database::insert($table, $params);
}
}
if (!$res) {
$errors .= "Set Field Error in $chm->sitename for case $case<br/>\n";
}
}
return $errors;
} else {

@ -1,14 +1,11 @@
<?php
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 '../../../main/inc/global.inc.php';
global $DB;
$DB = new DatabaseManager();
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';
$action = $_GET['what'];
$action = isset($_GET['what']) ? $_GET['what'] : '';
define('CHAMILO_INTERNAL', true);
$plugininstance = VChamiloPlugin::create();
@ -20,7 +17,7 @@ if ($action){
require_once(api_get_path(SYS_PLUGIN_PATH).'vchamilo/views/syncparams.controller.php');
}
$allparams = $DB->get_records('settings_current', array(), 'variable,subkey');
$settings = api_get_settings();
$table = new HTML_Table(array('class' => 'data_table', 'width' => '100%'));
$column = 0;
@ -31,17 +28,30 @@ $headers = array('', $plugininstance->get_lang('variable'), $plugininstance->get
$attrs = array('center' => 'left');
$table->addRow($headers, $attrs, 'th');
foreach ($allparams as $param) {
foreach ($settings as $param) {
// $check = '<input type="checkbox" name="sync_'.$param->id.'" value="'.$param->selected_value.'" />';
$check = '';
$attrs = array('center' => 'left');
$syncthisbutton = '<input type="button" name="syncthis" value="'.$plugininstance->get_lang('syncthis').'" onclick="ajax_sync_setting(\''.$_configuration['root_web'].'\', \''.$param->id.'\')" /> <input type="checkbox" name="del_'.$param->id.'" value="1" title="'.$plugininstance->get_lang('deleteifempty').'" /> <span id="res_'.$param->id.'"></span>';
$data = array($check, $param->variable, $param->subkey, $param->category, $param->access_url, '<input type="text" name="value_'.$param->id.'" value="'.htmlspecialchars($param->selected_value, ENT_COMPAT, 'UTF-8').'" size="40" />', $syncthisbutton);
$syncthisbutton = '<input type="button" name="syncthis" value="'.$plugininstance->get_lang('syncthis').'" onclick="ajax_sync_setting(\''.$_configuration['root_web'].'\', \''.$param['id'].'\')" />
<input type="checkbox" name="del_'.$param['id'].'" value="1" title="'.$plugininstance->get_lang('deleteifempty').'" /> <span id="res_'.$param['id'].'"></span>';
$data = array(
$check,
$param['variable'],
$param['subkey'],
$param['category'],
$param['access_url'],
'<input type="text" name="value_'.$param['id'].'" value="'.htmlspecialchars(
$param['selected_value'],
ENT_COMPAT,
'UTF-8'
).'" />',
$syncthisbutton,
);
$row = $table->addRow($data, $attrs, 'td');
$table->setRowAttributes($row, array('id' => 'row_'.$param->id), true);
$table->setRowAttributes($row, array('id' => 'row_'.$param['id']), true);
}
$content .= '<form name="settingsform" action="'.$thisurl.'">';
$content = '<form name="settingsform" action="'.$thisurl.'">';
$content .= '<input type="hidden" name="what" value="" />';
$content .= $table->toHtml();
// $content .= '<div class"vchamilo-right"><div></div><div><input type="button" name="syncall" value="'.$plugininstance->get_lang('syncall').'" onclick="this.form.what.value=\'syncall\';this.form.submit();">';
@ -52,7 +62,7 @@ $message = '';
$message = require_js('ajax.js', 'vchamilo', true);
$tpl = new Template($tool_name, true, true, false, true, false);
$tpl = new Template(get_lang('VChamilo'), true, true, false, true, false);
$tpl->assign('actions', $actions);
$tpl->assign('message', $message);
$tpl->assign('content', $content);

Loading…
Cancel
Save