<?php
require_once('database-connect.php');
class ProfileDisplay /* case insensitive */
{
/* functions generally have prefix: ShowProfile
* variables generally have prefix: Show
* to avoid confusion
*/
var $Title;
var $ProfileName;
var $ProfileTagline;
var $PrsaarURL;
var $PrsaarConnectURL;
var $ConnectURL;
var $ProfileTypes;
var $ShowIdentity;
var $ShowDOB;
var $ShowCategory;
var $ShowLink;
var $ShowScratch;
var $ShowFriend;
var $ShowQuestionCount;
var $ShowAnswer;
var $ShowAnswerByID;
var $ShowBlock;
var $DC;
function ProfileDisplay()
{
$DC = new DatabaseConnect;
//define title same as profile-name
$this->ProfileName = $DC->Result("SELECT * FROM ".PR_DATABASE_PREFIX."config WHERE config_name = 'profile_name'");
$this->Title = $this->ProfileName[0]['config_value'].' › powered by Prsaar Colour. ';
$this->ProfileName = $this->ProfileName[0]['config_value'];
$this->PrsaarURL = PR_URL;
$this->PrsaarConnectURL = $DC->Result("SELECT * FROM ".PR_DATABASE_PREFIX."config WHERE config_name = 'prsaar_connect_url'");
$this->PrsaarConnectURL = $this->PrsaarConnectURL[0]['config_value'];
$this->ConnectURL = $this->PrsaarConnectURL; //backward compatibility
$this->ProfileTagline = $DC->Result("SELECT * FROM ".PR_DATABASE_PREFIX."config WHERE config_name = 'profile_tagline'");
$this->ProfileTagline = $this->ProfileTagline[0]['config_value'];
$this->ProfileTypes = $this->GetProfileTypes();
$this->DC = new DatabaseConnect; //more easy this way;
}
function GetProfileTypes() //profile types and profile categories are same, shows all the profile categories in array
{
$DC = new DatabaseConnect;
$ProfileTypes[0] = 'identity';
$ProfileType = $DC->Result("SELECT DISTINCT profile_category FROM ".PR_DATABASE_PREFIX."profile");
if($ProfileType == false) return $this->ProfileTypes = false;
foreach( $ProfileType as $Key => $KeyValue)
{
$ProfileTypes[] = $KeyValue['profile_category'];
}
return $ProfileTypes;
}
function ShowProfileIdentity()
{
//tell if user wants to display his age
$ShowDOB = $this->DC->Select("config", "config_name", "show_dob");
$ShowDOB = $ShowDOB[0]['config_value'];
$this->ShowDOB = $ShowDOB;
$Identity = $this->DC->Select("identity");
if($Identity == false) return $this->ShowIdentity = false;
foreach($Identity as $Key => $KeyValue)
{
$this->ShowIdentity[$Key]['name'] = $KeyValue['identity_name'];
$this->ShowIdentity[$Key]['value'] = $KeyValue['identity_value'];
}
return $this->ShowIdentity;
}
function ShowProfileType($Type) //contents of a particular profile category
{
$DC = new DatabaseConnect;
$Category = $DC->Result("SELECT * FROM ".PR_DATABASE_PREFIX."profile WHERE profile_category = '$Type' AND profile_status = 'show'");
if($Category == false) return $this->ShowCategory = false;
foreach($Category as $Key => $KeyValue)
{
$this->ShowCategory[$Key]['name'] = $KeyValue['profile_name'];
$this->ShowCategory[$Key]['value'] = $KeyValue['profile_value'];
}
return $this->ShowCategory;
}
function ShowProfileLink()
{
$DC = new DatabaseConnect;
$Link = $DC->Result("SELECT * FROM ".PR_DATABASE_PREFIX."link");
if($Link == false) return $this->ShowLink = false;
foreach($Link as $Key => $KeyValue)
{
$LinkCategory = $KeyValue['link_category'];
$this->ShowLink[$LinkCategory][$Key]['id'] = $KeyValue['link_id'];
$this->ShowLink[$LinkCategory][$Key]['name'] = $KeyValue['link_name'];
$this->ShowLink[$LinkCategory][$Key]['url'] = $KeyValue['link_url'];
}
return $this->ShowLink;
}
function ShowProfileFriend()
{
$DC = new DatabaseConnect;
$Friend = $DC->Result("SELECT * FROM ".PR_DATABASE_PREFIX."friend");
if($Friend == false) return $this->ShowFriend = false;
//yet to complete
}
function ShowProfileScratch($Limit = 0) //shows all the scratches
{
$DC = new DatabaseConnect;
$Limit = intval($Limit);
if($Limit == 0)
{
$Scratch = $DC->Result("SELECT * FROM ".PR_DATABASE_PREFIX."scratch WHERE scratch_status = 'okay' ORDER BY scratch_time DESC");
}
else
{
$Scratch = $DC->Result("SELECT * FROM ".PR_DATABASE_PREFIX."scratch WHERE scratch_status = 'okay' ORDER BY scratch_time DESC LIMIT $Limit");
}
if($Scratch == false) return $this->ShowScratch = false;
foreach($Scratch as $Key => $KeyValue)
{
$this->ShowScratch[$Key]['id'] = $KeyValue['scratch_id'];
$this->ShowScratch[$Key]['user_name'] = $KeyValue['scratch_user_name'];
$this->ShowScratch[$Key]['user_url'] = $KeyValue['scratch_user_url'];
$this->ShowScratch[$Key]['value'] = $KeyValue['scratch_value'];
$this->ShowScratch[$Key]['time'] = $KeyValue['scratch_time'];
}
return $this->ShowScratch;
}
function ShowProfileQuestionCount() //counts questions ['total'] ['toanswer'] ['answered']
{
$Count_toanswer = $this->DC->Result("SELECT count(*) FROM ".PR_DATABASE_PREFIX."askme WHERE askme_status = 'toanswer'");
$Count_answered = $this->DC->Result("SELECT count(*) FROM ".PR_DATABASE_PREFIX."askme WHERE askme_status = 'answered'");
$Count_total = $this->DC->Result("SELECT count(*) FROM ".PR_DATABASE_PREFIX."askme");
if($Count_total == false) $this->ShowQuestionCount['total'] = 0;
else $this->ShowQuestionCount['total'] = $Count_total[0]['count(*)'];
if($Count_toanswer == false) $this->ShowQuestionCount['toanswer'] = 0;
else $this->ShowQuestionCount['toanswer'] = $Count_toanswer[0]['count(*)'];
if($Count_answered == false) $this->ShowQuestionCount['answered'] = 0;
else $this->ShowQuestionCount['answered'] = $Count_answered[0]['count(*)'];
return $this->ShowQuestionCount;
}
function ShowProfileAnswer() //shows all answers
{
$Answer = $this->DC->Result("SELECT * FROM ".PR_DATABASE_PREFIX."askme ORDER BY askme_question_time DESC");
if( $Answer == false) return $this->ShowAnswer = false;
foreach($Answer as $Key => $KeyValue)
{
$this->ShowAnswer[$Key]['id'] = $KeyValue['askme_id'];
$this->ShowAnswer[$Key]['question'] = $KeyValue['askme_question'];
$this->ShowAnswer[$Key]['asker_name'] = $KeyValue['askme_asker_name'];
$this->ShowAnswer[$Key]['asker_url'] = $KeyValue['askme_asker_url'];
$this->ShowAnswer[$Key]['question_time'] = $KeyValue['askme_question_time'];
$this->ShowAnswer[$Key]['answer'] = $KeyValue['askme_answer'];
$this->ShowAnswer[$Key]['answer_time'] = $KeyValue['askme_answer_time'];
$this->ShowAnswer[$Key]['status'] = $KeyValue['askme_status'];
}
return $this->ShowAnswer;
}
function ShowProfileAnswerByID($ID=0) //shows a particular answer
{
$View = $this->DC->Result("SELECT * FROM ".PR_DATABASE_PREFIX."askme WHERE askme_id = '$ID'");
if($View == false) return $this->ShowAnswerByID = false;
foreach($View as $Key => $KeyValue)
{
$this->ShowAnswerByID['id'] = $KeyValue['askme_id'];
$this->ShowAnswerByID['question'] = $KeyValue['askme_question'];
$this->ShowAnswerByID['asker_name'] = $KeyValue['askme_asker_name'];
$this->ShowAnswerByID['asker_url'] = $KeyValue['askme_asker_url'];;
$this->ShowAnswerByID['question_time'] = $KeyValue['askme_question_time'];
$this->ShowAnswerByID['answer'] = $KeyValue['askme_answer'];
$this->ShowAnswerByID['answer_time'] = $KeyValue['askme_answer_time'];
$this->ShowAnswerByID['status'] = $KeyValue['askme_status'];
}
return $this->ShowAnswerByID;
}
function ShowProfileBlock()
{
$Blocks = $this->DC->Select('block', 'block_status', 'show');
if($Blocks == false) return $this->ShowBlock = false;
foreach($Blocks as $Key => $KeyValue)
{
$this->ShowBlock[$Key]['id'] = $KeyValue['block_id'];
$this->ShowBlock[$Key]['name'] = $KeyValue['block_name'];
$this->ShowBlock[$Key]['value'] = $KeyValue['block_value'];
$this->ShowBlock[$Key]['category'] = $KeyValue['block_category'];
}
return $this->ShowBlock;
}
}
//the profile-display object
$Display = new ProfileDisplay;
?>