2009-08-27 12:48:09 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
require_once('common.php');
|
|
|
|
|
require_once('./db/config.php');
|
|
|
|
|
|
|
|
|
|
ini_set('display_errors', 'On');
|
|
|
|
|
|
2009-11-30 17:59:16 +00:00
|
|
|
if(!isset($config)) global $config;
|
|
|
|
|
Config::loadConfig($config);
|
|
|
|
|
unset($config);
|
|
|
|
|
|
2009-08-27 12:48:09 +00:00
|
|
|
# MySQL Database Connection
|
2009-11-30 17:59:16 +00:00
|
|
|
if(Config::get('db') == 'mysql')
|
2009-08-27 12:48:09 +00:00
|
|
|
{
|
|
|
|
|
require_once('class.db.mysql.php');
|
|
|
|
|
$db = new Database_Mysql;
|
2009-11-30 17:59:16 +00:00
|
|
|
$db->connect(Config::get('mysql.host'), Config::get('mysql.user'), Config::get('mysql.password'), Config::get('mysql.db'));
|
2009-08-27 12:48:09 +00:00
|
|
|
$db->dq("SET NAMES utf8");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# SQLite3 (pdo_sqlite)
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
require_once('class.db.sqlite3.php');
|
|
|
|
|
$db = new Database_Sqlite3;
|
|
|
|
|
$db->connect('./db/todolist.db');
|
|
|
|
|
}
|
2009-12-02 12:37:10 +00:00
|
|
|
$db->prefix = Config::get('prefix');
|
2009-08-27 12:48:09 +00:00
|
|
|
|
|
|
|
|
|
2009-11-30 17:59:16 +00:00
|
|
|
$needAuth = (Config::get('password') != '') ? 1 : 0;
|
2009-11-01 14:42:36 +00:00
|
|
|
if($needAuth && !isset($dontStartSession))
|
2009-08-27 12:48:09 +00:00
|
|
|
{
|
2009-11-30 17:59:16 +00:00
|
|
|
if(Config::get('session') == 'files')
|
2009-08-27 12:48:09 +00:00
|
|
|
{
|
|
|
|
|
session_save_path(realpath('./tmp/sessions/'));
|
|
|
|
|
ini_set('session.gc_maxlifetime', '1209600'); # 14 days session file minimum lifetime
|
|
|
|
|
ini_set('session.gc_probability', 1);
|
|
|
|
|
ini_set('session.gc_divisor', 10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ini_set('session.use_cookies', true);
|
|
|
|
|
ini_set('session.use_only_cookies', true);
|
|
|
|
|
session_set_cookie_params(1209600, substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '/') + 1)); #14 days session cookie lifetime
|
|
|
|
|
session_start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function is_logged()
|
|
|
|
|
{
|
|
|
|
|
if(!isset($_SESSION['logged']) || !$_SESSION['logged']) return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-13 12:38:55 +00:00
|
|
|
function timestampToDatetime($timestamp, $tz)
|
|
|
|
|
{
|
2009-11-30 17:59:16 +00:00
|
|
|
global $lang;
|
|
|
|
|
$format = Config::get('dateformat') .' '. (Config::get('clock') == 12 ? 'g:i A' : 'H:i');
|
2009-12-15 19:58:28 +00:00
|
|
|
return formatTime($format, $timestamp, $tz);
|
2009-12-15 14:49:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function formatTime($format, $timestamp=0, $tz=null)
|
|
|
|
|
{
|
|
|
|
|
global $lang;
|
|
|
|
|
if($timestamp == 0) $timestamp = time();
|
|
|
|
|
if(is_null($tz)) $tz = round(date('Z')/60);
|
2009-11-13 12:38:55 +00:00
|
|
|
$newformat = strtr($format, array('F'=>'%1', 'M'=>'%2'));
|
|
|
|
|
$adate = explode(',', gmdate('n,'.$newformat, $timestamp + $tz*60), 2);
|
|
|
|
|
$s = $adate[1];
|
|
|
|
|
if($newformat != $format)
|
|
|
|
|
{
|
|
|
|
|
$am = (int)$adate[0];
|
|
|
|
|
$ml = $lang->get('months_long');
|
|
|
|
|
$ms = $lang->get('months_short');
|
|
|
|
|
$F = $ml[$am-1];
|
|
|
|
|
$M = $ms[$am-1];
|
|
|
|
|
$s = strtr($s, array('%1'=>$F, '%2'=>$M));
|
|
|
|
|
}
|
|
|
|
|
return $s;
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-27 12:48:09 +00:00
|
|
|
?>
|