get(md5('CMP-USER-TABLE'),'MEM'); if($UT[0]){ $this->userTable = $UT[1]; $UPT = $cacher->get(md5('CMP-USER-PROFILE-TABLE'),'MEM'); if($UPT[0]){ $this->userProfileTable = $UPT[1]; }else{ $this->p_error(0,'Error with getting user profile table from the APC cache system'); } }else{ // ok it is not in the cache time to query // it from the database. $dbSlinger = new dbSlinger(); $sql = 'SELECT * FROM ' . DB_NAME . '.user'; $DBQ = $dbSlinger->db_query($sql,"MYFETCHASC"); if($DBQ[0]){ $uData = $DBQ[1]; $uTable = array(); $upTable = array(); $uTable['time'] = time() + (CACHE_TIME); $upTable['time'] = time() + (CACHE_TIME); for($i=0;$iadd(md5('CMP-USER-TABLE'),$uTable,'MEM',CACHE_TIME); if($addIt[0]){ // ok we now need to add our user profile table to // our system cache. We will store it into memcache $addIt = $cacher->add(md5('CMP-USER-PROFILE-TABLE'),$upTable,'MEM',CACHE_TIME); if($addIt[0]){ $this->userTable = $uTable; $this->userProfileTable = $upTable; }else{ $this->publicError = "Sorry, there was an error please try your request again"; } }else{ // error with storing data into system cache $this->publicError = "Sorry, there was an error , please try your request again"; } }else{ $this->p_error(0,"Error building userTable the data base, check database error logs"); $this->publicError = "Sorry, there was an error , please try your request again"; } } // our captcha table we will store into APC $CT = $cacher->get(md5('CMP-CAPTCHA-TABLE'),'APC'); if($CT[0]){ $this->capTable = $CT[1]; }else{ $Go = $this->buildCap(); if($Go[0]){ $addIt = $cacher->add(md5('CMP-CAPTCHA-TABLE'),$this->capTable,'APC',CACHE_TIME); } } // our form table we will store into APC. $FT = $cacher->get(md5('CMP-FORM-TABLE'),'APC'); if($FT[0]){ $this->formTable = $FT[1]; }else{ $Go = $this->buildForms(); if($Go[0]){ $addIt = $cacher->add(md5('CMP-FORM-TABLE'),$this->formTable,'APC',CACHE_TIME); } } } function userSignUp($userData){ /* ----------------------------------------- Our function to manage users regestration sign up. It Will go trough a step process to make sure the current user name is not already taken and or that the submited user email is not already in the system. userData will be a build array with the following setup userData [userName] = Users Name [passWord] = user password (md5) [email] = User Info [MySpace] = MySpace URL -----------------------------------------*/ $pass = 0; $fail = ''; $userData['userName'] = addslashes($userData['userName']); $userData['passWord'] = addslashes($userData['passWord']); $userData['email'] = addslashes($userData['email']); $userData['fName'] = addslashes($userData['fName']); $userData['MySpace'] = ''; $dbSlinger = new dbSlinger(1,1); $sql = 'SELECT uname,email FROM ' . DB_NAME . '.user WHERE uname = "' . $userData['userName'] . '" OR email = "' . $userData['email'] . '"'; $DBQ = $dbSlinger->db_query($sql,"MYFETCHASC"); if($DBQ[0]){ // we have a result. // time to check to see if they are valid $UN = $DBQ[1][0]['uname']; $UE = $DBQ[1][0]['email']; if(!empty($UN)){ $pass = 0; $fail = 'uname'; }else{ $pass = 1; } if($pass){ if(!empty($UE)){ $pass = 0; $fail = 'email'; } } }else{ $pass = 1; } if($pass){ // ok it passed our user name and email check // we will insert the user info into the database . // before we do that we need to collect the new BlogID // linksID and BlogID $sql = 'SELECT MAX(BINID)+1,MAX(BlogID)+1,MAX(linksID)+1 FROM ' . DB_NAME . '.user'; $DBQ = $dbSlinger->db_query($sql,"MYFETCHALL"); if($DBQ[0]){ $newBINID = $DBQ[1][0]; $newBlogID = $DBQ[1][1]; $newLinksID = $DBQ[1][2]; if(empty($newBINID) && empty($newBlogID) && empty($newLinksID)){ // if all data is returned null // then its a net set of data // set all to one by default $newBINID = 1; $newBlogID = 1; $newLinksID = 1; } if(empty($newBINID)){ $pass = 0; $fail = 'BINID'; } if($pass){ if(empty($newBlogID)){ $pass = 0; $fail = 'BlogID'; } } if($pass){ if(empty($newLinksID)){ $pass = 0; $fail = 'LinksID'; } } }else{ $pass = 0; $fail = 'DB'; } if($pass){ // ok we have all of our new data // time to insert it into the database $sql = 'INSERT INTO ' . DB_NAME . '.user SET uname = "' . $userData['userName'] . '", dob = "' . $userData['dob'] . '", pword = "' . $userData['passWord'] . '", name = "' . $userData['fName'] . '", email="' . $userData['email'] . '", MSURL = "' . $userData['MySpace'] . '"'; $sql .= ', BINID = \'' . $newBINID . '\', BlogID = \'' . $newBlogID . '\', linksID = \'' . $newLinksID . '\''; $DBQ = $dbSlinger->db_query($sql,"DBINSERT"); if($DBQ[0]){ // ok we got our new user // time to send activation email $userID = $dbSlinger->lastID; $this->sendActivationEmail($userID,$userData['email']); return array(1,1); }else{ // error with inserting new user into the database? $this->p_error(0,"Error with adding new user. check DB logs"); return array(0,"Sorry we could not process this account. Please try again later."); } }else{ // ok there was an error with trying to // collect to new data. switch($fail){ case 'BINID': $this->p_error(0,"Error BINID was empty, check sql results on: " . $sql); return array(0,"Sorry we could not process this account. Please try again later."); break; case 'BlogID': $this->p_error(0,"Error blogID was empty, check sql results on: " . $sql); return array(0,"Sorry we could not process this account. Please try again later."); break; case 'LinksID'; $this->p_error(0,"Error linksID was empty, check sql results on: " . $sql); return array(0,"Sorry we could not process this account. Please try again later."); break; case 'DB'; $this->p_error(0,"Error with running SQL Query on community->userSignUp(). Check DB Logs"); return array(0,"Sorry we could not process this account. Please try again later."); break; } } }else{ switch($fail){ case "uname": return array(0,"Sorry, but this user name or email is already taken, Please try another"); break; case "email": return array(0,"Sorry , but this the suplied email address is already in use"); break; } } } function sendActivationEmail($userID,$userEmail){ /* ----------------------------------------- Our function to send a new user the activation email. To activate there account. -----------------------------------------*/ // to generate our email we will open up a template // file and use that as our template draft to send // our email file . $userEmail = stripslashes($userEmail); $pass = 1; $template = TEMPLATE_DIR . 'email.html'; $fo = @fopen($template,'r'); if($fo){ @flock($fo,LOCK_EX); $tempContent = @fread($fo,filesize($template)); if(!$tempContent){ // error with reading template file. $pass = 0; $this->p_error(0,"Error with reading content from teplate: " . $template); } @flock($fo,LOCK_UN); @fclose($fo); }else{ // error with opening template file $pass = 0; $this->p_error(0,"Error with opening template file. Template: " . $template); } if($pass){ // ok we have our template content. // we will simply just replace our key // with a md5 has of the userID // Key = [USER-HASH] $tempContent = str_replace('[USER-ID]',$userID,$tempContent); $tempContent = str_replace('[USER-HASH]',md5($userEmail),$tempContent); // prepare our email $subject = ACTIVATION_SUBJECT; $to = $userEmail; $headers = "From: do-not-reply@custommyspaceprofiles.com\r\n"; // send our email if(mail($to,$subject,$tempContent,$headers)){ // successfully sent email }else{ // error with sending email $this->p_error(0,"Error with sending activation email to:" . $userEmail); } } } function activateAccount($userID,$hash){ /* ----------------------------------------- Function to activate account in the database. We will check the user id supplied with the md5 hash of the users email, if both check out activat account -----------------------------------------*/ // we will first check the userTable cache // to see if the user is in the cache yet if($this->userTable[$userID]['uname']){ // ok good the user is in the cache. // just check the md5 email from cache. if($hash == md5($this->userTable[$userID]['email'])){ // ok link is valid time to update // the database and activate account. $dbSlinger = new dbSlinger(); $sql = 'UPDATE ' . DB_NAME . '.user SET activated = \'1\' WHERE id = \'' . $userID . '\''; $DBQ = $dbSlinger->db_query($sql); if($DBQ[0]){ // ok we are good to go return array(1,1); }else{ // error with updating account info . $this->p_error(0,"Error with updating activation field for user:" . $userID . " check DB log"); return array(0,"Sorry there was an error while trying to activate your account. Please try again later"); } }else{ // ok link is not valid return array(0,"Sorry, but that is not a valid activation"); } }else{ // ok user is not in cache yet. // will check from database. $dbSlinger = new dbSlinger(); $sql = 'SELECT email FROM ' . DB_NAME . '.user WHERE id = \'' . $userID . '\''; $DBQ = $dbSlinger->db_query($sql,"MYFETCHASC"); if($DBQ[0]){ $email = $DBQ[1][0]['email']; if($hash == md5($email)){ // ok link is valid time to update // the database and activate account. $sql = 'UPDATE ' . DB_NAME . '.user SET activated = \'1\' WHERE id = \'' . $userID . '\''; $DBQ = $dbSlinger->db_query($sql); if($DBQ[0]){ // ok we are good to go return array(1,1); }else{ // error with updating account info . $this->p_error(0,"Error with updating activation field for user:" . $userID . " check DB log"); return array(0,"Sorry there was an error while trying to activate your account. Please try again later"); } }else{ // ok link is not valid return array(0,"Sorry, but that is not a valid activation"); } }else{ // error with getting user email $this->p_error(0,"Error with getting users email address from the database for activation. Check DB logs"); return array(0,"Sorry, but we could not activate your account succesfully."); } } } function userLogIn($userName,$password){ /* -------------------------------------------- Function to handle user login transactions $password will be md5 hashed before it is submited to function -------------------------------------------*/ $userName = addslashes($userName); $dbSlinger = new dbSlinger(1,1); $sql = 'SELECT id,pword FROM ' . DB_NAME . '.user WHERE uname = \'' . $userName . '\''; $DBQ = $dbSlinger->db_query($sql,"MYFETCHASC"); if($DBQ[0]){ if($password == $DBQ[1][0]['pword']){ return array(1,$DBQ[1][0]['id']); }else{ return array(0,"Sorry, but you have entered a invalid username and or password"); } }else{ $this->p_error(0,"Error with getting user password for " . $userName . " Check DB logs"); return false; } } function userUpdateInfo($userData){ /* -------------------------------------------- Function to update the user info table in the database. $userData is assoicated array of data to update; Will NOT update userName password or email. -------------------------------------------*/ if(!empty($userData)){ if(!empty($_SESSION['userID'])){ $userData['name'] = addslashes($userData['userName'],ENT_QUOTES); $userData['profession'] = addslashes($userData['profession'],ENT_QUOTES); $userData['bio'] = htmlentities($userData['bio']); $userData['MSURL'] = htmlentities($userData['MSURL']); $dbSlinger = new dbSlinger(1,1); $sql = 'UPDATE ' . DB_NAME . '.user SET '; $keys = array_keys($userData); for($i=0;$idb_query($sql); if($DBQ[0]){ // ok updated the info succesfully return array(1,"Updated information succesfully"); }else{ $this->p_error(0,"Error with updating user information, SQL:" . $sql); return array(0,"Sorry, there was an error while trying to update your information. Please try again later"); } }else{ return array(0,"Sorry you must be logged in for this"); } }else{ return array(0,"Sorry, supplied data was empty"); } } function userChangeEmail($newEmail){ /* -------------------------------------------- Function to change users email addy. We will update that user info then de-activate the account and re-send a confirmation email. -------------------------------------------*/ if(!empty($newEmail)){ $dbSlinger = new dbSlinger(); $sql = 'UPDATE ' . DB_NAME . '.user SET email = \'' . addslashes($newEmail,ENT_QUOTES) . '\', activated= 0 WHERE id = \'' . $_SESSION['userID'] . '\''; $DBQ = $dbSlinger->db_query($sql); if($DBQ[0]){ // ok updated the account successfully // time to send activation again . $this->sendActivationEmail($_SESSION['userID'],$newEmail); return array(1,1); }else{ $this->p_error(0,"Error witih updating user email address. "); return array(0,"Sorry, there was an error while trying to update email address"); } }else{ // suplied email was empty return array(0,"Sorry, there was an error while trying to update email address try again"); } } function userChangePW($newPW,$oldPW){ /* -------------------------------------------- Function to change the user's password. pretty obvious -------------------------------------------*/ if(!empty($newPW)){ if($oldPW == $_SESSION['pword']){ // ok it checks out time to update $dbSlinger = new dbSlinger(); $sql = 'UPDATE ' . DB_NAME . '.user SET pword = "' . $newPW . '" WHERE id = \'' . $_SESSION['userID'] .'\''; $DBQ = $dbSlinger->db_query($sql); if($DBQ[0]){ // updated password successfully $_SESSION['pword'] = $newPW; return array(1,'Updated password succesfully'); }else{ $this->p_error(0,"Error with updating users password, check DB logs"); return array(0,"Sorry, there was an error while trying to udpate your password"); } }else{ return array(0,"Incorrect password"); } }else{ // new passowrd was empty } } function buildCap(){ /* -------------------------------------------- Function to get our captcha data from the db and store it into the cap array. -------------------------------------------*/ $dbSlinger = new dbSlinger(); $sql = 'SELECT * FROM ' . DB_NAME . '.captcha'; $DBQ = $dbSlinger->db_query($sql,"MYFETCHASC"); if($DBQ[0]){ // ok we have our data time to return it $this->capTable = $DBQ[1]; return array(1,1); }else{ // error with getting data from db $this->p_error(0,"Error with getting captcha data from database, check sql logs"); return array(0,"Error with building captcha table"); } } function buildForms(){ /* -------------------------------------------- Function to get our form dataout of the db and store it into the formTable array. -------------------------------------------*/ $dbSlinger = new dbSlinger(); $sql = 'SELECT * FROM ' . DB_NAME . '.forms'; $DBQ = $dbSlinger->db_query($sql,"MYFETCHASC"); if($DBQ[0]){ for($i=0;$iformTable[$DBQ[1][$i]['id']]['formKeys'] = $DBQ[1][$i]['formKeys']; $this->formTable[$DBQ[1][$i]['id']]['formHTML'] = $DBQ[1][$i]['formHTML']; } return array(1,1); }else{ $this->p_error(0,"Error with building form data from database, check sql logs"); return array(0,"Error with building form table"); } } function formBuilder($formID,$keyData = array()){ /* ----------------------------------------- Our functio to produce forms build from our formTable templates. There will be a set of key tags that are replaced with data and re-rendered for the final HTML produced form. $keyData will be an asc array that will contain the key name and value. Example: keyData ['var'] = value ['var2'] = value2 -----------------------------------------*/ // first have to get our data //$formKeys = $this->formTable[$formID]['formKeys']; // $formHTML = html_entity_decode($this->formTable[$formID]['formHTML']); // once we have our data time to break out our // formKeys into an array //$arrayKeys = split(','$formKeys); } function accountNav(){ /* -------------------------------------------- Function to spit out the navagation for login. this should be in a template format, Will update this at a later time. -------------------------------------------*/ if($this->showLogin){ echo ''; }else{ echo '
'; echo '
'; echo '
'; echo '
'; echo ' Welcome,
'; echo ' ' . $_SESSION['uname'] . ''; echo '
'; echo '
'; echo ' ' . $_SESSION['uname'] . ''; }else{ echo md5('DEFAULT-MICRO') . '.jpg" border="0" alt = "' . $_SESSION['uname'] . '"/>'; } echo '
'; echo '
'; echo ' View Your Profile | Blog
'; echo '
'; echo ' Profile Views: ' . $this->userTable[$_SESSION['userID']]['views'] . '
'; echo ' Blog Comments: ' . $blah . '
'; echo '
'; echo '
'; echo '
'; echo '
'; echo '
    '; echo '
  • My Profile
  • '; echo '
  • My Blog
  • '; echo '
  • My Favorites
  • '; echo '
  • Account Settings
  • '; echo '
'; echo '
'; echo '
'; echo '
'; echo '
'; } } function updateUserTable(){ return $this->userTable; } function p_error($err,$sql = ""){ switch($err){ case 0: // custom error $err = "0 - " . date("m-j-y") . " Custom Error: " . $sql; write_error("COMMUNITY",$err); break; default: break; } } } ?>