File: api.user.inc.php

package info (click to toggle)
jffnms 0.8.3dfsg.1-2.1etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 4,928 kB
  • ctags: 5,050
  • sloc: php: 19,981; sh: 266; makefile: 91; perl: 52
file content (87 lines) | stat: -rw-r--r-- 2,622 bytes parent folder | download | duplicates (5)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?
/* This file is part of JFFNMS
 * Copyright (C) <2002-2005> Javier Szyszlican <javier@szysz.com>
 * This program is licensed under the GNU GPL, full terms in the LICENSE file
 */
    function user_add ($username) {

	$user_id = db_insert("auth", array("usern"=>$username));

	$query = "SELECT id, default_value FROM profiles_options WHERE use_default = 1"; //FIXME order
	$result = db_query($query) or die ("Query Filed - user_add() - profile - ".db_error()); 

	while ($row = db_fetch_array($result)) //add every default option to the user profile
	    profile_add_option($user_id,$row["id"]);

	return $user_id;
    }

    function user_get_id($username){
	if ($username) {
	    $query = "select id from auth where usern = '$username'";
	    $result = db_query($query) or die ("Query Failed - USER_GET_ID-1 - ".db_error());
	
	    if (db_num_rows($result)==1) {
		$row = db_fetch_array($result);
    		return $row["id"];
	    }
	}
	return false;
    }

    function user_get_username($user_id){
	if ($user_id > 0) {
	    $query = "select usern from auth where id = '$user_id'";
	    $result = db_query($query) or die ("Query Failed - USER_GET_USERNAME-1 - ".db_error());
	    $row = db_fetch_array($result);
	}
	return $row["usern"];
    }

    function user_del ($user_id){ 
	if ($user_id) {
	    foreach (profiles_list($user_id) as $option)  
		profile_del_option($user_id,$option[profile_option]); //delete all user profile options

	    foreach (triggers_users_list(NULL,$user_id) as $user) //delete all user triggers
	        triggers_users_del($user[id]);

	    if ((count(profiles_list($user_id)) == 0) && 
		(count(triggers_users_list(NULL,$user_id)) == 0) )
		return db_delete("auth",$user_id); //if everthing is ok delete the user
	    else 
		return FALSE;
	}	
    }

    function user_modify($user_id, $usern, $old_password, $new_password, $fullname, $router) {

	if ($new_password == $old_password) $passwd = $new_password;
	    else if (!empty($new_password)) $passwd = crypt($new_password);
		
	if (empty($router)) unset($router);
	if (empty($usern)) unset($usern);
	if (empty($passwd)) unset($passwd);
	
    	$user_fields = compact("fullname","usern","passwd","router");
		
	return db_update("auth",$user_id,$user_fields);
    }

    function users_list ($ids = NULL,$where_special = NULL) { 
	
	if (!is_array($where_special)) $where_special = array();

        return get_db_list(
	    "auth",
	    $ids, 
	    array(
	    "*",
	    "old_passwd"=>"passwd"),
	    array_merge(
	        array(array("id",">",1)),
	        $where_special), //where
	    array(array("usern","asc")) ); //order 
    }

?>