DIR : /home/kozerus/public_html/go/kogo_20211211_2212.php

/home/kozerus/public_html/go

<?php

# kogo.php 20211211_2211	fmt=json debug 
# kogo.php 20211210_1800 


$progid="kogo.php";
$dttm=date("Ymd_His");


	startup_kogo("");

function startup_kogo($args) {
#	print( "<h1>BUGS_10 startup_kogo args=$args</h1>\n" );

# kogo init
	$db3fil="kogo.db3";
	$tbl="games";
	$kogo="";
	$t=0; $x=0; $y=0; $g=0;
	$bxlim=9; $bylim=9; $bhandi=0;
	$l=0; $d=0;
	$gid=""; $pb="pb"; $pw="pw";
	$moves="";
	$dttm=date('Ymd_His');
	$htmout = "";

	$htmout .= htmout_head("");



	if( ! isset($_REQUEST['kogo'])) {
$game = 'gid|bxlim|bylim|bhandi|t|x|y|g|l|d|pb|pw|lidb|lidw|dttm|status|note
1|1|1
1|1|2
1|1|3
1|2|1
1|2|2
1|2|3
1|3|1
1|3|2
1|3|3
';
		$htmout .= htmout_kogo_form("");
		$htmout .= htmout_kogo_gamedata($game);
		$htmout .= htmout_board($game);
		$htmout .= htmout_stones($game);
		$htmout .= htmout_lids($game);
		$htmout .= "	</body>\n";
		$htmout .= "</html>\n";
		print( $htmout );
		return( $htmout );
		}

# kogo_isset
	$bxlim=9; $bylim=9; $bhandi=9;
	if ( isset($_REQUEST['kogo'] )) {$kogo=$_REQUEST['kogo'];}
	if ( isset($_REQUEST['t'] )) {$t=$_REQUEST['t'];}
	if ( isset($_REQUEST['x'] )) {$x=$_REQUEST['x'];}
	if ( isset($_REQUEST['y'] )) {$y=$_REQUEST['y'];}
	if ( isset($_REQUEST['txy'] )) {
		$txy=$_REQUEST['txy'];
		$t=explode(",",$txy)[0];
		if( count(explode(",",$txy)) > 1 ) {$x=explode(",",$txy)[1]; }
		if( count(explode(",",$txy)) > 2 ) {$y=explode(",",$txt)[2];}
		}

#	if( preg_match("/.,.,.$/",$kogo)) {
	if( count(explode(",",$kogo)) > 1 ) {
		$txy=str_replace("add","",$kogo);
		$t=explode(",",$txy)[0];
		$x=explode(",",$txy)[1];
		$y=explode(",",$txy)[2];
		if( preg_match("/^a/",$t)) {
			$t=explode(",",$txy)[1];
			$x=explode(",",$txy)[2];
			$y=explode(",",$txy)[3];
			}
		$x=explode(",",$txy)[1];
		$y=explode(",",$txy)[2];
		}
#	print( "<h1>MSG_84 kogo=$kogo t=$t x=$x y=$y</h1>\n" );


	if ( isset($_REQUEST['step'] )) {$step=$_REQUEST['step'];}
	if ( isset($_REQUEST['gid'] )) {$gid=$_REQUEST['gid'];}
	if ( isset($_REQUEST['bhid'] )) {$bhid=$_REQUEST['bhid'];}
	if ( isset($_REQUEST['g'] )) {$g=$_REQUEST['g'];}
	if ( isset($_REQUEST['bxlim'] )) {$bxlim=$_REQUEST['bxlim'];}
	if ( isset($_REQUEST['bylim'] )) {$bylim=$_REQUEST['bylim'];}
	if ( isset($_REQUEST['bhandi'] )) {$bhandi=$_REQUEST['bhandi'];}
	if ( isset($_REQUEST['l'] )) {$l=$_REQUEST['l'];}
	if ( isset($_REQUEST['d'] )) {$d=$_REQUEST['d'];}
	if ( isset($_REQUEST['moves'] )) {$moves=$_REQUEST['moves'];}
	if ( isset($_REQUEST['pb'] )) {$kbogo=$_REQUEST['kbogo'];}
	if ( isset($_REQUEST['pw'] )) {$pw=$_REQUEST['pw'];}
	if ( isset($_REQUEST['gid'] )) {$gid=$_REQUEST['gid'];}
	if ( ! isset( $htmout )) { $htmout = ""; }
# kogo_match ========================
	if( preg_match("/new/", $kogo )) {
#		$htmout = "";
		$htmout .= kogo_new($db3fil,$tbl,$kogo,$t,$x,$y,$g,$bxlim,$bylim,$bhandi,$l,$d,$moves,$pb,$pw,$gid);
		$htmout .= "<h3>kogo_new $db3fil,$tbl,$kogo</h3><h2>$t,$x,$y,$g</h2>$bxlim,$bylim,$bhandi</h1>$l,$d,$moves,$pb,$pw,$gid\n";
		print($htmout);
		return($htmout);	
		}
	if( preg_match("/add/", $kogo )) {
#		$htmout="";
		$htmout .= kogo_add($db3fil,$tbl,$kogo,$t,$x,$y,$g,$bxlim,$bylim,$bhandi,$l,$d,$moves,$pb,$pw,$gid);
		$htmout .= "<h3>kogo_add $db3fil,$tbl,$kogo</h3><h2>$t,$x,$y,$g</h2>$bxlim,$bylim,$bhandi,$l,$d,$moves,$pb,$pw,$gid)";
		print($htmout);
		return($htmout);
		}
	if( preg_match("/del/", $kogo )) {
#		$htmout="";
		$htmout .= kogo_del($db3fil,$tbl,$kogo,$t,$x,$y,$g,$bxlim,$bylim,$bhandi,$l,$d,$moves,$pb,$pw,$gid);
		return($htmout);
		}
	if( preg_match("/upd/", $kogo )) {
#		$htmout = "";
		$htmout .= kogo_upd($db3fil,$tbl,$kogo,$t,$x,$y,$g,$bxlim,$bylim,$bhandi,$l,$d,$moves,$pb,$pw,$gid);
		return($htmout);
		}
	if( preg_match("/sel/", $kogo )) {
#		$htmout = "";
		$htmout .= kogo_sel($db3fil,$tbl,$kogo,$t,$x,$y,$g,$bxlim,$bylim,$bhandi,$l,$d,$moves,$pb,$pw,$gid);
		$htmout .= "<h3>kogo_sel$db3fil,$tbl,$kogo</h3><h2>$t,$x,$y,$g</h2>$bxlim,$bylim,$bhandi,$l,$d,$moves,$pb,$pw,$gid\n";
		print($htmout);
		return($htmout);
		}
	}

# kogo ========================
function kogo_new($db3fil,$tbl,$kogo,$t,$x,$y,$g,$bxlim,$bylim,$bhandi,$l,$d,$moves,$pb,$pw,$gid) {
	$htmout=kogo_db3new($db3fil,$tbl,$kogo,$t,$x,$y,$g,$bxlim,$bylim,$bhandi,$l,$d,$moves,$pb,$pw,$gid);
	return($htmout);
	}
function kogo_add($db3fil,$tbl,$kogo,$t,$x,$y,$g,$bxlim,$bylim,$bhandi,$l,$d,$moves,$pb,$pw,$gid) {
	$htmout=kogo_db3add($db3fil,$tbl,$kogo,$t,$x,$y,$g,$bxlim,$bylim,$bhandi,$l,$d,$moves,$pb,$pw,$gid);
	return($htmout);
	}
function kogo_del($db3fil,$tbl,$kogo,$t,$x,$y,$g,$bxlim,$bylim,$bhandi,$l,$d,$moves,$pb,$pw,$gid) {
	$htmout=kogo_db3del($db3fil,$tbl,$kogo,$t,$x,$y,$g,$bxlim,$bylim,$bhandi,$l,$d,$moves,$pb,$pw,$gid);
	return($htmout);
	}
function kogo_upd($db3fil,$tbl,$kogo,$t,$x,$y,$g,$bxlim,$bylim,$bhandi,$l,$d,$moves,$pb,$pw,$gid) {
	$htmout=kogo_db3upd($db3fil,$tbl,$kogo,$t,$x,$y,$g,$bxlim,$bylim,$bhandi,$l,$d,$moves,$pb,$pw,$gid);
	return($htmout);
	}
function kogo_sel($db3fil,$tbl,$kogo,$t,$x,$y,$g,$bxlim,$bylim,$bhandi,$l,$d,$moves,$pb,$pw,$gid) {
	$htmout=kogo_db3sel($db3fil,$tbl,$kogo,$t,$x,$y,$g,$bxlim,$bylim,$bhandi,$l,$d,$moves,$pb,$pw,$gid);
	return($htmout);
	}

# kogo_db3 ========================
function kogo_db3drop($db3fil,$tbl) {
	$htmout = "";
	$sql_drop = "";
	$sql_drop .= "drop table if exists $tbl";
#	$htmout .= "<h1>BUGS_150 DB3DROP db3fil=$db3fil tbl=$tbl sql_drop=$sql_drop</h1>\n";
	$pdo=newpdo($db3fil); 
	if($pdo) { 
		$pdo->exec($sql_drop); 
		$pdo=null;
		}
	return($htmout);
	}

function kogo_db3new($db3fil,$tbl,$kogo,$t,$x,$y,$g,$bxlim,$bylim,$bhandi,$l,$d,$moves,$pb,$pw,$gid) {
	$htmout = "";
	$htmout .= kogo_db3drop($db3fil,$tbl);

	$sql_cr = "";
	$sql_cr .= "create table if not exists $tbl (\n";
	$sql_cr .= "db3fil varchar,";
	$sql_cr .= "tbl varchar,";
	$sql_cr .= "kogo varchar,";
	$sql_cr .= "t varchar,";
	$sql_cr .= "x varchar,";
	$sql_cr .= "y varchar,";
	$sql_cr .= "g varchar,";
	$sql_cr .= "bxlim varchar,";
	$sql_cr .= "bylim varchar,";
	$sql_cr .= "bhandi varchar,";
	$sql_cr .= "l varchar,";
	$sql_cr .= "d varchar,";
	$sql_cr .= "moves varchar,";
	$sql_cr .= "pb varchar,";
	$sql_cr .= "pw varchar,";
	$sql_cr .= "gid varchar,";
	$sql_cr .= "status varchar,";
	$sql_cr .= "dttm varchar,";
	$sql_cr .= "note varchar";
	$sql_cr .= " );\n";
#	print( "<h1>BUGS_140 sql_cr=$sql_cr</h1>\n");

	$pdo=newpdo($db3fil);
	if( $pdo ) {
		$pdo->exec($sql_cr);
		$pdo=null; 
		}
	$htmout .= "<h3>db3new db3fil=$db3fil tbl=$tbl sql_cr=$sql_cr<h3>\n";


	$htmout .= kogo_db3add($db3fil,$tbl,$kogo,$t,$x,$y,$g,$bxlim,$bylim,$bhandi,$l,$d,$moves,$pb,$pw,$gid);
	return($htmout);
	}
function kogo_db3add($db3fil,$tbl,$kogo,$t,$x,$y,$g,$bxlim,$bylim,$bhandi,$l,$d,$moves,$pb,$pw,$gid) {
	$note="note"; $status="";
	$dttm=date('Ymd_His');
	$sql_add = "";
	$sql_add .="insert into $tbl (\n";
	$sql_add .="'db3fil',";
	$sql_add .="'tbl',";
	$sql_add .="'kogo',";
	$sql_add .="'t',";
	$sql_add .="'x',";
	$sql_add .="'y',";
	$sql_add .="'g',";
	$sql_add .="'bxlim',";
	$sql_add .="'bhandi',";
	$sql_add .="'l',";
	$sql_add .="'d',";
	$sql_add .="'moves',";
	$sql_add .="'pb',";
	$sql_add .="'pw',";
	$sql_add .="'gid',";
	$sql_add .="'status',";
	$sql_add .="'dttm',";
	$sql_add .="'note'";
	$sql_add .= " ) values ( \n";
	$sql_add .="'$db3fil',";
	$sql_add .="'$tbl',";
	$sql_add .="'$kogo',";
	$sql_add .="'$t',";
	$sql_add .="'$x',";
	$sql_add .="'$y',";
	$sql_add .="'$g',";
	$sql_add .="'$bxlim',";
	$sql_add .="'$bhandi',";
	$sql_add .="'$l',";
	$sql_add .="'$d',";
	$sql_add .="'$moves',";
	$sql_add .="'$pb',";
	$sql_add .="'$pw',";
	$sql_add .="'$gid',";
	$sql_add .="'$status',";
	$sql_add .="'$dttm',";
	$sql_add .="'$note'";
	$sql_add .= " );\n";
#	print( "<h1>MSG_150 sql_add=$sql_add</h1>\n" );
	$pdo = newpdo($db3fil);
	if( $pdo ) {
		$pdo->exec($sql_add);
		$pdo=null; 
		}
#	print( "<h1>MSG_200 sql_add=$sql_add db3fil=$db3fil tbl=$tbl</h1>\n" );
	$htmout = "";
	$htmout .= "<h3>MSG_250 db3fil=$db3fil tbl=$tbl sql_add=$sql_add</h3>\n";
	return($htmout);
	}

function kogo_db3del($db3fil,$tbl,$kogo,$t,$x,$y,$g,$bxlim,$bylim,$bhandi,$l,$d,$moves,$pb,$pw,$gid) {
	$sql_del="delete from $tbl where t=$t";
	$pdo = newpdo($db3fil);
	$pdo->exec($sql_del);
	$pdo=null; 
	return($sql_del);
	}
function kogo_db3upd($db3fil,$tbl,$kogo,$t,$x,$y,$g,$bxlim,$bylim,$bhandi,$l,$d,$moves,$pb,$pw,$gid) {
	$fld="g"; $val=$g;
	$sql_upd="update $tbl set $fld='$val' where t=$t";
	$pdo = newpdo($db3fil);
	$pdo->exec($sql_upd);
	$pdo=null; 
	return($sql_upd);
	}
function kogo_db3sel($db3fil,$tbl,$kogo,$t,$x,$y,$g,$bxlim,$bylim,$bhandi,$l,$d,$moves,$pb,$pw,$gid) {
#	print( "<h1>BUGS_230 bxlim=$bxlim bylim=$bylim t=$t x=$x y=$y g=$g</h1>\n" );
	$htmout = "";
	$fmt=""; if( isset($_REQUEST['fmt'] )) { $fmt=$_REQUEST['fmt']; }
	if( isset($_REQUEST['db3fil'] )) { $db3fil=$_REQUEST['db3fil']; }
	if( isset($_REQUEST['tbl'] )) { $db3fil=$_REQUEST['tbl']; }
	$psv=""; $csv=""; $json="";  $txt="";
	$sql_sel="select * from $tbl";
#	$htmout .= "<h3>$db3fil $tbl sql_sel=$sql_sel</h3>\n";
	$pdo = newpdo($db3fil);
	$pdo->query($sql_sel);
	$progid="kogo";
	$dttm=date('Ymd_His');


#	$htmout="";
	$htmout .= "<div id=div_db3sel>";
	$htmout .= "<h2>$kogo $dttm $gid $bxlim $bylim $bhandi $pb $pw</h2>";
	$htmout .= "<table id=table_kogo_$gid>";
	$htmout .= "<tr>";
	$htmout .= "<td>db3fil</td>";
	$htmout .= "<td>tbl</td>";
	$htmout .= "<td>t</td>";
	$htmout .= "<td>x</td>";
	$htmout .= "<td>y</td>";
	$htmout .= "<td>g</td>";
	$htmout .= "<td>bxlim</td>";
	$htmout .= "<td>bylim</td>";
	$htmout .= "<td>bhandi</td>";
	$htmout .= "<td>l</td>";
	$htmout .= "<td>d</td>";
	$htmout .= "<td>dttm</td>";
	$htmout .= "<td>status</td>";
	$htmout .= "<td>gid</td>";
	$htmout .= "<td>note</td>";
	$htmout .= "</tr>\n";

	$sql=""; $lidb=""; $lidw="";


	$json = '';
	$json .= '{ "kogo": [';

	$sql=""; $lidb=0; $lidw=0;
	$j=0;
	foreach($pdo->query($sql_sel) as $row ) {
		$j=$j+1;

	$sql=""; $lidb=0; $lidw=0;
		if( $row['db3fil'] ) { $dbfil=$row['db3fil']; }
		if( $row['tbl'] ) { $tbl=$row['tbl']; } 
#		if( $row['sql'] ) { $sql=$row['sql'];}
		if( $row['kogo'] ) { $kogo=$row['kogo']; }
		if( $row['t'] ) { $t=$row['kogo']; }
		if( $row['x'] ) { $x=$row['x'];}
		if( $row['y'] ) { $y=$row['y'];}
		if( $row['g'] ) { $g=$row['g'];}
		if( $row['bxlim'] ) { $bxlim=$row['bxlim'];}
		if( $row['bylim'] ) { $bylim=$row['bylim'];}
#		print_r($row);
#		print( "<h1>BUGS_290 bxlim=$bxlim bylim=$bylim</h1>\n" );
		if( $row['bhandi'] ) { $bhandi=$row['bhandi'];}
		if( $row['l'] ) { $l=$row['l'];}
		if( $row['d'] ) { $d=$row['d'];}
#		if( $row['lidb'] ) { $lidb=$row['lidb'];}
#		if( $row['lidw'] ) { $lidw=$row['lidw'];}
		if( $row['moves'] ) { $moves=$row['moves'];}
	
		if( $row['pb'] ) { $pb=$row['pb'];}
		if( $row['pb'] ) { $pb=$row['pb'];}
		if( $row['pw'] ) { $pw=$row['pw'];}
		if( $row['gid'] ) { $gid=$row['gid'];}
		if( $row['status'] ) { $status=$row['status'];} else { $status=""; }
		if( $row['dttm'] ) { $dttm=$row['dttm'];}
		if( $row['note'] ) { $note=$row['note'];}


		$json .= "{";
		$json .= '"db3fil":"$db3fil",';
		$json .= '"tbl":"$tbl",';
		$json .= '"sql":"$sql",';
		$json .= '"t":"$t",';
		$json .= '"x":"$x",';
		$json .= '"y":"$y",';
		$json .= '"bxlim":"$bxlim",';
		$json .= '"bylim":"$bylim",';
		$json .= '"bhandi":"$bhandi",';
		$json .= '"g":"$g",';
		$json .= '"l":"$l",';
		$json .= '"d":"$d",';
		$json .= '"lidb":"$lidb",';
		$json .= '"lidw":"$lidw",';
		$json .= '"pb":"$pb",';
		$json .= '"pw":"$pw",';
		$json .= '"gid":"$gid",';
		$json .= '"status":"$status",';
		$json .= '"dttm":"$dttm",';
		$json .= '"note":"$note"';
		$json .= '	},';

		$psv .= "$db3fil|";
		$psv .= "$tbl|";
		$psv .= "$t|";
		$psv .= "$x|";
		$psv .= "$y|";
		$psv .= "$g|";
		$psv .= "$bxlim|";
		$psv .= "$bylim|";
		$psv .= "$bhandi|";
		$psv .= "$l|";
		$psv .= "$d|";
		$psv .= "$dttm|";
		$psv .= "$status|";
		$psv .= "$gid|";
		$psv .= "$note\n";


		$htmout .= "<tr>";
		$htmout .= "<td>$db3fil</td>";
		$htmout .= "<td>$tbl</td>";
		$htmout .= "<td>$t</td>";
		$htmout .= "<td>$x</td>";
		$htmout .= "<td>$y</td>";
		$htmout .= "<td>$g</td>";
		$htmout .= "<td>$bxlim</td>";
		$htmout .= "<td>$bylim</td>";
		$htmout .= "<td>$bhandi</td>";
		$htmout .= "<td>$l</td>";
		$htmout .= "<td>$dttm</td>";
		$htmout .= "<td>$status</td>";
		$htmout .= "<td>$note</td>";
		$htmout .= "<\tr>";

		}
	$pdo=null; 
	$matches="";
	$csv=str_replace("|", $psv, $matches );


	$json .= '{';
	$json .= '"db3fil":"$db3fil",';
	$json .= '"tbl":"$tbl",';
	$json .= '"sql":"$sql",';
	$json .= '"t":"$t",';
	$json .= '"x":"$x",';
	$json .= '"y":"$y",';
	$json .= '"bxlim":"$bxlim",';
	$json .= '"bylim":"$bylim",';
	$json .= '"bhandi":"$bhandi",';
	$json .= '"g":"$g",';
	$json .= '"l":"$l",';
	$json .= '"d":"$d",';
	$json .= '"lidb":"$lidb",';
	$json .= '"lidw":"$lidw",';
	$json .= '"pb":"$pb",';
	$json .= '"pw":"$pw",';
	$json .= '"gid":"$gid",';
	$json .= '"status":"$status",';
	$json .= '"dttm":"$dttm",';
	$json .= '"note":"$note"';
	$json .= '	}';
	$json .= ' ]}';

	$htmout .= "	</table>\n";
	$htmout .= "	</div id=div_db3sel_end>\n";
	$htmout .= "<hr color=goldenrod>\n";


	if( preg_match( "/psv/", $fmt )) { return( $psv ); }
	if( preg_match( "/csv/", $fmt )) { 
		header("Content-type: text/csv");
		print( $csv );
		return( $csv ); 
		}
	if( preg_match( "/txt/", $fmt )) { 
		header("Content-type: text/plain");
		print($txt);
		return( $txt ); 
		}
	if( preg_match( "/json/", $fmt )) { 
#		header("Content-type: image/png");
#		header("Content-type: image/jpg");
#		header("Content-type: image/gif");
		header("Content-type: application/json");
		print( $json ); 
		exit;
#		return( $json );
#		return("");
		}
	if( preg_match( "/html/", $fmt )) { 
		print($htmout);
		return($htmout);
		}
	return( $htmout );
	}
function htmout_kogo_gamedata($game) {
	$htmout = "";
	$htmout .= "<script id=script_gamedata>\n";
	$htmout .= "	function kogo_gamedata(args) {\n";
	$htmout .= "var kogo_gamedata = '\n";

	for( $j=0; $j<count(explode("\n",$game)); $j++ ) {
		$line=explode("\n",$game)[$j];
		if( $line == "" ) { continue; }
		$htmout .= "$line\n";
		}

	$htmout .= "';\n";
	$htmout .= "		return(kogo_gamedata);\n";
	$htmout .= "		}\n";
	$htmout .= "	</script>\n";
	return($htmout);
	}

function htmout_kogo_game($game) {
	$htmout = "";
	$htmout .= "<img  src=/imgs/btn/koeye.png id=img_kogo_game ";
	$htmout .= " onclick=\"toggle('div_kogo_game');return false;\" height=25>game\n";
	$htmout .= "<hr color=goldenrod>\n";
	$htmout .= "<div id=div_kogo_game>\n";
	$htmout .= "	<h1>div_kogo_game</h1>\n";
	$htmout_table = "";
	for( $j=0; $j<count(explode("\n",$game)); $j++ ) {
		$line = explode("\n",$game)[$j];
		if( $line == "" ) { continue; }
		if( $j == 0 ) {
			$flds=explode("|",$line);
			$gid=$flds[0];
			$bxlim=$flds[2];
			$bxylim=$flds[3];
			$bhandi=$flds[4];
			$t=$flds[5];
			$x=$flds[6];
			$y=$flds[7];
			$l=$flds[8];
			$d=$flds[9];
			$pb=$flds[10];
			$libb=$flds[11];
			$libw=$flds[12];
			$dttm=$flds[13];
			$status=$flds[14];
			$note=$flds[15];
#			($gid,$bxlim,$bylim,$bhandi,$t,$x,$y,$g,$l,$d,$pb,$pw,$lidb,$lidw,$dttm,$status,$note) = explode("|",$line));
			$htmout .= "<h1>$gid ($bxlim,$bylim,$bhandi) ($t,$x,$y,$g,$l)</h1>\n";
			$htmout_table .= "<table id=table_$gid>\n";
			}
		$t=explode("|",$line)[0];
		$x=explode("|",$line)[0];
		$y=explode("|",$line)[0];
		$g=$t;
		$l=4;
		$htmout_table .= "<tr>";
		$htmout_table .= "<td>$t</td>";
		$htmout_table .= "<td>$x</td>";
		$htmout_table .= "<td>$y</td>";
		$htmout_table .= "<td>$g</td>";
		$htmout_table .= "<td>$l</td>";
		$htmout_table .= "</tr>\n";
		}
	$htmout_table .= "	</table>\n";
	$htmout .= $htmout_table;
	$htmout .= "	</div id=div_kogo_game_end>\n";
	return($htmout);
	}


function htmout_board($game) {
	$htmout = "";
#	print( "<h1>BUGS_420 game=$game</h1>\n" );
	$gamelen = count(explode("\n",$game));

	$k=0;
	for( $j=0; $j<$gamelen; $j++ ) {
		$line = explode("\n",$game)[$j];
		if( $line =="" ) {continue;}
		$k=$k+1;
//		print( "<h1>BUGS_421 j=$j line=$line</h1>\n" );
		}
	$line=explode("\n",$game)[0];
	$flds=explode("|",$line);
	$fldslen = count(explode("|",$line));
//	print( "<h1>BUGS_421 gamelen=$gamelen fldslen=$fldslen line=$line</h1>\n" );
	$gid=$flds[0]; 
	if( $fldslen > 0 ) { $bxlim=$flds[1]; }
	if( $fldslen > 1 ) { $bylim=$flds[2]; }
	if( $fldslen > 2 ) { $bhandi=$flds[3]; }
	if( $fldslen > 3 ) { $t=$flds[4]; }
	if( $fldslen > 4 ) { $x=$flds[5]; }
	if( $fldslen > 5 ) { $y=$flds[6]; }
	if( $fldslen > 6 ) { $g=$flds[7]; }
	if( $fldslen > 7 ) { $l=$flds[8]; }
	if( $fldslen > 8 ) { $d=$flds[9]; }
	if( $fldslen > 9 ) { $pb=$flds[10]; }
	if( $fldslen > 10 ) { $libb=$flds[11]; }
	if( $fldslen > 11 ) { $libw=$flds[12]; }
	if( $fldslen > 12 ) { $dttm=$flds[13]; }
	if( $fldslen > 13 ) { $status=$flds[14]; }
	if( $fldslen > 14 ) { $note=$flds[15]; }

	$bt=0; $bx=0; $by=0;
	$board="";
	$gamelen=count(explode("\n",$game));
#	print( "<h1>BUGS_470 bx=$bx by=$by bt=$bt bxlim=$bxlim bylim=$bylim</h1>\n" );
	return("");
	for( $bx=0; $bx<$bxlim; $bx++ ) {
		for( $by=0; $by<$bylim; $by++ ) {
			$line=explode("\n",$game)[$bt];
			if( $line == "" ) { continue; }
			$flds=explode("|",$line);
			$fldslen=count($flds);
print( "BUGS_470 line=$line gamelen=$gamelen fldslen=$fldslen</h1>\n" );
			$t=$flds[0];
			if( $fldslen > 0 ) { $x=$flds[1]; }
			if( $fldslen > 1 ) { $y=$flds[2]; }
			if( $fldslen > 2 ) { $g=$flds[3]; }
			if( $fldslen > 3 ) { $l=$flds[4]; }
			if( $t == 0 ) {$bxby = ".";}
			else {
				if( isOdd($bt)) { $bxby = "*"; } else { $bxby = "o"; }
				}
			$board .= $bxby;
			if( $bx == $bxlim ) { $board .= "<br>\n"; }
			$bt=$bt+1;
			}
		}
	return( $board );

//	for( $j=1; $j<explode("\n",$game); $j++ ) {
//		$line = explode("\n",$game)[$j];
//		$t=explode(" ", $line)[0];
//		$x=explode(" ", $line)[1];
//		$y=explode(" ", $line)[2];
//		}
	return($htmout);
	}


function htmout_boardtime($game) {
	$htmout = "";
	$line = explode("\n",$game)[0];
	$flds=explode("|",$line);
	$gid=$flds[0];
	$bxlim=$flds[2];
	$bxylim=$flds[3];
	$bhandi=$flds[4];
	$t=$flds[5];
	$x=$flds[6];
	$y=$flds[7];
	$l=$flds[8];
	$d=$flds[9];
	$pb=$flds[10];
	$libb=$flds[11];
	$libw=$flds[12];
	$dttm=$flds[13];
	$status=$flds[14];
	$note=$flds[15];
#	($gid,$bxlim,$bylim,$bhandi,$t,$x,$y,$g,$l,$d,$pb,$pw,$lidb,$lidw,$dttm,$status,$note) = explode("|",$line));

	$j=1;
	$board="";
	for( $by=0; $by<$bylim; $by++ ) {
		for( $bx=0; $bx<$bxlim; $bx++ ) {
			$line = explode("\n",$game)[$j];
			$flds = explode(" ",$line);
			$t=flds[0];
			$x=flds[1];
			$y=flds[2];
			$g=flds[3];
			$l=flds[4];
			$board .= sprintf( "%3d|",$t );
			if( $bx == $bxlim ) { $board .= "<br>\n"; }
			$j=$j+1;
			}
		}
	return( $board );

//	for( $j=1; $j<explode("\n",$game); $j++ ) {
//		$line = explode("\n",$game)[$j];
//		$t=explode(" ", $line)[0];
//		$x=explode(" ", $line)[1];
//		$y=explode(" ", $line)[2];
//		}
	return($htmout);
	}


function htmout_stones($game) {
	$htmout = "";
	$line = explode("\n",$game)[0];
	$flds=explode("|",$line);
	$gid=$flds[0];
	$bxlim=$flds[2];
	$bxylim=$flds[3];
	$bhandi=$flds[4];
	$t=$flds[5];
	$x=$flds[6];
	$y=$flds[7];
	$l=$flds[8];
	$d=$flds[9];
	$pb=$flds[10];
	$libb=$flds[11];
	$libw=$flds[12];
	$dttm=$flds[13];
	$status=$flds[14];
	$note=$flds[15];
#	($gid,$bxlim,$bylim,$bhandi,$t,$x,$y,$g,$l,$d,$pb,$pw,$lidb,$lidw,$dttm,$status,$note) = explode("|",$line));
	return( $htmout );
	}

function htmout_lids($game) {
 	$htmout = "";
 	$line = explode("\n",$game)[0];
 	$flds=explode("|",$line);
 	$gid=$flds[0];
 	$bxlim=$flds[2];
 	$bxylim=$flds[3];
 	$bhandi=$flds[4];
 	$t=$flds[5];
 	$x=$flds[6];
 	$y=$flds[7];
 	$l=$flds[8];
 	$d=$flds[9];
 	$pb=$flds[10];
 	$libb=$flds[11];
 	$libw=$flds[12];
 	$dttm=$flds[13];
 	$status=$flds[14];
 	$note=$flds[15];
#	($gid,$bxlim,$bylim,$bhandi,$t,$x,$y,$g,$l,$d,$pb,$pw,$lidb,$lidw,$dttm,$status,$note) = explode("|",$line));
	return( $htmout );
 	}


function kogo_drop($ftarget,$ttarget) {
	$htmout="";
	if(( preg_match("/^stone/",$ftarget)) && ( preg_match("/^stone/",$ttarget))) {
		$htmout += $htmout_status("stone2stone",$t,$x,$y,$g,$bxlim,$bylim,$bhandi,d,l,$ftarget,$ttarget);
		}
	if(( preg_match("/^stone/",$ftarget)) && ( preg_match("/^board/",$ttarget))) {
		$htmout += $htmout_status("stone2board",$t,$x,$y,$g,$bxlim,$bylim,$bhandi,d,l,$ftarget,$ttarget);
		}
	if(( preg_match("/^stone/",$ftarget)) && ( preg_match("/^lid/",$ttarget))) {
		$htmout += $htmout_status("stone2lid",$t,$x,$y,$g,$bxlim,$bylim,$bhandi,d,l,$ftarget,$ttarget);
		}
	if(( preg_match("/^stone/",$ftarget)) && ( preg_match("/^bowl/",$ttarget))) {
		$htmout += $htmout_status("stone2bowl",$t,$x,$y,$g,$bxlim,$bylim,$bhandi,d,l,$ftarget,$ttarget);
		}
	if(( preg_match("/^bowl/",$ftarget)) && ( preg_match("/^stone/",$ttarget))) {
		$htmout += $htmout_status("bowl2stone",$t,$x,$y,$g,$bxlim,$bylim,$bhandi,d,l,$ftarget,$ttarget);
		}
	if(( preg_match("/^bowl/",$ftarget)) && ( preg_match("/^board/",$ttarget))) {
		$htmout += $htmout_status("bowl2bowl",$t,$x,$y,$g,$bxlim,$bylim,$bhandi,d,l,$ftarget,$ttarget);
		}
	if(( preg_match("/^bowl/",$ftarget)) && ( preg_match("/^lid/",$ttarget))) {
		$htmout += $htmout_status("bowl2lid",$t,$x,$y,$g,$bxlim,$bylim,$bhandi,d,l,$ftarget,$ttarget);
		}
	print("MSG_200 $htmout="+$htmout );
	return($htmout);
	}

function htmout_kogo_form($args) {
	$htmout="";
	$htmout .= "<img src=/imgs/btn/koeye.png id=img_form_kogo ";
	$htmout .= " onclick=\"toggle('div_form_kogo','');return false;\" height=25>\n";
	$htmout .= "form_kogo\n";
	$htmout .= "<div id=div_form_kogo hidden>\n";
	$htmout .= "<h1>div_form_kogo</h1>\n";
	$htmout .= "<form id=form_kogo name=form_kogo action=\"/go/kogo.php?kogo=formback\" type=\"GET\">\n";
	$htmout .= "<table id=table_form_kogo>\n";
	$htmout .= "	<tr><td>db3fil</td><td><input type=text id=form_db3file name=form_db3file value='kogo.db3' ></td><tr>\n";
	$htmout .= "	<tr><td>db3fil</td><td><input type=text id=form_tbl name=form_tbl value='games' ></td><tr>\n";
	$htmout .= "	<tr><td>db3fil</td><td><input type=text id=form_t name=form_t value='0'  ></td>\<tr>n";
	$htmout .= "	<tr><td>db3fil</td><td><input type=text id=form_x name=form_x value='0'  ></td>\<tr>n";
	$htmout .= "	<tr><td>db3fil</td><td><input type=text id=form_y name=form_y value='0'  ></td>\<tr>n";
	$htmout .= "	<tr><td>db3fil</td><td><input type=text id=form_g name=form_g value='0'  ></td>\<tr>n";
	$htmout .= "	<tr><td>db3fil</td><td><input type=text id=form_bxlim name=form_bxlim value='9'  ></td>\<tr>n";
	$htmout .= "	<tr><td>db3fil</td><td><input type=text id=form_bylim name=form_bylim value='9'  ></td>\<tr>n";
	$htmout .= "	<tr><td>db3fil</td><td><input type=text id=form_bhandi name=form_bhandi value='9'  ></td>\<tr>n";
	$htmout .= "	<tr><td>db3fil</td><td><input type=text id=form_l name=form_l value='0'  ></td>\<tr>n";
	$htmout .= "	<tr><td>db3fil</td><td><input type=text id=form_d name=form_d value='0'  ></td>\<tr>n";
	$htmout .= "	<tr><td>db3fil</td><td><input type=text id=form_dttm name=form_dttm value='0'  ></td>\<tr>n";
	$htmout .= "	<tr><td>db3fil</td><td><input type=text id=form_status name=form_status value='0'  ></td>\<tr>n";
	$htmout .= "	<tr><td>db3fil</td><td><input type=text id=form_gid name=form_gid value=''  ></td>\<tr>n";
	$htmout .= "	<tr><td>db3fil</td><td><input type=text id=form_note name=form_note value='0'  ></td>\<tr>n";
	$htmout .= "	<tr><td>db3fil</td><td><input type=submit id=submit name=form_submit></td>\<tr>n";
	$htmout .= "	</table>\n";
	$htmout .= "	</form>\n";
	$htmout .= "	</div id=div_kogo_form_end>\n";
	return($htmout);
	}


function htmout_script_toggle($divid) {
# $script_toggle = <<<SCRIPT_TOGGLE
	$htmout_script= "";
 	$htmout_script.= "<script id=script_toggle>\n";
	$htmout_script .= " 		function toggle(divid) {\n";
	$htmout_script .= " 			var imgid=divid.replace(\"div_\",\"img_\" );\n";
	$htmout_script .= " 			if(! document.getElementById(divid)) { return; }\n";
	$htmout_script .= " \n";
	$htmout_script .= " 			var imgid=divid.replace(\"div_\",\"img_\" );\n";
	$htmout_script .= " 			style_display=document.getElementById(divid).style.display;\n";
	$htmout_script .= " 			\n";
	$htmout_script .= " 			if( style_display == \"none\" ) {\n";
	$htmout_script .= " 				img=\"<img src=/imgs/btn/koeyew.png id=\"+imgid+\" height=50 onclick=\"toggle('+divid+'); return false;\" >";
	$htmout_script .= " 				document.getElementById(divid).style.display=\"inline\";\n";
	$htmout_script .= " 				document.getElementById(imgid).innerHTML=img;\n";
	$htmout_script .= " 				document.getElementById(imgid).src=\"/imgs/btn/koeyew.png\";\n";
	$htmout_script .= " 				}\n";
	$htmout_script .= " 			else {\n";
	$htmout_script .= " 				img=\"<img src=/imgs/btn/koeyeb.png id=\"+imgid+\" height=50 onclick=\"toggle('+divid+'); return false;\" >";
	$htmout_script .= " 				document.getElementById(divid).style.display=\"none\";\n";
	$htmout_script .= " 				document.getElementById(imgid).innerHTML=img;\n";
	$htmout_script .= " 				document.getElementById(imgid).src=\"/imgs/btn/koeyeb.png\"";
	$htmout_script .= " 				}\n";
	$htmout_script .= " 			}\n";
	$htmout_script .= " 		</script>\n";
# <<<SCRIPT_TOGGLE;
#	print( "<h1>BUGS_660 htmout_script_toggle</h1>\n" );
 	return( $htmout_script );
	}


function htmout_head($args) {
	$dttm=date('Ymd_His');
	$htmout = "";
	$htmout .= "<html><head>\n";
	$htmout .= "	<title>kogo $dttm</title>\n";
	$htmout .= htmout_script_toggle("");
	$htmout .= "	</head>\n";
	$htmout .= "<body bgcolor=linen>\n";
	$htmout .= "<hr color=goldenron>\n";
	$htmout .= "<div id=div_kogo>\n";
	$htmout .= "<hr color=goldenron>\n";
	$htmout .= "	<img src=/imgs/btn/koeye.png id=img_kogo ";
	$htmout .= "	onclick=\"window.open('./kogo.php');return false;\" height=25>\n";
	$htmout .= "	<h1>div_kogo $dttm</h1>\n";
	$htmout .= "	</div id=div_kogo_end>\n";
	$htmout .= "<hr color=goldenrod>\n";
	return($htmout);
	}

function htmout_tail($args) {
	$htmout = "";
	$htmout .= "	</body>\n";
	$htmout .= "	</html>\n";
	return($htmout);
	}





function htmout_script_startup_kogo($args) {
	$htmout = "";
	$htmout .= "<script id=script_startup_kogo>\n";
	$htmout .= "	function startup_kogo(args) {\n";
	$htmout .= "		alert( \"MSG_101 srtup_kogo args=\"+args );\n";
#	$htmout .= "		var gamedata=load_gamedata('');\n";
#	$htmout .= "		if (document.getElementById('div_gamedata')) {\n";
#	$htmout .= "			document.getElementById('div_gamedata').innerHTML=gamedata;\n";
#	$htmout .= "			}\n";

#	$htmout .= "	divid=\"div_board\";\n"


#	$htmout .= "	$(\"\'+divid+\'\").html(gamedata);\n";
#	$htmout .= "	divid=\"div_stones\";"
#	$htmout .= "	$(\"'+divid+'\").html(gamedata);\n";
#	$htmout .= "	divid=\"div_gamelist\";"
#	$htmout .= "	$(\"'+divid+'\").html(gamedata);\n";
#	$htmout .= "	return(\"\")\n";
	$htmout .= "	}\n";
	$htmout .= "	</script>\n";
	return($htmout);
	}

function isodd($n) {if($n % 2 == 0 ) {return(0);} else {return(1);}}



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_3979:  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



Your browser does not support the HTML5 canvas element.


Drag mouse to navigate.

Navigation





17.Aug.2010, Martin Wengenmayer