コード例 #1
0
ファイル: min_side_user.php プロジェクト: Kuzat/kofradia
    /**
     * Økter
     */
    protected static function page_ses()
    {
        function vis_ip_list($ip)
        {
            static $mod = NULL;
            if (is_null($mod)) {
                $mod = access::has("mod");
            }
            $list = explode(";", $ip);
            if ($mod) {
                foreach ($list as &$val) {
                    $val = '<a href="' . ess::$s['rpath'] . '/admin/brukere/finn?ip=' . $val . '">' . $val . '</a>';
                }
            }
            return implode("<br />\n", $list);
        }
        // logge ut noen økter
        if (isset($_POST['delete'])) {
            $delete = array();
            if (isset($_POST['session'])) {
                foreach ($_POST['session'] as $del) {
                    $del = intval($del);
                    if ($del != 0) {
                        $delete[] = $del;
                    }
                }
            }
            if (count($delete) == 0) {
                ess::$b->page->add_message("Fant ingen økter å logge ut.", "error");
                redirect::handle(page_min_side::addr());
            } else {
                // forsøk å logg ut de merkede øktene
                $delete = implode(",", $delete);
                $dels = \Kofradia\DB::get()->exec("UPDATE sessions SET ses_active = 0, ses_logout_time = " . time() . " WHERE ses_active = 1 AND ses_expire_time > " . time() . " AND ses_u_id = " . page_min_side::$active_user->id . " AND ses_id != " . login::$info['ses_id'] . " AND FIND_IN_SET(ses_id, '{$delete}')");
                ess::$b->page->add_message("<b>{$dels}</b> økt" . ($dels == 1 ? '' : 'er') . " ble logget ut.");
                redirect::handle(page_min_side::addr());
            }
        }
        ess::$b->page->add_title("Økter");
        echo '
	<div class="bg1_c">
		<h1 class="bg1">Aktive økter<span class="left2"></span><span class="right2"></span></h1>
		<div class="bg1">
			<p>Her er en oversikt over alle stedene hvor brukeren er logget inn uten å ha blitt logget ut manuelt og som fortsatt er aktive.</p>';
        $time = time();
        $result = \Kofradia\DB::get()->query("SELECT * FROM sessions WHERE ses_u_id = " . page_min_side::$active_user->id . " AND ses_expire_time > {$time} AND ses_active = 1 ORDER BY ses_id DESC");
        echo '
			<form action="" method="post">
				<table class="table center">
					<thead>
						<tr>
							<th>Opprettet (<a href="#" class="box_handle_toggle" rel="session[]">Merk alle</a>)</th>
							<th>IP-er</th>
							<th>Type</th>
							<th>Varighet</th>
							<th>Hits</th>
							<th>Siste visning</th>
						</tr>
					</thead>
					<tbody>';
        $i = 0;
        while ($row = $result->fetch()) {
            $class = new attr("class");
            if ($row['ses_id'] != login::$info['ses_id']) {
                $class->add("box_handle");
            }
            $i++;
            if ($row['ses_id'] == login::$info['ses_id']) {
                $class->add("highlight");
            } elseif ($i % 2 == 0) {
                $class->add("color");
            }
            $type = $row['ses_expire_type'];
            $type = $type == LOGIN_TYPE_TIMEOUT ? 'Tidsavbrudd' : ($type == LOGIN_TYPE_BROWSER ? 'Lukke nettleser' : 'Alltid innlogget');
            echo '
						<tr' . $class->build() . '>
							<td class="r">' . ($row['ses_id'] == login::$info['ses_id'] ? '' : '<input type="checkbox" name="session[]" value="' . $row['ses_id'] . '" /> ') . ess::$b->date->get($row['ses_created_time'])->format("d.m.Y H:i") . '</td>
							<td>' . vis_ip_list($row['ses_ip_list']) . '</td>
							<td class="c">' . $type . '</td>
							<td class="c">' . ($row['ses_expire_type'] == LOGIN_TYPE_ALWAYS ? 'Alltid' : game::timespan($row['ses_expire_time'], game::TIME_ABS)) . '</td>
							<td class="r">' . game::format_number($row['ses_hits']) . '</td>
							<td class="r">' . ess::$b->date->get($row['ses_last_time'])->format("d.m.Y H:i") . ($row['ses_last_time'] != 0 ? '<br />' . game::timespan($row['ses_last_time'], game::TIME_ABS) : '') . '</td>
						</tr>';
        }
        echo '
					</tbody>
				</table>
				<p class="c">' . show_sbutton("Logg ut merkede", 'name="delete"') . '</p>
			</form>
		</div>
	</div>';
        // hent øktene på denne siden
        $pagei = new pagei(pagei::ACTIVE_GET, "side", pagei::PER_PAGE, 7);
        $result = $pagei->query("SELECT ses_id, ses_created_time, ses_ip_list, ses_expire_type, ses_expire_time, ses_active, ses_hits, ses_last_time, ses_last_ip FROM sessions WHERE ses_u_id = " . page_min_side::$active_user->id . " ORDER BY ses_last_time DESC");
        echo '
	<div class="bg1_c">
		<h1 class="bg1">Tidligere økter<span class="left2"></span><span class="right2"></span></h1>
		<div class="bg1">
			<p>Dette er en oversikt over alle innlogginger på brukeren.</p>
			<table class="table' . ($pagei->pages == 1 ? ' tablemb' : '') . ' center">
				<thead>
					<tr>
						<th>ID</th>
						<th>Opprettet</th>
						<th>IP</th>
						<th>Type</th>
						<th>Status</th>
						<th>Hits</th>
						<th>Siste visning</th>
					</tr>
				</thead>
				<tbody>';
        $i = 0;
        while ($row = $result->fetch()) {
            $type = $row['ses_expire_type'];
            $type = $type == LOGIN_TYPE_TIMEOUT ? 'Tidsavbrudd' : ($type == LOGIN_TYPE_BROWSER ? 'Lukke nettleser' : 'Alltid innlogget');
            echo '
					<tr' . (++$i % 2 == 0 ? ' class="color"' : '') . '>
						<td class="r">' . $row['ses_id'] . '</td>
						<td class="r">' . ess::$b->date->get($row['ses_created_time'])->format("d.m.Y H:i") . '<br /><span style="color: #888">' . game::timespan($row['ses_created_time'], game::TIME_ABS) . '</span></td>
						<td class="c">' . vis_ip_list($row['ses_ip_list']) . '</td>
						<td class="c">' . $type . '</td>
						<td class="c">' . ($row['ses_active'] == 1 ? $row['ses_expire_time'] < $time ? 'Ikke aktiv' : ($row['ses_expire_type'] == LOGIN_TYPE_ALWAYS ? '<b>Aktiv</b><br />Alltid logget inn' : '<b>' . game::timespan($row['ses_expire_time'], game::TIME_ABS) . '</b>') : 'Logget ut') . '</td>
						<td class="r">' . game::format_number($row['ses_hits']) . '</td>
						<td class="r">' . ess::$b->date->get($row['ses_last_time'])->format("d.m.Y H:i") . ($row['ses_last_time'] != 0 ? '<br /><span style="color: #888">' . game::timespan($row['ses_last_time'], game::TIME_ABS) . '</span>' : '') . '</td>
					</tr>';
        }
        echo '
				</tbody>
			</table>' . ($pagei->pages > 1 ? '
			<p class="c">' . $pagei->pagenumbers() . '</p>' : '') . '
		</div>
	</div>';
    }
コード例 #2
0
ファイル: fengsel.php プロジェクト: Kuzat/kofradia
    /**
     * Vis fengsel
     */
    protected function show()
    {
        // er vi i fengsel nå?
        if ($wait = $this->up->fengsel_wait()) {
            ess::$b->page->add_js_domready('$("fengsel_dusor").focus();');
            echo '
<div class="bg1_c xsmall">
	<h1 class="bg1">Du er i fengsel<span class="left"></span><span class="right"></span></h1>
	<p class="h_right"><a href="node/16">Hjelp</a></p>
	<div class="bg1">
		<p>Du befinner deg for øyeblikket i fengsel og slipper ut om ' . game::counter($wait, true) . '.</p>' . (!$this->up->is_nostat() ? '
		<form action="" method="post">
			<input type="hidden" name="sid" value="' . login::$info['ses_id'] . '" />
			<input type="hidden" name="expire" value="' . $this->up->data['up_fengsel_time'] . '" />
			<dl class="dd_right">
				<dt>Dusør for å bryte deg ut</dt>
				<dd><input type="text" class="styled w80" name="amount" id="fengsel_dusor" value="' . game::format_cash($this->up->data['up_fengsel_dusor']) . '" /></dd>
			</dl>
			<p class="c">' . show_sbutton($this->up->data['up_fengsel_dusor'] > 0 ? "Endre dusør" : "Sett dusør", 'name="dusor"') . '</p>
			<p class="c">Spilleren som bryter ut mottar kun ' . self::DUSOR_PROFIT * 100 . ' % av dusøren.</p>
		</form>' : '') . '
	</div>
</div>';
        }
        // sortering
        $sort = new sorts("sort");
        $sort->append("asc", "Spiller", "up_name");
        $sort->append("desc", "Spiller", "up_name DESC");
        $sort->append("asc", "Wanted nivå", "up_wanted_level, up_fengsel_time DESC");
        $sort->append("desc", "Wanted nivå", "up_wanted_level DESC, up_fengsel_time DESC");
        $sort->append("asc", "Tid igjen", "up_fengsel_time");
        $sort->append("desc", "Tid igjen", "up_fengsel_time DESC");
        $sort->set_active(requestval("sort"), 5);
        // hent folk i fengsel
        $sort_info = $sort->active();
        $pagei = new pagei(pagei::ACTIVE_GET, "side", pagei::PER_PAGE, 15);
        $result = $pagei->query("\n\t\t\tSELECT up_id, up_name, up_access_level, up_fengsel_time, up_fengsel_num, up_fengsel_dusor, ROUND(up_fengsel_dusor * " . self::DUSOR_PROFIT . ") up_fengsel_dusor_get, up_wanted_level\n\t\t\tFROM users_players\n\t\t\tWHERE up_fengsel_time > " . time() . " AND up_access_level != 0\n\t\t\tORDER BY {$sort_info['params']}");
        $num = $result->rowCount();
        echo '
<div class="bg1_c ' . ($num == 0 ? 'xsmall' : 'xlarge') . '">
	<h1 class="bg1">Fengsel<span class="left"></span><span class="right"></span></h1>
	<p class="h_right"><a href="node/16">Hjelp</a></p>
	<div class="bg1">
		<form action="" method="post">
			<p class="c dark">Ditt wanted nivå er på ' . game::format_number($this->up->data['up_wanted_level'] / 10, 1) . ' %.</p>';
        if ($num == 0) {
            echo '
			<p class="c dark">Ingen er i fengselet for øyeblikket.</p>
			<p class="c"><a href="' . htmlspecialchars(game::address("fengsel", $_GET)) . '" class="button">Oppdater</a></p>';
        } else {
            echo '
			<table class="table center" width="100%">
				<thead>
					<tr>
						<th>Spiller ' . $sort->show_link(0, 1) . '</th>
						<th>Wanted<br />nivå ' . $sort->show_link(2, 3) . '</th>
						<th>Utbrytning<br />sannsynlighet</th>
						<th>Ca. poeng</th>
						<th>Dusør</th>
						<th>Tid igjen ' . $sort->show_link(4, 5) . '</th>
					</tr>
				</thead>
				<tbody>';
            $i = 0;
            while ($row = $result->fetch()) {
                $prefix = "";
                $attr = new attr("class");
                if (++$i % 2 == 0) {
                    $attr->add("color");
                }
                if (!$this->up->fengsel_check()) {
                    $attr->add("box_handle");
                    $prefix = '<input type="radio" name="up_id" value="' . $row['up_id'] . '_' . $row['up_fengsel_time'] . '_' . $row['up_fengsel_dusor'] . '" /> ';
                }
                $time = $row['up_fengsel_time'] - time();
                $prob = self::calc_prob($time, $row['up_wanted_level'] / 10);
                $points = self::calc_points($prob);
                echo '
					<tr' . $attr->build() . '>
						<td>' . $prefix . game::profile_link($row['up_id'], $row['up_name'], $row['up_access_level']) . '</td>
						<td class="c">' . game::format_number($row['up_wanted_level'] / 10, 1) . ' %</td>
						<td class="c">' . game::format_number($prob, 1) . ' %</td>
						<td class="c">' . game::format_num($points) . '</td>
						<td class="r nowrap">' . game::format_cash($row['up_fengsel_dusor_get']) . '</td>
						<td class="r">' . game::counter($time) . '</td>
					</tr>';
            }
            echo '
				</tbody>
			</table>
			<p class="c">' . (($wait = $this->up->fengsel_wait()) == 0 ? '
				' . show_sbutton("Bryt ut", 'name="brytut"') : '
				Du er i fengsel og slipper ut om ' . game::counter($wait, true) . '.
			</p>
			<p class="c">') . '
				<a href="' . htmlspecialchars(game::address("fengsel", $_GET)) . '" class="button">Oppdater</a>
			</p>';
            // flere sider?
            if ($pagei->pages > 1) {
                echo '
			<div class="hr"></div>
			<p class="c">
				' . $pagei->pagenumbers() . '
			</p>';
            }
        }
        echo '
		</form>
	</div>
</div>';
        // testing
        if (!MAIN_SERVER || access::is_nostat() && access::has("mod")) {
            echo '
<div class="bg1_c xxsmall bg1_padding">
	<h1 class="bg1">' . (MAIN_SERVER ? 'No-stat' : 'Testing') . '<span class="left"></span><span class="right"></span></h1>
	<div class="bg1">
		<form action="" method="post">' . ($this->up->fengsel_check() ? '
			<p class="c">' . show_sbutton("Gå ut av fengsel", 'name="remove"') . '</p>' : '
			<dl class="dd_right dl_2x">
				<dt>Tid</dt>
				<dd><input type="text" name="time" value="' . htmlspecialchars(postval("time", 20)) . '" class="styled w40" /> sekunder</dd>
			</dl>
			<p class="c">' . show_sbutton("Gå inn i fensgel") . '</p>') . '
		</form>
	</div>
</div>';
        }
    }
コード例 #3
0
ファイル: poker.php プロジェクト: Kuzat/kofradia
    protected function show_active()
    {
        echo '
<div class="bg1_c ' . (access::has("admin") ? 'xmedium' : 'small') . '">
	<h1 class="bg1">Utfordre en spiller<span class="left"></span><span class="right"></span></h1>
	<p class="h_right"><a href="' . ess::$s['relative_path'] . '/node/28">Hjelp</a></p>
	<div class="bg1">';
        // hent alle utfordringene som utfordrer..
        $result = \Kofradia\DB::get()->query("SELECT poker_id, poker_starter_up_id, poker_time_start, poker_starter_cards, poker_cash FROM poker WHERE poker_state = 2 ORDER BY poker_cash");
        $num = $result->rowCount();
        // javascript for oppdatering
        ess::$b->page->add_js_domready('
	stuff = {
		interval: 3000, // hvert 3. sek
		active: true,
		init: function()
		{
			this.table = $("poker_players_table");
			this.players_true = $("poker_players_true");
			this.players_false = $("poker_players_false");
			this.tbody = $("poker_players");
			this.info = new Element("p", {"class": "c"}).inject(this.players_true, "before");
			this.start_timer();
		},
		start_timer: function()
		{
			this.info.set("text", "Oppdatering aktivert.");
			
			// sett events for aktiv/inaktiv
			var self = this;
			document.addEvents({
				"active": function()
				{
					if (self.active) return;
					
					// start timer og oppdater
					self.active = true;
					self.startUpdateTimer();
					self.update();
				},
				"idle": function()
				{
					// avbryt mulig xhr og stopp timer
					self.xhr.cancel();
					$clear(self.timer);
					self.active = false;
				}
			});
			
			// sett opp ajax objektet
			this.xhr = new Request({
				"url": relative_path + "/ajax/poker_challengers",
				"autoCancel": true
			});
			
			this.xhr.addEvents({
				"success": function(text, xml)
				{
					// vis sist oppdatert tidspunkt
					var d = new Date($time()+window.servertime_offset);
					self.info.set("html", "Oppdatert " + str_pad(d.getHours()) + ":" + str_pad(d.getMinutes()) + ":" + str_pad(d.getSeconds()));
					
					// hent ut spillerene
					var players = JSON.decode(text);
					
					if (players.length > 0)
					{
						self.players_true.setStyle("display", "block");
						self.players_false.setStyle("display", "none");
						
						// sjekk om vi har merket noen
						selected = false;
						$$("#poker_players_true input[type=radio]").each(function(elm)
						{
							if (elm.checked)
							{
								selected = elm.value;
							}
						});
						
						// fjern alle nåværende spillere
						self.tbody.empty();
						
						// legg til nye spillere
						i = 0;
						players.each(function(row)
						{
							tr = new Element("tr");
							if (!row.self) tr.addClass("box_handle");
							if (i == 1) { tr.addClass("color"); }
							i++;
							if (i == 2) { i = 0; }
							new Element("td", {"html": row.player}).inject(tr);
							new Element("td", {"class": "r", "html": row.cash}).inject(tr);
							new Element("td", {"class": "c", "html": row.reltime}).inject(tr);' . (access::has("admin") ? '
							new Element("td", {"html": row.cards}).inject(tr);' : '') . '
							tr.inject(self.tbody);
						});
						self.tbody.check_html();
						
						// merke en spiller?
						if (selected)
						{
							box = $$("#poker_players_true input[type=radio]")[0];
							name = box.get("rel") || box.get("name").replace(new RegExp("^(.*)\\[.+?\\]$"), "$1[]");
							boxHandleElms[name].each(function(obj)
							{
								if (obj.box.value == selected)
								{
									obj.checked = true;
									obj.check();
								}
							});
						}
					}
					else
					{
						self.players_true.setStyle("display", "none");
						self.players_false.setStyle("display", "block");
					}
					
					window.fireEvent("update_pa", players.length);
				},
				"failure": function(xhr)
				{
					// logget inn men feil?
					if (xhr.responseText != "ERROR:SESSION-EXPIRE" && xhr.responseText != "ERROR:WRONG-SESSION-ID")
					{
						self.info.set("html", "<b>Oppdatering feilet:</b> "+xhr.responseText+"<br />Henter ikke lenger oppdateringer.");
						self.info.check_html();
					}
					
					// ikke logget inn
					else
					{
						self.info.set("text", "Oppdateringer avbrutt - ikke logget inn.");
					}
					
					// stopp timer
					$clear(self.timer);
				}
			});
			
			// start oppdatering
			this.startUpdateTimer();
		},
		
		/** Start oppdateringstimer */
		startUpdateTimer: function()
		{
			this.timer = this.update.bind(this).periodical(this.interval);
		},
		
		/** Hent oppdateringer */
		update: function()
		{
			// sett info
			this.info.set("text", "Oppdaterer..");
			
			// oppdater
			this.xhr.send();
		}
	}
	stuff.init();');
        echo '
		<div id="poker_players_true"' . ($num == 0 ? ' style="display: none"' : '') . '>
			<form action="" method="post">
				<table class="table center tablemb">
					<thead>
						<tr>
							<th>Spiller</th>
							<th>Beløp</th>
							<th>Tid</th>' . (access::has("admin") ? '
							<th>Kort</th>' : '') . '
						</tr>
					</thead>
					<tbody id="poker_players">';
        $i = 0;
        while ($row = $result->fetch()) {
            $attr = new attr("class");
            if ($row['poker_starter_up_id'] != $this->up->id) {
                $attr->add("box_handle");
            }
            if (++$i % 2 == 0) {
                $attr->add("color");
            }
            $cards = new CardsPoker(explode(",", $row['poker_starter_cards']));
            $cardstext = $cards->solve_text($cards->solve());
            echo '
						<tr' . $attr->build() . '>
							<td>' . ($row['poker_starter_up_id'] != $this->up->id ? '<input type="radio" name="id" value="' . $row['poker_id'] . '" />' : '') . '<user id="' . $row['poker_starter_up_id'] . '" /></td>
							<td class="r">' . game::format_cash($row['poker_cash']) . '</td>
							<td class="c">' . poker_round::get_time_text($row['poker_time_start']) . '</td>' . (access::has("admin") ? '
							<td>' . $cardstext . '</td>' : '') . '
						</tr>';
        }
        echo '
					</tbody>
				</table>
				<p class="c">' . show_sbutton("Utfordre", 'name="utfordre"') . '</p>
			</div>
			<div id="poker_players_false"' . ($num > 0 ? ' style="display: none"' : '') . '>
				<p class="c">Ingen utfordringer.</p>
				<p class="c"><a href="poker" class="button">Oppdater</a></p>
			</div>
		</form>
	</div>
</div>';
    }