~ubuntu-branches/ubuntu/maverick/mahara/maverick-updates

« back to all changes in this revision

Viewing changes to htdocs/lib/user.php

  • Committer: Bazaar Package Importer
  • Author(s): Francois Marier
  • Date: 2009-10-30 13:46:40 UTC
  • mfrom: (6.2.6 sid)
  • Revision ID: james.westby@ubuntu.com-20091030134640-13srv45w4660pmic
Tags: 1.1.7-1
* New upstream release
  - Privilege escalation fix (CVE-2009-3298)
  - XSS fix (CVE-2009-3299)

* Bump Standards-Version up to 3.8.3
* Switch packaging license to refer to GPL-3
* debian/mahara.config: Move -e to a separate line to silence lintian

Show diffs side-by-side

added added

removed removed

Lines of Context:
271
271
 * @throws EmailException
272
272
 */ 
273
273
function email_user($userto, $userfrom, $subject, $messagetext, $messagehtml='', $customheaders=null) {
 
274
    global $IDPJUMPURL;
 
275
    static $mnetjumps = array();
 
276
 
274
277
    if (!get_config('sendemail')) {
275
278
        // You can entirely disable Mahara from sending any e-mail via the 
276
279
        // 'sendemail' configuration variable
281
284
        throw new InvalidArgumentException("empty user given to email_user");
282
285
    }
283
286
    
 
287
    // If the user is a remote xmlrpc user, trawl through the email text for URLs
 
288
    // to our wwwroot and modify the url to direct the user's browser to login at
 
289
    // their home site before hitting the link on this site
 
290
    if (!empty($userto->mnethostwwwroot) && !empty($userto->mnethostapp)) {
 
291
        require_once(get_config('docroot') . 'auth/xmlrpc/lib.php');
 
292
 
 
293
        // Form the request url to hit the idp's jump.php
 
294
        if (isset($mnetjumps[$userto->mnethostwwwroot])) {
 
295
            $IDPJUMPURL = $mnetjumps[$userto->mnethostwwwroot];
 
296
        } else {
 
297
            $mnetjumps[$userto->mnethostwwwroot] = $IDPJUMPURL = PluginAuthXmlrpc::get_jump_url_prefix($userto->mnethostwwwroot, $userto->mnethostapp);
 
298
        }
 
299
 
 
300
        $wwwroot = get_config('wwwroot');
 
301
        $messagetext = preg_replace_callback('%(' . $wwwroot . '([\w_:\?=#&@/;.~-]*))%',
 
302
            'localurl_to_jumpurl',
 
303
            $messagetext);
 
304
        $messagehtml = preg_replace_callback('%href=["\'`](' . $wwwroot . '([\w_:\?=#&@/;.~-]*))["\'`]%',
 
305
            'localurl_to_jumpurl',
 
306
            $messagehtml);
 
307
    }
 
308
 
 
309
 
284
310
    require_once('phpmailer/class.phpmailer.php');
285
311
 
286
312
    $mail = new phpmailer();
312
338
        }
313
339
    }
314
340
 
315
 
    if (empty($userfrom)) {
 
341
    if (empty($userfrom) || $userfrom->email == get_config('noreplyaddress')) {
316
342
        $mail->Sender = get_config('noreplyaddress');
317
343
        $mail->From = $mail->Sender;
318
 
        $mail->FromName = get_string('emailname');
 
344
        $mail->FromName = (isset($userfrom->id)) ? display_name($userfrom, $userto) : get_config('sitename');
319
345
        $customheaders[] = 'Precedence: Bulk'; // Try to avoid pesky out of office responses
320
346
        $messagetext .= "\n\n" . get_string('pleasedonotreplytothismessage') . "\n";
321
347
        if ($messagehtml) {
443
469
            $user->lastname      = $USER->get('lastname');
444
470
            $user->admin         = $USER->get('admin') || $USER->is_institutional_admin();
445
471
            $user->staff         = $USER->get('staff') || $USER->is_institutional_staff();
 
472
            $user->deleted       = 0;
446
473
            $usercache[$user->id] = $user;
447
474
        }
448
475
        else {
463
490
        $user->lastname      = $userObj->get('lastname');
464
491
        $user->admin         = $userObj->get('admin');
465
492
        $user->staff         = $userObj->get('staff');
 
493
        $user->deleted       = $userObj->get('deleted');
466
494
    }
467
495
 
468
496
    $user->id   = (isset($user->id)) ? $user->id : null;
473
501
    }
474
502
 
475
503
    // if they don't have a preferred name set, just return here
 
504
    $firstlast = (isset($user->deleted) && $user->deleted) ? get_string('deleteduser') : ($user->firstname . ' ' . $user->lastname);
476
505
    if (empty($user->preferredname)) {
477
506
        if ((!empty($userto->admin) || !empty($userto->staff)) && !$nameonly) {
478
 
            return ($resultcache[$user->id][$userto->id][$nameonly]
479
 
                = $user->firstname . ' ' . $user->lastname . ' (' . $user->username . ')');
 
507
            return ($resultcache[$user->id][$userto->id][$nameonly] = $firstlast . ' (' . $user->username . ')');
480
508
        }
481
 
        return ($resultcache[$user->id][$userto->id][$nameonly]
482
 
            = $user->firstname . ' ' . $user->lastname);
 
509
        return ($resultcache[$user->id][$userto->id][$nameonly] = $firstlast);
483
510
    }
484
511
    else if ($user->id == $userto->id) {
485
512
        // If viewing our own name, show it how we like it
486
 
        return ($resultcache[$user->id][$userto->id][$nameonly]
487
 
            = $user->preferredname);
 
513
        return ($resultcache[$user->id][$userto->id][$nameonly] = $user->preferredname);
488
514
    }
489
515
 
490
516
    if ((!empty($userto->admin) || !empty($userto->staff)) && !$nameonly) {
491
517
        return ($resultcache[$user->id][$userto->id][$nameonly]
492
 
            = $user->preferredname . ' (' . $user->firstname . ' ' . $user->lastname . ' - ' . $user->username . ')');
 
518
            = $user->preferredname . ' (' . $firstlast . ' - ' . $user->username . ')');
493
519
    }
494
520
 
495
521
    $sql = "SELECT g1.member
500
526
            WHERE g1.member = ? AND g2.member = ? AND g2.role = 'tutor'";
501
527
    if (record_exists_sql($sql, array($user->id, $userto->id))) {
502
528
        return ($resultcache[$user->id][$userto->id][$nameonly]
503
 
            = $user->preferredname . ($nameonly ? '' : ' (' . $user->firstname . ' ' . $user->lastname . ')'));
 
529
            = $user->preferredname . ($nameonly ? '' : ' (' . $firstlast . ')'));
504
530
    }
505
 
    return ($resultcache[$user->id][$userto->id][$nameonly]
506
 
        = $user->preferredname);
 
531
    return ($resultcache[$user->id][$userto->id][$nameonly] = $user->preferredname);
507
532
}
508
533
 
509
534
/**