Page Menu
Home
Code
Search
Configure Global Search
Log In
Files
F391150
user.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Subscribers
None
user.php
View Options
<?php
/*
* User class
*
* 0.1 2010-01-27 00:33 Autogenerated by Pluton Scaffolding
*
* @package Zed
* @copyright Copyright (c) 2010, Dereckson
* @license Released under BSD license
* @version 0.1
*
*/
class
User
{
public
$id
;
public
$name
;
public
$password
;
public
$active
;
public
$actkey
;
public
$email
;
public
$regdate
;
/*
* Initializes a new instance
* @param int $id the primary key
*/
function
__construct
(
$id
=
null
)
{
if
(
$id
)
{
$this
->
id
=
$id
;
$this
->
load_from_database
();
}
}
/*
* Loads the object User (ie fill the properties) from the $_POST array
*/
function
load_from_form
()
{
if
(
array_key_exists
(
'name'
,
$_POST
))
$this
->
name
=
$_POST
[
'name'
];
if
(
array_key_exists
(
'password'
,
$_POST
))
$this
->
password
=
$_POST
[
'password'
];
if
(
array_key_exists
(
'active'
,
$_POST
))
$this
->
active
=
$_POST
[
'active'
];
if
(
array_key_exists
(
'actkey'
,
$_POST
))
$this
->
actkey
=
$_POST
[
'actkey'
];
if
(
array_key_exists
(
'email'
,
$_POST
))
$this
->
email
=
$_POST
[
'email'
];
if
(
array_key_exists
(
'regdate'
,
$_POST
))
$this
->
regdate
=
$_POST
[
'regdate'
];
}
/*
* Loads the object User (ie fill the properties) from the database
*/
function
load_from_database
()
{
global
$db
;
$sql
=
"SELECT * FROM "
.
TABLE_USERS
.
" WHERE user_id = '"
.
$this
->
id
.
"'"
;
if
(
!(
$result
=
$db
->
sql_query
(
$sql
))
)
message_die
(
SQL_ERROR
,
"Unable to query users"
,
''
,
__LINE__
,
__FILE__
,
$sql
);
if
(!
$row
=
$db
->
sql_fetchrow
(
$result
))
{
$this
->
lastError
=
"User unkwown: "
.
$this
->
id
;
return
false
;
}
$this
->
name
=
$row
[
'username'
];
$this
->
password
=
$row
[
'user_password'
];
$this
->
active
=
$row
[
'user_active'
];
$this
->
actkey
=
$row
[
'user_actkey'
];
$this
->
email
=
$row
[
'user_email'
];
$this
->
regdate
=
$row
[
'user_regdate'
];
return
true
;
}
/*
* Saves to database
*/
function
save_to_database
()
{
global
$db
;
$id
=
$this
->
id
?
"'"
.
$db
->
sql_escape
(
$this
->
id
)
.
"'"
:
'NULL'
;
$name
=
$db
->
sql_escape
(
$this
->
name
);
$password
=
$db
->
sql_escape
(
$this
->
password
);
$active
=
$db
->
sql_escape
(
$this
->
active
);
$actkey
=
$db
->
sql_escape
(
$this
->
actkey
);
$email
=
$db
->
sql_escape
(
$this
->
email
);
$regdate
=
$db
->
sql_escape
(
$this
->
regdate
);
//Updates or inserts
$sql
=
"REPLACE INTO "
.
TABLE_USERS
.
" (`user_id`, `username`, `user_password`, `user_active`, `user_actkey`, `user_email`, `user_regdate`) VALUES ($id, '$name', '$password', '$active', '$actkey', '$email', '$regdate')"
;
if
(!
$db
->
sql_query
(
$sql
))
{
message_die
(
SQL_ERROR
,
"Unable to save"
,
''
,
__LINE__
,
__FILE__
,
$sql
);
}
if
(!
$id
)
{
//Gets new record id value
$this
->
id
=
$db
->
sql_nextid
();
}
}
/*
* Updates the specified field in the database record
*/
function
save_field
(
$field
)
{
global
$db
;
if
(!
$this
->
id
)
{
message_die
(
GENERAL_ERROR
,
"You're trying to update a record not yet saved in the database"
);
}
$id
=
$db
->
sql_escape
(
$this
->
id
);
$value
=
$db
->
sql_escape
(
$this
->
$field
);
$sql
=
"UPDATE "
.
TABLE_USERS
.
" SET `$field` = '$value' WHERE user_id = '$id'"
;
if
(!
$db
->
sql_query
(
$sql
))
{
message_die
(
SQL_ERROR
,
"Unable to save $field field"
,
''
,
__LINE__
,
__FILE__
,
$sql
);
}
}
//Generates a unique user id
private
function
generate_id
()
{
global
$db
;
do
{
$this
->
id
=
rand
(
2001
,
5999
);
$sql
=
"SELECT COUNT(*) FROM "
.
TABLE_USERS
.
" WHERE user_id = $this->id LOCK IN SHARE MODE;"
;
if
(!
$result
=
$db
->
sql_query
(
$sql
))
{
message_die
(
SQL_ERROR
,
"Can't access users table"
,
''
,
__LINE__
,
__FILE__
,
$sql
);
}
$row
=
$db
->
sql_fetchrow
(
$result
);
}
while
(
$row
[
0
]);
}
//Fills password field with encrypted version of the specified clear password
public
function
set_password
(
$newpassword
)
{
$this
->
password
=
md5
(
$newpassword
);
}
//Checks if a login is available
public
static
function
is_available_login
(
$login
)
{
global
$db
;
$sql
=
"SELECT COUNT(*) FROM "
.
TABLE_USERS
.
" WHERE username LIKE '$login' LOCK IN SHARE MODE;"
;
if
(!
$result
=
$db
->
sql_query
(
$sql
))
{
message_die
(
SQL_ERROR
,
"Utilisateurs non parsable"
,
''
,
__LINE__
,
__FILE__
,
$sql
);
}
$row
=
$db
->
sql_fetchrow
(
$result
);
return
(
$row
[
0
]
?
false
:
true
);
}
//Gets username from specified e-mail
public
static
function
get_username_from_email
(
$mail
)
{
global
$db
;
$sql
=
"SELECT username FROM "
.
TABLE_USERS
.
" WHERE user_email LIKE '$mail' LOCK IN SHARE MODE;"
;
if
(!
$result
=
$db
->
sql_query
(
$sql
))
{
message_die
(
SQL_ERROR
,
"Utilisateurs non parsable"
,
''
,
__LINE__
,
__FILE__
,
$sql
);
}
if
(
$row
=
$db
->
sql_fetchrow
(
$result
))
{
return
$row
[
username
];
}
return
false
;
}
}
?>
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Feb 22, 20:21 (15 h, 45 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
21924
Default Alt Text
user.php (5 KB)
Attached To
rZEDHG ZedLegacy
Event Timeline
Log In to Comment