View Single Post
Old 10-01-2008, 10:22   #5 (permalink)
PoeT4eva41
rock n' roller
 
PoeT4eva41's Avatar
 
Join Date: Jul 2007
Location: Yerevan, Armenia
Posts: 37
Send a message via ICQ to PoeT4eva41 Send a message via MSN to PoeT4eva41 Send a message via Skype™ to PoeT4eva41
I comment commonly in php and js. Html not so. I comment even if it's my project. I like commenting .

PHP Code:
/**
     * Functions.php
     * Last change: 18.11.07
     */
    
    /**
     * Function to get error ids and messages from database
     *
     * @param string $var
     * @param string $return
     * @return string
     */
    
    
function getError($var$return='value')
    {
        
$rst mysql_query("SELECT * FROM `languages_errors` WHERE `var` = '".$var."' AND `language` = '".$GLOBALS['selected_language']."'");
        
$row mysql_fetch_assoc($rst);
        return 
$row[$return];
    }

    
/**
     * 
     * Function to get information about registered users. 
     * $return can be "all". It will return array with all options of user.
     * if $userid is null, then $userid = logged user id :).
     * It also return a user type 0, when $return = type and no user logged
     *
     * @param string $return
     * @param integer $userid
     * @return string
     * 
     */

    
function useropt($return$userid='')
    {
    
        if (!
$userid)
        {
            
$rst mysql_query("SELECT `user` FROM `users_sessions` WHERE `session` = '".session_id()."'");
            
$row mysql_fetch_array($rst);
            
            
$userid $row['user'];
        }
        elseif (!
is_numeric($userid))
        {
            return 
false;
        }
    
        
$rst mysql_query("SELECT * FROM `users` WHERE `id` = '".$userid."'");
        
$row mysql_fetch_assoc($rst);
        if (
mysql_affected_rows())
        {
            if (
$return == 'all')
            {
                return 
$row;
            }
            else
            {
                return 
$row[$return];
            }
        }
        else
        {
            if ((!
$userid) && ($return == 'type'))
            {
                return 
0;
            }
            else
            {
                return 
false;
            }
        }
        
    }
    
    
/**
     * This function returns logged user permissions
     *
     * @param string $permission
     */
    
    
function permission($permission)
    {
        
        
// Usertype
        
$rst mysql_query("SELECT `type` FROM `users` WHERE `id` = '".useropt('id')."'");
        if (
mysql_affected_rows())
        {
            
$row mysql_fetch_assoc($rst);
            
$usertype $row['type'];
        }
        else 
        {
            
$usertype 0;
        }
        
        
// Permission
        
$rst mysql_query("SELECT `value` FROM `usertype_permissions` WHERE `usertype` = '".$usertype."' AND `permission` = '".$permission."'");
        
        
// If there is an information about this permission, return value, else return 1.
        
if (mysql_affected_rows())
        {
            
$row mysql_fetch_assoc($rst);
            return 
$row['value'];
        }
        else 
        {
            return 
1;
        }
        
    } 
That's an example of my code
  Reply With Quote