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 = "\n SELECT * FROM {$table} WHERE root_web = '{$_configuration['vchamilo_web_root']}'\n "; $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"); } }
<?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'); }