<?php

// step 1: find out in what way this page was called (personal home, personal page, person overview)
// /		-> person overview, search, login
// /home.html	-> personal homepage, show=default|friends|fans|faned|comm|content
// /UID.html	-> page to user UID, show=default|friends|fans|faned|comm|content
// /invite.html	-> page to invite user
// /verify.html	-> page to enter verification code from email
// /edit.html	-> edit profile, initially create profile during signup
// /people.html	-> list people, add/remove/change friends, fan-status, bookmarks

require("../../include/_global.php");
require("../../include/_account.php");
require("../../include/_account.db");
require("../../include/_account.length");

$err=0;
$err=_connect_to_database();

$account[id]=0;
$account[systemlanguage]="en";

if($err==0) _check_auth();

require("../../include/_lang.". $account[systemlanguage]);
_print_html_head();
_print_html_nav();

if($err==0 && $_SERVER[PHP_SELF]=="/account/home.html" && $account[id]>0)
{
 // personal homepage
 // print (part of) friendlist, (part of) communities, (part of) content list, edit-link, ...

 _print_personal_subnav();

}
elseif($err==0 && preg_match("{^/account/[0-9]+[.]html$}",$_SERVER[PHP_SELF]))
{
 // page to user UID
 // print user profile|friends|fans|faned|comm|content according to privacy settings and "show" variable
 $uid=preg_replace("{^/account/([0-9]+)[.]html$}","\\1",$_SERVER[PHP_SELF]);
 if($account[id]!=0)
  _print_personal_subnav();

 // Print info about person $uid. General info, contact data, friends, communities, content, picture...

 _print_profile($uid);

}
elseif($err==0 && $_SERVER[PHP_SELF]=="/account/invite.html" && $account[id]>0)
{
 // page to invite user
 // print and evaluate invite form
 
 _print_personal_subnav();

 _evaluate_invite_form();

 _print_invite_form();
 
}
elseif($err==0 && $_SERVER[PHP_SELF]=="/account/verify.html")
{
 // page to enter verification code from email
 // print and evaluate code verification form

 if($_POST[code]!="")
 {
  _eval_blacklist_request();
 }
 else
 {
  _print_code_verification_form();
  _print_email_blacklist_form();
 }

}
elseif($err==0 && $_SERVER[PHP_SELF]=="/account/edit.html" && ($account[id]>0 || $_GET[signup]==1 || strlen($_POST[code])>1))
{
 // page to edit own profile
 // print and evaluate profile change form
 // decide if _print_personal_subnav() should be called after _edit_account_page()
 $page_init=$page; $page="";
 _edit_account_page();
 $page_edit=$page; $page="";
 if($account[id]!=0)
 {
  _print_personal_subnav();
 }
 $page=$page_init.$page.$page_edit;
}
elseif($err==0 && $_SERVER[PHP_SELF]=="/account/people.html" && $account[id]>0)
{
 // list people, add/remove/change friends, fan-status, bookmarks
 // print lists of people according to parameters in GET, evaluate requests for changes


}
elseif($err==0)
{
 // FIXME: should this be a "catch-all" or maybe use a redirect-page as such?
 // person overview, search, login
 if($account[id]==0)
 {_print_login_form();}
 else
 {$page.="FIXME: logout";}

}
elseif($err==1)
{
 // some error occured
 // FIXME: general error page - text should not be here
 $page.="<p>Something unexpected happened. Please try again later.</p>";
}

_print_html_footer();

print($page);

?>
