Cheetah
customFunctions.inc.php
Go to the documentation of this file.
1 <?php
2 
8 require_once(CH_DIRECTORY_PATH_INC . "db.inc.php");
9 require_once(CH_DIRECTORY_PATH_INC . "utils.inc.php");
10 require_once(CH_DIRECTORY_PATH_INC . "design.inc.php");
11 
19 function loginUser($sName, $sPassword, $bLogin = false)
20 {
24  $sField = $bLogin ? "NickName" : "ID";
25  $sId = getValue("SELECT `ID` FROM `Profiles` WHERE `" . $sField . "`='" . $sName . "' AND `Password`='" . $sPassword . "' LIMIT 1");
26 
27  return !empty($sId) ? TRUE_VAL : FALSE_VAL;
28 }
29 
36 function loginAdmin($sLogin, $sPassword)
37 {
42  //--- Stanalone version.
43  //global $sAdminLogin;
44  //global $sAdminPassword;
45  //$bResult = $sLogin == $sAdminLogin && $sPassword == $sAdminPassword ? TRUE_VAL : FALSE_VAL;
46 
47  //--- Cheetah version.
48  $sName = getValue("SELECT `NickName` FROM `Profiles` WHERE `NickName`='$sLogin' AND `Password`='$sPassword' AND (`Role` & 2) LIMIT 1");
49  $bResult = !empty($sName) ? TRUE_VAL : FALSE_VAL;
50  //end of changes
51 
52  return $bResult;
53 }
54 
55 
61 function getUserInfo($sId, $bNick = false)
62 {
67 
68  //get info by ID on these fields
69  $sNick = "";
70  $sSex = "";
71  $sAge = "0";
72  $sDesc = "";
73  $sPhoto = "";
74  $sProfile = "";
75 
76  //You should change this query to retrieve user's data correctly
77  $sWherePart = ($bNick ? "`NickName`" : "`ID`") . " = '" . $sId . "'";
78  $aUser = getArray("SELECT * FROM `Profiles` WHERE " . $sWherePart . " LIMIT 1");
79 
85  $oBaseFunctions = ch_instance("ChBaseFunctions");
86  $sSex = !empty($aUser['Sex']) ? $aUser['Sex'] : "male";
87  $sPhoto = $oBaseFunctions->getMemberAvatar($sId);
88  if(empty($sPhoto))
89  $sPhoto = $sSex == "male" ? $sManImageUrl : $sWomanImageUrl;
90  $sNick = $GLOBALS['oFunctions']->getUserTitle($sId);
91  $sAge = isset($aUser['DateOfBirth']) ? getAge($aUser['DateOfBirth']) : "25";
92  $sDesc = $GLOBALS['oFunctions']->getUserInfo($sId);
93 
94  $sProfile = getParam('enable_modrewrite') == "on" ? $sRootURL . $aUser['NickName'] : $sProfileUrl . "?ID=" . $sId;
95 
100  return array("id" => (int)$aUser["ID"], "nick" => $sNick, "sex" => $sSex, "age" => $sAge, "desc" => $sDesc, "photo" => $sPhoto, "profile" => $sProfile);
101 }
102 
107 function getAge($sDob)
108 {
109  $aDob = explode('-', $sDob);
110  $iDobYear = $aDob[0];
111  $iDobMonth = $aDob[1];
112  $iDobDay = $aDob[2];
113  $iAge = date('Y') - $iDobYear;
114  if($iDobMonth > date('m'))
115  $iAge--;
116  else if($iDobMonth == date('m') && $iDobDay > date('d'))
117  $iAge--;
118  return $iAge;
119 }
120 
127 function searchUser($sValue, $sField = "ID")
128 {
129  if($sField == "ID")
130  $sField = "ID";//you migth change this value on your user's ID column name
131  else
132  $sField = "NickName";//you migth change this value on your user's nick column name
133 
134  //Search for user and type result of this search
135  $sId = getValue("SELECT `ID` FROM `Profiles` WHERE `" . $sField . "` = '" . $sValue . "' LIMIT 1");
136  return $sId;
137 }
138 
144 function getFriends($sId)
145 {
146  $aUsers = array();
147  $rResult = getResult("SELECT `Profile` FROM `sys_friend_list` WHERE `ID` = '" . $sId . "' AND `Check` = 1 UNION SELECT `ID` FROM `sys_friend_list` WHERE `Profile` = '" . $sId . "' AND `Check` = 1");
148  while($aUser = $rResult->fetch()) $aUsers[] = $aUser['Profile'];
149  return $aUsers;
150 }
$sSex
$sSex
Definition: browse.php:24
loginAdmin
loginAdmin($sLogin, $sPassword)
Definition: customFunctions.inc.php:36
$sRootURL
$sRootURL
Definition: header.inc.php:38
php
getValue
getValue($sQuery)
Definition: db.inc.php:59
$sWomanImageUrl
$sWomanImageUrl
Definition: header.inc.php:81
$sPassword
$sPassword
Definition: actions.inc.php:10
getUserInfo
getUserInfo($sId, $bNick=false)
Definition: customFunctions.inc.php:61
getParam
getParam($sParamName, $bUseCache=true)
Definition: db.inc.php:130
$sManImageUrl
$sManImageUrl
Definition: header.inc.php:82
ch_instance
ch_instance($sClassName, $aParams=array(), $aModule=array())
Definition: utils.inc.php:1264
global
if(!defined("GLOBAL_MODULE")) define("GLOBAL_MODULE" global
Definition: header.inc.php:25
$bResult
$bResult
Definition: get_file.php:11
searchUser
searchUser($sValue, $sField="ID")
Definition: customFunctions.inc.php:127
$aUser
$aUser
Definition: profiles.inc.php:74
$sId
$sId
Definition: actions.inc.php:8
getFriends
getFriends($sId)
Definition: customFunctions.inc.php:144
$sProfileUrl
$sProfileUrl
Definition: header.inc.php:99
$sNick
$sNick
Definition: actions.inc.php:9
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
$sDesc
$sDesc
Definition: actions.inc.php:21
loginUser
loginUser($sName, $sPassword, $bLogin=false)
Definition: customFunctions.inc.php:19
getArray
getArray($sQuery)
Definition: db.inc.php:52
$sName
$sName
Definition: ChWsbAdminTools.php:853
getAge
getAge($sDob)
Definition: customFunctions.inc.php:107
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10
$sAge
$sAge
Definition: browse.php:25
getResult
getResult($sQuery)
Definition: db.inc.php:45