request different re-work of external DB enrollment

request different re-work of external DB enrollment

by ryan sanders -
Number of replies: 0
while the external database enrollment is good for going at a single database, and table. that is about it.

while, UI is all nice, it also forces info to be put into the ugly database for someone to look at usernames/hosts/etc... that part i don't much care for at all.

it would be nice to have just a generic configuration.php much like what moodle uses in moodle/config.php at least this way, i can setup .htaccess on the file. to protect database connection info from prying eyes.

i am also going to suggest that multi databases can be setup via array within the file.
$databaseid = 0;
$database[$databaseid]['overviewname'] = "enrolserver1";
$database[$databaseid]['dbtype'] = 'mysql'; // mysql or postgres7 (for now)
$database[$databaseid]['dbhost'] = 'localhost'; // eg localhost or db.isp.com
$database[$databaseid]['dbname'] = 'moodle'; // database name, eg moodle
$database[$databaseid]['dbuser'] = 'username'; // your database username
$database[$databaseid]['dbpass'] = 'password'; // your database password
$database[$databaseid]['prefix'] = 'mdl_';
$database[$databaseid]['enabled'] = '0'; //1 = use this connection 0= do not use this connection

$databaseid++;
$database[$databaseid]['overviewname'] = "enrolserver2";
$database[$databaseid]['dbtype'] = 'mysql'; // mysql or postgres7 (for now)
$database[$databaseid]['dbhost'] = 'localhost'; // eg localhost or db.isp.com
$database[$databaseid]['dbname'] = 'moodleasfa'; // database name, eg moodle
$database[$databaseid]['dbuser'] = 'username'; // your database username
$database[$databaseid]['dbpass'] = 'password'; // your database password
$database[$databaseid]['prefix'] = 'm5s_';
$database[$databaseid]['enabled'] = '0'; //1 = use this connection 0= do not use this connection

===================================================
another issue, is things are hard coded for sql strings themselves. within enrol.php. for example:
$sql = "SELECT DISTINCT {$CFG->enrol_remotecoursefield} " .
" FROM {$CFG->enrol_dbtable} " .
" WHERE {$CFG->enrol_remoteuserfield} IS NOT NULL" .
(isset($remote_role_name, $remote_role_value) ? ' AND '.$remote_role_name.' = '.$remote_role_value : '');

my suggestion is to wrap these statements into a string that equal some var.

//some description of sql string.
$database[$databaseid]['sql2'] = ' $sql = "SELECT DISTINCT {$CFG->enrol_remotecoursefield} " . " FROM {$CFG->enrol_dbtable} " . " WHERE {$CFG->enrol_remoteuserfield} IS NOT NULL" . (isset($remote_role_name, $remote_role_value) ? " AND " .$remote_role_name." = ".$remote_role_value : "");';

//some description of sql string.
$database[$databaseid]['sql3'] = ' $sql = "SELECT {$CFG->enrol_remotecoursefield} " . " FROM {$CFG->enrol_dbtable} " . " WHERE {$CFG->enrol_remoteuserfield} IS NOT NULL";';

=========================
with above, i will be able to enter my own sql statements, so that i can build info from various tables in the external database. for example.... ""oscommerce with extra product fields mod""
$database[$databaseid]['sql3'] = ' SELECT
{$CFG->enrol_remotecoursefield} //products_description.extra_value6 ((is the field that holds course info))
FROM
orders
JOIN orders_products
JOIN products_description
JOIN products
WHERE orders.orders_id = orders_products.orders_id
AND orders_products.products_id = products_description.products_id
AND products_description.language_id = 1
AND orders.orders_status >= 3
AND orders_products.products_id = products.products_id
AND {$CFG->enrol_remoteuserfield} IS NOT NULL"; //orders.customer_id ((is the field that holds user id))

=====================================================
now with both database connections and sql statements are in a generic configuration.php. another file can be created. that has general functions. IE: enrol.php that require_once the configuration.php.

=====================================================
i am sure someone else has a much better way of going about things. but, if one looks at for example. mysqldumper, phpmyadmin, etc.... that holds multi configurations for different databases. *shrugs*



Average of ratings: -