* 
 * Silurus is a professionally developed PHP Classifieds script that was built for you.
 * Whether you are running classifieds for autos, motorcycles, bicycles, rv's, guns,
 * horses, or general merchandise, our product is the right package for you.
 * It has template system and no limit to usage with free for any changes.
 *
 * Copyright (c) 2009-2013
 */
include "./include_php/init.php";
include "./include_php/TemplVotingView.php";
$type = intval($_GET['type']);
$id = intval($_GET['id']);
$book = mysql_fetch_assoc(mysql_query("select * from Store where type=" . ($type - 1) . " and ID=" . $id));
$categ = mysql_fetch_assoc(mysql_query("select * from StoreCategories where ID=" . $book['categoryID']));
$user = mysql_fetch_assoc(mysql_query("select * from Profiles where ID=" . intval($book['userID'])));
$oVotingView = new TemplVotingView('gvoting', 0);
$oVotingView->_fRate = $book['rating'];
$vote1 = $oVotingView->getSmallVoting(0, '');
$book['title_short'] = strlen($book['Title']) > 30 ? substr(htmlspecialchars($book['Title']), 0, 30) . '...' : htmlspecialchars($book['Title']);
$book['price'] = number_format($book['price'], 2, ".", "");
if ($type == 1) {
    $book['url'] = 'product';
    $book['prefix'] = '';
} else {
    $book['url'] = 'wproduct';
    $book['prefix'] = '_b';
}
$img = '';
$photos = array();
$q = mysql_query("select v.* from StorePropValues v inner join StoreProp p on p.ID=v.PropID where v.itemID=" . $id . " and p.Type=3 limit 1");
while ($arr = mysql_fetch_assoc($q)) {
                        }
                    }
                } elseif (isset($photos[$prop['ID']])) {
                    mysql_query("insert into StorePropValues set PropID=" . $prop['ID'] . ",itemID=" . $newID . ",Value='" . $photos[$prop['ID']] . "'");
                }
            } elseif ($prop['Type'] == 3 && isset($photos[$prop['ID']])) {
                mysql_query("insert into StorePropValues set PropID=" . $prop['ID'] . ",itemID=" . $newID . ",Value='" . $photos[$prop['ID']] . "'");
            }
        }
        header("location: /product.php?ID=" . $newID);
        die;
    }
    $smarty->assign("error", $err);
}
$categoryID = intval($info['categoryID']);
$oVotingView = new TemplVotingView('gvoting', 0);
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
    $_REQUEST['Title'] = $info['Title'];
    $_REQUEST['price'] = number_format($info['price'], 2, ".", " ");
    $q = mysql_query("select * from StoreProp where Type<>3 and categoryID=" . $categoryID);
    while ($prop = mysql_fetch_assoc($q)) {
        $subitems = array();
        if ($prop['Type'] > 5) {
            $qq = mysql_query("select * from StorePropValues where PropID=" . intval($prop['ID']) . " and itemID=" . $info['ID']);
            while ($subprop = mysql_fetch_assoc($qq)) {
                $subitems[] = $subprop['Value'];
            }
        } else {
            $qq = mysql_fetch_assoc(mysql_query("select * from StorePropValues where PropID=" . intval($prop['ID']) . " and itemID=" . $info['ID']));
            $subitems = $qq['Value'];
        }
    header("location: /profile.php");
}
$seller = mysql_fetch_assoc(mysql_query("select * from Profiles where ID=" . intval($book['userID'])));
$photos = array();
$q = mysql_query("select v.* from StorePropValues v inner join StoreProp p on p.ID=v.PropID where v.itemID=" . intval($_REQUEST['ID']) . " and p.Type=3");
while ($arr = mysql_fetch_assoc($q)) {
    if (is_file("./media/store/small_" . $arr['Value'])) {
        $info = getimagesize('./media/store/small_' . $arr['Value']);
        $photos[] = array('path' => $arr['Value'], 'width' => $info[0] >= 300 ? 300 : $info[0], 'height' => $info[0] >= 300 ? $info[1] * 300 / $info[0] : $info[1]);
    }
}
$book['title_short'] = strlen($book['Title']) > 40 ? substr(htmlspecialchars($book['Title']), 0, 40) . '...' : htmlspecialchars($book['Title']);
$book['price'] = number_format($book['price'], 2, ".", " ");
$q = mysql_query("select * from StoreProp where Type<>3 and categoryID=" . $book['categoryID'] . "  order by Prior");
$props = array();
$oVotingView = new TemplVotingView('gvoting', 0);
while ($prop = mysql_fetch_assoc($q)) {
    $subitems = array();
    if ($prop['Type'] > 5) {
        $qq = mysql_query("select n.* from StorePropMulti n inner join StorePropValues v on v.Value=n.ID where v.PropID=" . intval($prop['ID']) . " and v.itemID=" . $book['ID']);
        while ($subprop = mysql_fetch_assoc($qq)) {
            $subitems[] = $subprop['Name'];
        }
    } elseif ($prop['Type'] == 5) {
        $qq = mysql_query("select n.* from StorePropMulti n inner join StorePropValues v on v.Value=n.ID where v.PropID=" . intval($prop['ID']) . " and v.itemID=" . $book['ID']);
        while ($subprop = mysql_fetch_assoc($qq)) {
            $subitems = $subprop['Name'];
        }
    } elseif ($prop['Type'] == 4) {
        $qq = mysql_fetch_assoc(mysql_query("select * from StorePropValues where PropID=" . intval($prop['ID']) . " and itemID=" . $book['ID']));
        $subitems = $qq['Value'];
    mysql_query("insert into Flags set date=" . time() . ",userID=" . $_SESSION['memberID'] . ",type=0,itemID=" . intval($_REQUEST['ID']));
    header("location: /profile.php?ID=" . intval($_REQUEST['ID']));
}
if ($profileID != $_SESSION['memberID']) {
    $user = mysql_fetch_assoc(mysql_query("select * from Profiles where ID=" . $profileID));
} else {
    $user = $_SESSION['memberINFO'];
}
$seller = $user;
$prof_photo = 'media/images/profile/' . $user['ID'] . '/thumb_' . $user['PrimPhoto'];
if (is_file($prof_photo)) {
    $fileinfo = getimagesize($prof_photo);
    $prof_photo = array("src" => $prof_photo, "width" => $fileinfo[0]);
    $smarty->assign("prof_photo", $prof_photo);
}
$oVotingView = new TemplVotingView('gvoting', 0);
$votecount = intval($user['rating_count']);
$oVotingView->_fRate = $user['rating'];
$vote1 = $oVotingView->getSmallVoting(0, intval($votecount) . ' votes');
$rating = mysql_fetch_assoc(mysql_query("select * from ProfilesRating where userID=" . intval($_SESSION['memberID']) . " and voteID={$profileID}"));
$oVotingView->_fRate = intval($rating['rating']) > 0 ? intval($rating['rating']) : '1';
$voter = '<input type="hidden" name="review_rating" id="gvotingbig" value="' . (intval($rating['rating']) > 0 ? intval($rating['rating']) : '1') . '">' . $oVotingView->getBigVoting(intval($rating['rating']) > 0 ? '0' : '1', '');
$user['LastLoggedIn'] = $user['LastLoggedIn'] ? date("d-m-Y H:i", strtotime($user['LastLoggedIn'])) : "Never";
$user['city'] = mysql_fetch_assoc(mysql_query("select * from City where ID=" . intval($user['city'])));
$user['city'] = $user['city']['Title'];
$smarty->assign("user", $user);
$smarty->assign("ap_seller", $seller);
$smarty->assign("vote1", $vote1);
$smarty->assign("voter", $voter);
$order = isset($_REQUEST['border']) ? $_REQUEST['border'] : 'title';
$desc = isset($_REQUEST['bdesc']) ? true : false;