DIR : /home/kozerus/public_html/ko_center/js/jqgrid_demo35/grid.php
/home/kozerus/public_html/ko_center/js/jqgrid_demo35
<?php
startup();
function startup() {
session_start();
$dttm=date("Ymd_His");
$query_string_all=$_SERVER['QUERY_STRING'];
$query_strings = split( "&", $query_string_all );
$query_string = $query_strings[0];
$php_self=$_SERVER['PHP_SELF'];
$http_host=$_SERVER['HTTP_HOST'];
$request_uri=$_SERVER['REQUEST_URI'];
$script_filename = $_SERVER['SCRIPT_FILENAME'];
$script_basename = basename( $script_filename );
$dbfile = str_replace( "php", "db3", $script_filename );
$drvltr="C";
if( is_dir( "L:/xampp/htdocs" )) { $drvltr="L"; }
if( is_dir( "N:/xampp/htdocs" )) { $drvltr="N"; }
// print( "drvltr=$drvltr<br>\n" );
$roles = array( 'admin', 'adminlocal', 'op', 'mgrs', 'users', 'public' );
$role=$_SESSION['role'];
$dbfile="grid.db3";
$GLOBALS['dbfile'] = $dbfile;
$args=split( "/", $query_string );
$options=split( "/", $query_string );
$option=$args[0]; $option1=$args[1]; $option2=$args[2]; $option3=$args[3]; $option4=$args[4];
$dt=date("Y-m-d H:i:s");
// phpinfo();
// print_r( $options );
// return;
$sql = "";
$table = "test";
if( $options[0] == "create" ) { pdo_create($dbfile, $sql ); return; }
if( $options[0] == "insert" ) { pdo_insert($dbfile, $sql ); return; }
if( $options[0] == "delete" ) { pdo_delete($dbfile, $sql ); return; }
if( $options[0] == "update" ) { pdo_update( $options ); return; }
if( $options[0] == "select" ) { pdo_select($dbfile, $sql ); return; }
if( $options[0] == "count" ) {
$table = "test";
if( $options[1] != "" ) { $table = $options[1]; }
$my_count = pdo_count($dbfile, $table );
print( "grid MSG: table=$table count=$my_count<br>\n" );
return;
}
if( $options[0] == "gridxml" ) { pdo_gridxml($options); return; }
htmlpage($options);
}
function htmlpage( $options ) {
$php_self=$_SERVER['PHP_SELF'];
$http_host=$_SERVER['HTTP_HOST'];
$dttm=date("Ymd_His");
$output = "<html><title>$php_self $dttm</title>\n";
$output .= "<body bgcolor=lightblue>\n";
$output .= "<hr>\n";
$option_list = array( 'count', 'create', 'insert', 'select', 'update', 'delete', 'gridxml' );
foreach( $option_list as $option ) {
$output .= "<a href=\"http://$http_host$php_self?$option\">$option</a><br>\n";
}
$output .= "<hr>\n";
$output .= "</body>\n";
$output .= "</html>\n";
print( $output );
}
function pdo_create( $dbfile, $sql ) {
if( $sql == "" ) {
$sql = "create table if not exists 'test' (\n";
$sql .= " test_id INT not null,\n";
$sql .= " c1 text,\n";
$sql .= " c2 text,\n";
$sql .= " c3 text,\n";
$sql .= " PRIMARY KEY( test_id ) \n";
$sql .= " );\n";
}
print( "pdo_insert MSG: dbfile=$dbfile sql=[$sql]<br>\n" );
$pdo = newpdo( $dbfile );
$pdo->exec( $sql );
$pdo = null;
return;
}
function pdo_insert( $dbfile, $sql ) {
if( $sql == "" ) {
$sql= "insert or replace into test ('c1', 'c2', 'c3' ) values ( 'v11', 'vl2', 'vl3' );";
}
$pdo = newpdo( $dbfile );
for( $row=1; $row<10; $row++ ) {
$sql = "insert or replace into test ( 'test_id', 'c1', 'c2', 'c3' ) ";
$sql .= "values ( '$row', 'v1$row', 'v2$row', 'v3$row' );";
print( "pdo_insert MSG: dbfile=$dbfile sql=[$sql]<br>\n" );
$pdo->exec( $sql );
}
$pdo = null;
}
function pdo_update( $options ) {
$dbfile=$options[1];
$table=$options[2];
if( $sql == "" ) {
$sql= "update test set c1='v111', c2='v112', c3='v113' where rowid = 1;";
}
print( "pdo_update MSG: dbfile=$dbfile sql=[$sql]<br>\n" );
$pdo = newpdo( $dbfile );
$pdo->exec( $sql );
$pdo = null;
}
function pdo_delete( $dbfile, $sql ) {
if( $sql == "" ) {
$sql= "delete from test where rowid='1';";
}
print( "pdo_delete MSG: dbfile=$dbfile sql=[$sql]<br>\n" );
$pdo = newpdo( $dbfile );
$pdo->exec( $sql );
$pdo = null;
}
function pdo_count( $dbfile, $table ) {
if( $table == "" ) { $table = "test"; }
$count=0;
$pdo = newpdo($dbfile);
$sqlcnt = "select count(*) pagetotal from $table";
$sqlout = $pdo->query($sqlcnt);
$record = $sqlout->fetchall();
if(sizeof($record) != 0) {
// print( "sizeof record != 0 $record<br>\n" );
$count=$record[0][0];
}
return( $count );
}
function pdo_select( $dbfile, $sql ) {
if( $sql == "" ) {
$sql= "select * from test;";
}
$table="test";
$pdo = newpdo($dbfile);
$sqlcnt = "select count(*) pagetotal from test";
$sqlout = $pdo->query($sqlcnt);
$record = $sqlout->fetchall();
$count=0;
$total_pages = 0;
$limit=10;
$page=1;
$sidx=1;
$count = pdo_count( $dbfile, $table );
if( $count > 0 ) {
$total_pages = ceil($count/$limit);
}
else {
}
if( $page > $total_pages) $page=$total_pages;
$start = $limit*$page - $limit; // do not put $limit*($page - 1)
$xml = "";
$xml ="<rows>\n";
$xml .= "<page>$page</page>\n";
$xml .= "<total>$total_pages</total>\n";
$xml .= "<records>$count</records>\n";
$xml .= "<limit>$limit</limit>\n";
$xml .= "<sidx>$sidx</sidx>\n";
$pdo = newpdo( $dbfile );
$result = $pdo->query($sql);
$collim = $result->columnCount();
$rowid = 1;
$output = "";
$htm = "";
$htm .= "<html>\n";
$htm .= "<title>grid search</title>\n";
$htm .= "<body bgcolor=\"lightblue\">\n";
$htm .= "pdo_select MSG: dbfile=$dbfile sql=[$sql]<br>\n";
$htm .= "<div id=\"select\">";
$htm .= "<table>\n";
$php_self=$_SERVER['PHP_SELF'];
$http_host=$_SERVER['HTTP_HOST'];
while($row = $result->fetch(PDO::FETCH_ASSOC)) {
$xml .= "<row id='". $rowid . "'>\n";
if( $rowid == 1 ) {
$htm .= "<tr>\n";
foreach( $row as $col => $val ) {
$htm .= "<td>".$col."</td>\n";
}
$htm .= "</tr>\n";
}
$htm .= "<tr>\n";
$colnum=0;
foreach( $row as $col => $val ) {
$htm .= "<td>". htmlentities($val). "</td>\n";
if( $colnum == 0 ) {
// $xml .= "<cell>". htmlentities($val). "</cell>\n";
/// $xml .= "<cell><![CDATA[";
/// $xml .= "<a href=\"http://$http_host$php_self?test/$val/$col\">". $val. "</a>";
/// $xml .= "]]></cell>\n";
$xml .= "<cell><![CDATA[". $val ."]]></cell>\n";
}
else {
$xml .= "<cell>". htmlentities($val). "</cell>\n";
}
$colnum++;
}
$xml .= "</row>\n";
$htm .= "</tr>\n";
$rowid++;
}
$xml .= "</rows>\n";
$htm .= "</table>\n";
$htm .= "</div>\n";
$htm .= "</body>\n";
$htm .= "</html>\n";
$pdo = null;
// print( "$htm" );
if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) {
header("Content-type: application/xhtml+xml;charset=utf-8");
}
else {
header("Content-type: text/xml;charset=utf-8");
}
$et = ">";
print( "<?xml version='1.0' encoding='utf-8'?$et\n" );
print( "$xml" );
}
function pdo_gridxml($options) {
$page=1;
$records=1;
$url_dbcode=$options[1];
$url_table=$options[2];
// $url_dbcode="jqgrid.db3";
// $url_table="test";
if( $options[1] != "" ) { $url_dbcode=$options[1]; }
if( $options[2] != "" ) { $url_table=$options[2]; }
if( $options[4] != "" ) { $total_pages=$options[4]; }
if( $options[5] != "" ) { $page=$options[5]; }
if( $options[6] != "" ) { $count=$options[6]; }
$dbfile="$url_dbcode.db3";
$page = $_GET['page']; // requested page
$limit = $_GET['rows']; //rows in grid
$sidx = $_GET['sidx']; // index row ie user click sort
$sord = $_GET['sord']; // sort direction
if(!$page) $page =1;
if(!$sidx) $sidx =1;
if(!$sord) $sord ="asc";
if(!$limit) $limit=20;
$count = pdo_count( $dbfile, $url_table );
// $pdo = newpdo($dbfile);
// $sql = "select count(*) pagetotal from $url_table";
// $sqlout = $pdo->query($sql);
// $record = $sqlout->fetchall();
/// if(sizeof($record) != 0) {
// print( "sizeof record != 0 $record<br>\n" );
// $count=$record[0][0];
// }
// else {
// $count=0;
// }
if( $count > 0 ) {
$total_pages = ceil($count/$limit);
}
else {
$total_pages = 0;
}
if( $page > $total_pages) $page=$total_pages;
$start = $limit*$page - $limit; // do not put $limit*($page - 1)
$xml ="<rows>\n";
$xml .= "<page>$page</page>\n";
$xml .= "<total>$total_pages</total>\n";
$xml .= "<records>$count</records>\n";
$xml .= "<limit>$limit</limit>\n";
$xml .= "<sidx>$sidx</sidx>\n";
$sql = "select * from $url_table ORDER BY $sidx $sord LIMIT $start, $limit";
// be sure to put text data in CDATA
// print( "BUGS_317 page=$page total_pages=$total_pages count=$count limit=$limit sidx=$sidx<br>\n" );
// print( "BUGS_318 dbfile=$dbfile url_table=$url_table<br>\n" );
// print( "BUGS_318 sql=[$sql]<br>\n" );
// return;
$pdo = newpdo($dbfile);
$result = $pdo->query($sql);
$collim = $result->columnCount();
$rowid = 1;
$output = "";
$http_host=$_SERVER['HTTP_HOST'];
while($row = $result->fetch(PDO::FETCH_ASSOC)) {
$xml .= "<row id='". $rowid . "'>\n";
foreach( $row as $col => $val ) {
$xml .= "<cell>". htmlentities($val). "</cell>\n";
// $xml .= "<cell><![CDATA[<a href=\"http://$http_host$php_self?test/$val>\"". $val. "</a>]]></cell>\n";
// $xml .= "<cell><![CDATA[". $val ."]]></cell>\n";
}
$xml .= "</row>\n";
$rowid++;
}
$pdo=null;
// $xml .= "<cell><![CDATA[". $row ."]]></cell>\n";
$xml .= "</rows>\n";
$dttm=date("Ymd_His");
// print( "__FUNCTION__=".__FUNCTION__."<br>\n" );
// $content_type = "Content-type: application/csv Content-Disposition: \"inline; filename=$csvfile\"";
if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) {
header("Content-type: application/xhtml+xml;charset=utf-8");
}
else {
header("Content-type: text/xml;charset=utf-8");
}
$et = ">";
print( "<?xml version='1.0' encoding='utf-8'?$et\n" );
// $ifile="jqgrid_demo35.txt";
// if( file_exists( $ifile ) {
// $rownum=0;
// $fp = fopen( $ifile, "r" );
// while(( $filetext = fgets($fp)) !== false ) {
// $filedata[] = $filetext;
// $output .= "pdo_load CSV: rownum=$rownum filedata=[".$filedata[$rownum]. "]<br>\n";
// $rownum++;
// }
// fclose($fp);
// }
$ofile="jqgrid_demo35.tmp";
$fp = fopen( $ofile, "w" );
$tmp = "";
$tmp .= "dbfile=$dbfile\n";
$tmp .= "url_table=$url_table\n";
$tmp .= "page=$page\n";
$tmp .= "total_pages=$total_pages\n";
$tmp .= "count=$count\n";
$tmp .= "limit-$limit\n";
$tmp .= "sidx=$sidx\n";
fwrite( $fp, $tmp );
$j=0;
fwrite( $fp, "post: =======================================\n" );
foreach( $_POST as $request ) {fwrite( $fp, "request-$j $request\n" ); $j++;}
$j=0;
fwrite( $fp, "request: =======================================\n" );
foreach( $_REQUEST as $request ) {fwrite( $fp, "request-$j $request\n" ); $j++;}
$j=0;
fwrite( $fp, "get: =======================================\n" );
foreach( $_GET as $get ) {fwrite( $fp, "get-$j $get\n" ); $j++;}
fwrite( $fp, "session: =======================================\n" );
foreach( $_SESSION as $session ) {fwrite( $fp, "session-$j $session\n" ); $j++;}
fwrite( $fp, $xml );
fclose( $fp );
system( "wi $ofile" );
print( "$xml" );
return;
}
function newpdo( $dbfile ) {
$php_self=$_SERVER['PHP_SELF'];
$http_host=$_SERVER['HTTP_HOST'];
$request_uri=$_SERVER['REQUEST_URI'];
if( ! file_exists( $dbfile )) {
print( "$php_self newpdo ERR: NOT_EXISTS dbfile=[$dbfile]<br>\n" );
if( $GLOBALS['install'] != true ) {
print( "$php_self newpdo ERR: NOT_INSTALL dbfile=[$dbfile]<br>\n" );
return;
}
else {
print( "$php_self newpdo MSG: CREATE dbfile=[$dbfile]<br>\n" );
}
}
try {
$pdo = null;
$pdo = new PDO("sqlite:$dbfile" );
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
// $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
if( $pdo == null ) {
print( "$php_self newpdo ERR: dbfile=[$dbfile]<br>\n" );
return $pdo;
}
return $pdo;
}
catch(PDOException $e ) {
$errmsg = $e->getMessage();
print( "$php_self newpdo ERR: pdo=[$pdo] dbfile=[$dbfile] errmsg=[$errmsg]<br>\n" );
$pdo = null;
return $pdo;
}
}
//
koh5_pano
Drag mouse to navigate.
Navigation
- Left/Right Mouse drag: Changes camera heading.
- Up/Sown Mouse drag: Changes camera pitch.
- Scroll wheel: Changes camera field of view.
- I-Key: Displays Info panel with canvas size, image size and FPS.
17.Aug.2010, Martin Wengenmayer