user.php 22.7 KB
Newer Older
Penny Leach's avatar
Penny Leach committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
/**
 * This program is part of Mahara
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 *
 * @package    mahara
 * @subpackage core
 * @author     Penny Leach <penny@catalyst.net.nz>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
 *
 */

defined('INTERNAL') || die();

/** 
 * loads up activity preferences for a given user
 *
 * @param int $userid to load preferences for 
 * @todo caching
 */
function load_activity_preferences($userid) {
    $prefs = array();
    if (empty($userid)) {
        throw new InvalidArgumentException("couldn't load activity preferences, no user id specified");
    }
40
    if ($prefs = get_records_array('usr_activity_preference', 'usr', $userid)) {
Penny Leach's avatar
Penny Leach committed
41
        foreach ($prefs as $p) {
42
            $prefs[$p->activity] = $p->method;
Penny Leach's avatar
Penny Leach committed
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
        }
    }
    return $prefs;
}

/** 
 * loads up account preferences for a given user
 * if you want them for the current user
 * use $SESSION->accountprefs
 *
 * @param int $userid to load preferences for 
 * @todo caching
 * @todo defaults? 
 */
function load_account_preferences($userid) {
    $prefs = array();
    $expectedprefs = expected_account_preferences();
    if (empty($userid)) {
        throw new InvalidArgumentException("couldn't load account preferences, no user id specified");
    }
63
    if ($prefs = get_records_array('usr_account_preference', 'usr', $userid)) {
Penny Leach's avatar
Penny Leach committed
64
        foreach ($prefs as $p) {
65
            $prefs[$p->field] = $p->value;
Penny Leach's avatar
Penny Leach committed
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
        }
    }
    foreach ($expectedprefs as $field => $default) {
        if (!isset($prefs[$field])) {
            $prefs[$field] = $default;
        }
    }
    return $prefs;
}


/** 
 * sets a user preference in the database
 * if you want to set it in the session as well
 * use SESSION->set_account_preference 
 *
 * @param int $userid user id to set preference for
 * @param string $field preference field to set
 * @param string $value preference value to set.
 */
function set_account_preference($userid, $field, $value) {
    if (record_exists('usr_account_preference', 'usr', $userid, 'field', $field)) {
        set_field('usr_account_preference', 'value', $value, 'usr', $userid, 'field', $field);
    }
    else {
        try {
            $pref = new StdClass;
            $pref->usr = $userid;
            $pref->field = $field;
            $pref->value = $value;
            insert_record('usr_account_preference', $pref);
        }
        catch (Exception $e) {
            throw new InvalidArgumentException("Failed to insert account preference "
                ." $value for $field for user $userid");
        }
    }
}

/** 
 * sets an activity preference in the database
 * if you want to set it in the session as well
 * use $SESSION->set_activity_preference 
 *
 * @param int $userid user id to set preference for
 * @param string $activity activity type to set
 * @param string $method notification method to set.
 */
function set_activity_preference($userid, $activity, $method) {
115
116
117
    if (empty($method)) {
        return delete_records('usr_activity_preference', 'activity', $activity, 'usr', $userid);
    }
Penny Leach's avatar
Penny Leach committed
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
    if (record_exists('usr_activity_preference', 'usr', $userid, 'activity', $activity)) {
        set_field('usr_activity_preference', 'method', $method, 'usr', $userid, 'activity', $activity);
    }
    else {
        try {
            $pref = new StdClass;
            $pref->usr = $userid;
            $pref->activity = $activity;
            $pref->method = $method;
            insert_record('usr_activity_preference', $pref);
        }
        catch (Exception $e) {
            throw new InvalidArgumentException("Failed to insert activity preference "
                ." $methodfor $activity for user $userid");
        }
    }
}

136
137
138
139
140
141
142
143
144
/**
 * gets an account preference for the user, 
 * or the default if not set for that user,
 * as specified in {@link expected_account_preferences}
 *
 * @param int $userid id of user
 * @param string $field preference to get
 */
function get_account_preference($userid, $field) {
145
    if ($pref = get_record('usr_account_preference', 'usr', $userid, 'field', $field)) {
146
147
148
149
150
151
152
153
154
155
156
        return $pref->value;
    }
    $expected = expected_account_preferences();
    return $expected[$field];
}

/**
 * default account settings
 * 
 * @returns array of fields => values
 */
Penny Leach's avatar
Penny Leach committed
157
158
159
160
161
162
163
164
function expected_account_preferences() {
    return array('friendscontrol' => 'auth',
                 'wysiwyg'        =>  1,
                 'messages'       => 'allow',
                 'lang'           => 'en.utf8'
                 );
}

165
166
function set_profile_field($userid, $field, $value) {
    safe_require('artefact', 'internal');
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186

    // this is a special case that replaces the primary email address with the
    // specified one
    if ($field == 'email') {
        try {
            $email = artefact_instance_from_type('email');
        }
        catch (ArtefactNotFoundException $e) {
            $email = new ArtefactTypeEmail();
            $email->set('owner', $userid);
        }
        $email->set('title', $value);
        $email->commit();
    }
    else {
        $classname = generate_artefact_class_name($field);
        $profile = new $classname(0, array('owner' => $userid));
        $profile->set('title', $value);
        $profile->commit();
    }
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
}

/**
 * Return the value of a profile field for a given user
 *
 * @param integer user id to find the profile field for
 * @param field what profile field you want the value for
 * @returns string the value of the profile field (null if it doesn't exist)
 *
 * @todo, this needs to be better (fix email behaviour)
 */
function get_profile_field($userid, $field) {
    $value = get_field('artefact', 'title', 'owner', $userid, 'artefacttype', $field);

    if ($value) {
        return $value;
    }
204

205
    return null;
206
207
}

208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
/** 
 * Always use this function for all emails to users
 * 
 * @param object $userto user object to send email to. must contain firstname,lastname,preferredname,email
 * @param object $userfrom user object to send email from. If null, email will come from mahara
 * @param string $subject email subject
 * @param string $messagetext text version of email
 * @param string $messagehtml html version of email (will send both html and text)
 * @throws EmailException
 */ 
function email_user($userto, $userfrom, $subject, $messagetext, $messagehtml='') {

    if (empty($userto)) {
        throw new InvalidArgumentException("empty user given to email_user");
    }
    
    require_once('phpmailer/class.phpmailer.php');

    $mail = new phpmailer();

    $mail->Version = 'Mahara ' . get_config('release'); 
    $mail->PluginDir = get_config('libroot')  . 'phpmailer/';
    
    $mail->CharSet = 'UTF-8';

    $smtphosts = get_config('smtphosts');
    if ($smtphosts == 'qmail') {
        // use Qmail system
        $mail->IsQmail();
    } 
    else if (empty($smtphosts)) {
        // use PHP mail() = sendmail
        $mail->IsMail();
    }
    else {
        $mail->IsSMTP();
        // use SMTP directly
        $mail->Host = get_config('smtphosts');
        if (get_config('smtpuser')) {
            // Use SMTP authentication
            $mail->SMTPAuth = true;
            $mail->Username = get_config('smtpuser');
            $mail->Password = get_config('smtppass');
        }
    }

    if (empty($userfrom)) {
        $mail->Sender = get_config('noreplyaddress');
        $mail->From = $mail->Sender;
        $mail->FromName = get_string('emailname');
    }
    else {
        $mail->Sender = $userfrom->email;
        $mail->From = $mail->Sender;
        $mail->FromName = display_name($userfrom, $userto);
    }
           
    $mail->AddReplyTo($mail->From, $mail->FromName);

    $mail->Subject = substr(stripslashes($subject), 0, 78);

    $usertoname = display_name($userto, $userto);
    $mail->AddAddress($userto->email, $usertoname );

    $mail->WordWrap = 79;   

    if ($messagehtml) { 
        $mail->IsHTML(true);
        $mail->Encoding = 'quoted-printable';
        $mail->Body    =  $messagehtml;
        $mail->AltBody =  "\n$messagetext\n";
    } 
    else {
        $mail->IsHTML(false);
        $mail->Body =  "\n$messagetext\n";
    }

    if ($mail->Send()) {
        return true;
    } 
    throw new EmailException("Couldn't send email to $usertoname with subject $subject. "
                        . "Error from phpmailer was: " . $mail->ErrorInfo );
}

/**
 * converts a user object to a string representation of the user suitable for
 * the current user (or specified user) to see
 *
 * Both parameters should be objects containing id, preferredname, firstname,
 * lastname, admin
 *
 * @param object the user that you're trying to format to a string
 * @param object the user that is looking at the string representation (if left
 * blank, will default to the currently logged in user).
 *
 * @returns string name to display
 */
function display_name($user, $userto=null) {
    global $USER;
    
    if (empty($userto)) {
        $userto = new StdClass;
        $userto->id            = $USER->get('id');
311
        $userto->username      = $USER->get('username');
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
        $userto->preferredname = $USER->get('preferredname');
        $userto->firstname     = $USER->get('firstname');
        $userto->lastname      = $USER->get('lastname');
        $userto->admin         = $USER->get('admin');
    }
    if (is_array($user)) {
        $user = (object)$user;
    }
    else if (is_numeric($user)) {
        $user = get_record('usr', 'id', $user);
    }
    if (!is_object($user)) {
        throw new InvalidArgumentException("Invalid user passed to display_name");
    }

Martyn Smith's avatar
Martyn Smith committed
327
328
329
330
    if ($user instanceof User) {
        $userObj = $user;
        $user = new StdClass;
        $user->id            = $userObj->get('id');
331
        $user->username      = $userObj->get('username');
Martyn Smith's avatar
Martyn Smith committed
332
333
334
335
336
337
        $user->preferredname = $userObj->get('preferredname');
        $user->firstname     = $userObj->get('firstname');
        $user->lastname      = $userObj->get('lastname');
        $user->admin         = $userObj->get('admin');
    }

338
339
    // if they don't have a preferred name set, just return here
    if (empty($user->preferredname)) {
340
341
342
        if ($userto->admin) {
            return $user->firstname . ' ' . $user->lastname . ' (' . $user->username . ')';
        }
343
344
345
346
        return $user->firstname . ' ' . $user->lastname;
    }

    if ($userto->admin) {
347
        return $user->preferredname . ' (' . $user->firstname . ' ' . $user->lastname . ' - ' . $user->username . ')';
348
349
350
351
352
353
354
355
356
357
358
359
360
361
    }

    $prefix = get_config('dbprefix');
    $sql = 'SELECT c1.member
            FROM ' . $prefix . 'community_member c1 
            JOIN  ' .$prefix. 'community_member c2
                ON c1.community = c2.community 
            WHERE c1.member = ? AND c2.member = ? AND c2.tutor = ?';
    if (record_exists_sql($sql, array($user->id, $userto->id, 1))) {
        return $user->preferredname . ' (' . $user->firstname . ' ' . $user->lastname . ')';
    }
    return  $user->preferredname;
}

Penny Leach's avatar
Penny Leach committed
362
363
364
/**
 * function to format a users name when there is no user to look at them
 * ie when display_name is not going to work..
365
 */
Penny Leach's avatar
Penny Leach committed
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
function display_default_name($user) {
    if (is_array($user)) {
        $user = (object)$user;
    }
    else if (is_numeric($user)) {
        $user = get_record('usr', 'id', $user);
    }
    if (!is_object($user)) {
        throw new InvalidArgumentException("Invalid user passed to display_name");
    }

    if ($user instanceof User) {
        $userObj = $user;
        $user = new StdClass;
        $user->id            = $userObj->get('id');
        $user->preferredname = $userObj->get('preferredname');
        $user->firstname     = $userObj->get('firstname');
        $user->lastname      = $userObj->get('lastname');
        $user->admin         = $userObj->get('admin');
    }

    // if they don't have a preferred name set, just return here
    if (empty($user->preferredname)) {
        return $user->firstname . ' ' . $user->lastname;
    }
    else {
        return $user->preferedname;
    }
}



398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
/**
 * Converts a user object to a full name representation, honouring the language
 * setting.
 *
 * Currently a stub, will need to be improved and completed as demand arises.
 *
 * @param object $user The user object to make a full name out of. If empty,
 *                     the global $USER object is used*/
function full_name($user=null) {
    global $USER;

    if ($user === null) {
        $user = new StdClass;
        $user->firstname = $USER->get('firstname');
        $user->lastname  = $USER->get('lastname');
    }

    return $user->firstname . ' ' . $user->lastname;
}
417

418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437

/**
 * helper function to default to currently
 * logged in user if there isn't an id specified
 * @throws InvalidArgumentException if there is no user and no $USER
 */
function optional_userid($userid) {

    if (!empty($userid)) {
        return $userid;
    }

    if (!is_logged_in()) {
        throw new InvalidArgumentException("optional_userid no userid and no logged in user");
    }
    
    global $USER;
    return $USER->get('id');
}

438
439
440
441
442
443
444
445
446
447
448
449
450


/**
 * helper function to default to currently
 * logged in user if there isn't an id specified
 * @throws InvalidArgumentException if there is no user and no $USER
 */
function optional_userobj($user) {

    if (!empty($user) && is_object($user)) {
        return $user;
    }

451
    if (!empty($user) && is_numeric($user)) {
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
        if ($user = get_record('usr', 'id', $user)) {
            return $user;
        }
        throw new InvalidArgumentException("optional_userobj given id $id no db match found");
    }

    if (!is_logged_in()) {
        throw new InvalidArgumentException("optional_userobj no userid and no logged in user");
    }
    
    global $USER;
    return $USER->to_stdclass();
}




469
470
471
/**
 * helper function for testing logins
 */
472
473
function is_logged_in() {
    global $USER;
Martyn Smith's avatar
Martyn Smith committed
474
475
476
477
478
    if (empty($USER)) {
        return false;
    }

    return $USER->is_logged_in();
479
480
}

481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
/**
 * is there a friend relationship between these two users?
 *
 * @param int $userid1 
 * @param int $userid2
 */

function is_friend($userid1, $userid2) {
    return record_exists_select('usr_friend', '(usr1 = ? AND usr2 = ?) OR (usr2 = ? AND usr1 = ?)', 
                                array($userid1, $userid2, $userid1, $userid2));
}

/**
 * has there been a request between these two users?
 *
 * @param int $userid1
 * @param int $userid2
 */
function get_friend_request($userid1, $userid2) {
    return get_record_select('usr_friend_request', '(owner = ? AND requester = ?) OR (requester = ? AND owner = ?)',
                             array($userid1, $userid2, $userid1, $userid2));
        
} 

505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
/**
 * Returns an object containing information about a user, including account
 * and activity preferences
 *
 * @param int $userid The ID of the user to retrieve information about
 * @return object     The user object. Note this is not in the same form as
 *                    the $USER object used to denote the current user -
 *                    the object returned by this method is a simple object.
 */
function get_user($userid) {
    if (!$user = get_record('usr', 'id', $userid, null, null, null, null,
        '*, ' . db_format_tsfield('expiry') . ', ' . db_format_tsfield('lastlogin'))) {
        throw new InvalidArgumentException('Unknown user ' . $userid);
    }

    $user->activityprefs = load_activity_preferences($userid);
    $user->accountprefs  = load_account_preferences($userid);
    return $user;
}

525

Nigel McNie's avatar
Nigel McNie committed
526
527
528
529
530
531
532
533
534
535
536
537
/**
 * Suspends a user
 *
 * @param int $suspendeduserid  The ID of the user to suspend
 * @param string $reason        The reason why the user is being suspended
 * @param int $suspendinguserid The ID of the user who is performing the suspension
 */
function suspend_user($suspendeduserid, $reason, $suspendinguserid=null) {
    if ($suspendinguserid === null) {
        global $USER;
        $suspendinguserid = $USER->get('id');
    }
538

Nigel McNie's avatar
Nigel McNie committed
539
540
541
542
543
544
    $suspendrec = new StdClass;
    $suspendrec->id              = $suspendeduserid;
    $suspendrec->suspendedcusr   = $suspendinguserid;
    $suspendrec->suspendedreason = $reason;
    $suspendrec->suspendedctime  = db_format_timestamp(time());
    update_record('usr', $suspendrec, 'id');
545

546
547
548
549
550
551
    $message = new StdClass;
    $message->users = array($suspendeduserid);
    $message->subject = get_string('youraccounthasbeensuspended');
    $message->message = get_string('youraccounthasbeensuspendedtext');
    activity_occurred('maharamessage', $message);

Nigel McNie's avatar
Nigel McNie committed
552
553
    handle_event('suspenduser', $suspendeduserid);
}
554

Penny Leach's avatar
Penny Leach committed
555
556
557
558
/**
 * handle the add/remove/approve/reject friend form
 * @param array $values from pieforms.
 */
Martyn Smith's avatar
Martyn Smith committed
559
function friend_submit($form, $values) {
Penny Leach's avatar
Penny Leach committed
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
    global $user, $USER;

    $loggedinid = $USER->get('id');
    $userid = $user->id;

    // friend db record
    $f = new StdClass;
    $f->ctime = db_format_timestamp(time());
    
    // notification info
    $n = new StdClass;
    $n->url = get_config('wwwroot') . 'user/view.php?id=' . $loggedinid;
    $n->users = array($user->id);
    $displayname = display_name($USER, $user);

    switch ($values['type']) {
    case 'add':
        $f->usr1 = $values['id'];
        $f->usr2 = $loggedinid;
        insert_record('usr_friend', $f);
        $n->subject = get_string('addedtofriendslistsubject');
        $n->message = get_string('addedtofriendslistmessage', 'mahara', $displayname, $displayname);
        break;
    case 'request':
        $f->owner     = $values['id'];
        $f->requester = $loggedinid;
        $f->reason    = $values['reason'];
        insert_record('usr_friend_request', $f);
        $n->subject = get_string('requestedfriendlistsubject');
        if (isset($values['reason']) && !empty($values['reason'])) {
            $n->message = get_string('requestedfriendlistmessagereason', 'mahara', $displayname) . $values['reason'];
        }
        else {
            $n->message = get_string('requestedfriendlistmessage', 'mahara', $displayname);
        }
        break;
    case 'remove':
        delete_records_select('usr_friend', '(usr1 = ? AND usr2 = ?) OR (usr2 = ? AND usr1 = ?)', 
                                array($userid, $loggedinid, $userid, $loggedinid));
        $n->subject = get_string('removedfromfriendslistsubject');
        if (isset($values['reason']) && !empty($values['reason'])) {
            $n->message = get_string('removedfromfriendslistmessage', 'mahara', $displayname) . $values['reason'];
        }
        else {
            $n->message = get_string('removedfromfriendslistmessage', 'mahara', $displayname);
        }
        break;
    case 'accept':
        if (isset($values['rejectsubmit']) && !empty($values['rejectsubmit'])) {
            delete_records('usr_friend_request', 'owner', $loggedinid, 'requester', $userid);
            $n->subject = get_string('friendrequestrejectedsubject');
            if (isset($values['rejectreason']) && !empty($values['rejectreason'])) {
                $n->message = get_string('friendrequestrejectedmessagereason', 'mahara', $displayname) . $values['rejectreason'];
            }
            else {
                $n->message = get_string('friendrequestrejectedmessage', 'mahara', $displayname);
            }
            $values['type'] = 'reject'; // for json reply message
        } 
        else {
            db_begin();
            delete_records('usr_friend_request', 'owner', $loggedinid, 'requester', $userid);
            $f->usr1 = $userid;
            $f->usr2 = $loggedinid;
            insert_record('usr_friend', $f);
            $n->subject = get_string('friendrequestacceptedsubject');
            $n->message = get_string('friendrequestacceptedmessage', 'mahara', $displayname, $displayname);
            db_commit();
        }
        break;
    }
    activity_occurred('maharamessage', $n);
Martyn Smith's avatar
Martyn Smith committed
632
633
634
635
636
637
638

    if ($form instanceof Pieform) {
        $form->json_reply(PIEFORM_OK, get_string('friendform' . $values['type'] . 'success', 'mahara', display_name($user)));
    }
    else {
        json_reply(false, get_string('friendform' . $values['type'] . 'success', 'mahara', display_name($user)));
    }
Penny Leach's avatar
Penny Leach committed
639
640
}

641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
/**
 * Unsuspends a user
 *
 * @param int $userid The ID of the user to unsuspend
 */
function unsuspend_user($userid) {
    $suspendedrec = new StdClass;
    $suspendedrec->id = $userid;
    $suspendedrec->suspendedcusr = null;
    $suspendedrec->suspendedreason = null;
    $suspendedrec->suspendedctime  = null;
    update_record('usr', $suspendedrec);

    $message = new StdClass;
    $message->users = array($userid);
    $message->subject = get_string('youraccounthasbeenunsuspended');
    $message->message = get_string('youraccounthasbeenunsuspendedtext');
    activity_occurred('maharamessage', $message);

    handle_event('unsuspenduser', $userid);
}

/**
 * Deletes a user
 *
 * @param int $userid The ID of the user to delete
 */
function delete_user($userid) {
    $deleterec = new StdClass;
    $deleterec->id = $userid;
    $deleterec->deleted = 1;
    update_record('usr', $deleterec);

    handle_event('deleteuser', $userid);
}

/**
 * Undeletes a user
 *
 * @param int $userid The ID of the user to undelete
 */
function undelete_user($userid) {
    $deleterec = new StdClass;
    $deleterec->id = $userid;
    $deleterec->deleted = 0;
    update_record('usr', $deleterec);

    handle_event('undeleteuser', $userid);
}

/**
 * Expires a user
 *
 * Nothing amazing needs to happen here, but this function is here for
 * consistency.
 *
 * This function is called when a user account is detected to be expired.
 * It is assumed that the account actually is expired.
 *
 * @param int $userid The ID of user to expire
 */
function expire_user($userid) {
    handle_event('expireuser', $userid);
}

/**
 * Unexpires a user
 *
 * @param int $userid The ID of user to unexpire
 */
function unexpire_user($userid) {
    handle_event('unexpireuser', $userid);
}

/**
 * Marks a user as inactive
 *
 * Nothing amazing needs to happen here, but this function is here for
 * consistency.
 *
 * This function is called when a user account is detected to be inactive.
 * It is assumed that the account actually is inactive.
 *
 * @param int $userid The ID of user to mark inactive
 */
function deactivate_user($userid) {
    handle_event('deactivateuser', $userid);
}

/**
 * Activates a user
 *
 * @param int $userid The ID of user to reactivate
 */
function activate_user($userid) {
    handle_event('activateuser', $userid);
}

Penny Leach's avatar
Penny Leach committed
739
?>