|
|
|
News id
|
50
|
Headline
|
functions.inc.php
|
Content
|
If you create this file in a folder called include, this file will be included in every page and the functions will be available. I've included like an example of this file with some functions that serve as an example of what it can be used for:<br /><br /><blockquote><br /><?php<br />error_reporting(E_ALL);<br />ini_set('display_errors','On');<br />define('APPROVAL_LEVEL_APPROVED',2);<br />define('APPROVAL_LEVEL_CONDITIONAL',1);<br />define('APPROVAL_LEVEL_NOT_APPROVED',0);<br /><br />define('APPROVAL_STATUS_APPROVED',2);<br />define('APPROVAL_STATUS_NOT_APPROVED',0);<br /><br />function isLoggedIn(){<br /> static $loggedIn = 0;<br /> if ( $loggedIn === 0 ){<br /> $user =& getUser();<br /> if ( $user ) $loggedIn = true;<br /> else $loggedIn = false;<br /> }<br /> return $loggedIn;<br />}<br /><br />function &getUser(){<br /> static $user = 0;<br /> if ( $user === 0 ){<br /> $auth =& Dataface_AuthenticationTool::getInstance();<br /> $user = $auth->getLoggedInUser();<br /> }<br /> return $user;<br />}<br /><br />// Checks whether the current user is an admin or not.<br />function isAdmin(){<br /> $user =& getUser();<br /> if ( !$user ) return false;<br /> return ($user->val('role') == 'ADMIN');<br />}<br /><br />function isBrokerCustomer(){<br /> $user =& getUser();<br /> if ( !$user ) return false;<br /> return ($user->val('cookedRole') == 'BROKER CUSTOMER');<br />}<br /><br />function getDealerID(){<br /> static $dealer_id = -1;<br /> $user =& getUser();<br /> if ( !$user){<br /> if ( $dealer_id == -1 ){<br /> $res = mysql_query("select company_id from companies where host_name='".addslashes($_SERVER['HTTP_HOST'])."' limit 1", df_db());<br /> if ( mysql_num_rows($res) == 0 ) $dealer_id = null;<br /> else list($dealer_id) = mysql_fetch_row($res);<br /> }<br /> return $dealer_id;<br /> }<br /> return $user->val('dealerID');<br />}<br /><br />function &getBrokerDealer(){<br /> static $bd = 0;<br /> if ( $bd === 0 ){<br /> $id = getDealerID();<br /> if ( $id ){<br /> $bd = df_get_record('companies', array('company_id'=>$id));<br /> }<br /> }<br /> return $bd;<br />}<br /><br />function isBrokerDealer(){<br /> $user =& getUser();<br /> if ( !$user ) return false;<br /> return ($user->val('cookedRole') == 'BROKER DEALER');<br />}<br /><br />function isCompanyOwner(){<br /> $user =& getUser();<br /> if ( !$user ) return false;<br /> return ($user->val('cookedRole') == 'COMPANY OWNER');<br />}<br /><br />function isCompanyRep(){<br /> $user =& getUser();<br /> if ( !$user ) return false;<br /> return ($user->val('cookedRole') == 'COMPANY REP');<br />}<br /><br />function getCompanyID(){<br /> $user =& getUser();<br /> if ( !$user ) return null;<br /> return $user->val('companyID');<br />}<br /><br />function &getCompany(){<br /> static $company = 0;<br /> if ($company === 0 ){<br /> $id = getCompanyID();<br /> if ( $id ){<br /> $company = df_get_record('companies', array('company_id'=>$id));<br /> }<br /> }<br /> return $company;<br />}<br /><br /><br />function off($date){<br /> $date = strtotime($date);<br /> $offset = (strftime("%j")+strftime("%Y")*365)-<br /> (strftime("%j",$date)+strftime("%Y",$date)*365);<br /> if ($offset>7){<br /> $offset = (strftime("%V")+strftime("%Y")*52)-<br /> (strftime("%V",$date)+strftime("%Y",$date)*52);<br /> $end=($offset!=0?($offset>1?$offset . " weeks ago":"a week ago"):"Today");<br /> } else<br /> $end=($offset!=0?($offset>1?"$offset days ago":"Yesterday"):"Today");<br /> return strftime("%A, %B %e, %Y",$date)." - ". $end;<br />}<br /></blockquote><br /><br />Here we have some common functions to help figure out what type of user is logged in.
|
Image
|
(Empty)
|
Date posted
|
Wed Apr 9 23:11:00 2008
|
Posted by
|
noreply@blogger.com (Fong Chun Chan)
|
Status
|
Approved
|
Categories
|
Blog
|
Source id
|
Fong's Blog
|
Source url
|
http://fongxataface.blogspot.com/2008/04/functionsincphp.html
|
|
|