TVProjects top



TVProjects bottom
You are not registered.
Registration allows you to subscribe to projects, open projects, and more. Click here to register.

Website Source Code
<< Back

users.php

<?php
    
function update_member_of($id)
    {
        
$result mysql_query('SELECT `id`, `category`, `name`, `positions`, `staff` FROM `projects` WHERE `staff` LIKE \'%' $id '%\';');
        
$mem '';
        
        while (
$row mysql_fetch_assoc($result))
        {
            
$staff_ex explode(';'$row['staff']);
            
            foreach (
$staff_ex as $each_stuff)
            {
                
$part explode('-'$each_stuff);
                if (
$part[0] == $id)
                {
                    
$pos_ex explode(';'$row['positions']);
                    
                    if (
$mem != '')
                        
$mem .= chr(1);
                        
                    
$mem .= $row['category'] . chr(2) . $row['id'] . chr(2) . $row['name'] . chr(2) . $pos_ex[$part[1]];
                }
            }
        }
        
        
mysql_query('UPDATE `users` SET `member_of` = \'' db_escape($mem) . '\' WHERE `id` = ' $id ' LIMIT 1;');
    }
    
    function 
update_project_members($id)
    {
        
$result mysql_query('SELECT `staff` FROM `projects` WHERE `id` = ' $id ' LIMIT 1;');
        
$row mysql_fetch_row($result);
        
        
$staff_ex explode(';'$row[0]);
        foreach (
$staff_ex as $each_stuff)
        {
            
$part explode('-'$each_stuff);
            
update_member_of($part[0]);
        }
    }
    
    function 
get_user($id)
    {
        global 
$users$usernames;
        
        if (!isset(
$users[$id]))
        {
            
$result mysql_query('SELECT `name`, `username`, `password`, `subscriptions` FROM `users` WHERE `id` = ' $id ' LIMIT 1;');
            
            if (
mysql_num_rows($result) == 0)
                die(
'Error in get_user()!');
            
            
$row mysql_fetch_row($result);
            
$users[$id] = $row;
            
$usernames[strtolower($row[0])] = $id;
        }
        
        return 
$users[$id];
    }
    
    function 
get_id_by_username($username)
    {
        
$result mysql_query('SELECT `id` FROM `users` WHERE `username` = \'' db_escape($username) . '\' LIMIT 1;');
        
        if (
mysql_num_rows($result) == 0)
        {
            return 
false;
        }
        
        
$row mysql_fetch_row($result);
        return 
$row[0];
    }
    
    function 
update_logged()
    {
        global 
$logged_user$login_error$log_u$log_p$path;
        
        
$login_error false;
        
        if (isset(
$_POST['login_username']))
        {
            
$id get_id_by_username($_POST['login_username']);
            
            if (
$id)
            {
                if (
username_password_ok($idmd5($_POST['login_password'])))
                {
                    
setcookie('login_id'$id.'|'.md5($_POST['login_password']), time()+(60*60*24*30), $path);
                    
$logged_user $id;
                }
                else
                {
                    
$login_error true;
                    
$logged_user = -1;
                }
            }
            else
            {
                
$login_error true;
                
$logged_user = -1;
            }
            
            
$log_u $_POST['login_username'];
            
$log_p $_POST['login_password'];
        }
        else
        {
            if (isset(
$_COOKIE['login_id']))
            {
                
$login_details explode('|'$_COOKIE['login_id']);
                if (
username_password_ok($login_details[0], $login_details[1]))
                {
                    
$logged_user $login_details[0];
                    
setcookie('login_id'$_COOKIE['login_id'], time()+(60*60*24*30), $path);
                }
                else
                {
                    
$logged_user = -1;
                }
            }
            else
            {
                
$logged_user = -1;
            }
        }
    }
    
    function 
username_password_ok($id$password)
    {
        
$result mysql_query('SELECT `activating`, `new_email` FROM `users` WHERE `id` = \'' db_escape($id) . '\' AND `password` = \'' db_escape($password) . '\' LIMIT 1;');
        if (
mysql_num_rows($result) > 0)
        {
            
$row mysql_fetch_row($result);
            return ((
$row[0] == '') or (($row[0] != '') and ($row[1] != '')));
        }
        else
        {
            return 
false;
        }
    }
?>