diff --git a/main/inc/lib/api.lib.php b/main/inc/lib/api.lib.php
index fae6f6f470..69e52a7428 100644
--- a/main/inc/lib/api.lib.php
+++ b/main/inc/lib/api.lib.php
@@ -615,6 +615,8 @@ function api_get_path($path = '', $configuration = [])
}
$course_folder = 'courses/';
+ $root_sys = $_configuration['root_sys'];
+
// Resolve master hostname.
if (!empty($configuration) && array_key_exists('root_web', $configuration)) {
$root_web = $configuration['root_web'];
@@ -694,11 +696,6 @@ function api_get_path($path = '', $configuration = [])
//static $isInitialized = [];
$isInitialized = [];
- // Configuration data for all installed systems is unique.
- if (empty($root_sys)) {
- $root_sys = $configuration['root_sys'];
- }
-
$loadNewConfig = false;
// To avoid that the api_get_access_url() function fails since global.inc.php also calls the main_api.lib.php
@@ -711,25 +708,15 @@ function api_get_path($path = '', $configuration = [])
}
}
- if (isset($configuration['course_folder'])) {
- $course_folder = $configuration['course_folder'];
- }
-
- $configuration['code_append'] = isset($configuration['code_append']) ? $configuration['code_append'] : 'main';
+ $course_folder = isset($configuration['course_folder']) ? $configuration['course_folder'] : $course_folder;
+ $root_rel = isset($configuration['url_append']) ? $configuration['url_append'] : '';
- if (preg_match('#https?://([^\.]+)#', $root_web, $matches)) {
- $web_host = $matches[1];
- } else {
- die('malformed root_web url');
- }
+ $configuration['code_append'] = 'main';
// Web server base and system server base.
- $root_rel = isset($configuration['url_append']) ? $configuration['url_append'] : '';
- $server_base_sys = preg_replace('@'.$root_rel.'$@', '', $root_sys); // No trailing slash.
if (!array_key_exists($root_web, $isInitialized)) {
// process absolute global roots
- //$root_rel = $configuration['url_append'];
if (!empty($configuration)) {
$code_folder = $configuration['code_append'];
} else {
@@ -846,13 +833,6 @@ function api_get_path($path = '', $configuration = [])
}
// Replacement of the present web server base with a slash '/'.
$path = preg_replace(VALID_WEB_SERVER_BASE, '/', $path);
- } elseif (strpos($path, $server_base_sys) === 0) {
- $path = preg_replace('@^'.$server_base_sys.'@', '', $path);
- } elseif (strpos($path, '/') === 0) {
- // Leading slash - we assume that this path is semi-absolute (REL),
- // then path is left without furthes modifications.
- } else {
- return null; // Probably implementation of this case won't be needed.
}
// Path now is semi-absolute. It is convenient at this moment repeated slashes to be removed.
diff --git a/main/inc/lib/database.lib.php b/main/inc/lib/database.lib.php
index b59e153edd..3528d25ec5 100755
--- a/main/inc/lib/database.lib.php
+++ b/main/inc/lib/database.lib.php
@@ -127,8 +127,10 @@ class Database
* @param string $entityRootPath
*
* @throws \Doctrine\ORM\ORMException
+ *
+ * @return
*/
- public function connect($params = array(), $sysPath = '', $entityRootPath = '')
+ public function connect($params = array(), $sysPath = '', $entityRootPath = '', $returnConnection = false)
{
$config = self::getDoctrineConfig($entityRootPath);
$config->setAutoGenerateProxyClasses(true);
@@ -175,6 +177,10 @@ class Database
$listener = new \Gedmo\Sortable\SortableListener();
$entityManager->getEventManager()->addEventSubscriber($listener);
$connection = $entityManager->getConnection();
+
+ if ($returnConnection) {
+ return $connection;
+ }
$this->setConnection($connection);
$this->setManager($entityManager);
diff --git a/plugin/vchamilo/ajax/service.php b/plugin/vchamilo/ajax/service.php
index bed1af78f9..12b34cc3f9 100644
--- a/plugin/vchamilo/ajax/service.php
+++ b/plugin/vchamilo/ajax/service.php
@@ -1,14 +1,9 @@
executeQuery($query);
$excludes = array('id', 'name');
- $res = mysql_query($query, $side_cnx);
- if ($res) {
- if (mysql_num_rows($res)) {
- $vchamilo = mysql_fetch_assoc($res);
- foreach($vchamilo as $key => $value){
- if (!in_array($key, $excludes)){
- $_configuration[$key] = $value;
- }
+ if ($result->rowCount()) {
+ $data = $result->fetchAll();
- // take first domain fragment as radical
- $arr = preg_replace('#https?://#', '', $_configuration['vchamilo_name']);
- $domain = explode('.', $arr);
- $vchamilo_radical = array_shift($domain);
- $VCHAMILO = $vchamilo_radical;
+ foreach($data as $key => $value){
+ if (!in_array($key, $excludes)){
+ $_configuration[$key] = $value;
}
- } else {
- die ("VChamilo : No configuration for this host. May be faked.");
+
+ // take first domain fragment as radical
+ $arr = preg_replace('#https?://#', '', $_configuration['vchamilo_name']);
+ $domain = explode('.', $arr);
+ $vchamilo_radical = array_shift($domain);
+ $VCHAMILO = $vchamilo_radical;
}
} else {
+ //die ("VChamilo : No configuration for this host. May be faked.");
die ("VChamilo : Could not fetch virtual chamilo configuration");
}
}
@@ -103,35 +101,28 @@ function vchamilo_get_hostname(&$_configuration)
* @param array $vchamilo
* @return a connection
*/
-function vchamilo_boot_connection(&$_configuration, $binddb = false)
+function vchamilo_boot_connection(&$_configuration)
{
- // Important : force new link here
- $mysql_side_cnx = mysql_connect(
- $_configuration['db_host'],
- $_configuration['db_user'],
- $_configuration['db_password'],
- true
+ $dbParams = array(
+ 'driver' => 'pdo_mysql',
+ 'host' => $_configuration['db_host'],
+ 'user' => $_configuration['db_user'],
+ 'password' => $_configuration['db_password'],
+ 'dbname' => $_configuration['main_database'],
+ // Only relevant for pdo_sqlite, specifies the path to the SQLite database.
+ 'path' => isset($_configuration['db_path']) ? $_configuration['db_path'] : '',
+ // Only relevant for pdo_mysql, pdo_pgsql, and pdo_oci/oci8,
+ 'port' => isset($_configuration['db_port']) ? $_configuration['db_port'] : ''
);
- if (!$mysql_side_cnx) {
- // echo('Side connection failure with '.$_configuration['db_host'].', '.$_configuration['db_user'].', '.$_configuration['db_password']);
+ try {
+ $database = new \Database();
+ $connection = $database->connect($dbParams, $_configuration['root_sys'], $_configuration['root_sys'], true);
+ } catch (Exception $e) {
echo('Side connection failure with '.$_configuration['db_host'].', '.$_configuration['db_user'].', ******** ');
- return false;
+ die();
}
- mysql_set_charset('utf8', $mysql_side_cnx);
- if (!empty($binddb)) {
- if (!in_array($binddb, array('main'), true)) {
- echo('Not a chamilo database. should be one of "main", "statistics" or "user_personal"');
- mysql_close($mysql_side_cnx);
- return false;
- }
- if (!mysql_select_db($_configuration[$binddb.'_database'], $mysql_side_cnx)) {
- echo("vchamilo_make_connection : Database not found
");
- mysql_close($mysql_side_cnx);
- return false;
- }
- }
- return $mysql_side_cnx;
+ return $connection;
}
function vchamilo_redirect($url) {
@@ -254,7 +245,7 @@ function vchamilo_create_databases($vchamilo, $cnx = null)
}
foreach($dbs as $adb){
- ctrace("Creating DB $adb ");
+ Display::addFlash(Display::return_message("Creating DB $adb"));
$sql = str_replace('%DATABASE%', $adb, $createstatement);
Database::query($sql);
/*if(!$DB->execute_sql($sql)){
@@ -278,18 +269,18 @@ function vchamilo_get_database_dump_cmd($vchamilodata)
$pgm = vchamilo_get_config('mysql_cmd');
// Checks the needed program.
- ctrace("load_database_from_dump : checking database command");
- if(!$pgm){
+ Display::addFlash(Display::return_message("load_database_from_dump : checking database command"));
+ if (!$pgm){
$pgm = '/usr/bin/mysql';
- ctrace("Using default database command $pgm ");
+ Display::addFlash(Display::return_message("Using default database command $pgm "));
}
$phppgm = str_replace("\\", '/', $pgm);
$phppgm = str_replace("\"", '', $phppgm);
$pgm = str_replace("/", DIRECTORY_SEPARATOR, $pgm);
- ctrace('load_database_from_dump : checking command is available');
- if(!is_executable($phppgm)){
+ Display::addFlash(Display::return_message('load_database_from_dump : checking command is available'));
+ if (!is_executable($phppgm)){
print_error('databasecommanddoesnotmatchanexecutablefile');
return false;
}
@@ -326,7 +317,7 @@ function vchamilo_load_db_template($vchamilo, $dbtemplate, $template){
$filerad = preg_replace('/_database$/', '', $dbtemplate);
$sqlfile = 'chamilo_master_'.$filerad.'.sql';
- if(!$sqlcmd = vchamilo_get_database_dump_cmd($vchamilo)){
+ if (!$sqlcmd = vchamilo_get_database_dump_cmd($vchamilo)){
return false;
}
@@ -336,7 +327,7 @@ function vchamilo_load_db_template($vchamilo, $dbtemplate, $template){
$import = $sqlcmd.$absolute_datadir.'/'.$sqlfile;
// Execute the command.
- ctrace("load_database_from_dump : executing feeding sql as \n $import ");
+ Display::addFlash(Display::return_message("load_database_from_dump : executing feeding sql as \n $import "));
if (!defined('CLI_SCRIPT')){
putenv('LANG=en_US.utf-8');
@@ -346,7 +337,8 @@ function vchamilo_load_db_template($vchamilo, $dbtemplate, $template){
exec($import, $output, $return);
- ctrace(implode("\n", $output)."\n");
+ Display::addFlash(Display::return_message(implode("\n", $output)."\n"));
+
return true;
}
@@ -439,7 +431,8 @@ function vchamilo_execute_db_sql(&$vchamilo, $bulkfile, $cnx = null, $vars=null,
* @param $outputfilerad string The output SQL file radical.
* @return bool If TRUE, dumping database was a success, otherwise FALSE.
*/
-function vchamilo_dump_databases($vchamilo, $outputfilerad){
+function vchamilo_dump_databases($vchamilo, $outputfilerad)
+{
global $CFG;
// Separating host and port, if sticked.
@@ -453,7 +446,7 @@ function vchamilo_dump_databases($vchamilo, $outputfilerad){
$pass = '';
$pgm = null;
- if (empty($port)){
+ if (empty($port)) {
$port = 3306;
}
@@ -464,7 +457,8 @@ function vchamilo_dump_databases($vchamilo, $outputfilerad){
// Making the commands for each database.
$cmds = array();
- if ($CFG->ostype == 'WINDOWS'){
+ //if ($CFG->ostype == 'WINDOWS') {
+ if (false) {
$cmd_main = "-h{$host} -P{$port} -u{$vchamilo->db_user} {$pass} {$vchamilo->main_database}";
$cmds[] = $cmd_main . ' > ' . $outputfilerad.'_main.sql';
@@ -481,25 +475,17 @@ function vchamilo_dump_databases($vchamilo, $outputfilerad){
} else {
$cmd_main = "-h{$host} -P{$port} -u{$vchamilo->db_user} {$pass} {$vchamilo->main_database}";
$cmds[] = $cmd_main . ' > ' . escapeshellarg($outputfilerad.'_main.sql');
-
- if ($vchamilo->statistics_database != $vchamilo->main_database){
- $cmd_stats = "-h{$host} -P{$port} -u{$vchamilo->db_user} {$pass} {$vchamilo->statistics_database}";
- $cmds[] = $cmd_stats . ' > ' . escapeshellarg($outputfilerad.'_statistics.sql');
- }
-
- if (($vchamilo->user_personal_database != $vchamilo->main_database) && ($vchamilo->user_personal_database != $vchamilo->statistics_database)) {
- $cmd_user = "-h{$host} -P{$port} -u{$vchamilo->db_user} {$pass} {$vchamilo->user_personal_database}";
- $cmds[] = $cmd_user . ' > ' . escapeshellarg($outputfilerad.'_user_personal.sql');
- }
}
$mysqldumpcmd = vchamilo_get_config('vchamilo', 'cmd_mysqldump', true);
- $pgm = (!empty($mysqldumpcmd)) ? stripslashes($mysqldumpcmd) : false ;
+ $pgm = !empty($mysqldumpcmd) ? stripslashes($mysqldumpcmd) : false ;
- if(!$pgm){
+ if (!$pgm) {
$erroritem = new StdClass();
- $erroritem->message = "Database dump command not available";
+ $erroritem->message = "Database dump command not available check here: ";
+ $url = api_get_path(WEB_CODE_PATH).'admin/configure_plugin.php?name=vchamilo';
+ $erroritem->message .= Display::url($url, $url);
return array($erroritem);
} else {
$phppgm = str_replace("\\", '/', $pgm);
@@ -517,8 +503,6 @@ function vchamilo_dump_databases($vchamilo, $outputfilerad){
// Final command.
$cmd = $pgm.' '.$cmd;
- // ctrace($cmd); // Be carefull there, this could divulgate DB password
-
// Prints log messages in the page and in 'cmd.log'.
if ($LOG = fopen(dirname($outputfilerad).'/cmd.log', 'a')){
fwrite($LOG, $cmd."\n");
@@ -558,16 +542,14 @@ function vchamilo_make_this()
{
global $_configuration;
- $thischamilo->root_web = $_configuration['root_web'];
+ $thisPortal = new stdClass();
+ $thisPortal->root_web = $_configuration['root_web'];
+ $thisPortal->db_host = $_configuration['db_host'];
+ $thisPortal->db_user = $_configuration['db_user'];
+ $thisPortal->db_password = $_configuration['db_password'];
+ $thisPortal->main_database = $_configuration['main_database'];
- $thischamilo->db_host = $_configuration['db_host'];
- $thischamilo->db_user = $_configuration['db_user'];
- $thischamilo->db_password = $_configuration['db_password'];
- $thischamilo->db_prefix = $_configuration['db_prefix'];
- $thischamilo->main_database = $_configuration['main_database']; ;
- $thischamilo->table_prefix = $_configuration['table_prefix'];
-
- return $thischamilo;
+ return $thisPortal;
}
/**
@@ -585,7 +567,7 @@ function vchamilo_get_available_templates()
$absolute_templatesdir = $_configuration['root_sys'].$templatefoldername;
// Scans the templates.
- if(!is_dir($absolute_templatesdir)){
+ if (!is_dir($absolute_templatesdir)){
mkdir($absolute_templatesdir, 0777, true);
}
$dirs = glob($absolute_templatesdir.'/*');
@@ -604,8 +586,8 @@ function vchamilo_get_available_templates()
return $templatesarray;
}
-function vchamilo_print_error($errortrace, $return = false){
-
+function vchamilo_print_error($errortrace, $return = false)
+{
$str = '';
if (!empty($errortrace)){
$str .= '
";
- echo $str;
+ Display::addFlash(Display::return_message($str));
if (!defined('CLI_SCRIPT')) echo "";
}
diff --git a/plugin/vchamilo/lib/bootlib.php b/plugin/vchamilo/lib/bootlib.php
index 530eea42a0..0c369c62a4 100644
--- a/plugin/vchamilo/lib/bootlib.php
+++ b/plugin/vchamilo/lib/bootlib.php
@@ -1,5 +1,5 @@
what == 'addinstance' || $data->what == 'registerinstance') {
if (!is_dir($homedir)){
ctrace("Creating home dir ");
- if (!mkdir($homedir, 0777, true)){
+ if (!mkdir($homedir, 0777, true)) {
ctrace("Error creating home dir $homedir \n");
}
}
@@ -147,7 +147,7 @@ if ($data->what == 'addinstance' || $data->what == 'registerinstance') {
if (!is_dir($archivedir)) {
ctrace("Creating archive dir ");
- if(!mkdir($archivedir, 0777, true)) {
+ if (!mkdir($archivedir, 0777, true)) {
ctrace("Error creating archive dir $archivedir\n");
}
}
@@ -183,9 +183,6 @@ if ($data->what == 'addinstance' || $data->what == 'registerinstance') {
ctrace("Fixing records");
- // Builds a new database manager on new instance to operate records
-// $NDB = new DatabaseManager($data);
-
// pluging in site name institution
$settingstable = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
$sitename = str_replace("'", "''", $data->sitename);
@@ -201,11 +198,11 @@ if ($data->what == 'addinstance' || $data->what == 'registerinstance') {
ctrace("Finished. ");
- if (!$automation) {
+ //if (!$automation) {
echo 'Continue';
// vchamilo_redirect(api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php');
die;
- }
+ //}
}
if ($data->what == 'updateinstance') {
@@ -217,12 +214,12 @@ if ($data->what == 'updateinstance') {
$data->lastcron = 0;
$data->lastcrongap = 0;
$data->croncount = 0;
- $data->id = $data->vid;
+ $id = $data->vid;
+ unset($data->vid);
+ unset($data->testconnection);
+ unset($data->testdatapath);
unset($data->vid);
- if (!$DB->update_record('vchamilo', $data, 'id')) {
- error_log('Vchamilo update error');
- }
-
+ Database::update('vchamilo', (array) $data, array('id = ?' => $id), true);
vchamilo_redirect(api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php');
}
diff --git a/plugin/vchamilo/views/editinstance.php b/plugin/vchamilo/views/editinstance.php
index ed8b95c1a2..6935414362 100644
--- a/plugin/vchamilo/views/editinstance.php
+++ b/plugin/vchamilo/views/editinstance.php
@@ -12,8 +12,8 @@ require_once api_get_path(SYS_PLUGIN_PATH).'vchamilo/views/editinstance_form.php
$htmlHeadXtra[] = '';
// get parameters
-$id = (int)($_REQUEST['vid']);
-$action = $_REQUEST['what'];
+$id = isset($_REQUEST['vid']) ? $_REQUEST['vid'] : '';
+$action = isset($_REQUEST['what']) ? $_REQUEST['what'] : '';
$registeronly = @$_REQUEST['registeronly'];
$plugininstance = VChamiloPlugin::create();
$thisurl = api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php';
@@ -24,7 +24,7 @@ api_protect_admin_script();
if ($id) {
$mode = 'update';
} else {
- $mode = ($registeronly) ? 'register' : 'add' ;
+ $mode = $registeronly ? 'register' : 'add' ;
}
$form = new InstanceForm($plugininstance, $mode);
@@ -33,11 +33,10 @@ $form->definition();
$actions = '';
$message = '';
if ($data = $form->get_data()) {
- include(api_get_path(SYS_PLUGIN_PATH).'vchamilo/views/editinstance.controller.php');
+ include api_get_path(SYS_PLUGIN_PATH).'vchamilo/views/editinstance.controller.php';
}
-if ($id){
-// $vhost = $DB->get_record('vchamilo', array('id' => $id));
+if ($id) {
$sql = "SELECT * FROM vchamilo WHERE id = $id";
$result = Database::query($sql);
$vhost = Database::fetch_array($result);
@@ -54,7 +53,7 @@ if ($id){
$content = $form->return_form();
-$tpl = new Template($tool_name, true, true, false, true, false);
+$tpl = new Template(get_lang('VChamilo'), true, true, false, true, false);
$tpl->assign('actions', $actions);
$tpl->assign('message', $message);
$tpl->assign('content', $content);
diff --git a/plugin/vchamilo/views/editinstance_form.php b/plugin/vchamilo/views/editinstance_form.php
index 54966995ab..eb3adfcc7e 100644
--- a/plugin/vchamilo/views/editinstance_form.php
+++ b/plugin/vchamilo/views/editinstance_form.php
@@ -1,14 +1,26 @@
_mode = $mode;
$this->_cancelurl = $cancelurl;
$this->_customdata = $customdata;
@@ -18,25 +30,30 @@ abstract class ChamiloForm
$this->_form = new FormValidator($mode.'_instance', 'post', $returnurl, '', $attributes);
}
- abstract function definition();
- abstract function validation($data, $files = null);
+ public abstract function definition();
+ public abstract function validation($data, $files = null);
- function validate() {
+ public function validate(
+
+ ) {
return $this->_form->validate();
}
- function display() {
+ public function display()
+ {
return $this->_form->display();
}
- function definition_after_data(){
+ public function definition_after_data(){
}
- function return_form(){
+ public function return_form()
+ {
return $this->_form->toHtml();
}
- function is_in_add_mode(){
+ public function is_in_add_mode()
+ {
return $this->_mode == 'add';
}
@@ -52,20 +69,19 @@ abstract class ChamiloForm
public function add_action_buttons($cancel = true, $submitlabel = null, $cancellabel = null)
{
// TODO : refine lang fetch to effective global strings.
- if (is_null($submitlabel)){
+ if (is_null($submitlabel)) {
$submitlabel = get_lang('save');
}
- if (is_null($cancellabel)){
+ if (is_null($cancellabel)) {
$submitlabel = get_lang('cancel');
}
$cform =& $this->_form;
- if ($cancel){
+ if ($cancel) {
//when two elements we need a group
$buttonarray = array();
$buttonarray[] = &$cform->createElement('submit', 'submitbutton', $submitlabel);
- //$buttonarray[] = &$cform->createElement('cancel', $cancellabel, $this->_cancelurl);
$cform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
} else {
//no group needed
@@ -87,14 +103,13 @@ abstract class ChamiloForm
if ($this->is_submitted() and $this->is_validated()) {
$data = $cform->exportValues(null, $slashed);
unset($data['sesskey']); // we do not need to return sesskey
- unset($data['_qf__'.$this->_formname]); // we do not need the submission marker too
if (empty($data)) {
- return NULL;
+ return null;
} else {
return (object)$data;
}
} else {
- return NULL;
+ return null;
}
}
@@ -111,14 +126,13 @@ abstract class ChamiloForm
if ($this->is_submitted()) {
$data = $cform->exportValues(null, $slashed);
unset($data['sesskey']); // we do not need to return sesskey
- unset($data['_qf__'.$this->_formname]); // we do not need the submission marker too
if (empty($data)) {
- return NULL;
+ return null;
} else {
return (object)$data;
}
} else {
- return NULL;
+ return null;
}
}
@@ -147,6 +161,7 @@ abstract class ChamiloForm
}
}
}
+
return false;
}
@@ -163,6 +178,7 @@ abstract class ChamiloForm
$this->_definition_finalized = true;
$this->definition_after_data();
}
+
return $this->validate_defined_fields();
}
@@ -221,6 +237,7 @@ abstract class ChamiloForm
$validated = ($internal_val and $chamilo_val and $file_val);
}
+
return $validated;
}
@@ -228,15 +245,16 @@ abstract class ChamiloForm
{
static $nosubmit = null; // one check is enough
- if (!is_null($nosubmit)){
+ if (!is_null($nosubmit)) {
return $nosubmit;
}
$cform =& $this->_form;
$nosubmit = false;
- if (!$this->is_submitted()){
+ if (!$this->is_submitted()) {
return false;
}
+
/*
foreach ($cform->_noSubmitButtons as $nosubmitbutton){
if (optional_param($nosubmitbutton, 0, PARAM_RAW)){
@@ -278,6 +296,7 @@ abstract class ChamiloForm
// note: server side rules do not work for files - use custom verification in validate() instead
return true;
}
+
$errors = array();
$mform =& $this->_form;
@@ -288,7 +307,9 @@ abstract class ChamiloForm
foreach ($_FILES as $elname=>$file) {
if ($mform->elementExists($elname) and $mform->getElementType($elname)=='file') {
$required = $mform->isElementRequired($elname);
- if (!empty($this->_upload_manager->files[$elname]['uploadlog']) and empty($this->_upload_manager->files[$elname]['clear'])) {
+ if (!empty($this->_upload_manager->files[$elname]['uploadlog']) &&
+ empty($this->_upload_manager->files[$elname]['clear'])
+ ) {
if (!$required and $file['error'] == UPLOAD_ERR_NO_FILE) {
// file not uploaded and not required - ignore it
continue;
@@ -304,40 +325,57 @@ abstract class ChamiloForm
}
// return errors if found
- if ($status and 0 == count($errors)){
+ if ($status && 0 == count($errors)) {
+
return true;
} else {
$files = array();
+
return $errors;
}
}
}
+/**
+ * Class InstanceForm
+ */
class InstanceForm extends ChamiloForm
{
public $_plugin;
+ /**
+ * InstanceForm constructor.
+ * @param $plugin
+ * @param string $mode
+ * @param null $returnurl
+ * @param null $cancelurl
+ */
public function __construct($plugin, $mode = 'add', $returnurl = null, $cancelurl = null)
{
global $_configuration;
$this->_plugin = $plugin;
-
$returnurl = $_configuration['root_web'].'plugin/vchamilo/views/editinstance.php';
+ if ($mode == 'update') {
+ $returnurl = $_configuration['root_web'].'plugin/vchamilo/views/editinstance.php?vid='.intval($_GET['vid']);
+ }
+
$cancelurl = $_configuration['root_web'].'plugin/vchamilo/views/manage.php';
parent::__construct($mode, $returnurl, $cancelurl);
}
- function definition()
+ /**
+ *
+ */
+ public function definition()
{
global $_configuration;
$cform = $this->_form;
// Settings variables.
- $size_input_text = 'size="30"';
- $size_input_text_big = 'size="60"';
+ $size_input_text_big = 'size="60"';
/*
* Host's id.
@@ -351,15 +389,25 @@ class InstanceForm extends ChamiloForm
*/
$cform->addElement('header', $this->_plugin->get_lang('hostdefinition'));
// Name.
- $cform->addElement('text', 'sitename', $this->_plugin->get_lang('sitename'), $size_input_text);
+ $cform->addElement('text', 'sitename', $this->_plugin->get_lang('sitename'));
$cform->applyFilter('sitename', 'trim');
// Shortname.
- $cform->addElement('text', 'institution', $this->_plugin->get_lang('institution'), ($this->mode == 'edit' ? 'disabled="disabled" ' : ''));
+ $cform->addElement(
+ 'text',
+ 'institution',
+ $this->_plugin->get_lang('institution'),
+ ($this->_mode == 'edit' ? 'disabled="disabled" ' : '')
+ );
$cform->applyFilter('institution', 'trim');
// Host's name.
- $cform->addElement('text', 'root_web', $this->_plugin->get_lang('rootweb'), ($this->mode == 'edit' ? 'disabled="disabled" ' : '').$size_input_text);
+ $cform->addElement(
+ 'text',
+ 'root_web',
+ $this->_plugin->get_lang('rootweb'),
+ ($this->_mode == 'edit' ? 'disabled="disabled" ' : '')
+ );
$cform->applyFilter('root_web', 'trim');
/*
@@ -376,31 +424,47 @@ class InstanceForm extends ChamiloForm
$cform->applyFilter('db_user', 'trim');
// Database password.
- $cform->addElement('password', 'db_password', $this->_plugin->get_lang('dbpassword'), array('id' => 'id_vdbpassword'));
-
- // Button for testing database connection.
- $cform->addElement('button', 'testconnection', $this->_plugin->get_lang('testconnection'), 'onclick="opencnxpopup(\''.$_configuration['root_web'].'\'); return false;"');
+ $cform->addElement(
+ 'password',
+ 'db_password',
+ $this->_plugin->get_lang('dbpassword'),
+ array('id' => 'id_vdbpassword')
+ );
// Database name.
$cform->addElement('text', 'main_database', $this->_plugin->get_lang('maindatabase'));
-
// Table's prefix.
- $cform->addElement('text', 'table_prefix', $this->_plugin->get_lang('tableprefix'));
+ //$cform->addElement('text', 'table_prefix', $this->_plugin->get_lang('tableprefix'));
// Db's prefix.
$cform->addElement('text', 'db_prefix', $this->_plugin->get_lang('dbprefix'));
- /*
- * data fieldset.
- */
$cform->addElement('header', $this->_plugin->get_lang('datalocation'));
// Path for "moodledata".
- $cform->addElement('text', 'course_folder', $this->_plugin->get_lang('coursefolder'), array('size' => $size_input_text_big, 'id' => 'id_vdatapath'));
+ $cform->addElement(
+ 'text',
+ 'course_folder',
+ $this->_plugin->get_lang('coursefolder'),
+ array('size' => $size_input_text_big, 'id' => 'id_vdatapath')
+ );
+
+ // Button for testing database connection.
+ $cform->addElement(
+ 'button',
+ 'testconnection',
+ $this->_plugin->get_lang('testconnection'),
+ 'onclick="opencnxpopup(\''.$_configuration['root_web'].'\'); return false;"'
+ );
// Button for testing datapath.
- $cform->addElement('button', 'testdatapath', $this->_plugin->get_lang('testdatapath'), 'onclick="opendatapathpopup(\''.$_configuration['root_web'].'\'); return true;"');
+ $cform->addElement(
+ 'button',
+ 'testdatapath',
+ $this->_plugin->get_lang('testdatapath'),
+ 'onclick="opendatapathpopup(\''.$_configuration['root_web'].'\'); return true;"'
+ );
/*
* Template selection.
@@ -419,16 +483,39 @@ class InstanceForm extends ChamiloForm
$this->add_action_buttons(true, $submitstr, $cancelstr);
// Rules for the add mode.
- if($this->is_in_add_mode()) {
+ if ($this->is_in_add_mode()) {
$cform->addRule('sitename', $this->_plugin->get_lang('sitenameinputerror'), 'required', null, 'client');
- $cform->addRule('institution', $this->_plugin->get_lang('institutioninputerror'), 'required', null, 'client');
+ $cform->addRule(
+ 'institution',
+ $this->_plugin->get_lang('institutioninputerror'),
+ 'required',
+ null,
+ 'client'
+ );
$cform->addRule('root_web', $this->_plugin->get_lang('rootwebinputerror'), 'required', null, 'client');
- $cform->addRule('main_database', $this->_plugin->get_lang('databaseinputerror'), 'required', null, 'client');
- $cform->addRule('course_folder', $this->_plugin->get_lang('coursefolderinputerror'), 'required', null, 'client');
+ $cform->addRule(
+ 'main_database',
+ $this->_plugin->get_lang('databaseinputerror'),
+ 'required',
+ null,
+ 'client'
+ );
+ $cform->addRule(
+ 'course_folder',
+ $this->_plugin->get_lang('coursefolderinputerror'),
+ 'required',
+ null,
+ 'client'
+ );
}
}
- function validation($data, $files = null)
+ /**
+ * @param array $data
+ * @param null $files
+ * @return array
+ */
+ public function validation($data, $files = null)
{
global $plugininstance;
@@ -438,11 +525,18 @@ class InstanceForm extends ChamiloForm
}
$tablename = Database::get_main_table('vchamilo');
- if($vchamilo = Database::select('*', $tablename, array('where' => array(' root_web = ? ' => array($data->root_web))))){
+ $vchamilo = Database::select(
+ '*',
+ $tablename,
+ array('where' => array(' root_web = ? ' => array($data['root_web']))),
+ 'first'
+ );
+
+ if ($vchamilo && isset($data['vid']) && $data['vid'] != $vchamilo['id']) {
$errors['root_web'] = $plugininstance->get_lang('errorrootwebexists');
}
- if(!empty($errors)){
+ if (!empty($errors)) {
return $errors;
}
}
diff --git a/plugin/vchamilo/views/manage.controller.php b/plugin/vchamilo/views/manage.controller.php
index 3738139758..f864a01d16 100644
--- a/plugin/vchamilo/views/manage.controller.php
+++ b/plugin/vchamilo/views/manage.controller.php
@@ -1,6 +1,6 @@
array('id = ?' => $vid)));
$vhost = (object)array_pop($vhosts);
@@ -140,22 +141,21 @@ if ($action == 'snapshotinstance') {
}
// Parsing url for building the template name.
- $wwwroot = $vhost->root_web;
- $vchamilostep = $_REQUEST['step'];
+ $wwwroot = $vhost->root_web;
+ $vchamilostep = isset($_REQUEST['step']) ? $_REQUEST['step'] : '';
preg_match('#https?://([^/]+)#', $wwwroot, $matches);
$hostname = $matches[1];
// Make template directory (files and SQL).
- $separator = DIRECTORY_SEPARATOR;
- $templatefoldername = 'plugin'.$separator.'vchamilo'.$separator.'templates';
- $relative_datadir = $templatefoldername.$separator.$hostname.'_vchamilodata';
- $absolute_datadir = $_configuration['root_sys'].$relative_datadir;
- $relative_sqldir = $templatefoldername.$separator.$hostname.'_sql';
- $absolute_sqldir = $_configuration['root_sys'].$separator.$relative_sqldir;
-// $absolute_templatesdir = api_get_path(SYS_PATH, CHAMILO_ARCHIVE_PATH).$separator.$templatefoldername; // can be problematic as self containing
+ $separator = DIRECTORY_SEPARATOR;
+ $templatefoldername = 'plugin'.$separator.'vchamilo'.$separator.'templates';
+ $relative_datadir = $templatefoldername.$separator.$hostname.'_vchamilodata';
+ $absolute_datadir = $_configuration['root_sys'].$relative_datadir;
+ $relative_sqldir = $templatefoldername.$separator.$hostname.'_sql';
+ $absolute_sqldir = $_configuration['root_sys'].$separator.$relative_sqldir;
$absolute_templatesdir = $_configuration['root_sys'].$templatefoldername;
- if (preg_match('/ /', $absolute_sqldir)){
+ if (preg_match('/ /', $absolute_sqldir)) {
$erroritem = new StdClass();
$erroritem->message = $plugininstance->get_lang('errorspacesinpath');
vchamilo_print_error(array($erroritem));
@@ -177,15 +177,15 @@ if ($action == 'snapshotinstance') {
}
if (empty($fullautomation)) {
$actionurl = $_configuration['root_web'].'/plugin/vchamilo/views/manage.php';
- $content .= '';
$content .= '"; - echo "copyDirTo($vcoursepath, $absolute_datadir, false); - copyDirTo($varchivepath, $absolute_datadir.'/archive, false); - copyDirTo($vhomepath, $absolute_datadir.'/home', false);"; - echo ""; - */ - - echo "
";
- echo ("Copying from $vcoursepath to $absolute_datadir \n");
+ Display::addFlash(Display::return_message("Copying from $vcoursepath to $absolute_datadir "));
copyDirTo($vcoursepath, $absolute_datadir, false);
- echo ("Copying from $varchivepath to {$absolute_datadir}/archive \n");
+ Display::addFlash(Display::return_message("Copying from $varchivepath to {$absolute_datadir}/archive "));
copyDirTo($varchivepath, $absolute_datadir.'/archive', false);
- echo ("Copying from $vhomepath to {$absolute_datadir}/home \n");
+ Display::addFlash(Display::return_message("Copying from $vhomepath to {$absolute_datadir}/home "));
copyDirTo($vhomepath, $absolute_datadir.'/home', false);
- echo "";
+
// Store original hostname and some config info for further database or filestore replacements.
$FILE = fopen($absolute_sqldir.$separator.'manifest.php', 'w');
@@ -281,18 +270,14 @@ if ($action == 'snapshotinstance') {
// Every step was SUCCESS.
if (empty($fullautomation)){
- $message_object->message = $plugininstance->get_lang('successfinishedcapture');
- $message_object->style = 'notifysuccess';
+ Display::addFlash($plugininstance->get_lang('successfinishedcapture'));
- // Save confirm message before redirection.
- $_SESSION['confirm_message'] = $message_object;
$actionurl = $_configuration['root_web'].'/plugin/vchamilo/views/manage.php';
- $content .= '