Changeset 1011

Show
Ignore:
Timestamp:
03/07/07 17:18:40 (2 years ago)
Author:
ben
Message:

Implemented the user_delete function in userlib.php. You can now completely remove a user from the system in code. TODO: create the interface!

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • devel/lib/userlib.php

    r1006 r1011  
    303303    } 
    304304 
     305// USER DEATH ////////////////////////////////////////////////////////////////// 
     306 
     307    /** 
     308     * Delete a user. 
     309     * 
     310     * @uses $CFG 
     311     * @param integer $user_id  The unique ID of the user to delete. 
     312     * @return true|false Returns true if the user was deleted; false otherwise. 
     313     */ 
     314     function user_delete($user_id) { 
     315 
     316         global $CFG; 
     317 
     318         // Verify that the user exists 
     319         if ($user = get_record_sql("select * from {$CFG->prefix}users where ident = {$user_id}"))) { 
     320              
     321             // Call the event hook for all plugins to do their worst with the user's data 
     322             $user = plugin_hook("user","delete",$user); 
     323              
     324             // If all went well ... 
     325             if (!empty($user)) { 
     326                  
     327                 // Remove any icons and icon folders 
     328                 if ($icons = get_records_sql("select * from {$CFG->prefix}icons where owner = {$user->ident}")) { 
     329                     foreach($icons as $icon) { 
     330                         $filepath = $CFG->dataroot . "icons/" . substr($user->username,0,1) . "/" . $user->username . "/" . $icon->filename; 
     331                         @unlink($filepath); 
     332                     } 
     333                     @rmdir($filepath = $CFG->dataroot . "icons/" . substr($user->username,0,1) . "/" . $user->username . "/"); 
     334                 } 
     335                  
     336                 // Remove the user from the database! 
     337                 delete_records("users","ident",$user->ident); 
     338                 return true; 
     339 
     340             } 
     341              
     342             return false; 
     343         } 
     344 
     345     } 
     346     
    305347?>