}
class db {
+
var $tables = array();
var $conn;
var $type;
}
function initParams($tables=null) {
+
if (empty($_REQUEST)) $_REQUEST = array();
if ($tables === null) $tables = $this->tables();
@$GLOBALS['PAGE']['js_code'] = 'var sem_ui_tables = ['.join(',',ar_map('str_quote($a)',$tables)).']; var sem_ui_table = '.str_quote(@$_REQUEST['table']).';';
+ }
+
+ function html_menu() {
+
+ $r = '';
+
+ $r .= '<ul class="db menu">'.PHP_EOL;
+ $r .= '<li class="tables">Tables';
+ $r .= '<ul>'.PHP_EOL;
+
+ foreach ($this->tables() as $table) {
+ #$count = $table->rowCount();
+ $r .= '<li class="'.$table.'">';
+ #$pretty = prettyText($table);
+ $r .= $table == @$_REQUEST['table'] ? "<span class=\"sel\">$table</span>" : '<a href="?table='.$table.'">'.$table."</a>";
+ $r .= '</li>'.PHP_EOL;
}
+
+ $r .= '</ul>'.PHP_EOL;
+ $r .= '</li>'.PHP_EOL;
+
+ $r .= '</ul>'.PHP_EOL;
+
+ return $r;
+
}
+}
+
class table {
var $name;
return $this->fields;
}
- function url_edit($values=null) {
+ function url_edit($values=null,$sep='&') {
if ($values === null) $values = $_REQUEST;
$url_edit = array();
$url_edit[] = $name . '=' .urlencode($values[$name]);
}
- return $url_edit ? 'edit/?table='.$_REQUEST['table'].'&'.join('&',$url_edit) : '';
+ return $url_edit ? 'edit/?table='.$_REQUEST['table'].$sep.join($sep,$url_edit) : '';
}
}
- function edit($values = null) {
+ function html_edit($values = null) {
if ($values === null) $values = $_REQUEST;
if (!is_array($values)) $values = array($values);
$st = $this->db->conn->prepare($sql);
$st->execute();
+ echo '<form class="db edit" method="post">'.PHP_EOL;
$count = 0;
if ($row = $st->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT)) {
$count ++;
}
echo ''
- .'<div class="buttons">'
- .'<input type="submit" />'
+ .'<div class="db buttons">'
+ .'<input type="submit" name="update"/>'
+ .'<input type="text" name="table" value="'.$_REQUEST['table'].'"/>'
.'<input type="reset" />'
.($_SERVER['HTTP_REFERER'] ? '<input type="button" onclick="document.location=document.referrer" value="Cancel" />' : '')
- .'</div>'
- .PHP_EOL;
+ .'</div>'.PHP_EOL
+ .'</form>'.PHP_EOL;
$this->row = $row;
return $this;
}
#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 href="'.$this->url_edit($row,'&').'">EDIT</a>');
echo $this->{"rows_rec_$format"}($row);
}
}
}
+
+return;
?>
<?php
-ini_set('include_path', realpath(dirname(__FILE__)).':'.ini_get('include_path'));
@define('DEBUG',(int)$_REQUEST['debug']);
-require_once((dirname(__FILE__).'/page.php'));
-
-
-function file_write($file,$data,$mode='w') {
-
- if (!$ftmp = fopen($file,$mode)) {
- if (DEBUG) warn("file_write(): Cant open $file in mode $mode");
- return;
- }
-
- if (fwrite($ftmp,$data) === FALSE) {
- if (DEBUG) warn("file_write(): Cant write $file in mode $mode");
- return;
- }
-
- fclose($ftmp);
- return 1;
-
-}
-
-function ls_dir($path,$recurse=false,$exp='') {
-
- $ls = array();
- $rep = opendir($path);
- #die(">>>".$exp);
-
- while($file = readdir($rep)) {
-
- if ($file == '.' or $file == '..') continue;
-
- if (!$exp or preg_match('#\.('.$exp.')$#',$file)) {
- $ls[] = $file;
- }
-
- if ($recurse and is_dir("$path/$file")) {
-#print ">>>$path/$file\n";
-
- foreach (ls_dir("$path/$file",$recurse,$exp) as $l) {
-#print ">>>$path/$file << $l\n";
- $ls[] = "$file/$l";
- }
-
- }
-
- #echo "<div>$file</div>\n";
-
- }
-
- closedir($rep);
-
-#print ">>>$path: ".print_r($ls,true)."\n";
- return $ls;
-
-}
-
-function ar_map($return,$array,$as_hash=false) {
- $map = array_map(create_function('$a',"return($return);"),$array);
- if ($as_hash) {
- $new = array();
- foreach ($map as $k => $v) {
- foreach ($v as $kk => $vv) {
- $new[$kk] = $vv;
- }
- }
- $map = $new;
- }
- return $map;
-}
+ini_set('include_path', realpath(dirname(__FILE__)).':'.ini_get('include_path'));
+require_once((dirname(__FILE__).'/functions.php'));
+require_once((dirname(__FILE__).'/page.php'));
?>
<?php
@define('DEBUG',(int)$_REQUEST['debug']);
-require_once((dirname(__FILE__).'//default.php'));
+require_once((dirname(__FILE__).'/default.php'));
require_once(dirname(__FILE__).'/parsedown/Parsedown.php');
+function file_write($file,$data,$mode='w') {
+
+ if (!$ftmp = fopen($file,$mode)) {
+ if (DEBUG) warn("file_write(): Cant open $file in mode $mode");
+ return;
+ }
+
+ if (fwrite($ftmp,$data) === FALSE) {
+ if (DEBUG) warn("file_write(): Cant write $file in mode $mode");
+ return;
+ }
+
+ fclose($ftmp);
+ return 1;
+
+}
+
+function ls_dir($path,$recurse=false,$exp='') {
+
+ $ls = array();
+ $rep = opendir($path);
+ #die(">>>".$exp);
+
+ while($file = readdir($rep)) {
+
+ if ($file == '.' or $file == '..') continue;
+
+ if (!$exp or preg_match('#\.('.$exp.')$#',$file)) {
+ $ls[] = $file;
+ }
+
+ if ($recurse and is_dir("$path/$file")) {
+#print ">>>$path/$file\n";
+
+ foreach (ls_dir("$path/$file",$recurse,$exp) as $l) {
+#print ">>>$path/$file << $l\n";
+ $ls[] = "$file/$l";
+ }
+
+ }
+
+ #echo "<div>$file</div>\n";
+
+ }
+
+ closedir($rep);
+
+#print ">>>$path: ".print_r($ls,true)."\n";
+ return $ls;
+
+}
+
+function ar_map($return,$array,$as_hash=false) {
+ $map = array_map(create_function('$a',"return($return);"),$array);
+
+ if ($as_hash) {
+
+ $new = array();
+
+ foreach ($map as $k => $v) {
+ foreach ($v as $kk => $vv) {
+ $new[$kk] = $vv;
+ }
+ }
+
+ $map = $new;
+
+ }
+
+ return $map;
+}
+
function txt2md($txt) {
static $MD = null;
if ($MD === null) $MD = new Parsedown();
}
function prettyText($text) {
- $text = str_replace('_',' ',$text);
- return ucwords(preg_replace('/\W+/',' ',$text));
+ return ucwords(
+ preg_replace('/\W+/',' ',
+ str_replace('_',' ',$text)
+ )
+ );
}
function rtf2txt($rtf) {
return mb_strtoupper(mb_substr($str,0,1)).mb_strtolower(mb_substr($str,1,mb_strlen($str)));
}
- function ar_map($return,$array) {
- return array_map(create_function('$a',"return($return);"),$array);
- }
-
function js_quote($str) {
return "'".str_replace("'","\'",$str)."'";
}
$html = array(
sprintf('%c[1;',27) => sprintf('<bold>%c[0;',27),
- 'black' => 30,
- 'red' => 31,
- 'green' => 32,
- 'yellow' => 33,
- 'blue' => 34,
- 'magenta' => 35,
- 'cyan' => 36,
- 'white' => 37,
- 'default' => 39,
+ 'black' => 30,
+ 'red' => 31,
+ 'green' => 32,
+ 'yellow' => 33,
+ 'blue' => 34,
+ 'magenta' => 35,
+ 'cyan' => 36,
+ 'white' => 37,
+ 'default' => 39,
sprintf('%c[0;30m',27) => '<span style="color:black">',
sprintf('%c[0;31m',27) => '<span style="color:red">',
sprintf('%c[0;32m',27) => '<span style="color:green">',
if ($is == 'xhtml') return preg_match('/xhtml$/',$this->content_type);
if ($is == 'html') return preg_match('/html$/',$this->content_type);
if ($is == 'xml') return preg_match('/xml$/',$this->content_type);
- die("Db->is(): unknow value '$is'");
+ die("Db->is(): unknow argument '$is'. Accepted values are xhtml, html, xml");
}
-}
-return;
+
+} return;
?>