@ -0,0 +1,16 @@ |
||||
<?php |
||||
/** |
||||
* @package chamilo.plugin.customfooter |
||||
*/ |
||||
|
||||
echo '<div class="well">'; |
||||
if (!empty($plugin_info['settings']['customfooter_show_type'])) { |
||||
echo "<h2>".$plugin_info['settings']['customfooter_show_type']."</h2>"; |
||||
} else { |
||||
echo "<h2>Custom Footer</h2>"; |
||||
} |
||||
|
||||
//Using get_lang inside a plugin |
||||
echo get_lang('CustomFooter'); |
||||
|
||||
echo '</div>'; |
@ -0,0 +1,17 @@ |
||||
<?php |
||||
/* PHP code to install the plugin |
||||
* For example: |
||||
* |
||||
// To query something to the database |
||||
|
||||
$table = Database::get_main_table(TABLE_MAIN_USER); // TABLE_MAIN_USER is a constant check the main/inc/database.constants.inc.php |
||||
$sql = "SELECT firstname, lastname FROM $table_users "; |
||||
$users = Database::query($sql); |
||||
|
||||
You can also use the Chamilo classes |
||||
$users = UserManager::get_user_list(); |
||||
*/ |
||||
global $_configuration; |
||||
|
||||
api_add_setting(@$_configuration['defaults']['customfooter_footer_left'], 'customfooter_footer_left', 'customfooter', 'setting', 'Plugins'); |
||||
api_add_setting(@$_configuration['defaults']['customfooter_footer_right'], 'customfooter_footer_right', 'customfooter', 'setting', 'Plugins'); |
@ -0,0 +1,72 @@ |
||||
<?php |
||||
|
||||
$string['accesstools'] = 'Go to delivery tools'; |
||||
$string['application'] = 'Application'; |
||||
$string['action'] = 'Command'; |
||||
$string['backtoprod'] = 'Plug in back'; |
||||
$string['clearreportarea'] = 'Clear report file area'; |
||||
$string['closesession'] = 'Close last session'; |
||||
$string['comment'] = 'Comment'; |
||||
$string['component'] = 'Component'; |
||||
$string['componentpath'] = 'Component Path'; |
||||
$string['configtooldeliverydir'] = 'From tools location the symlink directory where delivery must change moodle code'; |
||||
$string['configtooldeliveryenablesessions'] = 'If enabled, you need open and close delivery sessions for updating code. Session reports will be notified to reported recipients at the end of each session.'; |
||||
$string['configtooldeliverymethod'] = 'Choose the method (toolkit) for delivery'; |
||||
$string['configtooldeliveryprodscriptpath'] = 'Setup the physical path to reach delivery commands'; |
||||
$string['configtooldeliveryreportlogo'] = 'Logo image for the delivery report'; |
||||
$string['configtooldeliverysessionopenrecipients'] = 'All recipients (comma separated list) here will be notified when a delivery session is opened'; |
||||
$string['configtooldeliverysudo'] = 'Uses sudo in outcomming system commands'; |
||||
$string['configtooldeliverysudouser'] = 'Sudo username if sudo enabled (note that sudo user must have access to the whole delivery commands with NOPASSWD tag AND has write access to all the moodle files)'; |
||||
$string['configtooldirectdeliverytools'] = 'If checked, the delivery framework expects having tools in the immediate location given by the Path to Delivery Commands parameter. Tjhis is usefull when using a tool set located elsewhere then inthe delivery toolset.'; |
||||
$string['continuesession'] = 'Continue last session'; |
||||
$string['cvs'] = 'CVS'; |
||||
$string['dateend'] = 'End date'; |
||||
$string['datestart'] = 'Start date'; |
||||
$string['delivery'] = 'Code delivery'; |
||||
$string['deliveryoptions'] = 'Delivery Settings'; |
||||
$string['deliveryreport'] = 'Delivery Session Report'; |
||||
$string['deliverysessions'] = 'Delivery sessions'; |
||||
$string['deliverystate'] = 'Delivery State'; |
||||
$string['deliverytools'] = 'Delivery Tools'; |
||||
$string['errornotexecutable'] = 'Error : tools are not executable ({$a})'; |
||||
$string['errornotfound'] = 'Error : tools are not found ({$a})'; |
||||
$string['followup'] = 'Follow up'; |
||||
$string['goback'] = 'Plug out'; |
||||
$string['impact'] = 'Impact'; |
||||
$string['newdeliverysession'] = 'New delivery session'; |
||||
$string['nosessions'] = 'No delivery sessions'; |
||||
$string['opensession'] = 'Open new session'; |
||||
$string['outputstatus'] = 'Output state'; |
||||
$string['pluginname'] = 'Code Delivery Tools'; |
||||
$string['productionstate'] = 'Production State'; |
||||
$string['reports'] = 'Reports'; |
||||
$string['reporttitle'] = 'Code delivery report'; |
||||
$string['run'] = 'Run'; |
||||
$string['save'] = 'Save'; |
||||
$string['saveandclose'] = 'Save and close'; |
||||
$string['savesessiondata'] = 'Save session information'; |
||||
$string['security'] = 'Access security'; |
||||
$string['sessionend'] = 'Session end'; |
||||
$string['sessionlogs'] = 'Session logs'; |
||||
$string['sessionopening'] = 'Opening delivery session on {$a}'; |
||||
$string['sessionclosing'] = 'Closing delivery session on {$a}'; |
||||
$string['sessionstart'] = 'Session start'; |
||||
$string['sessiontitle'] = 'Session title'; |
||||
$string['sudomodeon'] = 'Sudo Mode: On'; |
||||
$string['summary'] = 'Summary'; |
||||
$string['supersyncback'] = 'Synchronize safe and supersafe codebase'; |
||||
$string['svn'] = 'SVN'; |
||||
$string['syncback'] = 'Synchronize safe codebase'; |
||||
$string['time'] = 'Time'; |
||||
$string['tooldeliverydir'] = 'Delivery dir radical'; |
||||
$string['tooldeliveryenablesessions'] = 'Enable delivery sessions'; |
||||
$string['tooldeliverymethod'] = 'Delivery method'; |
||||
$string['tooldeliveryprodscriptpath'] = 'Path to delivery commands'; |
||||
$string['tooldeliveryreportlogo'] = 'Delivery Report Logo'; |
||||
$string['tooldeliverysessionopenrecipients'] = 'Recipients for session opening'; |
||||
$string['tooldeliverysudo'] = 'Delivery uses sudo'; |
||||
$string['tooldeliverysudouser'] = 'User for sudo'; |
||||
$string['tooldirectdeliverytools'] = 'Direct path to delivery tools'; |
||||
$string['update'] = 'Update code'; |
||||
$string['updatesession'] = 'Update session'; |
||||
|
@ -0,0 +1,66 @@ |
||||
<?php |
||||
|
||||
$string['accesstools'] = 'Aller aux outils de livraison'; |
||||
$string['application'] = 'Application'; |
||||
$string['action'] = 'Commande'; |
||||
$string['backtoprod'] = 'Rétablir la production'; |
||||
$string['clearreportarea'] = 'Vider la zone de fichiers'; |
||||
$string['closesession'] = 'Clôturer la session en cours'; |
||||
$string['comment'] = 'Commentaire'; |
||||
$string['component'] = 'Composant'; |
||||
$string['componentpath'] = 'Chemin du composant'; |
||||
$string['configtooldeliverydir'] = 'Le code à maintenir doit se trouver dans ce répertoire, à partir du chemin des outils de livraison. Il s\'agit d\'un lien symbolique pointant vers le réperoire effectif du code de production'; |
||||
$string['configtooldeliveryenablesessions'] = 'Si activé, les modifications de code ont lieu dans des sessions de travail que l\'ont peut ouvrir et fermer. Un rapport est émis lors de la clôture.'; |
||||
$string['configtooldeliverymethod'] = 'La méthode (outil de versionnement) pour la livraison'; |
||||
$string['configtooldeliveryprodscriptpath'] = 'La racine d\'implantation des outils de livraison'; |
||||
$string['configtooldeliveryreportlogo'] = 'Logo pour les rapports de livraison'; |
||||
$string['configtooldeliverysessionopenrecipients'] = 'fournir une liste des adresses mail à notifier séparée par des virgules'; |
||||
$string['configtooldeliverysudo'] = 'Utiliser sudo pour les commandes systeme sortantes'; |
||||
$string['configtooldeliverysudouser'] = 'Utilisateur de sudo (Notez que cet utilisateur doit avoir accès à toutes commandes de livraison avec le mode NOPASSWD, et doit avoir l\'accès en écriture aux fichiers source de Moodle)'; |
||||
$string['configtooldirectdeliverytools'] = 'Si coché, l\'infrastructure de livraison s\'attend à trouver les scripts de livraison immédiatement dans le répertoire indiqué dans le paramètre "Chemin vers les outils". Ceci est utile lorsque les outils sont implantés en dehors de la présente distribution.'; |
||||
$string['continuesession'] = 'Continuer la dernière session'; |
||||
$string['cvs'] = 'CVS'; |
||||
$string['delivery'] = 'Livraison de code'; |
||||
$string['deliveryoptions'] = 'Réglages des outils de livraison'; |
||||
$string['deliveryreport'] = 'Rapport de Session de Livraison'; |
||||
$string['deliverysessions'] = 'Sessions de livraison'; |
||||
$string['deliverystate'] = 'Mode Livraison'; |
||||
$string['deliverytools'] = 'Outils de livraison'; |
||||
$string['errornotexecutable'] = 'Erreur : les outils ne sont pas exécutables ({$a})'; |
||||
$string['errornotfound'] = 'Erreur : les outils ne sont pas trouvés ({$a})'; |
||||
$string['goback'] = 'Remiser la production'; |
||||
$string['newdeliverysession'] = 'Nouvelle session de livraison'; |
||||
$string['nosessions'] = 'Pas de sessions'; |
||||
$string['opensession'] = 'Ouvrir une session'; |
||||
$string['outputstatus'] = 'Etat'; |
||||
$string['pluginname'] = 'Outils de livraison de code'; |
||||
$string['productionstate'] = 'Mode Production'; |
||||
$string['reports'] = 'Rapports'; |
||||
$string['reporttitle'] = 'Rapport de mise à jour de code'; |
||||
$string['run'] = 'Lancer l\'outil'; |
||||
$string['save'] = 'Enregistrer'; |
||||
$string['saveandclose'] = 'Enregistrer et clôturer'; |
||||
$string['savesessiondata'] = 'Sauvegarder les données de session'; |
||||
$string['security'] = 'Sécurisation de la livraison'; |
||||
$string['sessionend'] = 'Fin de session'; |
||||
$string['sessionopening'] = 'Ouverture de session de livraison sur {$a}'; |
||||
$string['sessionclosing'] = 'Fermeture de session de livraison sur {$a}'; |
||||
$string['sessionstart'] = 'Début de session'; |
||||
$string['sessiontitle'] = 'Titre de session'; |
||||
$string['sudomodeon'] = 'Mode "sudo" : Actif'; |
||||
$string['summary'] = 'Description'; |
||||
$string['supersyncback'] = 'Synchroniser la version de sauvegarde et la version de sécurité'; |
||||
$string['svn'] = 'SVN'; |
||||
$string['syncback'] = 'Synchroniser la version de sauvegarde'; |
||||
$string['time'] = 'Temps'; |
||||
$string['tooldeliverydir'] = 'Radical de réperoire de livraison'; |
||||
$string['tooldeliveryenablesessions'] = 'Activer les sessions'; |
||||
$string['tooldeliverymethod'] = 'Méthode de livraison'; |
||||
$string['tooldeliveryprodscriptpath'] = 'Chemin vers les outils'; |
||||
$string['tooldeliveryreportlogo'] = 'Logo'; |
||||
$string['tooldeliverysessionopenrecipients'] = 'Destinataires des notifications d\'ouverture de sessions'; |
||||
$string['tooldeliverysudo'] = 'Livraison par sudo'; |
||||
$string['tooldeliverysudouser'] = 'Utilisateur sudo'; |
||||
$string['tooldirectdeliverytools'] = 'Le répertoire vers les outils est direct'; |
||||
$string['update'] = 'Mettre à jour le code'; |
||||
$string['updatesession'] = 'Mettre à jour la session'; |
@ -0,0 +1,43 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Description of Custom Footer |
||||
* |
||||
* @copyright (c) 2014 VF Consulting |
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html |
||||
* @author Valery Fremaux <valery.fremaux@gmail.com> |
||||
*/ |
||||
class CustomFooterPlugin extends Plugin { |
||||
|
||||
/** |
||||
* |
||||
* @return CustomFooterPlugin |
||||
*/ |
||||
static function create() { |
||||
static $result = null; |
||||
return $result ? $result : $result = new self(); |
||||
} |
||||
|
||||
function get_name() { |
||||
return 'customfooter'; |
||||
} |
||||
|
||||
protected function __construct() { |
||||
parent::__construct('1.1', 'Valery Fremaux'); |
||||
} |
||||
|
||||
function pix_url($pixname, $size = 16) { |
||||
global $_configuration; |
||||
|
||||
if (file_exists($_configuration['root_sys'].'/plugin/customplugin/pix/'.$pixname.'.png')){ |
||||
return $_configuration['root_web'].'/plugin/customplugin/pix/'.$pixname.'.png'; |
||||
} |
||||
if (file_exists($_configuration['root_sys'].'/plugin/customplugin/pix/'.$pixname.'.jpg')){ |
||||
return $_configuration['root_web'].'/plugin/customplugin/pix/'.$pixname.'.jpg'; |
||||
} |
||||
if (file_exists($_configuration['root_sys'].'/plugin/customplugin/pix/'.$pixname.'.gif')){ |
||||
return $_configuration['root_web'].'/plugin/customplugin/pix/'.$pixname.'.gif'; |
||||
} |
||||
return $_configuration['root_web'].'/main/img/icons/'.$size.'/'.$pixname.'.png'; |
||||
} |
||||
} |
@ -0,0 +1,55 @@ |
||||
<?php |
||||
/** |
||||
* This script is a configuration file for the delivery tools plugin. You can use it as a master for other platform plugins (course plugins are slightly different). |
||||
* These settings will be used in the administration interface for plugins (Chamilo configuration settings->Plugins) |
||||
* @package chamilo.plugin |
||||
* @author Julio Montoya <gugli100@gmail.com> |
||||
*/ |
||||
|
||||
require_once api_get_path(LIBRARY_PATH) . 'plugin.class.php'; |
||||
require_once dirname(__FILE__).'/lib/customfooter_plugin.class.php'; |
||||
|
||||
/** |
||||
* Plugin details (must be present) |
||||
*/ |
||||
|
||||
/* Plugin config */ |
||||
|
||||
//the plugin title |
||||
$plugin_info['title'] = 'Custom Footer'; |
||||
//the comments that go with the plugin |
||||
$plugin_info['comment'] = "Drives configuration parameters that plugs custom footer notes"; |
||||
//the plugin version |
||||
$plugin_info['version'] = '1.0'; |
||||
//the plugin author |
||||
$plugin_info['author'] = 'Valery Fremaux'; |
||||
|
||||
|
||||
/* Plugin optional settings */ |
||||
|
||||
/* |
||||
* This form will be showed in the plugin settings once the plugin was installed |
||||
* in the plugin/hello_world/index.php you can have access to the value: $plugin_info['settings']['hello_world_show_type'] |
||||
*/ |
||||
|
||||
$form = new FormValidator('customfooter_form'); |
||||
|
||||
$plugininstance = CustomFooterPlugin::create(); |
||||
|
||||
$config = api_get_settings_params(array('subkey = ? ' => 'customfooter', ' AND category = ? ' => 'Plugins')); |
||||
foreach ($config as $fooid => $configrecord) { |
||||
$canonic = preg_replace('/^customfooter_/', '', $configrecord['variable']); |
||||
if (in_array($canonic, array('footer_left', 'footer_right'))){ |
||||
$form_settings[$canonic] = $configrecord['selected_value']; |
||||
} |
||||
} |
||||
|
||||
// A simple select. |
||||
$form->addElement('text', 'footer_left', $plugininstance->get_lang('footerleft')); |
||||
$form->addElement('text', 'footer_right', $plugininstance->get_lang('footerright')); |
||||
|
||||
$form->addElement('style_submit_button', 'submit_button', $plugininstance->get_lang('Save')); |
||||
|
||||
$form->setDefaults($form_settings); |
||||
|
||||
$plugin_info['settings_form'] = $form; |
@ -0,0 +1,26 @@ |
||||
<?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'); |
||||
|
||||
global $DB; |
||||
$DB = new DatabaseManager(); |
||||
|
||||
$action = $_GET['what']; |
||||
define('CHAMILO_INTERNAL', true); |
||||
|
||||
$plugininstance = VChamiloPlugin::create(); |
||||
$thisurl = api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php'; |
||||
|
||||
api_protect_admin_script(); |
||||
|
||||
if ($action == 'syncthis') { |
||||
$res = include_once(api_get_path(SYS_PLUGIN_PATH).'vchamilo/views/syncparams.controller.php'); |
||||
if (!$res) { |
||||
echo '<span class="ok">Success</span>'; |
||||
} else { |
||||
echo '<span class="failed">Failure<br/>'.$errors.'</span>'; |
||||
} |
||||
} |
@ -0,0 +1,218 @@ |
||||
<?php |
||||
|
||||
global $debuglevel; |
||||
global $debugdisplay; |
||||
$debuglevel = 4; |
||||
$debugdisplay = 4; |
||||
|
||||
define('CLI_SCRIPT', true); |
||||
define('CHAMILO_INTERNAL', true); |
||||
|
||||
// this will only run on master chamilo |
||||
echo "Starting tool\n"; |
||||
echo "Chamilo Bulk Nodes Creation v.1.0\n"; |
||||
echo "=================================\n"; |
||||
require_once('../../../main/inc/global.inc.php'); |
||||
require_once('clilib.php'); // cli only functions |
||||
// Ensure errors are well explained |
||||
ini_set('debug_display', 1); |
||||
ini_set('debug_level', E_ALL); |
||||
|
||||
// now get cli options |
||||
list($options, $unrecognized) = cli_get_params( |
||||
array( |
||||
'interactive' => false, |
||||
'help' => false, |
||||
'config' => false, |
||||
'nodes' => '', |
||||
'lint' => false, |
||||
'verbose' => false |
||||
), |
||||
array( |
||||
'h' => 'help', |
||||
'i' => 'interactive', |
||||
'c' => 'config', |
||||
'n' => 'nodes', |
||||
'l' => 'lint', |
||||
'v' => 'verbose' |
||||
) |
||||
); |
||||
|
||||
$interactive = !empty($options['interactive']); |
||||
|
||||
if ($unrecognized) { |
||||
$unrecognized = implode("\n ", $unrecognized); |
||||
cli_error("Cli unkown options\n".$unrecognized); |
||||
} |
||||
|
||||
if ($options['help']) { |
||||
$help = "Command line VChamilo Generator. |
||||
Please note you must execute this script with the same uid as apache! |
||||
|
||||
Options: |
||||
--interactive Blocks on each step and waits for input to continue |
||||
-h, --help Print out this help |
||||
-c, --config Define an external config file |
||||
-n, --nodes A node descriptor CSV file |
||||
-l, --lint Decodes node file and give a report on nodes to be created. |
||||
|
||||
Example: |
||||
\$sudo -u www-data /usr/bin/php /var/www/chamilo/plugin/vchamilo/cli/bulkcreatenodes.php --nodes=<nodelist> |
||||
"; //TODO: localize - to be translated later when everything is finished |
||||
|
||||
echo $help; |
||||
die; |
||||
} |
||||
|
||||
// Get all options from config file. |
||||
|
||||
if (!empty($options['config'])) { |
||||
echo "Loading config : ".$options['config']; |
||||
if (!file_exists($options['config'])){ |
||||
cli_error('Config file mentioned but not found'); |
||||
} |
||||
|
||||
$content = file($options['config']); |
||||
foreach($content as $l) { |
||||
if (preg_match('/^\s+$/', $l)) continue; // Empty lines. |
||||
if (preg_match('/^[#\/!;]/', $l)) continue; // Comments (any form). |
||||
if (preg_match('/^(.*?)=(.*)$/', $l, $matches)) { |
||||
if (in_array($matches[1], $expectedoptions)){ |
||||
$options[trim($matches[1])] = trim($matches[2]); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
require_once($_configuration['root_sys'].'local/classes/database.class.php'); // cli only functions |
||||
require_once($_configuration['root_sys'].'local/classes/textlib.class.php'); // cli only functions |
||||
require_once($_configuration['root_sys'].'local/classes/mootochamlib.php'); // moodle like API |
||||
require_once($_configuration['root_sys'] . '/plugin/vchamilo/lib/vchamilo_plugin.class.php'); |
||||
|
||||
global $DB; |
||||
if ($options['verbose']) echo "building database manager\n"; |
||||
$DB = new DatabaseManager(); |
||||
if ($options['verbose']) echo "building plugin vchamilo\n"; |
||||
$plugininstance = VChamiloPlugin::create(); |
||||
|
||||
if (empty($options['nodes'])) { |
||||
cli_error('Missing node definition. Halt.'); |
||||
} |
||||
|
||||
if ($options['verbose']) echo "parsing nodelist\n"; |
||||
$nodes = vchamilo_parse_csv_nodelist($options['nodes'], $plugininstance); |
||||
|
||||
if ($options['lint']) { |
||||
ctrace("Lint mode:\n"); |
||||
print_object($nodes); |
||||
die; |
||||
} |
||||
|
||||
if (empty($nodes)) { |
||||
cli_error('Node list empty'); |
||||
} |
||||
|
||||
ctrace('Starting generation'); |
||||
|
||||
// Get main admin for further replacement. |
||||
$admin = $DB->get_record('user', array('username' => 'admin')); |
||||
|
||||
foreach($nodes as $data) { |
||||
|
||||
ctrace('Making node '.$data->root_web); |
||||
|
||||
if (!empty($data->template)) { |
||||
ctrace('Using template '.$data->template); |
||||
|
||||
if (!vchamilo_template_exists($data->template)) { |
||||
ctrace('Template not found. Skipping node.'); |
||||
continue; |
||||
} |
||||
} |
||||
|
||||
if ($DB->get_record('vchamilo', array('root_web' => $data->root_web))) { |
||||
ctrace('Node exists. skipping'); |
||||
continue; |
||||
} |
||||
|
||||
$data->what = 'addinstance'; |
||||
$data->registeronly = false; |
||||
|
||||
$NDB = null; |
||||
|
||||
$automation = true; |
||||
$return = include($_configuration['root_sys'].'plugin/vchamilo/views/editinstance.controller.php'); |
||||
if ($return == -1) { |
||||
cli_error('Node create process error'); |
||||
} |
||||
|
||||
// This is specific code for presetting any plugin data per instance from the CSV |
||||
ctrace('Setting up ent_installer'); |
||||
if ($NDB) { |
||||
// Copy admin account info from master |
||||
$NDB->set_field('user', 'password', $admin->password, array('username' => 'admin'), 'user_id'); |
||||
|
||||
// Setting ENT_installer values |
||||
if (!empty($data->ent_installer)) { |
||||
foreach ($data->ent_installer as $setting => $value) { |
||||
$settingrec = new StdClass(); |
||||
$settingrec->variable = 'ent_installer_'.$setting; |
||||
$settingrec->subkey = 'ent_installer'; |
||||
$settingrec->type = 'setting'; |
||||
$settingrec->category = 'Plugins'; |
||||
$settingrec->access_url = 1; |
||||
$settingrec->selected_value = $value; |
||||
ctrace("Setting up {$settingrec->variable}|{$settingrec->subkey} to $value\n"); |
||||
if ($oldrec = $NDB->get_record('settings_current', array('variable' => $settingrec->variable, 'subkey' => $settingrec->subkey, 'type' => $settingrec->type))){ |
||||
$settingrec->id = $oldrec->id; |
||||
$NDB->update_record('settings_current', $settingrec, 'id'); |
||||
} else { |
||||
$NDB->insert_record('settings_current', $settingrec); |
||||
} |
||||
} |
||||
} |
||||
|
||||
// updating other config values |
||||
if (!empty($data->config)) { |
||||
ctrace("VChamilo has config overrides\n"); |
||||
foreach ($data->config as $configkey => $configsetting) { |
||||
ctrace("Setting up {$configkey}"); |
||||
// Note you can just alter existing settings here as we cannot pull enough data from csv headers to get a complete setting descriptor. |
||||
$settingrec = new StdClass(); |
||||
$settingrec->variable = $configkey; |
||||
if (!empty($settingrec->subkey)) { |
||||
$settingrec->subkey = $configsetting->subkey; |
||||
} |
||||
// $settingrec->type = 'setting'; |
||||
// $settingrec->category = 'Plugins'; |
||||
// $settingrec->access_url = 1; |
||||
$settingrec->selected_value = $configsetting->value; |
||||
|
||||
if (!empty($settingrec->subkey)) { |
||||
$params = array('variable' => $settingrec->variable, 'subkey' => $settingrec->subkey); |
||||
} else { |
||||
$params = array('variable' => $settingrec->variable); |
||||
} |
||||
|
||||
if ($oldrec = $NDB->get_record('settings_current', $params)) { |
||||
ctrace("Updating {$settingrec->variable}|{$settingrec->subkey} to $configsetting->value\n"); |
||||
$settingrec->id = $oldrec->id; |
||||
$NDB->update_record('settings_current', $settingrec, 'id'); |
||||
} |
||||
} |
||||
} |
||||
$NDB->dismount(); |
||||
} else { |
||||
ctrace('No Side CNX for setup'); |
||||
} |
||||
|
||||
if ($interactive) { |
||||
$input = readline("Continue (y/n|r) ?\n"); |
||||
if ($input == 'r' || $input == 'R'){ |
||||
// do nothing, just continue |
||||
} elseif ($input == 'n' || $input == 'N'){ |
||||
echo "finishing\n"; |
||||
exit; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,155 @@ |
||||
<?php |
||||
/** |
||||
* This script is to be used from PHP command line and will create a set |
||||
* of Virtual VChamilo automatically from a CSV nodelist description. |
||||
* The standard structure of the nodelist is given by the nodelist-dest.csv file. |
||||
*/ |
||||
|
||||
global $debuglevel; |
||||
global $debugdisplay; |
||||
$debuglevel = 4; |
||||
$debugdisplay = 4; |
||||
|
||||
define('CLI_SCRIPT', true); |
||||
define('CHAMILO_INTERNAL', true); |
||||
|
||||
// this will only run on master chamilo |
||||
echo "Starting tool\n"; |
||||
echo "Chamilo Bulk Nodes Creation v.1.0\n"; |
||||
echo "=================================\n"; |
||||
require_once('../../../main/inc/global.inc.php'); |
||||
require_once('clilib.php'); // cli only functions |
||||
// Ensure errors are well explained |
||||
ini_set('debug_display', 1); |
||||
ini_set('debug_level', E_ALL); |
||||
|
||||
// Now get cli options. |
||||
list($options, $unrecognized) = cli_get_params( |
||||
array( |
||||
'interactive' => false, |
||||
'help' => false, |
||||
'config' => false, |
||||
'nodes' => '', |
||||
'lint' => false |
||||
), |
||||
array( |
||||
'h' => 'help', |
||||
'c' => 'config', |
||||
'n' => 'nodes', |
||||
'i' => 'interactive', |
||||
'l' => 'lint' |
||||
) |
||||
); |
||||
|
||||
$interactive = !empty($options['interactive']); |
||||
|
||||
if ($unrecognized) { |
||||
$unrecognized = implode("\n ", $unrecognized); |
||||
cli_error(get_string('cliunknowoption', 'admin', $unrecognized)); |
||||
} |
||||
|
||||
if ($options['help']) { |
||||
$help = |
||||
"Command line VMoodle Generator. |
||||
Please note you must execute this script with the same uid as apache! |
||||
|
||||
Options: |
||||
--interactive No interactive questions or confirmations |
||||
-h, --help Print out this help |
||||
-c, --config Define an external config file |
||||
-n, --nodes A node descriptor CSV file |
||||
-l, --lint Decodes node file and give a report on nodes to be created. |
||||
|
||||
Example: |
||||
\$sudo -u www-data /usr/bin/php /var/www/chamilo19/plugin/vchamilo/cli/bulkdestroynodes.php --nodes=<node-file-path> |
||||
"; //TODO: localize - to be translated later when everything is finished |
||||
|
||||
echo $help; |
||||
die; |
||||
} |
||||
|
||||
// Get all options from config file. |
||||
if (!empty($options['config'])) { |
||||
echo "Loading config : ".$options['config']; |
||||
if (!file_exists($options['config'])) { |
||||
cli_error(get_string('confignotfound', 'block_vmoodle')); |
||||
} |
||||
$content = file($options['config']); |
||||
foreach ($content as $l) { |
||||
if (preg_match('/^\s+$/', $l)) { |
||||
continue; // Empty lines. |
||||
} |
||||
if (preg_match('/^[#\/!;]/', $l)) { |
||||
continue; // Comments (any form). |
||||
} |
||||
if (preg_match('/^(.*?)=(.*)$/', $l, $matches)) { |
||||
if (in_array($matches[1], $expectedoptions)) { |
||||
$options[trim($matches[1])] = trim($matches[2]); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
require_once($_configuration['root_sys'].'local/classes/database.class.php'); // cli only functions |
||||
if ($options['verbose']) echo "loaded dbclass\n"; |
||||
require_once($_configuration['root_sys'].'local/classes/textlib.class.php'); // cli only functions |
||||
if ($options['verbose']) echo "loaded textlib\n"; |
||||
require_once($_configuration['root_sys'].'local/classes/mootochamlib.php'); // moodle like API |
||||
if ($options['verbose']) echo "loaded moodle wrapping\n"; |
||||
require_once($_configuration['root_sys'] . '/plugin/vchamilo/lib/vchamilo_plugin.class.php'); |
||||
if ($options['verbose']) echo "loaded vchamilo plugin\n"; |
||||
|
||||
global $DB; |
||||
if ($options['verbose']) echo "building database manager\n"; |
||||
$DB = new DatabaseManager(); |
||||
if ($options['verbose']) echo "building plugin vchamilo\n"; |
||||
$plugininstance = VChamiloPlugin::create(); |
||||
|
||||
if (empty($options['nodes'])) { |
||||
cli_error(get_string('climissingnodes', 'block_vmoodle')); |
||||
} |
||||
|
||||
if ($options['verbose']) echo "parsing nodelist\n"; |
||||
$nodes = vchamilo_parse_csv_nodelist($options['nodes'], $plugininstance); |
||||
|
||||
if ($options['lint']) { |
||||
ctrace("Lint mode:\n"); |
||||
print_object($nodes); |
||||
die; |
||||
} |
||||
|
||||
if (empty($nodes)) { |
||||
cli_error(get_string('cliemptynodelist', 'block_vmoodle')); |
||||
} |
||||
|
||||
ctrace('Starting CLI processing'); |
||||
|
||||
foreach ($nodes as $n) { |
||||
|
||||
ctrace('Destroying node :'.$n->vhostname); |
||||
|
||||
if (!$DB->get_record('vchamilo', array('root_web' => $n->root_web))) { |
||||
ctrace('Node does not exist. Skipping'); |
||||
continue; |
||||
} |
||||
|
||||
/* |
||||
* This launches automatically all steps of the controller.management.php script several times |
||||
* with the "doadd" action and progressing in steps. |
||||
*/ |
||||
$action = "fulldeleteinstances"; |
||||
|
||||
$automation = true; |
||||
|
||||
$return = include($_configuration['root_sys'].'/plugin/vchamilo/views/manage.controller.php'); |
||||
if ($interactive) { |
||||
$input = readline("Continue (y/n|r) ?\n"); |
||||
if ($input == 'r' || $input == 'R') { |
||||
$vmoodlestep--; |
||||
} elseif ($input == 'n' || $input == 'N') { |
||||
echo "finishing\n"; |
||||
exit(0); |
||||
} |
||||
} |
||||
} |
||||
exit (0); |
@ -0,0 +1,12 @@ |
||||
rm -rf /app/www/chamilo19-ene-atrium/courses-lgt-* |
||||
rm -rf /app/www/chamilo19-ene-atrium/courses-lp-* |
||||
rm -rf /app/www/chamilo19-ene-atrium/archive/lp-* |
||||
rm -rf /app/www/chamilo19-ene-atrium/archive/lgt-* |
||||
rm -rf /app/www/chamilo19-ene-atrium/home/lp-* |
||||
rm -rf /app/www/chamilo19-ene-atrium/home/lgt-* |
||||
rm -rf /data/chamilodata/courses-lp-* |
||||
rm -rf /data/chamilodata/courses-lgt-* |
||||
rm -rf /data/chamilodata/home/lp-* |
||||
rm -rf /data/chamilodata/home/lgt-* |
||||
rm -rf /data/chamilodata/archives/lp-* |
||||
rm -rf /data/chamilodata/archives/lgt-* |
@ -0,0 +1,337 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Opens and parses/checks a VChamilo instance definition file |
||||
* @param string $location |
||||
* |
||||
*/ |
||||
function vchamilo_parse_csv_nodelist($nodelistlocation = '', $plugin = null){ |
||||
global $_configuration; |
||||
|
||||
$vnodes = array(); |
||||
|
||||
if (empty($nodelistlocation)){ |
||||
$nodelistlocation = $_configuratioh['root_sys'].'/plugin/vchamilo/nodelist.csv'; |
||||
} |
||||
|
||||
// decode file |
||||
$csv_delimiter = "\;"; |
||||
$csv_delimiter2 = ";"; |
||||
|
||||
// make arrays of valid fields for error checking |
||||
$required = array('root_web' => 1, |
||||
'sitename' => 1, |
||||
'institution' => 1, |
||||
'main_database' => 1, |
||||
'statistics_database' => 1, |
||||
'user_personal_database' => 1, |
||||
'db_user' => 1, |
||||
'db_password' => 1, |
||||
'course_folder' => 1, |
||||
); |
||||
|
||||
$optional = array( |
||||
'db_host' => 1, |
||||
'template' => 1, |
||||
'table_prefix' => 1, |
||||
'single_database' => 1, |
||||
'tracking_enabled' => 1, |
||||
'visible' => 1, |
||||
); |
||||
|
||||
$optionalDefaults = array( |
||||
'db_host' => $_configuration['db_host'], |
||||
'db_prefix' => 'chm_', |
||||
'table_prefix' => '', |
||||
'tracking_enabled' => 0, |
||||
'single_database' => 1, |
||||
'template' => '', |
||||
'visible' => 1, |
||||
); |
||||
|
||||
$patterns = array(); |
||||
|
||||
// Metas are accepted patterns (optional) |
||||
$metas = array( |
||||
'plugin_.*', |
||||
'config_.*' |
||||
); |
||||
|
||||
// Get header (field names) |
||||
|
||||
$textlib = new textlib(); |
||||
|
||||
if (!$fp = fopen($nodelistlocation, 'rb')) { |
||||
cli_error($plugin->get_lang('badnodefile', 'vchamilo', $nodelistlocation)); |
||||
} |
||||
|
||||
// Jump any empty or comment line |
||||
$text = fgets($fp, 1024); |
||||
$i = 0; |
||||
while(vchamilo_is_empty_line_or_format($text, $i == 0)){ |
||||
$text = fgets($fp, 1024); |
||||
$i++; |
||||
} |
||||
|
||||
$headers = explode($csv_delimiter2, $text); |
||||
|
||||
// Check for valid field names |
||||
foreach ($headers as $h) { |
||||
$header[] = trim($h); |
||||
$patternized = implode('|', $patterns) . "\\d+"; |
||||
$metapattern = implode('|', $metas); |
||||
if (!(isset($required[$h]) || |
||||
isset($optionalDefaults[$h]) || |
||||
isset($optional[$h]) || |
||||
preg_match("/$patternized/", $h) || |
||||
preg_match("/$metapattern/", $h))) { |
||||
cli_error("Node parse : invalidfieldname $h "); |
||||
return; |
||||
} |
||||
|
||||
if (isset($required[trim($h)])) { |
||||
$required[trim($h)] = 0; |
||||
} |
||||
} |
||||
|
||||
$expectedcols = count($headers); |
||||
$i++; |
||||
|
||||
// Check for required fields. |
||||
foreach ($required as $key => $value) { |
||||
if ($value) { // Required field missing. |
||||
cli_error("fieldrequired $key"); |
||||
return; |
||||
} |
||||
} |
||||
$linenum = 2; // Since header is line 1. |
||||
|
||||
// Take some from admin profile, other fixed by hardcoded defaults. |
||||
while (!feof ($fp)) { |
||||
|
||||
// Make a new base record. |
||||
$vnode = new StdClass(); |
||||
foreach ($optionalDefaults as $key => $value) { |
||||
$vnode->$key = $value; |
||||
} |
||||
|
||||
//Note: commas within a field should be encoded as , (for comma separated csv files) |
||||
//Note: semicolon within a field should be encoded as ; (for semicolon separated csv files) |
||||
$text = fgets($fp, 1024); |
||||
if (vchamilo_is_empty_line_or_format($text, false)) { |
||||
$i++; |
||||
continue; |
||||
} |
||||
|
||||
$valueset = explode($csv_delimiter2, $text); |
||||
if (count($valueset) != $expectedcols) { |
||||
cli_error('wrong line count at line '.$i); |
||||
} |
||||
$f = 0; |
||||
foreach ($valueset as $value) { |
||||
// Decode encoded commas. |
||||
$key = $headers[$f]; |
||||
if (preg_match('/\|/', $key)) { |
||||
list($plugin, $variable) = explode('|', str_replace('plugin_', '', $key)); |
||||
if (empty($variable)) die("Key error in CSV : $key "); |
||||
if (!isset($vnode->$plugin)) { |
||||
$vnode->$plugin = new StdClass(); |
||||
} |
||||
$vnode->$plugin->$variable = trim($value); |
||||
} else { |
||||
if (preg_match('/^config_/', $key)) { |
||||
$smartkey = str_replace('config_', '', $key); |
||||
$keyparts = implode('|', $smartkey); |
||||
$keyvar = $keyparts[0]; |
||||
$subkey = @$keyparts[1]; |
||||
$vnode->config->$smartkey = new StdClass; |
||||
$vnode->config->$smartkey->subkey = $subkey; |
||||
$vnode->config->$smartkey->value = trim($value); |
||||
} else { |
||||
$vnode->$key = trim($value); |
||||
} |
||||
} |
||||
$f++; |
||||
} |
||||
$vnodes[] = $vnode; |
||||
} |
||||
|
||||
return $vnodes; |
||||
} |
||||
|
||||
/** |
||||
* Check a CSV input line format for empty or commented lines |
||||
* Ensures compatbility to UTF-8 BOM or unBOM formats |
||||
*/ |
||||
function vchamilo_is_empty_line_or_format(&$text, $resetfirst = false) { |
||||
global $CFG; |
||||
|
||||
static $textlib; |
||||
static $first = true; |
||||
|
||||
// We may have a risk the BOM is present on first line |
||||
if ($resetfirst) $first = true; |
||||
if (!isset($textlib)) $textlib = new textlib(); // Singleton |
||||
$text = $textlib->trim_utf8_bom($text); |
||||
$first = false; |
||||
|
||||
$text = preg_replace("/\n?\r?/", '', $text); |
||||
|
||||
// last chance |
||||
if ('ASCII' == mb_detect_encoding($text)) { |
||||
$text = utf8_encode($text); |
||||
} |
||||
|
||||
// Check the text is empty or comment line and answer true if it is. |
||||
return preg_match('/^$/', $text) || preg_match('/^(\(|\[|-|#|\/| )/', $text); |
||||
} |
||||
|
||||
/** |
||||
* Get input from user |
||||
* @param string $prompt text prompt, should include possible options |
||||
* @param string $default default value when enter pressed |
||||
* @param array $options list of allowed options, empty means any text |
||||
* @param bool $casesensitive true if options are case sensitive |
||||
* @return string entered text |
||||
*/ |
||||
function cli_input($prompt, $default='', array $options=null, $casesensitiveoptions=false) { |
||||
echo $prompt; |
||||
echo "\n: "; |
||||
$input = fread(STDIN, 2048); |
||||
$input = trim($input); |
||||
if ($input === '') { |
||||
$input = $default; |
||||
} |
||||
if ($options) { |
||||
if (!$casesensitiveoptions) { |
||||
$input = strtolower($input); |
||||
} |
||||
if (!in_array($input, $options)) { |
||||
echo "Incorrect value, please retry.\n"; // TODO: localize, mark as needed in install |
||||
return cli_input($prompt, $default, $options, $casesensitiveoptions); |
||||
} |
||||
} |
||||
return $input; |
||||
} |
||||
|
||||
/** |
||||
* Returns cli script parameters. |
||||
* @param array $longoptions array of --style options ex:('verbose'=>false) |
||||
* @param array $shortmapping array describing mapping of short to long style options ex:('h'=>'help', 'v'=>'verbose') |
||||
* @return array array of arrays, options, unrecognised as optionlongname=>value |
||||
*/ |
||||
function cli_get_params(array $longoptions, array $shortmapping=null) { |
||||
$shortmapping = (array)$shortmapping; |
||||
$options = array(); |
||||
$unrecognized = array(); |
||||
|
||||
if (empty($_SERVER['argv'])) { |
||||
// Bad luck, we can continue in interactive mode ;-) |
||||
return array($options, $unrecognized); |
||||
} |
||||
$rawoptions = $_SERVER['argv']; |
||||
|
||||
// Remove anything after '--', options can not be there. |
||||
if (($key = array_search('--', $rawoptions)) !== false) { |
||||
$rawoptions = array_slice($rawoptions, 0, $key); |
||||
} |
||||
|
||||
// Remove script. |
||||
unset($rawoptions[0]); |
||||
foreach ($rawoptions as $raw) { |
||||
if (substr($raw, 0, 2) === '--') { |
||||
$value = substr($raw, 2); |
||||
$parts = explode('=', $value); |
||||
if (count($parts) == 1) { |
||||
$key = reset($parts); |
||||
$value = true; |
||||
} else { |
||||
$key = array_shift($parts); |
||||
$value = implode('=', $parts); |
||||
} |
||||
if (array_key_exists($key, $longoptions)) { |
||||
$options[$key] = $value; |
||||
} else { |
||||
$unrecognized[] = $raw; |
||||
} |
||||
|
||||
} else if (substr($raw, 0, 1) === '-') { |
||||
$value = substr($raw, 1); |
||||
$parts = explode('=', $value); |
||||
if (count($parts) == 1) { |
||||
$key = reset($parts); |
||||
$value = true; |
||||
} else { |
||||
$key = array_shift($parts); |
||||
$value = implode('=', $parts); |
||||
} |
||||
if (array_key_exists($key, $shortmapping)) { |
||||
$options[$shortmapping[$key]] = $value; |
||||
} else { |
||||
$unrecognized[] = $raw; |
||||
} |
||||
} else { |
||||
$unrecognized[] = $raw; |
||||
continue; |
||||
} |
||||
} |
||||
// Apply defaults. |
||||
foreach ($longoptions as $key=>$default) { |
||||
if (!array_key_exists($key, $options)) { |
||||
$options[$key] = $default; |
||||
} |
||||
} |
||||
// Finished. |
||||
return array($options, $unrecognized); |
||||
} |
||||
|
||||
/** |
||||
* Print or return section separator string |
||||
* @param bool $return false means print, true return as string |
||||
* @return mixed void or string |
||||
*/ |
||||
function cli_separator($return=false) { |
||||
$separator = str_repeat('-', 79)."\n"; |
||||
if ($return) { |
||||
return $separator; |
||||
} else { |
||||
echo $separator; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Print or return section heading string |
||||
* @param string $string text |
||||
* @param bool $return false means print, true return as string |
||||
* @return mixed void or string |
||||
*/ |
||||
function cli_heading($string, $return=false) { |
||||
$string = "== $string ==\n"; |
||||
if ($return) { |
||||
return $string; |
||||
} else { |
||||
echo $string; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Write error notification |
||||
* @param $text |
||||
* @return void |
||||
*/ |
||||
function cli_problem($text) { |
||||
fwrite(STDERR, $text."\n"); |
||||
} |
||||
|
||||
/** |
||||
* Write to standard out and error with exit in error. |
||||
* |
||||
* @param string $text |
||||
* @param int $errorcode |
||||
* @return void (does not return) |
||||
*/ |
||||
function cli_error($text, $errorcode = 1) { |
||||
fwrite(STDERR, $text); |
||||
fwrite(STDERR, "\n"); |
||||
die($errorcode); |
||||
} |
@ -0,0 +1,75 @@ |
||||
<?php |
||||
/** |
||||
* This script should be called by a properly set cron process on your server. |
||||
* For more information, check the installation guide in the documentation |
||||
* folder. |
||||
* Add your own executable scripts below the inclusion of notification.php |
||||
* @package chamilo.cron |
||||
*/ |
||||
/** |
||||
* Settings that will influence the execution of the cron tasks |
||||
*/ |
||||
//ini_set('max_execution_time',300); //authorize execution for up to 5 minutes |
||||
//ini_set('memory_limit','100M'); //authorize script to use up to 100M RAM |
||||
/** |
||||
* Included cron-ed tasks. You might want to turn error-logging off by |
||||
* commenting the first and last line of this section. |
||||
*/ |
||||
|
||||
define('CLI_SCRIPT', true); // for chamilo imported code |
||||
define('CHAMILO_INTERNAL', true); |
||||
global $CLI_VCHAMILO_PRECHECK; |
||||
|
||||
$CLI_VCHAMILO_PRECHECK = true; // force first config to be minimal |
||||
require(dirname(dirname(dirname(dirname(__FILE__)))).'/main/inc/conf/configuration.php'); // get boot config |
||||
require_once($_configuration['root_sys'].'plugin/vchamilo/cli/clilib.php'); // cli only functions |
||||
|
||||
// Ensure errors are well explained |
||||
|
||||
// now get cli options |
||||
list($options, $unrecognized) = cli_get_params( |
||||
array( |
||||
'help' => false, |
||||
'host' => false, |
||||
), |
||||
array( |
||||
'h' => 'help', |
||||
'H' => 'host' |
||||
) |
||||
); |
||||
|
||||
if ($unrecognized) { |
||||
$unrecognized = implode("\n ", $unrecognized); |
||||
cli_error(get_string('cliunknowoption', 'admin', $unrecognized)); |
||||
} |
||||
|
||||
if ($options['help']) { |
||||
$help = |
||||
"Command line chamilo CRON |
||||
|
||||
Options: |
||||
-h, --help Print out this help |
||||
-H, --host Set the host (physical or virtual) to operate on |
||||
|
||||
"; //TODO: localize - to be translated later when everything is finished |
||||
|
||||
echo $help; |
||||
die; |
||||
} |
||||
|
||||
if (!empty($options['host'])) { |
||||
// arms the vchamilo switching |
||||
echo('Arming for '.$options['host']."\n"); // mtrace not yet available. |
||||
define('CLI_VCHAMILO_OVERRIDE', $options['host']); |
||||
} |
||||
// replay full config whenever. If vchamilo switch is armed, will switch now config |
||||
require($_configuration['root_sys'].'main/inc/conf/configuration.php'); // do REALLY force configuration to play again, or the following call will not have config twicked (require_once) |
||||
echo('Config check : playing for '.$_configuration['root_web']."\n"); |
||||
|
||||
error_log('[chamilo][cronjob] Starting cron jobs as process '.getmypid()); |
||||
echo '<pre>'; |
||||
echo ('[chamilo][cronjob] Starting cron jobs as process '.getmypid()."\n"); |
||||
require_once $_configuration['root_sys'].'main/cron/notification.php'; |
||||
error_log('[chamilo][cronjob] Ending cron jobs of process '.getmypid()); |
||||
echo('[chamilo][cronjob] Ending cron jobs of process '.getmypid()."\n"); |
||||
echo '</pre>'; |
@ -0,0 +1,22 @@ |
||||
<?php |
||||
/** |
||||
* This script should be called by a properly set cron process on your server. |
||||
* For more information, check the installation guide in the documentation |
||||
* folder. |
||||
* Add your own executable scripts below the inclusion of notification.php |
||||
* @package chamilo.cron |
||||
*/ |
||||
/** |
||||
* Settings that will influence the execution of the cron tasks |
||||
*/ |
||||
//ini_set('max_execution_time',300); //authorize execution for up to 5 minutes |
||||
//ini_set('memory_limit','100M'); //authorize script to use up to 100M RAM |
||||
/** |
||||
* Included cron-ed tasks. You might want to turn error-logging off by |
||||
* commenting the first and last line of this section. |
||||
*/ |
||||
define('CLI_SCRIPT', true); // for chamilo imported code |
||||
define('CHAMILO_INTERNAL', true); |
||||
error_log('[chamilo][cronjob] Starting cron jobs as process '.getmypid()); |
||||
require_once(dirname(dirname(dirname(dirname(__FILE__)))).'/main/cron/notification.php'); |
||||
error_log('[chamilo][cronjob] Ending cron jobs of process '.getmypid()); |
|
|
|
|
|
|
@ -0,0 +1,38 @@ |
||||
<?php |
||||
/** |
||||
* @package chamilo.plugin.vchamilo |
||||
*/ |
||||
|
||||
require_once api_get_path(LIBRARY_PATH) . 'plugin.class.php'; |
||||
require_once dirname(__FILE__).'/lib/vchamilo_plugin.class.php'; |
||||
|
||||
global $VCHAMILO; |
||||
|
||||
$plugininstance = VChamiloPlugin::create(); |
||||
|
||||
// See also the share_user_info plugin |
||||
|
||||
$_template['show_message'] = true; |
||||
$_template['title'] = $plugininstance->get_lang('hostlist'); |
||||
|
||||
$tablename = Database::get_main_table('vchamilo'); |
||||
$sql = " |
||||
SELECT |
||||
sitename, |
||||
root_web |
||||
FROM |
||||
$tablename |
||||
WHERE |
||||
visible = 1 |
||||
"; |
||||
|
||||
if ($VCHAMILO == '%'){ |
||||
$result = Database::query($sql); |
||||
$_template['hosts'] = array(); |
||||
if ($result){ |
||||
while($vchamilo = Database::fetch_assoc($result)){ |
||||
$_template['hosts'][] = $vchamilo; |
||||
} |
||||
} |
||||
} else { |
||||
} |
@ -0,0 +1,68 @@ |
||||
<?php |
||||
/* PHP code to install the plugin |
||||
* For example: |
||||
* |
||||
// To query something to the database |
||||
|
||||
$table = Database::get_main_table(TABLE_MAIN_USER); // TABLE_MAIN_USER is a constant check the main/inc/database.constants.inc.php |
||||
$sql = "SELECT firstname, lastname FROM $table_users "; |
||||
$users = Database::query($sql); |
||||
|
||||
You can also use the Chamilo classes |
||||
$users = UserManager::get_user_list(); |
||||
|
||||
*/ |
||||
|
||||
$table = 'vchamilo'; |
||||
$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, |
||||
`institution` varchar(80) NOT NULL, |
||||
`root_web` varchar(120), |
||||
|
||||
`db_host` varchar(80) NOT NULL, |
||||
`db_user` varchar(16) DEFAULT 'root', |
||||
`db_password` varchar(32), |
||||
`tracking_enabled` int(1) DEFAULT 0, |
||||
`single_database` int(1) DEFAULT 1, |
||||
`table_prefix` varchar(16), |
||||
`db_prefix` varchar(16), |
||||
`main_database` varchar(60) DEFAULT 'chamilo', |
||||
`statistics_database` varchar(60) DEFAULT 'chamilo', |
||||
`user_personal_database` varchar(60) DEFAULT 'chamilo', |
||||
|
||||
`url_append` varchar(32), |
||||
`course_folder` varchar(80), |
||||
`visible` int(1), |
||||
`lastcrongap` int(11), |
||||
`lastcron` int(11), |
||||
`croncount` int(11), |
||||
|
||||
PRIMARY KEY (`id`) |
||||
) DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; |
||||
"; |
||||
Database::query($sql); |
||||
|
||||
$table = 'vchamilo_config'; |
||||
$tablename = Database::get_main_table($table); |
||||
$sql = "CREATE TABLE IF NOT EXISTS $tablename ( |
||||
`id` int(11) NOT NULL AUTO_INCREMENT, |
||||
`component` int(11) NOT NULL, |
||||
`name` varchar(64) NOT NULL, |
||||
`value` varchar(255) NOT NULL, |
||||
`longvalue` varchar(255) NOT NULL, |
||||
PRIMARY KEY (id) |
||||
) |
||||
"; |
||||
Database::query($sql); |
||||
|
||||
api_add_setting(0, 'vchamilo_cron_lasthost', 'vchamilo', 'setting', 'Plugins'); |
||||
api_add_setting(0, 'vchamilo_vcrontime', 'vchamilo', 'setting', 'Plugins'); |
||||
api_add_setting(0, 'vchamilo_vcrontickperiod', 'vchamilo', 'setting', 'Plugins'); |
||||
|
||||
// create root storage directory for templates |
||||
global $_configuration; |
||||
if (!is_dir($_configuration['root_sys'].'plugin/vchamilo/templates')){ |
||||
mkdir($_configuration['root_sys'].'plugin/vchamilo/templates', 0777, true); |
||||
} |
@ -0,0 +1,18 @@ |
||||
|
||||
function ajax_sync_setting(wwwroot, settingid) { |
||||
|
||||
spare = $('#row_'+settingid).html(); |
||||
formobj = document.forms['settingsform']; |
||||
|
||||
url = wwwroot+'plugin/vchamilo/ajax/service.php?what=syncthis&settingid='+settingid+'&value='+encodeURIComponent(formobj.elements['value_'+settingid].value); |
||||
if (formobj.elements['del_'+settingid].checked) { |
||||
url += '&del=1'; |
||||
} |
||||
|
||||
$('#row_'+settingid).html('<td colspan="7"><img src="'+wwwroot+'plugin/vchamilo/pix/ajax_waiter.gif" /></td>'); |
||||
|
||||
$.get(url, function (data) { |
||||
$('#row_'+settingid).html(spare); |
||||
$('#res_'+settingid).html(data); |
||||
} ); |
||||
} |
@ -0,0 +1,86 @@ |
||||
/** |
||||
* 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; |
||||
var dbpass = document.getElementById('id_vdbpassword').value; |
||||
|
||||
// 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;
|
||||
} |
||||
|
||||
/** |
||||
* Pop-up testing connection with database. |
||||
*/ |
||||
function opendatapathpopup(webroot) { |
||||
|
||||
// Input data.
|
||||
var datapath = document.getElementById('id_vdatapath').value; |
||||
|
||||
// PHP file linked the pop-up, and name.
|
||||
var url = webroot + "/plugin/vchamilo/views/manage.testdatapath.php?dataroot=" + escape(datapath); |
||||
|
||||
// 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_testdatapath;
|
||||
} |
||||
|
||||
/** |
||||
* Activates/desactivates services selection. |
||||
*/ |
||||
function switcherServices(mnetnewsubnetwork) { |
||||
|
||||
// Retrieve 'select' elements from form.
|
||||
var mnetenabled = document.getElementById('id_mnetenabled'); |
||||
var multimnet = document.getElementById('id_multimnet'); |
||||
var services = document.getElementById('id_services'); |
||||
|
||||
// Default values for services.
|
||||
var mnetfreedefault = '0'; |
||||
var defaultservices = 'default'; |
||||
var subnetworkservices = 'subnetwork'; |
||||
|
||||
// Do the actions.
|
||||
if (multimnet.value == mnetfreedefault |
||||
|| multimnet.value == mnetnewsubnetwork) { |
||||
services.value = defaultservices; |
||||
services.disabled = true; |
||||
} else { |
||||
services.disabled = false; |
||||
services.value = subnetworkservices; |
||||
} |
||||
} |
||||
|
||||
function syncSchema(){ |
||||
|
||||
var originelement = document.getElementById("id_shortname"); |
||||
|
||||
var syncedelement2 = document.getElementById("id_vdbname"); |
||||
var syncedelement3 = document.getElementById("id_vdatapath"); |
||||
var syncedelement4 = document.getElementById("id_vhostname"); |
||||
|
||||
syncedelement2.value = syncedelement2.value.replace(/<%%INSTANCE%%>/g, originelement.value); |
||||
syncedelement3.value = syncedelement3.value.replace(/<%%INSTANCE%%>/g, originelement.value); |
||||
syncedelement4.value = syncedelement4.value.replace(/<%%INSTANCE%%>/g, originelement.value); |
||||
} |
||||
|
||||
function onLoadInit(){ |
||||
var originelement = document.getElementById("id_shortname"); |
||||
originelement.onchange = syncSchema; |
||||
} |
@ -0,0 +1,15 @@ |
||||
function selectallhosts() { |
||||
$('.vnodessel').attr('checked', true); |
||||
} |
||||
|
||||
function deselectallhosts() { |
||||
$('.vnodessel').attr('checked', false); |
||||
} |
||||
|
||||
function setpreset(form, select) { |
||||
presetvalue = select.options[select.selectedindex].value; |
||||
parts = presetvalue.split('/'); |
||||
|
||||
form.elements['variable'].value = parts[0]; |
||||
form.elements['subkey'].value = parts[1]; |
||||
} |
@ -0,0 +1,103 @@ |
||||
<?php |
||||
/** |
||||
* |
||||
* @copyright (c) 2014 Valery Fremaux |
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html |
||||
* @author Valery Fremaux <valery.fremaux@gmail.com> |
||||
*/ |
||||
|
||||
$strings['archiverealroot'] = 'Archive container real root (no symlinks here)'; |
||||
$strings['backtoindex'] = 'Back to instance index'; |
||||
$strings['badconnection'] = 'Connection FAILED'; |
||||
$strings['cancel'] = 'Cancel'; |
||||
$strings['choose'] = 'choose...'; |
||||
$strings['clearcache'] = 'Clear Twig cache'; |
||||
$strings['clearmastercache'] = 'Clear Twig cache for master'; |
||||
$strings['closewindow'] = 'Close this window'; |
||||
$strings['connectionok'] = 'Connection OK'; |
||||
$strings['continue'] = 'Continue'; |
||||
$strings['coursefolder'] = 'Physical dir'; |
||||
$strings['courserealroot'] = 'Course container real root (no symlinks here)'; |
||||
$strings['datalocation'] = 'Data location'; |
||||
$strings['datapathavailable'] = 'Data path is available and ready to be used as : <br/>'; |
||||
$strings['datapathnotavailable'] = 'Data path exists but has already files in it at <br/>'; |
||||
$strings['datapathcreated'] = 'Data path has been created as :<br/>'; |
||||
$strings['dbgroup'] = 'Database Settings'; |
||||
$strings['dbhost'] = 'DB Host'; |
||||
$strings['dbpassword'] = 'DB Password'; |
||||
$strings['dbprefix'] = 'Database prefix'; |
||||
$strings['dbuser'] = 'DB Username'; |
||||
$strings['deleteifempty'] = 'Delete if empty'; |
||||
$strings['deleteinstances'] = 'Remove instance'; |
||||
$strings['destroyinstances'] = 'Full delete instance'; |
||||
$strings['distributevalue'] = 'Distribute configuration value'; |
||||
$strings['edit'] = 'Edit instance info'; |
||||
$strings['emptysite'] = 'New empty site'; |
||||
$strings['enable_virtualisation'] = 'Enable'; |
||||
$strings['enabled'] = 'enabled'; |
||||
$strings['enableinstances'] = 'Enable'; |
||||
$strings['enabling'] = 'General enabling'; |
||||
$strings['errormuststartwithcourses'] = 'the course folder MUST start with \'courses_\' to avoid directory conflicts'; |
||||
$strings['homerealroot'] = 'Home container real root (no symlinks here)'; |
||||
$strings['hostdefinition'] = 'Host definition'; |
||||
$strings['hostlist'] = 'Other hosts'; |
||||
$strings['institution'] = 'Institution'; |
||||
$strings['lastcron'] = 'Last cron'; |
||||
$strings['maindatabase'] = 'Main database'; |
||||
$strings['manage_instances'] = 'Go to instance manager'; |
||||
$strings['newinstance'] = 'Add new instance'; |
||||
$strings['no'] = 'No'; |
||||
$strings['plugin_comment'] = 'Allows virtualizing chamilo.'; |
||||
$strings['plugin_title'] = 'Virtual Chamilo'; |
||||
$strings['proxysettings'] = 'Proxy settings'; |
||||
$strings['registerinstance'] = 'Register an instance'; |
||||
$strings['rootweb'] = 'Web root'; |
||||
$strings['savechanges'] = 'Save changes'; |
||||
$strings['selectall'] = 'Select all'; |
||||
$strings['selectnone'] = 'Deselect all'; |
||||
$strings['sendconfigvalue'] = 'Distribute a configuration value'; |
||||
$strings['setconfigvalue'] = 'Set a configuration value'; |
||||
$strings['singledatabase'] = 'Single database'; |
||||
$strings['sitename'] = 'Site Name'; |
||||
$strings['snapshotinstance'] = 'Snapshot'; |
||||
$strings['snapshotmaster'] = 'Snapshot master Chamilo'; |
||||
$strings['statisticsdatabase'] = 'Statistics database'; |
||||
$strings['successfinishedcapture'] = 'Capture of chamilo is finished'; |
||||
$strings['sync_settings'] = 'Synchronize settings'; |
||||
$strings['tableprefix'] = 'Table prefix'; |
||||
$strings['template'] = 'Template'; |
||||
$strings['templating'] = 'Templating'; |
||||
$strings['testconnection'] = 'Test DB connexion'; |
||||
$strings['testdatapath'] = 'Test data location'; |
||||
$strings['trackingenabled'] = 'Tracking enabled'; |
||||
$strings['userpersonaldatabase'] = 'User personal database'; |
||||
$strings['vchamilo'] = 'Virtual Chamilo'; |
||||
$strings['vchamilosnapshot1'] = 'STEP 1 OF 3 : Directories for snapshot have been created. Continue with database dumping...'; |
||||
$strings['vchamilosnapshot2'] = 'STEP 2 OF 3 : Databases have been dumped. Continue with saving the exploitation files... beware this step can be long if a lot of content resides in the instance...'; |
||||
$strings['vchamilosnapshot3'] = 'STEP 3 OF 3 : Files saved.'; |
||||
$strings['withselection'] = 'With selection: '; |
||||
$strings['yes'] = 'Yes'; |
||||
|
||||
$strings['mysqlcmds'] = 'Mysql commands location'; |
||||
$strings['mysqlcmd'] = 'Full path to mysql client command'; |
||||
$strings['mysqldumpcms'] = 'Full path to mysqldump command'; |
||||
|
||||
$strings['sitenameinputerror'] = "Site Name is empty or invalid"; |
||||
$strings['institutioninputerror'] = "Institution is empty or invalid"; |
||||
$strings['rootwebinputerror'] = "Root web is empty or invalid"; |
||||
$strings['databaseinputerror'] = "Database empty"; |
||||
$strings['coursefolderinputerror'] = "Data location is empty"; |
||||
|
||||
$strings['httpproxyhost'] = "HTTP proxy host"; |
||||
$strings['httpproxyport'] = "HTTP proxy port"; |
||||
$strings['httpproxybypass'] = "HTTP proxy URL bypass"; |
||||
$strings['httpproxyuser'] = "HTTP proxy user"; |
||||
$strings['httpproxypassword'] = "HTTP proxy password"; |
||||
|
||||
$strings['variable'] = 'Variable'; |
||||
$strings['subkey'] = 'Subkey'; |
||||
$strings['category'] = 'Category'; |
||||
$strings['accessurl'] = 'Access URL'; |
||||
$strings['value'] = 'Value'; |
||||
$strings['syncall'] = 'Sync all the selection'; |
||||
$strings['syncthis'] = 'Sync this setting'; |
@ -0,0 +1,101 @@ |
||||
<?php |
||||
/** |
||||
* |
||||
* @copyright (c) 2014 Valery Fremaux |
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html |
||||
* @author Valery Fremaux <valery.fremaux@gmail.com> |
||||
*/ |
||||
|
||||
$strings['archiverealroot'] = 'Container effectif d\'archives (chemin réel)'; |
||||
$strings['backtoindex'] = 'Retour aux instances'; |
||||
$strings['cancel'] = 'Annuler'; |
||||
$strings['choose'] = 'Choisir une action...'; |
||||
$strings['closewindow'] = 'Fermer cette fenêtre'; |
||||
$strings['continue'] = 'Continuer'; |
||||
$strings['coursefolder'] = 'Répertoire des cours'; |
||||
$strings['courserealroot'] = 'Container effectif de cours (chemin réel)'; |
||||
$strings['clearcache'] = 'Vider le cache Twig'; |
||||
$strings['clearmastercache'] = 'Vider le cache Twig du maître'; |
||||
$strings['datalocation'] = 'Emplacement des données'; |
||||
$strings['datapathavailable'] = 'Le répertoire de données est disponible : <br/>'; |
||||
$strings['datapathnotavailable'] = 'Le répertoire de données existe mais a déjà des fichiers à l\'emplacement <br/>'; |
||||
$strings['datapathcreated'] = 'Le répertoire de données a été créé :<br/>'; |
||||
$strings['dbgroup'] = 'Réglages de base de données'; |
||||
$strings['dbhost'] = 'Hôte de BdD'; |
||||
$strings['dbpassword'] = 'Mot de passe'; |
||||
$strings['dbprefix'] = 'Préfix de base'; |
||||
$strings['dbuser'] = 'Utilisateur BdD'; |
||||
$strings['deleteinstances'] = "Désactiver"; |
||||
$strings['destroyinstances'] = "Détruire"; |
||||
$strings['edit'] = 'Modifier les paramètres'; |
||||
$strings['emptysite'] = 'Nouveau site vide'; |
||||
$strings['enable_virtualisation'] = 'Activer'; |
||||
$strings['enabled'] = 'Etat'; |
||||
$strings['enableinstances'] = "Activer"; |
||||
$strings['enabling'] = 'Activation'; |
||||
$strings['errormuststartwithcourses'] = 'Le répertoire de cours doit commencer par \'courses_\' pour éviter les collisions de chemin'; |
||||
$strings['homerealroot'] = 'Container effectif de pages d\'accueil (chemin réel)'; |
||||
$strings['hostdefinition'] = 'Définition d\'hôte'; |
||||
$strings['hostlist'] = 'Les sites du réseau'; |
||||
$strings['institution'] = 'Institution'; |
||||
$strings['lastcron'] = 'Dernier cron'; |
||||
$strings['maindatabase'] = 'Base de données principale'; |
||||
$strings['manage_instances'] = 'Aller au gestionnaire d\'instances'; |
||||
$strings['sync_settings'] = 'Synchroniser des réglages'; |
||||
$strings['deleteifempty'] = 'Supprimer la clef si vide'; |
||||
$strings['newinstance'] = "Ajouter une instance"; |
||||
$strings['no'] = 'Non'; |
||||
$strings['plugin_comment'] = 'Permettre les chamilos virtuels.'; |
||||
$strings['plugin_title'] = 'Virtualisation de Chamilo'; |
||||
$strings['proxysettings'] = 'Réglages du Proxy'; |
||||
$strings['registerinstance'] = "Enregistrer une instance"; |
||||
$strings['rootweb'] = 'Racine Web'; |
||||
$strings['savechanges'] = 'Enregistrer les modifications'; |
||||
$strings['selectall'] = 'Selectionner tout'; |
||||
$strings['selectnone'] = 'Déselectionner tout'; |
||||
$strings['setconfigvalue'] = 'Mettre à jour une variable de configuration'; |
||||
$strings['distributevalue'] = 'Distribuer la configuration'; |
||||
$strings['sendconfigvalue'] = 'Distribution d\'une valeur de configuration'; |
||||
$strings['singledatabase'] = 'Base de données unique'; |
||||
$strings['sitename'] = 'Nom du site'; |
||||
$strings['snapshotinstance'] = 'Snapshot'; |
||||
$strings['snapshotmaster'] = 'Snapshot du Chamilo maître'; |
||||
$strings['statisticsdatabase'] = 'base de données de statistiques'; |
||||
$strings['successfinishedcapture'] = 'La capture de Chamilo est terminée'; |
||||
$strings['tableprefix'] = 'Prefixe de table'; |
||||
$strings['template'] = 'Modèle'; |
||||
$strings['templating'] = 'Templating'; |
||||
$strings['testconnection'] = "Test de la connexion"; |
||||
$strings['testdatapath'] = "Test de l'emplacement de données"; |
||||
$strings['trackingenabled'] = "Tracking activé"; |
||||
$strings['userpersonaldatabase'] = 'base de données des données personnelles'; |
||||
$strings['vchamilo'] = 'Chamilo Virtuel'; |
||||
$strings['vchamilosnapshot1'] = 'ETAPE 1 DE 3 : Les répertoires de snapshot ont été créés. contibuer avec la capture des bases...'; |
||||
$strings['vchamilosnapshot2'] = 'ETAPE 2 DE 3 : Les bases ont été capturées. continuer avec la récupération des fichiers d\'usage... Attention, cette étape peut être longue si la plate-forme est fortement chargée en documents...'; |
||||
$strings['vchamilosnapshot3'] = 'ETAPE 3 DE 3 : Fichiers capturés.'; |
||||
$strings['withselection'] = "Avec la sélection : "; |
||||
$strings['yes'] = 'Oui'; |
||||
|
||||
$strings['mysqlcmds'] = 'Emplacement de la commande Mysql'; |
||||
$strings['mysqlcmd'] = 'Chemin vers le client mysql'; |
||||
$strings['mysqldumpcms'] = 'Chemin vers la commande mysqldump'; |
||||
|
||||
$strings['sitenameinputerror'] = "Le nom de site est vide"; |
||||
$strings['institutioninputerror'] = "L'institutiob est vide ou invalide"; |
||||
$strings['rootwebinputerror'] = "L'URL d'acces est vide ou invalide"; |
||||
$strings['databaseinputerror'] = "La base de données n'est pas définie"; |
||||
$strings['coursefolderinputerror'] = "Le réperotire de cours n'est pas défini"; |
||||
|
||||
$strings['httpproxyhost'] = "Hôte Proxy HTTP"; |
||||
$strings['httpproxyport'] = "Port Proxy HTTP"; |
||||
$strings['httpproxybypass'] = "Filtre d'URL de proxy (exclusions)"; |
||||
$strings['httpproxyuser'] = "Utilisateur Proxy"; |
||||
$strings['httpproxypassword'] = "Mot de passe Proxy"; |
||||
|
||||
$strings['variable'] = 'Variable'; |
||||
$strings['subkey'] = 'Clef'; |
||||
$strings['category'] = 'Categorie'; |
||||
$strings['accessurl'] = 'Sous-site'; |
||||
$strings['value'] = 'Valeur'; |
||||
$strings['syncall'] = 'Synchroniser la sélection'; |
||||
$strings['syncthis'] = 'Synchroniser ce réglage'; |
@ -0,0 +1,3 @@ |
||||
<?php |
||||
|
||||
$strings['HelloPlugin'] = "Hola chaval!"; |
@ -0,0 +1,720 @@ |
||||
<?php |
||||
require_once('lib/bootlib.php'); |
||||
require_once('lib/vchamilo_plugin.class.php'); |
||||
|
||||
function vchamilo_hook_configuration(&$_configuration) { |
||||
global $VCHAMILO; |
||||
|
||||
if (defined('CLI_SCRIPT') && !defined('CLI_VCHAMILO_OVERRIDE')) return; |
||||
|
||||
// provides an effective value for the virtual root_web based on domain analysis |
||||
vchamilo_get_hostname($_configuration); |
||||
|
||||
$plugin = VChamiloPlugin::create(); |
||||
|
||||
// We are on physical chamilo. Let original config play |
||||
if ($_configuration['root_web'] == $_configuration['vchamilo_web_root'].'/'){ |
||||
$VCHAMILO = 'main'; |
||||
return; |
||||
} |
||||
|
||||
// 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'); |
||||
|
||||
$table = 'vchamilo'; |
||||
|
||||
$query = " |
||||
SELECT * FROM $table WHERE root_web = '{$_configuration['vchamilo_web_root']}' |
||||
"; |
||||
|
||||
$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; |
||||
} |
||||
|
||||
// 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."); |
||||
} |
||||
} else { |
||||
die ("VChamilo : Could not fetch virtual chamilo configuration"); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* |
||||
*/ |
||||
function vchamilo_get_hostname(&$_configuration) { |
||||
|
||||
if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_configuration['force_https_forwarded_proto'])) { |
||||
$protocol = 'https'; |
||||
} else { |
||||
$protocol = 'http'; |
||||
} |
||||
|
||||
if (defined('CLI_VCHAMILO_OVERRIDE')) { |
||||
$_configuration['vchamilo_web_root'] = CLI_VCHAMILO_OVERRIDE; |
||||
$_configuration['vchamilo_name'] = preg_replace('#https?://#', '', CLI_VCHAMILO_OVERRIDE); // remove radical from override for name |
||||
|
||||
// fake the server signature |
||||
global $_SERVER; |
||||
|
||||
$_SERVER['SERVER_NAME'] = $_configuration['vchamilo_name']; |
||||
$_SERVER['HTTP_HOST'] = $_configuration['vchamilo_name']; |
||||
$_SERVER['QUERY_STRING'] = ''; |
||||
$_SERVER['REQUEST_URI'] = CLI_VCHAMILO_OVERRIDE; |
||||
|
||||
return; |
||||
} |
||||
|
||||
$_configuration['vchamilo_web_root'] = "{$protocol}://".@$_SERVER['HTTP_HOST']; |
||||
$_configuration['vchamilo_name'] = @$_SERVER['HTTP_HOST']; |
||||
if (empty($_configuration['vchamilo_name'])) { // try again with another source if has failed |
||||
$_configuration['vchamilo_name'] = "{$protocol}://".$_SERVER['SERVER_NAME']; |
||||
if ($_SERVER['SERVER_PORT'] != 80) { |
||||
$_configuration['vchamilo_name'] .= ':'.$_SERVER['SERVER_PORT']; |
||||
} |
||||
$_configuration['vchamilo_name'] = $_SERVER['SERVER_NAME']; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* provides a side connection to a vchamilo database |
||||
* @param array $vchamilo |
||||
* @return a connection |
||||
*/ |
||||
function vchamilo_boot_connection(&$_configuration, $binddb = false) { |
||||
|
||||
// Important : force new link here |
||||
$mysql_side_cnx = mysql_connect($_configuration['db_host'], $_configuration['db_user'], $_configuration['db_password'], true); |
||||
if (!$mysql_side_cnx) { |
||||
// echo('Side connection failure with '.$_configuration['db_host'].', '.$_configuration['db_user'].', '.$_configuration['db_password']); |
||||
echo('Side connection failure with '.$_configuration['db_host'].', '.$_configuration['db_user'].', ******** '); |
||||
return false; |
||||
} |
||||
mysql_set_charset('utf8', $mysql_side_cnx); |
||||
if (!empty($binddb)) { |
||||
if (!in_array($binddb, array('main', 'statistics', 'user_personal'), 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; |
||||
} |
||||
|
||||
function vchamilo_redirect($url) { |
||||
if (preg_match('#https?://#', $url)) { |
||||
header('location: '.$url); |
||||
} else { |
||||
header('location: ' . api_get_path(WEB_PATH).$url); |
||||
} |
||||
} |
||||
|
||||
function vchamilo_get_htaccess_fragment($course_folder) { |
||||
|
||||
$str = " |
||||
# Change this file to fit your configuration and save it as .htaccess in the courses folder # |
||||
# Chamilo mod rewrite |
||||
# Comment lines start with # and are not processed |
||||
|
||||
<IfModule mod_rewrite.c> |
||||
RewriteEngine On |
||||
|
||||
# Rewrite base is the dir chamilo is installed in with trailing slash |
||||
RewriteBase /{$course_folder}/ |
||||
|
||||
# Do not rewrite on the main dir |
||||
# Change this path to the path of your main folder |
||||
RewriteCond %{REQUEST_URI} !^/main/ |
||||
|
||||
#replace nasty ampersands by 3 slashes, we change these back in download.php |
||||
RewriteRule ([^/]+)/document/(.*)&(.*)$ $1/document/$2///$3 [N] |
||||
|
||||
# Rewrite everything in the scorm folder of a course to the download script |
||||
RewriteRule ([^/]+)/scorm/(.*)$ /main/document/download_scorm.php?doc_url=/$2&cDir=$1 [QSA,L] |
||||
|
||||
# Rewrite everything in the document folder of a course to the download script |
||||
RewriteRule ([^/]+)/document/(.*)$ /main/document/download.php?doc_url=/$2&cDir=$1 [QSA,L] |
||||
|
||||
# Rewrite everything in the work folder |
||||
RewriteRule ([^/]+)/work/(.*)$ /main/work/download.php?file=work/$2&cDir=$1 [QSA,L] |
||||
</IfModule> |
||||
"; |
||||
} |
||||
|
||||
function vchamilo_get_default_course_index_fragment() { |
||||
return "<html><head></head><body></body></html>"; |
||||
} |
||||
|
||||
function vchamilo_template_exists($template) { |
||||
global $_configuration; |
||||
|
||||
// Find and checktemplate directory (files and SQL). |
||||
$separator = DIRECTORY_SEPARATOR; |
||||
$templatefoldername = 'plugin'.$separator.'vchamilo'.$separator.'templates'; |
||||
$absolute_templatesdir = $_configuration['root_sys'].$templatefoldername; |
||||
$relative_datadir = $templatefoldername.$separator.$template.'_sql'; |
||||
$absolute_datadir = $_configuration['root_sys'].$relative_datadir; |
||||
|
||||
return is_dir($absolute_datadir); |
||||
} |
||||
|
||||
/** |
||||
* drop a vchamilo instance databases using the physical connection |
||||
* @param object $vchamilo |
||||
* @param handle $side_cnx |
||||
* return an array of errors or false if ok |
||||
*/ |
||||
function vchamilo_drop_databases(&$vchamilo){ |
||||
global $plugininstance; |
||||
|
||||
if (is_array($vchamilo)) $vchamilo = (object)$vchamilo; |
||||
|
||||
// Drop databases you need to drop |
||||
$sqls = array(" DROP DATABASE `{$vchamilo->main_database}` "); |
||||
|
||||
if (!empty($vchamilo->statistics_database) && ($vchamilo->main_database != $vchamilo->statistics_database)) { |
||||
$sqls[] = " DROP DATABASE `{$vchamilo->statistics_database}` "; |
||||
}; |
||||
|
||||
if (!empty($vchamilo->user_personal_database) && ($vchamilo->user_personal_database != $vchamilo->statistics_database) && ($vchamilo->main_database != $vchamilo->user_personal_database)) { |
||||
$sqls[] = " DROP DATABASE `{$vchamilo->user_personal_database}` "; |
||||
} |
||||
|
||||
foreach($sqls as $sql){ |
||||
$res = Database::query($sql); |
||||
if (!$res){ |
||||
$erroritem = new StdClass(); |
||||
$erroritem->message = $plugininstance->get_lang('couldnotdropdb'); |
||||
$erroritem->on = 'db'; |
||||
$erroritems[] = $erroritem; |
||||
} |
||||
} |
||||
|
||||
if (!empty($erroritems)){ |
||||
return $erroritems; |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
/** |
||||
* Create all needed databases. |
||||
* @uses $CFG The global configuration. |
||||
* @param $vmoodledata object All the Host_form data. |
||||
* @param $outputfile array The variables to inject in setup template SQL. |
||||
* @return bool If TRUE, loading database from template was sucessful, otherwise FALSE. |
||||
*/ |
||||
function vchamilo_create_databases($vchamilo, $cnx = null) { |
||||
global $_configuration, $DB; |
||||
|
||||
// availability of SQL commands |
||||
|
||||
$createstatement = 'CREATE DATABASE %DATABASE% DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci '; |
||||
|
||||
$dbs = array($vchamilo->main_database); |
||||
|
||||
if (!empty($vchamilo->statistics_database) && $vchamilo->main_database != $vchamilo->statistics_database){ |
||||
$dbs[] = $vchamilo->statistics_database; |
||||
} |
||||
|
||||
if (!empty($vchamilo->user_personal_database) && ($vchamilo->main_database != $vchamilo->user_personal_database) && ($vchamilo->statistics_database != $vchamilo->user_personal_database)){ |
||||
$dbs[] = $vchamilo->user_personal_database; |
||||
} |
||||
|
||||
foreach($dbs as $adb){ |
||||
ctrace("Creating DB $adb "); |
||||
$sql = str_replace('%DATABASE%', $adb, $createstatement); |
||||
if(!$DB->execute_sql($sql)){ |
||||
print_error('noexecutionfor','block_vmoodle', $sql); |
||||
return false; |
||||
} |
||||
|
||||
} |
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* get a proper SQLdump command |
||||
* @param object $vmoodledata the complete new host information |
||||
* @return string the shell command |
||||
*/ |
||||
function vchamilo_get_database_dump_cmd($vchamilodata){ |
||||
global $CFG; |
||||
|
||||
$pgm = vchamilo_get_config('mysql_cmd'); |
||||
|
||||
// Checks the needed program. |
||||
ctrace("load_database_from_dump : checking database command"); |
||||
if(!$pgm){ |
||||
$pgm = '/usr/bin/mysql'; |
||||
ctrace("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)){ |
||||
print_error('databasecommanddoesnotmatchanexecutablefile'); |
||||
return false; |
||||
} |
||||
|
||||
// Retrieves the host configuration (more secure). |
||||
$vchamilodata = vchamilo_make_this(); |
||||
if (strstr($vchamilodata->db_host, ':') !== false){ |
||||
list($vchamilodata->db_host, $vchamilodata->db_port) = split(':', $vchamilodata->db_host); |
||||
} |
||||
|
||||
// Password. |
||||
if (!empty($vchamilodata->db_password)){ |
||||
$vchamilodata->db_password = '-p'.escapeshellarg($vchamilodata->db_password).' '; |
||||
} |
||||
|
||||
// Making the command line (see 'vconfig.php' file for defining the right paths). |
||||
$sqlcmd = $pgm.' -h'.$vchamilodata->db_host.(isset($vchamilodata->db_port) ? ' -P'.$vchamilodata->db_port.' ' : ' ' ); |
||||
$sqlcmd .= '-u'.$vchamilodata->db_user.' '.$vchamilodata->db_password; |
||||
$sqlcmd .= '%DATABASE% < '; |
||||
|
||||
return $sqlcmd; |
||||
} |
||||
|
||||
function vchamilo_load_db_template($vchamilo, $dbtemplate, $template){ |
||||
global $_configuration; |
||||
|
||||
// Make template directory (files and SQL). |
||||
$separator = DIRECTORY_SEPARATOR; |
||||
$templatefoldername = 'plugin'.$separator.'vchamilo'.$separator.'templates'; |
||||
$absolute_templatesdir = $_configuration['root_sys'].$templatefoldername; |
||||
$relative_datadir = $templatefoldername.$separator.$template.'_sql'; |
||||
$absolute_datadir = $_configuration['root_sys'].$relative_datadir; |
||||
|
||||
$filerad = preg_replace('/_database$/', '', $dbtemplate); |
||||
$sqlfile = 'chamilo_master_'.$filerad.'.sql'; |
||||
|
||||
if(!$sqlcmd = vchamilo_get_database_dump_cmd($vchamilo)){ |
||||
return false; |
||||
} |
||||
|
||||
$sqlcmd = str_replace('%DATABASE%', $vchamilo->$dbtemplate, $sqlcmd); |
||||
|
||||
// Make final commands to execute, depending on the database type. |
||||
$import = $sqlcmd.$absolute_datadir.'/'.$sqlfile; |
||||
|
||||
// Execute the command. |
||||
ctrace("load_database_from_dump : executing feeding sql as \n $import "); |
||||
|
||||
if (!defined('CLI_SCRIPT')){ |
||||
putenv('LANG=en_US.utf-8'); |
||||
} |
||||
// ensure utf8 is correctly handled by php exec() |
||||
// @see http://stackoverflow.com/questions/10028925/call-a-program-via-shell-exec-with-utf-8-text-input |
||||
|
||||
exec($import, $output, $return); |
||||
|
||||
ctrace(implode("\n", $output)."\n"); |
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* load a bulk sql in database that is given through a vchamilo configuration record. |
||||
* @param object $vchamilo |
||||
* @param string $bulfile a bulk file of queries to process on the database |
||||
* @param handle $cnx |
||||
* @param array $vars an array of vars to inject in the bulk file before processing |
||||
*/ |
||||
function vchamilo_execute_db_sql(&$vchamilo, $bulkfile, $cnx = null, $vars=null, $filter=null){ |
||||
global $_configuration; |
||||
|
||||
if (file_exists($bulkfile)){ |
||||
$erroritem = new StdClass(); |
||||
$erroritem->message = "vchamilo_load_db_template : Bulk file $bulkfile not found"; |
||||
$erroritems[] = $erroritem; |
||||
return $erroritem; |
||||
} |
||||
|
||||
$local_cnx = 0; |
||||
if (is_null($cnx)){ |
||||
$cnx = vchamilo_make_connection($vchamilo, true); |
||||
$local_cnx = 1; |
||||
} |
||||
|
||||
/// get dump file |
||||
$sql = file($bulkfile); |
||||
|
||||
// converts into an array of text lines |
||||
$dumpfile = implode('', $sql); |
||||
if ($filter){ |
||||
foreach($filter as $from => $to){ |
||||
$dumpfile = mb_ereg_replace(preg_quote($from), $to, $dumpfile); |
||||
} |
||||
} |
||||
// insert any external vars |
||||
if (!empty($vars)){ |
||||
foreach($vars as $key => $value){ |
||||
// for debug : echo "$key => $value"; |
||||
$dumpfile = str_replace("<%%$key%%>", $value, $dumpfile); |
||||
} |
||||
} |
||||
$sql = explode ("\n", $dumpfile); |
||||
// cleanup unuseful things |
||||
$sql = preg_replace("/^--.*/", "", $sql); |
||||
$sql = preg_replace("/^\/\*.*/", "", $sql); |
||||
$dumpfile = implode("\n", $sql); |
||||
|
||||
/// split into single queries |
||||
$dumpfile = str_replace("\r\n", "\n", $dumpfile); // translates to Unix LF |
||||
$queries = preg_split("/;\n/", $dumpfile); |
||||
/// feed queries in database |
||||
$i = 0; |
||||
$j = 0; |
||||
$l = 0; |
||||
if (!empty($queries)){ |
||||
foreach($queries as $query){ |
||||
$query = trim($query); // get rid of trailing spaces and returns |
||||
if ($query == '') continue; // avoid empty queries |
||||
$query = mb_convert_encoding($query, 'iso-8859-1', 'auto'); |
||||
if (!$res = vchamilo_execute_query($vchamilo, $query, $cnx)){ |
||||
$erroritem = new StdClass(); |
||||
$erroritem->message = "vchamilo_load_db_template : Load error on query $l"; |
||||
$erroritem->content = $query; |
||||
$erroritems[] = $erroritem; |
||||
$j++; |
||||
} else { |
||||
$i++; |
||||
} |
||||
$l++; |
||||
} |
||||
} |
||||
echo "loaded : $i queries succeeded, $j queries failed<br/>"; |
||||
|
||||
if ($local_cnx){ |
||||
vchamilo_close_connection($vchamilo, $cnx); |
||||
} |
||||
|
||||
if (!empty($erroritems)){ |
||||
return $erroritems; |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
/** |
||||
* Dumps a SQL database for having a snapshot. |
||||
* @param $vchamilo object The Vchamilo object. |
||||
* @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){ |
||||
global $CFG; |
||||
|
||||
// Separating host and port, if sticked. |
||||
if (strstr($vchamilo->db_host, ':') !== false){ |
||||
list($host, $port) = split(':', $vchamilo->db_host); |
||||
} else { |
||||
$host = $vchamilo->db_host; |
||||
} |
||||
|
||||
// By default, empty password. |
||||
$pass = ''; |
||||
$pgm = null; |
||||
|
||||
if (empty($port)){ |
||||
$port = 3306; |
||||
} |
||||
|
||||
// Password. |
||||
if (!empty($vchamilo->db_password)){ |
||||
$pass = "-p".escapeshellarg($vchamilo->db_password); |
||||
} |
||||
|
||||
// Making the commands for each database. |
||||
$cmds = array(); |
||||
if ($CFG->ostype == 'WINDOWS'){ |
||||
$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'; |
||||
} |
||||
|
||||
} 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 ; |
||||
|
||||
if(!$pgm){ |
||||
$erroritem = new StdClass(); |
||||
$erroritem->message = "Database dump command not available"; |
||||
return array($erroritem); |
||||
} else { |
||||
$phppgm = str_replace("\\", '/', $pgm); |
||||
$phppgm = str_replace("\"", '', $phppgm); |
||||
$pgm = str_replace('/', DIRECTORY_SEPARATOR, $pgm); |
||||
|
||||
if (!is_executable($phppgm)){ |
||||
$erroritem = new StdClass(); |
||||
$erroritem->message = "Database dump command $phppgm does not match any executable"; |
||||
return array($erroritem); |
||||
} |
||||
|
||||
// executing all commands |
||||
foreach($cmds as $cmd){ |
||||
|
||||
// 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"); |
||||
} |
||||
|
||||
// Executes the SQL command. |
||||
exec($cmd, $execoutput, $returnvalue); |
||||
if ($LOG){ |
||||
foreach($execoutput as $execline) fwrite($LOG, $execline."\n"); |
||||
fwrite($LOG, $returnvalue."\n"); |
||||
fclose($LOG); |
||||
} |
||||
} |
||||
} |
||||
|
||||
// End with success. |
||||
return 0; |
||||
} |
||||
|
||||
/** |
||||
* read manifest values in vchamilo template. |
||||
* @uses $CFG |
||||
*/ |
||||
function vchamilo_get_vmanifest($version){ |
||||
global $_configuration; |
||||
|
||||
include(api_get_path(SYS_PATH, SYS_PATH).'/plugin/vchamilo/templates/'.$version.'_sql/manifest.php'); |
||||
$manifest->templatewwwroot = $templatewwwroot; |
||||
$manifest->templatevdbprefix = $templatevdbprefix; |
||||
$manifest->coursefolder = $coursefolder; |
||||
return $manifest; |
||||
} |
||||
|
||||
/** |
||||
* make a fake vchamilo that represents the current host |
||||
*/ |
||||
function vchamilo_make_this(){ |
||||
global $_configuration; |
||||
|
||||
$thischamilo->root_web = $_configuration['root_web']; |
||||
|
||||
$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_databse']; |
||||
$thischamilo->statistics_database = $_configuration['statistics_databse']; |
||||
$thischamilo->user_personal_database = $_configuration['user_personal_databse']; |
||||
$thischamilo->table_prefix = $_configuration['table_prefix']; |
||||
$thischamilo->single_database = $_configuration['single_database']; |
||||
$thischamilo->tracking_enabled = $_configuration['tracking_enabled']; |
||||
return $thischamilo; |
||||
} |
||||
|
||||
/** |
||||
* Get available templates for defining a new virtual host. |
||||
* @return array The availables templates, or EMPTY array. |
||||
*/ |
||||
function vchamilo_get_available_templates() { |
||||
global $_configuration; |
||||
global $plugininstance; |
||||
|
||||
$separator = DIRECTORY_SEPARATOR; |
||||
|
||||
$templatefoldername = 'plugin'.$separator.'vchamilo'.$separator.'templates'; |
||||
$absolute_templatesdir = $_configuration['root_sys'].$templatefoldername; |
||||
|
||||
// Scans the templates. |
||||
if(!is_dir($absolute_templatesdir)){ |
||||
mkdir($absolute_templatesdir, 0777, true); |
||||
} |
||||
$dirs = glob($absolute_templatesdir.'/*'); |
||||
$vtemplates = preg_grep("/[^\/](.*)_vchamilodata$/", $dirs); |
||||
|
||||
// Retrieves template(s) name(s). Should be hostnames. |
||||
$templatesarray = array('' => $plugininstance->get_lang('emptysite')); |
||||
if ($vtemplates){ |
||||
foreach($vtemplates as $vtemplatedir){ |
||||
preg_match("/([^\/]*)_vchamilodata/", $vtemplatedir, $matches); |
||||
$templatesarray[$matches[1]] = $matches[1]; |
||||
if (!isset($first)) $first = $matches[1]; |
||||
} |
||||
} |
||||
|
||||
return $templatesarray; |
||||
} |
||||
|
||||
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">'; |
||||
$str .= '<pre>'; |
||||
foreach($errortrace as $error){ |
||||
$str .= $error->message.'<br/>'; |
||||
$str .= @$error->content; |
||||
} |
||||
$str .= '</pre>'; |
||||
$str .= '</div>'; |
||||
} |
||||
|
||||
if ($return) return $str; |
||||
echo $str; |
||||
} |
||||
|
||||
/** |
||||
* this function set will map standard moodle API calls to chamilo |
||||
* internal primitives. This avoids too many changes to do in imported |
||||
* code |
||||
* |
||||
*/ |
||||
function vchamilo_get_config($module, $key, $isplugin = true){ |
||||
global $_configuration, $DB; |
||||
|
||||
if ($isplugin){ |
||||
$key = $module.'_'.$key; |
||||
} |
||||
if($configrec = $DB->get_record(TABLE_MAIN_SETTINGS_CURRENT, array('variable' => $key, 'subkey' => $module))){ |
||||
return $configrec->selected_value; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
function vchamilo_load_files_from_template($vchamilo, $template){ |
||||
global $_configuration; |
||||
|
||||
// Make template directory (files and SQL). |
||||
$separator = DIRECTORY_SEPARATOR; |
||||
$templatefoldername = 'plugin'.$separator.'vchamilo'.$separator.'templates'; |
||||
$relative_template_datadir = $templatefoldername.$separator.$template.'_vchamilodata'; |
||||
|
||||
$absolute_templatesdir = $_configuration['root_sys'].$templatefoldername; |
||||
$absolute_template_datadir = $_configuration['root_sys'].$relative_template_datadir; |
||||
|
||||
$vchamilo->virtual = true; |
||||
|
||||
// Get Vchamilo known record. |
||||
$vcoursepath = api_get_path(TO_SYS, SYS_COURSE_PATH, (array)$vchamilo); |
||||
$vhomepath = api_get_path(TO_SYS, SYS_HOME_PATH, (array)$vchamilo); |
||||
$varchivepath = api_get_path(TO_SYS, SYS_ARCHIVE_PATH, (array)$vchamilo); |
||||
|
||||
echo "archiveapth : $varchivepath"; |
||||
|
||||
// Rename some dirs top match instance requirements |
||||
$manifest = vchamilo_get_vmanifest($template); |
||||
|
||||
// get the protocol free hostname |
||||
$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"); |
||||
|
||||
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); |
||||
copyDirContentTo(chop_last_slash($absolute_template_datadir.'/home/'.$originhomedir), chop_last_slash($vhomepath), false); |
||||
|
||||
} |
||||
|
||||
function chop_last_slash($path){ |
||||
return preg_replace('/\/$/', '', $path); |
||||
} |
||||
|
||||
/** |
||||
* Moves a directory and its content to an other area |
||||
* |
||||
* @author - Hugues Peeters <peeters@ipm.ucl.ac.be> |
||||
* @param - $orig_dir_path (string) - the path of the directory to move |
||||
* @param - $destination (string) - the path of the new area |
||||
* @return - no return |
||||
*/ |
||||
function copyDirContentTo($source, $destination, $move = true) { |
||||
|
||||
// Extract directory name - create it at destination - update destination trail |
||||
if (!is_dir($source)) { |
||||
return; |
||||
} |
||||
|
||||
if (!is_dir($destination)) { |
||||
mkdir($destination, api_get_permissions_for_new_directories()); |
||||
} |
||||
|
||||
$DIR = opendir($source); |
||||
|
||||
while ($element = readdir($DIR)) { |
||||
if ($element == '.' || $element == '..') { |
||||
continue; // Skip the current and parent directories |
||||
} elseif (is_file($source.'/'.$element)) { |
||||
copy($source.'/'.$element, $destination.'/'.$element); |
||||
|
||||
if ($move) { |
||||
unlink($source.'/'.$element) ; |
||||
} |
||||
} elseif (is_dir($source.'/'.$element)) { |
||||
$dirs_to_copy[] = $element; |
||||
} |
||||
} |
||||
|
||||
closedir($DIR) ; |
||||
|
||||
if (sizeof($dirs_to_copy) > 0) { |
||||
foreach ($dirs_to_copy as $dir) { |
||||
copyDirContentTo($source.'/'.$dir, $destination.'/'.$dir, $move); // Recursivity |
||||
} |
||||
} |
||||
|
||||
if ($move) { |
||||
rmdir($source) ; |
||||
} |
||||
} |
||||
|
@ -0,0 +1,60 @@ |
||||
<?php |
||||
require_once('HTML/QuickForm/submit.php'); |
||||
|
||||
/** |
||||
* HTML class for a submit type element |
||||
* |
||||
* @author Valery Fremaux |
||||
* @access public |
||||
*/ |
||||
class HTML_QuickForm_cancel extends HTML_QuickForm_button |
||||
{ |
||||
// {{{ constructor |
||||
|
||||
/** |
||||
* Class constructor |
||||
* |
||||
* @since 1.0 |
||||
* @access public |
||||
* @return void |
||||
*/ |
||||
function HTML_QuickForm_cancel($elementName=null, $value=null, $escapeurl=null, $attributes = null) |
||||
{ |
||||
if ($elementName==null){ |
||||
$elementName = 'cancel'; |
||||
} |
||||
if ($value == null){ |
||||
$value = get_lang('cancel'); |
||||
} |
||||
|
||||
parent::HTML_QuickForm_button($elementName, $value, $attributes); |
||||
|
||||
if ($escapeurl!=null){ |
||||
$this->updateAttributes(array('onclick'=>'window.location.href = "'.$escapeurl.'"; return true;')); |
||||
} |
||||
} //end constructor |
||||
|
||||
function onQuickFormEvent($event, $arg, &$caller){ |
||||
|
||||
$value = $arg[0]; |
||||
$escapeurl = $arg[1]; |
||||
|
||||
if ($value != null){ |
||||
$this->updateAttributes(array('value'=> $value)); |
||||
} |
||||
|
||||
if ($escapeurl != null){ |
||||
$this->updateAttributes(array('onclick'=>'window.location.href = "'.$escapeurl.'"; return true;')); |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
function getFrozenHtml(){ |
||||
return HTML_QuickForm_submit::getFrozenHtml(); |
||||
} |
||||
|
||||
function freeze(){ |
||||
return HTML_QuickForm_submit::freeze(); |
||||
} |
||||
// }}} |
||||
} //end class MoodleQuickForm_cancel |
@ -0,0 +1,5 @@ |
||||
<?php |
||||
|
||||
function vchamilo_boot_api_get_path(&$_configuration){ |
||||
return $_configuration['root_sys'].'main/inc/lib/'; |
||||
} |
@ -0,0 +1,54 @@ |
||||
<?php |
||||
|
||||
|
||||
global $_configuration; |
||||
require_once 'bootlib.php'; |
||||
require_once vchamilo_boot_api_get_path($_configuration) . 'plugin.class.php'; |
||||
|
||||
/** |
||||
* Description of VChamilo |
||||
* |
||||
* @copyright (c) 2014 VF Consulting |
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html |
||||
* @author Valery Fremaux <valery.fremaux@gmail.com> |
||||
*/ |
||||
class VChamiloPlugin extends Plugin |
||||
{ |
||||
|
||||
/** |
||||
* |
||||
* @return VChamiloPlugin |
||||
*/ |
||||
static function create() |
||||
{ |
||||
static $result = null; |
||||
return $result ? $result : $result = new self(); |
||||
} |
||||
|
||||
function get_name() |
||||
{ |
||||
return 'vchamilo'; |
||||
} |
||||
|
||||
protected function __construct() |
||||
{ |
||||
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')){ |
||||
return $_configuration['root_web'].'/plugin/vchamilo/pix/'.$pixname.'.png'; |
||||
} |
||||
if (file_exists($_configuration['root_sys'].'/plugin/vchamilo/pix/'.$pixname.'.jpg')){ |
||||
return $_configuration['root_web'].'/plugin/vchamilo/pix/'.$pixname.'.jpg'; |
||||
} |
||||
if (file_exists($_configuration['root_sys'].'/plugin/vchamilo/pix/'.$pixname.'.gif')){ |
||||
return $_configuration['root_web'].'/plugin/vchamilo/pix/'.$pixname.'.gif'; |
||||
} |
||||
|
||||
return $_configuration['root_web'].'/main/img/icons/'.$size.'/'.$pixname.'.png'; |
||||
|
||||
} |
||||
} |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 315 B |
After Width: | Height: | Size: 212 B |
After Width: | Height: | Size: 213 B |
After Width: | Height: | Size: 205 B |
After Width: | Height: | Size: 7.1 KiB |
After Width: | Height: | Size: 223 B |
@ -0,0 +1,91 @@ |
||||
<?php |
||||
/** |
||||
* This script is a configuration file for the vchamilo plugin. You can use it as a master for other platform plugins (course plugins are slightly different). |
||||
* These settings will be used in the administration interface for plugins (Chamilo configuration settings->Plugins) |
||||
* @package chamilo.plugin |
||||
* @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'); |
||||
|
||||
global $_configuration; |
||||
require_once($_configuration['root_sys'].'/local/classes/database.class.php'); |
||||
|
||||
// replace chamilo Database API with stronger DB api |
||||
global $DB; |
||||
$DB = new DatabaseManager(); |
||||
|
||||
/** |
||||
* Plugin details (must be present) |
||||
*/ |
||||
|
||||
/* Plugin config */ |
||||
|
||||
//the plugin title |
||||
$plugin_info['title'] = 'Chamilo Virtualization'; |
||||
//the comments that go with the plugin |
||||
$plugin_info['comment'] = "Holds chamilo virtualisation tools"; |
||||
//the plugin version |
||||
$plugin_info['version'] = '1.0'; |
||||
//the plugin author |
||||
$plugin_info['author'] = 'Valery Fremaux'; |
||||
|
||||
|
||||
/* Plugin optional settings */ |
||||
|
||||
/* |
||||
* This form will be showed in the plugin settings once the plugin was installed |
||||
* in the plugin/hello_world/index.php you can have access to the value: $plugin_info['settings']['hello_world_show_type'] |
||||
*/ |
||||
|
||||
$form = new FormValidator('vchamilo_form'); |
||||
|
||||
$plugininstance = VChamiloPlugin::create(); |
||||
|
||||
$form_settings = array( |
||||
'enable_virtualisation' => vchamilo_get_config('vchamilo', 'enable_virtualisation', true), |
||||
'httpproxyhost' => vchamilo_get_config('vchamilo', 'httpproxyhost', true), |
||||
'httpproxyport' => vchamilo_get_config('vchamilo', 'httpproxyport', true), |
||||
'httpproxybypass' => vchamilo_get_config('vchamilo', 'httpproxybypass', true), |
||||
'httpproxyuser' => vchamilo_get_config('vchamilo', 'httpproxyuser', true), |
||||
'httpproxypassword' => vchamilo_get_config('vchamilo', 'httpproxypassword', true), |
||||
'cmd_mysql' => vchamilo_get_config('vchamilo', 'cmd_mysql', true), |
||||
'cmd_mysqldump' => vchamilo_get_config('vchamilo', 'cmd_mysqldump', true), |
||||
'course_real_root' => vchamilo_get_config('vchamilo', 'course_real_root', true), |
||||
'archive_real_root' => vchamilo_get_config('vchamilo', 'archive_real_root', true), |
||||
'home_real_root' => vchamilo_get_config('vchamilo', 'home_real_root', true), |
||||
); |
||||
|
||||
$form->setDefaults($form_settings); |
||||
|
||||
$wwwroot = $_configuration['root_web']; |
||||
|
||||
//A simple select |
||||
$options = array(0 => $plugininstance->get_lang('no'), 1 => $plugininstance->get_lang('yes')); |
||||
$form->addElement('static', 'enable_vchamilo_manager', '<a href="'.api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php">'.$plugininstance->get_lang('manage_instances').'</a>'); |
||||
$form->addElement('static', 'sync_vchamilo_settings', '<a href="'.api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/syncparams.php">'.$plugininstance->get_lang('sync_settings').'</a>'); |
||||
$form->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')); |
||||
$form->addElement('text', 'archive_real_root', $plugininstance->get_lang('archiverealroot')); |
||||
$form->addElement('text', 'home_real_root', $plugininstance->get_lang('homerealroot')); |
||||
|
||||
$form->addElement('header', $plugininstance->get_lang('proxysettings')); |
||||
$form->addElement('text', 'httpproxyhost', $plugininstance->get_lang('httpproxyhost')); |
||||
$form->addElement('text', 'httpproxyport', $plugininstance->get_lang('httpproxyport')); |
||||
$form->addElement('text', 'httpproxybypass', $plugininstance->get_lang('httpproxybypass')); |
||||
$form->addElement('text', 'httpproxyuser', $plugininstance->get_lang('httpproxyuser')); |
||||
$form->addElement('text', 'httpproxypassword', $plugininstance->get_lang('httpproxypassword')); |
||||
|
||||
$form->addElement('header', $plugininstance->get_lang('mysqlcmds')); |
||||
$form->addElement('text', 'cmd_mysql', $plugininstance->get_lang('mysqlcmd')); |
||||
$form->addElement('text', 'cmd_mysqldump', $plugininstance->get_lang('mysqldumpcmd')); |
||||
|
||||
$form->addElement('style_submit_button', 'submit_button', $plugininstance->get_lang('Save')); |
||||
|
||||
$plugin_info['settings_form'] = $form; |
||||
|
||||
//set the templates that are going to be used |
||||
$plugin_info['templates'] = array('template.tpl'); |
@ -0,0 +1,72 @@ |
||||
Virtual Chamilo |
||||
############################## |
||||
|
||||
Author : Valery Fremaux (valery.fremaux@gmail.com) |
||||
|
||||
Virtual chamilo is a feature that allows running several chamilo instances sharing the same |
||||
code base. |
||||
|
||||
Version features |
||||
############################## |
||||
This is a yet prototypal version that is not full featured in back-office tools. |
||||
At the moment, the setup of virtual clones still is a technical operation and has no |
||||
middle-office GUI. Developement is in progress to offer a sufficiant medium-level |
||||
administrability of the process. |
||||
|
||||
How to setup : |
||||
############################## |
||||
|
||||
You need : |
||||
|
||||
1/ Install the vchamilo package into the <chamiloroot>/plugin directory |
||||
2/ Install the plugin in chamilo administration |
||||
3/ Insert the virtualisation hook into the chamilo master configuration : |
||||
|
||||
file : <chamiloroot>/main/inc/config/configure.php |
||||
|
||||
insert the hook: |
||||
|
||||
include_once $_configuration['root_sys'].'plugin/vchamilo/lib.php'; |
||||
vchamilo_hook_configuration($_configuration); |
||||
|
||||
This should be inserted just after the definition of db_admin_path and |
||||
just before the login module section : |
||||
|
||||
<here> |
||||
|
||||
/** |
||||
* |
||||
* Login modules settings |
||||
*/ |
||||
|
||||
Setup of virtual nodes : |
||||
|
||||
what you need for a virtual node is : |
||||
|
||||
- a blank database copy of chamilo |
||||
- a dedicated course directory, that needs being accessible from chamilo installation root (directly, or using symlinks). the name |
||||
of this directory is free, as it will be mapped into the vchamilo record. |
||||
- a dedicated home page directory, that is located into <chamiloroot>/home directory and is named |
||||
as the chamilo instance domain name. |
||||
- a vchamilo record into the vchamilo table of the master installation. (the master installation is the install that refers to |
||||
the effective "configuration.php" information. |
||||
- an appropriate multiroot home root setup in the local chamilo instance |
||||
|
||||
# Prerequisites for VCHamilo working nice |
||||
|
||||
Multiple URL access must be enabled : |
||||
|
||||
# in <chamiloroot>/main/inc/config/configuration.php |
||||
$_configuration['multiple_access_urls'] = true; |
||||
|
||||
In the administration, you will need configure an adequate home root definition for the instance finding |
||||
the dedicated home directory. You just need editing the http://localhost default host, and give the real domain |
||||
name you are using. |
||||
|
||||
Check you have the <chamilo>/home/<instancedomain> clone of the standard home directory. |
||||
|
||||
# Important note about file system permissions |
||||
|
||||
Vchamilos will use several side-directories apart from the standard installation (dedicated courses, |
||||
dedicated home page). Check you set the adequate filesystem permissions (usually let the server write |
||||
in there) for them. |
@ -0,0 +1,10 @@ |
||||
<div class="vchamilo-title"> |
||||
<h2>{{title}}</h2> |
||||
</div> |
||||
<div class="vchamilo-host-list"> |
||||
<ul> |
||||
{% for host in hosts %} |
||||
<li class="vchamilo-host"> <a href="{{host.url}}">{{host.name}}</a></li> |
||||
{% endfor %} |
||||
</ul> |
||||
</div> |
@ -0,0 +1,2 @@ |
||||
This directory whould be http server writable for templates snapshot to be created. |
||||
Set GID to web server group, or give write access to everyone. |
@ -0,0 +1,9 @@ |
||||
<?php |
||||
/* PHP code to uninstall the plugin */ |
||||
|
||||
$table = 'vchamilo'; |
||||
$tablename = Database::get_main_table($table); |
||||
$sql = " DROP TABLE IF EXISTS $tablename "; |
||||
|
||||
Database::query($sql); |
||||
|
@ -0,0 +1,296 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* This file is a cron microclock script. |
||||
* It will be used as replacement of setting individual |
||||
* cron lines for all virtual instances. |
||||
* |
||||
* Setup this vcron to run at the smallest period possible, as |
||||
* it will schedule all availables vchamilos to be run as required. |
||||
* Note that one activaton of this cron may not always run real crons |
||||
* or may be run more than one cron. |
||||
* |
||||
* If used on a big system with clustering, ensure hostnames are adressed |
||||
* at the load balancer entry and not on physical hosts |
||||
* |
||||
* @package plugin/vchamilo |
||||
* @category plugins |
||||
* @author Valery fremaux (valery.fremaux@gmail.com) |
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL |
||||
*/ |
||||
define('CLI_SCRIPT', true); // for chamilo imported code |
||||
require_once dirname(dirname(dirname(__FILE__))).'/main/inc/global.inc.php'; |
||||
require_once dirname(dirname(dirname(__FILE__))).'/local/classes/database.class.php'; |
||||
|
||||
global $DB; |
||||
$DB = new DatabaseManager(); |
||||
|
||||
define('ROUND_ROBIN', 0); |
||||
define('LOWEST_POSSIBLE_GAP', 1); |
||||
|
||||
global $VCRON; |
||||
|
||||
$VCRON = new StdClass; |
||||
$VCRON->ACTIVATION = 'cli'; // choose how individual cron are launched, 'cli' or 'web' |
||||
$VCRON->STRATEGY = ROUND_ROBIN ; // choose vcron rotation mode |
||||
$VCRON->PERIOD = 15 * MINSECS ; // used if LOWEST_POSSIBLE_GAP to setup the max gap |
||||
$VCRON->TIMEOUT = 300; // time out for CURL call to effective cron |
||||
// $VCRON->TRACE = $_configuration['root_sys'].'plugin/vchamilo/log/vcrontrace.log'; // Trace file where to collect cron outputs |
||||
$VCRON->TRACE = '/data/log/chamilo/vcrontrace.log'; // Trace file where to collect cron outputs |
||||
$VCRON->TRACE_ENABLE = true; // enables tracing |
||||
|
||||
if (!is_dir($_configuration['root_sys'].'plugin/vchamilo/log')) { |
||||
mkdir($_configuration['root_sys'].'plugin/vchamilo/log', 0777, true); |
||||
} |
||||
|
||||
/** |
||||
* fire a cron URL using CURL. |
||||
* |
||||
* |
||||
*/ |
||||
function fire_vhost_cron($vhost) { |
||||
global $VCRON,$DB; |
||||
|
||||
if ($VCRON->TRACE_ENABLE) { |
||||
$CRONTRACE = fopen($VCRON->TRACE, 'a'); |
||||
} |
||||
$ch = curl_init($vhost->root_web.'/main/cron/run.php'); |
||||
|
||||
$http_proxy_host = api_get_setting('vchamilo_httpproxyhost', 'vchamilo'); |
||||
$http_proxy_port = api_get_setting('vchamilo_httpproxyport', 'vchamilo'); |
||||
$http_proxy_bypass = api_get_setting('vchamilo_httpproxybypass', 'vchamilo'); |
||||
$http_proxy_user = api_get_setting('vchamilo_httpproxyuser', 'vchamilo'); |
||||
$http_proxy_password = api_get_setting('vchamilo_httpproxypassword', 'vchamilo'); |
||||
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $VCRON->TIMEOUT); |
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
||||
curl_setopt($ch, CURLOPT_POST, true); |
||||
curl_setopt($ch, CURLOPT_USERAGENT, 'Chamilo'); |
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, ''); |
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml charset=UTF-8")); |
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); |
||||
|
||||
// Check for proxy. |
||||
if (!empty($http_proxy_host) and !is_proxybypass($uri)) { |
||||
|
||||
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, false); |
||||
|
||||
if (empty($http_proxy_port)) { |
||||
echo "Using proxy $http_proxy_host\n"; |
||||
curl_setopt($ch, CURLOPT_PROXY, $http_proxy_host); |
||||
} else { |
||||
echo "Using proxy $http_proxy_host:$http_proxy_port\n"; |
||||
curl_setopt($ch, CURLOPT_PROXY, $http_proxy_host.':'.$http_proxy_port); |
||||
} |
||||
|
||||
if (!empty($http_proxy_user) and !empty($http_proxy_password)) { |
||||
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $http_proxy_user.':'.$http_proxy_password); |
||||
if (defined('CURLOPT_PROXYAUTH')) { |
||||
// any proxy authentication if PHP 5.1 |
||||
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC | CURLAUTH_NTLM); |
||||
} |
||||
} |
||||
} |
||||
|
||||
$timestamp_send = time(); |
||||
$rawresponse = curl_exec($ch); |
||||
$timestamp_receive = time(); |
||||
|
||||
if ($rawresponse === false) { |
||||
$error = curl_errno($ch) .':'. curl_error($ch); |
||||
if ($VCRON->TRACE_ENABLE){ |
||||
if ($CRONTRACE){ |
||||
fputs($CRONTRACE, "VCron start on $vhost->root_web : ".api_time_to_hms($timestamp_send)."\n" ); |
||||
fputs($CRONTRACE, "VCron Error : $error \n"); |
||||
fputs($CRONTRACE, "VCron stop on $vhost->root_web : $timestamp_receive\n#################\n\n" ); |
||||
fclose($CRONTRACE); |
||||
} |
||||
} |
||||
echo("VCron started on $vhost->root_web : ".api_time_to_hms($timestamp_send)."\n" ); |
||||
echo("VCron Error : $error \n"); |
||||
echo("VCron stop on $vhost->root_web : ".api_time_to_hms($timestamp_receive)."\n#################\n\n" ); |
||||
return false; |
||||
} |
||||
|
||||
if ($VCRON->TRACE_ENABLE) { |
||||
if ($CRONTRACE) { |
||||
fputs($CRONTRACE, "VCron start on $vhost->vhostname : ".api_time_to_hms($timestamp_send)."\n" ); |
||||
fputs($CRONTRACE, $rawresponse."\n"); |
||||
fputs($CRONTRACE, "VCron stop on $vhost->vhostname : ".api_time_to_hms($timestamp_receive)."\n#################\n\n" ); |
||||
fclose($CRONTRACE); |
||||
} |
||||
} |
||||
echo("VCron start on $vhost->root_web : ".api_time_to_hms($timestamp_send)."\n" ); |
||||
echo($rawresponse."\n"); |
||||
echo("VCron stop on $vhost->root_web : ".api_time_to_hms($timestamp_receive)."\n#################\n\n" ); |
||||
$vhost->lastcrongap = time() - $vhost->lastcron; |
||||
$vhost->lastcron = $timestamp_send; |
||||
$vhost->croncount++; |
||||
|
||||
$vhostid = $vhost->id; |
||||
unset($vhost->id); |
||||
|
||||
Database::update('vchamilo', (array)$vhost, array('id = ?' => $vhostid)); |
||||
|
||||
} |
||||
|
||||
/** |
||||
* fire a cron URL using cli exec |
||||
* |
||||
* |
||||
*/ |
||||
function exec_vhost_cron($vhost) { |
||||
global $VCRON, $DB, $_configuration; |
||||
|
||||
if ($VCRON->TRACE_ENABLE) { |
||||
$CRONTRACE = fopen($VCRON->TRACE, 'a'); |
||||
} |
||||
|
||||
$cmd = 'php "'.$_configuration['root_sys'].'/plugin/vchamilo/cli/cron.php" --host='.$vhost->root_web; |
||||
|
||||
$timestamp_send = time(); |
||||
exec($cmd, $rawresponse); |
||||
$timestamp_receive = time(); |
||||
|
||||
if ($VCRON->TRACE_ENABLE) { |
||||
if ($CRONTRACE) { |
||||
fputs($CRONTRACE, "VCron start on $vhost->root_web : $timestamp_send\n" ); |
||||
fputs($CRONTRACE, $rawresponse."\n"); |
||||
fputs($CRONTRACE, "VCron stop on $vhost->root_web : $timestamp_receive\n#################\n\n" ); |
||||
fclose($CRONTRACE); |
||||
} |
||||
} |
||||
|
||||
echo "VCron start on $vhost->root_web : $timestamp_send\n"; |
||||
echo implode("\n", $rawresponse)."\n"; |
||||
echo "VCron stop on $vhost->root_web : $timestamp_receive\n#################\n\n"; |
||||
|
||||
$vhost->lastcrongap = time() - $vhost->lastcron; |
||||
$vhost->lastcron = $timestamp_send; |
||||
$vhost->croncount++; |
||||
|
||||
$DB->update_record('vchamilo', $vhost, 'id'); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* check if $url matches anything in proxybypass list |
||||
* |
||||
* any errors just result in the proxy being used (least bad) |
||||
* |
||||
* @global object |
||||
* @param string $url url to check |
||||
* @return boolean true if we should bypass the proxy |
||||
*/ |
||||
function is_proxybypass( $url ) { |
||||
global $CFG; |
||||
|
||||
$http_proxy_host = api_get_setting('vchamilo_httpproxyhost', 'vchamilo'); |
||||
$http_proxy_port = api_get_setting('vchamilo_httpproxyport', 'vchamilo'); |
||||
$http_proxy_bypass = api_get_setting('vchamilo_httpproxybypass', 'vchamilo'); |
||||
|
||||
// sanity check |
||||
if (empty($http_proxy_host) or empty($http_proxy_bypass)) { |
||||
return false; |
||||
} |
||||
|
||||
// get the host part out of the url |
||||
if (!$host = parse_url( $url, PHP_URL_HOST )) { |
||||
return false; |
||||
} |
||||
|
||||
// get the possible bypass hosts into an array |
||||
$matches = explode(',', $http_proxy_bypass ); |
||||
|
||||
// check for a match |
||||
// (IPs need to match the left hand side and hosts the right of the url, |
||||
// but we can recklessly check both as there can't be a false +ve) |
||||
$bypass = false; |
||||
foreach ($matches as $match) { |
||||
$match = trim($match); |
||||
|
||||
// try for IP match (Left side) |
||||
$lhs = substr($host,0,strlen($match)); |
||||
if (strcasecmp($match,$lhs)==0) { |
||||
return true; |
||||
} |
||||
|
||||
// try for host match (Right side) |
||||
$rhs = substr($host,-strlen($match)); |
||||
if (strcasecmp($match,$rhs)==0) { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
// nothing matched. |
||||
return false; |
||||
} |
||||
|
||||
// Main execution sequence |
||||
|
||||
if (!$vchamilos = Database::select('*', 'vchamilo', array(), 'all')){ |
||||
die("Nothing to do. No Vhosts"); |
||||
} |
||||
|
||||
$allvhosts = array_values($vchamilos); |
||||
|
||||
echo("<pre>"); |
||||
echo("Chamilo VCron... start\n"); |
||||
echo("Last croned : ".api_get_setting('vchamilo_cron_lasthost', 'vchamilo')."\n"); |
||||
|
||||
if ($VCRON->STRATEGY == ROUND_ROBIN) { |
||||
$rr = 0; |
||||
foreach ($allvhosts as $vhostassoc) { |
||||
$vhost = (object)$vhostassoc; |
||||
if ($rr == 1) { |
||||
api_set_setting('vchamilo_cron_lasthost', $vhost->id); |
||||
echo("Round Robin : ".$vhost->root_web."\n"); |
||||
if ($VCRON->ACTIVATION == 'cli') { |
||||
exec_vhost_cron($vhost); |
||||
} else { |
||||
fire_vhost_cron($vhost); |
||||
} |
||||
|
||||
die('Done.'); |
||||
} |
||||
if ($vhost->id == api_get_setting('vchamilo_cron_lasthost', 'vchamilo')){ |
||||
$rr = 1; // take next one |
||||
} |
||||
} |
||||
|
||||
// We were at last. Loop back and take first. |
||||
$firsthost = (object)$allvhosts[0]; |
||||
api_set_setting('vchamilo_cron_lasthost', $firsthost->id, 'vchamilo'); |
||||
echo("Round Robin : ".$firsthost->root_web."\n"); |
||||
if ($VCRON->ACTIVATION == 'cli') { |
||||
exec_vhost_cron($firsthost); |
||||
} else { |
||||
fire_vhost_cron($firsthost); |
||||
} |
||||
|
||||
} else if ($VCRON->STRATEGY == LOWEST_POSSIBLE_GAP) { |
||||
// First make measurement of cron period. |
||||
if (api_get_setting('vcrontickperiod', 'vchamilo')) { |
||||
api_set_setting('vcrontime', time(), 'vchamilo'); |
||||
return; |
||||
} |
||||
api_set_setting('vcrontickperiod', time() - api_get_setting('vcrontime', 'vchamilo'), 'vchamilo'); |
||||
$hostsperturn = max(1, $VCRON->PERIOD / api_get_setting('vcrontickperiod', 'vchamilo') * count($allvhosts)); |
||||
$i = 0; |
||||
foreach ($allvhosts as $vhostassoc) { |
||||
$vhost = (object)$vhostassoc; |
||||
if ((time() - $vhost->lastcron) > $VCRON->PERIOD) { |
||||
if ($VCRON->ACTIVATION == 'cli') { |
||||
exec_vhost_cron($vhost); |
||||
} else { |
||||
fire_vhost_cron($vhost); |
||||
} |
||||
$i++; |
||||
if ($i >= $hostsperturn) { |
||||
return; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,230 @@ |
||||
<?php |
||||
|
||||
require_once(api_get_path(LIBRARY_PATH).'fileManage.lib.php'); |
||||
|
||||
if (!defined('CHAMILO_INTERNAL')) die('You cannot use this script this way'); |
||||
|
||||
if ($data->what == 'addinstance' || $data->what == 'registerinstance') { |
||||
|
||||
unset($data->what); |
||||
unset($data->submitbutton); |
||||
unset($data->id); |
||||
$registeronly = $data->registeronly; |
||||
unset($data->registeronly); |
||||
$data->lastcron = 0; |
||||
$data->lastcrongap = 0; |
||||
$data->croncount = 0; |
||||
|
||||
if (isset($data->template)) { |
||||
$template = $data->template; |
||||
unset($data->template); |
||||
} |
||||
|
||||
ctrace("Registering VChamilo "); |
||||
$tablename = Database::get_main_table('vchamilo'); |
||||
if ($DB->record_exists('vchamilo', array('root_web' => $data->root_web))) { |
||||
$DB->update_record('vchamilo', $data, 'root_web'); |
||||
} else { |
||||
$DB->insert_record('vchamilo', $data); |
||||
} |
||||
|
||||
if ($registeronly){ |
||||
// Stop it now. |
||||
ctrace("Registering only. out."); |
||||
vchamilo_redirect(api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php'); |
||||
} |
||||
|
||||
// or we continue with physical creation |
||||
|
||||
// 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(TO_SYS, SYS_PATH).$data->course_folder; |
||||
} |
||||
|
||||
if (!is_dir($coursedir)) { |
||||
ctrace("Creating physical course dir in $coursedir"); |
||||
mkdir($coursedir, 0777, true); |
||||
// initiate default index |
||||
$INDEX = fopen($coursedir.'/index.html', 'w'); |
||||
fputs($INDEX, vchamilo_get_default_course_index_fragment()); |
||||
fclose($INDEX); |
||||
|
||||
$HTACCESS = fopen($coursedir.'/.htaccess', 'w'); |
||||
fputs($HTACCESS, vchamilo_get_htaccess_fragment($data->course_folder)); |
||||
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 |
||||
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 |
||||
assert(!is_dir($standardlocation)); |
||||
|
||||
ctrace("Linking virtual coursedir "); |
||||
chdir(dirname($standardlocation)); |
||||
if (!symlink($coursedir, basename($coursedir))) { |
||||
ctrace("Could not link $standardlocation => $coursedir "); |
||||
} |
||||
} else { |
||||
ctrace("Course dir in standard location"); |
||||
} |
||||
|
||||
// create homedir |
||||
|
||||
// Structure of virtualized home folders : |
||||
|
||||
/* |
||||
* {LegacyHomeContainer} => {VChamiloSubcontainer} => {BrandedAccessUrlHome} |
||||
* |
||||
*/ |
||||
|
||||
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(TO_SYS, SYS_PATH).'home/'.$home_folder; |
||||
} |
||||
|
||||
ctrace("Making home dir as $homedir "); |
||||
|
||||
if (!is_dir($homedir)){ |
||||
ctrace("Creating home dir "); |
||||
if (!mkdir($homedir, 0777, true)){ |
||||
ctrace("Error creating home dir $homedir \n"); |
||||
} |
||||
} |
||||
|
||||
ctrace("Checking direct home dir "); |
||||
|
||||
// if real homedir IS NOT under chamilo install, link to it |
||||
// Seems not be necessary as we can globally link the whole Home container |
||||
/* |
||||
$standardlocation = $_configuration['root_sys'].'home/'.$home_folder; // where it should be |
||||
if ($homedir != $standardlocation){ |
||||
ctrace("Linking virtual home dir "); |
||||
if (!symlink($homedir, $standardlocation)){ |
||||
ctrace("could not link $standardlocation => $homedir "); |
||||
} |
||||
} |
||||
*/ |
||||
|
||||
// create archive |
||||
if($absalternatearchive = vchamilo_get_config('vchamilo', 'archive_real_root')){ |
||||
$archivedir = str_replace('//', '/', $absalternatearchive.'/'.$archive_folder); |
||||
} else { |
||||
$archivedir = $_configuration['root_sys'].'archive/'.$archive_folder; |
||||
} |
||||
|
||||
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"); |
||||
} |
||||
} |
||||
|
||||
ctrace("Checking direct archive dir "); |
||||
|
||||
// if real archivedir IS NOT under chamilo install, link to it |
||||
// Seems not be necessary as we can globally link the whole Home container |
||||
/* |
||||
$standardlocation = $_configuration['root_sys'].'archive/'.$archive_folder; // where it should be |
||||
if ($archivedir != $standardlocation){ |
||||
ctrace("Linking virtual archive dir "); |
||||
if (!symlink($archivedir, $standardlocation)){ |
||||
ctrace("could not link $standardlocation => $archivedir "); |
||||
} |
||||
} |
||||
*/ |
||||
|
||||
if (!$template) { |
||||
// Create empty database for install |
||||
ctrace("Creating databases (empty) "); |
||||
vchamilo_create_databases($data); |
||||
} else { |
||||
// deploy template database |
||||
|
||||
ctrace("Creating databases from template $template "); |
||||
|
||||
vchamilo_create_databases($data); |
||||
|
||||
ctrace("Loading data template $template "); |
||||
|
||||
vchamilo_load_db_template($data, 'main_database', $template); |
||||
if (!empty($data->statistics_database) && $data->main_database != $data->statistics_database) { |
||||
vchamilo_load_db_template($data, 'statistics_database', $template); |
||||
} |
||||
if (!empty($data->user_personal_database) && ($data->main_database != $data->user_personal_database) && ($data->user_personal_database != $data->statistics_database)) { |
||||
vchamilo_load_db_template($data, 'user_personal_database', $template); |
||||
} |
||||
|
||||
ctrace("Coying files from template $template "); |
||||
|
||||
vchamilo_load_files_from_template($data, $template); |
||||
} |
||||
|
||||
ctrace("Fixing records"); |
||||
|
||||
// Builds a new database manager on new instance to operate records |
||||
$NDB = new DatabaseManager($data); |
||||
|
||||
// pluging in site name institution |
||||
$settingstable = $NDB->format_table_name(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' "; |
||||
$accessurltable = $NDB->format_table_name('access_url'); |
||||
$sqls[] = " UPDATE {$accessurltable} SET url = '{$data->root_web}' WHERE id = '1' "; |
||||
|
||||
foreach ($sqls as $sql) { |
||||
$NDB->execute_sql($sql); |
||||
} |
||||
|
||||
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; |
||||
} |
||||
} |
||||
|
||||
if ($data->what == 'updateinstance') { |
||||
|
||||
unset($data->what); |
||||
unset($data->submitbutton); |
||||
unset($data->registeronly); |
||||
unset($data->template); |
||||
$data->lastcron = 0; |
||||
$data->lastcrongap = 0; |
||||
$data->croncount = 0; |
||||
$data->id = $data->vid; |
||||
unset($data->vid); |
||||
|
||||
if (!$DB->update_record('vchamilo', $data, 'id')) { |
||||
error_log('Vchamilo update error'); |
||||
} |
||||
|
||||
vchamilo_redirect(api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php'); |
||||
} |
@ -0,0 +1,68 @@ |
||||
<?php |
||||
|
||||
define('CHAMILO_INTERNAL', true); |
||||
|
||||
global $plugininstance; |
||||
|
||||
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'); |
||||
|
||||
global $DB; |
||||
$DB = new DatabaseManager(); |
||||
|
||||
require_once(api_get_path(SYS_PLUGIN_PATH).'vchamilo/lib/vchamilo_plugin.class.php'); |
||||
require_once(api_get_path(SYS_PLUGIN_PATH).'vchamilo/views/editinstance_form.php'); |
||||
HTML_QuickForm::registerElementType('cancel', api_get_path(SYS_PLUGIN_PATH).'vchamilo/lib/QuickForm/cancel.php', 'HTML_QuickForm_cancel'); |
||||
|
||||
$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']; |
||||
$registeronly = @$_REQUEST['registeronly']; |
||||
$plugininstance = VChamiloPlugin::create(); |
||||
$thisurl = api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php'; |
||||
|
||||
// security |
||||
api_protect_admin_script(); |
||||
|
||||
|
||||
if ($id) { |
||||
$mode = 'update'; |
||||
} else { |
||||
$mode = ($registeronly) ? 'register' : 'add' ; |
||||
} |
||||
|
||||
$form = new InstanceForm($plugininstance, $mode); |
||||
$form->definition(); |
||||
|
||||
$actions = ''; |
||||
$message = ''; |
||||
|
||||
// call controller |
||||
// $data = $form->get_data(); |
||||
if ($data = $form->get_data()){ |
||||
include(api_get_path(SYS_PLUGIN_PATH).'vchamilo/views/editinstance.controller.php'); |
||||
} |
||||
|
||||
if ($id){ |
||||
$vhost = $DB->get_record('vchamilo', array('id' => $id)); |
||||
$vhost->vid = $vhost->id; |
||||
unset($vhost->id); |
||||
$form->set_data((array)$vhost); |
||||
} else { |
||||
$data = array(); |
||||
$data['db_host'] = 'localhost'; |
||||
$data['single_database'] = 1; |
||||
$data['registeronly'] = $registeronly; |
||||
$form->set_data($data); |
||||
} |
||||
|
||||
$content = $form->return_form(); |
||||
|
||||
$tpl = new Template($tool_name, true, true, false, true, false); |
||||
$tpl->assign('actions', $actions); |
||||
$tpl->assign('message', $message); |
||||
$tpl->assign('content', $content); |
||||
$tpl->display_one_col_template(); |
@ -0,0 +1,151 @@ |
||||
<?php |
||||
|
||||
require_once(api_get_path(SYS_CODE_PATH).'inc/lib/pear/HTML/QuickForm.php'); |
||||
require_once(api_get_path(SYS_CODE_PATH).'inc/lib/formvalidator/FormValidator.class.php'); |
||||
require_once($_configuration['root_sys'].'local/classes/formslib.php'); |
||||
|
||||
class InstanceForm extends ChamiloForm{ |
||||
|
||||
var $_plugin; |
||||
|
||||
function __construct($plugin, $mode = 'add', $returnurl = null, $cancelurl = null){ |
||||
global $_configuration; |
||||
|
||||
$this->_plugin = $plugin; |
||||
|
||||
$returnurl = $_configuration['root_web'].'plugin/vchamilo/views/editinstance.php'; |
||||
$cancelurl = $_configuration['root_web'].'plugin/vchamilo/views/manage.php'; |
||||
parent::__construct($mode, $returnurl, $cancelurl); |
||||
} |
||||
|
||||
function definition(){ |
||||
global $_configuration; |
||||
|
||||
$cform = $this->_form; |
||||
|
||||
// Settings variables. |
||||
$size_input_text = 'size="30"'; |
||||
$size_input_text_big = 'size="60"'; |
||||
|
||||
/* |
||||
* Host's id. |
||||
*/ |
||||
$cform->addElement('hidden', 'vid'); |
||||
$cform->addElement('hidden', 'what', $this->_mode.'instance'); |
||||
$cform->addElement('hidden', 'registeronly'); |
||||
|
||||
/* |
||||
* Features fieldset. |
||||
*/ |
||||
$cform->addElement('header', $this->_plugin->get_lang('hostdefinition')); |
||||
// Name. |
||||
$cform->addElement('text', 'sitename', $this->_plugin->get_lang('sitename'), $size_input_text); |
||||
$cform->applyFilter('sitename', 'html_filter'); |
||||
$cform->applyFilter('sitename', 'trim'); |
||||
|
||||
// Shortname. |
||||
$cform->addElement('text', 'institution', $this->_plugin->get_lang('institution'), ($this->mode == 'edit' ? 'disabled="disabled" ' : '')); |
||||
$cform->applyFilter('institution', 'html_filter'); |
||||
$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->applyFilter('root_web', 'trim'); |
||||
|
||||
/* |
||||
* Database fieldset. |
||||
*/ |
||||
$cform->addElement('header', $this->_plugin->get_lang('dbgroup')); |
||||
|
||||
// Database host. |
||||
$cform->addElement('text', 'db_host', $this->_plugin->get_lang('dbhost'), array('id' => 'id_vdbhost')); |
||||
$cform->applyFilter('db_host', 'trim'); |
||||
|
||||
// Database login. |
||||
$cform->addElement('text', 'db_user', $this->_plugin->get_lang('dbuser'), array('id' => 'id_vdbuser')); |
||||
$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;"'); |
||||
|
||||
// Database name. |
||||
$cform->addElement('text', 'main_database', $this->_plugin->get_lang('maindatabase')); |
||||
|
||||
// Database name. |
||||
$cform->addElement('text', 'statistics_database', $this->_plugin->get_lang('statisticsdatabase')); |
||||
|
||||
// Database name. |
||||
$cform->addElement('text', 'user_personal_database', $this->_plugin->get_lang('userpersonaldatabase')); |
||||
|
||||
// tracking_enabled |
||||
$yesnooptions = array('0' => $this->_plugin->get_lang('no'), '1' => $this->_plugin->get_lang('yes')); |
||||
$cform->addElement('select', 'tracking_enabled', $this->_plugin->get_lang('trackingenabled'), $yesnooptions); |
||||
|
||||
// Single database |
||||
$cform->addElement('select', 'single_database', $this->_plugin->get_lang('singledatabase'), $yesnooptions); |
||||
|
||||
// Table's prefix. |
||||
$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')); |
||||
|
||||
// Button for testing datapath. |
||||
$cform->addElement('button', 'testdatapath', $this->_plugin->get_lang('testdatapath'), 'onclick="opendatapathpopup(\''.$_configuration['root_web'].'\'); return true;"'); |
||||
|
||||
/* |
||||
* Template selection. |
||||
*/ |
||||
if ($this->is_in_add_mode()) { |
||||
$cform->addElement('header', $this->_plugin->get_lang('templating')); |
||||
|
||||
$templateoptions = vchamilo_get_available_templates(); |
||||
|
||||
// Template choice |
||||
$cform->addElement('select', 'template', $this->_plugin->get_lang('template'), $templateoptions); |
||||
} |
||||
|
||||
$submitstr = $this->_plugin->get_lang('savechanges'); |
||||
$cancelstr = $this->_plugin->get_lang('cancel'); |
||||
$this->add_action_buttons(true, $submitstr, $cancelstr); |
||||
|
||||
// Rules for the 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('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'); |
||||
} |
||||
} |
||||
|
||||
function validation($data, $files = null){ |
||||
global $plugininstance; |
||||
|
||||
$errors = array(); |
||||
var_dump($data); |
||||
if (!preg_match('/^courses[_-]/', $data['course_folder'])){ |
||||
$errors['course_folder'] = $plugininstance->get_lang('errormuststartwithcourses'); |
||||
} |
||||
|
||||
$tablename = Database::get_main_table('vchamilo'); |
||||
if($vchamilo = Database::select('*', $tablename, array('where' => array(' root_web = ? ' => array($data->root_web))))){ |
||||
$errors['root_web'] = $plugininstance->get_lang('errorrootwebexists'); |
||||
} |
||||
|
||||
if(!empty($errors)){ |
||||
return $errors; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,375 @@ |
||||
<?php |
||||
|
||||
require_once(api_get_path(LIBRARY_PATH).'fileManage.lib.php'); |
||||
|
||||
$table = Database::get_main_table('vchamilo'); |
||||
|
||||
if (!defined('CHAMILO_INTERNAL')) { |
||||
die('You cannot use this script this way'); |
||||
} |
||||
|
||||
if ($action == 'newinstance' || $action == 'instance') { |
||||
$registeronly = $_REQUEST['registeronly']; |
||||
vchamilo_redirect(api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/editinstance.php?registeronly='.$registeronly); |
||||
} |
||||
|
||||
if ($action == 'editinstance') { |
||||
$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"); |
||||
// Make it not visible. |
||||
$vidlist = implode("','", $_REQUEST['vids']); |
||||
$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') { |
||||
|
||||
ctrace("Enabling instance"); |
||||
$vidlist = implode("','", $_REQUEST['vids']); |
||||
$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') { |
||||
|
||||
ctrace("Destroying instance"); |
||||
// Removes everything. |
||||
if (empty($automation)) { |
||||
$vidlist = implode("','", $_REQUEST['vids']); |
||||
$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()))); |
||||
} |
||||
|
||||
foreach ($todelete as $fooid => $instance) { |
||||
|
||||
echo "<pre>"; |
||||
echo ("Dropping instance databases \n"); |
||||
vchamilo_drop_databases($instance); |
||||
|
||||
// Remove all files and eventual symlinks |
||||
|
||||
$absalternatecourse = vchamilo_get_config('vchamilo', 'course_real_root'); |
||||
if (!empty($absalternatecourse)){ |
||||
// this is the relocated case |
||||
$coursedir = str_replace('//', '/', $absalternatecourse.'/'.$instance->course_folder); |
||||
} else { |
||||
// this is the standard local case |
||||
$coursedir = api_get_path(TO_SYS, SYS_PATH).$instance->course_folder; |
||||
} |
||||
$standardlocation = str_replace('//', '/', $_configuration['root_sys'].'/'.$instance->course_folder); // where it should be |
||||
|
||||
echo ("Deleting $coursedir \n"); |
||||
removeDir($coursedir); |
||||
if (is_link($standardlocation)) { |
||||
unlink($standardlocation); |
||||
} |
||||
|
||||
preg_match('#https?://([^\.]+)#', $instance->root_web, $matches); |
||||
$home_folder = $matches[1]; |
||||
$archive_folder = $matches[1]; // prepare it now |
||||
|
||||
if ($absalternatehome = vchamilo_get_config('vchamilo', 'home_real_root')){ |
||||
$homedir = str_replace('//', '/', $absalternatehome.'/'.$home_folder); |
||||
} else { |
||||
$homedir = api_get_path(TO_SYS, SYS_PATH).'home/'.$home_folder; |
||||
} |
||||
$standardlocation = $_configuration['root_sys'].'home/'.$home_folder; // where it should be |
||||
|
||||
echo ("Deleting $homedir \n"); |
||||
removeDir($homedir); |
||||
if (is_link($standardlocation)) { |
||||
unlink($standardlocation); |
||||
} |
||||
|
||||
// delete archive |
||||
if($absalternatearchive = vchamilo_get_config('vchamilo', 'archive_real_root')){ |
||||
$archivedir = str_replace('//', '/', $absalternatearchive.'/'.$archive_folder); |
||||
} else { |
||||
$archivedir = $_configuration['root_sys'].'archive/'.$archive_folder; |
||||
} |
||||
$standardlocation = $_configuration['root_sys'].'archive/'.$archive_folder; // where it should be |
||||
|
||||
echo ("Deleting $archivedir \n"); |
||||
removeDir($archivedir); |
||||
if (is_link($standardlocation)) { |
||||
unlink($standardlocation); |
||||
} |
||||
echo '</pre>'; |
||||
|
||||
echo ("Removing vchamilo record \n"); |
||||
$sql = " |
||||
DELETE FROM |
||||
{$table} |
||||
WHERE |
||||
id = {$instance->id} |
||||
"; |
||||
Database::query($sql); |
||||
|
||||
} |
||||
|
||||
// vchamilo_redirect($_configuration['root_web'].'/plugin/vchamilo/views/manage.php'); |
||||
} |
||||
if ($action == 'snapshotinstance') { |
||||
|
||||
$vid = $_REQUEST['vid']; |
||||
if ($vid) { |
||||
$vhosts = Database::select('*', 'vchamilo', array('where' => array('id = ?' => $vid))); |
||||
$vhost = (object)array_pop($vhosts); |
||||
} else { |
||||
$vhost = (object)$_configuration; |
||||
} |
||||
|
||||
// Parsing url for building the template name. |
||||
$wwwroot = $vhost->root_web; |
||||
$vchamilostep = $_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 |
||||
$absolute_templatesdir = $_configuration['root_sys'].$templatefoldername; |
||||
|
||||
if (preg_match('/ /', $absolute_sqldir)){ |
||||
$erroritem = new StdClass(); |
||||
$erroritem->message = $plugininstance->get_lang('errorspacesinpath'); |
||||
vchamilo_print_error(array($erroritem)); |
||||
} |
||||
|
||||
if (!is_dir($absolute_templatesdir)){ |
||||
mkdir($absolute_templatesdir, 0777, true); |
||||
} |
||||
|
||||
if ($vchamilostep == 0) { |
||||
// Create directories, if necessary. |
||||
if (!is_dir($absolute_datadir)){ |
||||
mkdir($absolute_datadir, 0777, true); |
||||
mkdir($absolute_datadir.'/archive', 0777, true); |
||||
mkdir($absolute_datadir.'/home', 0777, true); |
||||
} |
||||
if (!is_dir($absolute_sqldir)) { |
||||
mkdir($absolute_sqldir, 0777, true); |
||||
} |
||||
if (empty($fullautomation)) { |
||||
$actionurl = $_configuration['root_web'].'/plugin/vchamilo/views/manage.php'; |
||||
$content .= '<form name"single" action="'.$actionurl.'">'; |
||||
$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->assign('actions', ''); |
||||
$tpl->assign('message', $plugininstance->get_lang('vchamilosnapshot1')); |
||||
$tpl->assign('content', $content); |
||||
$tpl->display_one_col_template(); |
||||
|
||||
die; |
||||
} else { |
||||
// continue next step |
||||
$vchamilostep = 1; |
||||
} |
||||
} |
||||
if ($vchamilostep >= 1) { |
||||
if ($wwwroot == $_configuration['root_web']) { |
||||
// Make fake Vchamilo record. |
||||
$vchamilo = vchamilo_make_this(); |
||||
$vcoursepath = api_get_path(TO_SYS, SYS_COURSE_PATH); |
||||
$vhomepath = api_get_path(TO_SYS, SYS_HOME_PATH); |
||||
$varchivepath = api_get_path(TO_SYS, SYS_ARCHIVE_PATH); |
||||
} else { |
||||
// Get Vchamilo known record. |
||||
$vchamilos = Database::select('*', 'vchamilo', array('where' => array('root_web = ?' => array($wwwroot)))); |
||||
$vchamilo = (object)array_pop($vchamilos); |
||||
$vcoursepath = api_get_path(TO_SYS, SYS_COURSE_PATH, (array)$vchamilo); |
||||
$vhomepath = api_get_path(TO_SYS, SYS_HOME_PATH, (array)$vchamilo); |
||||
$varchivepath = api_get_path(TO_SYS, SYS_ARCHIVE_PATH, (array)$vchamilo); |
||||
} |
||||
|
||||
if ($vchamilostep == 1) { |
||||
// Auto dump the databases in a master template folder. |
||||
// this will create three files : chamilo_master_main.sql, chamilo_master_statistics.sql, chamilo_master_user_personal.sql |
||||
$errors = vchamilo_dump_databases($vchamilo, $absolute_sqldir.$separator.'chamilo_master'); |
||||
|
||||
if (empty($fullautomation)) { |
||||
if(!empty($errors)) { |
||||
$actionurl = $_configuration['root_web'].'/plugin/vchamilo/views/manage.php'; |
||||
|
||||
$message = vchamilo_print_error($errors, true); |
||||
|
||||
$content .= '<p><form name"single" action="'.$actionurl.'">'; |
||||
$content .= '<input type="submit" name="go_btn" value="'.$plugininstance->get_lang('cancel').'" />'; |
||||
$content .= '</form></p>'; |
||||
} else { |
||||
$actionurl = $_configuration['root_web'].'/plugin/vchamilo/views/manage.php'; |
||||
|
||||
$message = $plugininstance->get_lang('vchamilosnapshot2'); |
||||
|
||||
$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="2" />'; |
||||
$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->assign('actions', ''); |
||||
$tpl->assign('message', $message); |
||||
$tpl->assign('content', $content); |
||||
$tpl->display_one_col_template(); |
||||
|
||||
die; |
||||
} |
||||
} |
||||
|
||||
// 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"); |
||||
copyDirTo($vcoursepath, $absolute_datadir, false); |
||||
echo ("Copying from $varchivepath to {$absolute_datadir}/archive \n"); |
||||
copyDirTo($varchivepath, $absolute_datadir.'/archive', false); |
||||
echo ("Copying from $vhomepath to {$absolute_datadir}/home \n"); |
||||
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'); |
||||
fwrite($FILE, '<'.'?php '); |
||||
fwrite($FILE, "\$templatewwwroot = '".$wwwroot."';\n"); |
||||
fwrite($FILE, "\$templatevdbprefix = '".$vhost->table_prefix."';\n "); |
||||
fwrite($FILE, "\$coursefolder = '".$vhost->course_folder."';\n "); |
||||
fwrite($FILE, '?'.'>'); |
||||
fclose($FILE); |
||||
|
||||
// Every step was SUCCESS. |
||||
if (empty($fullautomation)){ |
||||
$message_object->message = $plugininstance->get_lang('successfinishedcapture'); |
||||
$message_object->style = 'notifysuccess'; |
||||
|
||||
// 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->assign('actions', ''); |
||||
$tpl->assign('message', $plugininstance->get_lang('vchamilosnapshot3')); |
||||
$tpl->assign('content', $content); |
||||
$tpl->display_one_col_template(); |
||||
|
||||
die; |
||||
} |
||||
} |
||||
} |
||||
|
||||
if ($action == 'clearcache') { |
||||
|
||||
ctrace("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 = $_REQUEST['vid']; |
||||
if ($vid) { |
||||
$vhosts = Database::select('*', 'vchamilo', array('where' => array('id = ?' => $vid))); |
||||
$vhost = (object)array_pop($vhosts); |
||||
$toclear[$vhost->id] = $vhost; |
||||
} else { |
||||
$toclear[0] = (object)$_configuration; |
||||
} |
||||
} |
||||
} else { |
||||
$toclear = Database::select('*', 'vchamilo', array('where' => array("root_web = '{$n->root_web}' " => array()))); |
||||
} |
||||
|
||||
echo '<pre>'; |
||||
foreach ($toclear as $fooid => $instance) { |
||||
|
||||
if ($fooid == 0) { |
||||
echo ("Clearing master template cache \n"); |
||||
} else { |
||||
echo ("Clearing instance template cache \n"); |
||||
} |
||||
|
||||
// Get instance archive |
||||
$archivepath = api_get_path(SYS_ARCHIVE_PATH, TO_SYS, (array)$instance); |
||||
$templatepath = $archivepath.'twig'; |
||||
echo ("Deleting $templatepath \n"); |
||||
removeDir($templatepath); |
||||
} |
||||
echo '</pre>'; |
||||
} |
||||
|
||||
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) { |
||||
$select .= '<option name="'.$setting->variable.'/'.$setting->subkey.'">'.$setting->variable.' / '.$setting->subkey.'</option>'; |
||||
} |
||||
$select .= '</select>'; |
||||
|
||||
Display::display_header(); |
||||
|
||||
echo '<h2>'.$plugininstance->get_lang('sendconfigvalue').'</h2>'; |
||||
echo '<form name="setconfigform">'; |
||||
$vidlist = implode("','", $_REQUEST['vids']); |
||||
echo '<input type="hidden" name="vidlist" value="'.$vidlist.'" />'; |
||||
echo '<input type="hidden" name="confirm" value="1" />'; |
||||
echo '<table>'; |
||||
echo '<tr><td>'.get_lang('variable').'</td><td>'.get_lang('subkey').'</td></tr>'; |
||||
echo '<tr><td><input type="text" name="variable" value="" size="30" /></td>'; |
||||
echo '<td><input type="text" name="subkey" value="" size="30" /></td></tr>'; |
||||
echo '<tr><td colspan="2">'.$select.'</td></tr>'; |
||||
echo '<tr><td colspan="2"><input type="submit" name="go_btn" value="'.$plugininstance->get_lang('distributevalue').'"</td></tr>'; |
||||
echo '</table>'; |
||||
echo '</form>'; |
||||
Display::display_footer(); |
||||
exit; |
||||
} |
@ -0,0 +1,104 @@ |
||||
<?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'); |
||||
|
||||
global $DB; |
||||
$DB = new DatabaseManager(); |
||||
|
||||
$action = $_GET['what']; |
||||
define('CHAMILO_INTERNAL', true); |
||||
|
||||
$plugininstance = VChamiloPlugin::create(); |
||||
$thisurl = api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php'; |
||||
|
||||
api_protect_admin_script(); |
||||
|
||||
require_js('host_list.js', 'vchamilo'); |
||||
|
||||
if ($action){ |
||||
require_once(api_get_path(SYS_PLUGIN_PATH).'vchamilo/views/manage.controller.php'); |
||||
} |
||||
|
||||
$content = Display::page_header('VChamilo Instances'); |
||||
|
||||
$table = 'vchamilo'; |
||||
|
||||
$query = " |
||||
SELECT |
||||
* |
||||
FROM |
||||
$table |
||||
"; |
||||
|
||||
$result = Database::query($query); |
||||
$instances = array(); |
||||
while ($instance = Database::fetch_object($result)) { |
||||
$instances[$instance->id] = $instance; |
||||
} |
||||
|
||||
$table = new HTML_Table(array('class' => 'data_table')); |
||||
$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'), ''); |
||||
$attrs = array('center' => 'left'); |
||||
$table->addRow($headers, $attrs, 'th'); |
||||
|
||||
$i = 0; |
||||
foreach ($instances as $instance) { |
||||
$checkbox = '<input type="checkbox" class="vnodessel" name="vids[]" value="'.$instance->id.'" />'; |
||||
|
||||
$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>'; |
||||
} else { |
||||
$status = '<a href="'.$thisurl.'?what=enableinstances&vids[]='.$instance->id.'" ><img src="'.$plugininstance->pix_url('disabled').'" /></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>'; |
||||
} 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=editinstance&vid='.$instance->id.'" title="'.$plugininstance->get_lang('edit').'"><img src="'.$plugininstance->pix_url('edit').'" /></a>'; |
||||
$cmd .= ' <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); |
||||
$attrs = array('center' => 'left'); |
||||
$table->addRow($data, $attrs, 'td'); |
||||
$i++; |
||||
} |
||||
|
||||
$content .= '<form action="'.$thisurl.'">'; |
||||
|
||||
$content .= $table->toHtml(); |
||||
|
||||
$selectionoptions = array('<option value="0" selected="selected">'.$plugininstance->get_lang('choose').'</option>'); |
||||
$selectionoptions[] = '<option value="deleteinstances">'.$plugininstance->get_lang('deleteinstances').'</option>'; |
||||
$selectionoptions[] = '<option value="enableinstances">'.$plugininstance->get_lang('enableinstances').'</option>'; |
||||
$selectionoptions[] = '<option value="fulldeleteinstances">'.$plugininstance->get_lang('destroyinstances').'</option>'; |
||||
$selectionoptions[] = '<option value="clearcache">'.$plugininstance->get_lang('clearcache').'</option>'; |
||||
$selectionoptions[] = '<option value="setconfigvalue">'.$plugininstance->get_lang('setconfigvalue').'</option>'; |
||||
$selectionaction = '<select name="what" onchange="this.form.submit()">'.implode('', $selectionoptions).'</select>'; |
||||
|
||||
$content .= '<div class"vchamilo-right"><div></div><div><a href="javascript:selectallhosts()">'.$plugininstance->get_lang('selectall').'</a> - <a href="javascript:deselectallhosts()">'.$plugininstance->get_lang('selectnone').'</a> - <a href="'.$thisurl.'?what=newinstance">'.$plugininstance->get_lang('newinstance').'</a> - <a href="'.$thisurl.'?what=instance®isteronly=1">'.$plugininstance->get_lang('registerinstance').'</a> - '.$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->assign('actions', $actions); |
||||
$tpl->assign('message', $message); |
||||
$tpl->assign('content', $content); |
||||
$tpl->display_one_col_template(); |
||||
|
@ -0,0 +1,30 @@ |
||||
<?php |
||||
/** |
||||
* Tests database connection. |
||||
* |
||||
* @package vchamilo |
||||
* @author Moheissen Fabien (fabien.moheissen@gmail.com) |
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL |
||||
*/ |
||||
|
||||
// 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'); |
||||
|
||||
$plugininstance = VChamiloPlugin::create(); |
||||
|
||||
// Retrieve parameters for database connection test. |
||||
$database = array(); |
||||
$database['db_host'] = $_REQUEST['vdbhost']; |
||||
$database['db_user'] = $_REQUEST['vdblogin']; |
||||
$database['db_password'] = $_REQUEST['vdbpass']; |
||||
|
||||
// Works, but need to improve the style... |
||||
if (vchamilo_boot_connection($database, false)) { |
||||
echo($plugininstance->get_lang('connectionok')); |
||||
} else { |
||||
echo($plugininstance->get_lang('badconnection')); |
||||
} |
@ -0,0 +1,65 @@ |
||||
<?php |
||||
/** |
||||
* Tests presence of course directories. |
||||
* |
||||
* @package vchamilo |
||||
* @category plugin |
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL |
||||
*/ |
||||
|
||||
// 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(); |
||||
|
||||
$plugininstance = VChamiloPlugin::create(); |
||||
|
||||
// Retrieve parameters for database connection test. |
||||
$dataroot = $_REQUEST['dataroot']; |
||||
|
||||
$absalternatecourse = vchamilo_get_config('vchamilo', 'course_real_root'); |
||||
if (!empty($absalternatecourse)){ |
||||
// this is the relocated case |
||||
$coursedir = str_replace('//', '/', $absalternatecourse.'/'.$dataroot); |
||||
} else { |
||||
// this is the standard local case |
||||
$coursedir = api_get_path(TO_SYS, SYS_PATH).$dataroot; |
||||
} |
||||
|
||||
if (is_dir($coursedir)) { |
||||
$DIR = opendir($coursedir); |
||||
$cpt = 0; |
||||
$hasfiles = false; |
||||
while (($file = readdir($DIR)) && !$hasfiles) { |
||||
if (!preg_match("/^\\./", $file)) { |
||||
$hasfiles = true; |
||||
} |
||||
} |
||||
closedir($DIR); |
||||
|
||||
if ($hasfiles) { |
||||
echo '<div class="error">'.$plugininstance->get_lang('datapathnotavailable').'</div>'; |
||||
} else { |
||||
echo '<div class="success">'.$plugininstance->get_lang('datapathavailable').'</div>'; |
||||
} |
||||
echo stripslashes($coursedir); |
||||
} else { |
||||
if (mkdir($coursedir, 02777, true)) { |
||||
echo '<div class="success">'.$plugininstance->get_lang('datapathcreated').'</div>'; |
||||
} else { |
||||
echo '<div class="error">'.$plugininstance->get_lang('couldnotcreatedataroot').'</div>'; |
||||
} |
||||
echo stripslashes($coursedir); |
||||
} |
||||
|
||||
echo "</p>"; |
||||
|
||||
$closestr = $plugininstance->get_lang('closewindow'); |
||||
echo "<center>"; |
||||
echo "<input type=\"button\" name=\"close\" value=\"$closestr\" onclick=\"self.close();\" />"; |
||||
echo "</center>"; |
@ -0,0 +1,62 @@ |
||||
<?php |
||||
|
||||
// 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); |
||||
|
||||
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); |
||||
} |
||||
} |
||||
} |
||||
|
||||
if ($action == 'syncthis') { |
||||
$settingid = $_GET['settingid']; |
||||
$vchamilos = $DB->get_records('vchamilo', array()); |
||||
|
||||
if (is_numeric($settingid)) { |
||||
$delifempty = @$_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); |
||||
$errors = ''; |
||||
foreach ($vchamilos as $vcid => $chm) { |
||||
if ($delifempty && empty($value)) { |
||||
$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"; |
||||
} else { |
||||
$remotesetting = $setting; |
||||
$remotesetting->selected_value = str_replace("'", "''", $value); |
||||
unset($remotesetting->id); |
||||
$res = $DB->insert_record('settings_current', $remotesetting, $chm->main_database); |
||||
$case = "insert"; |
||||
} |
||||
} |
||||
if (!$res) { |
||||
$errors .= "Set Field Error in $chm->sitename for case $case<br/>\n"; |
||||
} |
||||
} |
||||
return $errors; |
||||
} else { |
||||
return "Bad ID. Non numeric"; |
||||
} |
||||
} |
||||
|
||||
return 0; |
@ -0,0 +1,59 @@ |
||||
<?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'); |
||||
|
||||
global $DB; |
||||
$DB = new DatabaseManager(); |
||||
|
||||
$action = $_GET['what']; |
||||
define('CHAMILO_INTERNAL', true); |
||||
|
||||
$plugininstance = VChamiloPlugin::create(); |
||||
$thisurl = api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php'; |
||||
|
||||
api_protect_admin_script(); |
||||
|
||||
if ($action){ |
||||
require_once(api_get_path(SYS_PLUGIN_PATH).'vchamilo/views/syncparams.controller.php'); |
||||
} |
||||
|
||||
$allparams = $DB->get_records('settings_current', array(), 'variable,subkey'); |
||||
|
||||
$table = new HTML_Table(array('class' => 'data_table', 'width' => '100%')); |
||||
$column = 0; |
||||
$row = 0; |
||||
|
||||
// $table->set_additional_parameters($parameters); |
||||
$headers = array('', $plugininstance->get_lang('variable'), $plugininstance->get_lang('subkey'), $plugininstance->get_lang('category'), $plugininstance->get_lang('accessurl'), $plugininstance->get_lang('value'), ''); |
||||
$attrs = array('center' => 'left'); |
||||
$table->addRow($headers, $attrs, 'th'); |
||||
|
||||
foreach ($allparams 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); |
||||
$row = $table->addRow($data, $attrs, 'td'); |
||||
$table->setRowAttributes($row, array('id' => 'row_'.$param->id), true); |
||||
} |
||||
|
||||
$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();">'; |
||||
$content .= '</form>'; |
||||
|
||||
$actions = ''; |
||||
$message = ''; |
||||
|
||||
$message = require_js('ajax.js', 'vchamilo', true); |
||||
|
||||
$tpl = new Template($tool_name, true, true, false, true, false); |
||||
$tpl->assign('actions', $actions); |
||||
$tpl->assign('message', $message); |
||||
$tpl->assign('content', $content); |
||||
$tpl->display_one_col_template(); |