コード例 #1
0
ファイル: sheet_lib.php プロジェクト: EZDM/omeyocan
function assign_object($obj_id, $new_owner, $copy = false, $by_user = false, $uses = -1, $new_name = false)
{
    global $db, $prefix;
    $error = '';
    $query = $db->DoQuery("SELECT username \n\t\t\t\tFROM {$prefix}users WHERE username='******'");
    $row_usr = $db->Do_Fetch_Assoc($query);
    if (!$row_usr) {
        $error = "Utente non esistente";
    }
    $more_query = '';
    if ($by_user) {
        $more_query = "AND owner = '{$by_user}'";
    }
    $query = $db->DoQuery("SELECT * FROM {$prefix}objects \n\t\t\t\tWHERE id='{$obj_id}'  {$more_query}");
    $row = $db->Do_Fetch_Assoc($query);
    if (!$row || $row['id'] == '') {
        $error = "Oggetto non esistente";
    }
    if (!$row['equipped'] && $by_user) {
        $error .= "Non puoi consegnare un oggetto che non trasporti";
    }
    get_obj_name_and_uses($obj_id, $obj_name, $dummy);
    if ($error == '') {
        $residuo = get_user_space($new_owner);
        $total_space = $row['size'];
        if ($residuo - $total_space < 0) {
            $error = "L'utente non pu&ograve; trasportare l'oggetto:<br>" . "spazio residuo: {$residuo}<br>spazio richiesto: {$total_space}<br>";
        }
    }
    if ($error == '') {
        if ($uses > 0) {
            $row['uses'] = $uses;
        }
        if ($new_name) {
            $row['name'] = $new_name;
        }
        if ($copy) {
            $db->DoQuery("INSERT INTO {$prefix}objects\n\t\t\t\t\t\t(name,description,uses,image_url,owner,equipped,size,category,\n\t\t\t\t\t\t visible_uses, expire_span, shop_return,random_img)\n\t\t\t\t\t\tVALUES('{$row['name']}','{$row['description']}','{$row['uses']}',\n\t\t\t\t\t\t\t'{$row['image_url']}','{$new_owner}','1','{$row['size']}',\n\t\t\t\t\t\t\t'{$row['category']}','{$row['visible_uses']}','{$row['expire_span']}',\n\t\t\t\t\t\t\t'{$row['shop_return']}','{$row['random_img']}')");
            $new_id = mysql_insert_id();
            $error .= "Oggetto assegnato correttamente<br>";
            if ($row['expire_span'] > 0) {
                $expire_time = time() + $row['expire_span'] * 60;
                $db->DoQuery("INSERT INTO {$prefix}temp_obj \n\t\t\t\t\t\t\t(id, expire_time, shop_return)\n\t\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t\t('{$new_id}', '{$expire_time}', '{$row['shop_return']}')");
                $error .= "<br>L'oggetto scadra' il:" . date("d/m/Y H:i", $expire_time);
            }
            include_once './lib/alarms.php';
            object_assignement($new_owner, $row['name']);
        } else {
            $db->DoQuery("UPDATE {$prefix}objects SET owner='{$new_owner}'\n\t\t\t\t\t\tWHERE id='{$obj_id}' AND owner='{$by_user}'");
            include_once './lib/alarms.php';
            object_moves($new_owner, $by_user, $obj_name);
            $error .= "Oggetto assegnato correttamente<br>";
        }
    }
    return $error;
}
コード例 #2
0
ファイル: shop_lib.php プロジェクト: EZDM/omeyocan
function pay($qty, $from, $to, $check_only = false, $only_equipped = true, $equip = 1)
{
    global $db, $prefix, $money_group, $money_group_size, $money_name, $shopper;
    $space_required = ($qty / $money_group + 1) * $money_group_size;
    // Check if buyer own money
    $money = get_total_user_money($from, $only_equipped);
    if ($money < $qty) {
        return "Denaro non disponibile<br>";
    }
    include_once './lib/sheet_lib.php';
    // Shopper has infinite space
    if ($to != $shopper && $equip) {
        if (get_user_space($to) - $space_required < 0) {
            return "Spazio non sufficiente per ricevere i soldi<br>";
        }
    }
    if ($check_only) {
        return;
    }
    remove_money($qty, $from);
    assign_money($qty, $to, $equip);
    include_once "./lib/alarms.php";
    record_payment($from, $to, $qty);
    return "Pagamento effettuato<br>";
}
コード例 #3
0
ファイル: sheet.php プロジェクト: EZDM/omeyocan
function sheet_page_equip()
{
    global $db, $x7c, $prefix, $x7s, $print;
    $pg = $_GET['pg'];
    $body = '';
    $errore = '';
    include_once './lib/sheet_lib.php';
    include_once './lib/shop_lib.php';
    global $money_name;
    if (isset($_GET['moduse']) && checkIfMaster()) {
        if (!isset($_POST['use']) || !isset($_POST['id'])) {
            die("Bad form 3");
        }
        $db->DoQuery("UPDATE {$prefix}objects SET uses='{$_POST['use']}'\n\t\t\t\tWHERE id='{$_POST['id']}'");
        include_once './lib/alarms.php';
        object_uses($pg, $_POST['id'], $_POST['use']);
    }
    if (isset($_GET['delete']) && ($x7s->username == $pg || checkIfMaster())) {
        $db->DoQuery("DELETE FROM {$prefix}objects WHERE id='{$_GET['delete']}'");
    }
    if (isset($_GET['equiptgl']) && ($x7s->username == $pg || checkIfMaster())) {
        $query = $db->DoQuery("SELECT equipped,name,size \n\t\t\t\tFROM {$prefix}objects WHERE id='{$_GET['equiptgl']}'");
        $row = $db->Do_Fetch_Assoc($query);
        if (!$row) {
            $errore = "Oggetto non esistente";
        } else {
            $equip_value = 0;
            $azione = "";
            $action_ok = true;
            if (!$row['equipped']) {
                $equip_value = 1;
                $azione = "equipaggiato";
                if (get_user_space($pg) - $row['size'] < 0) {
                    $errore = "Spazio insufficiente per equipaggiare l'oggetto";
                    $action_ok = false;
                }
            } else {
                $equip_value = 0;
                $azione = "depositato";
                if (get_user_space($pg) + $row['size'] < 0) {
                    $errore = "Impossibile depositare l'oggetto";
                    $action_ok = false;
                }
            }
            if ($action_ok) {
                $db->DoQuery("UPDATE {$prefix}objects \n\t\t\t\t\t\tSET equipped='{$equip_value}' WHERE id='{$_GET['equiptgl']}'");
                include './lib/alarms.php';
                toggle_equip_log($row['name'], $azione);
                $query = $db->DoQuery("SELECT position\t\t\n\t\t\t\t\t\tFROM {$prefix}users WHERE username='******'");
                $row_msg = $db->Do_Fetch_Assoc($query);
                if ($row_msg && $row_msg['position'] != "Mappa" && $row_msg['position'] != "") {
                    include_once "./lib/message.php";
                    $txt = "L\\'utente {$pg} ha {$azione} l\\'oggetto {$row['name']}";
                    alert_room($row_msg['position'], $txt);
                }
                header("location: index.php?act=sheet&page=equip&pg={$pg}&refreshparent");
            }
        }
    }
    if (isset($_GET['pay']) && ($x7s->username == $pg || checkIfMaster())) {
        global $shopper;
        if (!isset($_POST['owner']) || !isset($_POST['amount']) || !$_POST['owner'] || !$_POST['amount']) {
            $errore = "Non hai specificato il destinatario o l'ammontare";
        } else {
            $query = $db->DoQuery("SELECT count(*) AS cnt\n\t\t\t\t\tFROM {$prefix}users WHERE username='******'owner']}'");
            $row = $db->Do_Fetch_Assoc($query);
            if ((!$row || $row['cnt'] == 0) && $_POST['owner'] != $shopper) {
                $errore = "Utente non esistente";
            } else {
                $errore = pay($_POST['amount'], $pg, $_POST['owner']);
            }
        }
    }
    if (isset($_GET['split']) && ($x7s->username == $pg || checkIfMaster())) {
        if (!isset($_POST['amount']) || !isset($_POST['group'])) {
            die("Bad form 2");
        }
        $errore = split_money($_POST['amount'], $pg, $_POST['group']);
    }
    if (isset($_GET['group_money']) && ($x7s->username == $pg || checkIfMaster())) {
        group_money($pg);
    }
    if (isset($_GET['assign']) && ($x7s->username == $pg || checkIfMaster())) {
        if (!isset($_POST['owner']) || !isset($_POST['id'])) {
            die("Bad form owner: {$_POST['owner']} id: {$_POST['id']}");
        }
        $dummy = '';
        get_obj_name_and_uses($_POST['id'], $obj, $dummy);
        //keys duplicates, and does not disappera from my sheet
        if (preg_match("/^masterkey/", $obj)) {
            list($pre, $name) = split("masterkey_", $obj);
            $obj = "key_{$name}";
            if (!isset($_POST['grants']) || $_POST['grants'] <= 0 || $_POST['grants'] == '') {
                $_POST['grants'] = -1;
            }
            $errore .= assign_object($_POST['id'], $_POST['owner'], true, $pg, $_POST['grants'], $obj);
        } else {
            $errore .= assign_object($_POST['id'], $_POST['owner'], false, $pg);
        }
    }
    $body .= "<script language=\"javascript\" type=\"text/javascript\">\n\t\t\t\tfunction confirmDrop(id){\n\t\t\t\t\tif(confirm(\"Vuoi davvero buttare l'oggetto?\")){\n\t\t\t\t\t\tlocation.href='index.php?act=sheet&page=equip&pg={$pg}&delete='+id;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t}\n\n\t\t\tfunction requestReady_channel1(){\n\t\t\t\tif(httpReq2){\n\t\t\t\t\tif(httpReq2.readyState == 4){\n\t\t\t\t\t\tif(httpReq2.status == 200){\n\t\t\t\t\t\t\tvar dataArray = httpReq2.responseText;\n\t\t\t\t\t\t\tdocument.getElementById('objects').innerHTML = dataArray;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction do_refresh(search){\n\t\t\t\tjd=new Date();\n\t\t\t\tnocache = jd.getTime();\n\t\t\t\ttext = search.value;\n\t\t\t\turl = './index.php?act=sheet&page=equip&pg={$pg}&search=' + text + '&nc=' + nocache;\n\t\t\t\tif(window.XMLHttpRequest){\n\t\t\t\t\ttry {\n\t\t\t\t\t\thttpReq2 = new XMLHttpRequest();\n\t\t\t\t\t} catch(e) {\n\t\t\t\t\t\thttpReq2 = false;\n\t\t\t\t\t}\n\t\t\t\t}else if(window.ActiveXObject){\n\t\t\t\t\ttry{\n\t\t\t\t\t\thttpReq2 = new ActiveXObject('Msxml2.XMLHTTP');\n\t\t\t\t\t}catch(e){\n\t\t\t\t\t\ttry{\n\t\t\t\t\t\t\thttpReq2 = new ActiveXObject('Microsoft.XMLHTTP');\n\t\t\t\t\t\t}catch(e){\n\t\t\t\t\t\t\thttpReq2 = false;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\thttpReq2.onreadystatechange = requestReady_channel1;\n\t\t\t\thttpReq2.open('GET', url, true);\n\t\t\t\thttpReq2.send('');\n\t\t\t}\n\t\t\t</script>";
    $body .= "<div id=\"search_box\">\n\t<input type=\"text\" size=20 onkeyup=\"javascript:do_refresh(this)\"\n\tonclick=\"this.value=''\" \n\tonblur=\"this.value=!this.value?'cerca oggetto':this.value;\"\n\tvalue=\"cerca oggetto\">\n\t</div>\n";
    $body .= "<div id=\"objects\">\n";
    $obj_div = "";
    $refine_query = "";
    if (isset($_GET['search']) && $_GET['search']) {
        $refine_query = " AND name like '%{$_GET['search']}%'";
    }
    $query = $db->DoQuery("SELECT * FROM {$prefix}objects\n\t\t\tWHERE owner='{$pg}' {$refine_query} ORDER BY equipped DESC, name");
    $room = '';
    while ($row = $db->Do_Fetch_Assoc($query)) {
        if ($pg != $x7s->username && $row['equipped'] || $pg == $x7s->username || checkIfMaster()) {
            $more_form = '';
            $obj_name = $row['name'];
            $description = $row['description'];
            $dimensione = "";
            $disabled = "";
            if (!$row['equipped']) {
                $disabled = "style=\"color: #aeaeae;\"";
            }
            switch ($row['size']) {
                case 0:
                    $dimensione = "Minuscolo";
                    break;
                case 1:
                    $dimensione = "Piccolo";
                    break;
                case 2:
                    $dimensione = "Medio";
                    break;
                case 5:
                    $dimensione = "Grande";
                    break;
                case -1:
                    $dimensione = "Capienza piccola";
                    break;
                case -2:
                    $dimensione = "Capienza media";
                    break;
                case -5:
                    $dimensione = "Capienza grande";
                    break;
            }
            if ($row['uses'] == 0) {
                $obj_name .= " [inutilizzabile]";
            }
            if (preg_match("/^key_/", $row['name']) || preg_match("/^masterkey_/", $row['name'])) {
                $master_key = 0;
                $master_string = '';
                if (preg_match("/^key_/", $row['name'])) {
                    list($pre, $name) = split("key_", $row['name']);
                } elseif (preg_match("/^masterkey_/", $row['name'])) {
                    list($pre, $name) = split("masterkey_", $row['name']);
                    $master_key = 1;
                    $master_string = " (chiave master)";
                }
                if (strcasecmp($_GET['pg'], $x7s->username) == 0 || checkIfMaster()) {
                    //we make clickable only key of my sheet
                    if ($master_key) {
                        //This a master key
                        $more_form = ' <tr>
							<td>Usi concessi (vuoto per illimitati):</td>
							<td><input type="text" name="grants" class="text_input" size=2>
							</td>
              </tr>';
                    }
                    $obj_name = '<a onClick="javascript: hdl=window.open(\'\',\'main\'); hdl.location.href=\'index.php?act=frame&room=' . $name . '&key_used=' . $row['id'] . '\'; window.location.reload(); hdl.focus(); "> Stanza di ' . $name . $master_string . '</a>';
                } else {
                    $obj_name = "Stanza di {$name}";
                }
            }
            if ($row['name'] == $money_name) {
                $obj_name .= ": {$row['uses']}";
            }
            $visible_uses = '';
            if ($row['visible_uses']) {
                if ($row['uses'] >= 0) {
                    $visible_uses = "<br>Usi rimasti: {$row['uses']}";
                } else {
                    $visible_uses = "<br>Usi rimasti: illimitati";
                }
            }
            $expire_string = '';
            if ($row['expire_span'] > 0) {
                $query_expire = $db->DoQuery("SELECT expire_time \n\t\t\t\t\t\tFROM {$prefix}temp_obj\n\t\t\t\t\t\tWHERE id = '{$row['id']}'");
                $row_expire = $db->Do_Fetch_Assoc($query_expire);
                if ($row_expire) {
                    $expire_string = "<br>(Nullificazione: " . date("d/m/Y H:i", $row_expire['expire_time']) . ")";
                }
            }
            $obj_div .= "<table width=100%> <tr> <td class=\"obj\">\n\t\t\t\t<img width=100 height=100 src=\"{$row['image_url']}\" align=\"left\">\n        <div {$disabled}>\n        <b>{$obj_name}</b>\n        <br>Dimensione: {$dimensione}\n\t\t\t\t{$visible_uses}\n\t\t\t\t{$expire_string}\n        <p>{$description}</p>\n        </div> </td> </tr> </table>";
            if ($pg == $x7s->username || checkIfMaster()) {
                $money_qty = "";
                $money_form = "";
                if ($row['name'] == $money_name) {
                    if ($row['equipped']) {
                        $money_form = "\n\t\t\t\t\t\t\t<form action=\"index.php?act=sheet&page=equip&pg={$pg}&split=1\"\n\t\t\t\t\t\t\tmethod=\"post\" name=\"split\">\n\t\t\t\t\t\t\t<input type=\"hidden\" name=\"id\" value=\"{$row['id']}\">\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td>\n\t\t\t\t\t\t\t<input type=\"button\" class=\"button\" value=\"Raggruppa tutti\"\n\t\t\t\t\t\t\tonClick=\"javascript: location.href='index.php?act=sheet&page=equip&pg={$pg}&group_money'\">\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td>\n\t\t\t\t\t\t\t<input type=\"submit\" class=\"button\" value=\"Dividi\">" . "<input type=\"text\" name=\"amount\" class=\"text_input\" size=5>\n\t\t\t\t\t\t\t<input type=\"hidden\" name=\"group\" value=\"{$row['id']}\">\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t</form>\n\t\t\t\t\t\t\t<form action=\"index.php?act=sheet&page=equip&pg={$pg}&pay=1\"\n\t\t\t\t\t\t\tmethod=\"post\" name=\"payment\">\n\t\t\t\t\t\t\t<input type=\"hidden\" name=\"id\" value=\"{$row['id']}\">\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td>Paga a:</td>\n\t\t\t\t\t\t\t<td>\n\t\t\t\t\t\t\t<input type=\"text\" name=\"owner\" class=\"text_input\" size=10>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td>\n\t\t\t\t\t\t\tAmmontare:</td>\n\t\t\t\t\t\t\t<td>\n\t\t\t\t\t\t\t<input type=\"text\" name=\"amount\" class=\"text_input\" size=5>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td><input type=\"submit\" class=\"button\" value=\"Paga\"></td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t</form>";
                    }
                }
                $equip_text = "Deposita";
                if (!$row['equipped']) {
                    $equip_text = "Equipaggia";
                }
                $obj_div .= "\n          <table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n\t\t\t\t\t<form action=\"index.php?act=sheet&page=equip&pg={$pg}&assign=1\"\n\t\t\t\t\tmethod=\"post\" name=\"object_assign\">\n          <input type=\"hidden\" name=\"id\" value=\"{$row['id']}\">\n          <tr>\n          <td>Dai a:</td>\n          <td><input type=\"text\" name=\"owner\" class=\"text_input\"></td>\n          <td><input type=\"submit\" class=\"button\" value=\"Dai\"></td>\n          </tr>\n          {$more_form}\n          </form>\n          <tr>\n          <td><input type=\"button\" class=\"button\" value=\"Butta\"\n\t\t\t\t\tonClick=\"javascript: confirmDrop({$row['id']})\">\n          <input type=\"button\" class=\"button\" value=\"{$equip_text}\"\n\t\t\t\t\tonClick=\"javascript: location.href='index.php?act=sheet&page=equip&pg={$pg}&equiptgl={$row['id']}'\"></td>\n          </tr>\n\t\t\t\t\t{$money_form}\n          </table>";
            }
            if (checkIfMaster() && $row['name'] != $money_name) {
                $obj_div .= "<form action=\"index.php?act=sheet&page=equip&pg={$pg}&moduse=1\"" . " method=\"post\" name=\"object_moduse\">\n          <table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n          <input type=\"hidden\" name=\"id\" value=\"{$row['id']}\">\n          <tr>\n          <td>Usi:</td>\n          <td><input type=\"text\" name=\"use\" class=\"text_input\" size=2 value=\"{$row['uses']}\"></td>\n          <td><input type=\"submit\" class=\"button\" value=\"Cambia\"></div></td>\n          </tr>\n          </table>\n          ";
                $obj_div .= "</form>\n";
            }
            $obj_div .= "<br><br>\n";
        }
    }
    if (isset($_GET['search'])) {
        echo $obj_div;
        return "";
    }
    $body .= $obj_div;
    $body .= "</div>\n";
    $body .= '<div class="counter" id="spazio">' . get_user_space($pg) . '</div>';
    if ($errore != '') {
        $body .= '<script language="javascript" type="text/javascript">
					function close_err(){
						document.getElementById("errore").style.visibility="hidden";
				}
				</script>
				<div id="errore" class="errore">' . $errore . '
				<br><br><input name="ok" type="button" class="button" value="OK" onClick="javascript: close_err(); window.location.href=\'index.php?act=sheet&page=equip&pg=' . $_GET['pg'] . '\';">
				</div>';
    }
    return $body;
}