<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=x-sjis">
<TITLE>KOMOショッピング</TITLE>
<STYLE TYPE="text/css">
<!--
:link {
Color : blue ;
Text-Decoration : None
}
:active {
Color : blue ;
Text-Decoration : None
}
:visited {
Color : blue ;
Text-Decoration : None
}
A:hover {
Color : blue ;
Text-Decoration : UnderLine
}
-->
</STYLE>
</HEAD>
<BODY BGCOLOR="#FFFBF0">
<CENTER>
<P ALIGN="CENTER"><IMG SRC="shop_title.gif" WIDTH="345" HEIGHT="53" ALIGN="BOTTOM" BORDER="0">
<P><B><FONT COLOR="#990066">Web上で商品管理が出来ます。登録データの修正も可能です!(^o^)丿</FONT></B></P>
<P>パスワードは「777」です。お好きな商品画像をアップできます。</P>
<?php
//============================初期設定==============================
$data_file = './goods.dat'; //データログ用ファイル
$php_path = './komoshop.php'; //ショッピングカート・スクリプト名
$passwd = '777'; //管理者用パスワード
$data_max = 50; //データ最大記録数
$page_view = 5; //1ページの記事表示件数
$up_dir = '/img/'; //商品画像データ保存フォルダ名
//画像の表示最大値(ピクセル)
$w_max = 140; //横幅
$h_max = 140; //縦幅
//縮小画像の表示最大値(ピクセル)
$w_max2 = 60; //横幅
$h_max2 = 60; //縦幅
//==================================================================
//スーパーグローバル変数対策
if(!isset($PATH_TRANSLATED)){
$path = dirname($_SERVER["PATH_TRANSLATED"]).$up_dir;
}else{
$path = dirname($PATH_TRANSLATED).$up_dir;
}
if(!isset($PHP_SELF)){ $PHP_SELF = $_SERVER["PHP_SELF"]; }
if(!isset($action)){
if($_POST['action']){
$action = $_POST['action'];
}else{
$action = $_GET['action'];
}
}
if(!isset($password)){
if($_POST['password']){
$password = $_POST['password'];
}else{
$password = $_GET['password'];
}
}
if(!isset($code)){ $code = $_POST['code']; }
if(!isset($g_name)){ $g_name = $_POST['g_name']; }
if(!isset($fname)){ $fname = $_POST['fname']; }
if(!isset($fname2)){ $fname2 = $_POST['fname2']; }
if(!isset($price)){ $price = $_POST['price']; }
if(!isset($expl)){ $expl = $_POST['expl']; }
if(!isset($g_amount)){ $g_amount = $_POST['g_amount']; }
if(!isset($button)){ $button = $_POST['button']; }
if(!isset($fname_del)){ $fname_del = $_POST['fname_del']; }
if(!isset($fname2_del)){ $fname2_del = $_POST['fname2_del']; }
if(!isset($upfile)){ $upfile = $_FILES['upfile']['tmp_name']; }
if(!isset($upfile_name)){ $upfile_name = $_FILES['upfile']['name']; }
if(!isset($upfile2)){ $upfile2 = $_FILES['upfile2']['tmp_name']; }
if(!isset($upfile2_name)){ $upfile2_name = $_FILES['upfile2']['name']; }
if(!isset($e_code)){ $e_code = $_POST['e_code']; }
if(!isset($pline)){ $pline = $_POST['pline']; }
if($action == "regist"){
//処理の分岐
if($button == "修正"){
//ここから書き込みデータの調整
$g_name = str_replace(" ", "_",$g_name); //空白対策
$g_name = str_replace(" ", "_",$g_name);
$price = str_replace(",", ",",$price); //桁区切りのコンマ対策
$expl = htmlspecialchars($expl);
$expl = nl2br($expl);
$expl = str_replace("\r", "", $expl);
$expl = str_replace("\n", "", $expl);
//ログファイルの区切文字(",")と区別するために文字コード(,)に書き換える。
$expl = str_replace(",", ",",$expl);
//在庫数の制限
if($g_amount > 999){ $g_amount = 999; }
//画像の削除指定があれば、削除。
if($fname_del > 0){
unlink(".".$up_dir.$fname);
}
if($fname2_del > 0){
unlink(".".$up_dir.$fname2);
}
//画像のアップロード処理
if(is_uploaded_file($upfile)){
$imagesize = getimagesize($upfile); //画像の属性を取得
switch($imagesize[2]){
case 1:
$out = $code . ".gif";
break;
case 2:
$out = $code . ".jpg";
break;
case 3:
$out = $code . ".png";
break;
default:
unlink($upfile);
}
if($out){
$sendpath = $path.$out;
if(move_uploaded_file($upfile, $sendpath)){
chmod($sendpath,0666);
$fname = $out;
}
}
}
//画像のアップロード処理2
if(is_uploaded_file($upfile2)){
$imagesize2 = getimagesize($upfile2); //画像の属性を取得
switch($imagesize2[2]){
case 1:
$out2 = $code . "-2.gif";
break;
case 2:
$out2 = $code . "-2.jpg";
break;
case 3:
$out2 = $code . "-2.png";
break;
default:
unlink($upfile);
}
if($out2){
$sendpath2 = $path.$out2;
if(move_uploaded_file($upfile2, $sendpath2)){
chmod($sendpath2,0666);
$fname2 = $out2;
}
}
}
$repdata = file($data_file);
$fp = fopen($data_file, "w");
for($i=0; $i<count($repdata); $i++){
list($rcode,$rname,$rfname,$rfname2,$rprice,$rexpl,$ramount) = split( ",", $repdata[$i]);
if ($code == $rcode) {
$repdata[$i] = "$code,$g_name,$fname,$fname2,$price,$expl,$g_amount\n";
fputs($fp, $repdata[$i]);
}else{
fputs($fp, $repdata[$i]);
}
}
fclose($fp);
echo "<META HTTP-EQUIV=refresh CONTENT=0;URL=$PHP_SELF?action=edit&password=$passwd>\n";
exit;
}elseif($button == "削除"){
$deldata = file($data_file);
$fp = fopen($data_file, "w");
for($i=0; $i<count($deldata); $i++){
list($dcode,$dname,$dfname,$dfname2,$dprice,$dexpl,$damount) = split(",", $deldata[$i]);
if ($code == $dcode) {
$deldata[$i] = "";
if($dfname){
unlink(".".$up_dir.$dfname);
}
if($dfname2){
unlink(".".$up_dir.$dfname2);
}
}
fputs($fp, $deldata[$i]);
}
fclose($fp);
}elseif($button == "先頭へ"){
$sw_data = file($data_file);
$fp = fopen($data_file, "w");
for($i=0; $i<count($sw_data); $i++){
list($scode,$sname,$sfname,$sfname2,$sprice,$sexpl,$samount) = split(",", $sw_data[$i]);
if ($code == $scode) {
$sw_data[$i] = "";
//移動データを生成
$sw_msg = implode(",", array($scode,$sname,$sfname,$sfname2,$sprice,$sexpl,$samount));
}
fputs($fp, $sw_data[$i]);
}
fclose($fp);
unset($sw_data);
//抜き出したデータをファイルの先頭に書き込み
$message = file($data_file);
$fp = fopen($data_file, "w");
rewind($fp);
fputs($fp, "$sw_msg");
for($i=0; $i<count($message); $i++){
fputs($fp, $message[$i]);
}
fclose($fp);
unset($message);
}else{
if($g_name){
$code = time(); //アクセス時の秒数
//ここから書き込みデータの調整
$g_name = str_replace(" ", "_",$g_name); //空白対策
$g_name = str_replace(" ", "_",$g_name);
$price = str_replace(",", ",",$price); //桁区切りのコンマ対策
$expl = htmlspecialchars($expl);
$expl = nl2br($expl);
$expl = str_replace("\r", "", $expl);
$expl = str_replace("\n", "", $expl);
//ログファイルの区切文字(",")と区別するために文字コード(,)に書き換える。
$expl = str_replace(",", ",",$expl);
//在庫数の制限
if($g_amount > 999){ $g_amount = 999; }
//画像のアップロード処理
if(is_uploaded_file($upfile)){
$imagesize = getimagesize($upfile); //画像の属性を取得
switch($imagesize[2]){
case 1:
$out = $code . ".gif";
break;
case 2:
$out = $code . ".jpg";
break;
case 3:
$out = $code . ".png";
break;
default:
unlink($upfile);
}
if($out){
$sendpath = $path.$out;
if(move_uploaded_file($upfile, $sendpath)){
chmod($sendpath,0666);
$fname = $out;
}
}
}
//画像のアップロード処理2
if(is_uploaded_file($upfile2)){
$imagesize2 = getimagesize($upfile2); //画像の属性を取得
switch($imagesize2[2]){
case 1:
$out2 = $code . "-2.gif";
break;
case 2:
$out2 = $code . "-2.jpg";
break;
case 3:
$out2 = $code . "-2.png";
break;
default:
unlink($upfile);
}
if($out2){
$sendpath2 = $path.$out2;
if(move_uploaded_file($upfile2, $sendpath2)){
chmod($sendpath2,0666);
$fname2 = $out2;
}
}
}
//配列要素を文字列により連結
$input_msg = implode(",", array($code,$g_name,$fname,$fname2,$price,$expl,$g_amount));
$message = file($data_file);
$fp = fopen($data_file, "w");
rewind($fp);
fputs($fp, "$input_msg\n");
//最大記録数の調整
if($data_max <= count($message)){
$msg_num = $data_max - 1;
}else{
$msg_num = count($message);
}
for($i = 0; $i < $msg_num; $i++){
fputs($fp, $message[$i]);
}
fclose($fp);
unset($message);
}
echo "<META HTTP-EQUIV=refresh CONTENT=0;URL=$PHP_SELF?action=edit&password=$passwd>\n";
exit;
}
}elseif(($action == "edit") && ($password == $passwd)){
$kanri_flag = 1;
if($e_code < 1){
echo "<form action=$PHP_SELF method=POST ENCTYPE=multipart/form-data>\n";
echo "<input type=hidden name=action value=regist>\n";
echo "<table border=0>\n";
echo "<tr><td align=right>商品名:</td><td colspan=2><input type=text size=25 name=g_name></td></tr>\n";
echo "<tr><td align=right>商品画像1:</td><td colspan=2><INPUT TYPE=file NAME=upfile SIZE=35><FONT SIZE=2 COLOR=#CC0000> *GIF、JPG、PNG画像のみ有効。</FONT></td></tr>\n";
echo "<tr><td align=right>商品画像2:</td><td colspan=2><INPUT TYPE=file NAME=upfile2 SIZE=35><FONT SIZE=2 COLOR=#CC0000> *GIF、JPG、PNG画像のみ有効。</FONT></td></tr>\n";
echo "<tr><td align=right>提供価格:</td><td colspan=2><input type=text size=15 name=price>円(税込総額)</td></tr>\n";
echo "<tr><td align=right>商品説明:</td><td colspan=2><textarea name=expl rows=6 cols=50></textarea></td></tr>\n";
echo "<tr><td align=right>在庫数:</td><td colspan=2><input type=text size=10 name=g_amount></td></tr>\n";
echo "<tr><td></td><td>\n";
echo "<input type=submit value=登録> <input type=reset value=リセット></td></form>\n";
}else{
$comdata = file($data_file);
for($i=0; $i<count($comdata); $i++){
list($ccode,$cname,$cfname,$cfname2,$cprice,$cexpl,$camount) = split(",", $comdata[$i]);
if ($e_code == $ccode) {
$rname = $cname; $rfname = $cfname; $rfname2 = $cfname2; $rprice = $cprice; $rexpl = $cexpl; $ramount = $camount;
$rexpl = str_replace("<br />", "\n", $rexpl);
break;
}
}
unset($comdata);
echo "<form action=$PHP_SELF method=POST ENCTYPE=multipart/form-data>\n";
echo "<input type=hidden name=action value=regist>\n";
echo "<input type=hidden name=code value=$e_code>\n";
echo "<table border=0>\n";
echo "<tr><td align=right>商品名:</td><td colspan=2><input type=text size=25 name=g_name value=$rname></td></tr>\n";
echo "<tr><td align=right>商品画像1:</td><td colspan=2>";
if($rfname && file_exists("$path$rfname")){
$size = getimagesize("$path$rfname");
$img_w=$size[0];
$img_h=$size[1];
if($img_w > $w_max2 || $img_h > $h_max2){
$w_ritu = $w_max2 / $img_w;
$h_ritu = $h_max2 / $img_h;
($w_ritu < $h_ritu) ? $key = $w_ritu : $key = $h_ritu;
$width = (int) $img_w * $key;
$height = (int) $img_h * $key;
echo "<A HREF=.$up_dir$rfname TARGET=_blank><img src=.$up_dir$rfname WIDTH=" . $width . " HEIGHT=" . $height . " border=0></A> ";
}else{
echo "<img src=.$up_dir$rfname border=0> ";
}
echo "<input type=hidden name=fname value=$rfname><INPUT TYPE=CHECKBOX NAME=fname_del VALUE=1>削除";
echo " 上書:<INPUT TYPE=file NAME=upfile SIZE=20><FONT SIZE=2 COLOR=#CC0000> *GIF、JPG、PNG画像のみ有効。</FONT>";
}else{
echo "<INPUT TYPE=file NAME=upfile SIZE=35><FONT SIZE=2 COLOR=#CC0000> *GIF、JPG、PNG画像のみ有効。</FONT>";
}
echo "</td></tr>\n";
echo "<tr><td align=right>商品画像2:</td><td colspan=2>";
if($rfname2 && file_exists("$path$rfname2")){
$size = getimagesize("$path$rfname2");
$img_w=$size[0];
$img_h=$size[1];
if($img_w > $w_max2 || $img_h > $h_max2){
$w_ritu = $w_max2 / $img_w;
$h_ritu = $h_max2 / $img_h;
($w_ritu < $h_ritu) ? $key = $w_ritu : $key = $h_ritu;
$width = (int) $img_w * $key;
$height = (int) $img_h * $key;
echo "<A HREF=.$up_dir$rfname2 TARGET=_blank><img src=.$up_dir$rfname2 WIDTH=" . $width . " HEIGHT=" . $height . " border=0></A>";
}else{
echo "<img src=.$up_dir$rfname2 border=0>";
}
echo "<input type=hidden name=fname2 value=$rfname2><INPUT TYPE=CHECKBOX NAME=fname2_del VALUE=1>削除";
echo " 上書:<INPUT TYPE=file NAME=upfile2 SIZE=20><FONT SIZE=2 COLOR=#CC0000> *GIF、JPG、PNG画像のみ有効。</FONT>";
}else{
echo "<INPUT TYPE=file NAME=upfile2 SIZE=35><FONT SIZE=2 COLOR=#CC0000> *GIF、JPG、PNG画像のみ有効。</FONT>";
}
echo "</td></tr>\n";
echo "<tr><td align=right>提供価格:</td><td colspan=2><input type=text size=15 name=price value=$rprice>円(税込総額)</td></tr>\n";
echo "<tr><td align=right>商品説明:</td><td colspan=2><textarea name=expl rows=6 cols=50>$rexpl</textarea></td></tr>\n";
echo "<tr><td align=right>在庫数:</td><td colspan=2><input type=text size=10 name=g_amount value=$ramount></td></tr>\n";
echo "<tr><td></td><td>\n";
echo "<input type=submit name=button value=修正> <input type=submit name=button value=削除> <input type=submit name=button value=先頭へ></td></form>\n";
}
echo "<td><form action=$PHP_SELF method=POST><input type=submit value=ログアウト></td></tr>\n";
echo "</table></form>\n";
}
if($message = file($data_file)){
$msg_count = count($message);
if($pline == ""){
$p_line = 0;
}else{
$p_line = $pline;
}
$end_data = $msg_count - 1;
$page_end = $p_line + ($page_view - 1);
if($page_end >= $end_data)
$page_end = $end_data;
for($i = $p_line; $i <= $page_end; $i++){
list($vcode,$vname,$vfname,$vfname2,$vprice,$vexpl,$vamount) = split( ",", $message[$i]);
echo "<TABLE BORDER=0 CELLSPACING=1 WIDTH=600 BGCOLOR=#666666>\n";
echo "<form action=$PHP_SELF method=POST>\n";
echo "<input type=hidden name=action value=edit>\n";
echo "<input type=hidden name=e_code value=\"$vcode\">\n";
echo "<TR><TD WIDTH=75 BGCOLOR=#CCFFCC>商品名</TD>\n";
echo "<TD WIDTH=200 BGCOLOR='white'><B><FONT COLOR='blue'>" . $vname . "</FONT></B>";
if (($action == 'edit') && ($password == $passwd)) {
echo "<input type=hidden name=password value=\"$passwd\"> <input type=submit value=訂正>";
}
echo "</TD></FORM>\n";
echo "<TD ROWSPAN=6 BGCOLOR='white'>";
if($vfname && file_exists("$path$vfname")){
$size = getimagesize("$path$vfname");
$img_w=$size[0];
$img_h=$size[1];
if($img_w > $w_max || $img_h > $h_max){
$w_ritu = $w_max / $img_w;
$h_ritu = $h_max / $img_h;
($w_ritu < $h_ritu) ? $key = $w_ritu : $key = $h_ritu;
$width = (int) $img_w * $key;
$height = (int) $img_h * $key;
echo "<A HREF=.$up_dir$vfname TARGET=_blank><img src=.$up_dir$vfname WIDTH=" . $width . " HEIGHT=" . $height . "></A> ";
}else{
echo "<img src=.$up_dir$vfname> ";
}
if($vfname2 && file_exists("$path$vfname2")){
$size2 = getimagesize("$path$vfname2");
$img_w2=$size2[0];
$img_h2=$size2[1];
if($img_w2 > $w_max || $img_h2 > $h_max){
$w_ritu2 = $w_max / $img_w2;
$h_ritu2 = $h_max / $img_h2;
($w_ritu2 < $h_ritu2) ? $key2 = $w_ritu2 : $key2 = $h_ritu2;
$width2 = (int) $img_w2 * $key2;
$height2 = (int) $img_h2 * $key2;
echo "<A HREF=.$up_dir$vfname2 TARGET=_blank><img src=.$up_dir$vfname2 WIDTH=" . $width2 . " HEIGHT=" . $height2 . "></A>";
}else{
echo "<img src=.$up_dir$vfname2>";
}
}
}else{
if($vfname2 && file_exists("$path$vfname2")){
$size = getimagesize("$path$vfname2");
$img_w=$size[0];
$img_h=$size[1];
if($img_w > $w_max || $img_h > $h_max){
$w_ritu = $w_max / $img_w;
$h_ritu = $h_max / $img_h;
($w_ritu < $h_ritu) ? $key = $w_ritu : $key = $h_ritu;
$width = (int) $img_w * $key;
$height = (int) $img_h * $key;
echo "<A HREF=.$up_dir$vfname2 TARGET=_blank><img src=.$up_dir$vfname2 WIDTH=" . $width . " HEIGHT=" . $height . "></A>";
}else{
echo "<img src=.$up_dir$vfname2>";
}
}
}
echo "</TD></TR>\n";
echo "<TR><TD WIDTH=75 BGCOLOR=#CCFFCC>価格</TD>\n";
echo "<TD WIDTH=200 BGCOLOR='white'>";
$vprice2 = number_format($vprice);
echo $vprice2 . "円<FONT SIZE=2>(税込総額)</FONT></TD></TR>\n";
echo "<TR><TD WIDTH=75 BGCOLOR=#CCFFCC>在庫数</TD>\n";
echo "<TD WIDTH=200 BGCOLOR='white'>";
if($vamount < 1){ $vamount = 0; }
$vamount2 = number_format($vamount);
echo $vamount2 . "</TD></TR>\n";
echo "<TR><TD WIDTH=75 BGCOLOR=#CCFFCC>商品説明</TD>\n";
echo "<TD WIDTH=200 BGCOLOR='white'><FONT SIZE=2>" . $vexpl . "</FONT></TD></TR>\n";
echo "<TR><TD COLSPAN=2 BGCOLOR='white'>";
echo "<form action=$php_path method=POST>\n";
echo "<input type=hidden name=action value=regist>\n";
echo "<input type=hidden name=code value=\"$vcode\">\n";
echo "<input type=hidden name=goods value=\"$vname\">\n";
$vprice = str_replace(",", "", $vprice);
echo "<input type=hidden name=price value=\"$vprice\">\n";
echo "<B>注文数:</B>\n";
if($vamount > 0){
echo "<SELECT NAME=amount>\n";
for($j=1;$j<=$vamount;$j++){
echo "<OPTION VALUE=$j>" . $j . "</OPTION>\n";
}
echo "</SELECT>\n";
echo "<input type=submit value=買物カゴへ入れる>\n";
}else{
echo "<font color='red'>在庫切れ</font>\n";
}
echo "</TD></TR></FORM></TABLE><BR>\n";
}
?>
<P>
<TABLE BORDER="0" WIDTH="600">
<TR>
<TD WIDTH="50%">
<?php
if($page_end >= $page_view){
$page_count = floor($page_end / $page_view);
$prev_line = ($page_count - 1) * $page_view;
print "<form method=Post action=$PHP_SELF>\n";
if (($action == 'edit') && ($password == $passwd)){
echo "<input type=hidden name=action value=edit>\n";
echo "<input type=hidden name=password value=$passwd>\n";
}
print "<input type=hidden name=pline value=$prev_line>\n";
print "<input type=submit value=前のページ>\n";
print "</form>\n";
}else{
print " \n";
}
?>
</TD>
<TD WIDTH="50%"><P ALIGN="RIGHT">
<?php
$next_line = $page_end + 1;
if($page_end != $end_data){
print "<form method=Post action=$PHP_SELF>\n";
if (($action == 'edit') && ($password == $passwd)){
echo "<input type=hidden name=action value=edit>\n";
echo "<input type=hidden name=password value=$passwd>\n";
}
print "<input type=hidden name=pline value=$next_line>\n";
print "<input type=submit value=次のページ>\n";
print "</form>\n";
}else{
print " \n";
}
?>
</TD>
</TR>
</TABLE>
<?php
echo "<form action=$php_path method=POST>\n";
echo "<input type=submit value=買物カゴの中身を見る></form>\n";
echo "<hr>\n";
}
if($kanri_flag < 1){
echo "<div align=left>\n";
echo "<form action=$PHP_SELF method=POST>\n";
echo "<input type=hidden name=action value=edit>\n";
echo "<input type=password size=10 name=password>\n";
echo " <input type=submit value=管理><br>\n";
echo "</form></div>\n";
}
?>
<div align="right"><font size="-1">Powered by <a href="http://www.komonet.ne.jp/" onMouseOver="this.style.color='red'" onMouseOut="this.style.color='blue'">KOMONET</a></font></div>
</CENTER>
</BODY>
</HTML>