<?php
define('IN_MUDDER', TRUE);
require_once(dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR."./include/common.inc.php");

if(!is_numeric($shopid) || $shopid <= 0) {
    echo 'ID无效'.$shopid;
} else {
    $offset = 5;
    $limit = get_limit($page, $offset);
    $total = $db->get_value("SELECT COUNT(*) FROM {$dbpre}pictures WHERE shopid='$shopid' AND status=1");
    if($total) {
        $query = $db->query("SELECT * FROM {$dbpre}pictures WHERE shopid='$shopid' AND status=1 LIMIT $limit");
        while($row = $db->fetch_array($query)) {
            $small_imgurl = get_picture($row['folder'],$row['filename'],'small');
            $imgurl = $row['folder'].'/'.$row['filename'];
            $contents .="<tr><td width=\"120\"><img src=\"{$small_imgurl}\" /></td><td><input type=\"radio\" name=\"picture\" value=\"{$imgurl}\" />{$row['title']}<br />{$row['comments']}</td></tr>";
        }
        $multipage = multi($total, $offset, $page, "dlg_selectpicture.php?shopid=$shopid&objid=$objid");
        $multipage = $multipage ? "<div class=\"multipage\">{$multipage}</div>" : "";
    } else {
        echo '没有图片。';
    }
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=<?=$charset?>">
<title>选择封面图片</title>
<link rel="stylesheet" type="text/css" id="css" href="../images/admin/dialog.css">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">  
<meta http-equiv="Expires" content="0">
</head>
<body>
<form method="post" action="" name="selectpicture_from">
<table>
<?=$contents?>
</table>
<?=$multipage?>
<div class="btndiv"><input type="button" value="确定" onclick="selectpicture();" />&nbsp;<input type="button" value="关闭" onclick="window.close();" /></div>
</form>
<script type="text/javascript">
var objid = '<?=$objid?>';
function selectpicture() {
    var rds = document.getElementsByTagName('input');
    for(var i=0;i<rds.length;i++) {
        if(rds[i].name == 'picture' && rds[i].checked){
            window.opener.document.getElementById(objid).value = rds[i].value;
            window.close();
            return;
        }
    }
    alert('没有选择图片。');
}
</script>
</body>
</html>