the pws script

Results 1 to 3 of 3
  1. #1
    Member tabarnak1 is offline
    MemberRank
    Jan 2007 Join Date
    QuLocation
    45Posts

    the pws script

    <?php

    $conn = odbc_connect("$dbname","$dbuser","$dbpass");

    /* CONFIGURATION */
    $community = "IceTeaKO's";
    $table = "PUS_STORE";
    $items_per_row = 5;
    $filename = "pus";
    $images = "pus_images";

    /* Logs
    1 = on
    0 = off

    Requires the PUS_STORE_LOGS table
    */
    $logs = 1;

    /* Knight Cash */
    # Get from TB_USER
    #$_WHERE = "TB_USER";
    #$kc_col = "KC";

    # Get from USERDATA [ jifen ]
    # This is for most people.
    $_WHERE = "TB_USER";
    $kc_col = "kc";

    /*
    Categories
    */
    $cats = array(
    1 => "Weapons",
    2 => "Armour",
    3 => "Scrolls",
    4 => "Jewellery"
    );


    /* END OF CONFIGURATION */

    $kc = 0;

    if (empty($_SESSION['sesuser']))
    {

    parth1tr();
    parth1('100%',1,'center');
    echo "Error";
    parth2();
    parth2tr();

    part1tr();
    part1('100%',1,'center', 1);
    echo "You are not logged in!";
    part2();
    part2tr();
    }
    else
    {
    if ($_WHERE == "TB_USER")
    {
    $results = odbc_exec($conn, "SELECT $kc_col FROM $_WHERE WHERE strAccountID='{$_SESSION['sesuser']}'");
    $kc = intval(odbc_result($results, 1));
    }
    else
    {
    $results = odbc_exec($conn, "SELECT strCharID1, strCharID2, strCharID3 FROM ACCOUNT_CHAR WHERE strAccountID='{$_SESSION['sesuser']}'");
    while (odbc_fetch_row($results))
    {
    $x = 1;
    while ($x <= 3)
    {
    $char = odbc_result($results, $x);
    if (!empty($char))
    {
    $results2 = odbc_exec($conn, "SELECT $kc_col FROM $_WHERE WHERE strUserID='{$char}'");
    $_CHAR[$x] = $char;
    $_KC[$x] = intval(odbc_result($results2, 1));
    $kc = $kc + $_KC[$x];
    }
    $x++;
    }
    }
    }
    parth1tr();
    parth1('100%',$items_per_row,'center');
    echo "Power-Up Store";
    parth2();
    parth2tr();

    $cat = trim(intval($_GET['cat']));
    if (!$cat)
    $cat = 1;

    $dwID = trim(intval($_POST['item']));
    if ($dwID == 0)
    {
    part1tr();
    part1('100%',$items_per_row,'center', 1);
    echo "<div align=\"right\"><b>You have {$kc} Knight Cash</b></div>";
    echo "Welcome to $community Power-Up Store <br /><center><font size=\"+1\">{$cats[$cat]}</font></center>";
    part2();
    part2tr();

    $results = odbc_exec($conn, "SELECT * FROM $table WHERE category=$cat ORDER BY price DESC");
    $x = 1;
    $y = 0;
    echo "<table align=\"center\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">";
    while ($row = odbc_fetch_array($results))
    {
    $y++;
    if ($x == 1)
    {
    if ($y > 1)
    echo "<tr><td colspan='{$items_per_row}'><br /><hr><br /></td></tr>";
    # Main row
    echo "<tr>";
    }

    $dwID2 = substr($row['dwID'], 0, -2) . "00";

    $img_res = odbc_exec($conn, "SELECT dwIDicon FROM ITEM_BASIC WHERE dwID = '{$dwID2}'");
    $img_id = odbc_result($img_res, 1);

    $image = "{$img_id}.gif";

    if (!file_exists("./{$images}/" . $image))
    $image = "noimage.gif";

    $image = "./image.php?link=" . substr($image, 0, -4);

    echo "
    <td>
    <table>
    <tr>
    <td align='center'><b>{$row['szName']}</b></td>
    </tr>
    <tr>
    <td align='center'><img src='{$image}' border='0' /></td>
    </tr>
    <tr>
    <td align='center'><i>{$row['szDescript']}</i></td>
    </tr>
    <tr>
    <td align='center'><b>{$row['price']}</b> KC</td>
    </tr>
    <tr>
    <td valign='bottom' align='center'>
    <form action=\"./?act={$filename}&selected=1\" method=\"POST\">
    <input type=\"submit\" value=\"Buy!\" />
    <input type=\"hidden\" name=\"item\" value=\"{$row['dwID']}\" />
    </form>
    </div>
    </td>
    </tr>
    </table>
    </td>";
    if ($x == $items_per_row)
    {
    echo "
    </tr>";
    $x = 0;
    }
    $x++;
    }
    if ($y == 0)
    {
    echo "<tr><td colspan='{$items_per_row}'><center>There are no items in this category!</center></td></tr>";
    }
    echo "<tr>
    <td class=\"thead\" width=\"100%\" colspan=\"{$items_per_row}\" align=\"center\" height=\"{$items_per_row}\">
    <div align=\"right\">
    <form action='./' method='GET' name='dd'>
    <input type=\"hidden\" name=\"act\" value=\"{$filename}\"/>
    <select id=\"cat\" name=\"cat\" onChange=\"elem = document.getElementById('cat').value; if (elem != 'dontpickme') { document.dd.submit(); } \">
    <option value=\"dontpickme\">Select category</option>";
    foreach ($cats as $key => $value) {
    echo "<option value=\"{$key}\">{$value}</option>";
    }
    echo "</select></td></tr>";
    }
    else
    {
    $results = odbc_exec($conn, "SELECT szName, price, max_stack FROM $table WHERE dwID={$dwID}");
    $item = odbc_result($results, 1);
    $_item = $item;
    $price = odbc_result($results, 2);
    $max_stack = odbc_result($results, 3);

    if ($max_stack > 1)
    $stackable = "is [adding stacked items is not working: all stacked items will be added as non-stacked]";
    else
    $stackable = "is not";

    part1tr();
    part1('100%',$items_per_row,'center', 1);
    echo "Welcome to $community Power-Up Store <br /><center><font size=\"+1\">Purchase <b>{$item}</b></font></center>";
    part2();
    part2tr();
    parth1tr();
    parth1('100%',$items_per_row,'center');
    echo "&nbsp;";
    parth2();
    parth2tr();
    part1tr();
    part1('100%',$items_per_row,'center', 1);
    if ($kc >= $price)
    {
    if ($_GET['selected'] == 1)
    {
    echo "<div align=\"right\"><b>You have $kc Knight Cash</b></div>";
    echo "How many do you wish to purchase?<br />
    Note: This item $stackable stackable.<br />
    <br />
    <form action='./?act={$filename}&selected=2' method='POST'>
    <input type='hidden' name='item' value='{$dwID}' />
    Amount: <input type='text' name='amount' /><input type='submit' value='Okay!' />
    </form>";
    }
    else
    {
    $amount = intval($_POST['amount']);
    $x = 1;
    while ($x <= 9998 && !$max_purchase)
    {
    $p = $price * $x;

    if ($kc < $p)
    $max_purchase = ($x - 1);

    $x++;
    }
    if ($amount <= $max_purchase)
    {
    $price = $price * $amount;
    if ($kc >= $price)
    {
    if (substr($item, -1) != "s" && $amount > 1)
    $item = $item . "s";
    elseif (substr($item, -1) == "s" && $amount == 1)
    $item = substr($item, 0, -1);

    if ($_GET['selected'] == 2)
    {
    echo "<div align=\"right\"><b>You have $kc Knight Cash</b></div>";
    echo "Are you sure you wish to purchase <b>{$amount} {$item}?</b><br /><br />
    <form action='./?act={$filename}&selected=3' method='POST'>
    <input type='hidden' name='item' value='{$dwID}' />
    <input type='hidden' name='amount' value='{$amount}' />
    <input type='button' value='No' onClick='window.location=\"./?act={$filename}\"' /><input type='submit' value='Yes!' />
    </form>";
    }
    elseif ($_GET['selected'] == 3)
    {
    if (/*$stackable == "is not" && */ $amount > 1)
    {
    $x = 1;
    while ($x <= $amount)
    {
    odbc_exec($conn, "EXEC InsertItem '{$_SESSION['sesuser']}', 2, {$dwID}, {$x}");
    $x++;
    }
    }
    else
    {
    odbc_exec($conn, "EXEC InsertItem '{$_SESSION['sesuser']}', 2, {$dwID}, 1");
    }

    $_price = $price;
    if ($_WHERE == "USERDATA")
    {
    if ($_KC[1] >= $price)
    {
    $_KC[1] -= $price;
    }
    else
    {
    $takeKC = $_KC[1];
    $price -= $takeKC;
    $_KC[1] -= $takeKC;

    if ($_KC[2] >= $price)
    {
    $_KC[2] -= $price;
    }
    else
    {
    $takeKC = $_KC[2];
    $price -= $takeKC;
    $_KC[2] -= $takeKC;
    if ($_KC[3] >= $price)
    {
    $_KC[3] -= $price;
    }
    }
    }
    $x = 1;
    while ($x <= 3)
    {
    if (!empty($_CHAR[$x]))
    @odbc_exec($conn, "UPDATE $_WHERE SET {$kc_column}='{$_KC[$x]}' WHERE strUserID='{$_CHAR[$x]}'");

    $x++;
    }
    }
    else
    {
    $kc -= $price;
    @odbc_exec($conn, "UPDATE $_WHERE SET $kc_col = $kc WHERE strAccountID='{$_SESSION['sesuser']}'");
    }
    if ($_WHERE == "TB_USER")
    {
    $results = odbc_exec($conn, "SELECT $kc_col FROM $_WHERE WHERE strAccountID='{$_SESSION['sesuser']}'");
    $kc = intval(odbc_result($results, 1));
    }
    else
    {
    $kc = 0;
    $results = odbc_exec($conn, "SELECT strCharID1, strCharID2, strCharID3 FROM ACCOUNT_CHAR WHERE strAccountID='{$_SESSION['sesuser']}'");
    while (odbc_fetch_row($results))
    {
    $x = 1;
    while ($x <= 3)
    {
    $char = odbc_result($results, $x);
    if (!empty($char))
    {
    $results2 = odbc_exec($conn, "SELECT $kc_col FROM $_WHERE WHERE strUserID='{$char}'");
    $_CHAR[$x] = $char;
    $_KC[$x] = intval(odbc_result($results2, 1));
    $kc = $kc + $_KC[$x];
    }
    $x++;
    }
    }
    }


    $ip = (getenv(HTTP_X_FORWARDED_FOR)) ? getenv(HTTP_X_FORWARDED_FOR) : getenv(REMOTE_ADDR);

    if ($logs)
    odbc_exec($conn, "INSERT INTO PUS_STORE_LOGS (strAccountID, item, amount, price, kc_left, ip, timestamp) VALUES('{$_SESSION['sesuser']}', '{$_item}', '{$amount}', '{$_price}', '{$kc}', '{$ip}', getdate())");

    echo "<div align=\"right\"><b>You have {$_kc} Knight Cash</b></div><br />";
    echo "Thankyou for your purchase!<br /><br />
    For future reference and in case of any fraud purchases, this order has been recorded.<br /><br />
    You purchased $amount {$item}, bringing the total price to <b>{$_price}</b>
    <br /><br />
    Enjoy your purchase!";

    }

    }
    else
    {
    echo "<div align=\"right\"><b>You have {$kc} Knight Cash</b></div><br />";
    echo "How many do you wish to purchase?<br />
    Note: This item $stackable stackable.<br /><br />
    You cannot purchase $amount of the item <b>{$item}</b>! You don't have enough Knight Cash to afford it.<br />
    The maximum number of the item <b>{$item}</b> that you can purchase is {$max_purchase}!
    <br /><br />
    <form action='./?act={$filename}&selected=2' method='POST'>
    <input type='hidden' name='item' value='{$dwID}' />
    Amount: <input type='text' name='amount' /><input type='submit' value='Okay!' />
    </form>";
    }

    }
    else
    {
    echo "<div align=\"right\"><b>You have {$kc} Knight Cash</b></div><br />";
    echo "How many do you wish to purchase?<br />
    Note: This item $stackable stackable.<br /><br />
    You cannot have more than $max_stack of the item <b>{$item}</b>.
    <br /><br />
    <form action='./?act={$filename}&selected=2' method='POST'>
    <input type='hidden' name='item' value='{$dwID}' />
    Amount: <input type='text' name='amount' /><input type='submit' value='Okay!' />
    </form>";
    }
    }
    }
    else
    {
    echo "<div align=\"right\"><b>You have {$kc} Knight Cash</b></div><br />";
    echo "The <b>{$item}</b> costs <b>{$price}</b> Knight Cash, but you only have <b>{$kc}</b> Knight Cash!<br />
    You must purchase more Knight Cash to be able to afford this!<br /><br />
    <a href='javascript: history.go(-1);'><< Go back</a>";
    }
    part2();

    }

    echo '
    <tr>
    <td align="center" height="35" valign="middle" colspan="' . $items_per_row . '" background="./skins/default/cat_top_mid.gif"><center><strong>Copyright to twostars &copy;, 2008.</strong></center></td>
    </tr>';

    }
    ?>




    the problem is the odbc connection who can help ??? thx


  2. #2
    Sorcerer Supreme OMEGAbuffer is offline
    Member +Rank
    Jan 2008 Join Date
    301Posts

    Re: the pws script

    Code:
    <?php
    
    $conn = odbc_connect("$dbname","$dbuser","$dbpass");
    
    /* CONFIGURATION */
    $community = "IceTeaKO's";
    $table = "PUS_STORE";
    $items_per_row = 5;
    $filename = "pus";
    $images = "pus_images";
    Here?

  3. #3
    Newbie yuiyui is offline
    MemberRank
    Aug 2007 Join Date
    9Posts

    Re: the pws script

    no i fix it and its the odbc is not fix



Advertisement