MDL-9224 - Score sometimes relealed, even when the quiz settings say it should not...
[moodle.git] / auth / db / auth.php
CommitLineData
b9ddb2d5 1<?php
2
3/**
4 * @author Martin Dougiamas
5 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
6 * @package moodle multiauth
7 *
8 * Authentication Plugin: External Database Authentication
9 *
10 * Checks against an external database.
11 *
12 * 2006-08-28 File created.
13 */
14
8ae42b8d 15if (!defined('MOODLE_INTERNAL')) {
16 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
17}
b9ddb2d5 18
6bc1e5d5 19require_once($CFG->libdir.'/authlib.php');
20
b9ddb2d5 21/**
22 * External database authentication plugin.
23 */
6bc1e5d5 24class auth_plugin_db extends auth_plugin_base {
b9ddb2d5 25
26 /**
27 * Constructor.
28 */
29 function auth_plugin_db() {
6bc1e5d5 30 $this->authtype = 'db';
b9ddb2d5 31 $this->config = get_config('auth/db');
8ae42b8d 32 if (empty($this->config->extencoding)) {
33 $this->config->extencoding = 'utf-8';
34 }
b9ddb2d5 35 }
36
37 /**
38 * Returns true if the username and password work and false if they are
39 * wrong or don't exist.
40 *
8ae42b8d 41 * @param string $username The username (with system magic quotes)
42 * @param string $password The password (with system magic quotes)
43 *
44 * @return bool Authentication success or failure.
b9ddb2d5 45 */
139ebfdb 46 function user_login($username, $password) {
b9ddb2d5 47
48 global $CFG;
49
8ae42b8d 50 $textlib = textlib_get_instance();
51 $extusername = $textlib->convert(stripslashes($username), 'utf-8', $this->config->extencoding);
52 $extpassword = $textlib->convert(stripslashes($password), 'utf-8', $this->config->extencoding);
53
139ebfdb 54 $authdb = $this->db_init();
b9ddb2d5 55
8ae42b8d 56 if ($this->config->passtype === 'internal') {
b9ddb2d5 57 // lookup username externally, but resolve
58 // password locally -- to support backend that
59 // don't track passwords
8ae42b8d 60 $rs = $authdb->Execute("SELECT * FROM {$this->config->table}
61 WHERE {$this->config->fielduser} = '".$this->ext_addslashes($extusername)."' ");
b9ddb2d5 62 $authdb->Close();
63
64 if (!$rs) {
a9ad3633 65 print_error('auth_dbcantconnect','auth');
b9ddb2d5 66 return false;
67 }
8ae42b8d 68
b9ddb2d5 69 if ( $rs->RecordCount() ) {
70 // user exists exterally
71 // check username/password internally
b7b50143 72 if ($user = get_record('user', 'username', $username, 'mnethostid', $CFG->mnet_localhost_id)) {
b9ddb2d5 73 return validate_internal_user_password($user, $password);
74 }
75 } else {
76 // user does not exist externally
77 return false;
8ae42b8d 78 }
b9ddb2d5 79
8ae42b8d 80 } else {
b9ddb2d5 81 // normal case: use external db for passwords
82
83 if ($this->config->passtype === 'md5') { // Re-format password accordingly
8ae42b8d 84 $extpassword = md5($extpassword);
85 } else if ($this->config->passtype === 'sha1') {
86 $extpassword = sha1($extpassword);
b9ddb2d5 87 }
88
8ae42b8d 89 $rs = $authdb->Execute("SELECT * FROM {$this->config->table}
90 WHERE {$this->config->fielduser} = '".$this->ext_addslashes($extusername)."'
91 AND {$this->config->fieldpass} = '".$this->ext_addslashes($extpassword)."' ");
b9ddb2d5 92 $authdb->Close();
8ae42b8d 93
b9ddb2d5 94 if (!$rs) {
a9ad3633 95 print_error('auth_dbcantconnect','auth');
b9ddb2d5 96 return false;
97 }
8ae42b8d 98
139ebfdb 99 if ($rs->RecordCount()) {
b9ddb2d5 100 return true;
101 } else {
102 return false;
8ae42b8d 103 }
104
b9ddb2d5 105 }
106 }
107
139ebfdb 108 function db_init() {
93901eb4 109 // Connect to the external database (forcing new connection)
110 $authdb = &ADONewConnection($this->config->type);
8ae42b8d 111 if (!empty($this->config->debugauthdb)) {
112 $authdb->debug = true;
113 ob_start();//start output buffer to allow later use of the page headers
114 }
115 $authdb->Connect($this->config->host, $this->config->user, $this->config->pass, $this->config->name, true);
b9ddb2d5 116 $authdb->SetFetchMode(ADODB_FETCH_ASSOC);
8ae42b8d 117 if (!empty($this->config->setupsql)) {
118 $authdb->Execute($this->config->setupsql);
119 }
b9ddb2d5 120
139ebfdb 121 return $authdb;
122 }
123 /**
124 * retuns user attribute mappings between moodle and ldap
125 *
126 * @return array
127 */
128 function db_attributes() {
8ae42b8d 129 $fields = array("firstname", "lastname", "email", "phone1", "phone2",
130 "department", "address", "city", "country", "description",
139ebfdb 131 "idnumber", "lang" );
132 $moodleattributes = array();
b9ddb2d5 133 foreach ($fields as $field) {
139ebfdb 134 if (!empty($this->config->{"field_map_$field"})) {
135 $moodleattributes[$field] = $this->config->{"field_map_$field"};
0f02788f 136 }
137 }
139ebfdb 138 $moodleattributes['username'] = $this->config->fielduser;
139 return $moodleattributes;
140 }
141
142 /**
143 * Reads any other information for a user from external database,
144 * then returns it in an array
145 *
146 * @param string $username (with system magic quotes)
147 *
148 * @return array without magic quotes
149 */
150 function get_userinfo($username) {
151
152 global $CFG;
153
154 $textlib = textlib_get_instance();
155 $extusername = $textlib->convert(stripslashes($username), 'utf-8', $this->config->extencoding);
156
157 $authdb = $this->db_init();
158
159 //Array to map local fieldnames we want, to external fieldnames
160 $selectfields = $this->db_attributes();
161
0f02788f 162 $result = array();
163 //If at least one field is mapped from external db, get that mapped data:
164 if ($selectfields) {
165 $select = '';
166 foreach ($selectfields as $localname=>$externalname) {
167 $select .= ", $externalname AS $localname";
168 }
169 $select = 'SELECT ' . substr($select,1);
170 $sql = $select .
171 " FROM {$this->config->table}" .
8ae42b8d 172 " WHERE {$this->config->fielduser} = '".$this->ext_addslashes($extusername)."'";
0f02788f 173 if ($rs = $authdb->Execute($sql)) {
174 if ( $rs->RecordCount() == 1 ) {
931b5085 175 $fields_obj = rs_fetch_record($rs);
0f02788f 176 foreach ($selectfields as $localname=>$externalname) {
8ae42b8d 177 $result[$localname] = $textlib->convert($fields_obj->{$localname}, $this->config->extencoding, 'utf-8');
0f02788f 178 }
179 }
931b5085 180 rs_close($rs);
b9ddb2d5 181 }
182 }
183 $authdb->Close();
b9ddb2d5 184 return $result;
185 }
186
187
fb5c7739 188 /**
189 * Change a user's password
190 *
c57dcb62 191 * @param object $user User table object (with system magic quotes)
192 * @param string $newpassword Plaintext password (with system magic quotes)
8ae42b8d 193 *
fb5c7739 194 * @return bool True on success
195 */
da249a30 196 function user_update_password($user, $newpassword) {
b9ddb2d5 197
b7b50143 198 global $CFG;
b9ddb2d5 199 if ($this->config->passtype === 'internal') {
139ebfdb 200 update_internal_user_password($user, $newpassword);
b9ddb2d5 201 } else {
202 // we should have never been called!
203 return false;
204 }
205 }
206
207 /**
208 * syncronizes user fron external db to moodle user table
209 *
210 * Sync shouid be done by using idnumber attribute, not username.
211 * You need to pass firstsync parameter to function to fill in
212 * idnumbers if they dont exists in moodle user table.
8ae42b8d 213 *
b9ddb2d5 214 * Syncing users removes (disables) users that dont exists anymore in external db.
8ae42b8d 215 * Creates new users and updates coursecreator status of users.
216 *
b9ddb2d5 217 * @param bool $do_updates Optional: set to true to force an update of existing accounts
218 *
219 * This implementation is simpler but less scalable than the one found in the LDAP module.
220 *
221 */
139ebfdb 222 function sync_users($do_updates=false) {
8ae42b8d 223
b9ddb2d5 224 global $CFG;
225 $pcfg = get_config('auth/db');
226
139ebfdb 227/// list external users
b9ddb2d5 228 $userlist = $this->get_userlist();
8ae42b8d 229 $quoteduserlist = implode("', '", addslashes_recursive($userlist));
b9ddb2d5 230 $quoteduserlist = "'$quoteduserlist'";
231
139ebfdb 232/// delete obsolete internal users
233 if (!empty($this->config->removeuser)) {
b9ddb2d5 234
139ebfdb 235 // find obsolete users
236 if (count($userlist)) {
237 $sql = "SELECT u.id, u.username, u.email
238 FROM {$CFG->prefix}user u
239 WHERE u.auth='db' AND u.deleted=0 AND u.username NOT IN ($quoteduserlist)";
240 } else {
241 $sql = "SELECT u.id, u.username, u.email
242 FROM {$CFG->prefix}user u
243 WHERE u.auth='db' AND u.deleted=0";
244 }
245 $remove_users = get_records_sql($sql);
246
247 if (!empty($remove_users)) {
248 print_string('auth_dbuserstoremove','auth', count($remove_users)); echo "\n";
249
250 begin_sql();
251 foreach ($remove_users as $user) {
252 if ($this->config->removeuser == 2) {
253 //following is copy pasted from admin/user.php
254 //maybe this should moved to function in lib/datalib.php
255 $updateuser = new object();
256 $updateuser->id = $user->id;
257 $updateuser->deleted = 1;
258 $updateuser->username = addslashes("$user->email.".time()); // Remember it just in case
259 $updateuser->email = ''; // Clear this field to free it up
260 $updateuser->idnumber = ''; // Clear this field to free it up
261 $updateuser->timemodified = time();
262 if (update_record('user', $updateuser)) {
263 delete_records('role_assignments', 'userid', $user->id); // unassign all roles
264 //copy pasted part ends
265 echo "\t"; print_string('auth_dbdeleteuser', 'auth', array($user->username, $user->id)); echo "\n";
266 } else {
267 echo "\t"; print_string('auth_dbdeleteusererror', 'auth', $user->username); echo "\n";
268 }
269 } else if ($this->config->removeuser == 1) {
270 $updateuser = new object();
271 $updateuser->id = $user->id;
272 $updateuser->auth = 'nologin';
273 if (update_record('user', $updateuser)) {
274 echo "\t"; print_string('auth_dbsuspenduser', 'auth', array($user->username, $user->id)); echo "\n";
275 } else {
276 echo "\t"; print_string('auth_dbsuspendusererror', 'auth', $user->username); echo "\n";
277 }
278 }
b9ddb2d5 279 }
139ebfdb 280 commit_sql();
8ae42b8d 281 }
139ebfdb 282 unset($remove_users); // free mem!
8ae42b8d 283 }
b9ddb2d5 284
285 if (!count($userlist)) {
286 // exit right here
287 // nothing else to do
288 return true;
289 }
290
291 ///
292 /// update existing accounts
293 ///
294 if ($do_updates) {
295 // narrow down what fields we need to update
296 $all_keys = array_keys(get_object_vars($this->config));
297 $updatekeys = array();
298 foreach ($all_keys as $key) {
299 if (preg_match('/^field_updatelocal_(.+)$/',$key, $match)) {
300 if ($this->config->{$key} === 'onlogin') {
301 array_push($updatekeys, $match[1]); // the actual key name
302 }
303 }
304 }
305 // print_r($all_keys); print_r($updatekeys);
306 unset($all_keys); unset($key);
307
308 // only go ahead if we actually
309 // have fields to update locally
310 if (!empty($updatekeys)) {
8ae42b8d 311 $sql = 'SELECT u.id, u.username
312 FROM ' . $CFG->prefix .'user u
b9ddb2d5 313 WHERE u.auth=\'db\' AND u.deleted=\'0\' AND u.username IN (' . $quoteduserlist . ')';
8ae42b8d 314 if ($update_users = get_records_sql($sql)) {
139ebfdb 315 print "User entries to update: ". count($update_users). "\n";
8ae42b8d 316
317 foreach ($update_users as $user) {
139ebfdb 318 echo "\t"; print_string('auth_dbupdatinguser', 'auth', array($user->username, $user->id));
319 if (!$this->update_user_record(addslashes($user->username), $updatekeys)) {
320 echo " - ".get_string('skipped');
321 }
322 echo "\n";
8ae42b8d 323 }
324 unset($update_users); // free memory
b9ddb2d5 325 }
b9ddb2d5 326 }
327 }
328
329
330 ///
331 /// create missing accounts
332 ///
333 // NOTE: this is very memory intensive
334 // and generally inefficient
8ae42b8d 335 $sql = 'SELECT u.id, u.username
336 FROM ' . $CFG->prefix .'user u
b9ddb2d5 337 WHERE u.auth=\'db\' AND u.deleted=\'0\'';
338
339 $users = get_records_sql($sql);
8ae42b8d 340
b9ddb2d5 341 // simplify down to usernames
342 $usernames = array();
343 foreach ($users as $user) {
344 array_push($usernames, $user->username);
345 }
346 unset($users);
347
348 $add_users = array_diff($userlist, $usernames);
349 unset($usernames);
350
351 if (!empty($add_users)) {
139ebfdb 352 print_string('auth_dbuserstoadd','auth',count($add_users)); echo "\n";
b9ddb2d5 353 begin_sql();
354 foreach($add_users as $user) {
355 $username = $user;
356 $user = $this->get_userinfo_asobj($user);
8ae42b8d 357
b9ddb2d5 358 // prep a few params
b7b50143 359 $user->username = $username;
360 $user->modified = time();
361 $user->confirmed = 1;
362 $user->auth = 'db';
363 $user->mnethostid = $CFG->mnet_localhost_id;
8ae42b8d 364 if (empty($user->lang)) {
365 $user->lang = $CFG->lang;
366 }
367
368 $user = addslashes_object($user);
b9ddb2d5 369 // maybe the user has been deleted before
b7b50143 370 if ($old_user = get_record('user', 'username', $user->username, 'deleted', 1, 'mnethostid', $user->mnethostid)) {
b9ddb2d5 371 $user->id = $old_user->id;
372 set_field('user', 'deleted', 0, 'username', $user->username);
139ebfdb 373 echo "\t"; print_string('auth_dbreviveuser', 'auth', array(stripslashes($user->username), $user->id)); echo "\n";
8ae42b8d 374 } elseif ($id = insert_record ('user',$user)) { // it is truly a new user
139ebfdb 375 echo "\t"; print_string('auth_dbinsertuser','auth',array(stripslashes($user->username), $id)); echo "\n";
b9ddb2d5 376 // if relevant, tag for password generation
377 if ($this->config->passtype === 'internal') {
378 set_user_preference('auth_forcepasswordchange', 1, $id);
379 set_user_preference('create_password', 1, $id);
380 }
381 } else {
139ebfdb 382 echo "\t"; print_string('auth_dbinsertusererror', 'auth', $user->username); echo "\n";
b9ddb2d5 383 }
b9ddb2d5 384 }
385 commit_sql();
386 unset($add_users); // free mem
387 }
388 return true;
389 }
390
139ebfdb 391 function user_exists($username) {
93901eb4 392
8ae42b8d 393 $textlib = textlib_get_instance();
394 $extusername = $textlib->convert(stripslashes($username), 'utf-8', $this->config->extencoding);
395
139ebfdb 396 $authdb = $this->db_init();
b9ddb2d5 397
8ae42b8d 398 $rs = $authdb->Execute("SELECT * FROM {$this->config->table}
399 WHERE {$this->config->fielduser} = '".$this->ext_addslashes($extusername)."' ");
b9ddb2d5 400 $authdb->Close();
401
402 if (!$rs) {
a9ad3633 403 print_error('auth_dbcantconnect','auth');
b9ddb2d5 404 return false;
405 }
8ae42b8d 406
b9ddb2d5 407 if ( $rs->RecordCount() ) {
408 // user exists exterally
b9ddb2d5 409 return $rs->RecordCount();
410 } else {
411 // user does not exist externally
412 return false;
8ae42b8d 413 }
b9ddb2d5 414 }
415
416
417 function get_userlist() {
93901eb4 418
139ebfdb 419 $authdb = $this->db_init();
b9ddb2d5 420
421 // fetch userlist
422 $rs = $authdb->Execute("SELECT {$this->config->fielduser} AS username
423 FROM {$this->config->table} ");
424 $authdb->Close();
425
426 if (!$rs) {
a9ad3633 427 print_error('auth_dbcantconnect','auth');
b9ddb2d5 428 return false;
429 }
8ae42b8d 430
b9ddb2d5 431 if ( $rs->RecordCount() ) {
432 $userlist = array();
c024b94b 433 while ($rec = rs_fetch_next_record($rs)) {
434 array_push($userlist, $rec->username);
b9ddb2d5 435 }
436 return $userlist;
437 } else {
438 return array();
8ae42b8d 439 }
b9ddb2d5 440 }
441
442 /**
443 * reads userinformation from DB and return it in an object
444 *
8ae42b8d 445 * @param string $username username (with system magic quotes)
b9ddb2d5 446 * @return array
447 */
448 function get_userinfo_asobj($username) {
449 $user_array = truncate_userinfo($this->get_userinfo($username));
8ae42b8d 450 $user = new object();
b9ddb2d5 451 foreach($user_array as $key=>$value) {
452 $user->{$key} = $value;
453 }
454 return $user;
455 }
456
8ae42b8d 457 /**
458 * will update a local user record from an external source.
459 * is a lighter version of the one in moodlelib -- won't do
b9ddb2d5 460 * expensive ops such as enrolment
461 *
8ae42b8d 462 * If you don't pass $updatekeys, there is a performance hit and
b9ddb2d5 463 * values removed from DB won't be removed from moodle.
8ae42b8d 464 *
465 * @param string $username username (with system magic quotes)
b9ddb2d5 466 */
139ebfdb 467 function update_user_record($username, $updatekeys=false) {
b7b50143 468 global $CFG;
b9ddb2d5 469
b9ddb2d5 470 //just in case check text case
471 $username = trim(moodle_strtolower($username));
8ae42b8d 472
b9ddb2d5 473 // get the current user record
b7b50143 474 $user = get_record('user', 'username', $username, 'mnethostid', $CFG->mnet_localhost_id);
b9ddb2d5 475 if (empty($user)) { // trouble
476 error_log("Cannot update non-existent user: $username");
a9ad3633 477 print_error('auth_dbusernotexist','auth',$username);
b9ddb2d5 478 die;
479 }
480
b7b50143 481 // Ensure userid is not overwritten
482 $userid = $user->id;
483
b9ddb2d5 484 if ($newinfo = $this->get_userinfo($username)) {
485 $newinfo = truncate_userinfo($newinfo);
8ae42b8d 486
b9ddb2d5 487 if (empty($updatekeys)) { // all keys? this does not support removing values
488 $updatekeys = array_keys($newinfo);
489 }
8ae42b8d 490
b9ddb2d5 491 foreach ($updatekeys as $key) {
b9ddb2d5 492 if (isset($newinfo[$key])) {
493 $value = $newinfo[$key];
b9ddb2d5 494 } else {
495 $value = '';
496 }
8ae42b8d 497
498 if (!empty($this->config->{'field_updatelocal_' . $key})) {
139ebfdb 499 if ($user->{$key} != $value) { // only update if it's changed
500 set_field('user', $key, addslashes($value), 'id', $userid);
501 }
b9ddb2d5 502 }
503 }
504 }
139ebfdb 505 return get_record_select('user', "id = $userid AND deleted = 0");
506 }
507
508 /**
509 * Called when the user record is updated.
510 * Modifies user in external database. It takes olduser (before changes) and newuser (after changes)
511 * conpares information saved modified information to external db.
512 *
513 * @param mixed $olduser Userobject before modifications (without system magic quotes)
514 * @param mixed $newuser Userobject new modified userobject (without system magic quotes)
515 * @return boolean result
516 *
517 */
518 function user_update($olduser, $newuser) {
519 if (isset($olduser->username) and isset($newuser->username) and $olduser->username != $newuser->username) {
520 error_log("ERROR:User renaming not allowed in ext db");
521 return false;
522 }
523
524 if (isset($olduser->auth) and $olduser->auth != 'db') {
525 return true; // just change auth and skip update
526 }
527
528 $curruser = $this->get_userinfo($olduser->username);
529 if (empty($curruser)) {
530 error_log("ERROR:User $olduser->username found in ext db");
531 return false;
532 }
533
534 $textlib = textlib_get_instance();
535 $extusername = $textlib->convert($olduser->username, 'utf-8', $this->config->extencoding);
536
537 $authdb = $this->db_init();
538
539 $update = array();
540 foreach($curruser as $key=>$value) {
541 if ($key == 'username') {
542 continue; // skip this
543 }
544 if (empty($this->config->{"field_updateremote_$key"})) {
545 continue; // remote update not requested
546 }
547 if (!isset($newuser->$key)) {
548 continue;
549 }
550 $nuvalue = stripslashes($newuser->$key);
551 if ($nuvalue != $value) {
552 $update[] = $this->config->{"field_map_$key"}."='".$this->ext_addslashes($textlib->convert($nuvalue, 'utf-8', $this->config->extencoding))."'";
553 }
554 }
555 if (!empty($update)) {
556 $authdb->Execute("UPDATE {$this->config->table}
557 SET ".implode(',', $update)."
558 WHERE {$this->config->fielduser}='".$this->ext_addslashes($extusername)."'");
559 }
560 $authdb->Close();
561 return true;
b9ddb2d5 562 }
563
8ae42b8d 564 /**
565 * A chance to validate form data, and last chance to
566 * do stuff before it is inserted in config_plugin
567 */
568 function validate_form(&$form, &$err) {
150b5fb0 569 if ($form->passtype === 'internal') {
b9ddb2d5 570 $this->config->changepasswordurl = '';
571 set_config('changepasswordurl', '', 'auth/db');
572 }
b9ddb2d5 573 }
574
575 /**
576 * Returns true if this authentication plugin is 'internal'.
577 *
139ebfdb 578 * @return bool
b9ddb2d5 579 */
580 function is_internal() {
581 return false;
582 }
583
584 /**
585 * Returns true if this authentication plugin can change the user's
586 * password.
587 *
139ebfdb 588 * @return bool
b9ddb2d5 589 */
590 function can_change_password() {
430759a5 591 return ($this->config->passtype == 'internal' or !empty($this->config->changepasswordurl));
b9ddb2d5 592 }
593
594 /**
430759a5 595 * Returns the URL for changing the user's pw, or empty if the default can
b9ddb2d5 596 * be used.
597 *
430759a5 598 * @return string
b9ddb2d5 599 */
600 function change_password_url() {
430759a5 601 if ($this->config->passtype == 'internal') {
602 // standard form
603 return '';
604 } else {
605 // use custom url
606 return $this->config->changepasswordurl;
607 }
b9ddb2d5 608 }
609
610 /**
611 * Prints a form for configuring this authentication plugin.
612 *
613 * This function is called from admin/auth.php, and outputs a full page with
614 * a form for configuring this plugin.
615 *
616 * @param array $page An object containing all the data for this page.
617 */
139ebfdb 618 function config_form($config, $err, $user_fields) {
8ae42b8d 619 include 'config.html';
b9ddb2d5 620 }
621
622 /**
623 * Processes and stores configuration data for this authentication plugin.
624 */
625 function process_config($config) {
626 // set to defaults if undefined
627 if (!isset($config->host)) {
8ae42b8d 628 $config->host = 'localhost';
b9ddb2d5 629 }
630 if (!isset($config->type)) {
8ae42b8d 631 $config->type = 'mysql';
632 }
633 if (!isset($config->sybasequoting)) {
634 $config->sybasequoting = 0;
b9ddb2d5 635 }
636 if (!isset($config->name)) {
8ae42b8d 637 $config->name = '';
b9ddb2d5 638 }
639 if (!isset($config->user)) {
8ae42b8d 640 $config->user = '';
b9ddb2d5 641 }
642 if (!isset($config->pass)) {
8ae42b8d 643 $config->pass = '';
b9ddb2d5 644 }
645 if (!isset($config->table)) {
8ae42b8d 646 $config->table = '';
b9ddb2d5 647 }
648 if (!isset($config->fielduser)) {
8ae42b8d 649 $config->fielduser = '';
b9ddb2d5 650 }
651 if (!isset($config->fieldpass)) {
8ae42b8d 652 $config->fieldpass = '';
b9ddb2d5 653 }
654 if (!isset($config->passtype)) {
8ae42b8d 655 $config->passtype = 'plaintext';
656 }
657 if (!isset($config->extencoding)) {
658 $config->extencoding = 'utf-8';
659 }
660 if (!isset($config->setupsql)) {
661 $config->setupsql = '';
662 }
663 if (!isset($config->debugauthdb)) {
664 $config->debugauthdb = 0;
b9ddb2d5 665 }
139ebfdb 666 if (!isset($config->removeuser)) {
667 $config->removeuser = 0;
668 }
b9ddb2d5 669 if (!isset($config->changepasswordurl)) {
670 $config->changepasswordurl = '';
671 }
672
8ae42b8d 673 $config = stripslashes_recursive($config);
b9ddb2d5 674 // save settings
8ae42b8d 675 set_config('host', $config->host, 'auth/db');
676 set_config('type', $config->type, 'auth/db');
677 set_config('sybasequoting', $config->sybasequoting, 'auth/db');
678 set_config('name', $config->name, 'auth/db');
679 set_config('user', $config->user, 'auth/db');
680 set_config('pass', $config->pass, 'auth/db');
681 set_config('table', $config->table, 'auth/db');
682 set_config('fielduser', $config->fielduser, 'auth/db');
683 set_config('fieldpass', $config->fieldpass, 'auth/db');
684 set_config('passtype', $config->passtype, 'auth/db');
685 set_config('extencoding', trim($config->extencoding), 'auth/db');
139ebfdb 686 set_config('setupsql', trim($config->setupsql),'auth/db');
8ae42b8d 687 set_config('debugauthdb', $config->debugauthdb, 'auth/db');
139ebfdb 688 set_config('removeuser', $config->removeuser, 'auth/db');
8ae42b8d 689 set_config('changepasswordurl', trim($config->changepasswordurl), 'auth/db');
690
b9ddb2d5 691 return true;
692 }
693
8ae42b8d 694 function ext_addslashes($text) {
695 // using custom made function for now
696 if (empty($this->config->sybasequoting)) {
697 $text = str_replace('\\', '\\\\', $text);
698 $text = str_replace(array('\'', '"', "\0"), array('\\\'', '\\"', '\\0'), $text);
699 } else {
700 $text = str_replace("'", "''", $text);
701 }
702 return $text;
703 }
b9ddb2d5 704}
705
706?>