border: solid 1px red;
*/
.sel:before { content: ">"; }
+
+div.db.menu label {
+ margin-right: 0.1em;
+}
+div.db.menu label:after {
+ content: ": ";
+}
+
.db.menu {
float: left;
+ margin-right: 1em;
+}
+ul.db.menu {
/*
margin: -4em 0.4em 0 -7em;
*/
- margin-right: 1em;
max-width: 7em;
}
td.phone {
white-space: nowrap;
}
+
+.button {
+ display: inline-block;
+ text-decoration: none;
+ font-size: 13px;
+ line-height: 26px;
+ height: 28px;
+ margin: 0;
+ padding: 0 10px 1px;
+ cursor: pointer;
+ border-width: 1px;
+ border-style: solid;
+ -webkit-appearance: none;
+ -webkit-border-radius: 3px;
+ border-radius: 3px;
+ white-space: nowrap;
+ -webkit-box-sizing: border-box;
+ -moz-box-sizing: border-box;
+ box-sizing: border-box;
+}
*****************************************************************************/
require_once(dirname(__FILE__).'/functions.php');
+if (!defined('DB_HTML_EDIT')) define('DB_HTML_EDIT','Edit');
if (!defined('DEBUG')) define('DEBUG',0);
if (!function_exists('err')) {
$r = '';
+ $r .= '<div class="db menu center">'.PHP_EOL;
+ $r .= '<label>Tables</label>'
+ .'<select class="tables" onchange="if (this.value) location.href = \'?table=\'+this.value;">'
+ ;
+
+ foreach ($this->tables() as $table) {
+ #$count = $table->rowCount();
+ $r .= '<option value="'.$table.'"';
+ #$pretty = prettyText($table);
+ $r .= $table == @$_REQUEST['table'] ? ' selected="selected"' : '';
+ $r .= ">$table</option>".PHP_EOL;
+ }
+
+ $r .= '</select>'.PHP_EOL;
+
+ $r .= '</div>'.PHP_EOL;
+
+ return $r;
+
$r .= '<ul class="db menu">'.PHP_EOL;
$r .= '<li class="tables">Tables';
$r .= '<ul>'.PHP_EOL;
$this->fields[$row['name']]['type'] = $row['type'];
- if (array_key_exists('notnull',$row)) {
+ if (isset($row['notnull'])) {
$this->fields[$row['name']]['null'] = $row['notnull'] == '0' ? 1 : 0;
} else {
}
foreach (array('dflt_value') as $f) {
- if (!array_key_exists($f,$row)) continue;
+ if (!isset($row[$f])) continue;
$this->fields[$row['name']]['default'] = $row[$f];
}
foreach (array('pk','Key') as $f) {
- if (!array_key_exists($f,$row)) continue;
+ if (!isset($row[$f])) continue;
$this->fields[$row['name']]['key'] = preg_match('/^1|yes|t/i',$row[$f]) ? 1 : 0;
}
function debug($msg,$level=0) {
if ($level and $level>DEBUG) return;
-
$msg = is_scalar($msg) ? $msg : print_r($msg,true);
- if (@$GLOBALS['PAGE']['is_text']) {
- echo "DEBUG: $msg\n";
+
+ if (!@$GLOBALS['PAGE']['is_text']) {
+ echo '<pre class="debug">'
+ .(@$_SERVER['HTTP_HOST'] ? htmlentities($msg) : $msg)
+ .'</pre>'.PHP_EOL;
return;
}
- echo '<pre class="debug">'
- .(@$_SERVER['HTTP_HOST'] ? htmlentities($msg) : $msg)
- .'</pre>'.PHP_EOL;
+ echo "DEBUG: $msg\n";
}
}
#debug($this->url_edit($row));
- if ($format == 'table') array_unshift($row,'<a href="'.$this->url_edit($row,'&').'">EDIT</a>');
+ if ($format == 'table') array_unshift($row,'<a class="edit button" href="'.$this->url_edit($row,'&').'">'.DB_HTML_EDIT.'</a>');
echo $this->{"rows_rec_$format"}($row);
}
$html = '<table class="'.$this->name.' rows border">'.PHP_EOL;
$html .= '<tr class="'.$this->name.' row bold">';
- $html .= '<th class="EDIT"></th>';
+ $html .= '<th class="'.DB_HTML_EDIT.'"></th>';
foreach (array_keys($this->fields()) as $f) {
$html .= '<th class="'.$f.'">'.$this->url_sort($f).'</th>';
}
<?php
-@define('DEBUG',(int)$_REQUEST['debug']);
+if (!defined('DEBUG')) define('DEBUG',(int)$_REQUEST['debug']);
ini_set('include_path', realpath(dirname(__FILE__)).':'.ini_get('include_path'));
require_once((dirname(__FILE__).'/functions.php'));
<?php
-@define('DEBUG',(int)$_REQUEST['debug']);
-require_once((dirname(__FILE__).'/default.php'));
-require_once(dirname(__FILE__).'/parsedown/Parsedown.php');
+/*
+Vim:
+
+s/array_key_exists(\([^,]\+\),\([^)]\+\))/isset(\2[\1])/g
+
+s/^define(\([^,]\+\)/if (!defined(\1)) define(\1/
+
+*/
+if (!defined('DEBUG')) define('DEBUG',(int)@$_REQUEST['debug']);
+// NB 28.06.15 require_once((dirname(__FILE__).'/default.php'));
function file_write($file,$data,$mode='w') {
}
function txt2md($txt) {
- static $MD = null;
- if ($MD === null) $MD = new Parsedown();
+ global $_txt2md;
+ if ($_txt2md === null) {
+ require_once(dirname(__FILE__).'/parsedown/Parsedown.php');
+ $_txt2md = new Parsedown();
+ }
+ return $_txt2md->text($txt);
+}
+
+function benchmark($function=null,$limit=1000000) {
+ global $_benchmark;
+
+ if ($_benchmark === null) {
+ $_benchmark = array('.' => microtime(true));
+ }
- return $MD->text($txt);
+ if ($function === null) {
+ $prev = $_benchmark['.'];
+ foreach ($_benchmark as $lib => $sec) {
+ if ($lib === '.') continue;
+ printf("%-30s %s\n",$lib,($sec-$prev));
+ $prev = $sec;
+ }
+ return;
+ }
+
+ for ($i=0; $i<$limit; $i++) {
+ $function();
+ }
+
+ $_benchmark[$function] = microtime(true);
}
function bye($msg='') {
function err($msg) {
$msg = is_scalar($msg) ? $msg : print_r($msg,true);
- echo( @$GLOBALS['PAGE']['is_text'] ? "ERR: $msg" : '<pre class="err">'.$msg.'</pre>').PHP_EOL;
+ echo( !@$GLOBALS['PAGE']['is_text'] ? '<pre class="err">'.$msg.'</pre>' : "ERR: $msg").PHP_EOL;
}
function debug($msg,$level=0) {
if ($level and $level>DEBUG) return;
$msg = is_scalar($msg) ? $msg : print_r($msg,true);
- if (@$GLOBALS['PAGE']['is_text']) {
+ if (!@$GLOBALS['PAGE']['is_text']) {
+ echo '<pre class="debug">'
+ .(@$_SERVER['HTTP_HOST'] ? htmlentities($msg) : $msg)
+ .'</pre>'.PHP_EOL;
+ } else {
echo "DEBUG: $msg\n";
- return;
}
- echo '<pre class="debug">'
- .(@$_SERVER['HTTP_HOST'] ? htmlentities($msg) : $msg)
- .'</pre>'.PHP_EOL;
}
<?php
+/*
if (
!@$_SERVER['DOCUMENT_ROOT'] and (realpath($argv[0]) == __FILE__)
) {
),
));
}
+*/
class Page {
}
// Defaults
- if ( ! array_key_exists('title',$opt) )
+ if ( ! isset($opt['title']) )
#$this->title = $GLOBALS['argv'][0]
$this->title = $this->filename2title($_SERVER['SCRIPT_NAME']);
#$this->title = preg_replace('@^.*?([^/\.]+)[^/]*@','\1',$_SERVER['SCRIPT_NAME']);