<?
exit();
// Application Initialization File
//
// Version 1.0b

// Version 1.0b - First part update to syndlib.php3
// Version 1.0a - really uses config.php3
//              - renamed vars to prepend app
//              - Syndication Support
//
// Version 1.0 - uses config.php3
set_time_limit(0);
include "layoutelements.php3";
include "config.php3";
include "proflib.php3";
include "syndlib.php3";
$starttime=set_timer();
#	var gets &'d to determine output
#	0x01 = SQL
#	0x02 = objectform
#	0x04 = applib level
#	0x08 = SecureURLs
#	0x16 = Prepend safety
#	0x32 & up  - free for higher level stuff
$LIB_DIR='applib/interfaces';

#$IMAGE_PATH="/shop.tnug.com/images";
include "objform.php3";
#include "objwizard.php3";
#include "objnavbar.php3";
include "mysql.php3";
include "loglib.php3";
include "nroklib.php3";

//if (useringroup(array('adminsitrator'))) echo "obj[$obj] action[$action] id[$id] sid[$auth_sid]<br>\n";
if ($SECURE_URLS) {
$DEBUG_LEVEL+=8;
include "urlwrapper.php3";
}
//if (useringroup(array('adminsitrator'))) echo "obj[$obj] action[$action] id[$id] sid[$auth_sid]<br>\n";
$conn=sqlconn($SQL_APP_HOST,$SQL_APP_USR,$SQL_APP_PWD,$SQL_APP_DB);

header ('Last-Modified: '. gmstrftime("%b %d %Y %H:%M:%S GMT"));
header ('Expires: '. gmstrftime("%b %d %Y %H:%M:%S GMT", 1));
header ('Pragma: no-cache');
header ('Cache-Control: no-cache');

//ob_start();
if (!isset($NeuroOekakiUserid)) {
  mt_srand((double)microtime()*1000000);
  #$username=mt_rand(0,10000000);
  $username=uniqid('');
  sqlexec("insert into auth_users (username,lastvisit) values ('$username',now())");
  $id=sqlgetinsertid();
  if ($id==0) {
    echo "<h2>Just Ignore the error and reload</h2>";
  }
  # 232243200
  setcookie("NeuroOekakiUserid",$id,time()+3600*24*7*4*12);
  $NeuroOekakiUserid=$id;
  #echo "Welcome new visitor, Your unique id is $username<br>\n";
  //echo "Welcome new user<br>\n";
} else {
  #echo "Updating cookie<br>\n";
  setcookie("NeuroOekakiUserid",$NeuroOekakiUserid,time()+3600*24*7*4*12);
  $anfo=getnfo($NeuroOekakiUserid);
  // FIXME: user can fake cookie and become admin
  $username=$anfo['username'];
  $password=$anfo['password'];
  $rpp=$anfo['rpp'];
}

if ($obj=="picture" && $action=="edit") {
header ('Last-Modified: '. gmstrftime("%b %d %Y %H:%M:%S GMT"));
header ('Expires: '. gmstrftime("%b %d %Y %H:%M:%S GMT", 1));
header ('Pragma: no-cache');
header ('Cache-Control: no-cache');
}

if (($obj=="comment") && ($action=="ins")) {
setnfo($NeuroOekakiUserid,$name,$email,$homepage);
}

if (($obj=="picture") && ($action=="upd")) {
setnfo($NeuroOekakiUserid,$name,$email,$homepage);
}

if (!$ADMIN_ONLY) {
if (empty($auth_sid)) {
$auth_username=$username;
$auth_password=$password;
#$auth_username='anonymous';
#$auth_password='anonymous';
}
}

if ($USE_AUTH) {
  include "authwrapper.php3";
} else {
  include "noauthwrapper.php3";
}

// Auth overrides cookie
if (loggedin()) {
setcookie("NeuroOekakiUserid",$myauth['id'],time()+3600*24*7*4*12);
$NeuroOekakiUserid=$myauth['id'];
#echo "Switch Cookie to user [".$myauth['id']."]<br>\n";
}
//ob_end_flush();
#echo "DBG user[$username] CookeID[$NeuroOekakiUserid] AuthID[".$myauth['id']."]<br>\n";
//echo "asdf";

include "apptemplate.php3";
include "session.php3";
$ses=new session($conn,15,"app",255);

/*
if (useringroup(array('administrator'))) {
echo "<H1>DEBUG MODE(for admins)</H1><h3>Right now, Neuro's
fixing/adding new stuff. this doesn't affect the public site</h3>";
$DEBUG_LEVEL+=1;
$diff=get_timer($starttime);
echo "<h6>Took [$diff] secs</h6>\n";
#print_r($GLOBALS);
echo "obj[$obj] action[$action] id[$id] sid[$auth_sid] str[$str]<br>\n";
}
*/

if (!$NOLAYOUT) {
$file="cache/".date('Y-m-d').'.'.$myauth['id'].'.cache';
if (file_exists($file)) {
  $fp=fopen($file,"r");
  fpassthru($fp);
  fclose($fp);
} else {
  // clean old files
  $myaid=$myauth['id'];
  $yesterday=date('Y-m-d',mktime(0,0,0,date('m'),date('d')-1,date('Y')));
  if(useringroup(array('administrator'))) {
    echo "removing *.$myaid.cache & $yesterday*.cache<br>\n";
  }
  `rm -f cache/*.$myaid.cache`;
  `rm -f cache/$yesterday*.cache`;
  // create new one
  ob_start();
  appheader();
  $data=ob_get_flush();
  $fp=fopen($file,"w");
  fputs($fp,$data);
  fclose($fp);
}
}
?>
