Skip to content

Commit

Permalink
Merge branch 'w13_MDL-26992_21_uploadtemplates' of git://github.com/s…
Browse files Browse the repository at this point in the history
…kodak/moodle
  • Loading branch information
Sam Hemelryk committed Mar 28, 2011
2 parents 982e619 + 43070e6 commit bc071c7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 20 deletions.
23 changes: 17 additions & 6 deletions admin/uploaduser.php
Expand Up @@ -307,6 +307,9 @@
// process templates // process templates
$user->$field = uu_process_template($formdata->$field, $user); $user->$field = uu_process_template($formdata->$field, $user);
$formdefaults[$field] = true; $formdefaults[$field] = true;
if (in_array($field, $upt->columns)) {
$upt->track($field, s($user->$field), 'normal');
}
} }
} }
foreach ($PRF_FIELDS as $field) { foreach ($PRF_FIELDS as $field) {
Expand Down Expand Up @@ -614,7 +617,13 @@


$isinternalauth = $auth->is_internal(); $isinternalauth = $auth->is_internal();


if ($DB->record_exists('user', array('email'=>$user->email))) { if (empty($user->email)) {
$upt->track('email', get_string('invalidemail'), 'error');
$upt->track('status', $strusernotaddederror, 'error');
$userserrors++;
continue;

} else if ($DB->record_exists('user', array('email'=>$user->email))) {
if ($noemailduplicates) { if ($noemailduplicates) {
$upt->track('email', $stremailduplicate, 'error'); $upt->track('email', $stremailduplicate, 'error');
$upt->track('status', $strusernotaddederror, 'error'); $upt->track('status', $strusernotaddederror, 'error');
Expand Down Expand Up @@ -898,11 +907,13 @@
$rowcols['status'][] = get_string('missingusername'); $rowcols['status'][] = get_string('missingusername');
} }


if (!validate_email($rowcols['email'])) { if (isset($rowcols['email'])) {
$rowcols['status'][] = get_string('invalidemail'); if (!validate_email($rowcols['email'])) {
} $rowcols['status'][] = get_string('invalidemail');
if ($DB->record_exists('user', array('email'=>$rowcols['email']))) { }
$rowcols['status'][] = $stremailduplicate; if ($DB->record_exists('user', array('email'=>$rowcols['email']))) {
$rowcols['status'][] = $stremailduplicate;
}
} }
$rowcols['status'] = implode('<br />', $rowcols['status']); $rowcols['status'] = implode('<br />', $rowcols['status']);
$data[] = $rowcols; $data[] = $rowcols;
Expand Down
43 changes: 29 additions & 14 deletions admin/uploaduserlib.php
Expand Up @@ -248,33 +248,48 @@ function uu_process_template($template, $user) {


if (is_null($result)) { if (is_null($result)) {
return $template; //error during regex processing?? return $template; //error during regex processing??
}

if (is_array($template)) {
$template['text'] = $result;
return $t;
} else { } else {
if (array($template)) { return $result;
$template['text'] = $t;
return $t;
} else {
return $t;
}
} }
} }


/** /**
* Internal callback function. * Internal callback function.
*/ */
function uu_process_template_callback($block, $username, $firstname, $lastname) { function uu_process_template_callback($username, $firstname, $lastname, $block) {
$textlib = textlib_get_instance(); $textlib = textlib_get_instance();
$repl = $block[0];


switch ($block[3]) { switch ($block[3]) {
case 'u': $repl = $username; break; case 'u':
case 'f': $repl = $firstname; break; $repl = $username;
case 'l': $repl = $lastname; break; break;
case 'f':
$repl = $firstname;
break;
case 'l':
$repl = $lastname;
break;
default:
return $block[0];
} }

switch ($block[1]) { switch ($block[1]) {
case '+': $repl = $textlib->strtoupper($repl); break; case '+':
case '-': $repl = $textlib->strtolower($repl); break; $repl = $textlib->strtoupper($repl);
case '~': $repl = $textlib->strtotitle($repl); break; break;
case '-':
$repl = $textlib->strtolower($repl);
break;
case '~':
$repl = $textlib->strtotitle($repl);
break;
} }

if (!empty($block[2])) { if (!empty($block[2])) {
$repl = $textlib->substr($repl, 0 , $block[2]); $repl = $textlib->substr($repl, 0 , $block[2]);
} }
Expand Down

0 comments on commit bc071c7

Please sign in to comment.