PHP CodeStandard update

- all if/while/for/etc blocks have brackets on same line
- functions have brackets on new line
- no blocks without brackets
- all code starts on col 0 and there are no tab intends anymore

off: came case for classes and class methods
ignore: _ prefix functions (we can't change that anymore)
This commit is contained in:
2018-03-15 17:38:33 +09:00
parent 5226fbcfc3
commit 7d42256a30
42 changed files with 11623 additions and 12013 deletions

View File

@@ -1,194 +1,195 @@
<?
$DEBUG_ALL_OVERRIDE = 0; // set to 1 to debug on live/remote server locations
$DEBUG_ALL = 1;
$PRINT_ALL = 1;
$DB_DEBUG = 1;
$DEBUG_ALL_OVERRIDE = 0; // set to 1 to debug on live/remote server locations
$DEBUG_ALL = 1;
$PRINT_ALL = 1;
$DB_DEBUG = 1;
if ($DEBUG_ALL)
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
if ($DEBUG_ALL) {
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
}
define('USE_DATABASE', true);
// sample config
require("config.inc");
// set session name
DEFINE('SET_SESSION_NAME', EDIT_SESSION_NAME);
define('USE_DATABASE', true);
// sample config
require("config.inc");
// set session name
DEFINE('SET_SESSION_NAME', EDIT_SESSION_NAME);
// session_name(EDIT_SESSION_NAME);
// session_start();
// basic class test file
foreach (array ('Login', 'Admin.Backend') as $class)
_spl_autoload('Class.'.$class.'.inc');
// basic class test file
foreach (array ('Login', 'Admin.Backend') as $class) {
_spl_autoload('Class.'.$class.'.inc');
}
$lang = 'en_utf8';
$lang = 'en_utf8';
DEFINE('LOG_FILE_ID', 'classTest');
$login = new login($DB_CONFIG[LOGIN_DB], $lang);
// init with standard
DEFINE('LOG_FILE_ID', 'classTest');
$login = new login($DB_CONFIG[LOGIN_DB], $lang);
// init with standard
// $basic = new db_io($DB_CONFIG[MAIN_DB]);
$basic = new AdminBackend($DB_CONFIG[MAIN_DB], $lang);
$basic->db_info(1);
$basic = new AdminBackend($DB_CONFIG[MAIN_DB], $lang);
$basic->db_info(1);
// set + check edit access id
$edit_access_id = 3;
print "ACL UNIT: ".print_r(array_keys($login->acl['unit']), 1)."<br>";
print "ACCESS CHECK: ".$login->login_check_edit_access($edit_access_id)."<br>";
if ($login->login_check_edit_access($edit_access_id))
$basic->edit_access_id = $edit_access_id;
else
$basic->edit_access_id = $login->acl['unit_id'];
// set + check edit access id
$edit_access_id = 3;
print "ACL UNIT: ".print_r(array_keys($login->acl['unit']), 1)."<br>";
print "ACCESS CHECK: ".$login->login_check_edit_access($edit_access_id)."<br>";
if ($login->login_check_edit_access($edit_access_id)) {
$basic->edit_access_id = $edit_access_id;
} else {
$basic->edit_access_id = $login->acl['unit_id'];
}
// $basic->debug('SESSION', $basic->print_ar($_SESSION));
print "<html><head><title>TEST CLASS</title><head>";
print "<body>";
print '<form method="post" name="loginlogout">';
print '<a href="javascript:document.loginlogout.login_logout.value=\'Logou\';document.loginlogout.submit();">Logout</a>';
print '<input type="hidden" name="login_logout" value="">';
print '</form>';
print "<html><head><title>TEST CLASS</title><head>";
print "<body>";
print '<form method="post" name="loginlogout">';
print '<a href="javascript:document.loginlogout.login_logout.value=\'Logou\';document.loginlogout.submit();">Logout</a>';
print '<input type="hidden" name="login_logout" value="">';
print '</form>';
// print the debug core vars
print "DEBUG OUT: ".$basic->debug_output."<br>";
print "ECHO OUT: ".$basic->echo_output."<br>";
print "PRINT OUT: ".$basic->print_output."<br>";
print "NOT DEBUG OUT: ".$basic->debug_output_not."<br>";
print "NOT ECHO OUT: ".$basic->echo_output_not."<br>";
print "NOT PRINT OUT: ".$basic->print_output_not."<br>";
print "DEBUG OUT ALL: ".$basic->debug_output_all."<br>";
print "ECHO OUT ALL: ".$basic->echo_output_all."<br>";
print "PRINT OUT ALL: ".$basic->print_output_all."<br>";
// print the debug core vars
print "DEBUG OUT: ".$basic->debug_output."<br>";
print "ECHO OUT: ".$basic->echo_output."<br>";
print "PRINT OUT: ".$basic->print_output."<br>";
print "NOT DEBUG OUT: ".$basic->debug_output_not."<br>";
print "NOT ECHO OUT: ".$basic->echo_output_not."<br>";
print "NOT PRINT OUT: ".$basic->print_output_not."<br>";
print "DEBUG OUT ALL: ".$basic->debug_output_all."<br>";
print "ECHO OUT ALL: ".$basic->echo_output_all."<br>";
print "PRINT OUT ALL: ".$basic->print_output_all."<br>";
print "CALLER BACKTRACE: ".$basic->get_caller_method()."<br>";
$basic->debug('SOME MARK', 'Some error output');
print "CALLER BACKTRACE: ".$basic->get_caller_method()."<br>";
$basic->debug('SOME MARK', 'Some error output');
print "EDIT ACCESS ID: ".$basic->edit_access_id."<br>";
print "EDIT ACCESS ID: ".$basic->edit_access_id."<br>";
// print "ACL: <br>".$basic->print_ar($login->acl)."<br>";
$basic->debug('ACL', "ACL: ".$basic->print_ar($login->acl));
$basic->debug('ACL', "ACL: ".$basic->print_ar($login->acl));
// print "DEFAULT ACL: <br>".$basic->print_ar($login->default_acl_list)."<br>";
// print "DEFAULT ACL: <br>".$basic->print_ar($login->default_acl_list)."<br>";
// $result = array_flip(array_filter(array_flip($login->default_acl_list), function ($key) { if (is_numeric($key)) return $key; }));
// print "DEFAULT ACL: <br>".$basic->print_ar($result)."<br>";
// DEPRICATED CALL
// DEPRICATED CALL
// $basic->adbSetACL($login->acl);
while ($res = $basic->db_return("SELECT * FROM max_test"))
{
print "TIME: ".$res['time']."<br>";
}
while ($res = $basic->db_return("SELECT * FROM max_test")) {
print "TIME: ".$res['time']."<br>";
}
$status = $basic->db_exec("INSERT INTO foo (test) VALUES ('FOO TEST ".time()."') RETURNING test");
print "DIRECT INSERT STATUS: $status | PRIMARY KEY: ".$basic->insert_id." | PRIMARY KEY EXT: ".print_r($basic->insert_id_ext, 1)."<br>";
print "DIRECT INSERT PREVIOUS INSERTED: ".print_r($basic->db_return_row("SELECT foo_id, test FROM foo WHERE foo_id = ".$basic->insert_id), 1)."<br>";
$basic->db_prepare("ins_foo", "INSERT INTO foo (test) VALUES ($1)");
$status = $basic->db_execute("ins_foo", array('BAR TEST '.time()));
print "PREPARE INSERT STATUS: $status | PRIMARY KEY: ".$basic->insert_id." | PRIMARY KEY EXT: ".print_r($basic->insert_id_ext, 1)."<br>";
print "PREPARE INSERT PREVIOUS INSERTED: ".print_r($basic->db_return_row("SELECT foo_id, test FROM foo WHERE foo_id = ".$basic->insert_id), 1)."<br>";
// returning test with multiple entries
$status = $basic->db_exec("INSERT INTO foo (test) VALUES ('FOO TEST ".time()."') RETURNING test");
print "DIRECT INSERT STATUS: $status | PRIMARY KEY: ".$basic->insert_id." | PRIMARY KEY EXT: ".print_r($basic->insert_id_ext, 1)."<br>";
print "DIRECT INSERT PREVIOUS INSERTED: ".print_r($basic->db_return_row("SELECT foo_id, test FROM foo WHERE foo_id = ".$basic->insert_id), 1)."<br>";
$basic->db_prepare("ins_foo", "INSERT INTO foo (test) VALUES ($1)");
$status = $basic->db_execute("ins_foo", array('BAR TEST '.time()));
print "PREPARE INSERT STATUS: $status | PRIMARY KEY: ".$basic->insert_id." | PRIMARY KEY EXT: ".print_r($basic->insert_id_ext, 1)."<br>";
print "PREPARE INSERT PREVIOUS INSERTED: ".print_r($basic->db_return_row("SELECT foo_id, test FROM foo WHERE foo_id = ".$basic->insert_id), 1)."<br>";
// returning test with multiple entries
// $status = $basic->db_exec("INSERT INTO foo (test) values ('BAR 1 ".time()."'), ('BAR 2 ".time()."'), ('BAR 3 ".time()."') RETURNING foo_id");
$status = $basic->db_exec("INSERT INTO foo (test) values ('BAR 1 ".time()."'), ('BAR 2 ".time()."'), ('BAR 3 ".time()."') RETURNING foo_id, test");
print "DIRECT MULTIPLE INSERT STATUS: $status | PRIMARY KEYS: ".print_r($basic->insert_id, 1)." | PRIMARY KEY EXT: ".print_r($basic->insert_id_ext, 1)."<br>";
// no returning, but not needed ;
$status = $basic->db_exec("INSERT INTO foo (test) VALUES ('FOO; TEST ".time()."');");
print "DIRECT INSERT STATUS: $status | PRIMARY KEY: ".$basic->insert_id." | PRIMARY KEY EXT: ".print_r($basic->insert_id_ext, 1)."<br>";
$status = $basic->db_exec("INSERT INTO foo (test) values ('BAR 1 ".time()."'), ('BAR 2 ".time()."'), ('BAR 3 ".time()."') RETURNING foo_id, test");
print "DIRECT MULTIPLE INSERT STATUS: $status | PRIMARY KEYS: ".print_r($basic->insert_id, 1)." | PRIMARY KEY EXT: ".print_r($basic->insert_id_ext, 1)."<br>";
// no returning, but not needed ;
$status = $basic->db_exec("INSERT INTO foo (test) VALUES ('FOO; TEST ".time()."');");
print "DIRECT INSERT STATUS: $status | PRIMARY KEY: ".$basic->insert_id." | PRIMARY KEY EXT: ".print_r($basic->insert_id_ext, 1)."<br>";
# db write class test
$table = 'foo';
print "TABLE META DATA: ".$basic->print_ar($basic->db_show_table_meta_data($table))."<br>";
$primary_key = ''; # unset
$db_write_table = array ('test', 'string_a', 'number_a', 'some_bool');
# db write class test
$table = 'foo';
print "TABLE META DATA: ".$basic->print_ar($basic->db_show_table_meta_data($table))."<br>";
$primary_key = ''; # unset
$db_write_table = array ('test', 'string_a', 'number_a', 'some_bool');
// $db_write_table = array ('test');
$object_fields_not_touch = array ();
$object_fields_not_update = array ();
$data = array ('test' => 'BOOL TEST SOMETHING '.time(), 'string_a' => 'SOME TEXT', 'number_a' => 5);
$primary_key = $basic->db_write_data_ext($db_write_table, $primary_key, $table, $object_fields_not_touch, $object_fields_not_update, $data);
print "Wrote to DB tabel $table and got primary key $primary_key<br>";
$data = array ('test' => 'BOOL TEST ON '.time(), 'string_a' => '', 'number_a' => 0, 'some_bool' => 1);
$primary_key = $basic->db_write_data_ext($db_write_table, $primary_key, $table, $object_fields_not_touch, $object_fields_not_update, $data);
print "Wrote to DB tabel $table and got primary key $primary_key<br>";
$data = array ('test' => 'BOOL TEST OFF '.time(), 'string_a' => null, 'number_a' => null, 'some_bool' => 0);
$primary_key = $basic->db_write_data_ext($db_write_table, $primary_key, $table, $object_fields_not_touch, $object_fields_not_update, $data);
print "Wrote to DB tabel $table and got primary key $primary_key<br>";
$data = array ('test' => 'BOOL TEST UNSET '.time());
$primary_key = $basic->db_write_data_ext($db_write_table, $primary_key, $table, $object_fields_not_touch, $object_fields_not_update, $data);
print "Wrote to DB tabel $table and got primary key $primary_key<br>";
$object_fields_not_touch = array ();
$object_fields_not_update = array ();
$data = array ('test' => 'BOOL TEST SOMETHING '.time(), 'string_a' => 'SOME TEXT', 'number_a' => 5);
$primary_key = $basic->db_write_data_ext($db_write_table, $primary_key, $table, $object_fields_not_touch, $object_fields_not_update, $data);
print "Wrote to DB tabel $table and got primary key $primary_key<br>";
$data = array ('test' => 'BOOL TEST ON '.time(), 'string_a' => '', 'number_a' => 0, 'some_bool' => 1);
$primary_key = $basic->db_write_data_ext($db_write_table, $primary_key, $table, $object_fields_not_touch, $object_fields_not_update, $data);
print "Wrote to DB tabel $table and got primary key $primary_key<br>";
$data = array ('test' => 'BOOL TEST OFF '.time(), 'string_a' => null, 'number_a' => null, 'some_bool' => 0);
$primary_key = $basic->db_write_data_ext($db_write_table, $primary_key, $table, $object_fields_not_touch, $object_fields_not_update, $data);
print "Wrote to DB tabel $table and got primary key $primary_key<br>";
$data = array ('test' => 'BOOL TEST UNSET '.time());
$primary_key = $basic->db_write_data_ext($db_write_table, $primary_key, $table, $object_fields_not_touch, $object_fields_not_update, $data);
print "Wrote to DB tabel $table and got primary key $primary_key<br>";
# async test queries
# async test queries
/* $basic->db_exec_async("SELECT test FROM foo, (SELECT pg_sleep(10)) as sub WHERE foo_id IN (27, 50, 67, 44, 10)");
echo "WAITING FOR ASYNC: ";
$chars = array('|', '/', '-', '\\');
while (($ret = $basic->db_check_async()) === true)
echo "WAITING FOR ASYNC: ";
$chars = array('|', '/', '-', '\\');
while (($ret = $basic->db_check_async()) === true)
{
if ((list($_, $char) = each($chars)) === FALSE)
{
if ((list($_, $char) = each($chars)) === FALSE)
{
reset($chars);
list($_, $char) = each($chars);
}
print $char;
sleep(1);
flush();
reset($chars);
list($_, $char) = each($chars);
}
print "<br>END STATUS: ".$ret."<br>";
print $char;
sleep(1);
flush();
}
print "<br>END STATUS: ".$ret."<br>";
// while ($res = $basic->db_fetch_array($ret))
while ($res = $basic->db_fetch_array())
{
echo "RES: ".$res['test']."<br>";
}
# test async insert
$basic->db_exec_async("INSERT INTO foo (Test) VALUES ('ASYNC TEST ".time()."')");
echo "WAITING FOR ASYNC INSERT: ";
while (($ret = $basic->db_check_async()) === true)
{
print ".";
sleep(1);
flush();
}
print "<br>END STATUS: ".$ret." | PK: ".$basic->insert_id."<br>";
print "ASYNC PREVIOUS INSERTED: ".print_r($basic->db_return_row("SELECT foo_id, test FROM foo WHERE foo_id = ".$basic->insert_id), 1)."<br>"; */
while ($res = $basic->db_fetch_array())
{
echo "RES: ".$res['test']."<br>";
}
# test async insert
$basic->db_exec_async("INSERT INTO foo (Test) VALUES ('ASYNC TEST ".time()."')");
echo "WAITING FOR ASYNC INSERT: ";
while (($ret = $basic->db_check_async()) === true)
{
print ".";
sleep(1);
flush();
}
print "<br>END STATUS: ".$ret." | PK: ".$basic->insert_id."<br>";
print "ASYNC PREVIOUS INSERTED: ".print_r($basic->db_return_row("SELECT foo_id, test FROM foo WHERE foo_id = ".$basic->insert_id), 1)."<br>"; */
$to_db_version = '9.1.9';
print "VERSION DB: ".$basic->db_version()."<br>";
print "DB Version smaller $to_db_version: ".$basic->db_compare_version('<'.$to_db_version)."<br>";
print "DB Version smaller than $to_db_version: ".$basic->db_compare_version('<='.$to_db_version)."<br>";
print "DB Version equal $to_db_version: ".$basic->db_compare_version('='.$to_db_version)."<br>";
print "DB Version bigger than $to_db_version: ".$basic->db_compare_version('>='.$to_db_version)."<br>";
print "DB Version bigger $to_db_version: ".$basic->db_compare_version('>'.$to_db_version)."<br>";
$to_db_version = '9.1.9';
print "VERSION DB: ".$basic->db_version()."<br>";
print "DB Version smaller $to_db_version: ".$basic->db_compare_version('<'.$to_db_version)."<br>";
print "DB Version smaller than $to_db_version: ".$basic->db_compare_version('<='.$to_db_version)."<br>";
print "DB Version equal $to_db_version: ".$basic->db_compare_version('='.$to_db_version)."<br>";
print "DB Version bigger than $to_db_version: ".$basic->db_compare_version('>='.$to_db_version)."<br>";
print "DB Version bigger $to_db_version: ".$basic->db_compare_version('>'.$to_db_version)."<br>";
/* $q = "SELECT FOO FRO BAR";
// $q = "Select * from foo";
$foo = $basic->db_exec_async($q);
print "[ERR] Query: ".$q."<br>";
print "[ERR] RESOURCE: $foo<br>";
while (($ret = $basic->db_check_async()) === true)
{
print "[ERR]: $ret<br>";
$foo = $basic->db_exec_async($q);
print "[ERR] Query: ".$q."<br>";
print "[ERR] RESOURCE: $foo<br>";
while (($ret = $basic->db_check_async()) === true)
{
print "[ERR]: $ret<br>";
// sleep(5);
} */
} */
// search path check
$q = "SHOW search_path";
$cursor = $basic->db_exec($q);
$data = $basic->db_fetch_array($cursor)['search_path'];
print "RETURN DATA FOR search_path: ".$data."<br>";
// search path check
$q = "SHOW search_path";
$cursor = $basic->db_exec($q);
$data = $basic->db_fetch_array($cursor)['search_path'];
print "RETURN DATA FOR search_path: ".$data."<br>";
// print "RETURN DATA FOR search_path: ".$basic->print_ar($data)."<br>";
// insert something into test.schema_test and see if we get the PK back
$status = $basic->db_exec("INSERT INTO test.schema_test (contents, id) VALUES ('TIME: ".time()."', ".rand(1, 10).")");
print "OTHER SCHEMA INSERT STATUS: ".$status." | PK NAME: ".$basic->pk_name.", PRIMARY KEY: ".$basic->insert_id."<br>";
// insert something into test.schema_test and see if we get the PK back
$status = $basic->db_exec("INSERT INTO test.schema_test (contents, id) VALUES ('TIME: ".time()."', ".rand(1, 10).")");
print "OTHER SCHEMA INSERT STATUS: ".$status." | PK NAME: ".$basic->pk_name.", PRIMARY KEY: ".$basic->insert_id."<br>";
// time string thest
$timestamp = 5887998.33445;
$time_string = $basic->TimeStringFormat($timestamp);
print "TIME STRING TEST: ".$time_string."<br>";
print "REVERSE TIME STRING: ".$basic->StringToTime($time_string);
// time string thest
$timestamp = 5887998.33445;
$time_string = $basic->TimeStringFormat($timestamp);
print "TIME STRING TEST: ".$time_string."<br>";
print "REVERSE TIME STRING: ".$basic->StringToTime($time_string);
// magic links test
print $basic->magic_links('user@bubu.at').'<br>';
print $basic->magic_links('http://test.com/foo/bar.php?foo=1').'<br>';
// magic links test
print $basic->magic_links('user@bubu.at').'<br>';
print $basic->magic_links('http://test.com/foo/bar.php?foo=1').'<br>';
// compare date
$date_1 = '2017/1/5';
$date_2 = '2017-01-05';
print "COMPARE DATE: ".$basic->CompareDate($date_1, $date_2)."<br>";
// compare date
$date_1 = '2017/1/5';
$date_2 = '2017-01-05';
print "COMPARE DATE: ".$basic->CompareDate($date_1, $date_2)."<br>";
// print error messages
print $basic->print_error_msg();
// print error messages
print $basic->print_error_msg();
print "</body></html>";
?>
print "</body></html>";

View File

@@ -1,345 +1,324 @@
<?
/********************************************************************
* AUTHOR: Clemens "Gullevek" Schwaighofer (www.gullevek.org)
* CREATED: 2003/06/10
* SHORT DESCRIPTION:
* central include for all edit_pages
* - edit_groups.php
* - edit_languages.php
* - edit_pages.php
* - edit_schemes.php
* - edit_users.php
* - edit_visible_group.php
* HISTORY:
* 2005/06/30 (cs) remove color settings, they are in CSS File now
* 2005/06/22 (cs) moved load of config array into form class, set lang and lang is must set var for form class; removed the page name setting, moved it into the form class, remove all HTML from main page
* 2004/09/30 (cs) changed layout to fit default layout & changed LIBS, etc
* 2003-06-10: creation of this page
*********************************************************************/
/********************************************************************
* AUTHOR: Clemens "Gullevek" Schwaighofer (www.gullevek.org)
* CREATED: 2003/06/10
* SHORT DESCRIPTION:
* central include for all edit_pages
* - edit_groups.php
* - edit_languages.php
* - edit_pages.php
* - edit_schemes.php
* - edit_users.php
* - edit_visible_group.php
* HISTORY:
* 2005/06/30 (cs) remove color settings, they are in CSS File now
* 2005/06/22 (cs) moved load of config array into form class, set lang and lang is must set var for form class; removed the page name setting, moved it into the form class, remove all HTML from main page
* 2004/09/30 (cs) changed layout to fit default layout & changed LIBS, etc
* 2003-06-10: creation of this page
*********************************************************************/
$DEBUG_ALL = 1;
$DB_DEBUG = 1;
$DEBUG_ALL = 1;
$DB_DEBUG = 1;
extract($_POST, EXTR_SKIP);
extract($_POST, EXTR_SKIP);
$table_width = 750;
// this is for certain CMS modules that set a relative path
define(REL_PATH, '');
$table_width = 750;
// this is for certain CMS modules that set a relative path
define(REL_PATH, '');
ob_start();
include("config.inc");
// overrride debug flags
if (!DEBUG)
{
$DEBUG_ALL = 0;
$PRINT_ALL = 0;
$DB_DEBUG = 0;
$ECHO_ALL = 0;
ob_start();
include("config.inc");
// overrride debug flags
if (!DEBUG) {
$DEBUG_ALL = 0;
$PRINT_ALL = 0;
$DB_DEBUG = 0;
$ECHO_ALL = 0;
// $DEBUG_TMPL = 0;
}
// set session name here
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
// login class
require(LIBS."Class.Login.inc");
// form generate for edit interface
require(LIBS."Class.Form.Generate.inc");
// Smarty: and the small extend for l10n calls
require(LIBS.'Class.Smarty.Extend.inc');
}
// set session name here
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
// login class
require(LIBS."Class.Login.inc");
// form generate for edit interface
require(LIBS."Class.Form.Generate.inc");
// Smarty: and the small extend for l10n calls
require(LIBS.'Class.Smarty.Extend.inc');
// set default lang if not set otherwise
if (!$lang)
$lang = DEFAULT_LANG;
// should be utf8
header("Content-type: text/html; charset=".DEFAULT_ENCODING);
ob_end_flush();
$login = new login($DB_CONFIG[LOGIN_DB], $lang);
// set default lang if not set otherwise
if (!$lang) {
$lang = DEFAULT_LANG;
}
// should be utf8
header("Content-type: text/html; charset=".DEFAULT_ENCODING);
ob_end_flush();
$login = new login($DB_CONFIG[LOGIN_DB], $lang);
// create form class
$form = new form($DB_CONFIG[MAIN_DB], $lang);
$form->db_exec("SET search_path TO ".LOGIN_DB_SCHEMA);
if ($form->mobile_phone)
{
echo "I am sorry, but this page cannot be viewed by a mobile phone";
exit;
}
// smarty template engine (extended Translation version)
$smarty = new SmartyML($lang);
// create form class
$form = new form($DB_CONFIG[MAIN_DB], $lang);
$form->db_exec("SET search_path TO ".LOGIN_DB_SCHEMA);
if ($form->mobile_phone) {
echo "I am sorry, but this page cannot be viewed by a mobile phone";
exit;
}
// smarty template engine (extended Translation version)
$smarty = new SmartyML($lang);
if (TARGET == 'live' || TARGET == 'remote')
{
// login
$login->debug_output_all = DEBUG ? 1 : 0;
$login->echo_output_all = 0;
$login->print_output_all = DEBUG ? 1 : 0;
// form
$form->debug_output_all = DEBUG ? 1 : 0;
$form->echo_output_all = 0;
$form->print_output_all = DEBUG ? 1 : 0;
}
// set the template dir
// WARNING: this has a special check for the mailing tool layout (old layout)
if (defined('LAYOUT'))
{
$smarty->setTemplateDir(LAYOUT.DEFAULT_TEMPLATE.TEMPLATES);
$DATA['css'] = LAYOUT.DEFAULT_TEMPLATE.CSS;
$DATA['js'] = LAYOUT.DEFAULT_TEMPLATE.JS;
}
else
{
$smarty->setTemplateDir(TEMPLATES.DEFAULT_TEMPLATE);
$DATA['css'] = CSS.DEFAULT_TEMPLATE;
$DATA['js'] = JS.DEFAULT_TEMPLATE;
}
if (TARGET == 'live' || TARGET == 'remote') {
// login
$login->debug_output_all = DEBUG ? 1 : 0;
$login->echo_output_all = 0;
$login->print_output_all = DEBUG ? 1 : 0;
// form
$form->debug_output_all = DEBUG ? 1 : 0;
$form->echo_output_all = 0;
$form->print_output_all = DEBUG ? 1 : 0;
}
// set the template dir
// WARNING: this has a special check for the mailing tool layout (old layout)
if (defined('LAYOUT')) {
$smarty->setTemplateDir(LAYOUT.DEFAULT_TEMPLATE.TEMPLATES);
$DATA['css'] = LAYOUT.DEFAULT_TEMPLATE.CSS;
$DATA['js'] = LAYOUT.DEFAULT_TEMPLATE.JS;
} else {
$smarty->setTemplateDir(TEMPLATES.DEFAULT_TEMPLATE);
$DATA['css'] = CSS.DEFAULT_TEMPLATE;
$DATA['js'] = JS.DEFAULT_TEMPLATE;
}
// space for setting special debug flags
$login->debug_output_all = 1;
// space for setting special debug flags
$login->debug_output_all = 1;
// define edit logging function. should be in a special edit interface class later
// METHOD: EditLog()
// PARAMS: event -> any kind of event description, data -> any kind of data related to that event
// RETURN: none
// DESC: writes all action vars plus other info into edit_log table
function EditLog($event = '', $data = '')
{
$q = "INSERT INTO edit_log ";
$q .= "(euid, event_date, ip, event, data, page) ";
$q .= "VALUES (".$_SESSION['EUID'].", NOW(), '".$_SERVER["REMOTE_ADDR"]."', '".$GLOBALS['form']->db_escape_string($event)."', '".$GLOBALS['form']->db_escape_string($data)."', '".$GLOBALS['form']->get_page_name()."')";
}
// define edit logging function. should be in a special edit interface class later
// METHOD: EditLog()
// PARAMS: event -> any kind of event description, data -> any kind of data related to that event
// RETURN: none
// DESC: writes all action vars plus other info into edit_log table
function EditLog($event = '', $data = '')
{
$q = "INSERT INTO edit_log ";
$q .= "(euid, event_date, ip, event, data, page) ";
$q .= "VALUES (".$_SESSION['EUID'].", NOW(), '".$_SERVER["REMOTE_ADDR"]."', '".$GLOBALS['form']->db_escape_string($event)."', '".$GLOBALS['form']->db_escape_string($data)."', '".$GLOBALS['form']->get_page_name()."')";
}
// log backend data
// data part creation
$data = array (
'_SESSION' => $_SESSION,
'_GET' => $_GET,
'_POST' => $_POST,
'_FILES' => $_FILES
);
// log action
EditLog('Edit Submit', serialize($data));
// log backend data
// data part creation
$data = array (
'_SESSION' => $_SESSION,
'_GET' => $_GET,
'_POST' => $_POST,
'_FILES' => $_FILES
);
// log action
EditLog('Edit Submit', serialize($data));
$form->form_procedure_load(${$form->archive_pk_name});
$form->form_procedure_new();
$form->form_procedure_save();
$form->form_procedure_delete();
$form->form_procedure_delete_from_element_list($element_list, $remove_name);
$form->form_procedure_load(${$form->archive_pk_name});
$form->form_procedure_new();
$form->form_procedure_save();
$form->form_procedure_delete();
$form->form_procedure_delete_from_element_list($element_list, $remove_name);
// define all needed smarty stuff for the general HTML/page building
$HEADER['CSS'] = CSS;
$HEADER['DEFAULT_ENCODING'] = DEFAULT_ENCODING;
$HEADER['JS'] = JS;
$HEADER['STYLESHEET'] = $EDIT_STYLESHEET;
$HEADER['JAVASCRIPT'] = $EDIT_JAVASCRIPT;
// define all needed smarty stuff for the general HTML/page building
$HEADER['CSS'] = CSS;
$HEADER['DEFAULT_ENCODING'] = DEFAULT_ENCODING;
$HEADER['JS'] = JS;
$HEADER['STYLESHEET'] = $EDIT_STYLESHEET;
$HEADER['JAVASCRIPT'] = $EDIT_JAVASCRIPT;
$DATA['table_width'] = $table_width;
$DATA['table_width'] = $table_width;
// write out error / status messages
$messages[] = $form->form_error_msg();
$DATA['form_error_msg'] = $messages;
// write out error / status messages
$messages[] = $form->form_error_msg();
$DATA['form_error_msg'] = $messages;
// MENU START
// request some session vars
if (!$HEADER_COLOR)
$DATA['HEADER_COLOR'] = "#E0E2FF";
else
$DATA['HEADER_COLOR'] = $_SESSION['HEADER_COLOR'];
$DATA['USER_NAME'] = $_SESSION["USER_NAME"];
$DATA['EUID'] = $_SESSION["EUID"];
$DATA['GROUP_NAME'] = $_SESSION["GROUP_NAME"];
$DATA['GROUP_LEVEL'] = $_SESSION["GROUP_LEVEL"];
$PAGES = $_SESSION["PAGES"];
// MENU START
// request some session vars
if (!$HEADER_COLOR) {
$DATA['HEADER_COLOR'] = "#E0E2FF";
} else {
$DATA['HEADER_COLOR'] = $_SESSION['HEADER_COLOR'];
}
$DATA['USER_NAME'] = $_SESSION["USER_NAME"];
$DATA['EUID'] = $_SESSION["EUID"];
$DATA['GROUP_NAME'] = $_SESSION["GROUP_NAME"];
$DATA['GROUP_LEVEL'] = $_SESSION["GROUP_LEVEL"];
$PAGES = $_SESSION["PAGES"];
//$form->debug('menu', $form->print_ar($PAGES));
// baue nav aus $PAGES ...
for ($i = 0; $i < count($PAGES); $i ++)
{
if ($PAGES[$i]["menu"] && $PAGES[$i]["online"])
{
$menuarray[] = $PAGES[$i];
}
// baue nav aus $PAGES ...
for ($i = 0; $i < count($PAGES); $i ++) {
if ($PAGES[$i]["menu"] && $PAGES[$i]["online"]) {
$menuarray[] = $PAGES[$i];
}
}
// split point for nav points
$COUNT_NAV_POINTS = count($menuarray);
$SPLIT_FACTOR = 3;
$START_SPLIT_COUNT = 3;
// WTF ?? I dunno what I am doing here ...
for ($i = 9; $i < $COUNT_NAV_POINTS; $i += $START_SPLIT_COUNT)
{
if ($COUNT_NAV_POINTS > $i)
$SPLIT_FACTOR += 1;
// split point for nav points
$COUNT_NAV_POINTS = count($menuarray);
$SPLIT_FACTOR = 3;
$START_SPLIT_COUNT = 3;
// WTF ?? I dunno what I am doing here ...
for ($i = 9; $i < $COUNT_NAV_POINTS; $i += $START_SPLIT_COUNT) {
if ($COUNT_NAV_POINTS > $i) {
$SPLIT_FACTOR += 1;
}
}
for ($i = 1; $i <= count($menuarray); $i ++)
{
// do that for new array
$j = $i - 1;
$menu_data[$j]['pagename'] = htmlentities($menuarray[($i-1)]["page_name"]);
$menu_data[$j]['filename'] = $menuarray[($i-1)]["filename"].$menuarray[($i-1)]["query_string"];
if ($i == 1 || !(($i - 1) % $SPLIT_FACTOR))
{
$menu_data[$j]['splitfactor_in'] = 1;
}
if ($menuarray[($i - 1)]["filename"] == $form->get_page_name())
{
$position = $i - 1;
$menu_data[$j]['position'] = 1;
}
else
{
// add query stuff
// HAS TO DONE LATER ... set urlencode, etc ...
// check if popup needed
if ($menuarray[($i - 1)]["popup"])
{
$menu_data[$j]['popup'] = 1;
$menu_data[$j]['rand'] = uniqid(rand());
$menu_data[$j]['width'] = $menuarray[($i-1)]["popup_x"];
$menu_data[$j]['height'] = $menuarray[($i-1)]["popup_y"];
} // popup or not
} // highlight or not
if (!($i % $SPLIT_FACTOR) || (($i + 1) > count($menuarray)))
{
$menu_data[$j]['splitfactor_out'] = 1;
} // split
} // for
$DATA['menu_data'] = $menu_data;
$DATA['page_name'] = $menuarray[$position]["page_name"];
$L_TITLE = $DATA['page_name'];
// html title
$HEADER['HTML_TITLE'] = ((!$L_TITLE) ? $form->l->__($G_TITLE) : $form->l->__($L_TITLE));
// END MENU
// LOAD AND NEW
$DATA['load'] = $form->form_create_load();
$DATA['new'] = $form->form_create_new();
// SHOW DATA PART
if ($form->yes)
{
$DATA['form_yes'] = $form->yes;
$DATA['form_my_page_name'] = $form->my_page_name;
for ($i = 1; $i <= count($menuarray); $i ++) {
// do that for new array
$j = $i - 1;
$menu_data[$j]['pagename'] = htmlentities($menuarray[($i-1)]["page_name"]);
$menu_data[$j]['filename'] = $menuarray[($i-1)]["filename"].$menuarray[($i-1)]["query_string"];
if ($i == 1 || !(($i - 1) % $SPLIT_FACTOR)) {
$menu_data[$j]['splitfactor_in'] = 1;
}
if ($menuarray[($i - 1)]["filename"] == $form->get_page_name()) {
$position = $i - 1;
$menu_data[$j]['position'] = 1;
} else {
// add query stuff
// HAS TO DONE LATER ... set urlencode, etc ...
// check if popup needed
if ($menuarray[($i - 1)]["popup"]) {
$menu_data[$j]['popup'] = 1;
$menu_data[$j]['rand'] = uniqid(rand());
$menu_data[$j]['width'] = $menuarray[($i-1)]["popup_x"];
$menu_data[$j]['height'] = $menuarray[($i-1)]["popup_y"];
} // popup or not
} // highlight or not
if (!($i % $SPLIT_FACTOR) || (($i + 1) > count($menuarray))) {
$menu_data[$j]['splitfactor_out'] = 1;
} // split
} // for
$DATA['menu_data'] = $menu_data;
$DATA['page_name'] = $menuarray[$position]["page_name"];
$L_TITLE = $DATA['page_name'];
// html title
$HEADER['HTML_TITLE'] = ((!$L_TITLE) ? $form->l->__($G_TITLE) : $form->l->__($L_TITLE));
// END MENU
// LOAD AND NEW
$DATA['load'] = $form->form_create_load();
$DATA['new'] = $form->form_create_new();
// SHOW DATA PART
if ($form->yes) {
$DATA['form_yes'] = $form->yes;
$DATA['form_my_page_name'] = $form->my_page_name;
// depending on the "get_page_name()" I show different stuff
switch ($form->my_page_name)
{
case "edit_users":
$elements[] = $form->form_create_element("login_error_count");
$elements[] = $form->form_create_element("login_error_date_last");
$elements[] = $form->form_create_element("login_error_date_first");
$elements[] = $form->form_create_element("enabled");
$elements[] = $form->form_create_element("username");
$elements[] = $form->form_create_element("password");
$elements[] = $form->form_create_element("password_change_interval");
$elements[] = $form->form_create_element("email");
$elements[] = $form->form_create_element("last_name");
$elements[] = $form->form_create_element("first_name");
$elements[] = $form->form_create_element("edit_group_id");
$elements[] = $form->form_create_element("edit_access_right_id");
$elements[] = $form->form_create_element("strict");
$elements[] = $form->form_create_element("locked");
$elements[] = $form->form_create_element("admin");
$elements[] = $form->form_create_element("debug");
$elements[] = $form->form_create_element("db_debug");
$elements[] = $form->form_create_element("edit_language_id");
$elements[] = $form->form_create_element("edit_scheme_id");
$elements[] = $form->form_show_list_table("edit_access_user");
// depending on the "get_page_name()" I show different stuff
switch ($form->my_page_name) {
case "edit_users":
$elements[] = $form->form_create_element("login_error_count");
$elements[] = $form->form_create_element("login_error_date_last");
$elements[] = $form->form_create_element("login_error_date_first");
$elements[] = $form->form_create_element("enabled");
$elements[] = $form->form_create_element("username");
$elements[] = $form->form_create_element("password");
$elements[] = $form->form_create_element("password_change_interval");
$elements[] = $form->form_create_element("email");
$elements[] = $form->form_create_element("last_name");
$elements[] = $form->form_create_element("first_name");
$elements[] = $form->form_create_element("edit_group_id");
$elements[] = $form->form_create_element("edit_access_right_id");
$elements[] = $form->form_create_element("strict");
$elements[] = $form->form_create_element("locked");
$elements[] = $form->form_create_element("admin");
$elements[] = $form->form_create_element("debug");
$elements[] = $form->form_create_element("db_debug");
$elements[] = $form->form_create_element("edit_language_id");
$elements[] = $form->form_create_element("edit_scheme_id");
$elements[] = $form->form_show_list_table("edit_access_user");
break;
case "edit_schemes":
$elements[] = $form->form_create_element("enabled");
$elements[] = $form->form_create_element("name");
$elements[] = $form->form_create_element("header_color");
$elements[] = $form->form_create_element("template");
case "edit_schemes":
$elements[] = $form->form_create_element("enabled");
$elements[] = $form->form_create_element("name");
$elements[] = $form->form_create_element("header_color");
$elements[] = $form->form_create_element("template");
break;
case "edit_pages":
if (!$form->table_array["edit_page_id"]["value"])
{
$q = "DELETE FROM temp_files";
$form->db_exec($q);
// gets all files in the current dir ending with .php
$crap = exec("ls *.php", $output, $status);
// now get all that are NOT in de DB
$q = "INSERT INTO temp_files VALUES ";
for ($i = 0; $i < count($output); $i ++)
{
$t_q = "('".$form->db_escape_string($output[$i])."')";
$form->db_exec($q.$t_q, 'NULL');
}
$elements[] = $form->form_create_element("filename");
case "edit_pages":
if (!$form->table_array["edit_page_id"]["value"]) {
$q = "DELETE FROM temp_files";
$form->db_exec($q);
// gets all files in the current dir ending with .php
$crap = exec("ls *.php", $output, $status);
// now get all that are NOT in de DB
$q = "INSERT INTO temp_files VALUES ";
for ($i = 0; $i < count($output); $i ++) {
$t_q = "('".$form->db_escape_string($output[$i])."')";
$form->db_exec($q.$t_q, 'NULL');
}
else // show file menu
{
// just show name of file ...
$DATA['filename_exist'] = 1;
$DATA['filename'] = $form->table_array["filename"]["value"];
} // File Name View IF
$elements[] = $form->form_create_element("name");
// $elements[] = $form->form_create_element("tag");
// $elements[] = $form->form_create_element("min_acl");
$elements[] = $form->form_create_element("order_number");
$elements[] = $form->form_create_element("online");
$elements[] = $form->form_create_element("menu");
$elements[] = $form->form_show_list_table("edit_query_string");
$elements[] = $form->form_create_element("popup");
$elements[] = $form->form_create_element("popup_x");
$elements[] = $form->form_create_element("popup_y");
$elements[] = $form->form_show_reference_table("edit_visible_group");
$elements[] = $form->form_show_reference_table("edit_menu_group");
$elements[] = $form->form_create_element("filename");
} else {
// show file menu
// just show name of file ...
$DATA['filename_exist'] = 1;
$DATA['filename'] = $form->table_array["filename"]["value"];
} // File Name View IF
$elements[] = $form->form_create_element("name");
// $elements[] = $form->form_create_element("tag");
// $elements[] = $form->form_create_element("min_acl");
$elements[] = $form->form_create_element("order_number");
$elements[] = $form->form_create_element("online");
$elements[] = $form->form_create_element("menu");
$elements[] = $form->form_show_list_table("edit_query_string");
$elements[] = $form->form_create_element("popup");
$elements[] = $form->form_create_element("popup_x");
$elements[] = $form->form_create_element("popup_y");
$elements[] = $form->form_show_reference_table("edit_visible_group");
$elements[] = $form->form_show_reference_table("edit_menu_group");
break;
case "edit_languages":
$elements[] = $form->form_create_element("enabled");
$elements[] = $form->form_create_element("short_name");
$elements[] = $form->form_create_element("long_name");
$elements[] = $form->form_create_element("iso_name");
case "edit_languages":
$elements[] = $form->form_create_element("enabled");
$elements[] = $form->form_create_element("short_name");
$elements[] = $form->form_create_element("long_name");
$elements[] = $form->form_create_element("iso_name");
break;
case "edit_groups":
$elements[] = $form->form_create_element("enabled");
$elements[] = $form->form_create_element("name");
$elements[] = $form->form_create_element("edit_access_right_id");
$elements[] = $form->form_create_element("edit_scheme_id");
$elements[] = $form->form_show_list_table("edit_page_access");
case "edit_groups":
$elements[] = $form->form_create_element("enabled");
$elements[] = $form->form_create_element("name");
$elements[] = $form->form_create_element("edit_access_right_id");
$elements[] = $form->form_create_element("edit_scheme_id");
$elements[] = $form->form_show_list_table("edit_page_access");
break;
case "edit_visible_group":
$elements[] = $form->form_create_element("name");
$elements[] = $form->form_create_element("flag");
case "edit_visible_group":
$elements[] = $form->form_create_element("name");
$elements[] = $form->form_create_element("flag");
break;
case "edit_menu_group":
$elements[] = $form->form_create_element("name");
$elements[] = $form->form_create_element("flag");
$elements[] = $form->form_create_element("order_number");
case "edit_menu_group":
$elements[] = $form->form_create_element("name");
$elements[] = $form->form_create_element("flag");
$elements[] = $form->form_create_element("order_number");
break;
case "edit_access":
$elements[] = $form->form_create_element("name");
$elements[] = $form->form_create_element("color");
$elements[] = $form->form_create_element("description");
// add name/value list here
$elements[] = $form->form_show_list_table("edit_access_data");
case "edit_access":
$elements[] = $form->form_create_element("name");
$elements[] = $form->form_create_element("color");
$elements[] = $form->form_create_element("description");
// add name/value list here
$elements[] = $form->form_show_list_table("edit_access_data");
break;
default:
print "[No valid page definition given]";
break;
default:
print "NO NO NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO!";
break;
}
}
// $form->debug('edit', "Elements: <pre>".$form->print_ar($elements));
$DATA['elements'] = $elements;
$DATA['hidden'] = $form->form_create_hidden_fields();
$DATA['save_delete'] = $form->form_create_save_delete();
}
$DATA['elements'] = $elements;
$DATA['hidden'] = $form->form_create_hidden_fields();
$DATA['save_delete'] = $form->form_create_save_delete();
}
// debug data, if DEBUG flag is on, this data is print out
$DEBUG_DATA['DEBUG'] = $DEBUG_TMPL;
// debug data, if DEBUG flag is on, this data is print out
$DEBUG_DATA['DEBUG'] = $DEBUG_TMPL;
// create main data array
$CONTENT_DATA = array_merge($HEADER, $DATA, $DEBUG_DATA);
// data is 1:1 mapping (all vars, values, etc)
while (list($key, $value) = each($CONTENT_DATA))
{
$smarty->assign($key, $value);
}
// create main data array
$CONTENT_DATA = array_merge($HEADER, $DATA, $DEBUG_DATA);
// data is 1:1 mapping (all vars, values, etc)
while (list($key, $value) = each($CONTENT_DATA)) {
$smarty->assign($key, $value);
}
// $smarty->assign('popup_page', 'mt_popup_'.$body_part.'.tpl');
$smarty->display('edit_body.tpl');
$smarty->display('edit_body.tpl');
// debug output
echo $login->print_error_msg();
echo $form->print_error_msg();
?>
// debug output
echo $login->print_error_msg();
echo $form->print_error_msg();

View File

@@ -1,18 +1,18 @@
<?php
$DEBUG_ALL_OVERRIDE = 0; // set to 1 to debug on live/remote server locations
$DEBUG_ALL = 1;
$PRINT_ALL = 1;
$DB_DEBUG = 1;
$DEBUG_ALL_OVERRIDE = 0; // set to 1 to debug on live/remote server locations
$DEBUG_ALL = 1;
$PRINT_ALL = 1;
$DB_DEBUG = 1;
if ($DEBUG_ALL)
error_reporting(E_ALL);
if ($DEBUG_ALL) {
error_reporting(E_ALL);
}
// sample config
require("config.inc");
require(LIBS."Error.Handling.inc");
// sample config
require("config.inc");
require(LIBS."Error.Handling.inc");
if ($var) {
echo "OUT<br>";
}
?>
if ($var) {
echo "OUT<br>";
}

View File

@@ -1,486 +1,456 @@
<?
/********************************************************************
* AUTHOR: Clemens Schwaighofer
* CREATED: 2005/07/13
* SHORT DESCRIPTION:
* Create categories for CMS
* HISTORY:
* 2005/08/19 (cs) changed the mime type get from the _FILE to mime get fkt
*********************************************************************/
/********************************************************************
* AUTHOR: Clemens Schwaighofer
* CREATED: 2005/07/13
* SHORT DESCRIPTION:
* Create categories for CMS
* HISTORY:
* 2005/08/19 (cs) changed the mime type get from the _FILE to mime get fkt
*********************************************************************/
// DEBUG vars here
$DEBUG_ALL = 1;
$DB_DEBUG = 1;
$DEBUG_TMPL = 1;
// DEBUG vars here
$DEBUG_ALL = 1;
$DB_DEBUG = 1;
$DEBUG_TMPL = 1;
//------------------------------ header
require("header.inc");
$MASTER_TEMPLATE_NAME = 'cms_popup.tpl';
$TEMPLATE_NAME = 'cms_files.tpl';
$PAGE_WIDTH = 750;
require("set_paths.inc");
//------------------------------ header
//------------------------------ header
require("header.inc");
$MASTER_TEMPLATE_NAME = 'cms_popup.tpl';
$TEMPLATE_NAME = 'cms_files.tpl';
$PAGE_WIDTH = 750;
require("set_paths.inc");
//------------------------------ header
//------------------------------ processing data start
$form_name = $_GET['form'];
$value_name = $_GET['name'];
$data_id = $_GET['id'];
$show_type = $_GET['type']; // P (pic), F (flash), V (video), D (document: word), A (document: pdf), B (binary); , separated string
//------------------------------ processing data start
$form_name = $_GET['form'];
$value_name = $_GET['name'];
$data_id = $_GET['id'];
$show_type = $_GET['type']; // P (pic), F (flash), V (video), D (document: word), A (document: pdf), B (binary); , separated string
// default view is list
if (!$view && !$data_id)
$view = 'list';
elseif (!$view && $data_id)
$view = 'list';
// default is online
if (!isset($online))
$online = 't';
// if not set, it is a fresh load
if (!$show_amount)
$fresh_load = 1;
// the next two are for page view
if (!$start_row)
$start_row = 0;
if (!$show_amount)
$show_amount = 12;
if (!$show_type)
$show_type = 'P';
// default view is list
if (!$view && !$data_id) {
$view = 'list';
} elseif (!$view && $data_id) {
$view = 'list';
}
// default is online
if (!isset($online)) {
$online = 't';
}
// if not set, it is a fresh load
if (!$show_amount) {
$fresh_load = 1;
}
// the next two are for page view
if (!$start_row) {
$start_row = 0;
}
if (!$show_amount) {
$show_amount = 12;
}
if (!$show_type) {
$show_type = 'P';
}
// yes no list (online)
$yesno_list['f'] = 'No';
$yesno_list['t'] = 'Yes';
// order list
$sort_order_list['date_created'] = 'ID / Insert time'; // default
$sort_order_list['file_name'] = 'File Name';
$sort_order_list['file_size'] = 'File Size';
$sort_order_list['mime_type'] = 'Mime Type';
$sort_order_list['name_en'] = 'Alt Name English';
$sort_order_list['name_ja'] = 'Alt Name Japanese';
$sort_order_list['date_updated'] = 'Updated';
if (!$sort_order)
$sort_order = 'date_created';
$sort_direction_list['ASC'] = 'Normal';
$sort_direction_list['DESC'] = 'Reverse';
if (!$sort_direction)
$sort_direction = 'ASC';
// set if we need to write to any of the set live queues
// a) on page save with set_live
// b) global page with live_queue
// set via QUEUE variable
// yes no list (online)
$yesno_list['f'] = 'No';
$yesno_list['t'] = 'Yes';
// order list
$sort_order_list['date_created'] = 'ID / Insert time'; // default
$sort_order_list['file_name'] = 'File Name';
$sort_order_list['file_size'] = 'File Size';
$sort_order_list['mime_type'] = 'Mime Type';
$sort_order_list['name_en'] = 'Alt Name English';
$sort_order_list['name_ja'] = 'Alt Name Japanese';
$sort_order_list['date_updated'] = 'Updated';
if (!$sort_order) {
$sort_order = 'date_created';
}
$sort_direction_list['ASC'] = 'Normal';
$sort_direction_list['DESC'] = 'Reverse';
if (!$sort_direction) {
$sort_direction = 'ASC';
}
// set if we need to write to any of the set live queues
// a) on page save with set_live
// b) global page with live_queue
// set via QUEUE variable
// create 0 entries for: templates, menu, data_group?
if ($cms->action == 'new' && $cms->action_yes == 'true')
{
unset($file_uid);
unset($file_id);
unset($file_type);
$new_okay = 1;
// create 0 entries for: templates, menu, data_group?
if ($cms->action == 'new' && $cms->action_yes == 'true') {
unset($file_uid);
unset($file_id);
unset($file_type);
$new_okay = 1;
}
// file type: P picture, M mouse over picutre, F flash, V video, B binary
if ($cms->action == 'save') {
if (!$file_type) {
$file_type = 'B';
}
// file type: P picture, M mouse over picutre, F flash, V video, B binary
if ($cms->action == 'save')
{
if (!$file_type)
$file_type = 'B';
$file_ok = false;
if (!$_FILES['file_up']['name'] && !$file_uid)
{
$cms->messages[] = array('msg' => 'No file name given', 'class' => 'error');
$file_ok = false;
if (!$_FILES['file_up']['name'] && !$file_uid) {
$cms->messages[] = array('msg' => 'No file name given', 'class' => 'error');
$error = 1;
}
if (!$_FILES['file_up']['name'] && $file_uid) {
$file_ok = true;
}
// echo "FILE TYPE: ".$_FILES['file_up']['type']."<br>";
foreach (split(',', $show_type) as $_show_type) {
// check if the uploaded filename matches to the given type
if ($_FILES['file_up']['name'] && preg_match("/jpeg|png|gif/", $_FILES['file_up']['type']) && preg_match("/P/", $show_type)) {
$file_ok = true;
}
if ($_FILES['file_up']['name'] && preg_match("/swf/", $_FILES['file_up']['type']) && preg_match("/F/", $show_type)) {
$file_ok = true;
}
if ($_FILES['file_up']['name'] && preg_match("/video/", $_FILES['file_up']['type']) && preg_match("/V/", $show_type)) {
$file_ok = true;
}
if ($_FILES['file_up']['name'] && preg_match("/msword|vnd.oasis.opendocument.text/", $_FILES['file_up']['type']) && preg_match("/D/", $show_type)) {
$file_ok = true;
}
if ($_FILES['file_up']['name'] && preg_match("/pdf/", $_FILES['file_up']['type']) && preg_match("/A/", $show_type)) {
$file_ok = true;
}
if ($_FILES['file_up']['name'] && preg_match("/B/", $show_type)) {
$file_ok = true;
}
}
// write out error messages according to show type
if (!$file_ok) {
if (preg_match("/P/", $show_type)) {
$cms->messages[] = array('msg' => 'File is not a JPEG/PNG/GIF file', 'class' => 'error');
$error = 1;
}
if (!$_FILES['file_up']['name'] && $file_uid)
$file_ok = true;
// echo "FILE TYPE: ".$_FILES['file_up']['type']."<br>";
foreach (split(',', $show_type) as $_show_type)
{
// check if the uploaded filename matches to the given type
if ($_FILES['file_up']['name'] && preg_match("/jpeg|png|gif/", $_FILES['file_up']['type']) && preg_match("/P/", $show_type))
{
$file_ok = true;
}
if ($_FILES['file_up']['name'] && preg_match("/swf/", $_FILES['file_up']['type']) && preg_match("/F/", $show_type))
{
$file_ok = true;
}
if ($_FILES['file_up']['name'] && preg_match("/video/", $_FILES['file_up']['type']) && preg_match("/V/", $show_type))
{
$file_ok = true;
}
if ($_FILES['file_up']['name'] && preg_match("/msword|vnd.oasis.opendocument.text/", $_FILES['file_up']['type']) && preg_match("/D/", $show_type))
{
$file_ok = true;
}
if ($_FILES['file_up']['name'] && preg_match("/pdf/", $_FILES['file_up']['type']) && preg_match("/A/", $show_type))
{
$file_ok = true;
}
if ($_FILES['file_up']['name'] && preg_match("/B/", $show_type))
$file_ok = true;
if (preg_match("/F/", $show_type)) {
$cms->messages[] = array('msg' => 'File is not a Flash File', 'class' => 'error');
$error = 1;
}
// write out error messages according to show type
if (!$file_ok)
{
if (preg_match("/P/", $show_type))
{
$cms->messages[] = array('msg' => 'File is not a JPEG/PNG/GIF file', 'class' => 'error');
$error = 1;
}
if (preg_match("/F/", $show_type))
{
$cms->messages[] = array('msg' => 'File is not a Flash File', 'class' => 'error');
$error = 1;
}
if (preg_match("/V/", $show_type))
{
$cms->messages[] = array('msg' => 'File is not a Video', 'class' => 'error');
$error = 1;
}
if (preg_match("/D/", $show_type))
{
$cms->messages[] = array('msg' => 'File is not a DOC/ODT file', 'class' => 'error');
$error = 1;
}
if (preg_match("/A/", $show_type))
{
$cms->messages[] = array('msg' => 'File is not a PDF file', 'class' => 'error');
$error = 1;
}
if (preg_match("/B/", $show_type))
{
$cms->messages[] = array('msg' => 'No valid file was given', 'class' => 'error');
$error = 1;
}
if (preg_match("/V/", $show_type)) {
$cms->messages[] = array('msg' => 'File is not a Video', 'class' => 'error');
$error = 1;
}
if (preg_match("/D/", $show_type)) {
$cms->messages[] = array('msg' => 'File is not a DOC/ODT file', 'class' => 'error');
$error = 1;
}
if (preg_match("/A/", $show_type)) {
$cms->messages[] = array('msg' => 'File is not a PDF file', 'class' => 'error');
$error = 1;
}
if (preg_match("/B/", $show_type)) {
$cms->messages[] = array('msg' => 'No valid file was given', 'class' => 'error');
$error = 1;
}
// binary: all okay
// if no error, save data
if (!$error)
{
if ($_FILES['file_up']['name'])
{
$mime_type = $_FILES['file_up']['type'];
$file_size = $_FILES['file_up']['size'];
$file_name = $_FILES['file_up']['name'];
// get picture size
list($width, $height) = getimagesize($_FILES['file_up']['tmp_name']);
$cms->debug('upload', "Width: $width X Height: $height");
// set the file type and the target folder
if (preg_match("/jpeg|png|gif/", $mime_type))
$file_type = 'P';
elseif (preg_match("/swf/", $mime_type))
$file_type = 'F';
elseif (preg_match("/video/", $mime_type))
$file_type = 'V';
elseif (preg_match("/msword|vnd.oasis.opendocument.text/", $mime_type))
$file_type = 'D';
elseif (preg_match("/pdf/", $mime_type))
$file_type = 'A';
elseif ($mime_type)
$file_type = 'B';
}
// if we have an id -> updated
if ($file_uid)
{
$q = "UPDATE file SET";
$q_set = " name_en = '".addslashes($name_en)."', name_ja = '".addslashes($name_ja)."', file_name = '".addslashes($file_name)."', online = '".$online."' ";
if ($_FILES['file_up']['name'])
{
$q_set .= ", type = '".$file_type."', mime_type = '$mime_type', file_size = $file_size, size_x = $width, size_y = $height ";
}
$q .= $q_set."WHERE file_uid = '".$file_uid."'";
$cms->db_exec($q);
if (QUEUE == 'live_queue')
{
$sql_action = 'UPDATE';
$sql_data = $q_set;
}
}
// insert new data
else
{
$file_uid = md5(uniqid(rand(), true));
$q = "INSERT INTO file (name_en, name_ja, file_name, online, mime_type, file_size, size_x, size_y, file_uid, type) VALUES ('".addslashes($name_en)."', '".addslashes($name_ja)."', '".addslashes($file_name)."', '".$online."', '".$mime_type."', $file_size, ".(($width) ? $width : 'NULL').", ".(($height) ? $height : 'NULL').", '".$file_uid."', '".$file_type."')";
$cms->db_exec($q);
$file_id = $cms->insert_id;
// if queue
if (QUEUE == 'live_queue')
{
$sql_data = $q;
$sql_action = 'INSERT';
}
}
$size_x = $width;
$size_y = $height;
$file = DEV_SCHEMA."_".$file_uid;
// now upload the file
if ($_FILES['file_up']['name'])
{
$upload_file = ROOT.MEDIA.$cms->data_path[$file_type].$file;
// wipe out any old tmp data for this new upload
if (is_array(glob(ROOT.TMP."thumb_".$file."*")))
{
foreach (glob(ROOT.TMP."thumb_".$file."*") AS $filename)
@unlink($filename);
}
# copy file to correct path
$error = move_uploaded_file($_FILES['file_up']['tmp_name'], $upload_file);
$cms->debug('file_upload', "UP: $upload_file");
$cms->debug('file_upload', "Orig: ".$cms->print_ar($_FILES['file_up']));
// because I get bogus error info from move_uploaded_file ...
$error = 0;
if ($error)
{
$cms->debug('file_upload', "ERROR: $error | INI FSize: ".ini_get("upload_max_filesize"));
$cms->messages[] = array('msg' => 'File upload failed', 'class' => 'error');
$q = "DELETE FROM file WHERE file_uid = '".$file_uid."'";
$cms->db_exec($q);
unset($file_id);
unset($file_uid);
$view = 'list';
}
else
{
$cms->messages[] = array('msg' => 'File upload successful', 'class' => 'warning');
// $vew = 'list';
}
} // if file upload
// create thumbs + file size
$picture = $cms->cache_pictures.$cms->adbCreateThumbnail($file, 400, 280, $file_type, '', $cms->cache_pictures_root);
$picture_small = $cms->cache_pictures.$cms->adbCreateThumbnail($file, 80, 60, $file_type, '', $cms->cache_pictures_root);
$file_size = $cms->adbByteStringFormat($file_size);
// for live queue this is here needed
if (QUEUE == 'live_queue')
{
$q = "INSERT INTO ".GLOBAL_DB_SCHEMA.".live_queue (queue_key, key_value, key_name, type, target, data, group_key, action";
if ($_FILES['file_up']['name'])
$q .= ", file";
$q .= ") VALUES ('".$cms->queue_name."', '".$file_uid."', 'file_uid', '".$sql_action."', 'file', '".$cms->db_escape_string($sql_data)."', '".$cms->queue_key."', '".$cms->action."'";
if ($_FILES['file_up']['name'])
$q .= ", '".ROOT.MEDIA.$cms->data_path[$file_type].$file."#".ROOT.MEDIA.$cms->data_path[$file_type].PUBLIC_SCHEMA."_".$file_uid."'";
$q .= ")";
$cms->db_exec($q);
}
} // if not error
}
if ($cms->action == 'delete' && $cms->action_yes == 'true')
{
$file_uid = $cms->action_id;
$q = "SELECT type FROM file WHERE file_uid = '".$file_uid."'";
list ($file_type) = $cms->db_return_row($q);
// get the file type for the file path
$q = "DELETE FROM file WHERE file_uid = '".$file_uid."'";
$cms->db_exec($q);
if (QUEUE == 'set_live')
{
$q = "INSERT INTO ".GLOBAL_DB_SCHEMA.".set_live (table_name, pkid, delete_flag) VALUES ('".$cms->page_name."', ".$file_uid.", 't')";
// binary: all okay
// if no error, save data
if (!$error) {
if ($_FILES['file_up']['name']) {
$mime_type = $_FILES['file_up']['type'];
$file_size = $_FILES['file_up']['size'];
$file_name = $_FILES['file_up']['name'];
// get picture size
list($width, $height) = getimagesize($_FILES['file_up']['tmp_name']);
$cms->debug('upload', "Width: $width X Height: $height");
// set the file type and the target folder
if (preg_match("/jpeg|png|gif/", $mime_type)) {
$file_type = 'P';
} elseif (preg_match("/swf/", $mime_type)) {
$file_type = 'F';
} elseif (preg_match("/video/", $mime_type)) {
$file_type = 'V';
} elseif (preg_match("/msword|vnd.oasis.opendocument.text/", $mime_type)) {
$file_type = 'D';
} elseif (preg_match("/pdf/", $mime_type)) {
$file_type = 'A';
} elseif ($mime_type) {
$file_type = 'B';
}
}
// if we have an id -> updated
if ($file_uid) {
$q = "UPDATE file SET";
$q_set = " name_en = '".addslashes($name_en)."', name_ja = '".addslashes($name_ja)."', file_name = '".addslashes($file_name)."', online = '".$online."' ";
if ($_FILES['file_up']['name']) {
$q_set .= ", type = '".$file_type."', mime_type = '$mime_type', file_size = $file_size, size_x = $width, size_y = $height ";
}
$q .= $q_set."WHERE file_uid = '".$file_uid."'";
$cms->db_exec($q);
if (QUEUE == 'live_queue') {
$sql_action = 'UPDATE';
$sql_data = $q_set;
}
} else {
// insert new data
$file_uid = md5(uniqid(rand(), true));
$q = "INSERT INTO file (name_en, name_ja, file_name, online, mime_type, file_size, size_x, size_y, file_uid, type) VALUES (";
$q .= "'".addslashes($name_en)."', '".addslashes($name_ja)."', '".addslashes($file_name)."', '".$online."', '".$mime_type."', ";
$q .= "$file_size, ".(($width) ? $width : 'NULL').", ".(($height) ? $height : 'NULL').", '".$file_uid."', '".$file_type."')";
$cms->db_exec($q);
$file_id = $cms->insert_id;
// if queue
if (QUEUE == 'live_queue') {
$sql_data = $q;
$sql_action = 'INSERT';
}
}
if (QUEUE == 'live_queue')
{
$q = "INSERT INTO ".GLOBAL_DB_SCHEMA.".live_queue (queue_key, key_value, key_name, type, target, data, group_key, action, file) VALUES ('".$cms->queue_name."', '".$file_uid."', 'file_uid', 'DELETE', 'file', '', '".$cms->queue_key."', '".$cms->action."', '".ROOT.MEDIA.$cms->data_path[$file_type].PUBLIC_SCHEMA."_".$file_uid."')";
}
@unlink(ROOT.MEDIA.$cms->data_path[$file_type].DEV_SCHEMA."_".$file_uid);
unset($file_uid);
unset($file_id);
$delete_done = 1;
$view = 'list';
}
if ($cms->action == 'load')
{
$file_uid = $cms->action_id;
// load the data
$q = "SELECT file_id, name_en, name_ja, file_name, online, mime_type, file_size, size_x, size_y, type FROM file WHERE file_uid = '".$file_uid."'";
list($file_id, $name_en, $name_ja, $file_name, $online, $mime_type, $file_size, $size_x, $size_y, $file_type) = $cms->db_return_row($q);
// create thumbnail for edit view
$size_x = $width;
$size_y = $height;
$file = DEV_SCHEMA."_".$file_uid;
// thumbnails are only valid for pictures
// now upload the file
if ($_FILES['file_up']['name']) {
$upload_file = ROOT.MEDIA.$cms->data_path[$file_type].$file;
// wipe out any old tmp data for this new upload
if (is_array(glob(ROOT.TMP."thumb_".$file."*"))) {
foreach (glob(ROOT.TMP."thumb_".$file."*") as $filename) {
@unlink($filename);
}
}
# copy file to correct path
$error = move_uploaded_file($_FILES['file_up']['tmp_name'], $upload_file);
$cms->debug('file_upload', "UP: $upload_file");
$cms->debug('file_upload', "Orig: ".$cms->print_ar($_FILES['file_up']));
// because I get bogus error info from move_uploaded_file ...
$error = 0;
if ($error) {
$cms->debug('file_upload', "ERROR: $error | INI FSize: ".ini_get("upload_max_filesize"));
$cms->messages[] = array('msg' => 'File upload failed', 'class' => 'error');
$q = "DELETE FROM file WHERE file_uid = '".$file_uid."'";
$cms->db_exec($q);
unset($file_id);
unset($file_uid);
$view = 'list';
} else {
$cms->messages[] = array('msg' => 'File upload successful', 'class' => 'warning');
// $view = 'list';
}
} // if file upload
// create thumbs + file size
$picture = $cms->cache_pictures.$cms->adbCreateThumbnail($file, 400, 280, $file_type, '', $cms->cache_pictures_root);
$picture_small = $cms->cache_pictures.$cms->adbCreateThumbnail($file, 80, 60, $file_type, '', $cms->cache_pictures_root);
$file_size = $cms->adbByteStringFormat($file_size);
// view to edit
$view = 'edit';
}
if ($cms->action == 'add_new')
{
$view = 'edit';
}
if ($cms->action == 'view_files' && $cms->action_yes == 'true')
{
$view = 'list';
}
// set delete live
if ($cms->action_flag == 'set_live' && $cms->action = 'set_delete')
{
$q = "SELECT file_uid, pkid, type FROM ".LOGIN_DB_SCHEMA.".set_live sl, file f WHERE sl.pkid = f.file_uid table_name = '".$cms->page_name."' AND delete_flag = 't'";
while ($res = $cms->db_return($q))
{
$q_del = "DELETE FROM ".PUBLIC_SCHEMA.".file WHERE file_uid = '".$res['pkid'].'"';
$cms->db_exec($q_del);
@unlink(ROOT.MEDIA.$cms->data_path[$res['type']].PUBLIC_SCHEMA."_".$res['file_uid']);
// for live queue this is here needed
if (QUEUE == 'live_queue') {
$q = "INSERT INTO ".GLOBAL_DB_SCHEMA.".live_queue (queue_key, key_value, key_name, type, target, data, group_key, action";
if ($_FILES['file_up']['name']) {
$q .= ", file";
}
$q .= ") VALUES ('".$cms->queue_name."', '".$file_uid."', 'file_uid', '".$sql_action."', 'file', '".$cms->db_escape_string($sql_data)."', '".$cms->queue_key."', '".$cms->action."'";
if ($_FILES['file_up']['name']) {
$q .= ", '".ROOT.MEDIA.$cms->data_path[$file_type].$file."#".ROOT.MEDIA.$cms->data_path[$file_type].PUBLIC_SCHEMA."_".$file_uid."'";
}
$q .= ")";
$cms->db_exec($q);
}
$q = "DELETE FROM ".LOGIN_DB_SCHEMA.".set_live WHERE table_name = '".$cms->page_name."' AND delete_flag = 't'";
} // if not error
}
if ($cms->action == 'delete' && $cms->action_yes == 'true') {
$file_uid = $cms->action_id;
$q = "SELECT type FROM file WHERE file_uid = '".$file_uid."'";
list ($file_type) = $cms->db_return_row($q);
// get the file type for the file path
$q = "DELETE FROM file WHERE file_uid = '".$file_uid."'";
$cms->db_exec($q);
if (QUEUE == 'set_live') {
$q = "INSERT INTO ".GLOBAL_DB_SCHEMA.".set_live (table_name, pkid, delete_flag) VALUES ('".$cms->page_name."', ".$file_uid.", 't')";
$cms->db_exec($q);
}
if (DEV_SCHEMA != PUBLIC_SCHEMA)
{
// read out possible deleted, to add "delete from live"
$q = "SELECT pkid FROM ".LOGIN_DB_SCHEMA.".set_live WHERE table_name = '".$cms->page_name."' AND delete_flag = 't'";
while ($res = $cms->db_return($q, 3))
{
$cms->DATA['set_delete'][]['pkid'] = $res['pkid'];
}
if (QUEUE == 'live_queue') {
$q = "INSERT INTO ".GLOBAL_DB_SCHEMA.".live_queue (queue_key, key_value, key_name, type, target, data, group_key, action, file) VALUES (";
$q .= "'".$cms->queue_name."', '".$file_uid."', 'file_uid', 'DELETE', 'file', '', '".$cms->queue_key."', '".$cms->action."', '".ROOT.MEDIA.$cms->data_path[$file_type].PUBLIC_SCHEMA."_".$file_uid."')";
}
// get th max entries
$q = "SELECT COUNT(file_uid) FROM file ";
$q_search_where = "WHERE type in ('".str_replace(',', "','", $show_type)."') ";
if ($search_what)
{
$q_search_where .= "AND LOWER(name_en) LIKE '%".addslashes(strtolower($search_what))."%' OR name_ja LIKE '%".addslashes($search_what)."%' OR LOWER(file_name) LIKE '%".addslashes(strtolower($search_what))."%' ";
@unlink(ROOT.MEDIA.$cms->data_path[$file_type].DEV_SCHEMA."_".$file_uid);
unset($file_uid);
unset($file_id);
$delete_done = 1;
$view = 'list';
}
if ($cms->action == 'load') {
$file_uid = $cms->action_id;
// load the data
$q = "SELECT file_id, name_en, name_ja, file_name, online, mime_type, file_size, size_x, size_y, type FROM file WHERE file_uid = '".$file_uid."'";
list($file_id, $name_en, $name_ja, $file_name, $online, $mime_type, $file_size, $size_x, $size_y, $file_type) = $cms->db_return_row($q);
// create thumbnail for edit view
$file = DEV_SCHEMA."_".$file_uid;
// thumbnails are only valid for pictures
$picture = $cms->cache_pictures.$cms->adbCreateThumbnail($file, 400, 280, $file_type, '', $cms->cache_pictures_root);
$picture_small = $cms->cache_pictures.$cms->adbCreateThumbnail($file, 80, 60, $file_type, '', $cms->cache_pictures_root);
$file_size = $cms->adbByteStringFormat($file_size);
// view to edit
$view = 'edit';
}
if ($cms->action == 'add_new') {
$view = 'edit';
}
if ($cms->action == 'view_files' && $cms->action_yes == 'true') {
$view = 'list';
}
// set delete live
if ($cms->action_flag == 'set_live' && $cms->action = 'set_delete') {
$q = "SELECT file_uid, pkid, type FROM ".LOGIN_DB_SCHEMA.".set_live sl, file f WHERE sl.pkid = f.file_uid table_name = '".$cms->page_name."' AND delete_flag = 't'";
while ($res = $cms->db_return($q)) {
$q_del = "DELETE FROM ".PUBLIC_SCHEMA.".file WHERE file_uid = '".$res['pkid'].'"';
$cms->db_exec($q_del);
@unlink(ROOT.MEDIA.$cms->data_path[$res['type']].PUBLIC_SCHEMA."_".$res['file_uid']);
}
$q .= $q_search_where;
// get selection from show_type
list ($file_count) = $cms->db_return_row($q);
$q = "DELETE FROM ".LOGIN_DB_SCHEMA.".set_live WHERE table_name = '".$cms->page_name."' AND delete_flag = 't'";
$cms->db_exec($q);
}
if (DEV_SCHEMA != PUBLIC_SCHEMA) {
// read out possible deleted, to add "delete from live"
$q = "SELECT pkid FROM ".LOGIN_DB_SCHEMA.".set_live WHERE table_name = '".$cms->page_name."' AND delete_flag = 't'";
while ($res = $cms->db_return($q, 3)) {
$cms->DATA['set_delete'][]['pkid'] = $res['pkid'];
}
}
// get th max entries
$q = "SELECT COUNT(file_uid) FROM file ";
$q_search_where = "WHERE type in ('".str_replace(',', "','", $show_type)."') ";
if ($search_what) {
$q_search_where .= "AND LOWER(name_en) LIKE '%".addslashes(strtolower($search_what))."%' OR name_ja LIKE '%".addslashes($search_what)."%' OR LOWER(file_name) LIKE '%".addslashes(strtolower($search_what))."%' ";
}
$q .= $q_search_where;
// get selection from show_type
list ($file_count) = $cms->db_return_row($q);
if ($cms->action == 'browse')
{
// browse in the list of data
switch ($cms->action_id)
{
case "<<<<":
$start_row = 0;
break;
case "<":
$start_row -= $show_amount;
break;
case ">":
$start_row += $show_amount;
break;
case ">>>>":
$start_row = $file_count - $show_amount;
break;
case "gopage":
// for page is page -1, so page 1 start from 0, etc
$start_row = ((($cms->action_value - 1) > 0) ? ($cms->action_value - 1) * $show_amount : 0);
$current_page = $cms->action_value;
break;
}
if ($cms->action == 'browse') {
// browse in the list of data
switch ($cms->action_id) {
case "<<<<":
$start_row = 0;
break;
case "<":
$start_row -= $show_amount;
break;
case ">":
$start_row += $show_amount;
break;
case ">>>>":
$start_row = $file_count - $show_amount;
break;
case "gopage":
// for page is page -1, so page 1 start from 0, etc
$start_row = ((($cms->action_value - 1) > 0) ? ($cms->action_value - 1) * $show_amount : 0);
$current_page = $cms->action_value;
break;
}
}
// check overflow
if ($start_row < 0)
$start_row = 0;
if ($start_row > $file_count)
$start_row = $file_count - $show_amount;
// check overflow
if ($start_row < 0) {
$start_row = 0;
}
if ($start_row > $file_count) {
$start_row = $file_count - $show_amount;
}
// if we have a "fresh_load"
if ($fresh_load)
{
$count = 1;
$q = "SELECT file_uid FROM file ";
if ($q_search_where)
$q .= $q_search_where;
$q .= "ORDER BY ".$sort_order." ".$sort_direction." ";
while ($res = $cms->db_return($q))
{
// if data_id is set and not file_id, go to the page where the current highlight is, but only if this is a "virgin" load of the page
if ($data_id && ($data_id == $res['file_uid']))
{
$current_page = floor(($count / $show_amount));
$start_row = $current_page * $show_amount;
$current_page ++;
}
$count ++;
}
}
// page forward/back buttons settings
if ($start_row > 0)
{
$cms->DATA['show_back'] = 1;
}
$cms->DATA['page_number'] = ceil($start_row / $show_amount) + 1;
$cms->DATA['page_count'] = ceil($file_count / $show_amount);
if ($cms->DATA['page_count'] > 2 && !$current_page)
{
$current_page = 1;
}
if (($start_row + $show_amount) < $file_count)
{
$cms->DATA['show_forward'] = 1;
}
$q = "SELECT file_id, name_en, name_ja, file_name, online, mime_type, file_size, size_x, size_y, file_uid, type FROM file ";
// if search what, search in name_en, name_ja, file_name for the string
if ($q_search_where)
// if we have a "fresh_load"
if ($fresh_load) {
$count = 1;
$q = "SELECT file_uid FROM file ";
if ($q_search_where) {
$q .= $q_search_where;
}
$q .= "ORDER BY ".$sort_order." ".$sort_direction." ";
$q .= "LIMIT ".$show_amount." OFFSET ".$start_row;
while ($res = $cms->db_return($q))
{
$data_files[] = array (
'id' => $res['file_id'],
'name_en' => $res['name_en'],
'name_ja' => $res['name_ja'],
'file_name' => $res['file_name'],
'online' => $res['online'],
'mime_type' => $res['mime_type'],
'file_size' => $cms->adbByteStringFormat($res['file_size']),
'size_x' => $res['size_x'],
'size_y' => $res['size_y'],
'file_uid' => $res['file_uid'],
'file_type' => $res['type'],
'picture' => $cms->cache_pictures.$cms->adbCreateThumbnail(DEV_SCHEMA.'_'.$res['file_uid'], 80, 60, $res['type'], '', $cms->cache_pictures_root)
);
while ($res = $cms->db_return($q)) {
// if data_id is set and not file_id, go to the page where the current highlight is, but only if this is a "virgin" load of the page
if ($data_id && ($data_id == $res['file_uid'])) {
$current_page = floor(($count / $show_amount));
$start_row = $current_page * $show_amount;
$current_page ++;
}
$count ++;
}
}
$cms->DATA['show_type'] = $show_type;
$cms->DATA['data_files'] = $data_files;
$cms->DATA['view'] = $view;
$cms->DATA['images_path'] = MEDIA.$cms->data_path[$file_type];
// get vars for position (only when)
$cms->DATA['form_name'] = $form_name;
$cms->DATA['value_name'] = $value_name;
$cms->DATA['file_id'] = $file_id;
$cms->DATA['file_uid'] = $file_uid;
// page forward/back buttons settings
if ($start_row > 0) {
$cms->DATA['show_back'] = 1;
}
$cms->DATA['page_number'] = ceil($start_row / $show_amount) + 1;
$cms->DATA['page_count'] = ceil($file_count / $show_amount);
if ($cms->DATA['page_count'] > 2 && !$current_page) {
$current_page = 1;
}
if (($start_row + $show_amount) < $file_count) {
$cms->DATA['show_forward'] = 1;
}
// write back all the other vars
if (!($delete_done || $new_okay))
{
// data name
$cms->DATA['file_name'] = $file_name;
$cms->DATA['name_en'] = $name_en;
$cms->DATA['name_ja'] = $name_ja;
$cms->DATA['mime_type'] = $mime_type;
$cms->DATA['file_size'] = $file_size;
$cms->DATA['size_x'] = $size_x;
$cms->DATA['size_y'] = $size_y;
$cms->DATA['online'] = $online;
$cms->DATA['picture'] = $picture;
$cms->DATA['picture_small'] = $picture_small;
$cms->DATA['file_type'] = $file_type;
}
$cms->DATA['sort_order_list'] = $sort_order_list;
$cms->DATA['sort_order'] = $sort_order;
$cms->DATA['sort_direction_list'] = $sort_direction_list;
$cms->DATA['sort_direction'] = $sort_direction;
$cms->DATA['search_what'] = $search_what;
$cms->DATA['current_page'] = $current_page;
$cms->DATA['yesno_list'] = $yesno_list;
$cms->DATA['start_row'] = $start_row;
$cms->DATA['show_amount'] = $show_amount;
if ($data_id)
$cms->DATA['data_id'] = $data_id;
$cms->DATA['top'] = 0;
$cms->DATA['left'] = 0;
$q = "SELECT file_id, name_en, name_ja, file_name, online, mime_type, file_size, size_x, size_y, file_uid, type FROM file ";
// if search what, search in name_en, name_ja, file_name for the string
if ($q_search_where) {
$q .= $q_search_where;
}
$q .= "ORDER BY ".$sort_order." ".$sort_direction." ";
$q .= "LIMIT ".$show_amount." OFFSET ".$start_row;
while ($res = $cms->db_return($q)) {
$data_files[] = array (
'id' => $res['file_id'],
'name_en' => $res['name_en'],
'name_ja' => $res['name_ja'],
'file_name' => $res['file_name'],
'online' => $res['online'],
'mime_type' => $res['mime_type'],
'file_size' => $cms->adbByteStringFormat($res['file_size']),
'size_x' => $res['size_x'],
'size_y' => $res['size_y'],
'file_uid' => $res['file_uid'],
'file_type' => $res['type'],
'picture' => $cms->cache_pictures.$cms->adbCreateThumbnail(DEV_SCHEMA.'_'.$res['file_uid'], 80, 60, $res['type'], '', $cms->cache_pictures_root)
);
}
//------------------------------ processing data end
$cms->DATA['show_type'] = $show_type;
$cms->DATA['data_files'] = $data_files;
$cms->DATA['view'] = $view;
$cms->DATA['images_path'] = MEDIA.$cms->data_path[$file_type];
// get vars for position (only when)
$cms->DATA['form_name'] = $form_name;
$cms->DATA['value_name'] = $value_name;
$cms->DATA['file_id'] = $file_id;
$cms->DATA['file_uid'] = $file_uid;
//------------------------------ smarty start
require("smarty.inc");
//------------------------------ smarty end
// write back all the other vars
if (!($delete_done || $new_okay)) {
// data name
$cms->DATA['file_name'] = $file_name;
$cms->DATA['name_en'] = $name_en;
$cms->DATA['name_ja'] = $name_ja;
$cms->DATA['mime_type'] = $mime_type;
$cms->DATA['file_size'] = $file_size;
$cms->DATA['size_x'] = $size_x;
$cms->DATA['size_y'] = $size_y;
$cms->DATA['online'] = $online;
$cms->DATA['picture'] = $picture;
$cms->DATA['picture_small'] = $picture_small;
$cms->DATA['file_type'] = $file_type;
}
$cms->DATA['sort_order_list'] = $sort_order_list;
$cms->DATA['sort_order'] = $sort_order;
$cms->DATA['sort_direction_list'] = $sort_direction_list;
$cms->DATA['sort_direction'] = $sort_direction;
$cms->DATA['search_what'] = $search_what;
$cms->DATA['current_page'] = $current_page;
$cms->DATA['yesno_list'] = $yesno_list;
$cms->DATA['start_row'] = $start_row;
$cms->DATA['show_amount'] = $show_amount;
if ($data_id) {
$cms->DATA['data_id'] = $data_id;
}
$cms->DATA['top'] = 0;
$cms->DATA['left'] = 0;
//------------------------------ footer
require("footer.inc");
//------------------------------ footer
//------------------------------ processing data end
?>
//------------------------------ smarty start
require("smarty.inc");
//------------------------------ smarty end
//------------------------------ footer
require("footer.inc");
//------------------------------ footer

View File

@@ -1,13 +1,12 @@
<?
/********************************************************************
* AUTHOR: Clemens Schwaighofer
* CREATED: 2008/08/14
* SHORT DESCRIPTION:
* URL redirect header
* HISTORY:
*********************************************************************/
/********************************************************************
* AUTHOR: Clemens Schwaighofer
* CREATED: 2008/08/14
* SHORT DESCRIPTION:
* URL redirect header
* HISTORY:
*********************************************************************/
// print debug messages
echo $login->print_error_msg();
echo $cms->print_error_msg();
?>
// print debug messages
echo $login->print_error_msg();
echo $cms->print_error_msg();

View File

@@ -1,102 +1,104 @@
<?
/********************************************************************
* AUTHOR: Clemens Schwaighofer
* CREATED: 2008/08/01
* SHORT DESCRIPTION:
* URL redirect header
* HISTORY:
*********************************************************************/
/********************************************************************
* AUTHOR: Clemens Schwaighofer
* CREATED: 2008/08/01
* SHORT DESCRIPTION:
* URL redirect header
* HISTORY:
*********************************************************************/
//------------------------------ variable init start
// for dev test we set full error reporting; writes everything, except E_ERROR into logs/php_error-<day>.log
if ($DEBUG_ALL && $ENABLE_ERROR_HANDLING)
include("libs/Error.Handling.inc");
// predefine vars
$lang = '';
$messages = array ();
// import all POST vars
extract($_POST, EXTR_SKIP);
//------------------------------ variable init end
//------------------------------ variable init start
// for dev test we set full error reporting; writes everything, except E_ERROR into logs/php_error-<day>.log
if ($DEBUG_ALL && $ENABLE_ERROR_HANDLING) {
include("libs/Error.Handling.inc");
}
// predefine vars
$lang = '';
$messages = array ();
// import all POST vars
extract($_POST, EXTR_SKIP);
//------------------------------ variable init end
//------------------------------ library include start
// set output to quiet for load of classes & session settings
ob_start();
require("config.inc");
// set the session name
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
// login class, DB connections & Admin class, Smarty extension
foreach (array ('Login', 'Admin.Backend', 'Smarty.Extend') as $class)
_spl_autoload('Class.'.$class.'.inc');
//------------------------------ library include end
//------------------------------ library include start
// set output to quiet for load of classes & session settings
ob_start();
require("config.inc");
//------------------------------ basic variable settings start
// set encoding
if (!isset($encoding))
$encoding = DEFAULT_ENCODING;
// set the default lang, if not given
if (session_id() && $_SESSION['DEFAULT_LANG'])
$lang = $_SESSION['DEFAULT_LANG'];
elseif (!$lang)
$lang = DEFAULT_LANG;
// end the stop of the output flow, but only if we didn't request a csv file download
if (array_key_exists('action', $_POST) && $_POST['action'] != 'download_csv')
{
header("Content-type: text/html; charset=".$encoding);
ob_end_flush();
}
//------------------------------ basic variable settings start
// login class, DB connections & Admin class, Smarty extension
foreach (array ('Login', 'Admin.Backend', 'Smarty.Extend') as $class) {
_spl_autoload('Class.'.$class.'.inc');
}
//------------------------------ library include end
//------------------------------ class init start
// login & page access check
$login = new login($DB_CONFIG[LOGIN_DB], $lang);
// post login lang check
if ($_SESSION['DEFAULT_LANG'])
$lang = $_SESSION['DEFAULT_LANG'];
// create smarty object
$smarty = new SmartyML($lang);
// create new DB class
$cms = new AdminBackend($DB_CONFIG[MAIN_DB], $lang);
// set search path to the default DB schema
$cms->db_exec("SET search_path TO ".DB_SCHEMA);
// the menu show flag (what menu to show)
$cms->menu_show_flag = 'main';
// db nfo
$cms->db_info();
// set acl
$cms->acl = $login->acl;
//------------------------------ class init end
//------------------------------ basic variable settings start
// set encoding
if (!isset($encoding)) {
$encoding = DEFAULT_ENCODING;
}
// set the default lang, if not given
if (session_id() && $_SESSION['DEFAULT_LANG']) {
$lang = $_SESSION['DEFAULT_LANG'];
} elseif (!$lang) {
$lang = DEFAULT_LANG;
}
// end the stop of the output flow, but only if we didn't request a csv file download
if (array_key_exists('action', $_POST) && $_POST['action'] != 'download_csv') {
header("Content-type: text/html; charset=".$encoding);
ob_end_flush();
}
//------------------------------ basic variable settings start
//------------------------------ logging start
// log backend data
// data part creation
$data = array (
'_SESSION' => $_SESSION,
'_GET' => $_GET,
'_POST' => $_POST,
'_FILES' => $_FILES
);
// log action
// no log if login
if (!$login->login)
$cms->adbEditLog('Submit', $data, 'BINARY');
//------------------------------ logging end
//------------------------------ class init start
// login & page access check
$login = new login($DB_CONFIG[LOGIN_DB], $lang);
// post login lang check
if ($_SESSION['DEFAULT_LANG']) {
$lang = $_SESSION['DEFAULT_LANG'];
}
// create smarty object
$smarty = new SmartyML($lang);
// create new DB class
$cms = new AdminBackend($DB_CONFIG[MAIN_DB], $lang);
// set search path to the default DB schema
$cms->db_exec("SET search_path TO ".DB_SCHEMA);
// the menu show flag (what menu to show)
$cms->menu_show_flag = 'main';
// db nfo
$cms->db_info();
// set acl
$cms->acl = $login->acl;
//------------------------------ class init end
//------------------------------ page rights start
// flag if to show the edit access id drop down list
// check if we have more than one EA ID
$cms->DATA['show_ea_extra'] = $login->acl['acl']['show_ea_extra'];
//------------------------------ page rights ned
//------------------------------ logging start
// log backend data
// data part creation
$data = array (
'_SESSION' => $_SESSION,
'_GET' => $_GET,
'_POST' => $_POST,
'_FILES' => $_FILES
);
// log action
// no log if login
if (!$login->login) {
$cms->adbEditLog('Submit', $data, 'BINARY');
}
//------------------------------ logging end
// automatic hide for DEBUG messages on live server
// can be overridden when setting DEBUG_ALL_OVERRIDE on top of the script (for emergency debugging of one page only)
if ((TARGET == 'live' || TARGET == 'remote') && !$DEBUG_ALL_OVERRIDE)
{
$login->debug_output_all = 0;
$login->echo_output_all = 0;
$login->print_output_all = 0;
$cms->debug_output_all = 0;
$cms->echo_output_all = 0;
$cms->print_output_all = 0;
}
$cms->DATA['JS_DEBUG'] = DEBUG;
?>
//------------------------------ page rights start
// flag if to show the edit access id drop down list
// check if we have more than one EA ID
$cms->DATA['show_ea_extra'] = $login->acl['acl']['show_ea_extra'];
//------------------------------ page rights ned
// automatic hide for DEBUG messages on live server
// can be overridden when setting DEBUG_ALL_OVERRIDE on top of the script (for emergency debugging of one page only)
if ((TARGET == 'live' || TARGET == 'remote') && !$DEBUG_ALL_OVERRIDE) {
$login->debug_output_all = 0;
$login->echo_output_all = 0;
$login->print_output_all = 0;
$cms->debug_output_all = 0;
$cms->echo_output_all = 0;
$cms->print_output_all = 0;
}
$cms->DATA['JS_DEBUG'] = DEBUG;

View File

@@ -1,53 +1,51 @@
<?
/********************************************************************
* AUTHOR: Clemens Schwaighofer
* CREATED: 2005/07/19
* SHORT DESCRIPTION:
* preset date variables
* HISTORY:
*********************************************************************/
/********************************************************************
* AUTHOR: Clemens Schwaighofer
* CREATED: 2005/07/19
* SHORT DESCRIPTION:
* preset date variables
* HISTORY:
*********************************************************************/
$day_short[1] = "Mon";
$day_short[2] = "Tue";
$day_short[3] = "Wed";
$day_short[4] = "Thu";
$day_short[5] = "Fri";
$day_short[6] = "Sat";
$day_short[7] = "Sun";
$day_short[1] = "Mon";
$day_short[2] = "Tue";
$day_short[3] = "Wed";
$day_short[4] = "Thu";
$day_short[5] = "Fri";
$day_short[6] = "Sat";
$day_short[7] = "Sun";
$day_long[1] = "Monday";
$day_long[2] = "Tuesday";
$day_long[3] = "Wednesday";
$day_long[4] = "Thursday";
$day_long[5] = "Friday";
$day_long[6] = "Saturday";
$day_long[7] = "Sunday";
$day_long[1] = "Monday";
$day_long[2] = "Tuesday";
$day_long[3] = "Wednesday";
$day_long[4] = "Thursday";
$day_long[5] = "Friday";
$day_long[6] = "Saturday";
$day_long[7] = "Sunday";
// monate
$month_long[1] = "January";
$month_long[2] = "February";
$month_long[3] = "March";
$month_long[4] = "April";
$month_long[5] = "May";
$month_long[6] = "June";
$month_long[7] = "July";
$month_long[8] = "August";
$month_long[9] = "September";
$month_long[10] = "October";
$month_long[11] = "November";
$month_long[12] = "December";
// monate
$month_long[1] = "January";
$month_long[2] = "February";
$month_long[3] = "March";
$month_long[4] = "April";
$month_long[5] = "May";
$month_long[6] = "June";
$month_long[7] = "July";
$month_long[8] = "August";
$month_long[9] = "September";
$month_long[10] = "October";
$month_long[11] = "November";
$month_long[12] = "December";
$month_short[1] = "Jan";
$month_short[2] = "Feb";
$month_short[3] = "Mar";
$month_short[4] = "Apr";
$month_short[5] = "May";
$month_short[6] = "Jun";
$month_short[7] = "Jul";
$month_short[8] = "Aug";
$month_short[9] = "Sep";
$month_short[10] = "Oct";
$month_short[11] = "Nov";
$month_short[12] = "Dec";
?>
$month_short[1] = "Jan";
$month_short[2] = "Feb";
$month_short[3] = "Mar";
$month_short[4] = "Apr";
$month_short[5] = "May";
$month_short[6] = "Jun";
$month_short[7] = "Jul";
$month_short[8] = "Aug";
$month_short[9] = "Sep";
$month_short[10] = "Oct";
$month_short[11] = "Nov";
$month_short[12] = "Dec";

View File

@@ -1,113 +1,119 @@
<?
/********************************************************************
* AUTHOR: Clemens Schwaighofer
* CREATED: 2007/09/03
* SHORT DESCRIPTION:
* set paths & language variables
* HISTORY:
*********************************************************************/
/********************************************************************
* AUTHOR: Clemens Schwaighofer
* CREATED: 2007/09/03
* SHORT DESCRIPTION:
* set paths & language variables
* HISTORY:
*********************************************************************/
// template path
if ($_SESSION['TEMPLATE'])
$TEMPLATE = $_SESSION['TEMPLATE'];
elseif ($LOCAL_TEMPLATE)
$TEMPLATE = $LOCAL_TEMPLATE;
else
$TEMPLATE = DEFAULT_TEMPLATE;
$TEMPLATE_DIR = $TEMPLATE.'/';
// master template
if (!$MASTER_TEMPLATE_NAME)
$MASTER_TEMPLATE_NAME = MASTER_TEMPLATE_NAME;
// template path
if ($_SESSION['TEMPLATE']) {
$TEMPLATE = $_SESSION['TEMPLATE'];
} elseif ($LOCAL_TEMPLATE) {
$TEMPLATE = $LOCAL_TEMPLATE;
} else {
$TEMPLATE = DEFAULT_TEMPLATE;
}
$TEMPLATE_DIR = $TEMPLATE.'/';
// master template
if (!$MASTER_TEMPLATE_NAME) {
$MASTER_TEMPLATE_NAME = MASTER_TEMPLATE_NAME;
}
// just emergency fallback for language
// set encoding
if ($_SESSION['DEFAULT_CHARSET'])
$encoding = $_SESSION['DEFAULT_CHARSET'];
elseif (!$encoding)
$encoding = DEFAULT_ENCODING;
// just emergency fallback for language
if ($_SESSION['DEFAULT_LANG'])
$lang = $_SESSION['DEFAULT_LANG'];
elseif (!$lang)
$lang = DEFAULT_LANG;
// create the char lang encoding
$lang_short = substr($lang, 0, 2);
// just emergency fallback for language
// set encoding
if ($_SESSION['DEFAULT_CHARSET']) {
$encoding = $_SESSION['DEFAULT_CHARSET'];
} elseif (!$encoding) {
$encoding = DEFAULT_ENCODING;
}
// just emergency fallback for language
if ($_SESSION['DEFAULT_LANG']) {
$lang = $_SESSION['DEFAULT_LANG'];
} elseif (!$lang) {
$lang = DEFAULT_LANG;
}
// create the char lang encoding
$lang_short = substr($lang, 0, 2);
// set include & template names
$CONTENT_INCLUDE = str_replace(".php", ".tpl", $cms->page_name);
$FORM_NAME = !isset($FORM_NAME) || !$FORM_NAME ? str_replace(".php", "", $cms->page_name) : $FORM_NAME;
// set local page title
$L_TITLE = ucfirst(str_replace('_', ' ', $cms->get_page_name(1))).' - '.$G_TITLE;
// strip tpl and replace it with inc
// php include file per page
$cms->INC_TEMPLATE_NAME = str_replace(".tpl", ".inc", $CONTENT_INCLUDE);
// javascript include per page
$cms->JS_TEMPLATE_NAME = str_replace(".tpl", ".js", $CONTENT_INCLUDE);
// css per page
$cms->CSS_TEMPLATE_NAME = str_replace(".tpl", ".css", $CONTENT_INCLUDE);
// special CSS file
$cms->CSS_SPECIAL_TEMPLATE_NAME = @$CSS_NAME;
// special JS file
$cms->JS_SPECIAL_TEMPLATE_NAME = @$JS_NAME;
// set include & template names
$CONTENT_INCLUDE = str_replace(".php", ".tpl", $cms->page_name);
$FORM_NAME = !isset($FORM_NAME) || !$FORM_NAME ? str_replace(".php", "", $cms->page_name) : $FORM_NAME;
// set local page title
$L_TITLE = ucfirst(str_replace('_', ' ', $cms->get_page_name(1))).' - '.$G_TITLE;
// strip tpl and replace it with inc
// php include file per page
$cms->INC_TEMPLATE_NAME = str_replace(".tpl", ".inc", $CONTENT_INCLUDE);
// javascript include per page
$cms->JS_TEMPLATE_NAME = str_replace(".tpl", ".js", $CONTENT_INCLUDE);
// css per page
$cms->CSS_TEMPLATE_NAME = str_replace(".tpl", ".css", $CONTENT_INCLUDE);
// special CSS file
$cms->CSS_SPECIAL_TEMPLATE_NAME = @$CSS_NAME;
// special JS file
$cms->JS_SPECIAL_TEMPLATE_NAME = @$JS_NAME;
// set basic template path (tmp)
$smarty->setTemplateDir(LAYOUT.$TEMPLATE_DIR.TEMPLATES.'/');
$cms->lang_dir = LAYOUT.$TEMPLATE_DIR.LANG."/";
$cms->includes = LAYOUT.$TEMPLATE_DIR.INCLUDES."/";
$cms->javascript = LAYOUT.$TEMPLATE_DIR.JS."/";
$cms->css = LAYOUT.$TEMPLATE_DIR.CSS."/";
$cms->pictures = LAYOUT.$TEMPLATE_DIR.IMAGES."/";
$cms->cache_pictures = LAYOUT.$TEMPLATE_DIR.CACHE.IMAGES.'/';
$cms->cache_pictures_root = ROOT.$cms->cache_pictures;
if (!is_dir($cms->cache_pictures_root))
mkdir($cms->cache_pictures_root);
$template_set = $TEMPLATE;
// set basic template path (tmp)
$smarty->setTemplateDir(LAYOUT.$TEMPLATE_DIR.TEMPLATES.'/');
$cms->lang_dir = LAYOUT.$TEMPLATE_DIR.LANG."/";
$cms->includes = LAYOUT.$TEMPLATE_DIR.INCLUDES."/";
$cms->javascript = LAYOUT.$TEMPLATE_DIR.JS."/";
$cms->css = LAYOUT.$TEMPLATE_DIR.CSS."/";
$cms->pictures = LAYOUT.$TEMPLATE_DIR.IMAGES."/";
$cms->cache_pictures = LAYOUT.$TEMPLATE_DIR.CACHE.IMAGES.'/';
$cms->cache_pictures_root = ROOT.$cms->cache_pictures;
if (!is_dir($cms->cache_pictures_root)) {
mkdir($cms->cache_pictures_root);
}
$template_set = $TEMPLATE;
// if we don't find the master template, set the template path back AND set the insert template as absolute path
if (!file_exists(ROOT.$smarty->getTemplateDir()[0]."/".MASTER_TEMPLATE_NAME))
{
if (file_exists(ROOT.$smarty->getTemplateDir()[0]."/".$TEMPLATE_NAME))
$TEMPLATE_NAME = ROOT.$smarty->getTemplateDir()[0]."/".$TEMPLATE_NAME;
$smarty->setTemplateDir(LAYOUT.DEFAULT_TEMPLATE.TEMPLATES);
$template_set = DEFAULT_TEMPLATE;
// if we don't find the master template, set the template path back AND set the insert template as absolute path
if (!file_exists(ROOT.$smarty->getTemplateDir()[0]."/".MASTER_TEMPLATE_NAME)) {
if (file_exists(ROOT.$smarty->getTemplateDir()[0]."/".$TEMPLATE_NAME)) {
$TEMPLATE_NAME = ROOT.$smarty->getTemplateDir()[0]."/".$TEMPLATE_NAME;
}
$smarty->setTemplateDir(LAYOUT.DEFAULT_TEMPLATE.TEMPLATES);
$template_set = DEFAULT_TEMPLATE;
} elseif (!file_exists(ROOT.$smarty->getTemplateDir()[0]."/".$TEMPLATE_NAME)) {
// check if the template exists in the template path, if not, set path to to default
elseif (!file_exists(ROOT.$smarty->getTemplateDir()[0]."/".$TEMPLATE_NAME))
{
$smarty->setTemplateDir(LAYOUT.DEFAULT_TEMPLATE.TEMPLATES);
$template_set = DEFAULT_TEMPLATE;
}
// loop to check if dir exists
// check if file exists, if not reset to default path
$smarty->setTemplateDir(LAYOUT.DEFAULT_TEMPLATE.TEMPLATES);
$template_set = DEFAULT_TEMPLATE;
}
// loop to check if dir exists
// check if file exists, if not reset to default path
// check if the javascript folder exists in the template path, if not fall back to default
if (!is_dir($cms->javascript))
$cms->javascript = LAYOUT.DEFAULT_TEMPLATE.JS."/";
// check if lang_dir folder exists in the template path, if not fall back to default
if (!is_dir($cms->lang_dir))
$cms->lang_dir = LAYOUT.DEFAULT_TEMPLATE.LANG."/";
// check if include folder exists in the template path, if not fall back to default
if (!is_dir($cms->includes))
$cms->includes = LAYOUT.DEFAULT_TEMPLATE.INCLUDES."/";
// check if css folder exists in the template path, if not fall back to default
if (!is_dir($cms->css))
$cms->css = LAYOUT.DEFAULT_TEMPLATE.CSS."/";
if (!is_dir($cms->pictures))
$cms->pictures = LAYOUT.DEFAULT_TEMPLATE.PICTURES.'/';
if (!is_dir($cms->cache_pictures))
$cms->cache_pictures = LAYOUT.DEFAULT_TEMPLATE.CACHE.IMAGES.'/';
// check if the javascript folder exists in the template path, if not fall back to default
if (!is_dir($cms->javascript)) {
$cms->javascript = LAYOUT.DEFAULT_TEMPLATE.JS."/";
}
// check if lang_dir folder exists in the template path, if not fall back to default
if (!is_dir($cms->lang_dir)) {
$cms->lang_dir = LAYOUT.DEFAULT_TEMPLATE.LANG."/";
}
// check if include folder exists in the template path, if not fall back to default
if (!is_dir($cms->includes)) {
$cms->includes = LAYOUT.DEFAULT_TEMPLATE.INCLUDES."/";
}
// check if css folder exists in the template path, if not fall back to default
if (!is_dir($cms->css)) {
$cms->css = LAYOUT.DEFAULT_TEMPLATE.CSS."/";
}
if (!is_dir($cms->pictures)) {
$cms->pictures = LAYOUT.DEFAULT_TEMPLATE.PICTURES.'/';
}
if (!is_dir($cms->cache_pictures)) {
$cms->cache_pictures = LAYOUT.DEFAULT_TEMPLATE.CACHE.IMAGES.'/';
}
// if the template_dir is != DEFAULT_TEMPLATE, then try to make a lang switch
// if the default lang is not like the lang given, switch lang
if (false === strstr(LAYOUT.DEFAULT_TEMPLATE.LANG, $cms->lang_dir) || strcasecmp(DEFAULT_LANG, $lang))
{
$cms->debug('LANG', 'Orig: '.LAYOUT.DEFAULT_TEMPLATE.LANG.', New: '.$cms->lang_dir.' | Orig Lang: '.DEFAULT_LANG.', New Lang: '.$lang);
$cms->l->l10nReloadMOfile($lang, $cms->lang_dir);
$smarty->l10n->l10nReloadMOfile($lang, $cms->lang_dir);
}
// if the template_dir is != DEFAULT_TEMPLATE, then try to make a lang switch
// if the default lang is not like the lang given, switch lang
if (false === strstr(LAYOUT.DEFAULT_TEMPLATE.LANG, $cms->lang_dir) || strcasecmp(DEFAULT_LANG, $lang)) {
$cms->debug('LANG', 'Orig: '.LAYOUT.DEFAULT_TEMPLATE.LANG.', New: '.$cms->lang_dir.' | Orig Lang: '.DEFAULT_LANG.', New Lang: '.$lang);
$cms->l->l10nReloadMOfile($lang, $cms->lang_dir);
$smarty->l10n->l10nReloadMOfile($lang, $cms->lang_dir);
}
// $cms->debug("LANGUAGE", "L: $lang | ".$cms->lang_dir." | MO File: ".$cms->l->mofile);
$cms->debug("LANGUAGE", "SL: ".$_SESSION['DEFAULT_CHARSET']." | ".$_SESSION['LANG']." | ".$_SESSION['DEFAULT_LANG']);
$cms->debug("TEMPLATE", "P: ".$smarty->getTemplateDir()[0]);
?>
$cms->debug("LANGUAGE", "SL: ".$_SESSION['DEFAULT_CHARSET']." | ".$_SESSION['LANG']." | ".$_SESSION['DEFAULT_LANG']);
$cms->debug("TEMPLATE", "P: ".$smarty->getTemplateDir()[0]);

View File

@@ -1,103 +1,96 @@
<?
/********************************************************************
* AUTHOR: Clemens Schwaighofer
* CREATED: 2005/07/12
* SHORT DESCRIPTION:
* default smarty vars, and create output template for smarty
* HISTORY:
*********************************************************************/
/********************************************************************
* AUTHOR: Clemens Schwaighofer
* CREATED: 2005/07/12
* SHORT DESCRIPTION:
* default smarty vars, and create output template for smarty
* HISTORY:
*********************************************************************/
// trigger flags
$cms->HEADER['USE_PROTOTYPE'] = USE_PROTOTYPE;
// scriptacolous, can only be used with prototype
if (USE_PROTOTYPE)
$cms->HEADER['USE_SCRIPTACULOUS'] = USE_SCRIPTACULOUS;
// jquery and prototype should not be used together
$cms->HEADER['USE_JQUERY'] = USE_JQUERY; // don't use either of those two toger
// trigger flags
$cms->HEADER['USE_PROTOTYPE'] = USE_PROTOTYPE;
// scriptacolous, can only be used with prototype
if (USE_PROTOTYPE) {
$cms->HEADER['USE_SCRIPTACULOUS'] = USE_SCRIPTACULOUS;
}
// jquery and prototype should not be used together
$cms->HEADER['USE_JQUERY'] = USE_JQUERY; // don't use either of those two toger
// set basic template path (tmp)
// paths are set in the 'set_paths.inc' file
// set basic template path (tmp)
// paths are set in the 'set_paths.inc' file
// check if we have an external file with the template name
if (file_exists($cms->includes.$cms->INC_TEMPLATE_NAME) && is_file($cms->includes.$cms->INC_TEMPLATE_NAME))
{
include($cms->includes.$cms->INC_TEMPLATE_NAME);
}
// additional per page Javascript include
$cms->JS_INCLUDE = '';
if (file_exists($cms->javascript.$cms->JS_TEMPLATE_NAME) && is_file($cms->javascript.$cms->JS_TEMPLATE_NAME))
{
$cms->JS_INCLUDE = $cms->javascript.$cms->JS_TEMPLATE_NAME;
}
// per page css file
$cms->CSS_INCLUDE = '';
if (file_exists($cms->css.$cms->CSS_TEMPLATE_NAME) && is_file($cms->css.$cms->CSS_TEMPLATE_NAME))
{
$cms->CSS_INCLUDE = $cms->css.$cms->CSS_TEMPLATE_NAME;
}
// optional CSS file
$cms->CSS_SPECIAL_INCLUDE = '';
if (file_exists($cms->css.$cms->CSS_SPECIAL_TEMPLATE_NAME) && is_file($cms->css.$cms->CSS_SPECIAL_TEMPLATE_NAME))
{
$cms->CSS_SPECIAL_INCLUDE = $cms->css.$cms->CSS_SPECIAL_TEMPLATE_NAME;
}
// optional JS file
$cms->JS_SPECIAL_INCLUDE = '';
if (file_exists($cms->javascript.$cms->JS_SPECIAL_TEMPLATE_NAME) && is_file($cms->javascript.$cms->JS_SPECIAL_TEMPLATE_NAME))
{
$cms->JS_SPECIAL_INCLUDE = $cms->javascript.$cms->JS_SPECIAL_TEMPLATE_NAME;
}
// check if we have an external file with the template name
if (file_exists($cms->includes.$cms->INC_TEMPLATE_NAME) && is_file($cms->includes.$cms->INC_TEMPLATE_NAME)) {
include($cms->includes.$cms->INC_TEMPLATE_NAME);
}
// additional per page Javascript include
$cms->JS_INCLUDE = '';
if (file_exists($cms->javascript.$cms->JS_TEMPLATE_NAME) && is_file($cms->javascript.$cms->JS_TEMPLATE_NAME)) {
$cms->JS_INCLUDE = $cms->javascript.$cms->JS_TEMPLATE_NAME;
}
// per page css file
$cms->CSS_INCLUDE = '';
if (file_exists($cms->css.$cms->CSS_TEMPLATE_NAME) && is_file($cms->css.$cms->CSS_TEMPLATE_NAME)) {
$cms->CSS_INCLUDE = $cms->css.$cms->CSS_TEMPLATE_NAME;
}
// optional CSS file
$cms->CSS_SPECIAL_INCLUDE = '';
if (file_exists($cms->css.$cms->CSS_SPECIAL_TEMPLATE_NAME) && is_file($cms->css.$cms->CSS_SPECIAL_TEMPLATE_NAME)) {
$cms->CSS_SPECIAL_INCLUDE = $cms->css.$cms->CSS_SPECIAL_TEMPLATE_NAME;
}
// optional JS file
$cms->JS_SPECIAL_INCLUDE = '';
if (file_exists($cms->javascript.$cms->JS_SPECIAL_TEMPLATE_NAME) && is_file($cms->javascript.$cms->JS_SPECIAL_TEMPLATE_NAME)) {
$cms->JS_SPECIAL_INCLUDE = $cms->javascript.$cms->JS_SPECIAL_TEMPLATE_NAME;
}
// the actual include files for javascript (per page)
$cms->HEADER['JS_INCLUDE'] = $cms->JS_INCLUDE;
$cms->HEADER['CSS_INCLUDE'] = $cms->CSS_INCLUDE;
$cms->HEADER['CSS_SPECIAL_INCLUDE'] = $cms->CSS_SPECIAL_INCLUDE;
$cms->HEADER['JS_SPECIAL_INCLUDE'] = $cms->JS_SPECIAL_INCLUDE;
// paths to the files
$cms->DATA['includes'] = $cms->includes;
$cms->DATA['js'] = $cms->javascript;
$cms->DATA['css'] = $cms->css;
$cms->DATA['pictures'] = $cms->pictures;
// the actual include files for javascript (per page)
$cms->HEADER['JS_INCLUDE'] = $cms->JS_INCLUDE;
$cms->HEADER['CSS_INCLUDE'] = $cms->CSS_INCLUDE;
$cms->HEADER['CSS_SPECIAL_INCLUDE'] = $cms->CSS_SPECIAL_INCLUDE;
$cms->HEADER['JS_SPECIAL_INCLUDE'] = $cms->JS_SPECIAL_INCLUDE;
// paths to the files
$cms->DATA['includes'] = $cms->includes;
$cms->DATA['js'] = $cms->javascript;
$cms->DATA['css'] = $cms->css;
$cms->DATA['pictures'] = $cms->pictures;
// default CMS settings
// define all needed smarty stuff for the general HTML/page building
$cms->HEADER['CSS'] = CSS;
$cms->HEADER['JS'] = JS;
$cms->HEADER['ENCODING'] = $encoding;
$cms->HEADER['DEFAULT_ENCODING'] = DEFAULT_ENCODING;
$cms->HEADER['STYLESHEET'] = $EDIT_STYLESHEET;
$cms->HEADER['JAVASCRIPT'] = $EDIT_JAVASCRIPT;
// html title
$cms->HEADER['HTML_TITLE'] = (!isset($L_TITLE) || !$L_TITLE) ? $cms->l->__($G_TITLE) : $cms->l->__($L_TITLE);
$cms->DATA['table_width'] = $PAGE_WIDTH ? $PAGE_WIDTH : PAGE_WIDTH;
// default CMS settings
// define all needed smarty stuff for the general HTML/page building
$cms->HEADER['CSS'] = CSS;
$cms->HEADER['JS'] = JS;
$cms->HEADER['ENCODING'] = $encoding;
$cms->HEADER['DEFAULT_ENCODING'] = DEFAULT_ENCODING;
$cms->HEADER['STYLESHEET'] = $EDIT_STYLESHEET;
$cms->HEADER['JAVASCRIPT'] = $EDIT_JAVASCRIPT;
// html title
$cms->HEADER['HTML_TITLE'] = (!isset($L_TITLE) || !$L_TITLE) ? $cms->l->__($G_TITLE) : $cms->l->__($L_TITLE);
$cms->DATA['table_width'] = $PAGE_WIDTH ? $PAGE_WIDTH : PAGE_WIDTH;
// messages = array('msg' =>, 'class' => 'error/warning/...')
$cms->DATA['messages'] = $cms->messages;
// messages = array('msg' =>, 'class' => 'error/warning/...')
$cms->DATA['messages'] = $cms->messages;
// top menu
$cms->DATA['nav_menu'] = $cms->adbTopMenu();
// the page name
$cms->DATA['page_name'] = $cms->page_name;
// user name
$cms->DATA['USER_NAME'] = $_SESSION['USER_NAME'];
// the template part to include into the body
$cms->DATA['TEMPLATE_NAME'] = $TEMPLATE_NAME;
$cms->DATA['CONTENT_INCLUDE'] = $CONTENT_INCLUDE;
// LANG
$cms->DATA['LANG'] = $lang;
$cms->DATA['TINYMCE_LANG'] = $lang_short;
// top menu
$cms->DATA['nav_menu'] = $cms->adbTopMenu();
// the page name
$cms->DATA['page_name'] = $cms->page_name;
// user name
$cms->DATA['USER_NAME'] = $_SESSION['USER_NAME'];
// the template part to include into the body
$cms->DATA['TEMPLATE_NAME'] = $TEMPLATE_NAME;
$cms->DATA['CONTENT_INCLUDE'] = $CONTENT_INCLUDE;
// LANG
$cms->DATA['LANG'] = $lang;
$cms->DATA['TINYMCE_LANG'] = $lang_short;
// debug data, if DEBUG flag is on, this data is print out
$cms->DEBUG_DATA['debug_error_msg'] = $cms->running_time();
$cms->DEBUG_DATA['DEBUG'] = @$DEBUG_TMPL;
// debug data, if DEBUG flag is on, this data is print out
$cms->DEBUG_DATA['debug_error_msg'] = $cms->running_time();
$cms->DEBUG_DATA['DEBUG'] = @$DEBUG_TMPL;
// create main data array
$cms->CONTENT_DATA = array_merge($cms->HEADER, $cms->DATA, $cms->DEBUG_DATA);
// data is 1:1 mapping (all vars, values, etc)
while (list($key, $value) = each($cms->CONTENT_DATA))
{
$smarty->assign($key, $value);
}
$smarty->display($MASTER_TEMPLATE_NAME, $TEMPLATE.$lang, $TEMPLATE.$lang);
?>
// create main data array
$cms->CONTENT_DATA = array_merge($cms->HEADER, $cms->DATA, $cms->DEBUG_DATA);
// data is 1:1 mapping (all vars, values, etc)
while (list($key, $value) = each($cms->CONTENT_DATA)) {
$smarty->assign($key, $value);
}
$smarty->display($MASTER_TEMPLATE_NAME, $TEMPLATE.$lang, $TEMPLATE.$lang);

View File

@@ -1,21 +1,20 @@
<?
$ENABLE_ERROR_HANDLING = 0;
$DEBUG_ALL_OVERRIDE = 0; // set to 1 to debug on live/remote server locations
$DEBUG_ALL = 1;
$PRINT_ALL = 1;
$DB_DEBUG = 1;
$LOG_PER_RUN = 1;
$ENABLE_ERROR_HANDLING = 0;
$DEBUG_ALL_OVERRIDE = 0; // set to 1 to debug on live/remote server locations
$DEBUG_ALL = 1;
$PRINT_ALL = 1;
$DB_DEBUG = 1;
$LOG_PER_RUN = 1;
define('USE_DATABASE', true);
require("header.inc");
$MASTER_TEMPLATE_NAME = 'main_body.tpl';
$TEMPLATE_NAME = 'smarty_test.tpl';
$PAGE_WIDTH = 750;
require("set_paths.inc");
define('USE_DATABASE', true);
require("header.inc");
$MASTER_TEMPLATE_NAME = 'main_body.tpl';
$TEMPLATE_NAME = 'smarty_test.tpl';
$PAGE_WIDTH = 750;
require("set_paths.inc");
// smarty test
$cms->DATA['SMARTY_TEST'] = 'Test Data';
// smarty test
$cms->DATA['SMARTY_TEST'] = 'Test Data';
require("smarty.inc");
require("footer.inc");
?>
require("smarty.inc");
require("footer.inc");

View File

@@ -1,77 +1,76 @@
<?
$edit_access = array (
"table_array" => array (
"edit_access_id" => array (
"value" => $GLOBALS["edit_access_id"],
"type" => "hidden",
"pk" => 1
),
"name" => array (
"value" => $GLOBALS["name"],
"output_name" => $this->l->__("Access Group Name"),
"mandatory" => 1,
"type" => "text",
"error_check" => "alphanumericspace|unique"
),
"description" => array (
"value" => $GLOBALS["description"],
"output_name" => $this->l->__("Description"),
"type" => "textarea"
),
"color" => array (
"value" => $GLOBALS["color"],
"output_name" => $this->l->__("Color"),
"mandatory" => 0,
"type" => "text",
"size" => 6,
"length" => 6,
"error_check" => "custom",
"error_regex" => "/[\dA-Fa-f]{6}/",
"error_example" => "F6A544"
)
$edit_access = array (
"table_array" => array (
"edit_access_id" => array (
"value" => $GLOBALS["edit_access_id"],
"type" => "hidden",
"pk" => 1
),
"table_name" => "edit_access",
"load_query" => "SELECT edit_access_id, name FROM edit_access ORDER BY name",
"show_fields" => array (
array (
"name" => "name"
)
"name" => array (
"value" => $GLOBALS["name"],
"output_name" => $this->l->__("Access Group Name"),
"mandatory" => 1,
"type" => "text",
"error_check" => "alphanumericspace|unique"
),
"element_list" => array (
"edit_access_data" => array (
"output_name" => "Edit Access Data",
"type" => "reference_data", # is not a sub table read and connect, but only a sub table with data
"max_empty" => 5, # maxium visible if no data is set, if filled add this number to visible
"prefix" => "ead",
"elements" => array (
"edit_access_data_id" => array (
"output_name" => "Activate",
"type" => "hidden",
"int" => 1,
"pk_id" => 1
),
"name" => array (
"type" => "text",
"error_check" => "alphanumeric|unique",
"output_name" => "Name"
),
"value" => array (
"type" => "text",
"output_name" => "Value"
),
"enabled" => array (
"type" => "checkbox",
"output_name" => "Activate",
"int" => 1,
"element_list" => array(1)
),
"edit_access_id" => array (
"int" => 1,
"type" => "hidden",
"fk_id" => 1 # reference main key from master table above
)
"description" => array (
"value" => $GLOBALS["description"],
"output_name" => $this->l->__("Description"),
"type" => "textarea"
),
"color" => array (
"value" => $GLOBALS["color"],
"output_name" => $this->l->__("Color"),
"mandatory" => 0,
"type" => "text",
"size" => 6,
"length" => 6,
"error_check" => "custom",
"error_regex" => "/[\dA-Fa-f]{6}/",
"error_example" => "F6A544"
)
),
"table_name" => "edit_access",
"load_query" => "SELECT edit_access_id, name FROM edit_access ORDER BY name",
"show_fields" => array (
array (
"name" => "name"
)
),
"element_list" => array (
"edit_access_data" => array (
"output_name" => "Edit Access Data",
"type" => "reference_data", # is not a sub table read and connect, but only a sub table with data
"max_empty" => 5, # maxium visible if no data is set, if filled add this number to visible
"prefix" => "ead",
"elements" => array (
"edit_access_data_id" => array (
"output_name" => "Activate",
"type" => "hidden",
"int" => 1,
"pk_id" => 1
),
"name" => array (
"type" => "text",
"error_check" => "alphanumeric|unique",
"output_name" => "Name"
),
"value" => array (
"type" => "text",
"output_name" => "Value"
),
"enabled" => array (
"type" => "checkbox",
"output_name" => "Activate",
"int" => 1,
"element_list" => array(1)
),
"edit_access_id" => array (
"int" => 1,
"type" => "hidden",
"fk_id" => 1 # reference main key from master table above
)
)
)
);
?>
)
);

View File

@@ -1,100 +1,99 @@
<?
$edit_groups = array (
"table_array" => array (
"edit_group_id" => array (
"value" => $GLOBALS["edit_group_id"],
"pk" => 1,
"type" => "hidden"
),
"enabled" => array (
"value" => $GLOBALS["enabled"],
"output_name" => "Enabled",
"int" => 1,
"type" => "binary",
"element_list" => array (
"1" => "Yes",
"0" => "No"
)
),
"name" => array (
"value" => $GLOBALS["name"],
"output_name" => "Group Name",
"type" => "text",
"mandatory" => 1
),
"edit_access_right_id" => array (
"value" => $GLOBALS["edit_access_right_id"],
"output_name" => "Group Level",
"mandatory" => 1,
"int" => 1,
"type" => "drop_down_db",
"query" => "SELECT edit_access_right_id, name FROM edit_access_right ORDER BY level"
),
"edit_scheme_id" => array (
"value" => $GLOBALS["edit_scheme_id"],
"output_name" => "Group Scheme",
"int_null" => 1,
"type" => "drop_down_db",
"query" => "SELECT edit_scheme_id, name FROM edit_scheme WHERE enabled = 1 ORDER BY name"
$edit_groups = array (
"table_array" => array (
"edit_group_id" => array (
"value" => $GLOBALS["edit_group_id"],
"pk" => 1,
"type" => "hidden"
),
"enabled" => array (
"value" => $GLOBALS["enabled"],
"output_name" => "Enabled",
"int" => 1,
"type" => "binary",
"element_list" => array (
"1" => "Yes",
"0" => "No"
)
),
"load_query" => "SELECT edit_group_id, name, enabled FROM edit_group ORDER BY name",
"table_name" => "edit_group",
"show_fields" => array (
array (
"name" => "name"
),
array (
"name" => "enabled",
"binary" => array ("Yes", "No"),
"before_value" => "Enabled: "
)
"name" => array (
"value" => $GLOBALS["name"],
"output_name" => "Group Name",
"type" => "text",
"mandatory" => 1
),
"element_list" => array (
"edit_page_access" => array (
"output_name" => "Pages",
"mandatory" => 1,
"delete" => 0, // set then reference entries are deleted, else the "enable" flag is only set
"enable_name" => "enable_page_access",
"prefix" => "epa",
"read_data" => array (
"table_name" => "edit_page",
"pk_id" => "edit_page_id",
"name" => "name",
"order" => "order_number"
),
"elements" => array (
"edit_page_access_id" => array (
"output_name" => "Activate",
"type" => "hidden",
"int" => 1,
"pk_id" => 1
),
"enabled" => array (
"type" => "checkbox",
"output_name" => "Activate",
"int" => 1,
"element_list" => array(1)
),
"edit_access_right_id" => array (
"type" => "drop_down_db",
"output_name" => "Access Level",
"int" => 1,
"preset" => 1, // first of the select
"query" => "SELECT edit_access_right_id, name FROM edit_access_right ORDER BY level"
),
"edit_page_id" => array (
"int" => 1,
"type" => "hidden"
)
/*,
"edit_default" => array (
"output_name" => "Default",
"type" => "radio",
"mandatory" => 1
)*/
)
) // edit pages ggroup
"edit_access_right_id" => array (
"value" => $GLOBALS["edit_access_right_id"],
"output_name" => "Group Level",
"mandatory" => 1,
"int" => 1,
"type" => "drop_down_db",
"query" => "SELECT edit_access_right_id, name FROM edit_access_right ORDER BY level"
),
"edit_scheme_id" => array (
"value" => $GLOBALS["edit_scheme_id"],
"output_name" => "Group Scheme",
"int_null" => 1,
"type" => "drop_down_db",
"query" => "SELECT edit_scheme_id, name FROM edit_scheme WHERE enabled = 1 ORDER BY name"
)
);
?>
),
"load_query" => "SELECT edit_group_id, name, enabled FROM edit_group ORDER BY name",
"table_name" => "edit_group",
"show_fields" => array (
array (
"name" => "name"
),
array (
"name" => "enabled",
"binary" => array ("Yes", "No"),
"before_value" => "Enabled: "
)
),
"element_list" => array (
"edit_page_access" => array (
"output_name" => "Pages",
"mandatory" => 1,
"delete" => 0, // set then reference entries are deleted, else the "enable" flag is only set
"enable_name" => "enable_page_access",
"prefix" => "epa",
"read_data" => array (
"table_name" => "edit_page",
"pk_id" => "edit_page_id",
"name" => "name",
"order" => "order_number"
),
"elements" => array (
"edit_page_access_id" => array (
"output_name" => "Activate",
"type" => "hidden",
"int" => 1,
"pk_id" => 1
),
"enabled" => array (
"type" => "checkbox",
"output_name" => "Activate",
"int" => 1,
"element_list" => array(1)
),
"edit_access_right_id" => array (
"type" => "drop_down_db",
"output_name" => "Access Level",
"int" => 1,
"preset" => 1, // first of the select
"query" => "SELECT edit_access_right_id, name FROM edit_access_right ORDER BY level"
),
"edit_page_id" => array (
"int" => 1,
"type" => "hidden"
)
/*,
"edit_default" => array (
"output_name" => "Default",
"type" => "radio",
"mandatory" => 1
)*/
)
) // edit pages ggroup
)
);

View File

@@ -1,73 +1,72 @@
<?
$edit_languages=array (
"table_array" => array (
"edit_language_id" => array (
"value" => $GLOBALS["edit_language_id"],
"type" => "hidden",
"pk" => 1
),
"short_name" => array (
"value" => $GLOBALS["short_name"],
"output_name" => "Language (short)",
"mandatory" => 1,
"type" => "text",
"size" => 2,
"length" => 2
),
"long_name" => array (
"value" => $GLOBALS["long_name"],
"output_name" => "Language (long)",
"mandatory" => 1,
"type" => "text",
"size" => 40
),
"iso_name" => array (
"value" => $GLOBALS["iso_name"],
"output_name" => "ISO Code",
"mandatory" => 1,
"type" => "text"
),
"order_number" => array (
"value" => $GLOBALS["order_number"],
"int" => 1,
"order" => 1
),
"enabled" => array (
"value" => $GLOBALS["enabled"],
"output_name" => "Enabled",
"int" => 1,
"type" => "binary",
"element_list" => array (
"1" => "Yes",
"0" => "No"
)
),
"lang_default" => array (
"value" => $GLOBALS["lang_default"],
"output_name" => "Default Language",
"int" => 1,
"type" => "binary",
"element_list" => array (
"1" => "Yes",
"0" => "No"
)
$edit_languages=array (
"table_array" => array (
"edit_language_id" => array (
"value" => $GLOBALS["edit_language_id"],
"type" => "hidden",
"pk" => 1
),
"short_name" => array (
"value" => $GLOBALS["short_name"],
"output_name" => "Language (short)",
"mandatory" => 1,
"type" => "text",
"size" => 2,
"length" => 2
),
"long_name" => array (
"value" => $GLOBALS["long_name"],
"output_name" => "Language (long)",
"mandatory" => 1,
"type" => "text",
"size" => 40
),
"iso_name" => array (
"value" => $GLOBALS["iso_name"],
"output_name" => "ISO Code",
"mandatory" => 1,
"type" => "text"
),
"order_number" => array (
"value" => $GLOBALS["order_number"],
"int" => 1,
"order" => 1
),
"enabled" => array (
"value" => $GLOBALS["enabled"],
"output_name" => "Enabled",
"int" => 1,
"type" => "binary",
"element_list" => array (
"1" => "Yes",
"0" => "No"
)
),
"load_query" => "SELECT edit_language_id, long_name, iso_name, enabled FROM edit_language ORDER BY long_name",
"show_fields" => array (
array (
"name" => "long_name"
),
array (
"name" => "iso_name",
"before_value" => "ISO: "
),
array (
"name" => "enabled",
"before_value" => "Enabled: ",
"binary" => array ("Yes","No")
"lang_default" => array (
"value" => $GLOBALS["lang_default"],
"output_name" => "Default Language",
"int" => 1,
"type" => "binary",
"element_list" => array (
"1" => "Yes",
"0" => "No"
)
)
),
"load_query" => "SELECT edit_language_id, long_name, iso_name, enabled FROM edit_language ORDER BY long_name",
"show_fields" => array (
array (
"name" => "long_name"
),
"table_name" => "edit_language"
);
?>
array (
"name" => "iso_name",
"before_value" => "ISO: "
),
array (
"name" => "enabled",
"before_value" => "Enabled: ",
"binary" => array ("Yes","No")
)
),
"table_name" => "edit_language"
);

View File

@@ -1,38 +1,37 @@
<?
$edit_menu_group = array (
"table_array" => array (
"edit_menu_group_id" => array (
"value" => $GLOBALS["edit_menu_group_id"],
"type" => "hidden",
"pk" => 1
),
"name" => array (
"value" => $GLOBALS["name"],
"output_name" => $this->l->__("Group name"),
"mandatory" => 1,
"type" => "text"
),
"flag" => array (
"value" => $GLOBALS["flag"],
"output_name" => $this->l->__("Flag"),
"mandatory" => 1,
"type" => "text",
"error_check" => "alphanumeric|unique"
),
"order_number" => array (
"value" => $GLOBALS["order_number"],
"output_name" => "Group order",
"type" => "order",
"int" => 1,
"order" => 1
)
$edit_menu_group = array (
"table_array" => array (
"edit_menu_group_id" => array (
"value" => $GLOBALS["edit_menu_group_id"],
"type" => "hidden",
"pk" => 1
),
"table_name" => "edit_menu_group",
"load_query" => "SELECT edit_menu_group_id, name FROM edit_menu_group ORDER BY name",
"show_fields" => array (
array (
"name" => "name"
)
"name" => array (
"value" => $GLOBALS["name"],
"output_name" => $this->l->__("Group name"),
"mandatory" => 1,
"type" => "text"
),
"flag" => array (
"value" => $GLOBALS["flag"],
"output_name" => $this->l->__("Flag"),
"mandatory" => 1,
"type" => "text",
"error_check" => "alphanumeric|unique"
),
"order_number" => array (
"value" => $GLOBALS["order_number"],
"output_name" => "Group order",
"type" => "order",
"int" => 1,
"order" => 1
)
);
?>
),
"table_name" => "edit_menu_group",
"load_query" => "SELECT edit_menu_group_id, name FROM edit_menu_group ORDER BY name",
"show_fields" => array (
array (
"name" => "name"
)
)
);

View File

@@ -1,178 +1,177 @@
<?
$edit_pages = array (
"table_array" => array (
"edit_page_id" => array (
"value" => $GLOBALS["edit_page_id"],
"type" => "hidden",
"pk" => 1
),
"filename" => array (
"value" => $GLOBALS["filename"],
"output_name" => "Add File ...",
"mandatory" => 1,
"type" => "drop_down_db",
"query" => "SELECT DISTINCT temp_files.filename AS id, temp_files.filename AS name FROM temp_files LEFT JOIN edit_page ep ON temp_files.filename = ep.filename WHERE ep.filename IS NULL"
),
"name" => array (
"value" => $GLOBALS["name"],
"output_name" => "Page name",
"mandatory" => 1,
"type" => "text"
),
"order_number" => array (
"value" => $GLOBALS["order_number"],
"output_name" => "Page order",
"type" => "order",
"int" => 1,
"order" => 1
),
$edit_pages = array (
"table_array" => array (
"edit_page_id" => array (
"value" => $GLOBALS["edit_page_id"],
"type" => "hidden",
"pk" => 1
),
"filename" => array (
"value" => $GLOBALS["filename"],
"output_name" => "Add File ...",
"mandatory" => 1,
"type" => "drop_down_db",
"query" => "SELECT DISTINCT temp_files.filename AS id, temp_files.filename AS name FROM temp_files LEFT JOIN edit_page ep ON temp_files.filename = ep.filename WHERE ep.filename IS NULL"
),
"name" => array (
"value" => $GLOBALS["name"],
"output_name" => "Page name",
"mandatory" => 1,
"type" => "text"
),
"order_number" => array (
"value" => $GLOBALS["order_number"],
"output_name" => "Page order",
"type" => "order",
"int" => 1,
"order" => 1
),
/* "flag" => array (
"value" => $GLOBALS["flag"],
"output_name" => "Page Flag",
"type" => "drop_down_array",
"query" => array (
"0" => "0",
"1" => "1",
"2" => "2",
"3" => "3",
"4" => "4",
"5" => "5"
)
),*/
"online" => array (
"value" => $GLOBALS["online"],
"output_name" => "Online",
"int" => 1,
"type" => "binary",
"element_list" => array (
"1" => "Yes",
"0" => "No"
)
),
"menu" => array (
"value" => $GLOBALS["menu"],
"output_name" => "Menu",
"int" => 1,
"type" => "binary",
"element_list" => array (
"1" => "Yes",
"0" => "No"
)
),
"popup" => array (
"value" => $GLOBALS["popup"],
"output_name" => "Popup",
"int" => 1,
"type" => "binary",
"element_list" => array (
"1" => "Yes",
"0" => "No"
)
),
"popup_x" => array (
"value" => $GLOBALS["popup_x"],
"output_name" => "Popup Width",
"int_null" => 1,
"type" => "text",
"size" => 4,
"length" => 4
),
"popup_y" => array (
"value" => $GLOBALS["popup_y"],
"output_name" => "Popup Height",
"int_null" => 1,
"type" => "text",
"size" => 4,
"length" => 4
)/*,
"query_string" => array (
"value" => $GLOBALS["query_string"],
"output_name" => "Query String for Link",
"type" => "text",
"size" => "50"
)*/
),
"load_query" => "SELECT edit_page_id, filename, name, online, menu, popup FROM edit_page ORDER BY order_number",
"table_name" => "edit_page",
"show_fields" => array (
array (
"name" => "name"
),
array (
"name" => "filename",
"before_value" => "Filename: "
),
array(
"name" => "online",
"binary" => array("Yes","No"),
"before_value" => "Online: "
),
array(
"name" => "menu",
"binary" => array("Yes","No"),
"before_value" => "Menu: "
),
array(
"name" => "popup",
"binary" => array("Yes","No"),
"before_value" => "Popup: "
"value" => $GLOBALS["flag"],
"output_name" => "Page Flag",
"type" => "drop_down_array",
"query" => array (
"0" => "0",
"1" => "1",
"2" => "2",
"3" => "3",
"4" => "4",
"5" => "5"
)
),*/
"online" => array (
"value" => $GLOBALS["online"],
"output_name" => "Online",
"int" => 1,
"type" => "binary",
"element_list" => array (
"1" => "Yes",
"0" => "No"
)
),
"reference_arrays" => array (
"edit_visible_group" => array (
"table_name" => "edit_page_visible_group",
"other_table_pk" => "edit_visible_group_id",
"output_name" => "Visible Groups (access)",
"mandatory" => 1,
"select_size" => 10,
"selected" => $GLOBALS["edit_visible_group_id"],
"query" => 'SELECT edit_visible_group_id, \'Name: \' || name || \', \' || \'Flag: \' || flag FROM edit_visible_group ORDER BY name'
),
"edit_menu_group" => array (
"table_name" => "edit_page_menu_group",
"other_table_pk" => "edit_menu_group_id",
"output_name" => "Menu Groups (grouping)",
"mandatory" => 1,
"select_size" => 10,
"selected" => $GLOBALS["edit_menu_group_id"],
"query" => 'SELECT edit_menu_group_id, \'Name: \' || name || \', \' || \'Flag: \' || flag FROM edit_menu_group ORDER BY order_number'
"menu" => array (
"value" => $GLOBALS["menu"],
"output_name" => "Menu",
"int" => 1,
"type" => "binary",
"element_list" => array (
"1" => "Yes",
"0" => "No"
)
),
"popup" => array (
"value" => $GLOBALS["popup"],
"output_name" => "Popup",
"int" => 1,
"type" => "binary",
"element_list" => array (
"1" => "Yes",
"0" => "No"
)
),
"popup_x" => array (
"value" => $GLOBALS["popup_x"],
"output_name" => "Popup Width",
"int_null" => 1,
"type" => "text",
"size" => 4,
"length" => 4
),
"popup_y" => array (
"value" => $GLOBALS["popup_y"],
"output_name" => "Popup Height",
"int_null" => 1,
"type" => "text",
"size" => 4,
"length" => 4
)/*,
"query_string" => array (
"value" => $GLOBALS["query_string"],
"output_name" => "Query String for Link",
"type" => "text",
"size" => "50"
)*/
),
"load_query" => "SELECT edit_page_id, filename, name, online, menu, popup FROM edit_page ORDER BY order_number",
"table_name" => "edit_page",
"show_fields" => array (
array (
"name" => "name"
),
array (
"name" => "filename",
"before_value" => "Filename: "
),
array (
"name" => "online",
"binary" => array ("Yes","No"),
"before_value" => "Online: "
),
array (
"name" => "menu",
"binary" => array ("Yes","No"),
"before_value" => "Menu: "
),
array (
"name" => "popup",
"binary" => array ("Yes","No"),
"before_value" => "Popup: "
)
),
"reference_arrays" => array (
"edit_visible_group" => array (
"table_name" => "edit_page_visible_group",
"other_table_pk" => "edit_visible_group_id",
"output_name" => "Visible Groups (access)",
"mandatory" => 1,
"select_size" => 10,
"selected" => $GLOBALS["edit_visible_group_id"],
"query" => 'SELECT edit_visible_group_id, \'Name: \' || name || \', \' || \'Flag: \' || flag FROM edit_visible_group ORDER BY name'
),
"edit_menu_group" => array (
"table_name" => "edit_page_menu_group",
"other_table_pk" => "edit_menu_group_id",
"output_name" => "Menu Groups (grouping)",
"mandatory" => 1,
"select_size" => 10,
"selected" => $GLOBALS["edit_menu_group_id"],
"query" => 'SELECT edit_menu_group_id, \'Name: \' || name || \', \' || \'Flag: \' || flag FROM edit_menu_group ORDER BY order_number'
)
),
"element_list" => array (
"edit_query_string" => array (
"output_name" => "Query Strings",
"delete_name" => "remove_query_string",
"prefix" => "eqs",
"elements" => array (
"name" => array (
"output_name" => "Name",
"type" => "text",
"error_check" => "unique|alphanumeric",
"mandatory" => 1
),
"value" => array (
"output_name" => "Value",
"type" => "text"
),
"enabled" => array (
"output_name" => "Enabled",
"int" => 1,
"type" => "checkbox",
"element_list" => array(1)
),
"dynamic" => array (
"output_name" => "Dynamic",
"int" => 1,
"type" => "checkbox",
"element_list" => array(1)
),
"edit_query_string_id" => array (
"type" => "hidden",
"pk_id" => 1
)
) // elements
) // query_string element list
) // element list
);
?>
),
"element_list" => array (
"edit_query_string" => array (
"output_name" => "Query Strings",
"delete_name" => "remove_query_string",
"prefix" => "eqs",
"elements" => array (
"name" => array (
"output_name" => "Name",
"type" => "text",
"error_check" => "unique|alphanumeric",
"mandatory" => 1
),
"value" => array (
"output_name" => "Value",
"type" => "text"
),
"enabled" => array (
"output_name" => "Enabled",
"int" => 1,
"type" => "checkbox",
"element_list" => array (1)
),
"dynamic" => array (
"output_name" => "Dynamic",
"int" => 1,
"type" => "checkbox",
"element_list" => array (1)
),
"edit_query_string_id" => array (
"type" => "hidden",
"pk_id" => 1
)
) // elements
) // query_string element list
) // element list
);

View File

@@ -1,55 +1,55 @@
<?
$edit_schemes = array (
"table_array" => array (
"edit_scheme_id" => array (
"value" => $GLOBALS["edit_scheme_id"],
"type" => "hidden",
"pk" => 1
),
"name" => array (
"value" => $GLOBALS["name"],
"output_name" => "Scheme Name",
"mandatory" => 1,
"type" => "text"
),
"header_color" => array (
"value" => $GLOBALS["header_color"],
"output_name" => "Header Color",
"mandatory" => 1,
"type" => "text",
"size" => 6,
"length" => 6,
"error_check" => "custom",
"error_regex" => "/[\dA-Fa-f]{6}/",
"error_example" => "F6A544"
),
"enabled" => array (
"value" => $GLOBALS["enabled"],
"output_name" => "Enabled",
"int" => 1,
"type" => "binary",
"element_list" => array (
"1" => "Yes",
"0" => "No"
)
),
"template" => array (
"value" => $GLOBALS["template"],
"output_name" => "Template",
"type" => "text"
$edit_schemes = array (
"table_array" => array (
"edit_scheme_id" => array (
"value" => $GLOBALS["edit_scheme_id"],
"type" => "hidden",
"pk" => 1
),
"name" => array (
"value" => $GLOBALS["name"],
"output_name" => "Scheme Name",
"mandatory" => 1,
"type" => "text"
),
"header_color" => array (
"value" => $GLOBALS["header_color"],
"output_name" => "Header Color",
"mandatory" => 1,
"type" => "text",
"size" => 6,
"length" => 6,
"error_check" => "custom",
"error_regex" => "/[\dA-Fa-f]{6}/",
"error_example" => "F6A544"
),
"enabled" => array (
"value" => $GLOBALS["enabled"],
"output_name" => "Enabled",
"int" => 1,
"type" => "binary",
"element_list" => array (
"1" => "Yes",
"0" => "No"
)
),
"table_name" => "edit_scheme",
"load_query" => "SELECT edit_scheme_id, name, enabled FROM edit_scheme ORDER BY name",
"show_fields" => array (
array (
"name" => "name"
),
array (
"name" => "enabled",
"binary" => array ("Yes", "No"),
"before_value" => "Enabled: "
)
"template" => array (
"value" => $GLOBALS["template"],
"output_name" => "Template",
"type" => "text"
)
); // main array
?>
),
"table_name" => "edit_scheme",
"load_query" => "SELECT edit_scheme_id, name, enabled FROM edit_scheme ORDER BY name",
"show_fields" => array (
array (
"name" => "name"
),
array (
"name" => "enabled",
"binary" => array ("Yes", "No"),
"before_value" => "Enabled: "
)
)
); // main array

View File

@@ -1,254 +1,253 @@
<?
$edit_users = array (
"table_array" => array (
"edit_user_id" => array (
"value" => $GLOBALS["edit_user_id"],
"type" => "hidden",
"pk" => 1,
"int" => 1
),
"username" => array (
"value" => $GLOBALS["username"],
"output_name" => "Username",
"mandatory" => 1,
"error_check" => "unique|alphanumericextended",
"type" => "text"
),
"password" => array (
"value" => $GLOBALS["password"],
"HIDDEN_value" => $GLOBALS["HIDDEN_password"],
"CONFIRM_value" => $GLOBALS["CONFIRM_password"],
"output_name" => "Password",
"mandatory" => 1,
"type" => "password", // later has to be password for encryption in database
'update' => array ( // connected field updates, and update data
'password_change_date' => array ( // db row to update
'type' => 'date', // type of field (int/text/date/etc)
'value' => 'NOW()' // value [todo: complex reference
)
$edit_users = array (
"table_array" => array (
"edit_user_id" => array (
"value" => $GLOBALS["edit_user_id"],
"type" => "hidden",
"pk" => 1,
"int" => 1
),
"username" => array (
"value" => $GLOBALS["username"],
"output_name" => "Username",
"mandatory" => 1,
"error_check" => "unique|alphanumericextended",
"type" => "text"
),
"password" => array (
"value" => $GLOBALS["password"],
"HIDDEN_value" => $GLOBALS["HIDDEN_password"],
"CONFIRM_value" => $GLOBALS["CONFIRM_password"],
"output_name" => "Password",
"mandatory" => 1,
"type" => "password", // later has to be password for encryption in database
'update' => array ( // connected field updates, and update data
'password_change_date' => array ( // db row to update
'type' => 'date', // type of field (int/text/date/etc)
'value' => 'NOW()' // value [todo: complex reference
)
),
// password date when first insert and password is set, needs special field with connection to password
'password_change_interval' => array (
'value' => $GLOBALS['password_change_interval'],
'output_name' => 'Password change interval',
'error_check' => 'intervalshort', // can be any date length format. n Y/M/D [not H/M/S], only one set, no combination
'type' => 'text',
'interval' => 1, // interval needs NULL write for empty
'size' => 5, // make it 5 chars long
'length' => 5
),
// password reset force interval, if set, user needs to reset password after X time period
"enabled" => array (
"value" => $GLOBALS["enabled"],
"output_name" => "Enabled",
"type" => "binary",
"int" => 1,
"element_list" => array (
"1" => "Yes",
"0" => "No"
)
),
"strict" => array (
"value" => $GLOBALS["strict"],
"output_name" => "Strict (Lock after errors)",
"type" => "binary",
"int" => 1,
"element_list" => array (
"1" => "Yes",
"0" => "No"
)
),
"locked" => array (
"value" => $GLOBALS["locked"],
"output_name" => "Locked (auto set if strict with errors)",
"type" => "binary",
"int" => 1,
"element_list" => array (
"1" => "Yes",
"0" => "No"
)
),
"admin" => array (
"value" => $GLOBALS["admin"],
"output_name" => "Admin",
"type" => "binary",
"int" => 1,
"element_list" => array (
"1" => "Yes",
"0" => "No"
)
),
"debug" => array (
"value" => $GLOBALS["debug"],
"output_name" => "Debug",
"type" => "binary",
"int" => 1,
"element_list" => array (
"1" => "Yes",
"0" => "No"
)
),
"db_debug" => array (
"value" => $GLOBALS["db_debug"],
"output_name" => "DB Debug",
"type" => "binary",
"int" => 1,
"element_list" => array (
"1" => "Yes",
"0" => "No"
)
),
"email" => array (
"value" => $GLOBALS["email"],
"output_name" => "E-Mail",
"type" => "text"
),
"last_name" => array (
"value" => $GLOBALS["last_name"],
"output_name" => "Last Name",
"type" => "text"
),
"first_name" => array (
"value" => $GLOBALS["first_name"],
"output_name" => "First Name",
"type" => "text"
),
"edit_language_id" => array (
"value" => $GLOBALS["edit_language_id"],
"output_name" => "Language",
"mandatory" => 1,
"int" => 1,
"type" => "drop_down_db",
"query" => "SELECT edit_language_id, long_name FROM edit_language WHERE enabled = 1 ORDER BY order_number"
),
"edit_scheme_id" => array (
"value" => $GLOBALS["edit_scheme_id"],
"output_name" => "Scheme",
"int_null" => 1,
"type" => "drop_down_db",
"query" => "SELECT edit_scheme_id, name FROM edit_scheme WHERE enabled = 1 ORDER BY name"
),
"edit_group_id" => array (
"value" => $GLOBALS["edit_group_id"],
"output_name" => "Group",
"int" => 1,
"type" => "drop_down_db",
"query" => "SELECT edit_group_id, name FROM edit_group WHERE enabled = 1 ORDER BY name",
"mandatory" => 1
),
"edit_access_right_id" => array (
"value" => $GLOBALS["edit_access_right_id"],
"output_name" => "User Level",
"mandatory" => 1,
"int" => 1,
"type" => "drop_down_db",
"query" => "SELECT edit_access_right_id, name FROM edit_access_right ORDER BY level"
),
"login_error_count" => array (
"output_name" => "Login error count",
"value" => $GLOBALS['login_error_count'],
"type" => "view",
"empty" => "0"
),
"login_error_date_last" => array (
"output_name" => "Last login error",
"value" => $GLOBALS['login_error_date_liast'],
"type" => "view",
"empty" => "-"
),
"login_error_date_first" => array (
"output_name" => "First login error",
"value" => $GLOBALS['login_error_date_first'],
"type" => "view",
"empty" => "-"
),
// planned delete lock flag
"protected" => array (
"value" => $GLOBALS["protected"],
"int" => 1
)
),
"load_query" => "SELECT edit_user_id, username, enabled, debug, db_debug, strict, locked, login_error_count FROM edit_user ORDER BY username",
"table_name" => "edit_user",
"show_fields" => array (
array (
"name" => "username"
),
array (
"name" => "enabled",
"binary" => array("Yes", "No"),
"before_value" => "Enabled: "
),
array (
"name" => "debug",
"binary" => array("Yes", "No"),
"before_value" => "Debug: "
),
array (
"name" => "db_debug",
"binary" => array("Yes", "No"),
"before_value" => "DB Debug: "
),
array (
"name" => "strict",
"binary" => array("Yes", "No"),
"before_value" => "Strict: "
),
array (
"name" => "locked",
"binary" => array("Yes", "No"),
"before_value" => "Locked: "
),
array (
"name" => "login_error_count",
"before_value" => "Errors: "
// password date when first insert and password is set, needs special field with connection to password
'password_change_interval' => array (
'value' => $GLOBALS['password_change_interval'],
'output_name' => 'Password change interval',
'error_check' => 'intervalshort', // can be any date length format. n Y/M/D [not H/M/S], only one set, no combination
'type' => 'text',
'interval' => 1, // interval needs NULL write for empty
'size' => 5, // make it 5 chars long
'length' => 5
),
// password reset force interval, if set, user needs to reset password after X time period
"enabled" => array (
"value" => $GLOBALS["enabled"],
"output_name" => "Enabled",
"type" => "binary",
"int" => 1,
"element_list" => array (
"1" => "Yes",
"0" => "No"
)
),
"element_list" => array (
"edit_access_user" => array (
"output_name" => "Accounts",
"mandatory" => 1,
"delete" => 0, // set then reference entries are deleted, else the "enable" flag is only set
"prefix" => "ecu",
"read_data" => array (
"table_name" => "edit_access",
"pk_id" => "edit_access_id",
"name" => "name",
"order" => "name"
),
"elements" => array (
"edit_access_user_id" => array (
"output_name" => "Activate",
"type" => "hidden",
"int" => 1,
"pk_id" => 1
),
"enabled" => array (
"type" => "checkbox",
"output_name" => "Activate",
"int" => 1,
"element_list" => array(1)
),
"edit_access_right_id" => array (
"type" => "drop_down_db",
"output_name" => "Access Level",
"preset" => 1, // first of the select
"int" => 1,
"query" => "SELECT edit_access_right_id, name FROM edit_access_right ORDER BY level"
),
"edit_default" => array (
"type" => "radio_group",
"output_name" => "Default",
"int" => 1,
"element_list" => "radio_group"
),
"edit_access_id" => array (
"type" => "hidden",
"int" => 1
)
)
) // edit pages ggroup
"strict" => array (
"value" => $GLOBALS["strict"],
"output_name" => "Strict (Lock after errors)",
"type" => "binary",
"int" => 1,
"element_list" => array (
"1" => "Yes",
"0" => "No"
)
),
"locked" => array (
"value" => $GLOBALS["locked"],
"output_name" => "Locked (auto set if strict with errors)",
"type" => "binary",
"int" => 1,
"element_list" => array (
"1" => "Yes",
"0" => "No"
)
),
"admin" => array (
"value" => $GLOBALS["admin"],
"output_name" => "Admin",
"type" => "binary",
"int" => 1,
"element_list" => array (
"1" => "Yes",
"0" => "No"
)
),
"debug" => array (
"value" => $GLOBALS["debug"],
"output_name" => "Debug",
"type" => "binary",
"int" => 1,
"element_list" => array (
"1" => "Yes",
"0" => "No"
)
),
"db_debug" => array (
"value" => $GLOBALS["db_debug"],
"output_name" => "DB Debug",
"type" => "binary",
"int" => 1,
"element_list" => array (
"1" => "Yes",
"0" => "No"
)
),
"email" => array (
"value" => $GLOBALS["email"],
"output_name" => "E-Mail",
"type" => "text"
),
"last_name" => array (
"value" => $GLOBALS["last_name"],
"output_name" => "Last Name",
"type" => "text"
),
"first_name" => array (
"value" => $GLOBALS["first_name"],
"output_name" => "First Name",
"type" => "text"
),
"edit_language_id" => array (
"value" => $GLOBALS["edit_language_id"],
"output_name" => "Language",
"mandatory" => 1,
"int" => 1,
"type" => "drop_down_db",
"query" => "SELECT edit_language_id, long_name FROM edit_language WHERE enabled = 1 ORDER BY order_number"
),
"edit_scheme_id" => array (
"value" => $GLOBALS["edit_scheme_id"],
"output_name" => "Scheme",
"int_null" => 1,
"type" => "drop_down_db",
"query" => "SELECT edit_scheme_id, name FROM edit_scheme WHERE enabled = 1 ORDER BY name"
),
"edit_group_id" => array (
"value" => $GLOBALS["edit_group_id"],
"output_name" => "Group",
"int" => 1,
"type" => "drop_down_db",
"query" => "SELECT edit_group_id, name FROM edit_group WHERE enabled = 1 ORDER BY name",
"mandatory" => 1
),
"edit_access_right_id" => array (
"value" => $GLOBALS["edit_access_right_id"],
"output_name" => "User Level",
"mandatory" => 1,
"int" => 1,
"type" => "drop_down_db",
"query" => "SELECT edit_access_right_id, name FROM edit_access_right ORDER BY level"
),
"login_error_count" => array (
"output_name" => "Login error count",
"value" => $GLOBALS['login_error_count'],
"type" => "view",
"empty" => "0"
),
"login_error_date_last" => array (
"output_name" => "Last login error",
"value" => $GLOBALS['login_error_date_liast'],
"type" => "view",
"empty" => "-"
),
"login_error_date_first" => array (
"output_name" => "First login error",
"value" => $GLOBALS['login_error_date_first'],
"type" => "view",
"empty" => "-"
),
// planned delete lock flag
"protected" => array (
"value" => $GLOBALS["protected"],
"int" => 1
)
);
?>
),
"load_query" => "SELECT edit_user_id, username, enabled, debug, db_debug, strict, locked, login_error_count FROM edit_user ORDER BY username",
"table_name" => "edit_user",
"show_fields" => array (
array (
"name" => "username"
),
array (
"name" => "enabled",
"binary" => array ("Yes", "No"),
"before_value" => "Enabled: "
),
array (
"name" => "debug",
"binary" => array ("Yes", "No"),
"before_value" => "Debug: "
),
array (
"name" => "db_debug",
"binary" => array ("Yes", "No"),
"before_value" => "DB Debug: "
),
array (
"name" => "strict",
"binary" => array ("Yes", "No"),
"before_value" => "Strict: "
),
array (
"name" => "locked",
"binary" => array ("Yes", "No"),
"before_value" => "Locked: "
),
array (
"name" => "login_error_count",
"before_value" => "Errors: "
)
),
"element_list" => array (
"edit_access_user" => array (
"output_name" => "Accounts",
"mandatory" => 1,
"delete" => 0, // set then reference entries are deleted, else the "enable" flag is only set
"prefix" => "ecu",
"read_data" => array (
"table_name" => "edit_access",
"pk_id" => "edit_access_id",
"name" => "name",
"order" => "name"
),
"elements" => array (
"edit_access_user_id" => array (
"output_name" => "Activate",
"type" => "hidden",
"int" => 1,
"pk_id" => 1
),
"enabled" => array (
"type" => "checkbox",
"output_name" => "Activate",
"int" => 1,
"element_list" => array (1)
),
"edit_access_right_id" => array (
"type" => "drop_down_db",
"output_name" => "Access Level",
"preset" => 1, // first of the select
"int" => 1,
"query" => "SELECT edit_access_right_id, name FROM edit_access_right ORDER BY level"
),
"edit_default" => array (
"type" => "radio_group",
"output_name" => "Default",
"int" => 1,
"element_list" => "radio_group"
),
"edit_access_id" => array (
"type" => "hidden",
"int" => 1
)
)
) // edit pages ggroup
)
);

View File

@@ -28,4 +28,3 @@
)
)
);
?>

View File

@@ -1,280 +1,275 @@
<?
/********************************************************************
* AUTHOR: Clemens "Gullevek" Schwaighofer (www.gullevek.org)
* CREATED: 2003/06/10
* SHORT DESCRIPTION:
* configuration file
* HISTORY:
*********************************************************************/
/********************************************************************
* AUTHOR: Clemens "Gullevek" Schwaighofer (www.gullevek.org)
* CREATED: 2003/06/10
* SHORT DESCRIPTION:
* configuration file
* HISTORY:
*********************************************************************/
/************* SESSION NAMES *************/
// backend
DEFINE('EDIT_SESSION_NAME', "<ADMIN SESSION NAME>");
// frontend
DEFINE('SESSION_NAME', "<SESSION NAME>");
/************* SESSION NAMES *************/
// backend
DEFINE('EDIT_SESSION_NAME', "<ADMIN SESSION NAME>");
// frontend
DEFINE('SESSION_NAME', "<SESSION NAME>");
// set the session name
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
/************* LANGUAGE / ENCODING *******/
DEFINE('DEFAULT_LANG', "en_utf8");
// default web page encoding setting
DEFINE('DEFAULT_ENCODING', "UTF-8");
/************* LANGUAGE / ENCODING *******/
DEFINE('DEFAULT_LANG', "en_utf8");
// default web page encoding setting
DEFINE('DEFAULT_ENCODING', "UTF-8");
/************* PATHS *********************/
// ** NEW/BETTER DIR DECLARATIONS **
// path to original file (if symlink)
DEFINE('DIR', __DIR__."/");
// libs base path based on DIR
DEFINE('LIBDIR', DIR.'libs/');
// SMARTY path based on DIR
DEFINE('SMARTYDIR', DIR.'Smarty/');
// table arrays for Class Form
DEFINE('TABLEARRAYDIR', DIR.'table_arrays/');
/************* PATHS *********************/
// ** NEW/BETTER DIR DECLARATIONS **
// path to original file (if symlink)
DEFINE('DIR', __DIR__."/");
// libs base path based on DIR
DEFINE('LIBDIR', DIR.'libs/');
// SMARTY path based on DIR
DEFINE('SMARTYDIR', DIR.'Smarty/');
// table arrays for Class Form
DEFINE('TABLEARRAYDIR', DIR.'table_arrays/');
// ** OLD DIR DECLARATIONS **
// path to document root of file called
DEFINE('ROOT', getcwd()."/");
// libs path
DEFINE('LIBS', "libs/");
// includes (strings, arrays for static, etc)
DEFINE('INCLUDES', "includes/");
// layout base path
DEFINE('LAYOUT', 'layout/');
// pic-root (compatible to CMS)
DEFINE('PICTURES', "images/");
// images
DEFINE('IMAGES', "images/");
// icons (below the images/ folder)
DEFINE('ICONS', 'icons/');
// media
DEFINE('MEDIA', "media/");
// flash-root (below media)
DEFINE('FLASH', "flash/");
// uploads (anything to keep)
DEFINE('UPLOADS', "uploads/");
// files (binaries) (below media)
DEFINE('BINARIES', "binaries/");
// files (videos) (below media)
DEFINE('VIDEOS', "videos/");
// files (documents) (below media)
DEFINE('DOCUMENTS', "documents/");
// files (pdfs) (below media)
DEFINE('PDFS', "documents/");
// css
DEFINE('CSS', "css/");
// js
DEFINE('JS', "javascript/");
// table arrays
DEFINE('TABLE_ARRAYS', "table_arrays/");
// smarty libs path
DEFINE('SMARTY', "Smarty/");
// po langs
DEFINE('LANG', "lang/");
// cache path
DEFINE('CACHE', "cache/");
// temp path
DEFINE('TMP', "tmp/");
// log files
DEFINE('LOG', 'log/');
// template base
DEFINE('TEMPLATES', "templates/");
// frontend template dir', only for admin
DEFINE('TEMPLATES_FRONTEND', "templates_frontend/");
// default template
DEFINE('DEFAULT_TEMPLATE', "default/");
// default template file
DEFINE('DEFAULT_TEMPLATE_FILE', 'default.tpl');
// ** OLD DIR DECLARATIONS **
// path to document root of file called
DEFINE('ROOT', getcwd()."/");
// libs path
DEFINE('LIBS', "libs/");
// includes (strings, arrays for static, etc)
DEFINE('INCLUDES', "includes/");
// layout base path
DEFINE('LAYOUT', 'layout/');
// pic-root (compatible to CMS)
DEFINE('PICTURES', "images/");
// images
DEFINE('IMAGES', "images/");
// icons (below the images/ folder)
DEFINE('ICONS', 'icons/');
// media
DEFINE('MEDIA', "media/");
// flash-root (below media)
DEFINE('FLASH', "flash/");
// uploads (anything to keep)
DEFINE('UPLOADS', "uploads/");
// files (binaries) (below media)
DEFINE('BINARIES', "binaries/");
// files (videos) (below media)
DEFINE('VIDEOS', "videos/");
// files (documents) (below media)
DEFINE('DOCUMENTS', "documents/");
// files (pdfs) (below media)
DEFINE('PDFS', "documents/");
// css
DEFINE('CSS', "css/");
// js
DEFINE('JS', "javascript/");
// table arrays
DEFINE('TABLE_ARRAYS', "table_arrays/");
// smarty libs path
DEFINE('SMARTY', "Smarty/");
// po langs
DEFINE('LANG', "lang/");
// cache path
DEFINE('CACHE', "cache/");
// temp path
DEFINE('TMP', "tmp/");
// log files
DEFINE('LOG', 'log/');
// template base
DEFINE('TEMPLATES', "templates/");
// frontend template dir', only for admin
DEFINE('TEMPLATES_FRONTEND', "templates_frontend/");
// default template
DEFINE('DEFAULT_TEMPLATE', "default/");
// default template file
DEFINE('DEFAULT_TEMPLATE_FILE', 'default.tpl');
/************* HASH / ACL DEFAULT / ERROR SETTINGS / SMARTY *************/
// default hash type
DEFINE('DEFAULT_HASH', 'sha256');
// default acl level
DEFINE('DEFAULT_ACL_LEVEL', 80);
// default levels for certain actions
/************* HASH / ACL DEFAULT / ERROR SETTINGS / SMARTY *************/
// default hash type
DEFINE('DEFAULT_HASH', 'sha256');
// default acl level
DEFINE('DEFAULT_ACL_LEVEL', 80);
// default levels for certain actions
/* DEFINE('DEFAULT_ACL_READ', 20);
DEFINE('DEFAULT_ACL_CONFIRM', 35);
DEFINE('DEFAULT_ACL_MOD', 40);
DEFINE('DEFAULT_ACL_WRITE', 60);
DEFINE('DEFAULT_ACL_SEND', 70);
DEFINE('DEFAULT_ACL_DEL', 80);
DEFINE('DEFAULT_ACL_ADMIN', 100); */
// SSL host name
DEFINE('DEFAULT_ACL_CONFIRM', 35);
DEFINE('DEFAULT_ACL_MOD', 40);
DEFINE('DEFAULT_ACL_WRITE', 60);
DEFINE('DEFAULT_ACL_SEND', 70);
DEFINE('DEFAULT_ACL_DEL', 80);
DEFINE('DEFAULT_ACL_ADMIN', 100); */
// SSL host name
// DEFINE('SSL_HOST', "ssl.host.name");
// error page strictness, Default is 3
// 1: only show error page as the last mesure if really no mid & aid can be loaded and found at all
// 2: if template not found, do not search, show error template
// 3: if default template is not found, show error template, do not fall back to default tree
// 4: very strict, even on normal fixable errors through error
// error page strictness, Default is 3
// 1: only show error page as the last mesure if really no mid & aid can be loaded and found at all
// 2: if template not found, do not search, show error template
// 3: if default template is not found, show error template, do not fall back to default tree
// 4: very strict, even on normal fixable errors through error
// DEFINE('ERROR_STRICT', 3);
// allow page caching in general, set to "FALSE" if you do debugging or development!
// allow page caching in general, set to "FALSE" if you do debugging or development!
// DEFINE('ALLOW_SMARTY_CACHE', FALSE);
// cache life time, in seconds, default here is 2 days (172800s)
// -1 is never expire cache
// cache life time, in seconds, default here is 2 days (172800s)
// -1 is never expire cache
// DEFINE('SMARTY_CACHE_LIFETIME', -1);
/************* LOGOUT ********************/
// logout target
DEFINE('LOGOUT_TARGET', '');
// password change allowed
DEFINE('PASSWORD_CHANGE', false);
/************* LOGOUT ********************/
// logout target
DEFINE('LOGOUT_TARGET', '');
// password change allowed
DEFINE('PASSWORD_CHANGE', false);
/************* AJAX / ACCESS *************/
// ajax request type
DEFINE('AJAX_REQUEST_TYPE', 'POST');
// what AJAX type to use
DEFINE('USE_PROTOTYPE', true);
DEFINE('USE_SCRIPTACULOUS', false);
DEFINE('USE_JQUERY', false);
/************* AJAX / ACCESS *************/
// ajax request type
DEFINE('AJAX_REQUEST_TYPE', 'POST');
// what AJAX type to use
DEFINE('USE_PROTOTYPE', true);
DEFINE('USE_SCRIPTACULOUS', false);
DEFINE('USE_JQUERY', false);
/************* LAYOUT WIDTHS *************/
DEFINE('PAGE_WIDTH', 800);
// the default template name
DEFINE('MASTER_TEMPLATE_NAME', 'main_body.tpl');
/************* LAYOUT WIDTHS *************/
DEFINE('PAGE_WIDTH', 800);
// the default template name
DEFINE('MASTER_TEMPLATE_NAME', 'main_body.tpl');
/************* QUEUE TABLE *************/
// if we have a dev/live system
// set_live is a per page/per item
// live_queue is a global queue system
/************* QUEUE TABLE *************/
// if we have a dev/live system
// set_live is a per page/per item
// live_queue is a global queue system
// DEFINE('QUEUE', 'live_queue');
/************* DB PATHS (PostgreSQL) *****************/
// schema names, can also be defined per <DB INFO>
DEFINE('PUBLIC_SCHEMA', 'public');
DEFINE('DEV_SCHEMA', 'public');
DEFINE('TEST_SCHEMA', 'public');
/************* DB PATHS (PostgreSQL) *****************/
// schema names, can also be defined per <DB INFO>
DEFINE('PUBLIC_SCHEMA', 'public');
DEFINE('DEV_SCHEMA', 'public');
DEFINE('TEST_SCHEMA', 'public');
// non constant part
/************* DB ACCESS *****************/
// please be VERY carefull only to change the right side
$DB_CONFIG = array(
"<db id>" => array (
"db_name" => "<database>",
"db_user" => "<user>",
"db_pass" => "<password>",
"db_host" => "<host>",
"db_port" => "5432",
"db_schema" => "public", // if not set, uses public
"db_type" => "pgsql",
"db_encoding" => '',
"db_ssl" => 'disable' // allow, disable, require, prefer
)
);
// non constant part
/************* DB ACCESS *****************/
// please be VERY carefull only to change the right side
$DB_CONFIG = array (
"<db id>" => array (
"db_name" => "<database>",
"db_user" => "<user>",
"db_pass" => "<password>",
"db_host" => "<host>",
"db_port" => "5432",
"db_schema" => "public", // if not set, uses public
"db_type" => "pgsql",
"db_encoding" => '',
"db_ssl" => 'disable' // allow, disable, require, prefer
)
);
// File and Folder paths
// ID is TARGET (first array element)
// File and Folder paths
// ID is TARGET (first array element)
// $PATHS["test"]["csv_path"] = "";
// $PATHS["test"]["perl_bin"] = "";
// $PATHS["test"]["redirect_url"] = "";
// each host has a different db_host
// development host
$DB_HOST['<host>'] = "<db id>";
// target host (live)
// each host has a different db_host
// development host
$DB_HOST['<host>'] = "<db id>";
// target host (live)
// $DB_TARGET_HOST['<host>'] = "<DB ID>";
// url redirect database
// url redirect database
// $DB_URL_REDIRECT_HOST['<host>'] = "<DB ID>";
// location flagging
// test/dev/live
$LOCATION['<host>'] = '<test|live|remote|etc>';
// show DEBUG override
// true/false
$DEBUG_FLAG['<host>'] = true;
// set postgresql paths (schemas)
$DB_PATH['<host>'] = PUBLIC_SCHEMA;
// location flagging
// test/dev/live
$LOCATION['<host>'] = '<test|live|remote|etc>';
// show DEBUG override
// true/false
$DEBUG_FLAG['<host>'] = true;
// set postgresql paths (schemas)
$DB_PATH['<host>'] = PUBLIC_SCHEMA;
// set the USE_DATABASE var, if there is nothing set, we assume TRUE
$USE_DATABASE = defined('USE_DATABASE') ? USE_DATABASE : true;
// set the USE_DATABASE var, if there is nothing set, we assume TRUE
$USE_DATABASE = defined('USE_DATABASE') ? USE_DATABASE : true;
// live frontend pages
// ** missing live domains **
// get the name without the port
list($HOST_NAME) = explode(":", $_SERVER['HTTP_HOST']);
if (!$DB_HOST[$HOST_NAME] && $USE_DATABASE)
{
echo "No matching DB config found. Contact Admin<br>";
exit -1;
}
// live frontend pages
// ** missing live domains **
// get the name without the port
list($HOST_NAME, $PORT) = array_pad(explode(":", $_SERVER['HTTP_HOST'], 2), 2, null);
if (!$DB_HOST[$HOST_NAME] && $USE_DATABASE) {
echo "No matching DB config found. Contact Admin<br>";
exit -1;
}
// define the static names
DEFINE('LOGIN_DB', $DB_HOST[$HOST_NAME]);
DEFINE('MAIN_DB', $DB_HOST[$HOST_NAME]);
DEFINE('DB_SCHEMA', $DB_PATH[$HOST_NAME]);
// define the static names
DEFINE('LOGIN_DB', $DB_HOST[$HOST_NAME]);
DEFINE('MAIN_DB', $DB_HOST[$HOST_NAME]);
DEFINE('DB_SCHEMA', $DB_PATH[$HOST_NAME]);
// DEFINE('TARGET_DB', $DB_TARGET_HOST[$HOST_NAME]);
// DEFINE('URL_REDIRECT_DB', $DB_URL_REDIRECT_HOST[$HOST_NAME]);
// next three if top is not set
// next three if top is not set
// DEFINE('DEV_SCHEMA', $DB_CONFIG[MAIN_DB]['db_schema']);
// DEFINE('TEST_SCHEMA', $DB_CONFIG[MAIN_DB]['db_schema']);
// DEFINE('PUBLIC_SCHEMA', $DB_CONFIG[TARGET_DB]['db_schema']);
DEFINE('LOGIN_DB_SCHEMA', 'public'); // where the edit* tables are
DEFINE('GLOBAL_DB_SCHEMA', 'public'); // where global tables are that are used by all schemas (eg queue tables for online, etc)
DEFINE('TARGET', $LOCATION[$HOST_NAME]);
DEFINE('LOGIN_DB_SCHEMA', 'public'); // where the edit* tables are
DEFINE('GLOBAL_DB_SCHEMA', 'public'); // where global tables are that are used by all schemas (eg queue tables for online, etc)
DEFINE('TARGET', $LOCATION[$HOST_NAME]);
// DEFINE('CSV_PATH', $PATHS[TARGET]['csv_path']);
// DEFINE('EXPORT_SCRIPT', $PATHS[TARGET]['perl_bin']);
// DEFINE('REDIRECT_URL', $PATHS[TARGET]['redirect_url']);
DEFINE('DEBUG', $DEBUG_FLAG[$HOST_NAME]);
DEFINE('SHOW_ALL_ERRORS', false); // show all errors if debug_all & show_error_handling are enabled
DEFINE('DEBUG', $DEBUG_FLAG[$HOST_NAME]);
DEFINE('SHOW_ALL_ERRORS', false); // show all errors if debug_all & show_error_handling are enabled
/************* GENERAL PAGE TITLE ********/
$G_TITLE = '<OVERALL PAGE TITLE>';
/************* GENERAL PAGE TITLE ********/
$G_TITLE = '<OVERALL PAGE TITLE>';
/************ STYLE SHEETS / JS **********/
$EDIT_STYLESHEET = "edit.css";
$EDIT_JAVASCRIPT = "edit.js";
/************ STYLE SHEETS / JS **********/
$EDIT_STYLESHEET = "edit.css";
$EDIT_JAVASCRIPT = "edit.js";
$STYLESHEET = "frontend.css";
$JAVASCRIPT = "frontend.js";
$STYLESHEET = "frontend.css";
$JAVASCRIPT = "frontend.js";
/************* CONVERT *******************/
$paths = array (
'/bin',
'/usr/bin',
'/usr/local/bin'
);
// find convert
foreach ($paths as $path)
{
if (file_exists($path."/convert") && is_file($path."/convert"))
{
// image magick convert location
DEFINE('CONVERT', $path."/convert");
}
/************* CONVERT *******************/
$paths = array (
'/bin',
'/usr/bin',
'/usr/local/bin'
);
// find convert
foreach ($paths as $path) {
if (file_exists($path."/convert") && is_file($path."/convert")) {
// image magick convert location
DEFINE('CONVERT', $path."/convert");
}
}
// turn off debug if debug flag is OFF
if (DEBUG == false)
{
$ECHO_ALL = 0;
$DEBUG_ALL = 0;
$PRINT_ALL = 0;
$DB_DEBUG = 0;
$ENABLE_ERROR_HANDLING = 0;
}
// turn off debug if debug flag is OFF
if (DEBUG == false) {
$ECHO_ALL = 0;
$DEBUG_ALL = 0;
$PRINT_ALL = 0;
$DB_DEBUG = 0;
$ENABLE_ERROR_HANDLING = 0;
}
// any other global definitons here
// any other global definitons here
// DEFINE('SOME_ID', <SOME VALUE>);
// function that will be called on top of each class include to load the class
function _spl_autoload($include_file)
{
// where to search for the files to include
$dirs = array (
LIBDIR,
SMARTYDIR,
TABLEARRAYDIR,
'',
LIBS,
SMARTY,
TABLE_ARRAYS,
__DIR__.'/'.LIBS,
__DIR__.'/'.SMARTY
);
// try to find and load the class ifle
foreach ($dirs as $folder)
{
if (file_exists($folder.$include_file))
{
require_once($folder.$include_file);
return true;
}
// function that will be called on top of each class include to load the class
function _spl_autoload($include_file)
{
// where to search for the files to include
$dirs = array (
LIBDIR,
SMARTYDIR,
TABLEARRAYDIR,
'',
LIBS,
SMARTY,
TABLE_ARRAYS,
__DIR__.'/'.LIBS,
__DIR__.'/'.SMARTY
);
// try to find and load the class ifle
foreach ($dirs as $folder) {
if (file_exists($folder.$include_file)) {
require_once($folder.$include_file);
return true;
}
return false;
}
?>
return false;
}

View File

@@ -1,280 +1,275 @@
<?
/********************************************************************
* AUTHOR: Clemens "Gullevek" Schwaighofer (www.gullevek.org)
* CREATED: 2003/06/10
* SHORT DESCRIPTION:
* configuration file
* HISTORY:
*********************************************************************/
/********************************************************************
* AUTHOR: Clemens "Gullevek" Schwaighofer (www.gullevek.org)
* CREATED: 2003/06/10
* SHORT DESCRIPTION:
* configuration file
* HISTORY:
*********************************************************************/
/************* SESSION NAMES *************/
// backend
DEFINE('EDIT_SESSION_NAME', "<ADMIN SESSION NAME>");
// frontend
DEFINE('SESSION_NAME', "<SESSION NAME>");
/************* SESSION NAMES *************/
// backend
DEFINE('EDIT_SESSION_NAME', "<ADMIN SESSION NAME>");
// frontend
DEFINE('SESSION_NAME', "<SESSION NAME>");
// set the session name
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
/************* LANGUAGE / ENCODING *******/
DEFINE('DEFAULT_LANG', "en_utf8");
// default web page encoding setting
DEFINE('DEFAULT_ENCODING', "UTF-8");
/************* LANGUAGE / ENCODING *******/
DEFINE('DEFAULT_LANG', "en_utf8");
// default web page encoding setting
DEFINE('DEFAULT_ENCODING', "UTF-8");
/************* PATHS *********************/
// ** NEW/BETTER DIR DECLARATIONS **
// path to original file (if symlink)
DEFINE('DIR', __DIR__."/");
// libs base path based on DIR
DEFINE('LIBDIR', DIR.'libs/');
// SMARTY path based on DIR
DEFINE('SMARTYDIR', DIR.'Smarty/');
// table arrays for Class Form
DEFINE('TABLEARRAYDIR', DIR.'table_arrays/');
/************* PATHS *********************/
// ** NEW/BETTER DIR DECLARATIONS **
// path to original file (if symlink)
DEFINE('DIR', __DIR__."/");
// libs base path based on DIR
DEFINE('LIBDIR', DIR.'libs/');
// SMARTY path based on DIR
DEFINE('SMARTYDIR', DIR.'Smarty/');
// table arrays for Class Form
DEFINE('TABLEARRAYDIR', DIR.'table_arrays/');
// ** OLD DIR DECLARATIONS **
// path to document root of file called
DEFINE('ROOT', getcwd()."/");
// libs path
DEFINE('LIBS', "libs/");
// includes (strings, arrays for static, etc)
DEFINE('INCLUDES', "includes/");
// layout base path
DEFINE('LAYOUT', 'layout/');
// pic-root (compatible to CMS)
DEFINE('PICTURES', "images/");
// images
DEFINE('IMAGES', "images/");
// icons (below the images/ folder)
DEFINE('ICONS', 'icons/');
// media
DEFINE('MEDIA', "media/");
// flash-root (below media)
DEFINE('FLASH', "flash/");
// uploads (anything to keep)
DEFINE('UPLOADS', "uploads/");
// files (binaries) (below media)
DEFINE('BINARIES', "binaries/");
// files (videos) (below media)
DEFINE('VIDEOS', "videos/");
// files (documents) (below media)
DEFINE('DOCUMENTS', "documents/");
// files (pdfs) (below media)
DEFINE('PDFS', "documents/");
// css
DEFINE('CSS', "css/");
// js
DEFINE('JS', "javascript/");
// table arrays
DEFINE('TABLE_ARRAYS', "table_arrays/");
// smarty libs path
DEFINE('SMARTY', "Smarty/");
// po langs
DEFINE('LANG', "lang/");
// cache path
DEFINE('CACHE', "cache/");
// temp path
DEFINE('TMP', "tmp/");
// log files
DEFINE('LOG', 'log/');
// template base
DEFINE('TEMPLATES', "templates/");
// frontend template dir', only for admin
DEFINE('TEMPLATES_FRONTEND', "templates_frontend/");
// default template
DEFINE('DEFAULT_TEMPLATE', "default/");
// default template file
DEFINE('DEFAULT_TEMPLATE_FILE', 'default.tpl');
// ** OLD DIR DECLARATIONS **
// path to document root of file called
DEFINE('ROOT', getcwd()."/");
// libs path
DEFINE('LIBS', "libs/");
// includes (strings, arrays for static, etc)
DEFINE('INCLUDES', "includes/");
// layout base path
DEFINE('LAYOUT', 'layout/');
// pic-root (compatible to CMS)
DEFINE('PICTURES', "images/");
// images
DEFINE('IMAGES', "images/");
// icons (below the images/ folder)
DEFINE('ICONS', 'icons/');
// media
DEFINE('MEDIA', "media/");
// flash-root (below media)
DEFINE('FLASH', "flash/");
// uploads (anything to keep)
DEFINE('UPLOADS', "uploads/");
// files (binaries) (below media)
DEFINE('BINARIES', "binaries/");
// files (videos) (below media)
DEFINE('VIDEOS', "videos/");
// files (documents) (below media)
DEFINE('DOCUMENTS', "documents/");
// files (pdfs) (below media)
DEFINE('PDFS', "documents/");
// css
DEFINE('CSS', "css/");
// js
DEFINE('JS', "javascript/");
// table arrays
DEFINE('TABLE_ARRAYS', "table_arrays/");
// smarty libs path
DEFINE('SMARTY', "Smarty/");
// po langs
DEFINE('LANG', "lang/");
// cache path
DEFINE('CACHE', "cache/");
// temp path
DEFINE('TMP', "tmp/");
// log files
DEFINE('LOG', 'log/');
// template base
DEFINE('TEMPLATES', "templates/");
// frontend template dir', only for admin
DEFINE('TEMPLATES_FRONTEND', "templates_frontend/");
// default template
DEFINE('DEFAULT_TEMPLATE', "default/");
// default template file
DEFINE('DEFAULT_TEMPLATE_FILE', 'default.tpl');
/************* HASH / ACL DEFAULT / ERROR SETTINGS / SMARTY *************/
// default hash type
DEFINE('DEFAULT_HASH', 'sha256');
// default acl level
DEFINE('DEFAULT_ACL_LEVEL', 80);
// default levels for certain actions
/************* HASH / ACL DEFAULT / ERROR SETTINGS / SMARTY *************/
// default hash type
DEFINE('DEFAULT_HASH', 'sha256');
// default acl level
DEFINE('DEFAULT_ACL_LEVEL', 80);
// default levels for certain actions
/* DEFINE('DEFAULT_ACL_READ', 20);
DEFINE('DEFAULT_ACL_CONFIRM', 35);
DEFINE('DEFAULT_ACL_MOD', 40);
DEFINE('DEFAULT_ACL_WRITE', 60);
DEFINE('DEFAULT_ACL_SEND', 70);
DEFINE('DEFAULT_ACL_DEL', 80);
DEFINE('DEFAULT_ACL_ADMIN', 100); */
// SSL host name
DEFINE('DEFAULT_ACL_CONFIRM', 35);
DEFINE('DEFAULT_ACL_MOD', 40);
DEFINE('DEFAULT_ACL_WRITE', 60);
DEFINE('DEFAULT_ACL_SEND', 70);
DEFINE('DEFAULT_ACL_DEL', 80);
DEFINE('DEFAULT_ACL_ADMIN', 100); */
// SSL host name
// DEFINE('SSL_HOST', "ssl.host.name");
// error page strictness, Default is 3
// 1: only show error page as the last mesure if really no mid & aid can be loaded and found at all
// 2: if template not found, do not search, show error template
// 3: if default template is not found, show error template, do not fall back to default tree
// 4: very strict, even on normal fixable errors through error
// error page strictness, Default is 3
// 1: only show error page as the last mesure if really no mid & aid can be loaded and found at all
// 2: if template not found, do not search, show error template
// 3: if default template is not found, show error template, do not fall back to default tree
// 4: very strict, even on normal fixable errors through error
// DEFINE('ERROR_STRICT', 3);
// allow page caching in general, set to "FALSE" if you do debugging or development!
// allow page caching in general, set to "FALSE" if you do debugging or development!
// DEFINE('ALLOW_SMARTY_CACHE', FALSE);
// cache life time, in seconds, default here is 2 days (172800s)
// -1 is never expire cache
// cache life time, in seconds, default here is 2 days (172800s)
// -1 is never expire cache
// DEFINE('SMARTY_CACHE_LIFETIME', -1);
/************* LOGOUT ********************/
// logout target
DEFINE('LOGOUT_TARGET', '');
// password change allowed
DEFINE('PASSWORD_CHANGE', false);
/************* LOGOUT ********************/
// logout target
DEFINE('LOGOUT_TARGET', '');
// password change allowed
DEFINE('PASSWORD_CHANGE', false);
/************* AJAX / ACCESS *************/
// ajax request type
DEFINE('AJAX_REQUEST_TYPE', 'POST');
// what AJAX type to use
DEFINE('USE_PROTOTYPE', true);
DEFINE('USE_SCRIPTACULOUS', false);
DEFINE('USE_JQUERY', false);
/************* AJAX / ACCESS *************/
// ajax request type
DEFINE('AJAX_REQUEST_TYPE', 'POST');
// what AJAX type to use
DEFINE('USE_PROTOTYPE', true);
DEFINE('USE_SCRIPTACULOUS', false);
DEFINE('USE_JQUERY', false);
/************* LAYOUT WIDTHS *************/
DEFINE('PAGE_WIDTH', 800);
// the default template name
DEFINE('MASTER_TEMPLATE_NAME', 'main_body.tpl');
/************* LAYOUT WIDTHS *************/
DEFINE('PAGE_WIDTH', 800);
// the default template name
DEFINE('MASTER_TEMPLATE_NAME', 'main_body.tpl');
/************* QUEUE TABLE *************/
// if we have a dev/live system
// set_live is a per page/per item
// live_queue is a global queue system
/************* QUEUE TABLE *************/
// if we have a dev/live system
// set_live is a per page/per item
// live_queue is a global queue system
// DEFINE('QUEUE', 'live_queue');
/************* DB PATHS (PostgreSQL) *****************/
// schema names, can also be defined per <DB INFO>
DEFINE('PUBLIC_SCHEMA', 'public');
DEFINE('DEV_SCHEMA', 'public');
DEFINE('TEST_SCHEMA', 'public');
/************* DB PATHS (PostgreSQL) *****************/
// schema names, can also be defined per <DB INFO>
DEFINE('PUBLIC_SCHEMA', 'public');
DEFINE('DEV_SCHEMA', 'public');
DEFINE('TEST_SCHEMA', 'public');
// non constant part
/************* DB ACCESS *****************/
// please be VERY carefull only to change the right side
$DB_CONFIG = array(
"<DB ID>" => array (
"db_name" => "<DB NAME>",
"db_user" => "<DB USER>",
"db_pass" => "<DB PASSWORD>",
"db_host" => "<DB HOST>",
"db_port" => "5432",
"db_schema" => "<DB SCHEMA>", // if not set, uses public
"db_type" => "pgsql",
"db_encoding" => '',
"db_ssl" => 'disable' // allow, disable, require, prefer
)
);
// non constant part
/************* DB ACCESS *****************/
// please be VERY carefull only to change the right side
$DB_CONFIG = array (
"<DB ID>" => array (
"db_name" => "<DB NAME>",
"db_user" => "<DB USER>",
"db_pass" => "<DB PASSWORD>",
"db_host" => "<DB HOST>",
"db_port" => "5432",
"db_schema" => "<DB SCHEMA>", // if not set, uses public
"db_type" => "pgsql",
"db_encoding" => '',
"db_ssl" => 'disable' // allow, disable, require, prefer
)
);
// File and Folder paths
// ID is TARGET (first array element)
// File and Folder paths
// ID is TARGET (first array element)
// $PATHS["test"]["csv_path"] = "";
// $PATHS["test"]["perl_bin"] = "";
// $PATHS["test"]["redirect_url"] = "";
// each host has a different db_host
// development host
$DB_HOST['<HOST NAME>'] = "<DB ID>";
// target host (live)
// each host has a different db_host
// development host
$DB_HOST['<HOST NAME>'] = "<DB ID>";
// target host (live)
// $DB_TARGET_HOST['<HOST NAME>'] = "<DB ID>";
// url redirect database
// url redirect database
// $DB_URL_REDIRECT_HOST['<HOST NAME>'] = "<DB ID>";
// location flagging
// test/dev/live
$LOCATION['<HOST NAME>'] = '<test|live|remote|etc>';
// show DEBUG override
// true/false
$DEBUG_FLAG['<HOST NAME>'] = true;
// set postgresql paths (schemas)
$DB_PATH['<HOST NAME>'] = PUBLIC_SCHEMA;
// location flagging
// test/dev/live
$LOCATION['<HOST NAME>'] = '<test|live|remote|etc>';
// show DEBUG override
// true/false
$DEBUG_FLAG['<HOST NAME>'] = true;
// set postgresql paths (schemas)
$DB_PATH['<HOST NAME>'] = PUBLIC_SCHEMA;
// set the USE_DATABASE var, if there is nothing set, we assume TRUE
$USE_DATABASE = defined('USE_DATABASE') ? USE_DATABASE : true;
// set the USE_DATABASE var, if there is nothing set, we assume TRUE
$USE_DATABASE = defined('USE_DATABASE') ? USE_DATABASE : true;
// live frontend pages
// ** missing live domains **
// get the name without the port
list($HOST_NAME) = explode(":", $_SERVER['HTTP_HOST']);
if (!$DB_HOST[$HOST_NAME] && $USE_DATABASE)
{
echo "No matching DB config found. Contact Admin<br>";
exit -1;
}
// live frontend pages
// ** missing live domains **
// get the name without the port
list($HOST_NAME, $PORT) = array_pad(explode(":", $_SERVER['HTTP_HOST'], 2), 2, null);
if (!$DB_HOST[$HOST_NAME] && $USE_DATABASE) {
echo "No matching DB config found. Contact Admin<br>";
exit -1;
}
// define the static names
DEFINE('LOGIN_DB', $DB_HOST[$HOST_NAME]);
DEFINE('MAIN_DB', $DB_HOST[$HOST_NAME]);
DEFINE('DB_SCHEMA', $DB_PATH[$HOST_NAME]);
// define the static names
DEFINE('LOGIN_DB', $DB_HOST[$HOST_NAME]);
DEFINE('MAIN_DB', $DB_HOST[$HOST_NAME]);
DEFINE('DB_SCHEMA', $DB_PATH[$HOST_NAME]);
// DEFINE('TARGET_DB', $DB_TARGET_HOST[$HOST_NAME]);
// DEFINE('URL_REDIRECT_DB', $DB_URL_REDIRECT_HOST[$HOST_NAME]);
// next three if top is not set
// next three if top is not set
// DEFINE('DEV_SCHEMA', $DB_CONFIG[MAIN_DB]['db_schema']);
// DEFINE('TEST_SCHEMA', $DB_CONFIG[MAIN_DB]['db_schema']);
// DEFINE('PUBLIC_SCHEMA', $DB_CONFIG[TARGET_DB]['db_schema']);
DEFINE('LOGIN_DB_SCHEMA', 'public'); // where the edit* tables are
DEFINE('GLOBAL_DB_SCHEMA', 'public'); // where global tables are that are used by all schemas (eg queue tables for online, etc)
DEFINE('TARGET', $LOCATION[$HOST_NAME]);
DEFINE('LOGIN_DB_SCHEMA', 'public'); // where the edit* tables are
DEFINE('GLOBAL_DB_SCHEMA', 'public'); // where global tables are that are used by all schemas (eg queue tables for online, etc)
DEFINE('TARGET', $LOCATION[$HOST_NAME]);
// DEFINE('CSV_PATH', $PATHS[TARGET]['csv_path']);
// DEFINE('EXPORT_SCRIPT', $PATHS[TARGET]['perl_bin']);
// DEFINE('REDIRECT_URL', $PATHS[TARGET]['redirect_url']);
DEFINE('DEBUG', $DEBUG_FLAG[$HOST_NAME]);
DEFINE('SHOW_ALL_ERRORS', false); // show all errors if debug_all & show_error_handling are enabled
DEFINE('DEBUG', $DEBUG_FLAG[$HOST_NAME]);
DEFINE('SHOW_ALL_ERRORS', false); // show all errors if debug_all & show_error_handling are enabled
/************* GENERAL PAGE TITLE ********/
$G_TITLE = '<OVERALL PAGE TITLE>';
/************* GENERAL PAGE TITLE ********/
$G_TITLE = '<OVERALL PAGE TITLE>';
/************ STYLE SHEETS / JS **********/
$EDIT_STYLESHEET = "edit.css";
$EDIT_JAVASCRIPT = "edit.js";
/************ STYLE SHEETS / JS **********/
$EDIT_STYLESHEET = "edit.css";
$EDIT_JAVASCRIPT = "edit.js";
$STYLESHEET = "frontend.css";
$JAVASCRIPT = "frontend.js";
$STYLESHEET = "frontend.css";
$JAVASCRIPT = "frontend.js";
/************* CONVERT *******************/
$paths = array (
'/bin',
'/usr/bin',
'/usr/local/bin'
);
// find convert
foreach ($paths as $path)
{
if (file_exists($path."/convert") && is_file($path."/convert"))
{
// image magick convert location
DEFINE('CONVERT', $path."/convert");
}
/************* CONVERT *******************/
$paths = array (
'/bin',
'/usr/bin',
'/usr/local/bin'
);
// find convert
foreach ($paths as $path) {
if (file_exists($path."/convert") && is_file($path."/convert")) {
// image magick convert location
DEFINE('CONVERT', $path."/convert");
}
}
// turn off debug if debug flag is OFF
if (DEBUG == false)
{
$ECHO_ALL = 0;
$DEBUG_ALL = 0;
$PRINT_ALL = 0;
$DB_DEBUG = 0;
$ENABLE_ERROR_HANDLING = 0;
}
// turn off debug if debug flag is OFF
if (DEBUG == false) {
$ECHO_ALL = 0;
$DEBUG_ALL = 0;
$PRINT_ALL = 0;
$DB_DEBUG = 0;
$ENABLE_ERROR_HANDLING = 0;
}
// any other global definitons here
// any other global definitons here
// DEFINE('SOME_ID', <SOME VALUE>);
// function that will be called on top of each class include to load the class
function _spl_autoload($include_file)
{
// where to search for the files to include
$dirs = array (
LIBDIR,
SMARTYDIR,
TABLEARRAYDIR,
'',
LIBS,
SMARTY,
TABLE_ARRAYS,
__DIR__.'/'.LIBS,
__DIR__.'/'.SMARTY
);
// try to find and load the class ifle
foreach ($dirs as $folder)
{
if (file_exists($folder.$include_file))
{
require_once($folder.$include_file);
return true;
}
// function that will be called on top of each class include to load the class
function _spl_autoload($include_file)
{
// where to search for the files to include
$dirs = array (
LIBDIR,
SMARTYDIR,
TABLEARRAYDIR,
'',
LIBS,
SMARTY,
TABLE_ARRAYS,
__DIR__.'/'.LIBS,
__DIR__.'/'.SMARTY
);
// try to find and load the class ifle
foreach ($dirs as $folder) {
if (file_exists($folder.$include_file)) {
require_once($folder.$include_file);
return true;
}
return false;
}
?>
return false;
}

View File

@@ -15,416 +15,353 @@
padding: 0;
} */
body
{
body {
background-color: white;
color: black;
font-size : 8pt;
font-family: Verdana,Arial,Helvetica,sans-serif;
font-size : 8pt;
}
.large
{
.large {
font-family: Verdana,Arial,Helvetica,sans-serif;
font-size : 16pt;
font-family: Verdana,Arial,Helvetica,sans-serif;
}
.big
{
.big {
font-family: Verdana,Arial,Helvetica,sans-serif;
font-size : 12pt;
font-family: Verdana,Arial,Helvetica,sans-serif;
}
.normal
{
.normal {
font-family: Verdana,Arial,Helvetica,sans-serif;
font-size : 9pt;
font-family: Verdana,Arial,Helvetica,sans-serif;
}
.small
{
font-size : 8pt;
.small {
font-family: Verdana,Arial,Helvetica,sans-serif;
font-size : 8pt;
}
.smallbold
{
font-size : 8pt;
.smallbold {
font-family: Verdana,Arial,Helvetica,sans-serif;
font-size : 8pt;
font-weight: bold;
}
a:link
{
a:link {
color: #FF0000;
text-decoration: none;
}
a:active
{
a:active {
color: #FFFF00;
text-decoration: none;
}
a:visited
{
a:visited {
color: #550000;
text-decoration: none;
}
a:hover, a.item_loaded:hover, a.item_deleted:hover, a.item_loaded_deleted:hover
{
color: #FF0000;
a:hover, a.item_loaded:hover, a.item_deleted:hover, a.item_loaded_deleted:hover {
background-color: #e5e5e5;
border-bottom: 1px dotted red;
color: #FF0000;
}
a:focus, a.item_loaded:hover, a.item_deleted:hover, a.item_loaded_deleted:hover
{
color: #ff0000;
a:focus, a.item_loaded:hover, a.item_deleted:hover, a.item_loaded_deleted:hover {
background-color: #b3b3b3;
border-top: 1px dotted red;
border-bottom: 1px dotted red;
border-top: 1px dotted red;
color: #ff0000;
}
/* link highlight */
a.item_loaded
{
font-weight: bold;
color: #451010;
a.item_loaded {
background-color: #d5d6d6;
color: #451010;
font-weight: bold;
}
a.item_deleted
{
a.item_deleted {
text-decoration: line-through;
}
a.item_loaded_deleted
{
text-decoration: line-through;
font-weight: bold;
color: #451010;
a.item_loaded_deleted {
background-color: #d5d6d6;
color: #451010;
font-weight: bold;
text-decoration: line-through;
}
/* experimental */
input[type="text"]
{
border: 1px solid #999999;
input[type="text"] {
background-color: #efefef;
}
input[type="password"]
{
border: 1px solid #999999;
}
input[type="submit"]
{
input[type="password"] {
border: 1px solid #999999;
}
input[type="submit"] {
border: 1px solid #666666;
}
input[type="checkbox"]
{
input[type="checkbox"] {
border: 1px solid #999999;
}
input[type="radio"]
{
input[type="radio"] {
border: 1px solid #999999;
}
input[type="file"]
{
input[type="file"] {
border: 1px solid #999999;
}
input[type="button"]
{
input[type="button"] {
border: 1px solid #999999;
}
textarea
{
border: 1px solid #999999;
textarea {
background-color: #efefef;
border: 1px solid #999999;
}
select
{
border: 1px solid #999999;
select {
background-color: #efefef;
border: 1px solid #999999;
}
/* mouse over */
input[type=submit]:hover, input[type=button]:hover, input[type="text"]:hover, input[type="password"]:hover, input[type="checkbox"]:hover, input[type="radio"]:hover, input[type="file"]:hover, textarea:hover, select:hover
{
input[type=submit]:hover, input[type=button]:hover, input[type="text"]:hover, input[type="password"]:hover, input[type="checkbox"]:hover, input[type="radio"]:hover, input[type="file"]:hover, textarea:hover, select:hover {
border: 1px dashed red;
}
/* selected */
input[type=submit]:focus, input[type=button]:focus, input[type="password"]:focus, input[type="checkbox"]:focus, input[type="radio"]:focus, input[type="file"]:focus
{
border: 1px solid red;
input[type=submit]:focus, input[type=button]:focus, input[type="password"]:focus, input[type="checkbox"]:focus, input[type="radio"]:focus, input[type="file"]:focus {
background-color: #ffffff;
border: 1px solid red;
}
input[type="text"]:focus, textarea:focus, select:focus
{
border: 1px solid red;
input[type="text"]:focus, textarea:focus, select:focus {
background-color: #ffffff;
border: 1px solid red;
}
/* error & status layouts for messges */
.error
{
.error {
border: 1px solid red;
margin: 5px;
padding: 2px;
color: red;
margin: 5px;
padding: 2px;
text-align: center;
}
.warning
{
.warning {
border: 1px solid #df7700;
margin: 5px;
padding: 2px;
color: #d57200;
text-align: center;
}
.info
{
border: 1px solid #72C47E;
margin: 5px;
padding: 2px;
color: #1D731A;
text-align: center;
}
.div_error
{
border: 1px solid red;
margin-top: 1px;
margin-bottom: 1px;
.info {
border: 1px solid #72C47E;
color: #1D731A;
margin: 5px;
padding: 2px;
text-align: center;
}
.div_warning
{
.div_error {
border: 1px solid red;
margin-bottom: 1px;
margin-top: 1px;
}
.div_warning {
border: 1px solid #df7700;
}
/* borders */
.border_all
{
.border_all {
border: 1px solid black;
}
.border_bottom_title
{
font-weight: bold;
.border_bottom_title {
border-bottom: 1px solid black;
font-weight: bold;
}
.border_top
{
.border_top {
border-top: 1px solid #DCDCCC;
}
.border_all_error
{
.border_all_error {
border: 1px solid red;
}
.border_group
{
.border_group {
border: 1px solid #a89c5a;
}
.border_master
{
.border_master {
border: 1px solid white;
}
.border_sub
{
.border_sub {
border: 1px solid gray;
}
.border_sub_sub
{
.border_sub_sub {
border: 1px solid #e5ddba;
}
/* employee hardware/software borders */
.border_hardware
{
.border_hardware {
background-color: #e9e9e9;
border: 2px solid black;
background-color: #e9e9e9;
}
.border_hardware_usage_end
{
.border_hardware_usage_end {
background-color: #e9e9e9;
border: 2px solid red;
background-color: #e9e9e9;
}
.border_hardware_line
{
border-left: 2px solid black;
.border_hardware_line {
border-bottom: 2px solid black;
border-left: 2px solid black;
}
.border_software
{
border: 2px solid #a89c5a;
.border_software {
background-color: #d5d4c8;
border: 2px solid #a89c5a;
}
.border_software_line
{
border-left: 2px solid #a89c5a;
.border_software_line {
border-bottom: 2px solid #a89c5a;
border-left: 2px solid #a89c5a;
}
.border_software_line_left
{
.border_software_line_left {
border-left: 2px solid #a89c5a;
padding-bottom: 10px;
}
.border_software_line_bottom
{
.border_software_line_bottom {
border-bottom: 2px solid #a89c5a;
padding-left: 2px;
}
/* highlight */
.highlight
{
.highlight {
background-color: #e7e7e7;
font-weight: bold;
}
/* hide & show */
.visible
{
.visible {
visibility: visible;
}
.hidden
{
visibility: hidden;
.hidden {
display: none;
visibility: hidden;
}
/* spacer for line break in float elements */
div.spacer
{
.spacer {
clear: both;
}
/* unique definitions */
/* main body */
/* menu on top */
.menu
{
.menu {
border-bottom: 1px solid #a4a4a4;
font-size: 10px;
}
.pagename
{
text-align: center; font-size: 15px;
.pagename {
background-color: #e7e7e7;
font-size: 15px;
font-weight: bold;
padding: 5px;
text-align: center;
}
/* overlay side menu */
.sidemenu
{
border: 1px solid black;
.sidemenu {
background-color: white;
border: 1px solid black;
}
.buttongroup
{
.buttongroup {
border: 1px solid #e5ddba;
}
/* input group field */
/* normal */
.input_group
{
.input_group {
border: 1px solid #e5ddba;
}
/* loaded with id */
.input_group_id
{
.input_group_id {
border: 1px solid #8a7d3a;
}
/* deleted */
.input_group_deleted
{
border: 1px solid #8a7d3a;
.input_group_deleted {
background-color: #d5d4c8;
border: 1px solid #8a7d3a;
}
/* header part */
/* normal */
.input_group_header
{
.input_group_header {
background-color: #e9e9e9;
}
/* loaded with id */
.input_group_header_id
{
.input_group_header_id {
background-color: #d5d5d5;
}
/* deleted */
.input_group_header_deleted
{
.input_group_header_deleted {
background-color: #bfb59d;
}
/* error & warning messages */
.top_error_message
{
.top_error_message {
border: 2px solid red;
color: red;
font-size: 18px;
margin: 5px;
padding: 10px;
border: 2px solid red;
font-size: 18px;
text-align: center;
color: red;
}
.top_inventory_number
{
margin: 5px;
padding: 10px;
.top_inventory_number {
border: 2px solid orange;
font-size: 18px;
text-align: center;
}
.top_info_message
{
border: 2px solid green;
margin: 5px;
padding: 10px;
text-align: center;
font-size: 12px;
}
.debug_message
{
.top_info_message {
border: 2px solid green;
font-size: 12px;
margin: 5px;
padding: 10px;
text-align: center;
}
.debug_message {
border-top: 1px solid #a4a4a4;
color: #a4a4a4;
font-size: 8px;
@@ -434,78 +371,63 @@ div.spacer
/* set all colors here and not in the config file */
/* for edit interface */
.menu_bgcolor
{
.menu_bgcolor {
background-color: #666666;
}
.menu_fgcolor
{
.menu_fgcolor {
background-color: #DDDDDD;
}
.menu_fgcolor_na
{
.menu_fgcolor_na {
background-color: #CCCCCC;
}
.menu_fgcolor_a
{
.menu_fgcolor_a {
background-color: #EEEEEE;
}
.edit_bgcolor
{
.edit_bgcolor {
background-color: #666666;
}
.edit_fgcolor
{
.edit_fgcolor {
background-color: #FFFFDF;
}
.edit_fgcolor_mod_a
{
.edit_fgcolor_mod_a {
background-color: #CECEB5;
}
.edit_fgcolor_mod_b
{
.edit_fgcolor_mod_b {
background-color: #DEDEC3;
}
.edit_fgcolor_2
{
.edit_fgcolor_2 {
background-color: #AADAA2;
}
.edit_fgcolor_no
{
.edit_fgcolor_no {
background-color: #CECEB5;
}
.edit_fgcolor_alt
{
.edit_fgcolor_alt {
background-color: #CCCCCC;
}
.edit_fgcolor_delete
{
.edit_fgcolor_delete {
background-color: red;
}
.font_error
{
.font_error {
color: red;
}
.edit_fgcolor_special
{
.edit_fgcolor_special {
background-color: #EEEEEE;
}
.edit_temp
{
.edit_temp {
background-color: #FFDF6F;
}

View File

@@ -9,9 +9,8 @@
*/
// if debug is set to true, console log messages are printed
if (!DEBUG)
{
if (!DEBUG) {
$($H(window.console)).each(function(w) {
window.console[w.key] = function() {}
window.console[w.key] = function() {};
});
}

View File

@@ -6,50 +6,43 @@
* Some browser detection
*/
var clientPC = navigator.userAgent.toLowerCase(); // Get client info
var is_gecko = ((clientPC.indexOf('gecko') != -1) && (clientPC.indexOf('spoofer') == -1)
&& (clientPC.indexOf('khtml') == -1) && (clientPC.indexOf('netscape/7.0') == -1));
var is_gecko = ((clientPC.indexOf('gecko') != -1) && (clientPC.indexOf('spoofer') == -1) &&
(clientPC.indexOf('khtml') == -1) && (clientPC.indexOf('netscape/7.0') == -1));
var is_safari = ((clientPC.indexOf('AppleWebKit') != -1) && (clientPC.indexOf('spoofer') == -1));
var is_khtml = (navigator.vendor == 'KDE' || ( document.childNodes && !document.all && !navigator.taintEnabled ));
if (clientPC.indexOf('opera') != -1)
{
if (clientPC.indexOf('opera') != -1) {
var is_opera = true;
var is_opera_preseven = (window.opera && !document.childNodes);
var is_opera_seven = (window.opera && document.childNodes);
}
function pop(theURL, winName, features)
{
function pop(theURL, winName, features) {
winName = window.open(theURL, winName, features);
winName.focus();
}
function emd_check_checkbox()
{
for (i = 0; i < document.manage_emails.length; i ++)
{
if (document.manage_emails.elements[i].checked == false && document.manage_emails.elements[i].type == 'checkbox')
{
function emd_check_checkbox() {
for (i = 0; i < document.manage_emails.length; i ++) {
if (document.manage_emails.elements[i].checked == false && document.manage_emails.elements[i].type == 'checkbox') {
document.manage_emails.elements[i].checked = true;
}
}
}
function expandTA(ta_id)
{
function expandTA(ta_id) {
var ta;
// if a string comes, its a get by id, else use it as an element pass on
if (!ta_id.length)
if (!ta_id.length) {
ta = ta_id;
else
} else {
ta = document.getElementById(ta_id);
}
var maxChars = ta.cols;
var theRows = ta.value.split("\n");
var numNewRows = 0;
for ( var i = 0; i < theRows.length; i++ )
{
if ((theRows[i].length+2) > maxChars)
{
for ( var i = 0; i < theRows.length; i++ ) {
if ((theRows[i].length+2) > maxChars) {
numNewRows += Math.ceil( (theRows[i].length+2) / maxChars ) ;
}
}
@@ -62,27 +55,27 @@ function expandTA(ta_id)
// DESC: shows or hides the menu
function ShowHideMenu(status, id)
{
if (status == 'show')
{
if (status == 'show') {
document.getElementById(id).style.visibility = 'visible';
if (document.getElementById('search_results').innerHTML)
if (document.getElementById('search_results').innerHTML) {
document.getElementById('search_results').style.visibility = 'visible';
}
else if (status == 'hide')
{
}
} else if (status == 'hide') {
document.getElementById(id).style.visibility = 'hidden';
if (document.getElementById('search_results').style.visibility == 'visible')
if (document.getElementById('search_results').style.visibility == 'visible') {
document.getElementById('search_results').style.visibility = 'hidden';
}
}
}
function ShowHideDiv(id)
{
element = document.getElementById(id);
if (element.className == 'visible' || !element.className)
if (element.className == 'visible' || !element.className) {
element.className = 'hidden';
else
} else {
element.className = 'visible';
}
// alert('E: ' + element.className + ' -- ' + element.style.visibility);
}
@@ -100,14 +93,16 @@ function mv(id, direction)
function le(id)
{
document.forms[form_name].action.value = 'load';
if (load_id)
if (load_id) {
document.forms[form_name].action_yes.value = confirm('Do you want to load this data?');
else
} else {
document.forms[form_name].action_yes.value = 'true';
}
document.forms[form_name].action_id.value = id;
document.forms[form_name].action_menu.value = id;
if (document.forms[form_name].action_yes.value == 'true')
if (document.forms[form_name].action_yes.value == 'true') {
document.forms[form_name].submit();
}
}
// METHOD: getWindowSize
@@ -119,7 +114,10 @@ function getWindowSize()
var width, height;
width = window.innerWidth || (window.document.documentElement.clientWidth || window.document.body.clientWidth);
height = window.innerHeight || (window.document.documentElement.clientHeight || window.document.body.clientHeight);
return {width: width, height: height};
return {
width: width,
height: height
};
}
// METHOD: getScrollOffset
@@ -131,7 +129,10 @@ function getScrollOffset()
var left, top;
left = window.pageXOffset || (window.document.documentElement.scrollLeft || window.document.body.scrollLeft);
top = window.pageYOffset || (window.document.documentElement.scrollTop || window.document.body.scrollTop);
return {left: left, top: top};
return {
left: left,
top: top
};
}
// METHOD: setCenter
@@ -149,14 +150,12 @@ function setCenter(id, left, top)
// console.log('Id %s, type: %s, dimensions %s x %s, viewport %s x %s', id, $(id).getStyle('position'), dimensions.width, dimensions.height, viewport.width, viewport.height);
// console.log('Scrolloffset left: %s, top: %s', offset.left, offset.top);
// console.log('Left: %s, Top: %s (%s)', parseInt((viewport.width / 2) - (dimensions.width / 2) + offset.left), parseInt((viewport.height / 2) - (dimensions.height / 2) + offset.top), parseInt((viewport.height / 2) - (dimensions.height / 2)));
if (left)
{
if (left) {
$(id).setStyle ({
left: parseInt((viewport.width / 2) - (dimensions.width / 2) + offset.left) + 'px'
});
}
if (top)
{
if (top) {
// if we have fixed, we do not add the offset, else it moves out of the screen
var top_pos = type == 'fixed' ? parseInt((viewport.height / 2) - (dimensions.height / 2)) : parseInt((viewport.height / 2) - (dimensions.height / 2) + offset.top);
$(id).setStyle ({
@@ -178,15 +177,12 @@ function sh(id, showText, hideText)
// get status from element (hidden or visible)
divStatus = $(id).visible();
//console.log('Set flag %s for element %s', divStatus, id);
if (divStatus)
{
if (divStatus) {
// hide the element
Effect.BlindUp(id, {duration:0.3});
$(flag).value = 0;
$(btn).innerHTML = showText;
}
else if (!divStatus)
{
} else if (!divStatus) {
// show the element
Effect.BlindDown(id, {duration:0.3});
$(flag).value = 1;

View File

@@ -10,7 +10,7 @@ var ConsoleSetup = function() {
for (var i = 0; i < names.length; ++i) {
if (!window.console[names[i]]) {
window.console[names[i]] = function() {}
window.console[names[i]] = function() {};
}
}
}();

View File

@@ -1,5 +1,4 @@
.debug_message
{
.debug_message {
border-top: 1px solid #a4a4a4;
color: #a4a4a4;
font-size: 8px;

View File

@@ -8,10 +8,10 @@
// PARAMS: front/back -> what image to show
// RETURN: none
// DESC: ajax call to switch the main image in the detail view
function SwitchImage(image)
{
if (image != 'front' || image != 'back')
function SwitchImage(image) {
if (image != 'front' || image != 'back') {
image = 'front';
}
// disable / enable the href for the other side
x_ajax_afSwitchImage(image, OutputSwitchImage);
}
@@ -20,7 +20,6 @@ function SwitchImage(image)
// PARAMS: data -> the image full path for the new image
// RETURN: none
// DESC: replace the image in the product detail with the back image
function OutputSwitchImage(data)
{
function OutputSwitchImage(data) {
}

View File

@@ -1,400 +1,410 @@
<?
/*********************************************************************
* AUTHOR: Clemens "Gullevek" Schwaighofer (www.gullevek.org)
* CREATED: 2006/08/15
* VERSION: 0.1.0
* RELEASED LICENSE: GNU GPL 3
* DESCRIPTION
* Basic Admin interface backend
* - sets action flags
* - menu creation
* - array vars for smarty
*
* PUBLIC VARIABLES
*
* PRIVATE VARIABLES
*
* PUBLIC METHODS
*
* PRIVATE METHODS
*
* HISTORY:
*
*********************************************************************/
/*********************************************************************
* AUTHOR: Clemens "Gullevek" Schwaighofer (www.gullevek.org)
* CREATED: 2006/08/15
* VERSION: 0.1.0
* RELEASED LICENSE: GNU GPL 3
* DESCRIPTION
* Basic Admin interface backend
* - sets action flags
* - menu creation
* - array vars for smarty
*
* PUBLIC VARIABLES
*
* PRIVATE VARIABLES
*
* PUBLIC METHODS
*
* PRIVATE METHODS
*
* HISTORY:
*
*********************************************************************/
// try to include file from LIBS path, or from normal path
_spl_autoload('Class.DB.IO.inc');
// try to include file from LIBS path, or from normal path
_spl_autoload('Class.DB.IO.inc');
class AdminBackend extends db_io
class AdminBackend extends db_io
{
// page name
public $page_name; // the name of the current page
public $menu = array();
public $menu_show_flag = 0; // top menu flag (mostly string)
// action ids
public $action_list = array ('action', 'action_id', 'action_sub_id', 'action_yes', 'action_flag', 'action_menu', 'action_value', 'action_error', 'action_loaded');
public $action;
public $action_id;
public $action_sub_id;
public $action_yes;
public $action_flag;
public $action_menu;
public $action_loaded;
public $action_value;
public $action_error;
// ACL array variable if we want to set acl data from outisde
public $acl = array ();
// the current active edit access id
public $edit_access_id;
// error/warning/info messages
public $messages = array ();
public $error = 0;
public $warning = 0;
public $info = 0;
// smarty publics
public $DATA;
public $HEADER;
public $DEBUG_DATA;
public $CONTENT_DATA;
// CONSTRUCTOR / DECONSTRUCTOR |====================================>
public function __construct($db_config, $lang, $debug = 0, $db_debug = 0, $echo = 1, $print = 0)
{
// page name
public $page_name; // the name of the current page
public $menu = array();
public $menu_show_flag = 0; // top menu flag (mostly string)
// action ids
public $action_list = array ('action', 'action_id', 'action_sub_id', 'action_yes', 'action_flag', 'action_menu', 'action_value', 'action_error', 'action_loaded');
public $action;
public $action_id;
public $action_sub_id;
public $action_yes;
public $action_flag;
public $action_menu;
public $action_loaded;
public $action_value;
public $action_error;
// ACL array variable if we want to set acl data from outisde
public $acl = array ();
// the current active edit access id
public $edit_access_id;
// error/warning/info messages
public $messages = array ();
public $error = 0;
public $warning = 0;
public $info = 0;
// smarty publics
public $DATA;
public $HEADER;
public $DEBUG_DATA;
public $CONTENT_DATA;
// get the language sub class & init it
_spl_autoload('Class.l10n.inc');
// CONSTRUCTOR / DECONSTRUCTOR |====================================>
public function __construct($db_config, $lang, $debug = 0, $db_debug = 0, $echo = 1, $print = 0)
{
// get the language sub class & init it
_spl_autoload('Class.l10n.inc');
$this->l = new l10n($lang);
$this->l = new l10n($lang);
// init the database class
// init the database class
// $this->db_io($db_config, $debug, $db_debug, $echo, $print);
parent::__construct($db_config, $debug, $db_debug, $echo, $print);
parent::__construct($db_config, $debug, $db_debug, $echo, $print);
// internal
$this->class_info["adbBackend"] = array(
"class_name" => "Admin Interface Backend",
"class_version" => "0.1.0",
"class_created" => "2006/08/15",
"class_author" => "cs/gullevek/jp"
// internal
$this->class_info["adbBackend"] = array(
"class_name" => "Admin Interface Backend",
"class_version" => "0.1.0",
"class_created" => "2006/08/15",
"class_author" => "cs/gullevek/jp"
);
// set page name
$this->page_name = $this->get_page_name();
// set the action ids
foreach ($this->action_list as $_action) {
$this->$_action = (isset($_POST[$_action])) ? $_POST[$_action] : '';
}
$this->default_acl = DEFAULT_ACL_LEVEL;
// random key generation
$this->key_range = array_merge(range('A', 'Z'), range('a', 'z'), range('0', '9'));
$GLOBALS["_KEY_RANGE"] = $this->key_range;
$this->one_key_length = count($this->key_range);
$this->key_length = 4; // pow($this->one_key_length, 4); // hardcoded, should be more than enought (62*62*62*62)
// queue key
if (preg_match("/^(add|save|delete|remove|move|up|down|push_live)$/", $this->action)) {
$this->queue_key = join(
'',
array_map(
function () {
$range = $GLOBALS['_KEY_RANGE'];
return $range[rand(0, (count($range) - 1))];
},
range(1, 3)
)
);
}
}
// set page name
$this->page_name = $this->get_page_name();
// deconstructor
public function __destruct()
{
parent::__destruct();
}
// set the action ids
foreach ($this->action_list as $_action)
{
$this->$_action = (isset($_POST[$_action])) ? $_POST[$_action] : '';
}
// INTERNAL METHODS |===============================================>
$this->default_acl = DEFAULT_ACL_LEVEL;
// random key generation
$this->key_range = array_merge(range('A', 'Z'), range('a', 'z'), range('0', '9'));
$GLOBALS["_KEY_RANGE"] = $this->key_range;
$this->one_key_length = count($this->key_range);
$this->key_length = 4; // pow($this->one_key_length, 4); // hardcoded, should be more than enought (62*62*62*62)
// PUBLIC METHODS |=================================================>
// queue key
if (preg_match("/^(add|save|delete|remove|move|up|down|push_live)$/", $this->action))
{
$this->queue_key = join('', array_map(function () { $range = $GLOBALS['_KEY_RANGE']; return $range[rand(0, (count($range) - 1))]; }, range(1, 3)));
}
// METHOD: adbEditLog()
// PARAMS: event -> any kind of event description, data -> any kind of data related to that event
// RETURN: none
// DESC: writes all action vars plus other info into edit_log table
public function adbEditLog($event = '', $data = '', $write_type = 'STRING')
{
if ($write_type == 'BINARY') {
$data_binary = $this->db_escape_bytea(bzcompress(serialize($data)));
$data = 'see bzip compressed data_binary field';
}
if ($write_type == 'STRING') {
$data = $this->db_escape_string(serialize($data));
}
// deconstructor
public function __destruct()
{
parent::__destruct();
$q = "INSERT INTO ".LOGIN_DB_SCHEMA.".edit_log ";
$q .= "(euid, event_date, event, data, data_binary, page, ";
$q .= "ip, user_agent, referer, script_name, query_string, server_name, http_host, http_accept, http_accept_charset, http_accept_encoding, session_id, ";
$q .= "action, action_id, action_yes, action_flag, action_menu, action_loaded, action_value, action_error) ";
$q .= "VALUES ";
$q .= "(".@$_SESSION['EUID'].", NOW(), '".$this->db_escape_string($event)."', '".$data."', '".$data_binary."', '".$this->page_name."', ";
$q .= "'".@$_SERVER["REMOTE_ADDR"]."', '".$this->db_escape_string(@$_SERVER['HTTP_USER_AGENT'])."', ";
$q .= "'".$this->db_escape_string(@$_SERVER['HTTP_REFERER'])."', '".$this->db_escape_string(@$_SERVER['SCRIPT_FILENAME'])."', ";
$q .= "'".$this->db_escape_string(@$_SERVER['QUERY_STRING'])."', '".$this->db_escape_string(@$_SERVER['SERVER_NAME'])."', ";
$q .= "'".$this->db_escape_string(@$_SERVER['HTTP_HOST'])."', '".$this->db_escape_string(@$_SERVER['HTTP_ACCEPT'])."', ";
$q .= "'".$this->db_escape_string(@$_SERVER['HTTP_ACCEPT_CHARSET'])."', '".$this->db_escape_string(@$_SERVER['HTTP_ACCEPT_ENCODING'])."', ";
$q .= "'".session_id()."', ";
$q .= "'".$this->db_escape_string($this->action)."', '".$this->db_escape_string($this->action_id)."', ";
$q .= "'".$this->db_escape_string($this->action_yes)."', '".$this->db_escape_string($this->action_flag)."', ";
$q .= "'".$this->db_escape_string($this->action_menu)."', '".$this->db_escape_string($this->action_loaded)."', ";
$q .= "'".$this->db_escape_string($this->action_value)."', '".$this->db_escape_string($this->action_error)."')";
$this->db_exec($q, 'NULL');
}
// ==================================
// ALL THE PAGE RIGHTS/USER RIGHTS/ETC need to fixed and put into one
// proper settings have to be done with the defined top down rights flow
// ==================================
// all ACLs are set in the login class
// METHOD: adbTopMenu
// PARAMS: level
// RETURN: returns an array for the top menu with all correct settings
// DESC: menu creater
public function adbTopMenu($flag = 0)
{
if ($this->menu_show_flag) {
$flag = $this->menu_show_flag;
}
// INTERNAL METHODS |===============================================>
// PUBLIC METHODS |=================================================>
// METHOD: adbEditLog()
// PARAMS: event -> any kind of event description, data -> any kind of data related to that event
// RETURN: none
// DESC: writes all action vars plus other info into edit_log table
public function adbEditLog($event = '', $data = '', $write_type = 'STRING')
{
if ($write_type == 'BINARY')
{
$data_binary = $this->db_escape_bytea(bzcompress(serialize($data)));
$data = 'see bzip compressed data_binary field';
}
if ($write_type == 'STRING')
{
$data = $this->db_escape_string(serialize($data));
}
$q = "INSERT INTO ".LOGIN_DB_SCHEMA.".edit_log ";
$q .= "(euid, event_date, event, data, data_binary, page, ";
$q .= "ip, user_agent, referer, script_name, query_string, server_name, http_host, http_accept, http_accept_charset, http_accept_encoding, session_id, ";
$q .= "action, action_id, action_yes, action_flag, action_menu, action_loaded, action_value, action_error) ";
$q .= "VALUES ";
$q .= "(".@$_SESSION['EUID'].", NOW(), '".$this->db_escape_string($event)."', '".$data."', '".$data_binary."', '".$this->page_name."', ";
$q .= "'".@$_SERVER["REMOTE_ADDR"]."', '".$this->db_escape_string(@$_SERVER['HTTP_USER_AGENT'])."', '".$this->db_escape_string(@$_SERVER['HTTP_REFERER'])."', '".$this->db_escape_string(@$_SERVER['SCRIPT_FILENAME'])."', '".$this->db_escape_string(@$_SERVER['QUERY_STRING'])."', '".$this->db_escape_string(@$_SERVER['SERVER_NAME'])."', '".$this->db_escape_string(@$_SERVER['HTTP_HOST'])."', '".$this->db_escape_string(@$_SERVER['HTTP_ACCEPT'])."', '".$this->db_escape_string(@$_SERVER['HTTP_ACCEPT_CHARSET'])."', '".$this->db_escape_string(@$_SERVER['HTTP_ACCEPT_ENCODING'])."', '".session_id()."', ";
$q .= "'".$this->db_escape_string($this->action)."', '".$this->db_escape_string($this->action_id)."', '".$this->db_escape_string($this->action_yes)."', '".$this->db_escape_string($this->action_flag)."', '".$this->db_escape_string($this->action_menu)."', '".$this->db_escape_string($this->action_loaded)."', '".$this->db_escape_string($this->action_value)."', '".$this->db_escape_string($this->action_error)."')";
$this->db_exec($q, 'NULL');
// get the session pages array
$pages = $_SESSION["PAGES"];
if (!is_array($pages)) {
$pages = array ();
}
// ==================================
// ALL THE PAGE RIGHTS/USER RIGHTS/ETC need to fixed and put into one
// proper settings have to be done with the defined top down rights flow
// ==================================
// all ACLs are set in the login class
// METHOD: adbTopMenu
// PARAMS: level
// RETURN: returns an array for the top menu with all correct settings
// DESC: menu creater
public function adbTopMenu($flag = 0)
{
if ($this->menu_show_flag)
$flag = $this->menu_show_flag;
// get the session pages array
$pages = $_SESSION["PAGES"];
if (!is_array($pages))
$pages = array ();
//$this->debug('pages', $this->print_ar($pages));
// if flag is 0, then we show all, else, we show only the matching flagges array points
// array is already sorted after correct order
reset($pages);
for ($i = 0; $i < count($pages); $i ++)
{
$show = 0;
// is it visible in the menu & is it online
if ($pages[$i]["menu"] && $pages[$i]["online"])
{
// check if it falls into our flag if we have a flag
if ($flag)
{
foreach ($pages[$i]["visible"] AS $name => $key)
{
if ($key == $flag)
$show = 1;
// if flag is 0, then we show all, else, we show only the matching flagges array points
// array is already sorted after correct order
reset($pages);
for ($i = 0; $i < count($pages); $i ++) {
$show = 0;
// is it visible in the menu & is it online
if ($pages[$i]["menu"] && $pages[$i]["online"]) {
// check if it falls into our flag if we have a flag
if ($flag) {
foreach ($pages[$i]["visible"] as $name => $key) {
if ($key == $flag) {
$show = 1;
}
}
else
{
// if no flag given, show all menu points
$show = 1;
}
} else {
// if no flag given, show all menu points
$show = 1;
}
if ($show)
{
// if it is popup, write popup arrayound
if ($pages[$i]["popup"])
{
$type = "popup";
}
else
{
$type = "normal";
}
$query_string = '';
if (count($pages[$i]["query"]))
{
for ($j = 0; $j < count($pages[$i]["query"]); $j ++)
{
if (strlen($query_string))
$query_string .= "&";
$query_string .= $pages[$i]["query"][$j]["name"]."=";
if (!$pages[$i]["query"][$j]["dynamic"])
$query_string .= urlencode($pages[$i]["query"][$j]["value"]);
else
$query_string .= (($_GET[$pages[$i]["query"][$j]["value"]]) ? urlencode($_GET[$pages[$i]["query"][$j]["value"]]) : urlencode($_POST[$pages[$i]["query"][$j]["value"]]));
if ($show) {
// if it is popup, write popup arrayound
if ($pages[$i]["popup"]) {
$type = "popup";
} else {
$type = "normal";
}
$query_string = '';
if (count($pages[$i]["query"])) {
for ($j = 0; $j < count($pages[$i]["query"]); $j ++) {
if (strlen($query_string)) {
$query_string .= "&";
}
$query_string .= $pages[$i]["query"][$j]["name"]."=";
if (!$pages[$i]["query"][$j]["dynamic"]) {
$query_string .= urlencode($pages[$i]["query"][$j]["value"]);
} else {
$query_string .= $_GET[$pages[$i]["query"][$j]["value"]] ? urlencode($_GET[$pages[$i]["query"][$j]["value"]]) : urlencode($_POST[$pages[$i]["query"][$j]["value"]]);
}
}
$url = $pages[$i]["filename"];
if (strlen($query_string))
$url .= "?".$query_string;
$name = $pages[$i]["page_name"];
// if page name matchs -> set selected flag
$selected = 0;
if ($this->get_page_name() == $pages[$i]["filename"])
{
$selected = 1;
$this->page_name = $name;
}
// last check, is this menu point okay to show
$enabled = 0;
if ($this->adbShowMenuPoint($pages[$i]["filename"]))
{
$enabled = 1;
}
// write in to view menu array
array_push($this->menu, array("name" => $this->l->__($name), "url" => $url, "selected" => $selected, "enabled" => $enabled, "type" => $type));
} // show page
} // online and in menu
} // for each page
return $this->menu;
}
}
$url = $pages[$i]["filename"];
if (strlen($query_string)) {
$url .= "?".$query_string;
}
$name = $pages[$i]["page_name"];
// if page name matchs -> set selected flag
$selected = 0;
if ($this->get_page_name() == $pages[$i]["filename"]) {
$selected = 1;
$this->page_name = $name;
}
// last check, is this menu point okay to show
$enabled = 0;
if ($this->adbShowMenuPoint($pages[$i]["filename"])) {
$enabled = 1;
}
// write in to view menu array
array_push($this->menu, array("name" => $this->l->__($name), "url" => $url, "selected" => $selected, "enabled" => $enabled, "type" => $type));
} // show page
} // online and in menu
} // for each page
return $this->menu;
}
// METHOD: adbShowMenuPoint
// PARAMS: filename
// RETURN: returns boolean true/false
// DESC: checks if this filename is in the current situation (user id, etc) available
public function adbShowMenuPoint($filename)
{
$enabled = 0;
switch ($filename)
{
default:
$enabled = 1;
// METHOD: adbShowMenuPoint
// PARAMS: filename
// RETURN: returns boolean true/false
// DESC: checks if this filename is in the current situation (user id, etc) available
public function adbShowMenuPoint($filename)
{
$enabled = 0;
switch ($filename) {
default:
$enabled = 1;
break;
};
return $enabled;
};
return $enabled;
}
// REMARK: below function has moved to "Class.Basic"
// METHOD: adbAssocArray
// PARAMS: db array, key, value part
// RETURN: returns and associative array
// DESC: creates out of a normal db_return array an assoc array
public function adbAssocArray($db_array, $key, $value)
{
return $this->GenAssocArray($db_array, $key, $value);
}
// REMARK: below function has moved to "Class.Basic"
// METHOD: adbByteStringFormat
// PARAMS: int
// RETURN: string
// DESC: converts bytes into formated string with KB, MB, etc
public function adbByteStringFormat($number)
{
return $this->ByteStringFormat($number);
}
// REMARK: below function has moved to "Class.Basic"
// METHOD: adbCreateThumbnail
// PARAMS: id from picture where from we create a thumbnail
// x -> max x size of thumbnail
// y -> max y size of thumbnail
// dummy -> if set to true, then if no images was found we show a dummy image
// path -> if source start is not ROOT path, if empty ROOT is choosen
// cache -> cache path, if not given TMP is used
// RETURN: thumbnail name
// DESC: converts picture to a thumbnail with max x and max y size
public function adbCreateThumbnail($pic, $size_x, $size_y, $dummy = false, $path = "", $cache = "")
{
return $this->CreateThumbnail($pic, $size_x, $size_y, $dummy, $path, $cache);
}
// METHOD: adbMsg
// PARAMS: level -> info/warning/error
// msg -> string, can be printf formated
// var array -> optional data for a possible printf formated msg
// RETURN: none
// DESC: wrapper function to fill up the mssages array
public function adbMsg($level, $msg, $vars = array ())
{
if (!preg_match("/^info|warning|error$/", $level)) {
$level = "info";
}
// REMARK: below function has moved to "Class.Basic"
// METHOD: adbAssocArray
// PARAMS: db array, key, value part
// RETURN: returns and associative array
// DESC: creates out of a normal db_return array an assoc array
public function adbAssocArray($db_array, $key, $value)
{
return $this->GenAssocArray($db_array, $key, $value);
}
// REMARK: below function has moved to "Class.Basic"
// METHOD: adbByteStringFormat
// PARAMS: int
// RETURN: string
// DESC: converts bytes into formated string with KB, MB, etc
public function adbByteStringFormat($number)
{
return $this->ByteStringFormat($number);
}
// REMARK: below function has moved to "Class.Basic"
// METHOD: adbCreateThumbnail
// PARAMS: id from picture where from we create a thumbnail
// x -> max x size of thumbnail
// y -> max y size of thumbnail
// dummy -> if set to true, then if no images was found we show a dummy image
// path -> if source start is not ROOT path, if empty ROOT is choosen
// cache -> cache path, if not given TMP is used
// RETURN: thumbnail name
// DESC: converts picture to a thumbnail with max x and max y size
public function adbCreateThumbnail($pic, $size_x, $size_y, $dummy = false, $path = "", $cache = "")
{
return $this->CreateThumbnail($pic, $size_x, $size_y, $dummy, $path, $cache);
}
// METHOD: adbMsg
// PARAMS: level -> info/warning/error
// msg -> string, can be printf formated
// var array -> optional data for a possible printf formated msg
// RETURN: none
// DESC: wrapper function to fill up the mssages array
public function adbMsg($level, $msg, $vars = array ())
{
if (!preg_match("/^info|warning|error$/", $level))
$level = "info";
$this->messages[] = array (
'msg' => sprintf($this->l->__($msg), $vars),
'class' => $level
);
switch ($level)
{
case 'info': $this->info = 1; break;
case 'warning': $this->warning = 1; break;
case 'error': $this->error = 1; break;
}
}
// METHOD: adbLiveQueue
// PARAMS: queue_key -> string to identfy the queue
// type -> INSERT/UPDATE/DELETE
// target -> target table to write to
// data -> SQL part to write, this can include #KEY_VALUE#, #KEY_NAME# for delete sub queries
// key_name -> key name, mostly used for update search
// key_value -> data for the key
// associate -> NULL for free, LOCK for first insert, group key for reference to first entry
// file -> string for special file copy actions; mostyle "test#live;..."
// RETURN: none
// DESC: writes live queue
public function adbLiveQueue($queue_key, $type, $target, $data, $key_name, $key_value, $associate = NULL, $file = NULL)
{
$q = "INSERT INTO ".GLOBAL_DB_SCHEMA.".live_queue (";
$q .= "queue_key, key_value, key_name, type, target, data, group_key, action, associate, file";
$q .= ") VALUES (";
$q .= "'".$this->db_escape_string($queue_key)."', '".$this->db_escape_string($key_value)."', '".$this->db_escape_string($key_name)."', '".$this->db_escape_string($type)."', '".$this->db_escape_string($target)."', '".$this->db_escape_string($data)."', '".$this->queue_key."', '".$this->action."', '".$this->db_escape_string($associate)."', '".$this->db_escape_string($file)."')";
$this->db_exec($q);
}
// METHOD: adbPrintDateTime
// PARAMS: year, month, day, hour, min: the date and time values
// suffix: additional info printed after the date time variable in the drop down, also used for ID in the on change JS call
// minute steps, can be 1 (default), 5, 10, etc, if invalid (outside 1h range, it falls back to 1min)
// RETURN: HTML formated strings for drop down lists of date and time
// DESC: print the date/time drop downs, used in any queue/send/insert at date/time place
public function adbPrintDateTime($year, $month, $day, $hour, $min, $suffix = '', $min_steps = 1)
{
// if suffix given, add _ before
if ($suffix)
$suffix = '_'.$suffix;
if ($min_steps < 1 || $min_steps > 59)
$min_steps = 1;
$on_change_call = 'dt_list(\''.$suffix.'\');';
// always be 1h ahead (for safety)
$timestamp = time() + 3600; // in seconds
// the max year is this year + 1;
$max_year = date("Y", $timestamp) + 1;
// preset year, month, ...
$year = (!$year) ? date("Y", $timestamp) : $year;
$month = (!$month) ? date("m", $timestamp) : $month;
$day = (!$day) ? date("d", $timestamp) : $day;
$hour = (!$hour) ? date("H", $timestamp) : $hour;
$min = (!$min) ? date("i", $timestamp) : $min; // add to five min?
// max days in selected month
$days_in_month = date("t", strtotime($year."-".$month."-".$day." ".$hour.":".$min.":0"));
// from now to ?
$string = $this->l->__('Year').' ';
$string .= '<select id="year'.$suffix.'" name="year'.$suffix.'" onChange="'.$on_change_call.'">';
for ($i = date("Y"); $i <= $max_year; $i ++)
{
$string .= '<option value="'.$i.'" '.(($year == $i) ? 'selected' : '').'>'.$i.'</option>';
}
$string .= '</select> '.$this->l->__('Month').' ';
$string .= '<select id="month'.$suffix.'" name="month'.$suffix.'" onChange="'.$on_change_call.'">';
for ($i = 1; $i <= 12; $i ++)
{
$string .= '<option value="'.(($i < 10) ? '0'.$i : $i).'" '.(($month == $i) ? 'selected' : '').'>'.$i.'</option>';
}
$string .= '</select> '.$this->l->__('Day').' ';
$string .= '<select id="day'.$suffix.'" name="day'.$suffix.'" onChange="'.$on_change_call.'">';
for ($i = 1; $i <= $days_in_month; $i ++)
{
// set weekday text based on current month ($month) and year ($year)
$string .= '<option value="'.(($i < 10) ? '0'.$i : $i).'" '.(($day == $i) ? 'selected' : '').'>'.$i.' ('.$this->l->__(date('D', mktime(0, 0, 0, $month, $i, $year))).')</option>';
}
$string .= '</select> '.$this->l->__('Hour').' ';
$string .= '<select id="hour'.$suffix.'" name="hour'.$suffix.'" onChange="'.$on_change_call.'">';
for ($i = 0; $i <= 23; $i ++)
{
$string .= '<option value="'.(($i < 10) ? '0'.$i : $i).'" '.(($hour == $i) ? 'selected' : '').'>'.$i.'</option>';
}
$string .= '</select> '.$this->l->__('Minute').' ';
$string .= '<select id="min'.$suffix.'" name="min'.$suffix.'" onChange="'.$on_change_call.'">';
for ( $i = 0; $i <= 59; $i += $min_steps)
{
$string .= '<option value="'.(( $i < 10) ? '0'.$i : $i).'" '.(($min == $i) ? 'selected' : '').'>'.$i.'</option>';
}
$string .= '</select>';
// return the datetime select string
return $string;
$this->messages[] = array (
'msg' => sprintf($this->l->__($msg), $vars),
'class' => $level
);
switch ($level) {
case 'info':
$this->info = 1;
break;
case 'warning':
$this->warning = 1;
break;
case 'error':
$this->error = 1;
break;
}
}
?>
// METHOD: adbLiveQueue
// PARAMS: queue_key -> string to identfy the queue
// type -> INSERT/UPDATE/DELETE
// target -> target table to write to
// data -> SQL part to write, this can include #KEY_VALUE#, #KEY_NAME# for delete sub queries
// key_name -> key name, mostly used for update search
// key_value -> data for the key
// associate -> NULL for free, LOCK for first insert, group key for reference to first entry
// file -> string for special file copy actions; mostyle "test#live;..."
// RETURN: none
// DESC: writes live queue
public function adbLiveQueue($queue_key, $type, $target, $data, $key_name, $key_value, $associate = null, $file = null)
{
$q = "INSERT INTO ".GLOBAL_DB_SCHEMA.".live_queue (";
$q .= "queue_key, key_value, key_name, type, target, data, group_key, action, associate, file";
$q .= ") VALUES (";
$q .= "'".$this->db_escape_string($queue_key)."', '".$this->db_escape_string($key_value)."', ";
$q .= "'".$this->db_escape_string($key_name)."', '".$this->db_escape_string($type)."', ";
$q .= "'".$this->db_escape_string($target)."', '".$this->db_escape_string($data)."', ";
$q .= "'".$this->queue_key."', '".$this->action."', '".$this->db_escape_string($associate)."', ";
$q .= "'".$this->db_escape_string($file)."')";
$this->db_exec($q);
}
// METHOD: adbPrintDateTime
// PARAMS: year, month, day, hour, min: the date and time values
// suffix: additional info printed after the date time variable in the drop down, also used for ID in the on change JS call
// minute steps, can be 1 (default), 5, 10, etc, if invalid (outside 1h range, it falls back to 1min)
// RETURN: HTML formated strings for drop down lists of date and time
// DESC: print the date/time drop downs, used in any queue/send/insert at date/time place
public function adbPrintDateTime($year, $month, $day, $hour, $min, $suffix = '', $min_steps = 1)
{
// if suffix given, add _ before
if ($suffix) {
$suffix = '_'.$suffix;
}
if ($min_steps < 1 || $min_steps > 59) {
$min_steps = 1;
}
$on_change_call = 'dt_list(\''.$suffix.'\');';
// always be 1h ahead (for safety)
$timestamp = time() + 3600; // in seconds
// the max year is this year + 1;
$max_year = date("Y", $timestamp) + 1;
// preset year, month, ...
$year = (!$year) ? date("Y", $timestamp) : $year;
$month = (!$month) ? date("m", $timestamp) : $month;
$day = (!$day) ? date("d", $timestamp) : $day;
$hour = (!$hour) ? date("H", $timestamp) : $hour;
$min = (!$min) ? date("i", $timestamp) : $min; // add to five min?
// max days in selected month
$days_in_month = date("t", strtotime($year."-".$month."-".$day." ".$hour.":".$min.":0"));
// from now to ?
$string = $this->l->__('Year').' ';
$string .= '<select id="year'.$suffix.'" name="year'.$suffix.'" onChange="'.$on_change_call.'">';
for ($i = date("Y"); $i <= $max_year; $i ++) {
$string .= '<option value="'.$i.'" '.(($year == $i) ? 'selected' : '').'>'.$i.'</option>';
}
$string .= '</select> '.$this->l->__('Month').' ';
$string .= '<select id="month'.$suffix.'" name="month'.$suffix.'" onChange="'.$on_change_call.'">';
for ($i = 1; $i <= 12; $i ++) {
$string .= '<option value="'.(($i < 10) ? '0'.$i : $i).'" '.(($month == $i) ? 'selected' : '').'>'.$i.'</option>';
}
$string .= '</select> '.$this->l->__('Day').' ';
$string .= '<select id="day'.$suffix.'" name="day'.$suffix.'" onChange="'.$on_change_call.'">';
for ($i = 1; $i <= $days_in_month; $i ++) {
// set weekday text based on current month ($month) and year ($year)
$string .= '<option value="'.(($i < 10) ? '0'.$i : $i).'" '.(($day == $i) ? 'selected' : '').'>'.$i.' ('.$this->l->__(date('D', mktime(0, 0, 0, $month, $i, $year))).')</option>';
}
$string .= '</select> '.$this->l->__('Hour').' ';
$string .= '<select id="hour'.$suffix.'" name="hour'.$suffix.'" onChange="'.$on_change_call.'">';
for ($i = 0; $i <= 23; $i ++) {
$string .= '<option value="'.(($i < 10) ? '0'.$i : $i).'" '.(($hour == $i) ? 'selected' : '').'>'.$i.'</option>';
}
$string .= '</select> '.$this->l->__('Minute').' ';
$string .= '<select id="min'.$suffix.'" name="min'.$suffix.'" onChange="'.$on_change_call.'">';
for ($i = 0; $i <= 59; $i += $min_steps) {
$string .= '<option value="'.(( $i < 10) ? '0'.$i : $i).'" '.(($min == $i) ? 'selected' : '').'>'.$i.'</option>';
}
$string .= '</select>';
// return the datetime select string
return $string;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,515 +1,497 @@
<?
/*********************************************************************
* AUTHOR: Clemens "Gullevek" Schwaighofer (www.gullevek.org)
* CREATED: 2002/12/17
* VERSION: 0.4.0
* RELEASED LICENSE: GNU GPL 3
* SHORT DESCRIPTION:
* DB Array IO Class:
* writes, reads or deletes a complete array (one data set) in/out a
* table from the connected DB.
* you don't have to write any SQL queries, worry over update/insert
*
* PUBLIC VARIABLES
*
* PRIVATE VARIABLES
*
* PUBLIC METHODS
*
* PRIVATE METHODS
*
* HISTORY:
* 2005/07/07 (cs) updated array class for postgres: set 0 & NULL if int field given, insert uses () values () syntax
* 2005/03/31 (cs) fixed the class call with all debug vars
* 2003-03-10: error_ids where still wrong chagned 11->21 and 12->22
* 2003-02-26: db_array_io is no longer single class but extens db_io,
* as it needs it anyway
* moved the class info vars into class_info array into
* the constructor, removed info function
* 2003-02-24: in db_delete moved query build to top, or pk_name/value
* will be reset before delete is done
* 2002-12-20: just added info() method
* 2002-12-17: splitted the class from other file (with main db wrapper)
*********************************************************************/
/*********************************************************************
* AUTHOR: Clemens "Gullevek" Schwaighofer (www.gullevek.org)
* CREATED: 2002/12/17
* VERSION: 0.4.0
* RELEASED LICENSE: GNU GPL 3
* SHORT DESCRIPTION:
* DB Array IO Class:
* writes, reads or deletes a complete array (one data set) in/out a
* table from the connected DB.
* you don't have to write any SQL queries, worry over update/insert
*
* PUBLIC VARIABLES
*
* PRIVATE VARIABLES
*
* PUBLIC METHODS
*
* PRIVATE METHODS
*
* HISTORY:
* 2005/07/07 (cs) updated array class for postgres: set 0 & NULL if int field given, insert uses () values () syntax
* 2005/03/31 (cs) fixed the class call with all debug vars
* 2003-03-10: error_ids where still wrong chagned 11->21 and 12->22
* 2003-02-26: db_array_io is no longer single class but extens db_io,
* as it needs it anyway
* moved the class info vars into class_info array into
* the constructor, removed info function
* 2003-02-24: in db_delete moved query build to top, or pk_name/value
* will be reset before delete is done
* 2002-12-20: just added info() method
* 2002-12-17: splitted the class from other file (with main db wrapper)
*********************************************************************/
// picture upload should be taken out from here and out in media_class
// as it actually has nothing to do with this one here ? (or at least
// put into separete function in this class)
// picture upload should be taken out from here and out in media_class
// as it actually has nothing to do with this one here ? (or at least
// put into separete function in this class)
// try to include file from LIBS path, or from normal path
_spl_autoload('Class.DB.IO.inc');
// try to include file from LIBS path, or from normal path
_spl_autoload('Class.DB.IO.inc');
// subclass for one array handling
class db_array_io extends db_io
// subclass for one array handling
class db_array_io extends db_io
{
// main calss variables
public $table_array; // the array from the table to work on
public $table_name; // the table_name
public $pk_name; // the primary key from this table
public $pk_id; // the PK id
// METHOD db_array_io
// PARAMS db_config -> db_io class init vars
// table_array -> the array from the table
// table_name -> name of the table (for the array)
// db_debug -> turn on db_io debug output (DB_DEBUG as global var does the same)
// RETURN none
// DESC constructor for the array io class, set the
// primary key name automatically (from array)
public function __construct($db_config, $table_array, $table_name, $debug = 0, $db_debug = 0, $echo = 1, $print = 0)
{
// main calss variables
public $table_array; // the array from the table to work on
public $table_name; // the table_name
public $pk_name; // the primary key from this table
public $pk_id; // the PK id
// instance db_io class
parent::__construct($db_config, $debug, $db_debug, $echo, $print);
// more error vars for this class
$this->error_string["21"] = "No Primary Key given";
$this->error_string["22"] = "Could not run Array Query";
// METHOD db_array_io
// PARAMS db_config -> db_io class init vars
// table_array -> the array from the table
// table_name -> name of the table (for the array)
// db_debug -> turn on db_io debug output (DB_DEBUG as global var does the same)
// RETURN none
// DESC constructor for the array io class, set the
// primary key name automatically (from array)
public function __construct($db_config, $table_array, $table_name, $debug = 0, $db_debug = 0, $echo = 1, $print = 0)
{
// instance db_io class
parent::__construct($db_config, $debug, $db_debug, $echo, $print);
// more error vars for this class
$this->error_string["21"] = "No Primary Key given";
$this->error_string["22"] = "Could not run Array Query";
$this->table_array = $table_array;
$this->table_name = $table_name;
$this->table_array = $table_array;
$this->table_name = $table_name;
// set primary key for given table_array
if ($this->table_array)
{
while (list($key, $value) = each($table_array))
{
if ($value["pk"])
$this->pk_name = $key;
// set primary key for given table_array
if ($this->table_array) {
while (list($key, $value) = each($table_array)) {
if ($value["pk"]) {
$this->pk_name = $key;
}
} // set pk_name IF table_array was given
// internal
$this->class_info["db_array_io"] = array(
"class_name" => "DB Array IO",
"class_version" => "0.4.0",
"class_created" => "2002/12/17",
"class_author" => "cs/gullevek/at"
);
}
// deconstruktor
public function __destruct()
{
parent::__destruct();
}
// METHOD convert_data
// PARAMS string -> the string that should be changed
// RETURN string -> the altered string
// DESC changes all previously alterd HTML code into visible one,
// works for <b>,<i>, and <a> (thought <a> can be / or should
// be handled with the magic links functions
// used with the read function
public function convert_data($text)
{
$text = eregi_replace ('&lt;b&gt;', '<B>', $text);
$text = eregi_replace ('&lt;/b&gt;', '</B>', $text);
$text = eregi_replace ('&lt;i&gt;', '<I>', $text);
$text = eregi_replace ('&lt;/i&gt;', '</I>', $text);
// my need a change
$text = eregi_replace ('&lt;a href=&quot;', '<A TARGET="_blank" HREF="', $text);
$text = eregi_replace ('&quot;&gt;', '">', $text);
$text = eregi_replace ('&lt;/a&gt;', '</A>', $text);
return $text;
}
// METHOD convert_entities
// PARAMS string -> string to be changed
// RETURN string -> altered string
// DESC changeds all HTML entities into non HTML ones
public function convert_entities($text)
{
$text = str_replace('&lt;', '<', $text);
$text = str_replace('&gt;', '>', $text);
$text = str_replace('&amp;', '&', $text);
$text = str_replace('&quot;', '"', $text);
$text = str_replace('&#039;', "'", $text);
return $text;
}
// METHOD db_dump_array
// PARAMS none
// RETURN returns the current array
// DESC dumps the current data
public function db_dump_array($write = 0)
{
reset($this->table_array);
while(list($column, $data_array) = each($this->table_array))
{
$string .= "<b>".$column."</b> -> ".$data_array["value"]."<br>";
}
// add output to internal error_msg
if ($write)
$this->error_msg['db'] .= $string;
return $string;
}
} // set pk_name IF table_array was given
// internal
$this->class_info["db_array_io"] = array(
"class_name" => "DB Array IO",
"class_version" => "0.4.0",
"class_created" => "2002/12/17",
"class_author" => "cs/gullevek/at"
);
}
// METHOD _db_error
// PARAMS none
// RETURN none
// DESC writes errors to internal error string
// deconstruktor
public function __destruct()
{
parent::__destruct();
}
// METHOD convert_data
// PARAMS string -> the string that should be changed
// RETURN string -> the altered string
// DESC changes all previously alterd HTML code into visible one,
// works for <b>,<i>, and <a> (thought <a> can be / or should
// be handled with the magic links functions
// used with the read function
public function convert_data($text)
{
$text = str_replace('&lt;b&gt;', '<b>', $text);
$text = str_replace('&lt;/b&gt;', '</b>', $text);
$text = str_replace('&lt;i&gt;', '<i>', $text);
$text = str_replace('&lt;/i&gt;', '</i>', $text);
// my need a change
$text = str_replace('&lt;a href=&quot;', '<a target="_blank" href="', $text);
$text = str_replace('&quot;&gt;', '">', $text);
$text = str_replace('&lt;/a&gt;', '</a>', $text);
return $text;
}
// METHOD convert_entities
// PARAMS string -> string to be changed
// RETURN string -> altered string
// DESC changeds all HTML entities into non HTML ones
public function convert_entities($text)
{
$text = str_replace('&lt;', '<', $text);
$text = str_replace('&gt;', '>', $text);
$text = str_replace('&amp;', '&', $text);
$text = str_replace('&quot;', '"', $text);
$text = str_replace('&#039;', "'", $text);
return $text;
}
// METHOD db_dump_array
// PARAMS none
// RETURN returns the current array
// DESC dumps the current data
public function db_dump_array($write = 0)
{
reset($this->table_array);
while (list($column, $data_array) = each($this->table_array)) {
$string .= "<b>".$column."</b> -> ".$data_array["value"]."<br>";
}
// add output to internal error_msg
if ($write) {
$this->error_msg['db'] .= $string;
}
return $string;
}
// METHOD _db_error
// PARAMS none
// RETURN none
// DESC writes errors to internal error string
/* function _db_error()
{
// if error occured
if ($this->error_id)
{
// if error occured
if ($this->error_id)
{
$this->error_msg['db'] .= "<b>-DB_ARRAY-error-></b> ".$this->error_id.": ".$this->error_string[$this->error_id]." <br>";
}
} */
// METHOD db_check_pk_set
// PARAMS none
// RETURN none
// DESC checks if pk is set and if not, set from pk_id and if this also not set return 0
public function db_check_pk_set()
{
// if pk_id is set, overrule ...
if ($this->pk_id)
$this->table_array[$this->pk_name]["value"] = $this->pk_id;
// if not set ... produce error
if (!$this->table_array[$this->pk_name]["value"])
{
// if no PK found, error ...
$this->error_id = 21;
$this->_db_error();
return 0;
}
else
return 1;
$this->error_msg['db'] .= "<b>-DB_ARRAY-error-></b> ".$this->error_id.": ".$this->error_string[$this->error_id]." <br>";
}
} */
// METHOD db_reset_array
// PARAMS reset_pk -> if set reset the pk too
// RETURN none
// DESC resets the whole array
public function db_reset_array($reset_pk = 0)
{
reset($this->table_array);
while(list($column, $data_array) = each($this->table_array))
{
if (!$this->table_array[$column]["pk"])
unset($this->table_array[$column]["value"]);
else if ($reset_pk)
unset($this->table_array[$column]["value"]);
}
// METHOD db_check_pk_set
// PARAMS none
// RETURN none
// DESC checks if pk is set and if not, set from pk_id and if this also not set return 0
public function db_check_pk_set()
{
// if pk_id is set, overrule ...
if ($this->pk_id) {
$this->table_array[$this->pk_name]["value"] = $this->pk_id;
}
// if not set ... produce error
if (!$this->table_array[$this->pk_name]["value"]) {
// if no PK found, error ...
$this->error_id = 21;
$this->_db_error();
return 0;
} else {
return 1;
}
}
// METHOD db_delete
// PARAMS optional the table_array, if not given uses class var
// RETURN 1 for successfull delete or 0 for error
// DESC deletes one dataset
public function db_delete($table_array = 0)
{
if (is_array($table_array))
$this->table_array = $table_array;
if (!$this->db_check_pk_set())
return $this->table_array;
// delete query
$q = "DELETE FROM ".$this->table_name." WHERE ";
$q .= $this->pk_name." = ".$this->table_array[$this->pk_name]["value"]." ";
// delete files and build FK query
reset($this->table_array);
while(list($column, $data_array) = each($this->table_array))
{
// suchen nach bildern und löschen ...
if ($this->table_array[$column]["file"] && file_exists($this->table_array[$column]["url"].$this->table_array[$column]["value"]))
{
if (file_exists($this->table_array[$column]["path"].$this->table_array[$column]["value"]))
unlink($this->table_array[$column]["path"].$this->table_array[$column]["value"]);
$dateiname = str_replace("_tn", "", $this->table_array[$column]["value"]);
if (file_exists($this->table_array[$column]["path"].$dateiname))
unlink($this->table_array[$column]["path"].$dateiname);
}
if ($this->table_array[$column]["fk"])
{
// zusammenstellen der FKs
if ($q_where)
$q_where .= " AND ";
$q_where .= $column." = ".$this->table_array[$column]["value"];
}
// allgemeines zurücksetzen des arrays
// METHOD db_reset_array
// PARAMS reset_pk -> if set reset the pk too
// RETURN none
// DESC resets the whole array
public function db_reset_array($reset_pk = 0)
{
reset($this->table_array);
while (list($column, $data_array) = each($this->table_array)) {
if (!$this->table_array[$column]["pk"]) {
unset($this->table_array[$column]["value"]);
} elseif ($reset_pk) {
unset($this->table_array[$column]["value"]);
}
}
}
// attach fk row if there ...
if ($q_where)
$q .= " AND ".$q_where;
// if 0, error
unset ($this->pk_id);
if (!$this->db_exec($q))
{
$this->error_id=22;
$this->_db_error();
}
// METHOD db_delete
// PARAMS optional the table_array, if not given uses class var
// RETURN 1 for successfull delete or 0 for error
// DESC deletes one dataset
public function db_delete($table_array = 0)
{
if (is_array($table_array)) {
$this->table_array = $table_array;
}
if (!$this->db_check_pk_set()) {
return $this->table_array;
}
// METHOD db_read
// PARAMS edit -> if 1 data will not be altered for output, optional the table_array, if not given uses class var
// RETURN true or false for reading
// DESC reads one row into the array
public function db_read($edit = 0, $table_array = 0)
{
// if array give, overrules internal array
if (is_array($table_array))
$this->table_array = $table_array;
if (!$this->db_check_pk_set())
return $this->table_array;
reset($this->table_array);
// create select part & addition FK part
while (list($column, $data_array)=each($this->table_array))
{
if ($q_select)
$q_select .= ", ";
$q_select .= $column;
// check FK ...
if ($this->table_array[$column]["fk"] && $this->table_array[$column]["value"])
{
if ($q_where)
$q_where .= " AND ";
$q_where .= $column .= " = ".$this->table_array[$column]["value"];
// delete query
$q = "DELETE FROM ".$this->table_name." WHERE ";
$q .= $this->pk_name." = ".$this->table_array[$this->pk_name]["value"]." ";
// delete files and build FK query
reset($this->table_array);
while (list($column, $data_array) = each($this->table_array)) {
// suchen nach bildern und löschen ...
if ($this->table_array[$column]["file"] && file_exists($this->table_array[$column]["url"].$this->table_array[$column]["value"])) {
if (file_exists($this->table_array[$column]["path"].$this->table_array[$column]["value"])) {
unlink($this->table_array[$column]["path"].$this->table_array[$column]["value"]);
}
$dateiname = str_replace("_tn", "", $this->table_array[$column]["value"]);
if (file_exists($this->table_array[$column]["path"].$dateiname)) {
unlink($this->table_array[$column]["path"].$dateiname);
}
}
$q = "SELECT ";
$q .= $q_select;
$q .= " FROM ".$this->table_name." WHERE ";
$q .= $this->pk_name." = ".$this->table_array[$this->pk_name]["value"]." ";
if ($q_where)
$q .= " AND ".$q_where;
if ($this->table_array[$column]["fk"]) {
// zusammenstellen der FKs
if ($q_where) {
$q_where .= " AND ";
}
$q_where .= $column." = ".$this->table_array[$column]["value"];
}
// allgemeines zurücksetzen des arrays
unset($this->table_array[$column]["value"]);
}
// if query was executed okay, else set error
if ($this->db_exec($q))
{
if ($res = $this->db_fetch_array())
{
reset($this->table_array);
while (list($column, $data_array) = each($this->table_array))
{
// wenn "edit" dann gib daten wie in DB zurück, ansonten aufbereiten für ausgabe
// ?? sollte das nicht draußen ??? man weis ja net was da drin steht --> is noch zu überlegen
// echo "EDIT: $edit | Spalte: $column | type: ".$this->table_array[$column]["type"]." | Res: ".$res[$column]."<br>";
if ($edit)
{
$this->table_array[$column]["value"] = $res[$column];
// if password, also write to hidden
if ($this->table_array[$column]["type"] == "password")
{
$this->table_array[$column]["HIDDEN_value"] = $res[$column];
}
}
else
{
$this->table_array[$column]["value"] = $this->convert_data(nl2br($res[$column]));
// had to put out the htmlentities from the line above as it breaks japanese characters
// attach fk row if there ...
if ($q_where) {
$q .= " AND ".$q_where;
}
// if 0, error
unset($this->pk_id);
if (!$this->db_exec($q)) {
$this->error_id=22;
$this->_db_error();
}
return $this->table_array;
}
// METHOD db_read
// PARAMS edit -> if 1 data will not be altered for output, optional the table_array, if not given uses class var
// RETURN true or false for reading
// DESC reads one row into the array
public function db_read($edit = 0, $table_array = 0)
{
// if array give, overrules internal array
if (is_array($table_array)) {
$this->table_array = $table_array;
}
if (!$this->db_check_pk_set()) {
return $this->table_array;
}
reset($this->table_array);
// create select part & addition FK part
while (list($column, $data_array)=each($this->table_array)) {
if ($q_select) {
$q_select .= ", ";
}
$q_select .= $column;
// check FK ...
if ($this->table_array[$column]["fk"] && $this->table_array[$column]["value"]) {
if ($q_where) {
$q_where .= " AND ";
}
$q_where .= $column .= " = ".$this->table_array[$column]["value"];
}
}
$q = "SELECT ";
$q .= $q_select;
$q .= " FROM ".$this->table_name." WHERE ";
$q .= $this->pk_name." = ".$this->table_array[$this->pk_name]["value"]." ";
if ($q_where) {
$q .= " AND ".$q_where;
}
// if query was executed okay, else set error
if ($this->db_exec($q)) {
if ($res = $this->db_fetch_array()) {
reset($this->table_array);
while (list($column, $data_array) = each($this->table_array)) {
// wenn "edit" dann gib daten wie in DB zurück, ansonten aufbereiten für ausgabe
// ?? sollte das nicht draußen ??? man weis ja net was da drin steht --> is noch zu überlegen
// echo "EDIT: $edit | Spalte: $column | type: ".$this->table_array[$column]["type"]." | Res: ".$res[$column]."<br>";
if ($edit) {
$this->table_array[$column]["value"] = $res[$column];
// if password, also write to hidden
if ($this->table_array[$column]["type"] == "password") {
$this->table_array[$column]["HIDDEN_value"] = $res[$column];
}
} else {
$this->table_array[$column]["value"] = $this->convert_data(nl2br($res[$column]));
// had to put out the htmlentities from the line above as it breaks japanese characters
}
}
// possible db_fetch_array errors ...
$this->pk_id = $this->table_array[$this->pk_name]["value"];
}
else
{
$this->error_id = 22;
$this->_db_error();
}
return $this->table_array;
// possible db_fetch_array errors ...
$this->pk_id = $this->table_array[$this->pk_name]["value"];
} else {
$this->error_id = 22;
$this->_db_error();
}
return $this->table_array;
}
// METHOD db_write
// PARAMS addslashes -> if 1 will make an addslashes for each array field, optional the table_array, if not given uses class var
// RETURN true or false on write
// DESC writes on set into DB or updates one set (if PK exists)
public function db_write($addslashes = 0, $table_array = 0)
{
if (is_array($table_array)) {
$this->table_array = $table_array;
}
// PK ID check
// if ($this->pk_id && !$this->table_array[$this->pk_name]["value"]) {
// $this->table_array[$this->pk_name]["value"]=$this->pk_id;
// }
// checken ob PKs gesetzt, wenn alle -> update, wenn keiner -> insert, wenn ein paar -> ERROR!
if (!$this->table_array[$this->pk_name]["value"]) {
$insert = 1;
} else {
$insert = 0;
}
// METHOD db_write
// PARAMS addslashes -> if 1 will make an addslashes for each array field, optional the table_array, if not given uses class var
// RETURN true or false on write
// DESC writes on set into DB or updates one set (if PK exists)
public function db_write($addslashes = 0, $table_array = 0)
{
if (is_array($table_array))
$this->table_array = $table_array;
// PK ID check
// if ($this->pk_id && !$this->table_array[$this->pk_name]["value"])
// $this->table_array[$this->pk_name]["value"]=$this->pk_id;
// checken ob PKs gesetzt, wenn alle -> update, wenn keiner -> insert, wenn ein paar -> ERROR!
if (!$this->table_array[$this->pk_name]["value"])
$insert = 1;
else
$insert = 0;
reset ($this->table_array);
while (list($column, $data_array) = each($this->table_array))
{
reset($this->table_array);
while (list($column, $data_array) = each($this->table_array)) {
/********************************* START FILE *************************************/
// file upload
if ($this->table_array[$column]["file"])
{
// falls was im tmp drinnen, sprich ein upload, datei kopieren, Dateinamen in db schreiben
// falls datei schon am server (physischer pfad), dann einfach url in db schreiben (update)
// falls in "delete" "ja" dann loeschen (und gibts eh nur beim update)
if ($this->table_array[$column]["delete"])
{
unset($this->table_array[$column]["delete"]);
if (file_exists($this->table_array[$column]["path"].$this->table_array[$column]["value"]))
unlink($this->table_array[$column]["path"].$this->table_array[$column]["value"]);
$dateiname = str_replace("_tn", "", $this->table_array[$column]["value"]);
if (file_exists($this->table_array[$column]["path"].$dateiname))
unlink($this->table_array[$column]["path"].$dateiname);
$this->table_array[$column]["value"] = "";
// file upload
if ($this->table_array[$column]["file"]) {
// falls was im tmp drinnen, sprich ein upload, datei kopieren, Dateinamen in db schreiben
// falls datei schon am server (physischer pfad), dann einfach url in db schreiben (update)
// falls in "delete" "ja" dann loeschen (und gibts eh nur beim update)
if ($this->table_array[$column]["delete"]) {
unset($this->table_array[$column]["delete"]);
if (file_exists($this->table_array[$column]["path"].$this->table_array[$column]["value"])) {
unlink($this->table_array[$column]["path"].$this->table_array[$column]["value"]);
}
else
{
if ($this->table_array[$column]["tmp"] != "none" && $this->table_array[$column]["tmp"])
{
// Dateiname zusammenbasteln: org-name + _pkid liste + .ext
list($name, $ext) = explode(".",$this->table_array[$column]["dn"]);
$dateiname = str_replace("_tn", "", $this->table_array[$column]["value"]);
if (file_exists($this->table_array[$column]["path"].$dateiname)) {
unlink($this->table_array[$column]["path"].$dateiname);
}
$this->table_array[$column]["value"] = "";
} else {
if ($this->table_array[$column]["tmp"] != "none" && $this->table_array[$column]["tmp"]) {
// Dateiname zusammenbasteln: org-name + _pkid liste + .ext
list($name, $ext) = explode(".", $this->table_array[$column]["dn"]);
// mozilla, patch
$fn_name = explode("/", $this->table_array[$column]["dn"]);
$this->table_array[$column]["dn"] = $fn_name[count($fn_name)-1];
$filename_parts = explode(".", $this->table_array[$column]["dn"]);
$ext = end($filename_parts);
array_splice($filename_parts, -1, 1);
$name = str_replace(" ", "_", implode(".", $filename_parts));
//echo "PK: $pk_ids_file<br>";
$dateiname = $name.$pk_ids_file.".".$ext;
//echo "Dn: $dateiname";
copy($this->table_array[$column]["tmp"], $this->table_array[$column]["path"].$dateiname);
// automatisch thumbnail generieren, geht nur mit convert (ImageMagic!!!), aber nur bei bild ..
if (strtolower($ext) == "jpeg" || strtolower($ext) == "jpg" || strtolower($ext) == "gif" || strtolower($ext) == "png")
{
$dateiname_tn = $name.$pk_ids_file."_tn.".$ext;
$eingang = $this->table_array[$column]["path"].$dateiname;
$ausgang = $this->table_array[$column]["path"].$dateiname_tn;
$com = "convert -geometry 115 $eingang $ausgang";
exec($com);
$this->table_array[$column]["value"] = $dateiname_tn;
}
else
$this->table_array[$column]["value"] = $dateiname;
// mozilla, patch
$fn_name = explode("/", $this->table_array[$column]["dn"]);
$this->table_array[$column]["dn"] = $fn_name[count($fn_name)-1];
$filename_parts = explode(".", $this->table_array[$column]["dn"]);
$ext = end($filename_parts);
array_splice($filename_parts, -1, 1);
$name = str_replace(" ", "_", implode(".", $filename_parts));
//echo "PK: $pk_ids_file<br>";
$dateiname = $name.$pk_ids_file.".".$ext;
//echo "Dn: $dateiname";
copy($this->table_array[$column]["tmp"], $this->table_array[$column]["path"].$dateiname);
// automatisch thumbnail generieren, geht nur mit convert (ImageMagic!!!), aber nur bei bild ..
if (strtolower($ext) == "jpeg" || strtolower($ext) == "jpg" || strtolower($ext) == "gif" || strtolower($ext) == "png") {
$dateiname_tn = $name.$pk_ids_file."_tn.".$ext;
$eingang = $this->table_array[$column]["path"].$dateiname;
$ausgang = $this->table_array[$column]["path"].$dateiname_tn;
$com = "convert -geometry 115 $eingang $ausgang";
exec($com);
$this->table_array[$column]["value"] = $dateiname_tn;
} else {
$this->table_array[$column]["value"] = $dateiname;
}
else if (file_exists($this->table_array[$column]["path"].$this->table_array[$column]["value"]))
{
// mach gar nix, wenn bild schon da ???
}
} // delete or upload
} // file IF
} elseif (file_exists($this->table_array[$column]["path"].$this->table_array[$column]["value"])) {
// mach gar nix, wenn bild schon da ???
}
} // delete or upload
} // file IF
/********************************* END FILE **************************************/
// do not write 'pk' (primary key) or 'view' values
if (!$this->table_array[$column]["pk"] && $this->table_array[$column]['type'] != 'view' && strlen($column) > 0 )
{
// for password use hidden value if main is not set
if ($this->table_array[$column]["type"] == "password" && !$this->table_array[$column]["value"])
$this->table_array[$column]["value"] = $this->table_array[$column]["HIDDEN_value"];
if (!$insert)
{
if (strlen($q_data))
$q_data .= ", ";
$q_data .= $column." = ";
// do not write 'pk' (primary key) or 'view' values
if (!$this->table_array[$column]["pk"] && $this->table_array[$column]['type'] != 'view' && strlen($column) > 0) {
// for password use hidden value if main is not set
if ($this->table_array[$column]["type"] == "password" && !$this->table_array[$column]["value"]) {
$this->table_array[$column]["value"] = $this->table_array[$column]["HIDDEN_value"];
}
if (!$insert) {
if (strlen($q_data)) {
$q_data .= ", ";
}
else
$q_data .= $column." = ";
} else {
// this is insert
{
if (strlen($q_data))
$q_data .= ", ";
if ($q_vars)
$q_vars .= ", ";
$q_vars .= $column;
if (strlen($q_data)) {
$q_data .= ", ";
}
// integer is different
if ($this->table_array[$column]["int"] || $this->table_array[$column]["int_null"])
{
$this->debug('write_check', "[$column][".$this->table_array[$column]["value"]."] Foo: ".isset($this->table_array[$column]["value"])." | ".$this->table_array[$column]["int_null"]);
if (!$this->table_array[$column]["value"] && $this->table_array[$column]["int_null"])
$_value = 'NULL';
elseif (!isset($this->table_array[$column]["value"]))
$_value = 0;
else
$_value = $this->table_array[$column]["value"];
$q_data .= $_value;
if ($q_vars) {
$q_vars .= ", ";
}
elseif ($this->table_array[$column]["interval"])
{
// for interval we check if no value, then we set null
if (!$this->table_array[$column]["value"])
$_value = 'NULL';
$q_data .= $_value;
$q_vars .= $column;
}
// integer is different
if ($this->table_array[$column]["int"] || $this->table_array[$column]["int_null"]) {
$this->debug('write_check', "[$column][".$this->table_array[$column]["value"]."] Foo: ".isset($this->table_array[$column]["value"])." | ".$this->table_array[$column]["int_null"]);
if (!$this->table_array[$column]["value"] && $this->table_array[$column]["int_null"]) {
$_value = 'NULL';
} elseif (!isset($this->table_array[$column]["value"])) {
$_value = 0;
} else {
$_value = $this->table_array[$column]["value"];
}
else
$q_data .= $_value;
} elseif ($this->table_array[$column]["interval"]) {
// for interval we check if no value, then we set null
if (!$this->table_array[$column]["value"]) {
$_value = 'NULL';
}
$q_data .= $_value;
} else {
// normal string
{
$q_data .= "'";
// if add slashes do convert & add slashes else write AS is
if ($addslashes)
$q_data .= $this->db_escape_string($this->convert_entities($this->table_array[$column]["value"]));
else
$q_data .= $this->db_escape_string($this->table_array[$column]["value"]);
$q_data .= "'";
$q_data .= "'";
// if add slashes do convert & add slashes else write AS is
if ($addslashes) {
$q_data .= $this->db_escape_string($this->convert_entities($this->table_array[$column]["value"]));
} else {
$q_data .= $this->db_escape_string($this->table_array[$column]["value"]);
}
}
} // while ...
// NOW get PK, and FK settings (FK only for update query)
// get it at the end, cause now we can be more sure of no double IDs, etc
reset($this->table_array);
// create select part & addition FK part
while (list($column, $data_array) = each($this->table_array))
{
// check FK ...
if ($this->table_array[$column]["fk"] && $this->table_array[$column]["value"])
{
if ($q_where)
$q_where .= " AND ";
$q_where .= $column .= " = ".$this->table_array[$column]["value"];
$q_data .= "'";
}
}
} // while ...
// if no PK set, then get max ID from DB
if (!$this->table_array[$this->pk_name]["value"])
{
// max id, falls INSERT
$q = "SELECT MAX(".$this->pk_name.") + 1 AS pk_id FROM ".$this->table_name;
$res = $this->db_return_row($q);
if (!$res["pk_id"])
$res["pk_id"] = 1;
$this->table_array[$this->pk_name]["value"] = $res["pk_id"];
// NOW get PK, and FK settings (FK only for update query)
// get it at the end, cause now we can be more sure of no double IDs, etc
reset($this->table_array);
// create select part & addition FK part
while (list($column, $data_array) = each($this->table_array)) {
// check FK ...
if ($this->table_array[$column]["fk"] && $this->table_array[$column]["value"]) {
if ($q_where) {
$q_where .= " AND ";
}
$q_where .= $column .= " = ".$this->table_array[$column]["value"];
}
if (!$insert)
{
$q = "UPDATE ".$this->table_name." SET ";
$q .= $q_data;
$q .= " WHERE ";
$q .= $this->pk_name." = ".$this->table_array[$this->pk_name]["value"]." ";
if ($q_where)
$q .= " AND ".$q_where;
// set pk_id ... if it has changed or so
$this->pk_id = $this->table_array[$this->pk_name]["value"];
}
else
{
$q = "INSERT INTO ".$this->table_name." ";
$q .= "(".$q_vars.") ";
$q .= "VALUES (".$q_data.")";
// write primary key too
/* if ($q_data)
$q .= ", ";
$q .= $this->pk_name." = ".$this->table_array[$this->pk_name]["value"]." ";
$this->pk_id = $this->table_array[$this->pk_name]["value"];
*/
}
// return success or not
if (!$this->db_exec($q))
{
$this->error_id = 22;
$this->_db_error();
}
// set primary key
if ($insert)
{
$this->table_array[$this->pk_name]["value"] = $this->insert_id;
$this->ok = $this->insert_id;
}
// return the table if needed
return $this->table_array;
}
} // end of class
?>
// if no PK set, then get max ID from DB
if (!$this->table_array[$this->pk_name]["value"]) {
// max id, falls INSERT
$q = "SELECT MAX(".$this->pk_name.") + 1 AS pk_id FROM ".$this->table_name;
$res = $this->db_return_row($q);
if (!$res["pk_id"]) {
$res["pk_id"] = 1;
}
$this->table_array[$this->pk_name]["value"] = $res["pk_id"];
}
if (!$insert) {
$q = "UPDATE ".$this->table_name." SET ";
$q .= $q_data;
$q .= " WHERE ";
$q .= $this->pk_name." = ".$this->table_array[$this->pk_name]["value"]." ";
if ($q_where) {
$q .= " AND ".$q_where;
}
// set pk_id ... if it has changed or so
$this->pk_id = $this->table_array[$this->pk_name]["value"];
} else {
$q = "INSERT INTO ".$this->table_name." ";
$q .= "(".$q_vars.") ";
$q .= "VALUES (".$q_data.")";
// write primary key too
// if ($q_data)
// $q .= ", ";
// $q .= $this->pk_name." = ".$this->table_array[$this->pk_name]["value"]." ";
// $this->pk_id = $this->table_array[$this->pk_name]["value"];
}
// return success or not
if (!$this->db_exec($q)) {
$this->error_id = 22;
$this->_db_error();
}
// set primary key
if ($insert) {
$this->table_array[$this->pk_name]["value"] = $this->insert_id;
$this->ok = $this->insert_id;
}
// return the table if needed
return $this->table_array;
}
} // end of class

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -73,10 +73,12 @@ class ProgressBar
public function __construct($width = 0, $height = 0)
{
$this->code = substr(md5(microtime()), 0, 6);
if ($width > 0)
if ($width > 0) {
$this->width = $width;
if ($height > 0)
}
if ($height > 0) {
$this->height = $height;
}
// needs to be called twice or I do not get any output
$this->_flushCache($this->clear_buffer_size_init);
$this->_flushCache($this->clear_buffer_size_init);
@@ -86,8 +88,9 @@ class ProgressBar
private function _flushCache($clear_buffer_size = 0)
{
if (!$clear_buffer_size)
if (!$clear_buffer_size) {
$clear_buffer_size = $this->clear_buffer_size;
}
echo str_repeat(' ', $clear_buffer_size);
ob_flush();
flush();
@@ -96,18 +99,19 @@ class ProgressBar
private function _calculatePercent($step)
{
// avoid divison through 0
if ($this->max - $this->min == 0)
if ($this->max - $this->min == 0) {
$this->max ++;
}
$percent = round(($step - $this->min) / ($this->max - $this->min) * 100);
if ($percent > 100)
if ($percent > 100) {
$percent = 100;
}
return $percent;
}
private function _calculatePosition($step)
{
switch ($this->direction)
{
switch ($this->direction) {
case 'right':
case 'left':
$bar = $this->width;
@@ -118,16 +122,18 @@ class ProgressBar
break;
}
// avoid divison through 0
if ($this->max - $this->min == 0)
if ($this->max - $this->min == 0) {
$this->max ++;
}
$pixel = round(($step - $this->min) * ($bar - ($this->pedding * 2)) / ($this->max - $this->min));
if ($step <= $this->min)
if ($step <= $this->min) {
$pixel = 0;
if ($step >= $this->max)
}
if ($step >= $this->max) {
$pixel = $bar - ($this->pedding * 2);
}
switch ($this->direction)
{
switch ($this->direction) {
case 'right':
$position['left'] = $this->pedding;
$position['top'] = $this->pedding;
@@ -158,10 +164,12 @@ class ProgressBar
private function _setStep($step)
{
if ($step > $this->max)
if ($step > $this->max) {
$step = $this->max;
if ($step < $this->min)
}
if ($step < $this->min) {
$step = $this->min;
}
$this->step = $step;
}
@@ -179,16 +187,17 @@ class ProgressBar
'brd_color' => '#dfdfdf #404040 #404040 #dfdfdf'
);
if ($width > 0)
if ($width > 0) {
$this->frame['width'] = $width;
if ($height > 0)
}
if ($height > 0) {
$this->frame['height'] = $height;
}
}
public function addLabel($type, $name, $value = '&nbsp;')
{
switch($type)
{
switch ($type) {
case 'text':
$this->label[$name] = array(
'type' => 'text',
@@ -242,10 +251,11 @@ class ProgressBar
case 'percentlbl':
case 'percent':
// check font size
if ($this->height <= 11)
if ($this->height <= 11) {
$font_size = $this->height - 1;
else
} else {
$font_size = 11;
}
$this->label[$name] = array(
'type' => $type, // either percent or percentlbl
'value' => $value,
@@ -288,23 +298,23 @@ class ProgressBar
$this->label[$name]['target'] = $target;
}
public function setLabelPosition($name, $left, $top, $width, $height, $align='')
public function setLabelPosition($name, $left, $top, $width, $height, $align = '')
{
// print "SET POSITION[$name]: $left<br>";
// if this is percent, we ignore anything, it is auto positioned
if ($this->label[$name]['type'] != 'percent')
{
foreach (array('top', 'left', 'width', 'height') as $pos_name)
if ($$pos_name !== false)
if ($this->label[$name]['type'] != 'percent') {
foreach (array('top', 'left', 'width', 'height') as $pos_name) {
if ($$pos_name !== false) {
$this->label[$name][$pos_name] = intval($$pos_name);
}
}
if ($align != '')
if ($align != '') {
$this->label[$name]['align'] = $align;
}
}
// init
if ($this->status != 'new')
{
if ($this->status != 'new') {
$output = '<script type="text/JavaScript">';
$output .= 'document.getElementById("plbl'.$name.$this->code.'").style.top="'.$this->label[$name]['top'].'px";';
$output .= 'document.getElementById("plbl'.$name.$this->code.'").style.left="'.$this->label[$name]['left'].'px";';
@@ -320,8 +330,7 @@ class ProgressBar
public function setLabelColor($name, $color)
{
$this->label[$name]['color'] = $color;
if ($this->status != 'new')
{
if ($this->status != 'new') {
echo '<script type="text/JavaScript">document.getElementById("plbl'.$name.$this->code.'").style.color="'.$color.'";</script>'."\n";
$this->_flushCache();
}
@@ -330,8 +339,7 @@ class ProgressBar
public function setLabelBackground($name, $color)
{
$this->label[$name]['bgr_color'] = $color;
if ($this->status != 'new')
{
if ($this->status != 'new') {
echo '<script type="text/JavaScript">document.getElementById("plbl'.$name.$this->code.'").style.background="'.$color.'";</script>'."\n";
$this->_flushCache();
}
@@ -340,24 +348,28 @@ class ProgressBar
public function setLabelFont($name, $size, $family = '', $weight = '')
{
// just in case if it is too small
if (intval($size) < 0)
if (intval($size) < 0) {
$size = 11;
}
// if this is percent, the size is not allowed to be bigger than the bar size - 5px
if ($this->label[$name]['type'] == 'percent' && intval($size) >= $this->height)
if ($this->label[$name]['type'] == 'percent' && intval($size) >= $this->height) {
$size = $this->height - 1;
}
// position the label new if this is percent
if ($this->label[$name]['type'] == 'percent')
if ($this->label[$name]['type'] == 'percent') {
$this->label[$name]['top'] = round(($this->height - intval($size)) / log($this->height - intval($size), 7), 0) - $this->pedding;
}
// print "HEIGHT: ".$this->height.", Size: ".intval($size).", Pedding: ".$this->pedding.", Calc: ".round($this->height - intval($size)).", Log: ".log($this->height - intval($size), 7)."<br>";
// then set like usual
$this->label[$name]['font-size'] = intval($size);
if ($family != '')
if ($family != '') {
$this->label[$name]['font-family'] = $family;
if ($weight != '')
}
if ($weight != '') {
$this->label[$name]['font-weight'] = $weight;
}
if ($this->status != 'new')
{
if ($this->status != 'new') {
$output = '<script type="text/JavaScript">';
$output .= 'document.getElementById("plbl'.$name.$this->code.'").style.font-size="'.$this->label[$name]['font-size'].'px";';
$output .= 'document.getElementById("plbl'.$name.$this->code.'").style.font-family="'.$this->label[$name]['font-family'].'";';
@@ -372,8 +384,7 @@ class ProgressBar
{
$this->label[$name]['value'] = $value;
// print "NAME[$name], Status: ".$this->status.": ".$value."<Br>";
if ($this->status != 'new')
{
if ($this->status != 'new') {
echo '<script type="text/JavaScript">PBlabelText'.$this->code.'("'.$name.'","'.$this->label[$name]['value'].'");</script>'."\n";
$this->_flushCache();
}
@@ -382,8 +393,7 @@ class ProgressBar
public function setBarColor($color)
{
$this->color = $color;
if ($this->status != 'new')
{
if ($this->status != 'new') {
echo '<script type="text/JavaScript">document.getElementById("pbar'.$this->code.'").style.background="'.$color.'";</script>'."\n";
$this->_flushCache();
}
@@ -392,8 +402,7 @@ class ProgressBar
public function setBarBackground($color)
{
$this->bgr_color = $color;
if ($this->status != 'new')
{
if ($this->status != 'new') {
echo '<script type="text/JavaScript">document.getElementById("pbrd'.$this->code.'").style.background="'.$color.'";</script>'."\n";
$this->_flushCache();
}
@@ -403,8 +412,7 @@ class ProgressBar
{
$this->direction = $direction;
if ($this->status != 'new')
{
if ($this->status != 'new') {
$this->position = $this->_calculatePosition($this->step);
echo '<script type="text/JavaScript">';
@@ -426,25 +434,30 @@ class ProgressBar
$this->_setStep($this->step);
$this->position = $this->_calculatePosition($this->step);
if ($this->top || $this->left)
if ($this->top || $this->left) {
$style_master = 'position:relative;top:'.$this->top.'px;left:'.$this->left.'px;width:'.($this->width + 10).'px;';
}
$html = '<div id="pbm'.$this->code.'" style="'.$style_master.'background:'.$this->bgr_color_master.';">';
$style_brd = 'width:'.$this->width.'px;height:'.$this->height.'px;background:'.$this->bgr_color.';';
if ($this->border > 0)
if ($this->border > 0) {
$style_brd .= 'border:'.$this->border.'px solid; border-color:'.$this->brd_color.'; -webkit-border-radius: 5px 5px 5px 5px; border-radius: 5px 5px 5px 5px; -webkit-shadow: 2px 2px 10px rgba(0, 0, 0, 0.25) inset; box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.25) inset;';
}
$style_bar = 'position:relative;width:'.$this->position['width'].'px;height:'.$this->position['height'].'px;background:'.$this->color.';';
if ($this->position['top'] !== false)
if ($this->position['top'] !== false) {
$style_bar .= 'top:'.$this->position['top'].'px;';
if ($this->position['left'] !== false)
}
if ($this->position['left'] !== false) {
$style_bar .= 'left:'.$this->position['left'].'px;';
if ($this->border > 0)
}
if ($this->border > 0) {
$style_bar .= '-webkit-border-radius: 5px 5px 5px 5px; border-radius: 5px 5px 5px 5px; -webkit-shadow: 2px 2px 10px rgba(0, 0, 0, 0.25) inset; box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.25) inset;';
}
if ($this->frame['show'] == true)
{
if ($this->frame['border'] > 0)
if ($this->frame['show'] == true) {
if ($this->frame['border'] > 0) {
$border = 'border:'.$this->frame['border'].'px solid;border-color:'.$this->frame['brd_color'].';margin-top:2px;-webkit-border-radius: 5px 5px 5px 5px; border-radius: 5px 5px 5px 5px;';
}
$html .= '<div id="pfrm'.$this->code.'" style="width:'.$this->frame['width'].'px;height:'.$this->frame['height'].'px;'.$border.'background:'.$this->frame['color'].';">'."\n";
}
@@ -465,34 +478,39 @@ class ProgressBar
$js .= '}'."\n";
//print "DUMP LABEL: <br><pre>".print_r($this->label, 1)."</pre><br>";
foreach ($this->label as $name => $data)
{
foreach ($this->label as $name => $data) {
// set what type of move we do
$move_prefix = $data['type'] == 'button' ? 'margin' : 'padding';
$style_lbl = 'position:relative;';
if ($data['top'] !== false)
if ($data['top'] !== false) {
$style_lbl .= $move_prefix.'-top:'.$data['top'].'px;';
if ($data['left'] !== false)
}
if ($data['left'] !== false) {
$style_lbl .= $move_prefix.'-left:'.$data['left'].'px;';
}
$style_lbl .= 'text-align:'.$data['align'].';';
if ($data['width'] > 0)
if ($data['width'] > 0) {
$style_lbl .= 'width:'.$data['width'].'px;';
if ($data['height'] > 0)
}
if ($data['height'] > 0) {
$style_lbl .= 'height:'.$data['height'].'px;';
}
if (array_key_exists('font-size', $data))
if (array_key_exists('font-size', $data)) {
$style_lbl .= 'font-size:'.$data['font-size'].'px;';
if (array_key_exists('font-family', $data))
}
if (array_key_exists('font-family', $data)) {
$style_lbl .= 'font-family:'.$data['font-family'].';';
if (array_key_exists('font-weight', $data))
}
if (array_key_exists('font-weight', $data)) {
$style_lbl .= 'font-weight:'.$data['font-weight'].';';
if (array_key_exists('bgr_color', $data) && ($data['bgr_color'] != ''))
}
if (array_key_exists('bgr_color', $data) && ($data['bgr_color'] != '')) {
$style_lbl .= 'background:'.$data['bgr_color'].';';
}
if (array_key_exists('type', $data))
{
switch ($data['type'])
{
if (array_key_exists('type', $data)) {
switch ($data['type']) {
case 'text':
$html .= '<div id="plbl'.$name.$this->code.'" style="'.$style_lbl.'margin-bottom:2px;">'.$data['value'].'</div>'."\n";
break;
@@ -505,8 +523,9 @@ class ProgressBar
case 'percent':
// only one inner percent
// print "STYLE[$name]: ".$style_lbl."<br>";
if (!$html_percent)
if (!$html_percent) {
$html_percent = '<div id="plbl'.$name.$this->code.'" style="'.$style_lbl.'width:'.$data['width'].'px;line-height:1;text-shadow: 0 0 .2em white, 0 0 .5em white;">'.$this->_calculatePercent($this->step).'%</div>'."\n";
}
break;
case 'percentlbl':
$html .= '<div id="plbl'.$name.$this->code.'" style="'.$style_lbl.'width:'.$data['width'].'px;">'.$this->_calculatePercent($this->step).'%</div>'."\n";
@@ -535,17 +554,14 @@ class ProgressBar
$html .= $html_bar_bottom;
$html .= $html_button; // any buttons on bottom
if (count($this->label) > 0)
{
if (count($this->label) > 0) {
$js .= 'function PBlabelText'.$this->code.'(name,text) {'."\n";
$js .= ' name = "plbl" + name + "'.$this->code.'";'."\n";
$js .= ' document.getElementById(name).innerHTML=text;'."\n";
$js .= '}'."\n";
}
if ($this->frame['show'] == true)
{
if ($this->frame['show'] == true) {
$html .= '</div>'."\n";
}
@@ -572,40 +588,31 @@ class ProgressBar
$js = '';
$new_position = $this->_calculatePosition($this->step);
if ($new_position['width'] != $this->position['width'] && ($this->direction == 'right' || $this->direction == 'left'))
{
if ($this->direction=='left')
{
if ($new_position['width'] != $this->position['width'] && ($this->direction == 'right' || $this->direction == 'left')) {
if ($this->direction=='left') {
$js .= 'PBposition'.$this->code.'("left",'.$new_position['left'].');';
}
$js .= 'PBposition'.$this->code.'("width",'.$new_position['width'].');';
}
if ($new_position['height'] != $this->position['height'] && ($this->direction == 'up' || $this->direction == 'down'))
{
if ($this->direction=='up')
{
if ($new_position['height'] != $this->position['height'] && ($this->direction == 'up' || $this->direction == 'down')) {
if ($this->direction=='up') {
$js .= 'PBposition'.$this->code.'("top",'.$new_position['top'].');';
}
$js .= 'PBposition'.$this->code.'("height",'.$new_position['height'].');';
}
$this->position = $new_position;
foreach($this->label as $name => $data)
{
if (array_key_exists('type', $data))
{
switch($data['type'])
{
foreach ($this->label as $name => $data) {
if (array_key_exists('type', $data)) {
switch($data['type']) {
case 'step':
if ($this->step != $last_step)
{
if ($this->step != $last_step) {
$js .= 'PBlabelText'.$this->code.'("'.$name.'","'.$this->step.'/'.$this->max.'");';
}
break;
case 'percentlbl':
case 'percent':
$percent = $this->_calculatePercent($this->step);
if ($percent != $this->_calculatePercent($last_step))
{
if ($percent != $this->_calculatePercent($last_step)) {
$js .= 'PBlabelText'.$this->code.'("'.$name.'","'.$percent.'%");';
}
break;
@@ -615,8 +622,7 @@ class ProgressBar
}
}
}
if ($js != '')
{
if ($js != '') {
echo '<script type="text/JavaScript">'.$js.'</script>'."\n";
$this->_flushCache();
}
@@ -634,8 +640,7 @@ class ProgressBar
public function hide()
{
if ($this->status == 'show')
{
if ($this->status == 'show') {
$this->status = 'hide';
$output = '<script type="text/JavaScript">';
@@ -648,8 +653,7 @@ class ProgressBar
public function unhide()
{
if ($this->status == 'hide')
{
if ($this->status == 'hide') {
$this->status = 'show';
$output = '<script type="text/JavaScript">';
@@ -659,6 +663,4 @@ class ProgressBar
$this->_flushCache();
}
}
}
?>

View File

@@ -1,31 +1,29 @@
<?
/********************************************************************
* AUTHOR: Clemens "Gullevek" Schwaighofer (www.gullevek.org)
* CREATED: 2004/12/21
* SHORT DESCRIPTION:
* extends smarty with the l10n class so I can use __(, etc calls
* HISTORY:
* 2005/06/22 (cs) include smarty class here, so there is no need to include it in the main file
*********************************************************************/
/********************************************************************
* AUTHOR: Clemens "Gullevek" Schwaighofer (www.gullevek.org)
* CREATED: 2004/12/21
* SHORT DESCRIPTION:
* extends smarty with the l10n class so I can use __(, etc calls
* HISTORY:
* 2005/06/22 (cs) include smarty class here, so there is no need to include it in the main file
*********************************************************************/
// read in the Smarty class for definition
// use smarty BC for backwards compability
// try to include file from LIBS path, or from normal path
_spl_autoload('SmartyBC.class.php');
// read in the Smarty class for definition
// use smarty BC for backwards compability
// try to include file from LIBS path, or from normal path
_spl_autoload('SmartyBC.class.php');
class SmartyML extends SmartyBC
class SmartyML extends SmartyBC
{
public $l10n;
// constructor class, just sets the language stuff
public function __construct($lang)
{
public $l10n;
// constructor class, just sets the language stuff
public function __construct($lang)
{
SmartyBC::__construct();
_spl_autoload('Class.l10n.inc');
$this->l10n = new l10n($lang);
// variable variable register
$this->register_modifier('getvar', array(&$this, 'get_template_vars'));
}
SmartyBC::__construct();
_spl_autoload('Class.l10n.inc');
$this->l10n = new l10n($lang);
// variable variable register
$this->register_modifier('getvar', array(&$this, 'get_template_vars'));
}
?>
}

View File

@@ -1,117 +1,118 @@
<?
/*********************************************************************
* AUTHOR: Clemens "Gullevek" Schwaighofer (www.gullevek.org)
* CREATED: 2004/11/18
* VERSION: 0.1.1
* RELEASED LICENSE: GNU GPL 3
* SHORT DESCRIPTION:
* init class for gettext. Original was just a function & var setting include for wordpress.
* I changed that to a class to be more portable with my style of coding
*
* PUBLIC VARIABLES
*
* PRIVATE VARIABLES
*
* PUBLIC METHODS
* __: returns string (translated or original if not found)
* _e: echos out string (translated or original if not found)
* __ngettext: should return plural. never tested this.
*
* PRIVATE METHODS
*
* HISTORY:
* 2005/10/17 (cs) made an on the fly switch method (reload of lang)
*********************************************************************/
/*********************************************************************
* AUTHOR: Clemens "Gullevek" Schwaighofer (www.gullevek.org)
* CREATED: 2004/11/18
* VERSION: 0.1.1
* RELEASED LICENSE: GNU GPL 3
* SHORT DESCRIPTION:
* init class for gettext. Original was just a function & var setting include for wordpress.
* I changed that to a class to be more portable with my style of coding
*
* PUBLIC VARIABLES
*
* PRIVATE VARIABLES
*
* PUBLIC METHODS
* __: returns string (translated or original if not found)
* _e: echos out string (translated or original if not found)
* __ngettext: should return plural. never tested this.
*
* PRIVATE METHODS
*
* HISTORY:
* 2005/10/17 (cs) made an on the fly switch method (reload of lang)
*********************************************************************/
// try to include file from LIBS path, or from normal path
_spl_autoload('Class.Basic.inc');
// try to include file from LIBS path, or from normal path
_spl_autoload('Class.Basic.inc');
class l10n extends basic
class l10n extends basic
{
private $lang = '';
private $mofile = '';
private $input;
private $l10n;
public function __construct($lang = '', $path = DEFAULT_TEMPLATE)
{
private $lang = '';
private $mofile = '';
private $input;
private $l10n;
public function __construct($lang = '', $path = DEFAULT_TEMPLATE)
{
foreach (array('streams.php', 'gettext.php') as $include_file)
_spl_autoload($include_file);
if (!$lang)
$this->lang = 'en';
else
$this->lang = $lang;
if (is_dir(LAYOUT.$path.LANG))
$path = LAYOUT.$path.LANG;
elseif (!is_dir($path))
$path = '';
$this->mofile = $path.$this->lang.".mo";
// check if get a readable mofile
if (is_readable($this->mofile))
$this->input = new FileReader($this->mofile);
else
$this->input = false;
$this->l10n = new gettext_reader($this->input);
foreach (array('streams.php', 'gettext.php') as $include_file) {
_spl_autoload($include_file);
}
// reloads the mofile, if the location of the lang file changes
public function l10nReloadMOfile($lang, $path = DEFAULT_TEMPLATE)
{
$old_mofile = $this->mofile;
$old_lang = $this->lang;
if (!$lang) {
$this->lang = 'en';
} else {
$this->lang = $lang;
if (is_dir(LAYOUT.$path.LANG))
$path = LAYOUT.$path.LANG;
elseif (!is_dir($path))
$path = '';
$this->mofile = $path.$this->lang.".mo";
// check if get a readable mofile
if (is_readable($this->mofile))
{
$this->input = new FileReader($this->mofile);
$this->l10n = new gettext_reader($this->input);
}
else
{
// else fall back to the old ones
$this->mofile = $old_mofile;
$this->lang = $old_lang;
}
}
public function __($text)
{
return $this->l10n->translate($text);
if (is_dir(LAYOUT.$path.LANG)) {
$path = LAYOUT.$path.LANG;
} elseif (!is_dir($path)) {
$path = '';
}
public function _e($text)
{
echo $this->l10n->translate($text);
$this->mofile = $path.$this->lang.".mo";
// check if get a readable mofile
if (is_readable($this->mofile)) {
$this->input = new FileReader($this->mofile);
} else {
$this->input = false;
}
// Return the plural form.
public function __ngettext($single, $plural, $number)
{
return $this->l10n->ngettext($single, $plural, $number);
$this->l10n = new gettext_reader($this->input);
}
// reloads the mofile, if the location of the lang file changes
public function l10nReloadMOfile($lang, $path = DEFAULT_TEMPLATE)
{
$old_mofile = $this->mofile;
$old_lang = $this->lang;
$this->lang = $lang;
if (is_dir(LAYOUT.$path.LANG)) {
$path = LAYOUT.$path.LANG;
} elseif (!is_dir($path)) {
$path = '';
}
public function __get_lang()
{
return $this->lang;
}
$this->mofile = $path.$this->lang.".mo";
public function __get_mofile()
{
return $this->mofile;
// check if get a readable mofile
if (is_readable($this->mofile)) {
$this->input = new FileReader($this->mofile);
$this->l10n = new gettext_reader($this->input);
} else {
// else fall back to the old ones
$this->mofile = $old_mofile;
$this->lang = $old_lang;
}
}
?>
public function __($text)
{
return $this->l10n->translate($text);
}
public function _e($text)
{
echo $this->l10n->translate($text);
}
// Return the plural form.
public function __ngettext($single, $plural, $number)
{
return $this->l10n->ngettext($single, $plural, $number);
}
public function __get_lang()
{
return $this->lang;
}
public function __get_mofile()
{
return $this->mofile;
}
}

View File

@@ -1,107 +1,104 @@
<?
/*********************************************************************
* AUTHOR: Clemens Schwaighofer
* CREATED: 2011/2/8
* DESCRIPTION: pre function to collect all non critical errors into a log file if possible
* include this file at the very beginning of the script to get the notices, strict, etc messages.
* error etc will still be written to the log/display
*********************************************************************/
/*********************************************************************
* AUTHOR: Clemens Schwaighofer
* CREATED: 2011/2/8
* DESCRIPTION: pre function to collect all non critical errors into a log file if possible
* include this file at the very beginning of the script to get the notices, strict, etc messages.
* error etc will still be written to the log/display
*********************************************************************/
// define the base working directory outside because in the function it might return undefined
DEFINE('CURRENT_WORKING_DIR', getcwd().'/');
// define the base working directory outside because in the function it might return undefined
DEFINE('CURRENT_WORKING_DIR', getcwd().'/');
// METHOD: MyErrorHandler
// PARAMS: $type: the error code from PHP
// $message: the error message from php
// $file: in which file the error happend. this is the source file (eg include)
// $line: in which line the error happened
// $context: array with all the variable
// RETURN: true, so cought errors do not get processed by the PHP error engine
// DESC: will catch any error except E_ERROR and try to write them to the log file in log/php_error-<DAY>.llog
// if this fails, it will print the data to the window via echo
function MyErrorHandler ($type, $message, $file, $line, $context)
{
if (!(error_reporting() & $type) && !SHOW_ALL_ERRORS) {
// This error code is not included in error_reporting
return;
}
// ERROR LEVEL
$error_level = array (
1 => 'E_ERROR',
2 => 'E_WARNING',
4 => 'E_PARSE',
8 => 'E_NOTICE',
16 => 'E_CORE_ERROR',
32 => 'E_CORE_WARNING',
64 => 'E_COMPILE_ERROR',
128 => 'E_COMPILE_WARNING',
256 => 'E_USER_ERROR',
512 => 'E_USER_WARNING',
1024 => 'E_USER_NOTICE',
2048 => 'E_STRICT',
4096 => 'E_RECOVERABLE_ERROR',
8192 => 'E_DEPRICATED',
16384 => 'E_USER_DEPRICATED',
30719 => 'E_ALL'
);
// METHOD: MyErrorHandler
// PARAMS: $type: the error code from PHP
// $message: the error message from php
// $file: in which file the error happend. this is the source file (eg include)
// $line: in which line the error happened
// $context: array with all the variable
// RETURN: true, so cought errors do not get processed by the PHP error engine
// DESC: will catch any error except E_ERROR and try to write them to the log file in log/php_error-<DAY>.llog
// if this fails, it will print the data to the window via echo
function MyErrorHandler($type, $message, $file, $line, $context)
{
if (!(error_reporting() & $type) && !SHOW_ALL_ERRORS) {
// This error code is not included in error_reporting
return;
}
// ERROR LEVEL
$error_level = array (
1 => 'E_ERROR',
2 => 'E_WARNING',
4 => 'E_PARSE',
8 => 'E_NOTICE',
16 => 'E_CORE_ERROR',
32 => 'E_CORE_WARNING',
64 => 'E_COMPILE_ERROR',
128 => 'E_COMPILE_WARNING',
256 => 'E_USER_ERROR',
512 => 'E_USER_WARNING',
1024 => 'E_USER_NOTICE',
2048 => 'E_STRICT',
4096 => 'E_RECOVERABLE_ERROR',
8192 => 'E_DEPRICATED',
16384 => 'E_USER_DEPRICATED',
30719 => 'E_ALL'
);
// get the current page name (strip path)
$page_temp = explode("/", $_SERVER["PHP_SELF"]);
// the output string:
// [] current timestamp
// {} the current page name in which the error occured (running script)
// [] the file where the error actually happened
// <> the line number in this file
// [|] error name and error number
// : the php error message
$output = '['.date("Y-m-d H:i:s").'] {'.array_pop($page_temp).'} ['.$file.'] <'.$line.'> ['.$error_level[$type].'|'.$type.']: '.$message;
# try to open file
$ROOT = CURRENT_WORKING_DIR;
$LOG = 'log/';
// if the log folder is not found, try to create it
if (!is_dir($ROOT.$LOG) && !is_file($ROOT.LOG))
$ok = mkdir($ROOT.$LOG);
$error = 0;
// again, if the folder now exists, else set error flag
if (is_dir($ROOT.$LOG))
{
$fn = $ROOT.$LOG.'php_errors-'.date('Y-m-d').'.log';
// when opening, surpress the warning so we can catch the no file pointer below without throwing a warning for this
$fp = @fopen($fn, 'a');
// write if we have a file pointer, else set error flag
if ($fp)
{
fwrite($fp, $output."\n");
fclose($fp);
}
else
$error = 1;
}
else
// get the current page name (strip path)
$page_temp = explode("/", $_SERVER["PHP_SELF"]);
// the output string:
// [] current timestamp
// {} the current page name in which the error occured (running script)
// [] the file where the error actually happened
// <> the line number in this file
// [|] error name and error number
// : the php error message
$output = '['.date("Y-m-d H:i:s").'] {'.array_pop($page_temp).'} ['.$file.'] <'.$line.'> ['.$error_level[$type].'|'.$type.']: '.$message;
# try to open file
$ROOT = CURRENT_WORKING_DIR;
$LOG = 'log/';
// if the log folder is not found, try to create it
if (!is_dir($ROOT.$LOG) && !is_file($ROOT.LOG)) {
$ok = mkdir($ROOT.$LOG);
}
$error = 0;
// again, if the folder now exists, else set error flag
if (is_dir($ROOT.$LOG)) {
$fn = $ROOT.$LOG.'php_errors-'.date('Y-m-d').'.log';
// when opening, surpress the warning so we can catch the no file pointer below without throwing a warning for this
$fp = @fopen($fn, 'a');
// write if we have a file pointer, else set error flag
if ($fp) {
fwrite($fp, $output."\n");
fclose($fp);
} else {
$error = 1;
// if the above writing failed
if ($error)
{
// if the display errors is on
// pretty print output for HTML
if (ini_get("display_errors"))
{
echo "<div style='border: 1px dotted red; background-color: #ffffe5; color: #000000; padding: 5px; margin-bottom: 2px;'>";
echo "<div style='color: orange; font-weight: bold;'>".$error_level[$type].":</div>";
echo "<b>$message</b> on line <b>$line</b> in <b>$file</b>";
echo "</div>";
}
// if write to log is on
// simplified, remove datetime for log file
if (ini_get('log_errors'))
error_log('{'.$page_temp.'} ['.$file.'] <'.$line.'> ['.$error_level[$type].'|'.$type.']: '.$message);
}
// return true, to avoid that php calls its own error stuff
// if E_ERROR, the php one gets called anyway
return true;
} else {
$error = 1;
}
// init the error handler
set_error_handler("MyErrorHandler");
?>
// if the above writing failed
if ($error) {
// if the display errors is on
// pretty print output for HTML
if (ini_get("display_errors")) {
echo "<div style='border: 1px dotted red; background-color: #ffffe5; color: #000000; padding: 5px; margin-bottom: 2px;'>";
echo "<div style='color: orange; font-weight: bold;'>".$error_level[$type].":</div>";
echo "<b>$message</b> on line <b>$line</b> in <b>$file</b>";
echo "</div>";
}
// if write to log is on
// simplified, remove datetime for log file
if (ini_get('log_errors')) {
error_log('{'.$page_temp.'} ['.$file.'] <'.$line.'> ['.$error_level[$type].'|'.$type.']: '.$message);
}
}
// return true, to avoid that php calls its own error stuff
// if E_ERROR, the php one gets called anyway
return true;
}
// init the error handler
set_error_handler("MyErrorHandler");

View File

@@ -3,155 +3,170 @@
/**
* Handle file uploads via XMLHttpRequest
*/
class qqUploadedFileXhr {
/**
* Save the file to the specified path
* @return boolean TRUE on success
*/
function save($path) {
$input = fopen("php://input", "r");
$temp = tmpfile();
$realSize = stream_copy_to_stream($input, $temp);
fclose($input);
class qqUploadedFileXhr
{
/**
* Save the file to the specified path
* @return boolean TRUE on success
*/
public function save($path)
{
$input = fopen("php://input", "r");
$temp = tmpfile();
$realSize = stream_copy_to_stream($input, $temp);
fclose($input);
if ($realSize != $this->getSize()){
return false;
}
if ($realSize != $this->getSize()) {
return false;
}
$target = fopen($path, "w");
fseek($temp, 0, SEEK_SET);
stream_copy_to_stream($temp, $target);
fclose($target);
$target = fopen($path, "w");
fseek($temp, 0, SEEK_SET);
stream_copy_to_stream($temp, $target);
fclose($target);
return true;
}
function getName() {
return $_GET['qqfile'];
}
function getSize() {
if (isset($_SERVER["CONTENT_LENGTH"])){
return (int)$_SERVER["CONTENT_LENGTH"];
} else {
throw new Exception('Getting content length is not supported.');
}
}
return true;
}
public function getName()
{
return $_GET['qqfile'];
}
public function getSize()
{
if (isset($_SERVER["CONTENT_LENGTH"])) {
return (int)$_SERVER["CONTENT_LENGTH"];
} else {
throw new Exception('Getting content length is not supported.');
}
}
}
/**
* Handle file uploads via regular form post (uses the $_FILES array)
*/
class qqUploadedFileForm {
/**
* Save the file to the specified path
* @return boolean TRUE on success
*/
function save($path) {
if(!move_uploaded_file($_FILES['qqfile']['tmp_name'], $path)){
return false;
}
return true;
}
function getName() {
return $_FILES['qqfile']['name'];
}
function getSize() {
return $_FILES['qqfile']['size'];
}
class qqUploadedFileForm
{
/**
* Save the file to the specified path
* @return boolean TRUE on success
*/
public function save($path)
{
if (!move_uploaded_file($_FILES['qqfile']['tmp_name'], $path)) {
return false;
}
return true;
}
public function getName()
{
return $_FILES['qqfile']['name'];
}
public function getSize()
{
return $_FILES['qqfile']['size'];
}
}
class qqFileUploader {
private $allowedExtensions = array();
private $sizeLimit = 10485760;
private $file;
class qqFileUploader
{
private $allowedExtensions = array();
private $sizeLimit = 10485760;
private $file;
function __construct(array $allowedExtensions = array(), $sizeLimit = 10485760){
$allowedExtensions = array_map("strtolower", $allowedExtensions);
public function __construct(array $allowedExtensions = array(), $sizeLimit = 10485760)
{
$allowedExtensions = array_map("strtolower", $allowedExtensions);
$this->allowedExtensions = $allowedExtensions;
$this->sizeLimit = $sizeLimit;
$this->allowedExtensions = $allowedExtensions;
$this->sizeLimit = $sizeLimit;
$this->checkServerSettings();
$this->checkServerSettings();
if (isset($_GET['qqfile'])) {
$this->file = new qqUploadedFileXhr();
} elseif (isset($_FILES['qqfile'])) {
$this->file = new qqUploadedFileForm();
} else {
$this->file = false;
}
}
if (isset($_GET['qqfile'])) {
$this->file = new qqUploadedFileXhr();
} elseif (isset($_FILES['qqfile'])) {
$this->file = new qqUploadedFileForm();
} else {
$this->file = false;
}
}
private function checkServerSettings(){
$postSize = $this->toBytes(ini_get('post_max_size'));
$uploadSize = $this->toBytes(ini_get('upload_max_filesize'));
private function checkServerSettings()
{
$postSize = $this->toBytes(ini_get('post_max_size'));
$uploadSize = $this->toBytes(ini_get('upload_max_filesize'));
if ($postSize < $this->sizeLimit || $uploadSize < $this->sizeLimit){
$size = max(1, $this->sizeLimit / 1024 / 1024) . 'M';
die("{'error':'increase post_max_size and upload_max_filesize to $size'}");
}
}
if ($postSize < $this->sizeLimit || $uploadSize < $this->sizeLimit) {
$size = max(1, $this->sizeLimit / 1024 / 1024) . 'M';
die("{'error':'increase post_max_size and upload_max_filesize to $size'}");
}
}
private function toBytes($str){
$val = trim($str);
$last = strtolower($str[strlen($str)-1]);
switch($last) {
case 'g': $val *= 1024;
case 'm': $val *= 1024;
case 'k': $val *= 1024;
}
return $val;
}
private function toBytes($str)
{
$val = trim($str);
$last = strtolower($str[strlen($str)-1]);
switch ($last) {
case 'g':
$val *= 1024;
// no break
case 'm':
$val *= 1024;
// no break
case 'k':
$val *= 1024;
}
return $val;
}
/**
* Returns array('success'=>true) or array('error'=>'error message')
*/
function handleUpload($uploadDirectory, $replaceOldFile = FALSE){
if (!is_writable($uploadDirectory)){
return array('error' => "Server error. Upload directory isn't writable.");
}
/**
* Returns array('success'=>true) or array('error'=>'error message')
*/
public function handleUpload($uploadDirectory, $replaceOldFile = false)
{
if (!is_writable($uploadDirectory)) {
return array('error' => "Server error. Upload directory isn't writable.");
}
if (!$this->file){
return array('error' => 'No files were uploaded.');
}
if (!$this->file) {
return array('error' => 'No files were uploaded.');
}
$size = $this->file->getSize();
$size = $this->file->getSize();
if ($size == 0) {
return array('error' => 'File is empty');
}
if ($size == 0) {
return array('error' => 'File is empty');
}
if ($size > $this->sizeLimit) {
return array('error' => 'File is too large');
}
if ($size > $this->sizeLimit) {
return array('error' => 'File is too large');
}
$pathinfo = pathinfo($this->file->getName());
$filename = $pathinfo['filename'];
//$filename = md5(uniqid());
$ext = $pathinfo['extension'];
$pathinfo = pathinfo($this->file->getName());
$filename = $pathinfo['filename'];
//$filename = md5(uniqid());
$ext = $pathinfo['extension'];
if($this->allowedExtensions && !in_array(strtolower($ext), $this->allowedExtensions)){
$these = implode(', ', $this->allowedExtensions);
return array('error' => 'File has an invalid extension, it should be one of '. $these . '.');
}
if ($this->allowedExtensions && !in_array(strtolower($ext), $this->allowedExtensions)) {
$these = implode(', ', $this->allowedExtensions);
return array('error' => 'File has an invalid extension, it should be one of '. $these . '.');
}
if(!$replaceOldFile){
/// don't overwrite previous files that were uploaded
while (file_exists($uploadDirectory . $filename . '.' . $ext)) {
$filename .= rand(10, 99);
}
}
if (!$replaceOldFile) {
/// don't overwrite previous files that were uploaded
while (file_exists($uploadDirectory . $filename . '.' . $ext)) {
$filename .= rand(10, 99);
}
}
$this->uploadFileName = $uploadDirectory . $filename . '.' . $ext;
$this->uploadFileExt = $ext;
$this->uploadFileName = $uploadDirectory . $filename . '.' . $ext;
$this->uploadFileExt = $ext;
if ($this->file->save($uploadDirectory . $filename . '.' . $ext)){
return array('success'=>true);
} else {
return array('error'=> 'Could not save uploaded file.' .
'The upload was cancelled, or server error encountered');
}
}
if ($this->file->save($uploadDirectory . $filename . '.' . $ext)) {
return array('success'=>true);
} else {
return array('error'=> 'Could not save uploaded file.' .
'The upload was cancelled, or server error encountered');
}
}
}
?>

View File

@@ -1,269 +1,259 @@
<?
/*********************************************************************
* AUTHOR: Clemens "Gullevek" Schwaighofer (www.gullevek.org)
* CREATED: 2003/04/09
* SHORT DESCRIPTION:
* pgsq; wrapper calls
* HISTORY:
* 2008/04/16 (cs) wrapper for pg escape string
* 2007/01/11 (cs) add prepare/execute for postgres
* 2006/09/12 (cs) in case db_query retuns false, save the query and run the query through the send/get procedure to get correct error data from the db
* 2006/06/26 (cs) added port for db connection
* 2006/04/03 (cs) added meta data for table
* 2005/07/25 (cs) removed the plural s remove, not needed and not 100% working
* 2005/07/07 (cs) the default it is table_name _ id
* 2005/01/19 (cs) changed the pgsql connect, so it dies if it can't connect to the DB
* 2004/09/30 (cs) layout cleanup
* /
/*********************************************************************
* AUTHOR: Clemens "Gullevek" Schwaighofer (www.gullevek.org)
* CREATED: 2003/04/09
* SHORT DESCRIPTION:
* pgsq; wrapper calls
* HISTORY:
* 2008/04/16 (cs) wrapper for pg escape string
* 2007/01/11 (cs) add prepare/execute for postgres
* 2006/09/12 (cs) in case db_query retuns false, save the query and run the query through the send/get procedure to get correct error data from the db
* 2006/06/26 (cs) added port for db connection
* 2006/04/03 (cs) added meta data for table
* 2005/07/25 (cs) removed the plural s remove, not needed and not 100% working
* 2005/07/07 (cs) the default it is table_name _ id
* 2005/01/19 (cs) changed the pgsql connect, so it dies if it can't connect to the DB
* 2004/09/30 (cs) layout cleanup
* /
/* collection of PostgreSQL wrappers
* REQUIRES 5.4 PHP!!! (should do check for this)
*
* pg_prepare
* pg_execute
* pg_num_rows
* pg_num_fields
* pg_field_name
* pg_affected_rows (*)
* pg_fetch_array
* pg_query
* pg_close
* pg_connect (*)
* pg_meta_data
* pg_escape_string
*
*/
/* collection of PostgreSQL wrappers
* REQUIRES 5.4 PHP!!! (should do check for this)
*
* pg_prepare
* pg_execute
* pg_num_rows
* pg_num_fields
* pg_field_name
* pg_affected_rows (*)
* pg_fetch_array
* pg_query
* pg_close
* pg_connect (*)
* pg_meta_data
* pg_escape_string
*
*/
trait db_pgsql
trait db_pgsql
{
private $last_error_query;
private $currval_query;
// METHOD: _db_query
// PARAMS: query, database handler
// RETURN: query result
// DESC : wrapper for gp_query, catches error and stores it in class var
private function _db_query($query, $dbh)
{
private $last_error_query;
private $currval_query;
// read out the query status and save the query if needed
$result = @pg_query($dbh, $query);
if (!$result) {
$this->last_error_query = $query;
}
return $result;
}
// METHOD: _db_query
// PARAMS: query, database handler
// RETURN: query result
// DESC : wrapper for gp_query, catches error and stores it in class var
private function _db_query($query, $dbh)
{
// read out the query status and save the query if needed
$result = @pg_query($dbh, $query);
if (!$result)
{
$this->last_error_query = $query;
// METHOD: _db_close
// PARAMS: database handler
// RETURN: none
// DESC : wrapper for pg_close
private function _db_close($dbh)
{
pg_close($dbh);
}
// METHOD: _db_prepare
// PARAMS: database handler, prepare name, query
// RETURN: prepared statement handler
// DESC : wrapper for pg_prepare
private function _db_prepare($dbh, $name, $query)
{
return @pg_prepare($dbh, $name, $query);
}
// METHOD: _db_execute
// PARAMS: database handler, prepare name, data for query
// RETURN: returns status
// DESC : wrapper for pg_execute for running a prepared statement
private function _db_execute($dbh, $name, $data)
{
return @pg_execute($dbh, $name, $data);
}
// METHOD: _db_num_rows
// PARAMS: cursor
// RETURN: rows
// DESC : wrapper for pg_num_rows
private function _db_num_rows($cursor)
{
return pg_num_rows($cursor);
}
// METHOD: _db_num_fields
// PARAMS: cursor
// RETURN: number for fields in query
// DESC : wrapper for pg_num_fields
private function _db_num_fields($cursor)
{
return pg_num_fields($cursor);
}
// METHOD: _db_field_name
// PARAMS: cursor, field position
// RETURN: name of field
// DESC : wrapper for pg_field_name
private function _db_field_name($cursor, $i)
{
return pg_field_name($cursor, $i);
}
// METHOD: _db_fetch_array
// PARAMS: cursor
// RETURN: row
// DESC : wrapper for pg_fetch_array
private function _db_fetch_array($cursor)
{
return pg_fetch_array($cursor);
}
// METHOD: _db_affected_ros
// PARAMS: database handler, cursor
// RETURN: number for rows
// DESC : wrapper for pg_affected_rows
private function _db_affected_rows($dbh, $cursor)
{
return pg_affected_rows($cursor);
}
// METHOD: _db_insert_id
// PARAMS: database handler, query, primary key name
// RETURN: last insert primary key
// DESC : reads the last inserted primary key for the query
// if ther is no pk_name tries to auto built it from the table name
// this only works if db schema is after "no plural names. and pk name is table name + _id
// detects schema prefix in table name
private function _db_insert_id($dbh, $query, $pk_name)
{
// only if an insert has been done
if (preg_match("/^insert /i", $query)) {
// get table name from insert
$array = explode(' ', $query);
$_table = $array[2];
// if there is a dot inside, we need to split
if (strstr($_table, '.')) {
list ($schema, $table) = explode('.', $_table);
} else {
$table = $_table;
}
return $result;
}
// METHOD: _db_close
// PARAMS: database handler
// RETURN: none
// DESC : wrapper for pg_close
private function _db_close($dbh)
{
pg_close($dbh);
}
// METHOD: _db_prepare
// PARAMS: database handler, prepare name, query
// RETURN: prepared statement handler
// DESC : wrapper for pg_prepare
private function _db_prepare($dbh, $name, $query)
{
return @pg_prepare($dbh, $name, $query);
}
// METHOD: _db_execute
// PARAMS: database handler, prepare name, data for query
// RETURN: returns status
// DESC : wrapper for pg_execute for running a prepared statement
private function _db_execute($dbh, $name, $data)
{
return @pg_execute($dbh, $name, $data);
}
// METHOD: _db_num_rows
// PARAMS: cursor
// RETURN: rows
// DESC : wrapper for pg_num_rows
private function _db_num_rows($cursor)
{
return pg_num_rows($cursor);
}
// METHOD: _db_num_fields
// PARAMS: cursor
// RETURN: number for fields in query
// DESC : wrapper for pg_num_fields
private function _db_num_fields($cursor)
{
return pg_num_fields($cursor);
}
// METHOD: _db_field_name
// PARAMS: cursor, field position
// RETURN: name of field
// DESC : wrapper for pg_field_name
private function _db_field_name($cursor, $i)
{
return pg_field_name($cursor, $i);
}
// METHOD: _db_fetch_array
// PARAMS: cursor
// RETURN: row
// DESC : wrapper for pg_fetch_array
private function _db_fetch_array($cursor)
{
return pg_fetch_array($cursor);
}
// METHOD: _db_affected_ros
// PARAMS: database handler, cursor
// RETURN: number for rows
// DESC : wrapper for pg_affected_rows
private function _db_affected_rows($dbh, $cursor)
{
return pg_affected_rows($cursor);
}
// METHOD: _db_insert_id
// PARAMS: database handler, query, primary key name
// RETURN: last insert primary key
// DESC : reads the last inserted primary key for the query
// if ther is no pk_name tries to auto built it from the table name
// this only works if db schema is after "no plural names. and pk name is table name + _id
// detects schema prefix in table name
private function _db_insert_id($dbh, $query, $pk_name)
{
// only if an insert has been done
if (preg_match("/^insert /i", $query))
{
// get table name from insert
$array = explode(' ', $query);
$_table = $array[2];
// if there is a dot inside, we need to split
if (strstr($_table, '.'))
list($schema, $table) = explode('.', $_table);
else
$table = $_table;
// no PK name given at all
if (!$pk_name)
{
// if name is plurar, make it singular
// if (preg_match("/.*s$/i", $table))
// $table = substr($table, 0, -1);
// set pk_name to "id"
$pk_name = $table."_id";
}
$seq = (($schema) ? $schema.'.' : '').$table."_".$pk_name."_seq";
$q = "SELECT CURRVAL('$seq') AS insert_id";
$this->currval_query = $q;
// no PK name given at all
if (!$pk_name) {
// if name is plurar, make it singular
// if (preg_match("/.*s$/i", $table))
// $table = substr($table, 0, -1);
// set pk_name to "id"
$pk_name = $table."_id";
}
$seq = (($schema) ? $schema.'.' : '').$table."_".$pk_name."_seq";
$q = "SELECT CURRVAL('$seq') AS insert_id";
$this->currval_query = $q;
//echo "Q: $q<Br>";
// I have to do manually or I overwrite the original insert internal vars ...
if ($q = @pg_query($dbh, $q))
{
list($id) = pg_fetch_array($q);
}
else
{
$id = array(-1, $q);
}
return $id;
// I have to do manually or I overwrite the original insert internal vars ...
if ($q = @pg_query($dbh, $q)) {
list($id) = pg_fetch_array($q);
} else {
$id = array(-1, $q);
}
}
// METHOD: _db_connect
// PARAMS: host name, user name, password, database name, optional port (defaults to default postgres port), optional ssl (default allow)
// RETURN: database handler
// DESC : wrapper for pg_connect, writes out failure to screen if error occurs (hidden var)
private function _db_connect($db_host, $db_user, $db_pass, $db_name, $db_port = 5432, $db_ssl = 'allow')
{
// to avoid empty db_port
if (!$db_port)
{
$db_port = 5432;
}
$this->dbh = @pg_connect("host=".$db_host." port=".$db_port." user=".$db_user." password=".$db_pass." dbname=".$db_name." sslmode=".$db_ssl);
if (!$this->dbh)
{
die("<!-- Can't connect [host=".$db_host." port=".$db_port." user=".$db_user." password=XXXX dbname=".$db_name." sslmode=".$db_ssl."] //-->");
}
return $this->dbh;
}
// METHOD: _db_print_error
// PARAMS: database handler, cursor
// RETURN: error string (HTML)
// DESC : reads the last error for this cursor
private function _db_print_error($dbh, $cursor = '')
{
// run the query again for the error result here
if (!$cursor && $this->last_error_query)
{
pg_send_query($dbh, $this->last_error_query);
$this->last_error_query = "";
$cursor = pg_get_result($dbh);
}
if (pg_result_error($cursor))
return "<span style=\"color: red;\"><b>-PostgreSQL-Error-></b> ".pg_result_error($cursor)."</span><br>";
}
// METHOD: _db_meta_data
// PARAMS: database handler, table name
// RETURN: array with table data
// DESC : wrapper for pg_emta_data
private function _db_meta_data($dbh, $table)
{
return @pg_meta_data($dbh, $table);
}
// METHOD: _db_escape_string
// PARAMS: string
// RETURN: escaped string for postgres
// DESC : wrapper for pg_escape_string
private function _db_escape_string($string)
{
return pg_escape_string($this->dbh, $string);
}
// METHOD: _db_escape_bytea
// PARAMS: string
// RETURN: escape bytes for postgres
// DESC : wrapper for pg_escape_bytea
private function _db_escape_bytea($bytea)
{
return pg_escape_bytea($this->dbh, $bytea);
}
// METHOD: _db_array_parse
// PARAMS: input text, output array [needed]
// [internal] limit: are we at the end of the parse
// [internal] offset: shift for {}
// RETURN: array with the elements
// DESC : postgresql array to php array
private function _db_array_parse($text, &$output, $limit = false, $offset = 1)
{
if (false === $limit)
{
$limit = strlen($text) - 1;
$output = array();
}
if ('{}' != $text)
do
{
if ('{' != $text{$offset})
{
preg_match("/(\\{?\"([^\"\\\\]|\\\\.)*\"|[^,{}]+)+([,}]+)/", $text, $match, 0, $offset);
$offset += strlen($match[0]);
$output[] = ('"' != $match[1]{0} ? $match[1] : stripcslashes(substr($match[1], 1, -1)));
if ('},' == $match[3])
return $offset;
}
else
$offset = pg_array_parse($text, $output[], $limit, $offset + 1);
}
while ($limit > $offset);
return $output;
return $id;
}
}
?>
// METHOD: _db_connect
// PARAMS: host name, user name, password, database name, optional port (defaults to default postgres port), optional ssl (default allow)
// RETURN: database handler
// DESC : wrapper for pg_connect, writes out failure to screen if error occurs (hidden var)
private function _db_connect($db_host, $db_user, $db_pass, $db_name, $db_port = 5432, $db_ssl = 'allow')
{
// to avoid empty db_port
if (!$db_port) {
$db_port = 5432;
}
$this->dbh = @pg_connect("host=".$db_host." port=".$db_port." user=".$db_user." password=".$db_pass." dbname=".$db_name." sslmode=".$db_ssl);
if (!$this->dbh) {
die("<!-- Can't connect [host=".$db_host." port=".$db_port." user=".$db_user." password=XXXX dbname=".$db_name." sslmode=".$db_ssl."] //-->");
}
return $this->dbh;
}
// METHOD: _db_print_error
// PARAMS: database handler, cursor
// RETURN: error string (HTML)
// DESC : reads the last error for this cursor
private function _db_print_error($dbh, $cursor = '')
{
// run the query again for the error result here
if (!$cursor && $this->last_error_query) {
pg_send_query($dbh, $this->last_error_query);
$this->last_error_query = "";
$cursor = pg_get_result($dbh);
}
if (pg_result_error($cursor)) {
return "<span style=\"color: red;\"><b>-PostgreSQL-Error-></b> ".pg_result_error($cursor)."</span><br>";
}
}
// METHOD: _db_meta_data
// PARAMS: database handler, table name
// RETURN: array with table data
// DESC : wrapper for pg_emta_data
private function _db_meta_data($dbh, $table)
{
return @pg_meta_data($dbh, $table);
}
// METHOD: _db_escape_string
// PARAMS: string
// RETURN: escaped string for postgres
// DESC : wrapper for pg_escape_string
private function _db_escape_string($string)
{
return pg_escape_string($this->dbh, $string);
}
// METHOD: _db_escape_bytea
// PARAMS: string
// RETURN: escape bytes for postgres
// DESC : wrapper for pg_escape_bytea
private function _db_escape_bytea($bytea)
{
return pg_escape_bytea($this->dbh, $bytea);
}
// METHOD: _db_array_parse
// PARAMS: input text, output array [needed]
// [internal] limit: are we at the end of the parse
// [internal] offset: shift for {}
// RETURN: array with the elements
// DESC : postgresql array to php array
private function _db_array_parse($text, &$output, $limit = false, $offset = 1)
{
if (false === $limit) {
$limit = strlen($text) - 1;
$output = array();
}
if ('{}' != $text) {
do {
if ('{' != $text{$offset}) {
preg_match("/(\\{?\"([^\"\\\\]|\\\\.)*\"|[^,{}]+)+([,}]+)/", $text, $match, 0, $offset);
$offset += strlen($match[0]);
$output[] = ('"' != $match[1]{0} ? $match[1] : stripcslashes(substr($match[1], 1, -1)));
if ('},' == $match[3]) {
return $offset;
}
} else {
$offset = pg_array_parse($text, $output[], $limit, $offset + 1);
}
} while ($limit > $offset);
}
return $output;
}
}

View File

@@ -1,402 +1,397 @@
<?
/*********************************************************************
* AUTHOR: Clemens "Gullevek" Schwaighofer (www.gullevek.org)
* CREATED: 2003/04/09
* SHORT DESCRIPTION:
* pgsql wrapper calls
* HISTORY:
* 2008/04/16 (cs) wrapper for pg escape string
* 2007/01/11 (cs) add prepare/execute for postgres
* 2006/09/12 (cs) in case db_query retuns false, save the query and run the query through the send/get procedure to get correct error data from the db
* 2006/06/26 (cs) added port for db connection
* 2006/04/03 (cs) added meta data for table
* 2005/07/25 (cs) removed the plural s remove, not needed and not 100% working
* 2005/07/07 (cs) the default it is table_name _ id
* 2005/01/19 (cs) changed the pgsql connect, so it dies if it can't connect to the DB
* 2004/09/30 (cs) layout cleanup
* /
/*********************************************************************
* AUTHOR: Clemens "Gullevek" Schwaighofer (www.gullevek.org)
* CREATED: 2003/04/09
* SHORT DESCRIPTION:
* pgsql wrapper calls
* HISTORY:
* 2008/04/16 (cs) wrapper for pg escape string
* 2007/01/11 (cs) add prepare/execute for postgres
* 2006/09/12 (cs) in case db_query retuns false, save the query and run the query through the send/get procedure to get correct error data from the db
* 2006/06/26 (cs) added port for db connection
* 2006/04/03 (cs) added meta data for table
* 2005/07/25 (cs) removed the plural s remove, not needed and not 100% working
* 2005/07/07 (cs) the default it is table_name _ id
* 2005/01/19 (cs) changed the pgsql connect, so it dies if it can't connect to the DB
* 2004/09/30 (cs) layout cleanup
* /
* collection of PostgreSQL wrappers
* REQUIRES 5.x PHP!!!
*
* pg_prepare
* pg_execute
* pg_num_rows
* pg_num_fields
* pg_field_name
* pg_affected_rows (*)
* pg_fetch_array
* pg_query
* pg_send_query
* pg_get_result
* pg_connection_busy
* pg_close
* pg_connect (*)
* pg_meta_data
* pg_escape_string
*
*/
* collection of PostgreSQL wrappers
* REQUIRES 5.x PHP!!!
*
* pg_prepare
* pg_execute
* pg_num_rows
* pg_num_fields
* pg_field_name
* pg_affected_rows (*)
* pg_fetch_array
* pg_query
* pg_send_query
* pg_get_result
* pg_connection_busy
* pg_close
* pg_connect (*)
* pg_meta_data
* pg_escape_string
*
*/
class db_pgsql
{
private $last_error_query;
private $dbh;
class db_pgsql
{
private $last_error_query;
private $dbh;
// public $currval_query;
// METHOD: __construct
// PARAMS: none
// RETURN: none
// DESC : class constructor
public function __construct()
{
}
// METHOD: __construct
// PARAMS: none
// RETURN: none
// DESC : class constructor
public function __construct()
{
}
public function _db_last_error_query()
{
if ($this->last_error_query)
return true;
else
return false;
}
// METHOD: _db_query
// PARAMS: query
// RETURN: query result
// DESC : wrapper for gp_query, catches error and stores it in class var
public function _db_query($query)
{
$this->last_error_query = '';
// read out the query status and save the query if needed
$result = pg_query($this->dbh, $query);
if (!$result)
$this->last_error_query = $query;
return $result;
}
// METHOD: _db_send_query
// PARAMS: query
// RETURN: true/false if query was sent successful
// DESC : sends an async query to the server
public function _db_send_query($query)
{
return pg_send_query($this->dbh, $query);
}
// METHOD: _db_get_result
// PARAMS: none
// RETURN: resource handler
// DESC : wrapper for pg_get_result
public function _db_get_result()
{
$this->last_error_query = '';
$result = pg_get_result($this->dbh);
if ($error = pg_result_error($result))
$this->last_error_query = $error;
return $result;
}
// METHOD: _db_close
// PARAMS: none
// RETURN: none
// DESC : wrapper for pg_close
public function _db_close()
{
if (is_resource($this->dbh))
if (pg_connection_status($this->dbh) === PGSQL_CONNECTION_OK)
pg_close($this->dbh);
}
// METHOD: _db_prepare
// PARAMS: prepare name, query
// RETURN: prepared statement handler
// DESC : wrapper for pg_prepare
public function _db_prepare($name, $query)
{
$result = pg_prepare($this->dbh, $name, $query);
if (!$result)
$this->last_error_query = $query;
return $result;
}
// METHOD: _db_execute
// PARAMS: prepare name, data for query
// RETURN: returns status
// DESC : wrapper for pg_execute for running a prepared statement
public function _db_execute($name, $data)
{
$result = pg_execute($this->dbh, $name, $data);
if (!$result)
$this->last_error_query = $query;
return $result;
}
// METHOD: _db_num_rows
// PARAMS: cursor
// RETURN: rows
// DESC : wrapper for pg_num_rows
public function _db_num_rows($cursor)
{
return pg_num_rows($cursor);
}
// METHOD: _db_num_fields
// PARAMS: cursor
// RETURN: number for fields in query
// DESC : wrapper for pg_num_fields
public function _db_num_fields($cursor)
{
return pg_num_fields($cursor);
}
// METHOD: _db_field_name
// PARAMS: cursor, field position
// RETURN: name of field
// DESC : wrapper for pg_field_name
public function _db_field_name($cursor, $i)
{
return pg_field_name($cursor, $i);
}
// METHOD: _db_fetch_array
// PARAMS: cursor, opt result type
// RETURN: row
// DESC : wrapper for pg_fetch_array
public function _db_fetch_array($cursor, $result_type = '')
{
// result type is passed on as is [should be checked]
if ($result_type)
return pg_fetch_array($cursor, NULL, $result_type);
else
return pg_fetch_array($cursor);
}
// METHOD: _db_fetch_all
// PARAMS: cursor
// RETURN: all rows as array
// DESC : wrapper for pg_fetch_array
public function _db_fetch_all($cursor)
{
return pg_fetch_all($cursor);
}
// METHOD: _db_affected_ros
// PARAMS: cursor
// RETURN: number for rows
// DESC : wrapper for pg_affected_rows
public function _db_affected_rows($cursor)
{
return pg_affected_rows($cursor);
}
// METHOD: _db_insert_id
// PARAMS: query, primary key name
// RETURN: last insert primary key
// DESC : reads the last inserted primary key for the query
// if ther is no pk_name tries to auto built it from the table name
// this only works if db schema is after "no plural names. and pk name is table name + _id
// detects schema prefix in table name
public function _db_insert_id($query, $pk_name)
{
// only if an insert has been done
if (preg_match("/^insert /i", $query))
{
$schema = '';
// get table name from insert
$array = explode(' ', $query);
$_table = $array[2];
// if there is a dot inside, we need to split
if (strstr($_table, '.'))
list($schema, $table) = explode('.', $_table);
else
$table = $_table;
// no PK name given at all
if (!$pk_name)
{
// if name is plurar, make it singular
// if (preg_match("/.*s$/i", $table))
// $table = substr($table, 0, -1);
// set pk_name to "id"
$pk_name = $table."_id";
}
$seq = (($schema) ? $schema.'.' : '').$table."_".$pk_name."_seq";
$q = "SELECT CURRVAL('$seq') AS insert_id";
// $this->currval_query = $q;
// I have to do manually or I overwrite the original insert internal vars ...
if ($q = $this->_db_query($q))
{
list($id) = $this->_db_fetch_array($q);
}
else
{
$id = array(-1, $q);
}
return $id;
}
}
// METHOD: _db_primary_key
// PARAMS: table and optional schema
// RETURN: primary key name OR false if not possible
// DESC : queries database for the primary key name to this table in the selected schema
public function _db_primary_key($table, $schema = '')
{
if ($table)
{
// check if schema set is different from schema given, only needed if schema is not empty
$table_prefix = '';
if ($schema)
{
$q = "SHOW search_path";
$cursor = $this->_db_query($q);
$search_path = $this->_db_fetch_array($cursor)['search_path'];
if ($search_path != $schema)
{
$table_prefix = $schema.'.';
}
}
// read from table the PK name
// faster primary key get
$q = "SELECT pg_attribute.attname AS column_name, format_type(pg_attribute.atttypid, pg_attribute.atttypmod) AS type ";
$q .= "FROM pg_index, pg_class, pg_attribute ";
if ($schema)
$q .= ", pg_namespace ";
$q .= "WHERE ";
// regclass translates the OID to the name
$q .= "pg_class.oid = '".$table_prefix.$table."'::regclass AND ";
$q .= "indrelid = pg_class.oid AND ";
if ($schema)
{
$q .= "nspname = '".$schema."' AND ";
$q .= "pg_class.relnamespace = pg_namespace.oid AND ";
}
$q .= "pg_attribute.attrelid = pg_class.oid AND ";
$q .= "pg_attribute.attnum = any(pg_index.indkey) ";
$q .= "AND indisprimary";
$cursor = $this->_db_query($q);
if ($cursor)
return $this->_db_fetch_array($cursor)['column_name'];
else
return false;
}
else
{
return false;
}
}
// METHOD: _db_connect
// PARAMS: host name, user name, password, database name, optional port (defaults to default postgres port), optional ssl (default allow)
// RETURN: database handler
// DESC : wrapper for pg_connect, writes out failure to screen if error occurs (hidden var)
public function _db_connect($db_host, $db_user, $db_pass, $db_name, $db_port = 5432, $db_ssl = 'allow')
{
// to avoid empty db_port
if (!$db_port)
{
$db_port = 5432;
}
$this->dbh = pg_connect("host=".$db_host." port=".$db_port." user=".$db_user." password=".$db_pass." dbname=".$db_name." sslmode=".$db_ssl);
if (!$this->dbh)
{
die("<!-- Can't connect [host=".$db_host." port=".$db_port." user=".$db_user." password=XXXX dbname=".$db_name." sslmode=".$db_ssl."] //-->");
}
return $this->dbh;
}
// METHOD: _db_print_error
// PARAMS: database handler, cursor
// RETURN: error string (HTML)
// DESC : reads the last error for this cursor
public function _db_print_error($cursor = '')
{
// run the query again for the error result here
if (!$cursor && $this->last_error_query)
{
pg_send_query($this->dbh, $this->last_error_query);
$this->last_error_query = '';
$cursor = pg_get_result($this->dbh);
}
if (pg_result_error($cursor))
return "<span style=\"color: red;\"><b>-PostgreSQL-Error-></b> ".pg_result_error($cursor)."</span><br>";
}
// METHOD: _db_meta_data
// PARAMS: table name
// RETURN: array with table data
// DESC : wrapper for pg_emta_data
public function _db_meta_data($table)
{
return pg_meta_data($this->dbh, $table);
}
// METHOD: _db_escape_string
// PARAMS: string
// RETURN: escaped string for postgres
// DESC : wrapper for pg_escape_string
public function _db_escape_string($string)
{
return pg_escape_string($this->dbh, $string);
}
// METHOD: _db_escape_bytea
// PARAMS: string
// RETURN: escape bytes for postgres
// DESC : wrapper for pg_escape_bytea
public function _db_escape_bytea($bytea)
{
return pg_escape_bytea($this->dbh, $bytea);
}
// METHOD: _db_connection_busy
// PARAMS: none
// RETURN: true/false for busy connection
// DESC : wrapper for pg_connection_busy
public function _db_connection_busy()
{
return pg_connection_busy($this->dbh);
}
// METHOD: _db_version
// PARAMS: none
// RETURN: databse version
// DESC : wrapper for pg_version
public function _db_version()
{
// array has client, protocol, server
// we just need the server
$v = pg_version($this->dbh);
return $v['server'];
}
// METHOD: _db_array_parse
// PARAMS: input text, output array [needed]
// [internal] limit: are we at the end of the parse
// [internal] offset: shift for {}
// RETURN: array with the elements
// DESC : postgresql array to php array
public function _db_array_parse($text, &$output, $limit = false, $offset = 1)
{
if (false === $limit)
{
$limit = strlen($text) - 1;
$output = array();
}
if ('{}' != $text)
do
{
if ('{' != $text{$offset})
{
preg_match("/(\\{?\"([^\"\\\\]|\\\\.)*\"|[^,{}]+)+([,}]+)/", $text, $match, 0, $offset);
$offset += strlen($match[0]);
$output[] = ('"' != $match[1]{0} ? $match[1] : stripcslashes(substr($match[1], 1, -1)));
if ('},' == $match[3])
return $offset;
}
else
$offset = pg_array_parse($text, $output[], $limit, $offset + 1);
}
while ($limit > $offset);
return $output;
public function _db_last_error_query()
{
if ($this->last_error_query) {
return true;
} else {
return false;
}
}
?>
// METHOD: _db_query
// PARAMS: query
// RETURN: query result
// DESC : wrapper for gp_query, catches error and stores it in class var
public function _db_query($query)
{
$this->last_error_query = '';
// read out the query status and save the query if needed
$result = pg_query($this->dbh, $query);
if (!$result) {
$this->last_error_query = $query;
}
return $result;
}
// METHOD: _db_send_query
// PARAMS: query
// RETURN: true/false if query was sent successful
// DESC : sends an async query to the server
public function _db_send_query($query)
{
return pg_send_query($this->dbh, $query);
}
// METHOD: _db_get_result
// PARAMS: none
// RETURN: resource handler
// DESC : wrapper for pg_get_result
public function _db_get_result()
{
$this->last_error_query = '';
$result = pg_get_result($this->dbh);
if ($error = pg_result_error($result)) {
$this->last_error_query = $error;
}
return $result;
}
// METHOD: _db_close
// PARAMS: none
// RETURN: none
// DESC : wrapper for pg_close
public function _db_close()
{
if (is_resource($this->dbh)) {
if (pg_connection_status($this->dbh) === PGSQL_CONNECTION_OK) {
pg_close($this->dbh);
}
}
}
// METHOD: _db_prepare
// PARAMS: prepare name, query
// RETURN: prepared statement handler
// DESC : wrapper for pg_prepare
public function _db_prepare($name, $query)
{
$result = pg_prepare($this->dbh, $name, $query);
if (!$result) {
$this->last_error_query = $query;
}
return $result;
}
// METHOD: _db_execute
// PARAMS: prepare name, data for query
// RETURN: returns status
// DESC : wrapper for pg_execute for running a prepared statement
public function _db_execute($name, $data)
{
$result = pg_execute($this->dbh, $name, $data);
if (!$result) {
$this->last_error_query = $query;
}
return $result;
}
// METHOD: _db_num_rows
// PARAMS: cursor
// RETURN: rows
// DESC : wrapper for pg_num_rows
public function _db_num_rows($cursor)
{
return pg_num_rows($cursor);
}
// METHOD: _db_num_fields
// PARAMS: cursor
// RETURN: number for fields in query
// DESC : wrapper for pg_num_fields
public function _db_num_fields($cursor)
{
return pg_num_fields($cursor);
}
// METHOD: _db_field_name
// PARAMS: cursor, field position
// RETURN: name of field
// DESC : wrapper for pg_field_name
public function _db_field_name($cursor, $i)
{
return pg_field_name($cursor, $i);
}
// METHOD: _db_fetch_array
// PARAMS: cursor, opt result type
// RETURN: row
// DESC : wrapper for pg_fetch_array
public function _db_fetch_array($cursor, $result_type = '')
{
// result type is passed on as is [should be checked]
if ($result_type) {
return pg_fetch_array($cursor, NULL, $result_type);
} else {
return pg_fetch_array($cursor);
}
}
// METHOD: _db_fetch_all
// PARAMS: cursor
// RETURN: all rows as array
// DESC : wrapper for pg_fetch_array
public function _db_fetch_all($cursor)
{
return pg_fetch_all($cursor);
}
// METHOD: _db_affected_ros
// PARAMS: cursor
// RETURN: number for rows
// DESC : wrapper for pg_affected_rows
public function _db_affected_rows($cursor)
{
return pg_affected_rows($cursor);
}
// METHOD: _db_insert_id
// PARAMS: query, primary key name
// RETURN: last insert primary key
// DESC : reads the last inserted primary key for the query
// if ther is no pk_name tries to auto built it from the table name
// this only works if db schema is after "no plural names. and pk name is table name + _id
// detects schema prefix in table name
public function _db_insert_id($query, $pk_name)
{
// only if an insert has been done
if (preg_match("/^insert /i", $query)) {
$schema = '';
// get table name from insert
$array = explode(' ', $query);
$_table = $array[2];
// if there is a dot inside, we need to split
if (strstr($_table, '.')) {
list($schema, $table) = explode('.', $_table);
} else {
$table = $_table;
}
// no PK name given at all
if (!$pk_name) {
// if name is plurar, make it singular
// if (preg_match("/.*s$/i", $table))
// $table = substr($table, 0, -1);
// set pk_name to "id"
$pk_name = $table."_id";
}
$seq = (($schema) ? $schema.'.' : '').$table."_".$pk_name."_seq";
$q = "SELECT CURRVAL('$seq') AS insert_id";
// $this->currval_query = $q;
// I have to do manually or I overwrite the original insert internal vars ...
if ($q = $this->_db_query($q)) {
list($id) = $this->_db_fetch_array($q);
} else {
$id = array(-1, $q);
}
return $id;
}
}
// METHOD: _db_primary_key
// PARAMS: table and optional schema
// RETURN: primary key name OR false if not possible
// DESC : queries database for the primary key name to this table in the selected schema
public function _db_primary_key($table, $schema = '')
{
if ($table) {
// check if schema set is different from schema given, only needed if schema is not empty
$table_prefix = '';
if ($schema) {
$q = "SHOW search_path";
$cursor = $this->_db_query($q);
$search_path = $this->_db_fetch_array($cursor)['search_path'];
if ($search_path != $schema) {
$table_prefix = $schema.'.';
}
}
// read from table the PK name
// faster primary key get
$q = "SELECT pg_attribute.attname AS column_name, format_type(pg_attribute.atttypid, pg_attribute.atttypmod) AS type ";
$q .= "FROM pg_index, pg_class, pg_attribute ";
if ($schema) {
$q .= ", pg_namespace ";
}
$q .= "WHERE ";
// regclass translates the OID to the name
$q .= "pg_class.oid = '".$table_prefix.$table."'::regclass AND ";
$q .= "indrelid = pg_class.oid AND ";
if ($schema) {
$q .= "nspname = '".$schema."' AND ";
$q .= "pg_class.relnamespace = pg_namespace.oid AND ";
}
$q .= "pg_attribute.attrelid = pg_class.oid AND ";
$q .= "pg_attribute.attnum = any(pg_index.indkey) ";
$q .= "AND indisprimary";
$cursor = $this->_db_query($q);
if ($cursor) {
return $this->_db_fetch_array($cursor)['column_name'];
} else {
return false;
}
} else {
return false;
}
}
// METHOD: _db_connect
// PARAMS: host name, user name, password, database name, optional port (defaults to default postgres port), optional ssl (default allow)
// RETURN: database handler
// DESC : wrapper for pg_connect, writes out failure to screen if error occurs (hidden var)
public function _db_connect($db_host, $db_user, $db_pass, $db_name, $db_port = 5432, $db_ssl = 'allow')
{
// to avoid empty db_port
if (!$db_port) {
$db_port = 5432;
}
$this->dbh = pg_connect("host=".$db_host." port=".$db_port." user=".$db_user." password=".$db_pass." dbname=".$db_name." sslmode=".$db_ssl);
if (!$this->dbh) {
die("<!-- Can't connect [host=".$db_host." port=".$db_port." user=".$db_user." password=XXXX dbname=".$db_name." sslmode=".$db_ssl."] //-->");
}
return $this->dbh;
}
// METHOD: _db_print_error
// PARAMS: database handler, cursor
// RETURN: error string (HTML)
// DESC : reads the last error for this cursor
public function _db_print_error($cursor = '')
{
// run the query again for the error result here
if (!$cursor && $this->last_error_query) {
pg_send_query($this->dbh, $this->last_error_query);
$this->last_error_query = '';
$cursor = pg_get_result($this->dbh);
}
if (pg_result_error($cursor)) {
return "<span style=\"color: red;\"><b>-PostgreSQL-Error-></b> ".pg_result_error($cursor)."</span><br>";
}
}
// METHOD: _db_meta_data
// PARAMS: table name
// RETURN: array with table data
// DESC : wrapper for pg_emta_data
public function _db_meta_data($table)
{
return pg_meta_data($this->dbh, $table);
}
// METHOD: _db_escape_string
// PARAMS: string
// RETURN: escaped string for postgres
// DESC : wrapper for pg_escape_string
public function _db_escape_string($string)
{
return pg_escape_string($this->dbh, $string);
}
// METHOD: _db_escape_bytea
// PARAMS: string
// RETURN: escape bytes for postgres
// DESC : wrapper for pg_escape_bytea
public function _db_escape_bytea($bytea)
{
return pg_escape_bytea($this->dbh, $bytea);
}
// METHOD: _db_connection_busy
// PARAMS: none
// RETURN: true/false for busy connection
// DESC : wrapper for pg_connection_busy
public function _db_connection_busy()
{
return pg_connection_busy($this->dbh);
}
// METHOD: _db_version
// PARAMS: none
// RETURN: databse version
// DESC : wrapper for pg_version
public function _db_version()
{
// array has client, protocol, server
// we just need the server
$v = pg_version($this->dbh);
return $v['server'];
}
// METHOD: _db_array_parse
// PARAMS: input text, output array [needed]
// [internal] limit: are we at the end of the parse
// [internal] offset: shift for {}
// RETURN: array with the elements
// DESC : postgresql array to php array
public function _db_array_parse($text, &$output, $limit = false, $offset = 1)
{
if (false === $limit) {
$limit = strlen($text) - 1;
$output = array();
}
if ('{}' != $text) {
do {
if ('{' != $text{$offset}) {
preg_match("/(\\{?\"([^\"\\\\]|\\\\.)*\"|[^,{}]+)+([,}]+)/", $text, $match, 0, $offset);
$offset += strlen($match[0]);
$output[] = ('"' != $match[1]{0} ? $match[1] : stripcslashes(substr($match[1], 1, -1)));
if ('},' == $match[3]) {
return $offset;
}
} else {
$offset = pg_array_parse($text, $output[], $limit, $offset + 1);
}
} while ($limit > $offset);
}
return $output;
}
}

View File

@@ -1,389 +1,375 @@
<?
/*********************************************************************
* AUTHOR: Clemens "Gullevek" Schwaighofer (www.gullevek.org)
* CREATED: 2014/12/3
* SHORT DESCRIPTION:
* pgsql pdo wrapper calls
* HISTORY:
* /
/*********************************************************************
* AUTHOR: Clemens "Gullevek" Schwaighofer (www.gullevek.org)
* CREATED: 2014/12/3
* SHORT DESCRIPTION:
* pgsql pdo wrapper calls
* HISTORY:
* /
/* collection of PostgreSQL wrappers
* REQUIRES 5.x PHP with compiled pdo pgsql (--with-pdo-pgsql)
*
*/
/* collection of PostgreSQL wrappers
* REQUIRES 5.x PHP with compiled pdo pgsql (--with-pdo-pgsql)
*
*/
class db_pgsql
class db_pgsql
{
private $last_error_query;
private $dbh;
private $cursor = array();
// METHOD: __construct
// PARAMS: none
// RETURN: none
// DESC : class constructor
public function __construct()
{
private $last_error_query;
private $dbh;
private $cursor = array();
}
// METHOD: __construct
// PARAMS: none
// RETURN: none
// DESC : class constructor
public function __construct()
{
}
public function _db_last_error_query()
{
if ($this->last_error_query)
return true;
else
return false;
}
// METHOD: _db_query
// PARAMS: query
// RETURN: cursor
// DESC : was wrapper for pg_query, now it runs pepare and execute in one set. uses the query md5 as the cursor name
public function _db_query($query)
{
$this->last_error_query = '';
/* // read out the query status and save the query if needed
$result = @pg_query($this->dbh, $query);
if (!$result)
$this->last_error_query = $query; */
$cursor = $this->_db_prepare(md5($query), $query);
$result = $this->_db_execute(md5($query), array ());
if (!$result)
$this->last_error_query = $query;
return $cursor;
}
// METHOD: _db_query_result
// PARAMS: query
// RETURN: result from query
// DESC : only valid for the pdo version here. use with care
public function _db_query_result($query)
{
return $this->dbh->query($query);
}
// METHOD: _db_send_query
// PARAMS: query
// RETURN: true/false if query was sent successful
// DESC : sends an async query to the server
public function _db_send_query($query)
{
// return @pg_send_query($this->dbh, $query);
}
// METHOD: _db_get_result
// PARAMS: none
// RETURN: resource handler
// DESC : wrapper for pg_get_result
public function _db_get_result()
{
$this->last_error_query = '';
/* $result = pg_get_result($this->dbh);
if ($error = pg_result_error($result))
$this->last_error_query = $error; */
return $result;
}
// METHOD: _db_close
// PARAMS: none
// RETURN: none
// DESC : wrapper for pg_close
public function _db_close()
{
if (is_array($this->cursor))
{
foreach ($this->cursor as $key => $data)
{
$this->cursor[$key]->closeCursor;
$this->cursor[$key] = null;
}
}
$this->dbh = null;
}
// METHOD: _db_prepare
// PARAMS: prepare name, query
// RETURN: prepared statement handler
// DESC : wrapper for pg_prepare
public function _db_prepare($name, $query)
{
// return @pg_prepare($this->dbh, $name, $query);
$this->cursor[$name] = $this->dbh->prepare($query);
return $this->cursor[$name];
}
// METHOD: _db_execute
// PARAMS: prepare name, data for query
// RETURN: returns status
// DESC : wrapper for pg_execute for running a prepared statement
public function _db_execute($name, $data)
{
// return @pg_execute($this->dbh, $name, $data);
return $this->cursor[$name]->execute($data);
}
// METHOD: _db_num_rows
// PARAMS: cursor
// RETURN: rows
// DESC : wrapper for pg_num_rows
public function _db_num_rows($cursor)
{
// return pg_num_rows($cursor);
return $cusor->rowCount();
}
// METHOD: _db_num_fields
// PARAMS: cursor
// RETURN: number for fields in query
// DESC : wrapper for pg_num_fields
public function _db_num_fields($cursor)
{
// return pg_num_fields($cursor);
return $cursor->columnCount();
}
// METHOD: _db_field_name
// PARAMS: cursor, field position
// RETURN: name of field
// DESC : wrapper for pg_field_name
public function _db_field_name($cursor, $i)
{
// return pg_field_name($cursor, $i);
}
// METHOD: _db_fetch_array
// PARAMS: cursor
// RETURN: row
// DESC : wrapper for pg_fetch_array
public function _db_fetch_array($cursor)
{
// return pg_fetch_array($cursor);
return $cursor->fetch();
}
// METHOD: _db_affected_ros
// PARAMS: cursor
// RETURN: number for rows
// DESC : wrapper for pg_affected_rows
public function _db_affected_rows($cursor)
{
// return pg_affected_rows($cursor);
return $cusor->rowCount();
}
// METHOD: _db_insert_id
// PARAMS: query, primary key name
// RETURN: last insert primary key
// DESC : reads the last inserted primary key for the query
// if ther is no pk_name tries to auto built it from the table name
// this only works if db schema is after "no plural names. and pk name is table name + _id
// detects schema prefix in table name
public function _db_insert_id($query, $pk_name)
{
// only if an insert has been done
if (preg_match("/^insert /i", $query))
{
$schema = '';
// get table name from insert
$array = explode(' ', $query);
$_table = $array[2];
// if there is a dot inside, we need to split
if (strstr($_table, '.'))
list($schema, $table) = explode('.', $_table);
else
$table = $_table;
// no PK name given at all
if (!$pk_name)
{
// if name is plural, make it singular
// if (preg_match("/.*s$/i", $table))
// $table = substr($table, 0, -1);
// set pk_name to "id"
$pk_name = $table."_id";
}
$seq = (($schema) ? $schema.'.' : '').$table."_".$pk_name."_seq";
$q = "SELECT CURRVAL('$seq') AS insert_id";
// I have to do manually or I overwrite the original insert internal vars ...
$row = $this->_db_query_result($q);
if ($row['insert_id'])
{
$id = $row['insert_id'];
}
else
{
$id = array(-1, $q);
}
return $id;
}
}
// METHOD: _db_primary_key
// PARAMS: table and optional schema
// RETURN: primary key name OR false if not possible
// DESC : queries database for the primary key name to this table in the selected schema
public function _db_primary_key($table, $schema = '')
{
if ($table)
{
// check if schema set is different from schema given, only needed if schema is not empty
$table_prefix = '';
if ($schema)
{
$q = "SHOW search_path";
// $cursor = $this->_db_query($q);
// $search_path = $this->_db_fetch_array($cursor)['search_path'];
$search_path = $this->_db_query_result($q)['search_path'];
if ($search_path != $schema)
{
$table_prefix = $schema.'.';
}
}
// read from table the PK name
// faster primary key get
$q = "SELECT pg_attribute.attname AS column_name, format_type(pg_attribute.atttypid, pg_attribute.atttypmod) AS type ";
$q .= "FROM pg_index, pg_class, pg_attribute ";
if ($schema)
$q .= ", pg_namespace ";
$q .= "WHERE ";
// regclass translates the OID to the name
$q .= "pg_class.oid = '".$table_prefix.$table."'::regclass AND ";
$q .= "indrelid = pg_class.oid AND ";
if ($schema)
{
$q .= "nspname = '".$schema."' AND ";
$q .= "pg_class.relnamespace = pg_namespace.oid AND ";
}
$q .= "pg_attribute.attrelid = pg_class.oid AND ";
$q .= "pg_attribute.attnum = any(pg_index.indkey) ";
$q .= "AND indisprimary";
$row = $this->_db_query_result($q);
if ($row === FALSE)
return false;
else
return $row['column_name'];
}
else
{
return false;
}
}
// METHOD: _db_connect
// PARAMS: host name, user name, password, database name, optional port (defaults to default postgres port), optional ssl (default allow)
// RETURN: database handler
// DESC : wrapper for pg_connect, writes out failure to screen if error occurs (hidden var)
public function _db_connect($db_host, $db_user, $db_pass, $db_name, $db_port = 5432, $db_ssl = 'allow')
{
// to avoid empty db_port
if (!$db_port)
{
$db_port = 5432;
}
try
{
$this->dbh = new PDO('pgsql:host='.$db_host.';dbname='.$db_name.';port='.$db_port.';sslmode='.$db_ssl, $db_user, $db_pass);
}
catch (PDOException $e)
{
print "Error!: ".$e->getMessage()."\n";
die("<!-- Can't connect [host=".$db_host." port=".$db_port." user=".$db_user." password=XXXX dbname=".$db_name." sslmode=".$db_ssl."]: ".$e->getMEssage()."//-->");
}
return $this->dbh;
}
// METHOD: _db_print_error
// PARAMS: database handler, cursor
// RETURN: error string (HTML)
// DESC : reads the last error for this cursor
public function _db_print_error($cursor = '')
{
/* // run the query again for the error result here
if (!$cursor && $this->last_error_query)
{
pg_send_query($this->dbh, $this->last_error_query);
$this->last_error_query = '';
$cursor = pg_get_result($this->dbh);
}
if (pg_result_error($cursor))
return "<span style=\"color: red;\"><b>-PostgreSQL-Error-></b> ".pg_result_error($cursor)."</span><br>"; */
}
// METHOD: _db_meta_data
// PARAMS: table name
// RETURN: array with table data
// DESC : wrapper for pg_emta_data
public function _db_meta_data($table)
{
// return @pg_meta_data($this->dbh, $table);
}
// METHOD: _db_escape_string
// PARAMS: string
// RETURN: escaped string for postgres
// DESC : wrapper for pg_escape_string
public function _db_escape_string($string)
{
// return pg_escape_string($this->dbh, $string);
}
// METHOD: _db_escape_bytea
// PARAMS: string
// RETURN: escape bytes for postgres
// DESC : wrapper for pg_escape_bytea
public function _db_escape_bytea($bytea)
{
// return pg_escape_bytea($this->dbh, $bytea);
}
// METHOD: _db_connection_busy
// PARAMS: none
// RETURN: true/false for busy connection
// DESC : wrapper for pg_connection_busy
public function _db_connection_busy()
{
// return pg_connection_busy($this->dbh);
}
// METHOD: _db_version
// PARAMS: none
// RETURN: databse version
// DESC : wrapper for pg_version
public function _db_version()
{
// array has client, protocol, server
// we just need the server
$v = pg_version($this->dbh);
return $v['server'];
}
// METHOD: _db_array_parse
// PARAMS: input text, output array [needed]
// [internal] limit: are we at the end of the parse
// [internal] offset: shift for {}
// RETURN: array with the elements
// DESC : postgresql array to php array
public function _db_array_parse($text, &$output, $limit = false, $offset = 1)
{
if (false === $limit)
{
$limit = strlen($text) - 1;
$output = array();
}
if ('{}' != $text)
do
{
if ('{' != $text{$offset})
{
preg_match("/(\\{?\"([^\"\\\\]|\\\\.)*\"|[^,{}]+)+([,}]+)/", $text, $match, 0, $offset);
$offset += strlen($match[0]);
$output[] = ('"' != $match[1]{0} ? $match[1] : stripcslashes(substr($match[1], 1, -1)));
if ('},' == $match[3])
return $offset;
}
else
$offset = pg_array_parse($text, $output[], $limit, $offset + 1);
}
while ($limit > $offset);
return $output;
public function _db_last_error_query()
{
if ($this->last_error_query) {
return true;
} else {
return false;
}
}
?>
// METHOD: _db_query
// PARAMS: query
// RETURN: cursor
// DESC : was wrapper for pg_query, now it runs pepare and execute in one set. uses the query md5 as the cursor name
public function _db_query($query)
{
$this->last_error_query = '';
/* // read out the query status and save the query if needed
$result = @pg_query($this->dbh, $query);
if (!$result)
$this->last_error_query = $query; */
$cursor = $this->_db_prepare(md5($query), $query);
$result = $this->_db_execute(md5($query), array ());
if (!$result) {
$this->last_error_query = $query;
}
return $cursor;
}
// METHOD: _db_query_result
// PARAMS: query
// RETURN: result from query
// DESC : only valid for the pdo version here. use with care
public function _db_query_result($query)
{
return $this->dbh->query($query);
}
// METHOD: _db_send_query
// PARAMS: query
// RETURN: true/false if query was sent successful
// DESC : sends an async query to the server
public function _db_send_query($query)
{
// return @pg_send_query($this->dbh, $query);
}
// METHOD: _db_get_result
// PARAMS: none
// RETURN: resource handler
// DESC : wrapper for pg_get_result
public function _db_get_result()
{
$this->last_error_query = '';
/* $result = pg_get_result($this->dbh);
if ($error = pg_result_error($result)) {
$this->last_error_query = $error;
}*/
return $result;
}
// METHOD: _db_close
// PARAMS: none
// RETURN: none
// DESC : wrapper for pg_close
public function _db_close()
{
if (is_array($this->cursor)) {
foreach ($this->cursor as $key => $data) {
$this->cursor[$key]->closeCursor;
$this->cursor[$key] = null;
}
}
$this->dbh = null;
}
// METHOD: _db_prepare
// PARAMS: prepare name, query
// RETURN: prepared statement handler
// DESC : wrapper for pg_prepare
public function _db_prepare($name, $query)
{
// return @pg_prepare($this->dbh, $name, $query);
$this->cursor[$name] = $this->dbh->prepare($query);
return $this->cursor[$name];
}
// METHOD: _db_execute
// PARAMS: prepare name, data for query
// RETURN: returns status
// DESC : wrapper for pg_execute for running a prepared statement
public function _db_execute($name, $data)
{
// return @pg_execute($this->dbh, $name, $data);
return $this->cursor[$name]->execute($data);
}
// METHOD: _db_num_rows
// PARAMS: cursor
// RETURN: rows
// DESC : wrapper for pg_num_rows
public function _db_num_rows($cursor)
{
// return pg_num_rows($cursor);
return $cusor->rowCount();
}
// METHOD: _db_num_fields
// PARAMS: cursor
// RETURN: number for fields in query
// DESC : wrapper for pg_num_fields
public function _db_num_fields($cursor)
{
// return pg_num_fields($cursor);
return $cursor->columnCount();
}
// METHOD: _db_field_name
// PARAMS: cursor, field position
// RETURN: name of field
// DESC : wrapper for pg_field_name
public function _db_field_name($cursor, $i)
{
// return pg_field_name($cursor, $i);
}
// METHOD: _db_fetch_array
// PARAMS: cursor
// RETURN: row
// DESC : wrapper for pg_fetch_array
public function _db_fetch_array($cursor)
{
// return pg_fetch_array($cursor);
return $cursor->fetch();
}
// METHOD: _db_affected_ros
// PARAMS: cursor
// RETURN: number for rows
// DESC : wrapper for pg_affected_rows
public function _db_affected_rows($cursor)
{
// return pg_affected_rows($cursor);
return $cusor->rowCount();
}
// METHOD: _db_insert_id
// PARAMS: query, primary key name
// RETURN: last insert primary key
// DESC : reads the last inserted primary key for the query
// if ther is no pk_name tries to auto built it from the table name
// this only works if db schema is after "no plural names. and pk name is table name + _id
// detects schema prefix in table name
public function _db_insert_id($query, $pk_name)
{
// only if an insert has been done
if (preg_match("/^insert /i", $query)) {
$schema = '';
// get table name from insert
$array = explode(' ', $query);
$_table = $array[2];
// if there is a dot inside, we need to split
if (strstr($_table, '.')) {
list($schema, $table) = explode('.', $_table);
} else {
$table = $_table;
}
// no PK name given at all
if (!$pk_name) {
// if name is plural, make it singular
// if (preg_match("/.*s$/i", $table))
// $table = substr($table, 0, -1);
// set pk_name to "id"
$pk_name = $table."_id";
}
$seq = (($schema) ? $schema.'.' : '').$table."_".$pk_name."_seq";
$q = "SELECT CURRVAL('$seq') AS insert_id";
// I have to do manually or I overwrite the original insert internal vars ...
$row = $this->_db_query_result($q);
if ($row['insert_id']) {
$id = $row['insert_id'];
} else {
$id = array(-1, $q);
}
return $id;
}
}
// METHOD: _db_primary_key
// PARAMS: table and optional schema
// RETURN: primary key name OR false if not possible
// DESC : queries database for the primary key name to this table in the selected schema
public function _db_primary_key($table, $schema = '')
{
if ($table) {
// check if schema set is different from schema given, only needed if schema is not empty
$table_prefix = '';
if ($schema) {
$q = "SHOW search_path";
// $cursor = $this->_db_query($q);
// $search_path = $this->_db_fetch_array($cursor)['search_path'];
$search_path = $this->_db_query_result($q)['search_path'];
if ($search_path != $schema) {
$table_prefix = $schema.'.';
}
}
// read from table the PK name
// faster primary key get
$q = "SELECT pg_attribute.attname AS column_name, format_type(pg_attribute.atttypid, pg_attribute.atttypmod) AS type ";
$q .= "FROM pg_index, pg_class, pg_attribute ";
if ($schema) {
$q .= ", pg_namespace ";
}
$q .= "WHERE ";
// regclass translates the OID to the name
$q .= "pg_class.oid = '".$table_prefix.$table."'::regclass AND ";
$q .= "indrelid = pg_class.oid AND ";
if ($schema) {
$q .= "nspname = '".$schema."' AND ";
$q .= "pg_class.relnamespace = pg_namespace.oid AND ";
}
$q .= "pg_attribute.attrelid = pg_class.oid AND ";
$q .= "pg_attribute.attnum = any(pg_index.indkey) ";
$q .= "AND indisprimary";
$row = $this->_db_query_result($q);
if ($row === false) {
return false;
} else {
return $row['column_name'];
}
} else {
return false;
}
}
// METHOD: _db_connect
// PARAMS: host name, user name, password, database name, optional port (defaults to default postgres port), optional ssl (default allow)
// RETURN: database handler
// DESC : wrapper for pg_connect, writes out failure to screen if error occurs (hidden var)
public function _db_connect($db_host, $db_user, $db_pass, $db_name, $db_port = 5432, $db_ssl = 'allow')
{
// to avoid empty db_port
if (!$db_port) {
$db_port = 5432;
}
try {
$this->dbh = new PDO('pgsql:host='.$db_host.';dbname='.$db_name.';port='.$db_port.';sslmode='.$db_ssl, $db_user, $db_pass);
} catch (PDOException $e) {
print "Error!: ".$e->getMessage()."\n";
die("<!-- Can't connect [host=".$db_host." port=".$db_port." user=".$db_user." password=XXXX dbname=".$db_name." sslmode=".$db_ssl."]: ".$e->getMEssage()."//-->");
}
return $this->dbh;
}
// METHOD: _db_print_error
// PARAMS: database handler, cursor
// RETURN: error string (HTML)
// DESC : reads the last error for this cursor
public function _db_print_error($cursor = '')
{
/* // run the query again for the error result here
if (!$cursor && $this->last_error_query)
{
pg_send_query($this->dbh, $this->last_error_query);
$this->last_error_query = '';
$cursor = pg_get_result($this->dbh);
}
if (pg_result_error($cursor))
return "<span style=\"color: red;\"><b>-PostgreSQL-Error-></b> ".pg_result_error($cursor)."</span><br>"; */
}
// METHOD: _db_meta_data
// PARAMS: table name
// RETURN: array with table data
// DESC : wrapper for pg_emta_data
public function _db_meta_data($table)
{
// return @pg_meta_data($this->dbh, $table);
}
// METHOD: _db_escape_string
// PARAMS: string
// RETURN: escaped string for postgres
// DESC : wrapper for pg_escape_string
public function _db_escape_string($string)
{
// return pg_escape_string($this->dbh, $string);
}
// METHOD: _db_escape_bytea
// PARAMS: string
// RETURN: escape bytes for postgres
// DESC : wrapper for pg_escape_bytea
public function _db_escape_bytea($bytea)
{
// return pg_escape_bytea($this->dbh, $bytea);
}
// METHOD: _db_connection_busy
// PARAMS: none
// RETURN: true/false for busy connection
// DESC : wrapper for pg_connection_busy
public function _db_connection_busy()
{
// return pg_connection_busy($this->dbh);
}
// METHOD: _db_version
// PARAMS: none
// RETURN: databse version
// DESC : wrapper for pg_version
public function _db_version()
{
// array has client, protocol, server
// we just need the server
$v = pg_version($this->dbh);
return $v['server'];
}
// METHOD: _db_array_parse
// PARAMS: input text, output array [needed]
// [internal] limit: are we at the end of the parse
// [internal] offset: shift for {}
// RETURN: array with the elements
// DESC : postgresql array to php array
public function _db_array_parse($text, &$output, $limit = false, $offset = 1)
{
if (false === $limit) {
$limit = strlen($text) - 1;
$output = array();
}
if ('{}' != $text) {
do {
if ('{' != $text{$offset}) {
preg_match("/(\\{?\"([^\"\\\\]|\\\\.)*\"|[^,{}]+)+([,}]+)/", $text, $match, 0, $offset);
$offset += strlen($match[0]);
$output[] = ('"' != $match[1]{0} ? $match[1] : stripcslashes(substr($match[1], 1, -1)));
if ('},' == $match[3]) {
return $offset;
}
} else {
$offset = pg_array_parse($text, $output[], $limit, $offset + 1);
}
} while ($limit > $offset);
}
return $output;
}
}

View File

@@ -1,432 +1,456 @@
<?php
/*
Copyright (c) 2003, 2009 Danilo Segan <danilo@kvota.net>.
Copyright (c) 2005 Nico Kaiser <nico@siriux.net>
Copyright (c) 2003, 2009 Danilo Segan <danilo@kvota.net>.
Copyright (c) 2005 Nico Kaiser <nico@siriux.net>
This file is part of PHP-gettext.
This file is part of PHP-gettext.
PHP-gettext is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
PHP-gettext is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
PHP-gettext is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with PHP-gettext; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
PHP-gettext is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with PHP-gettext; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* Provides a simple gettext replacement that works independently from
* the system's gettext abilities.
* It can read MO files and use them for translating strings.
* The files are passed to gettext_reader as a Stream (see streams.php)
*
* This version has the ability to cache all strings and translations to
* speed up the string lookup.
* While the cache is enabled by default, it can be switched off with the
* second parameter in the constructor (e.g. whenusing very large MO files
* that you don't want to keep in memory)
*/
class gettext_reader {
//public:
var $error = 0; // public variable that holds error code (0 if no error)
* Provides a simple gettext replacement that works independently from
* the system's gettext abilities.
* It can read MO files and use them for translating strings.
* The files are passed to gettext_reader as a Stream (see streams.php)
*
* This version has the ability to cache all strings and translations to
* speed up the string lookup.
* While the cache is enabled by default, it can be switched off with the
* second parameter in the constructor (e.g. whenusing very large MO files
* that you don't want to keep in memory)
*/
class gettext_reader
{
// public:
public $error = 0; // public variable that holds error code (0 if no error)
//private:
var $BYTEORDER = 0; // 0: low endian, 1: big endian
var $STREAM = NULL;
var $short_circuit = false;
var $enable_cache = false;
var $originals = NULL; // offset of original table
var $translations = NULL; // offset of translation table
var $pluralheader = NULL; // cache header field for plural forms
var $total = 0; // total string count
var $table_originals = NULL; // table for original strings (offsets)
var $table_translations = NULL; // table for translated strings (offsets)
var $cache_translations = NULL; // original -> translation mapping
private $BYTEORDER = 0; // 0: low endian, 1: big endian
private $STREAM = null;
private $short_circuit = false;
private $enable_cache = false;
private $originals = null; // offset of original table
private $translations = null; // offset of translation table
private $pluralheader = null; // cache header field for plural forms
private $total = 0; // total string count
private $table_originals = null; // table for original strings (offsets)
private $table_translations = null; // table for translated strings (offsets)
private $cache_translations = null; // original -> translation mapping
/* Methods */
/* Methods */
/**
* Reads a 32bit Integer from the Stream
*
* @access private
* @return Integer from the Stream
*/
private function readint()
{
if ($this->BYTEORDER == 0) {
// low endian
$input = unpack('V', $this->STREAM->read(4));
return array_shift($input);
} else {
// big endian
$input = unpack('N', $this->STREAM->read(4));
return array_shift($input);
}
}
public function read($bytes)
{
return $this->STREAM->read($bytes);
}
/**
* Reads an array of Integers from the Stream
*
* @param int count How many elements should be read
* @return Array of Integers
*/
public function readintarray($count)
{
if ($this->BYTEORDER == 0) {
// low endian
return unpack('V'.$count, $this->STREAM->read(4 * $count));
} else {
// big endian
return unpack('N'.$count, $this->STREAM->read(4 * $count));
}
}
/**
* Constructor
*
* @param object Reader the StreamReader object
* @param boolean enable_cache Enable or disable caching of strings (default on)
*/
public function __construct($Reader, $enable_cache = true)
{
// If there isn't a StreamReader, turn on short circuit mode.
if (!$Reader || isset($Reader->error)) {
$this->short_circuit = true;
return;
}
// Caching can be turned off
$this->enable_cache = $enable_cache;
$MAGIC1 = "\x95\x04\x12\xde";
$MAGIC2 = "\xde\x12\x04\x95";
$this->STREAM = $Reader;
$magic = $this->read(4);
if ($magic == $MAGIC1) {
$this->BYTEORDER = 1;
} elseif ($magic == $MAGIC2) {
$this->BYTEORDER = 0;
} else {
$this->error = 1; // not MO file
return false;
}
// FIXME: Do we care about revision? We should.
$revision = $this->readint();
$this->total = $this->readint();
$this->originals = $this->readint();
$this->translations = $this->readint();
}
/**
* Loads the translation tables from the MO file into the cache
* If caching is enabled, also loads all strings into a cache
* to speed up translation lookups
*
* @access private
*/
private function load_tables()
{
if (is_array($this->cache_translations) &&
is_array($this->table_originals) &&
is_array($this->table_translations)) {
return;
}
/* get original and translations tables */
if (!is_array($this->table_originals)) {
$this->STREAM->seekto($this->originals);
$this->table_originals = $this->readintarray($this->total * 2);
}
if (!is_array($this->table_translations)) {
$this->STREAM->seekto($this->translations);
$this->table_translations = $this->readintarray($this->total * 2);
}
if ($this->enable_cache) {
$this->cache_translations = array ();
/* read all strings in the cache */
for ($i = 0; $i < $this->total; $i++) {
$this->STREAM->seekto($this->table_originals[$i * 2 + 2]);
$original = $this->STREAM->read($this->table_originals[$i * 2 + 1]);
$this->STREAM->seekto($this->table_translations[$i * 2 + 2]);
$translation = $this->STREAM->read($this->table_translations[$i * 2 + 1]);
$this->cache_translations[$original] = $translation;
}
}
}
/**
* Returns a string from the "originals" table
*
* @access private
* @param int num Offset number of original string
* @return string Requested string if found, otherwise ''
*/
private function get_original_string($num)
{
$length = $this->table_originals[$num * 2 + 1];
$offset = $this->table_originals[$num * 2 + 2];
if (!$length) {
return '';
}
$this->STREAM->seekto($offset);
$data = $this->STREAM->read($length);
return (string)$data;
}
/**
* Returns a string from the "translations" table
*
* @access private
* @param int num Offset number of original string
* @return string Requested string if found, otherwise ''
*/
private function get_translation_string($num)
{
$length = $this->table_translations[$num * 2 + 1];
$offset = $this->table_translations[$num * 2 + 2];
if (!$length) {
return '';
}
$this->STREAM->seekto($offset);
$data = $this->STREAM->read($length);
return (string)$data;
}
/**
* Binary search for string
*
* @access private
* @param string string
* @param int start (internally used in recursive function)
* @param int end (internally used in recursive function)
* @return int string number (offset in originals table)
*/
private function find_string($string, $start = -1, $end = -1)
{
if (($start == -1) or ($end == -1)) {
// find_string is called with only one parameter, set start end end
$start = 0;
$end = $this->total;
}
if (abs($start - $end) <= 1) {
// We're done, now we either found the string, or it doesn't exist
$txt = $this->get_original_string($start);
if ($string == $txt) {
return $start;
} else {
return -1;
}
} elseif ($start > $end) {
// start > end -> turn around and start over
return $this->find_string($string, $end, $start);
} else {
// Divide table in two parts
$half = (int)(($start + $end) / 2);
$cmp = strcmp($string, $this->get_original_string($half));
if ($cmp == 0) {
// string is exactly in the middle => return it
return $half;
} else if ($cmp < 0) {
// The string is in the upper half
return $this->find_string($string, $start, $half);
} else {
// Translateshe string is in the lower half
return $this->find_string($string, $half, $end);
}
}
}
/**
* Translates a string
*
* @access public
* @param string string to be translated
* @return string translated string (or original, if not found)
*/
public function translate($string)
{
if ($this->short_circuit) {
return $string;
}
$this->load_tables();
if ($this->enable_cache) {
// Caching enabled, get translated string from cache
if (array_key_exists($string, $this->cache_translations)) {
return $this->cache_translations[$string];
} else {
return $string;
}
} else {
// Caching not enabled, try to find string
$num = $this->find_string($string);
if ($num == -1) {
return $string;
} else {
return $this->get_translation_string($num);
}
}
}
/**
* Sanitize plural form expression for use in PHP eval call.
*
* @access private
* @return string sanitized plural form expression
*/
private function sanitize_plural_expression($expr)
{
// Get rid of disallowed characters.
$expr = preg_replace('@[^a-zA-Z0-9_:;\(\)\?\|\&=!<>+*/\%-]@', '', $expr);
// Add parenthesis for tertiary '?' operator.
$expr .= ';';
$res = '';
$p = 0;
for ($i = 0; $i < strlen($expr); $i++) {
$ch = $expr[$i];
switch ($ch) {
case '?':
$res .= ' ? (';
$p++;
break;
case ':':
$res .= ') : (';
break;
case ';':
$res .= str_repeat(')', $p).';';
$p = 0;
break;
default:
$res .= $ch;
}
}
return $res;
}
/**
* Parse full PO header and extract only plural forms line.
*
* @access private
* @return string verbatim plural form header field
*/
private function extract_plural_forms_header_from_po_header($header)
{
if (preg_match("/(^|\n)plural-forms: ([^\n]*)\n/i", $header, $regs)) {
$expr = $regs[2];
} else {
$expr = "nplurals=2; plural=n == 1 ? 0 : 1;";
}
return $expr;
}
/**
* Reads a 32bit Integer from the Stream
*
* @access private
* @return Integer from the Stream
*/
function readint() {
if ($this->BYTEORDER == 0) {
// low endian
$input=unpack('V', $this->STREAM->read(4));
return array_shift($input);
} else {
// big endian
$input=unpack('N', $this->STREAM->read(4));
return array_shift($input);
}
}
* Get possible plural forms from MO header
*
* @access private
* @return string plural form header
*/
private function get_plural_forms()
{
// lets assume message number 0 is header
// this is true, right?
$this->load_tables();
function read($bytes) {
return $this->STREAM->read($bytes);
}
// cache header field for plural forms
if (! is_string($this->pluralheader)) {
if ($this->enable_cache) {
$header = $this->cache_translations[""];
} else {
$header = $this->get_translation_string(0);
}
$expr = $this->extract_plural_forms_header_from_po_header($header);
$this->pluralheader = $this->sanitize_plural_expression($expr);
}
return $this->pluralheader;
}
/**
* Reads an array of Integers from the Stream
*
* @param int count How many elements should be read
* @return Array of Integers
*/
function readintarray($count) {
if ($this->BYTEORDER == 0) {
// low endian
return unpack('V'.$count, $this->STREAM->read(4 * $count));
} else {
// big endian
return unpack('N'.$count, $this->STREAM->read(4 * $count));
}
}
/**
* Detects which plural form to take
*
* @access private
* @param n count
* @return int array index of the right plural form
*/
private function select_string($n)
{
$string = $this->get_plural_forms();
$string = str_replace('nplurals', "\$total", $string);
$string = str_replace("n", $n, $string);
$string = str_replace('plural', "\$plural", $string);
/**
* Constructor
*
* @param object Reader the StreamReader object
* @param boolean enable_cache Enable or disable caching of strings (default on)
*/
function __construct($Reader, $enable_cache = true) {
// If there isn't a StreamReader, turn on short circuit mode.
if (! $Reader || isset($Reader->error) ) {
$this->short_circuit = true;
return;
}
$total = 0;
$plural = 0;
// Caching can be turned off
$this->enable_cache = $enable_cache;
eval("$string");
if ($plural >= $total) {
$plural = $total - 1;
}
return $plural;
}
$MAGIC1 = "\x95\x04\x12\xde";
$MAGIC2 = "\xde\x12\x04\x95";
/**
* Plural version of gettext
*
* @access public
* @param string single
* @param string plural
* @param string number
* @return translated plural form
*/
public function ngettext($single, $plural, $number)
{
if ($this->short_circuit) {
if ($number != 1) {
return $plural;
} else {
return $single;
}
}
$this->STREAM = $Reader;
$magic = $this->read(4);
if ($magic == $MAGIC1) {
$this->BYTEORDER = 1;
} elseif ($magic == $MAGIC2) {
$this->BYTEORDER = 0;
} else {
$this->error = 1; // not MO file
return false;
}
// find out the appropriate form
$select = $this->select_string($number);
// FIXME: Do we care about revision? We should.
$revision = $this->readint();
// this should contains all strings separated by NULLs
$key = $single . chr(0) . $plural;
$this->total = $this->readint();
$this->originals = $this->readint();
$this->translations = $this->readint();
}
if ($this->enable_cache) {
if (! array_key_exists($key, $this->cache_translations)) {
return ($number != 1) ? $plural : $single;
} else {
$result = $this->cache_translations[$key];
$list = explode(chr(0), $result);
return $list[$select];
}
} else {
$num = $this->find_string($key);
if ($num == -1) {
return ($number != 1) ? $plural : $single;
} else {
$result = $this->get_translation_string($num);
$list = explode(chr(0), $result);
return $list[$select];
}
}
}
/**
* Loads the translation tables from the MO file into the cache
* If caching is enabled, also loads all strings into a cache
* to speed up translation lookups
*
* @access private
*/
function load_tables() {
if (is_array($this->cache_translations) &&
is_array($this->table_originals) &&
is_array($this->table_translations))
return;
public function pgettext($context, $msgid)
{
$key = $context.chr(4).$msgid;
$ret = $this->translate($key);
if (strpos($ret, "\004") !== false) {
return $msgid;
} else {
return $ret;
}
}
/* get original and translations tables */
if (!is_array($this->table_originals)) {
$this->STREAM->seekto($this->originals);
$this->table_originals = $this->readintarray($this->total * 2);
}
if (!is_array($this->table_translations)) {
$this->STREAM->seekto($this->translations);
$this->table_translations = $this->readintarray($this->total * 2);
}
if ($this->enable_cache) {
$this->cache_translations = array ();
/* read all strings in the cache */
for ($i = 0; $i < $this->total; $i++) {
$this->STREAM->seekto($this->table_originals[$i * 2 + 2]);
$original = $this->STREAM->read($this->table_originals[$i * 2 + 1]);
$this->STREAM->seekto($this->table_translations[$i * 2 + 2]);
$translation = $this->STREAM->read($this->table_translations[$i * 2 + 1]);
$this->cache_translations[$original] = $translation;
}
}
}
/**
* Returns a string from the "originals" table
*
* @access private
* @param int num Offset number of original string
* @return string Requested string if found, otherwise ''
*/
function get_original_string($num) {
$length = $this->table_originals[$num * 2 + 1];
$offset = $this->table_originals[$num * 2 + 2];
if (! $length)
return '';
$this->STREAM->seekto($offset);
$data = $this->STREAM->read($length);
return (string)$data;
}
/**
* Returns a string from the "translations" table
*
* @access private
* @param int num Offset number of original string
* @return string Requested string if found, otherwise ''
*/
function get_translation_string($num) {
$length = $this->table_translations[$num * 2 + 1];
$offset = $this->table_translations[$num * 2 + 2];
if (! $length)
return '';
$this->STREAM->seekto($offset);
$data = $this->STREAM->read($length);
return (string)$data;
}
/**
* Binary search for string
*
* @access private
* @param string string
* @param int start (internally used in recursive function)
* @param int end (internally used in recursive function)
* @return int string number (offset in originals table)
*/
function find_string($string, $start = -1, $end = -1) {
if (($start == -1) or ($end == -1)) {
// find_string is called with only one parameter, set start end end
$start = 0;
$end = $this->total;
}
if (abs($start - $end) <= 1) {
// We're done, now we either found the string, or it doesn't exist
$txt = $this->get_original_string($start);
if ($string == $txt)
return $start;
else
return -1;
} else if ($start > $end) {
// start > end -> turn around and start over
return $this->find_string($string, $end, $start);
} else {
// Divide table in two parts
$half = (int)(($start + $end) / 2);
$cmp = strcmp($string, $this->get_original_string($half));
if ($cmp == 0)
// string is exactly in the middle => return it
return $half;
else if ($cmp < 0)
// The string is in the upper half
return $this->find_string($string, $start, $half);
else
// The string is in the lower half
return $this->find_string($string, $half, $end);
}
}
/**
* Translates a string
*
* @access public
* @param string string to be translated
* @return string translated string (or original, if not found)
*/
function translate($string) {
if ($this->short_circuit)
return $string;
$this->load_tables();
if ($this->enable_cache) {
// Caching enabled, get translated string from cache
if (array_key_exists($string, $this->cache_translations))
return $this->cache_translations[$string];
else
return $string;
} else {
// Caching not enabled, try to find string
$num = $this->find_string($string);
if ($num == -1)
return $string;
else
return $this->get_translation_string($num);
}
}
/**
* Sanitize plural form expression for use in PHP eval call.
*
* @access private
* @return string sanitized plural form expression
*/
function sanitize_plural_expression($expr) {
// Get rid of disallowed characters.
$expr = preg_replace('@[^a-zA-Z0-9_:;\(\)\?\|\&=!<>+*/\%-]@', '', $expr);
// Add parenthesis for tertiary '?' operator.
$expr .= ';';
$res = '';
$p = 0;
for ($i = 0; $i < strlen($expr); $i++) {
$ch = $expr[$i];
switch ($ch) {
case '?':
$res .= ' ? (';
$p++;
break;
case ':':
$res .= ') : (';
break;
case ';':
$res .= str_repeat( ')', $p) . ';';
$p = 0;
break;
default:
$res .= $ch;
}
}
return $res;
}
/**
* Parse full PO header and extract only plural forms line.
*
* @access private
* @return string verbatim plural form header field
*/
function extract_plural_forms_header_from_po_header($header) {
if (preg_match("/(^|\n)plural-forms: ([^\n]*)\n/i", $header, $regs))
$expr = $regs[2];
else
$expr = "nplurals=2; plural=n == 1 ? 0 : 1;";
return $expr;
}
/**
* Get possible plural forms from MO header
*
* @access private
* @return string plural form header
*/
function get_plural_forms() {
// lets assume message number 0 is header
// this is true, right?
$this->load_tables();
// cache header field for plural forms
if (! is_string($this->pluralheader)) {
if ($this->enable_cache) {
$header = $this->cache_translations[""];
} else {
$header = $this->get_translation_string(0);
}
$expr = $this->extract_plural_forms_header_from_po_header($header);
$this->pluralheader = $this->sanitize_plural_expression($expr);
}
return $this->pluralheader;
}
/**
* Detects which plural form to take
*
* @access private
* @param n count
* @return int array index of the right plural form
*/
function select_string($n) {
$string = $this->get_plural_forms();
$string = str_replace('nplurals',"\$total",$string);
$string = str_replace("n",$n,$string);
$string = str_replace('plural',"\$plural",$string);
$total = 0;
$plural = 0;
eval("$string");
if ($plural >= $total) $plural = $total - 1;
return $plural;
}
/**
* Plural version of gettext
*
* @access public
* @param string single
* @param string plural
* @param string number
* @return translated plural form
*/
function ngettext($single, $plural, $number) {
if ($this->short_circuit) {
if ($number != 1)
return $plural;
else
return $single;
}
// find out the appropriate form
$select = $this->select_string($number);
// this should contains all strings separated by NULLs
$key = $single . chr(0) . $plural;
if ($this->enable_cache) {
if (! array_key_exists($key, $this->cache_translations)) {
return ($number != 1) ? $plural : $single;
} else {
$result = $this->cache_translations[$key];
$list = explode(chr(0), $result);
return $list[$select];
}
} else {
$num = $this->find_string($key);
if ($num == -1) {
return ($number != 1) ? $plural : $single;
} else {
$result = $this->get_translation_string($num);
$list = explode(chr(0), $result);
return $list[$select];
}
}
}
function pgettext($context, $msgid) {
$key = $context . chr(4) . $msgid;
$ret = $this->translate($key);
if (strpos($ret, "\004") !== FALSE) {
return $msgid;
} else {
return $ret;
}
}
function npgettext($context, $singular, $plural, $number) {
$key = $context . chr(4) . $singular;
$ret = $this->ngettext($key, $plural, $number);
if (strpos($ret, "\004") !== FALSE) {
return $singular;
} else {
return $ret;
}
}
public function npgettext($context, $singular, $plural, $number)
{
$key = $context.chr(4).$singular;
$ret = $this->ngettext($key, $plural, $number);
if (strpos($ret, "\004") !== false) {
return $singular;
} else {
return $ret;
}
}
}
?>

View File

@@ -1,167 +1,182 @@
<?php
/*
Copyright (c) 2003, 2005, 2006, 2009 Danilo Segan <danilo@kvota.net>.
Copyright (c) 2003, 2005, 2006, 2009 Danilo Segan <danilo@kvota.net>.
This file is part of PHP-gettext.
This file is part of PHP-gettext.
PHP-gettext is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
PHP-gettext is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
PHP-gettext is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with PHP-gettext; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
PHP-gettext is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with PHP-gettext; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// Simple class to wrap file streams, string streams, etc.
// seek is essential, and it should be byte stream
class StreamReader {
// should return a string [FIXME: perhaps return array of bytes?]
function read($bytes) {
return false;
}
class StreamReader
{
// should return a string [FIXME: perhaps return array of bytes?]
public function read($bytes)
{
return false;
}
// should return new position
function seekto($position) {
return false;
}
// should return new position
public function seekto($position)
{
return false;
}
// returns current position
function currentpos() {
return false;
}
// returns current position
public function currentpos()
{
return false;
}
// returns length of entire stream (limit for seekto()s)
function length() {
return false;
}
};
// returns length of entire stream (limit for seekto()s)
public function length()
{
return false;
}
}
class StringReader {
var $_pos;
var $_str;
class StringReader
{
public $_pos;
public $_str;
function __construct($str='') {
$this->_str = $str;
$this->_pos = 0;
}
public function __construct($str = '')
{
$this->_str = $str;
$this->_pos = 0;
}
function read($bytes) {
$data = substr($this->_str, $this->_pos, $bytes);
$this->_pos += $bytes;
if (strlen($this->_str)<$this->_pos)
$this->_pos = strlen($this->_str);
public function read($bytes)
{
$data = substr($this->_str, $this->_pos, $bytes);
$this->_pos += $bytes;
if (strlen($this->_str)<$this->_pos) {
$this->_pos = strlen($this->_str);
}
return $data;
}
return $data;
}
function seekto($pos) {
$this->_pos = $pos;
if (strlen($this->_str)<$this->_pos)
$this->_pos = strlen($this->_str);
return $this->_pos;
}
public function seekto($pos)
{
$this->_pos = $pos;
if (strlen($this->_str)<$this->_pos) {
$this->_pos = strlen($this->_str);
}
return $this->_pos;
}
function currentpos() {
return $this->_pos;
}
public function currentpos()
{
return $this->_pos;
}
function length() {
return strlen($this->_str);
}
};
public function length()
{
return strlen($this->_str);
}
}
class FileReader {
var $_pos;
var $_fd;
var $_length;
class FileReader
{
public $_pos;
public $_fd;
public $_length;
function __construct($filename) {
if (file_exists($filename)) {
public function __construct($filename)
{
if (file_exists($filename)) {
$this->_length=filesize($filename);
$this->_pos = 0;
$this->_fd = fopen($filename, 'rb');
if (!$this->_fd) {
$this->error = 3; // Cannot read file, probably permissions
return false;
}
} else {
$this->error = 2; // File doesn't exist
return false;
}
}
$this->_length=filesize($filename);
$this->_pos = 0;
$this->_fd = fopen($filename,'rb');
if (!$this->_fd) {
$this->error = 3; // Cannot read file, probably permissions
return false;
}
} else {
$this->error = 2; // File doesn't exist
return false;
}
}
public function read($bytes)
{
if ($bytes) {
fseek($this->_fd, $this->_pos);
function read($bytes) {
if ($bytes) {
fseek($this->_fd, $this->_pos);
// PHP 5.1.1 does not read more than 8192 bytes in one fread()
// the discussions at PHP Bugs suggest it's the intended behaviour
$data = '';
while ($bytes > 0) {
$chunk = fread($this->_fd, $bytes);
$data .= $chunk;
$bytes -= strlen($chunk);
}
$this->_pos = ftell($this->_fd);
// PHP 5.1.1 does not read more than 8192 bytes in one fread()
// the discussions at PHP Bugs suggest it's the intended behaviour
$data = '';
while ($bytes > 0) {
$chunk = fread($this->_fd, $bytes);
$data .= $chunk;
$bytes -= strlen($chunk);
}
$this->_pos = ftell($this->_fd);
return $data;
} else {
return '';
}
}
return $data;
} else return '';
}
public function seekto($pos)
{
fseek($this->_fd, $pos);
$this->_pos = ftell($this->_fd);
return $this->_pos;
}
function seekto($pos) {
fseek($this->_fd, $pos);
$this->_pos = ftell($this->_fd);
return $this->_pos;
}
public function currentpos()
{
return $this->_pos;
}
function currentpos() {
return $this->_pos;
}
public function length()
{
return $this->_length;
}
function length() {
return $this->_length;
}
function close() {
fclose($this->_fd);
}
};
public function close()
{
fclose($this->_fd);
}
}
// Preloads entire file in memory first, then creates a StringReader
// over it (it assumes knowledge of StringReader internals)
class CachedFileReader extends StringReader {
function __construct($filename) {
if (file_exists($filename)) {
class CachedFileReader extends StringReader
{
public function __construct($filename)
{
if (file_exists($filename)) {
$length=filesize($filename);
$fd = fopen($filename, 'rb');
$length=filesize($filename);
$fd = fopen($filename,'rb');
if (!$fd) {
$this->error = 3; // Cannot read file, probably permissions
return false;
}
$this->_str = fread($fd, $length);
fclose($fd);
} else {
$this->error = 2; // File doesn't exist
return false;
}
}
};
?>
if (!$fd) {
$this->error = 3; // Cannot read file, probably permissions
return false;
}
$this->_str = fread($fd, $length);
fclose($fd);
} else {
$this->error = 2; // File doesn't exist
return false;
}
}
}