Sfoglia il codice sorgente

WIP: Fix VChamilo plugin

jmontoyaa 9 anni fa
parent
commit
acbba687ae

+ 1 - 1
main/inc/lib/add_course.lib.inc.php

@@ -86,7 +86,7 @@ class AddCourse
         $perm_file = api_get_permissions_for_new_files();
         $htmlpage = "<!DOCTYPE html>\n<html lang=\"en\">\n  <head>\n    <meta charset=\"utf-8\">\n    <title>Not authorized</title>\n  </head>\n  <body>\n  </body>\n</html>";
         $cp = api_get_path(SYS_COURSE_PATH) . $course_repository;
-
+        
         //Creating document folder
         mkdir($cp, $perm);
         mkdir($cp . '/document', $perm);

+ 0 - 1
main/inc/lib/api.lib.php

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

+ 1 - 1
plugin/vchamilo/install.php

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

+ 13 - 17
plugin/vchamilo/lib.php

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

+ 19 - 12
plugin/vchamilo/lib/vchamilo_plugin.class.php

@@ -14,30 +14,38 @@ require_once vchamilo_boot_api_get_path($_configuration) . 'plugin.class.php';
  */
 class VChamiloPlugin extends Plugin
 {
+    /**
+     * VChamiloPlugin constructor.
+     */
+    public function __construct()
+    {
+        parent::__construct('1.2', 'Valery Fremaux, Julio Montoya');
+    }
 
     /**
      *
-     * @return VChamiloPlugin 
+     * @return VChamiloPlugin
      */
-    static function create()
+    public static function create()
     {
         static $result = null;
         return $result ? $result : $result = new self();
     }
-    
-    function get_name()
+
+    public function get_name()
     {
         return 'vchamilo';
     }
 
-    protected function __construct()
+    /**
+     * @param $pixname
+     * @param int $size
+     * @return string
+     */
+    public function pix_url($pixname, $size = 16)
     {
-        parent::__construct('1.1', 'Valery Fremaux');
-    }
-
-    function pix_url($pixname, $size = 16){
         global $_configuration;
-        
+
         if (file_exists($_configuration['root_sys'].'/plugin/vchamilo/pix/'.$pixname.'.png')){
             return $_configuration['root_web'].'/plugin/vchamilo/pix/'.$pixname.'.png';
         }
@@ -47,8 +55,7 @@ class VChamiloPlugin extends Plugin
         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';
-        
     }
 }

+ 23 - 35
plugin/vchamilo/views/editinstance.controller.php

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

+ 4 - 1
plugin/vchamilo/views/editinstance.php

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

+ 11 - 15
plugin/vchamilo/views/editinstance_form.php

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

+ 15 - 21
plugin/vchamilo/views/manage.controller.php

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

+ 1 - 0
plugin/vchamilo/views/manage.php

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

+ 6 - 7
plugin/vchamilo/views/manage.testcnx.php

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

+ 5 - 10
plugin/vchamilo/views/manage.testdatapath.php

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