khanat-code-old/code/web/public_php/admin/functions_auth.php

136 lines
2.9 KiB
PHP
Raw Normal View History

2010-05-06 00:08:41 +00:00
<?php
/*
2014-09-06 18:59:21 +00:00
* THIS FILE SHOULD ONLY INCLUDE AUTHENTIFICATION RELATED FUNCTIONS
*/
2010-05-06 00:08:41 +00:00
function nt_auth_set_logging_count($user_id)
{
global $db;
2014-09-05 23:40:37 +00:00
$sql = "UPDATE ". NELDB_USER_TABLE ." SET user_logged_count=user_logged_count+1,user_logged_last=". time() ." WHERE user_id=". (int)$user_id;
2010-05-06 00:08:41 +00:00
$db->sql_query($sql);
}
function nt_auth_load_user($nelid)
{
global $db;
$data = null;
2014-09-05 23:40:37 +00:00
$sql = "SELECT * FROM ". NELDB_USER_TABLE ." LEFT JOIN ". NELDB_GROUP_TABLE ." ON (user_group_id=group_id) WHERE user_id=". (int)$nelid;
2010-05-06 00:08:41 +00:00
if ($result = $db->sql_query($sql))
{
if ($db->sql_numrows($result))
{
$data = $db->sql_fetchrow($result);
}
}
return $data;
}
function nt_auth_get_group_name($group_id)
{
global $db;
2014-09-05 23:40:37 +00:00
$sql = "SELECT user_name FROM ". NELDB_USER_TABLE ." WHERE user_id=". (int)$group_id;
2010-05-06 00:08:41 +00:00
if ($result = $db->sql_query($sql))
{
if ($db->sql_numrows($result))
{
$row = $db->sql_fetchrow($result);
return $row['user_name'];
}
}
return null;
}
2014-09-06 18:59:21 +00:00
function nt_auth_check_login($user, $passwd)
2010-05-06 00:08:41 +00:00
{
global $db;
$data = null;
2014-09-05 23:40:37 +00:00
$user = $db->sql_escape_string(trim($user));
2010-05-06 00:08:41 +00:00
$passwd = md5(trim($passwd));
$sql = "SELECT * FROM ". NELDB_USER_TABLE ." LEFT JOIN ". NELDB_GROUP_TABLE ." ON (user_group_id=group_id) WHERE user_name='". $user ."' AND user_password='". $passwd ."' AND user_active=1 AND group_active=1";
if ($result = $db->sql_query($sql))
{
if ($db->sql_numrows($result))
{
$data = $db->sql_fetchrow($result);
}
}
return $data;
}
function nt_auth_load_login()
{
global $tpl;
2014-09-06 18:59:21 +00:00
$tpl->assign('tool_login_title', 'Login');
2010-05-06 00:08:41 +00:00
$tpl->display('index_login.tpl');
}
2014-09-06 18:56:06 +00:00
function nt_auth_start_session()
2010-05-06 00:08:41 +00:00
{
2014-09-06 18:56:06 +00:00
global $NEL_SETUP_SESSION;
2014-09-06 18:59:21 +00:00
if (isset($NEL_SETUP_SESSION) && ($NEL_SETUP_SESSION))
{
2014-09-06 18:56:06 +00:00
return;
}
2010-05-06 00:08:41 +00:00
session_name(NELTOOL_SESSIONID);
session_cache_limiter('nocache');
session_start();
2014-09-06 18:56:06 +00:00
header("Expires: Mon, 01 May 2000 06:00:00 GMT");
2014-09-06 18:59:21 +00:00
header("Last-Modified: ". gmdate("D, d M Y H:i:s") ." GMT");
2014-09-06 18:56:06 +00:00
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
2010-05-06 00:08:41 +00:00
}
2014-09-06 18:56:06 +00:00
function nt_auth_stop_session()
2010-05-06 00:08:41 +00:00
{
2014-09-06 18:56:06 +00:00
global $NEL_SETUP_SESSION;
2014-09-06 18:59:21 +00:00
if (isset($NEL_SETUP_SESSION) && ($NEL_SETUP_SESSION))
{
2014-09-06 18:56:06 +00:00
return;
}
2010-05-06 00:08:41 +00:00
global $NELTOOL;
2014-09-06 18:56:06 +00:00
foreach($NELTOOL['SESSION_VARS'] as $key => $val)
{
unset($NELTOOL['SESSION_VARS'][$key]);
}
2010-05-06 00:08:41 +00:00
}
2014-09-06 18:59:21 +00:00
function nt_auth_set_session_var($name, $value)
2010-05-06 00:08:41 +00:00
{
2014-09-06 18:56:06 +00:00
global $NELTOOL;
2010-05-06 00:08:41 +00:00
2014-09-06 18:56:06 +00:00
$NELTOOL['SESSION_VARS'][$name] = $value;
2010-05-06 00:08:41 +00:00
}
function nt_auth_get_session_var($name)
{
2014-09-06 18:56:06 +00:00
global $NELTOOL;
2010-05-06 00:08:41 +00:00
2014-09-06 18:56:06 +00:00
if (isset($NELTOOL['SESSION_VARS'][$name])) return $NELTOOL['SESSION_VARS'][$name];
return null;
2010-05-06 00:08:41 +00:00
}
2014-09-06 18:56:06 +00:00
function nt_auth_unset_session_var($name)
2010-05-06 00:08:41 +00:00
{
2014-09-06 18:56:06 +00:00
global $NELTOOL;
2010-05-06 00:08:41 +00:00
2014-09-06 18:56:06 +00:00
unset($NELTOOL['SESSION_VARS'][$name]);
2010-05-06 00:08:41 +00:00
}
2014-09-05 23:40:37 +00:00
?>