mirror of
https://github.com/maxpozdeev/mytinytodo.git
synced 2026-03-11 08:55:27 +00:00
+ setup will ask to select db type on first install and will overwrite config file
* changes in config file
This commit is contained in:
parent
991203fe84
commit
8a89b2845e
5 changed files with 121 additions and 25 deletions
|
|
@ -58,5 +58,40 @@ function _get($param,$defvalue = '')
|
|||
}
|
||||
}
|
||||
|
||||
function saveConfig($config)
|
||||
{
|
||||
$params = array(
|
||||
'db' => array('default'=>'sqlite', 'type'=>'s'),
|
||||
'mysql.host' => array('default'=>'localhost', 'type'=>'s'),
|
||||
'mysql.db' => array('default'=>'mytinytodo', 'type'=>'s'),
|
||||
'mysql.user' => array('default'=>'user', 'type'=>'s'),
|
||||
'mysql.password' => array('default'=>'', 'type'=>'s'),
|
||||
'lang' => array('default'=>'en', 'type'=>'s'),
|
||||
'password' => array('default'=>'', 'type'=>'s'),
|
||||
'allowread' => array('default'=>0, 'type'=>'i'),
|
||||
'smartsyntax' => array('default'=>1, 'type'=>'i'),
|
||||
'autotz' => array('default'=>1, 'type'=>'i'),
|
||||
'autotag' => array('default'=>1, 'type'=>'i'),
|
||||
'duedateformat' => array('default'=>1, 'type'=>'i'),
|
||||
'firstdayofweek' => array('default'=>1, 'type'=>'i'),
|
||||
'session' => array('default'=>'files', 'type'=>'s'),
|
||||
);
|
||||
|
||||
$s = '';
|
||||
foreach($params as $param=>$v)
|
||||
{
|
||||
$val = isset($config[$param]) ? $config[$param] : $v['default'];
|
||||
if($v['type']=='i') {
|
||||
$s .= "\$config['$param'] = ".(int)$val.";\n";
|
||||
}
|
||||
else {
|
||||
$s .= "\$config['$param'] = '".str_replace(array("\\","'"),array("\\\\","\\'"),$val)."';\n";
|
||||
}
|
||||
}
|
||||
$f = fopen('./db/config.php', 'w');
|
||||
if($f === false) throw new Exception("Error while saving config file");
|
||||
fwrite($f, "<?php\n\$config = array();\n$s?>");
|
||||
fclose($f);
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -3,8 +3,14 @@
|
|||
# Configuration goes here
|
||||
$config = array();
|
||||
|
||||
# Uncomment this line if you want to use Mysql, in format: array("host","login","password","database");
|
||||
#$config['mysql'] = array("localhost","user","password", "mytinytodo");
|
||||
# Database type: sqlite or mysql
|
||||
$config['db'] = 'sqlite';
|
||||
|
||||
# Specify these settings if you selected above to use Mysql
|
||||
$config['mysql.host'] = "localhost";
|
||||
$config['mysql.db'] = "mytinytodo";
|
||||
$config['mysql.user'] = "user";
|
||||
$config['mysql.password'] = "";
|
||||
|
||||
# Language pack
|
||||
$config['lang'] = "en";
|
||||
|
|
@ -13,9 +19,9 @@ $config['lang'] = "en";
|
|||
# or leave empty that everyone could read/write todolist
|
||||
$config['password'] = "";
|
||||
|
||||
# Restrict access for the others when password above is set:
|
||||
# "no" - No access, "read" - Read only
|
||||
$config['allow'] = "no";
|
||||
# Allow readonly access for the others when password above is set:
|
||||
# 0 - No access, 1 - Read only
|
||||
$config['allowread'] = 0;
|
||||
|
||||
# To disable smart syntax uncomment the line below
|
||||
#$config['smartsyntax'] = 0;
|
||||
|
|
|
|||
|
|
@ -11,10 +11,6 @@ require_once('./lang/class.default.php');
|
|||
require_once('./lang/'.$config['lang'].'.php');
|
||||
|
||||
$lang = new Lang();
|
||||
if(!$needAuth) $tabDisabled = '';
|
||||
elseif(!is_logged() && canAllRead()) $tabDisabled = ', selected:1, disabled: [0]';
|
||||
elseif(!is_logged()) $tabDisabled = ', disabled: [0,1]';
|
||||
else $tabDisabled = '';
|
||||
|
||||
$sort = 0;
|
||||
if(isset($_COOKIE['sort']) && $_COOKIE['sort'] != '') $sort = (int)$_COOKIE['sort'];
|
||||
|
|
|
|||
16
src/init.php
16
src/init.php
|
|
@ -6,23 +6,14 @@ require_once('./db/config.php');
|
|||
ini_set('display_errors', 'On');
|
||||
|
||||
# MySQL Database Connection
|
||||
if(isset($config['mysql']))
|
||||
if($config['db'] == 'mysql')
|
||||
{
|
||||
require_once('class.db.mysql.php');
|
||||
$db = new Database_Mysql;
|
||||
$db->connect($config['mysql'][0], $config['mysql'][1], $config['mysql'][2], $config['mysql'][3]);
|
||||
$db->connect($config['mysql.host'], $config['mysql.user'], $config['mysql.password'], $config['mysql.db']);
|
||||
$db->dq("SET NAMES utf8");
|
||||
}
|
||||
|
||||
# SQLite2 Database
|
||||
elseif(isset($config['sqlite']) && 2 == $config['sqlite'])
|
||||
|
||||
{
|
||||
require_once('class.db.sqlite.php');
|
||||
$db = new Database_Sqlite;
|
||||
$db->connect('./db/todolist.db');
|
||||
}
|
||||
|
||||
# SQLite3 (pdo_sqlite)
|
||||
else
|
||||
{
|
||||
|
|
@ -32,7 +23,6 @@ else
|
|||
}
|
||||
|
||||
|
||||
|
||||
$needAuth = (isset($config['password']) && $config['password'] != '') ? 1 : 0;
|
||||
if($needAuth)
|
||||
{
|
||||
|
|
@ -55,7 +45,7 @@ function canAllRead()
|
|||
{
|
||||
global $config;
|
||||
if(!isset($config['password']) || $config['password'] == '') return true;
|
||||
if(isset($config['allow']) && $config['allow'] == "read") return true;
|
||||
if(isset($config['allowread']) && $config['allowread']) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,23 @@
|
|||
Licensed under the GNU GPL v3 license. See file COPYRIGHT for details.
|
||||
*/
|
||||
|
||||
# Check old config file (prior v1.3)
|
||||
require_once('./db/config.php');
|
||||
if(!isset($config['db']))
|
||||
{
|
||||
if(isset($config['mysql'])) {
|
||||
$config['db'] = 'mysql';
|
||||
$config['mysql.host'] = $config['mysql'][0];
|
||||
$config['mysql.db'] = $config['mysql'][3];
|
||||
$config['mysql.user'] = $config['mysql'][1];
|
||||
$config['mysql.password'] = $config['mysql'][2];
|
||||
} else {
|
||||
$config['db'] = 'sqlite';
|
||||
}
|
||||
if(isset($config['allow']) && $config['allow'] == 'read') $config['allowread'] = 1;
|
||||
#saveConfig($config);
|
||||
}
|
||||
|
||||
require_once('./init.php');
|
||||
if($needAuth && !is_logged())
|
||||
{
|
||||
|
|
@ -16,18 +33,44 @@ $dbtype = ($dbclass == 'database_mysql') ? 'mysql' : 'sqlite';
|
|||
|
||||
$lastVer = '1.3';
|
||||
echo '<html><head><meta name="robots" content="noindex,nofollow"></head><body>';
|
||||
echo "<b>myTinyTodo v$lastVer Setup</b><br><br>";
|
||||
echo "<big><b>myTinyTodo v$lastVer Setup</b></big><br><br>";
|
||||
|
||||
# determine current installed version
|
||||
$ver = get_ver($db, $dbtype);
|
||||
|
||||
if(!$ver)
|
||||
{
|
||||
# install database
|
||||
if(!isset($_POST['install'])) {
|
||||
# Which DB to select
|
||||
if(!isset($_POST['installdb']) && !isset($_POST['install']))
|
||||
{
|
||||
exitMessage("<form method=post>Select database type to use:<br><br>
|
||||
<label><input type=radio name=installdb value=sqlite checked>SQLite</label><br><br>
|
||||
<label><input type=radio name=installdb value=mysql>MySQL</label><br>
|
||||
<table style=\"margin-left:30px\"><tr><td>Host:</td><td><input name=mysql_host value=localhost></td></tr>
|
||||
<tr><td>Database:</td><td><input name=mysql_db value=mytinytodo></td></tr>
|
||||
<tr><td>User:</td><td><input name=mysql_user value=user></td></tr>
|
||||
<tr><td>Password:</td><td><input type=password name=mysql_password></td></tr>
|
||||
</table><br><input type=submit value=' Next '></form>");
|
||||
}
|
||||
elseif(isset($_POST['installdb']))
|
||||
{
|
||||
# Save configuration
|
||||
$dbtype = ($_POST['installdb'] == 'mysql') ? 'mysql' : 'sqlite';
|
||||
$config['db'] = $dbtype;
|
||||
if($dbtype == 'mysql') {
|
||||
$config['mysql.host'] = _post('mysql_host');
|
||||
$config['mysql.db'] = _post('mysql_db');
|
||||
$config['mysql.user'] = _post('mysql_user');
|
||||
$config['mysql.password'] = _post('mysql_password');
|
||||
}
|
||||
if(!testConnect($error)) {
|
||||
exitMessage("Database connection error: $error");
|
||||
}
|
||||
saveConfig($config);
|
||||
exitMessage("This will create myTinyTodo database <form method=post><input type=hidden name=install value=1><input type=submit value=' Install '></form>");
|
||||
}
|
||||
|
||||
# install database
|
||||
if($dbtype == 'mysql')
|
||||
{
|
||||
try
|
||||
|
|
@ -202,6 +245,27 @@ function has_field_mysql($db, $table, $field)
|
|||
return false;
|
||||
}
|
||||
|
||||
function testConnect(&$error)
|
||||
{
|
||||
global $config;
|
||||
try {
|
||||
if($config['db'] == 'mysql')
|
||||
{
|
||||
require_once('class.db.mysql.php');
|
||||
$db = new Database_Mysql;
|
||||
$db->connect($config['mysql.host'], $config['mysql.user'], $config['mysql.password'], $config['mysql.db']);
|
||||
} else
|
||||
{
|
||||
if(false === $f = @fopen('./db/todolist.db', 'a+')) throw new Exception("database file is not readable/writable");
|
||||
else fclose($f);
|
||||
}
|
||||
} catch(Exception $e) {
|
||||
$error = $e->getMessage();
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
### 1.1-1.2 ##########
|
||||
function update_11_12($db, $dbtype)
|
||||
{
|
||||
|
|
@ -267,6 +331,11 @@ function update_task_tags($id, $tag_ids)
|
|||
### 1.2-1.3 ##########
|
||||
function update_12_13($db, $dbtype)
|
||||
{
|
||||
# update config
|
||||
global $config;
|
||||
saveConfig($config);
|
||||
|
||||
# and then db
|
||||
$db->ex("BEGIN");
|
||||
if($dbtype=='mysql')
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue