Esempio n. 1
0
    /**
     * Crewlogg
     */
    protected static function page_crewlog()
    {
        global $_game;
        ess::$b->page->add_title("Crewhendelser");
        ess::$b->page->add_css('
.gamelog { width: 80%; margin: 0 auto }
.gamelog .time { color: #888888; padding-right: 2px }
.log_section {
	background-color: #1C1C1C;
	padding: 15px 15px 5px;
	margin: 30px 0;
	border: 10px solid #111111;
}');
        echo '
	<div class="gamelog">';
        $gamelog = new gamelog();
        // liste over hva vi har av typer
        $types = array(gamelog::$items['crewforum_emne'], gamelog::$items['crewforum_svar'], gamelog::$items['crewforuma_emne'], gamelog::$items['crewforuma_svar'], gamelog::$items['crewforumi_emne'], gamelog::$items['crewforumi_svar']);
        // finn ut hva som er tilgjengelig
        $result = \Kofradia\DB::get()->query("SELECT type, COUNT(id) AS count FROM users_log WHERE ul_up_id = 0 AND type IN (" . implode(",", $types) . ") GROUP BY type");
        $in_use = array();
        $count = array();
        $total = 0;
        while ($row = $result->fetch()) {
            $in_use[] = $row['type'];
            $count[$row['type']] = $row['count'];
        }
        $tilgjengelig = array();
        foreach (gamelog::$items_id as $id => $name) {
            if (in_array($id, $in_use)) {
                $tilgjengelig[$id] = $id;
            }
        }
        $i_bruk = $tilgjengelig;
        $total = array_sum($count);
        // nye hendelser (viser også nye hendelser i firma/familie)?
        if (page_min_side::$active_user->data['u_log_crew_new'] > 0 && login::$user->id == page_min_side::$active_user->id && count($i_bruk) > 0) {
            echo '
		<h1 class="c">Nye crewhendelser</h1>';
            ess::$b->page->add_css('.ny { color: #FF0000 }');
            $where = ' AND type IN (' . implode(",", $i_bruk) . ')';
            $result = \Kofradia\DB::get()->query("SELECT time, type, note, num FROM users_log WHERE ul_up_id = 0{$where} ORDER BY time DESC, id DESC LIMIT " . page_min_side::$active_user->data['u_log_crew_new']);
            if ($result->rowCount() == 0) {
                echo '
		<p class="c">Ingen crewhendelser ble funnet.</p>';
            } else {
                // vis hendelsene
                $logs = array();
                while ($row = $result->fetch()) {
                    $day = ess::$b->date->get($row['time'])->format(date::FORMAT_NOTIME);
                    $data = $gamelog->format_log($row['type'], $row['note'], $row['num']);
                    $logs[$day][] = '
				<p><span class="time"><span class="ny">Ny!</span> - ' . ess::$b->date->get($row['time'])->format("H:i") . ':</span> ' . $data . '</p>';
                }
                foreach ($logs as $day => $items) {
                    echo '
		<div class="bg1_c">
			<h1 class="bg1">' . $day . '<span class="left2"></span><span class="right2"></span></h1>
			<div class="bg1">';
                    foreach ($items as $item) {
                        echo $item;
                    }
                    echo '
			</div>
		</div>';
                }
                echo '
				<p class="c">Viser ' . page_min_side::$active_user->data['u_log_crew_new'] . ' <b>ny' . (page_min_side::$active_user->data['u_log_crew_new'] == 1 ? '' : 'e') . '</b> crewhendelse' . (page_min_side::$active_user->data['u_log_crew_new'] == 1 ? '' : 'r') . '<br /><a href="' . htmlspecialchars(page_min_side::addr()) . '">Se full oversikt</a></p>';
                \Kofradia\DB::get()->exec("UPDATE users SET u_log_crew_new = 0 WHERE u_id = " . page_min_side::$active_user->id);
                page_min_side::$active_user->data['u_log_crew_new'] = 0;
            }
        } else {
            if (page_min_side::$active_user->data['u_log_crew_new'] > 0 && login::$user->id == page_min_side::$active_user->id) {
                \Kofradia\DB::get()->exec("UPDATE users SET u_log_crew_new = 0 WHERE u_id = " . page_min_side::$active_user->id);
                page_min_side::$active_user->data['u_log_crew_new'] = 0;
            }
            // filter
            $filter = array();
            foreach ($_GET as $name => $val) {
                $matches = NULL;
                if (preg_match("/^f([0-9]+)\$/Du", $name, $matches) && in_array($matches[1], $tilgjengelig)) {
                    $filter[] = $matches[1];
                }
            }
            if (count($filter) == 0) {
                $filter = false;
            } else {
                $i_bruk = $filter;
                $filter = true;
                ess::$b->page->add_message("Du har aktivert et filter og viser kun bestemte enheter.");
            }
            // hva skal vi vise?
            if (!$filter) {
                echo '
		<p class="c filterbox"><a href="#" onclick="toggle_display(\'.filterbox\', event)">Vis filteralternativer</a></p>';
            }
            echo '
		<div' . (!$filter ? ' style="display: none"' : '') . ' class="filterbox bg1_c">
			<h1 class="bg1">Filter<span class="left2"></span><span class="right2"></span></h1>
			<div class="bg1">
				<p class="c">Velg filter (<a href="#" class="box_handle_toggle" rel="f[]">Merk alle</a>)</p>
				<form action="" method="get">' . (!page_min_side::$active_own ? '
					<input type="hidden" name="u_id" value="' . page_min_side::$active_user->id . '" />' : '
					<input type="hidden" name="u" value="1" />') . '
					<input type="hidden" name="a" value="crewlog" />
					<table class="table center" width="100%">
						<tbody>';
            $tbody = new tbody(3);
            // 3 kolonner
            foreach ($tilgjengelig as $id) {
                $title = gamelog::$items_name[$id];
                $aktivt = in_array($id, $i_bruk) && $filter;
                $ant = $count[$id];
                $tbody->append('<input type="checkbox" name="f' . $id . '" rel="f[]" value=""' . ($aktivt ? ' checked="checked"' : '') . ' />' . htmlspecialchars($title) . ' <span class="dark">(' . $ant . ' stk)</span>', 'class="box_handle"');
            }
            $tbody->clean();
            echo '
						</tbody>
					</table>
					<p class="c">' . show_sbutton("Oppdater") . '</p>
				</form>
			</div>
		</div>';
            $i_bruk[] = "NULL";
            $where = ' AND type IN (' . implode(",", $i_bruk) . ')';
            // sideinformasjon - hent loggene på denne siden
            $pagei = new pagei(pagei::ACTIVE_GET, "side", pagei::PER_PAGE, max(50, page_min_side::$active_user->data['u_log_crew_new']));
            $result = $pagei->query("SELECT time, type, note, num FROM users_log WHERE ul_up_id IN (0, " . page_min_side::$active_player->id . "){$where} ORDER BY time DESC, id DESC");
            if ($result->rowCount() == 0) {
                echo '
		<p class="c">Ingen hendelser ble funnet.</p>';
            } else {
                echo '
		<p class="c">Totalt har du <b>' . game::format_number($total) . '</b> crewhendelse' . ($total == 1 ? '' : 'r') . '.</p>';
                if ($pagei->pages > 1) {
                    echo '
		<p class="c">' . address::make($_GET, "", $pagei) . '</p>';
                }
                // hendelsene
                $logs = array();
                $i = 0;
                $e = $pagei->start;
                while ($row = $result->fetch()) {
                    $day = ess::$b->date->get($row['time'])->format(date::FORMAT_NOTIME);
                    $data = $gamelog->format_log($row['type'], $row['note'], $row['num']);
                    $ny = $e < page_min_side::$active_user->data['u_log_crew_new'];
                    $logs[$day][] = '
				<p><span class="time">' . ($ny ? '<span class="ny">Ny!</span> - ' : '') . '' . ess::$b->date->get($row['time'])->format("H:i") . ':</span> ' . $data . '</p>';
                    $e++;
                }
                foreach ($logs as $day => $items) {
                    echo '
		<div class="bg1_c">
			<h1 class="bg1">' . $day . '<span class="left2"></span><span class="right2"></span></h1>
			<div class="bg1">';
                    foreach ($items as $item) {
                        echo $item;
                    }
                    echo '
			</div>
		</div>';
                }
                echo '
		<p class="c">Viser ' . $pagei->count_page . ' av ' . $pagei->total . ' crewhendelse' . ($pagei->total == 1 ? '' : 'r') . '</p>';
                if ($pagei->pages > 1) {
                    echo '
		<p class="c">' . address::make($_GET, "", $pagei) . '</p>';
                }
            }
        }
        echo '
	</div>';
    }
Esempio n. 2
0
    /**
     * Hendelsene til spilleren
     */
    protected static function page_log()
    {
        // kan ikke se?
        if (!page_min_side::$pstats) {
            echo '
	<p class="c">Du har ikke tilgang til å se denne siden.</p>';
            return;
        }
        global $_game;
        ess::$b->page->add_title("Hendelser");
        ess::$b->page->add_css('
.gamelog { width: 80%; margin: 0 auto }
.gamelog .time { color: #888888; padding-right: 2px }
.ffl_time {
	color: #AAA;
}
.log_section {
	background-color: #1C1C1C;
	padding: 15px 15px 5px;
	margin: 30px 0;
	border: 10px solid #111111;
}');
        echo '
	<div class="gamelog">';
        $gamelog = new gamelog();
        // finn ut hva som er tilgjengelig
        $result = \Kofradia\DB::get()->query("SELECT type, COUNT(id) AS count FROM users_log WHERE ul_up_id IN (0, " . page_min_side::$active_player->id . ") GROUP BY type");
        $in_use = array();
        $count = array();
        $total = 0;
        while ($row = $result->fetch()) {
            $in_use[] = $row['type'];
            $count[$row['type']] = $row['count'];
        }
        $tilgjengelig = array();
        foreach (gamelog::$items_id as $id => $name) {
            if (in_array($id, $in_use)) {
                $tilgjengelig[$id] = $id;
            }
        }
        // fjern ting vi ikke har tilgang til
        unset($tilgjengelig[gamelog::$items['crewforum_emne']], $count[gamelog::$items['crewforum_emne']]);
        unset($tilgjengelig[gamelog::$items['crewforum_svar']], $count[gamelog::$items['crewforum_svar']]);
        unset($tilgjengelig[gamelog::$items['crewforuma_emne']], $count[gamelog::$items['crewforuma_emne']]);
        unset($tilgjengelig[gamelog::$items['crewforuma_svar']], $count[gamelog::$items['crewforuma_svar']]);
        unset($tilgjengelig[gamelog::$items['crewforumi_emne']], $count[gamelog::$items['crewforumi_emne']]);
        unset($tilgjengelig[gamelog::$items['crewforumi_svar']], $count[gamelog::$items['crewforumi_svar']]);
        $i_bruk = $tilgjengelig;
        $total = array_sum($count);
        // nye hendelser (viser også nye hendelser i firma/familie)?
        if ((page_min_side::$active_player->data['up_log_ff_new'] > 0 || page_min_side::$active_player->data['up_log_new'] > 0) && page_min_side::$active_own) {
            echo '
		<h1 class="c">Nye hendelser</h1>';
            // nye hendelser i ff?
            if (page_min_side::$active_player->data['up_log_ff_new'] > 0) {
                // totalt antall logg hendelser som blir vist
                $counter_total = 0;
                // hent FF vi skal hente logg for
                $ffm_result = \Kofradia\DB::get()->query("SELECT ffm_ff_id, ffm_log_new FROM ff_members WHERE ffm_up_id = " . page_min_side::$active_player->id . " AND ffm_status = 1 AND ffm_log_new > 0");
                while ($ffm = $ffm_result->fetch()) {
                    $ff = ff::get_ff($ffm['ffm_ff_id'], ff::LOAD_SILENT);
                    if (!$ff) {
                        continue;
                    }
                    // hent hendelsene
                    $result = \Kofradia\DB::get()->query("SELECT ffl_id, ffl_time, ffl_type, ffl_data, ffl_extra FROM ff_log WHERE ffl_ff_id = {$ff->id} ORDER BY ffl_time DESC LIMIT {$ffm['ffm_log_new']}");
                    if ($result->rowCount() > 0) {
                        $logs = array();
                        while ($row = $result->fetch()) {
                            $counter_total++;
                            $day = ess::$b->date->get($row['ffl_time'])->format(date::FORMAT_NOTIME);
                            $data = $ff->format_log($row['ffl_id'], $row['ffl_time'], $row['ffl_type'], $row['ffl_data'], $row['ffl_extra']);
                            $logs[$day][] = '<span class="ffl_time">' . ess::$b->date->get($row['ffl_time'])->format("H:i") . ':</span> ' . $data;
                        }
                        echo '
		<div class="log_section">';
                        $ff->load_header();
                        foreach ($logs as $day => $items) {
                            echo '
			<div class="section">
				<h2>' . $day . '</h2>';
                            foreach ($items as $item) {
                                echo '
				<p>' . $item . '</p>';
                            }
                            echo '
			</div>';
                        }
                        echo '
			<p class="c"><a href="ff/logg?ff_id=' . $ff->id . '">Vis alle hendelsene for ' . $ff->type['refobj'] . ' &raquo;</a></p>';
                        $ff->load_footer();
                        echo '
		</div>';
                    }
                }
                // ble det ikke vist noen hendelser?
                if ($counter_total == 0) {
                    echo '
		<div class="bg1_c xsmall">
			<h1 class="bg1">Logg for firma og broderskap<span class="left"></span><span class="right"></span></h1>
			<div class="bg1">
				<p>Ingen nye hendelser tilknyttet firma eller broderskap.</p>
			</div>
		</div>';
                }
                // nullstill telleren
                \Kofradia\DB::get()->exec("UPDATE ff_members SET ffm_log_new = 0 WHERE ffm_up_id = " . page_min_side::$active_player->id);
                \Kofradia\DB::get()->exec("UPDATE users_players SET up_log_ff_new = 0 WHERE up_id = " . page_min_side::$active_player->id);
                page_min_side::$active_player->data['up_log_ff_new'] = 0;
            }
            // nye normale hendelser
            if (page_min_side::$active_player->data['up_log_new'] > 0) {
                ess::$b->page->add_css('.ny { color: #FF0000 }');
                $i_bruk[] = 'NULL';
                $where = ' AND type IN (' . implode(",", $i_bruk) . ')';
                $result = \Kofradia\DB::get()->query("SELECT time, type, note, num FROM users_log WHERE ul_up_id IN (0, " . page_min_side::$active_player->id . "){$where} ORDER BY time DESC, id DESC LIMIT " . page_min_side::$active_player->data['up_log_new']);
                if ($result->rowCount() == 0) {
                    echo '
		<p class="c">Ingen hendelser ble funnet.</p>';
                } else {
                    // vis hendelsene
                    $logs = array();
                    while ($row = $result->fetch()) {
                        $day = ess::$b->date->get($row['time'])->format(date::FORMAT_NOTIME);
                        $data = $gamelog->format_log($row['type'], $row['note'], $row['num']);
                        $logs[$day][] = '
				<p><span class="time"><span class="ny">Ny!</span> - ' . ess::$b->date->get($row['time'])->format("H:i") . ':</span> ' . $data . '</p>';
                    }
                    foreach ($logs as $day => $items) {
                        echo '
		<div class="bg1_c">
			<h1 class="bg1">' . $day . '<span class="left2"></span><span class="right2"></span></h1>
			<div class="bg1">';
                        foreach ($items as $item) {
                            echo $item;
                        }
                        echo '
			</div>
		</div>';
                    }
                    echo '
				<p class="c">Viser ' . page_min_side::$active_player->data['up_log_new'] . ' <b>ny' . (page_min_side::$active_player->data['up_log_new'] == 1 ? '' : 'e') . '</b> hendelse' . (page_min_side::$active_player->data['up_log_new'] == 1 ? '' : 'r') . '<br /><a href="' . htmlspecialchars(page_min_side::addr()) . '">Se full oversikt</a></p>';
                }
                \Kofradia\DB::get()->exec("UPDATE users_players SET up_log_new = 0 WHERE up_id = " . page_min_side::$active_player->id);
                page_min_side::$active_player->data['up_log_new'] = 0;
            } else {
                echo '
		<div class="bg1_c small bg1_padding">
			<h1 class="bg1">Normale hendelser<span class="left"></span><span class="right"></span></h1>
			<div class="bg1" id="logg">
				<p class="c"><a href="' . htmlspecialchars(page_min_side::addr()) . '">Vis oversikt over alle normale hendelser &raquo;</a></p>
			</div>
		</div>';
            }
        } else {
            // filter
            $filter = array();
            foreach ($_GET as $name => $val) {
                $matches = NULL;
                if (preg_match("/^f([0-9]+)\$/Du", $name, $matches) && in_array($matches[1], $tilgjengelig)) {
                    $filter[] = $matches[1];
                }
            }
            if (count($filter) == 0) {
                $filter = false;
            } else {
                $i_bruk = $filter;
                $filter = true;
                ess::$b->page->add_message("Du har aktivert et filter og viser kun bestemte enheter.");
            }
            // hva skal vi vise?
            if (!$filter) {
                echo '
		<p class="c filterbox"><a href="#" onclick="toggle_display(\'.filterbox\', event)">Vis filteralternativer</a></p>';
            }
            echo '
		<div' . (!$filter ? ' style="display: none"' : '') . ' class="filterbox bg1_c">
			<h1 class="bg1">Filter<span class="left2"></span><span class="right2"></span></h1>
			<div class="bg1">
				<p class="c">Velg filter (<a href="#" class="box_handle_toggle" rel="f[]">Merk alle</a>)</p>
				<form action="" method="get">' . (!page_min_side::$active_own || !page_min_side::$active_player->active ? '
					<input type="hidden" name="up_id" value="' . page_min_side::$active_player->id . '" />' : '') . '
					<input type="hidden" name="a" value="log" />
					<table class="table center" width="100%">
						<tbody>';
            $tbody = new tbody(3);
            // 3 kolonner
            foreach ($tilgjengelig as $id) {
                $title = gamelog::$items_name[$id];
                $aktivt = in_array($id, $i_bruk) && $filter;
                $ant = $count[$id];
                $tbody->append('<input type="checkbox" name="f' . $id . '" rel="f[]" value=""' . ($aktivt ? ' checked="checked"' : '') . ' />' . htmlspecialchars($title) . ' <span class="dark">(' . $ant . ' stk)</span>', 'class="box_handle"');
            }
            $tbody->clean();
            echo '
						</tbody>
					</table>
					<p class="c">' . show_sbutton("Oppdater") . '</p>
				</form>
			</div>
		</div>';
            $i_bruk[] = "NULL";
            $where = ' AND type IN (' . implode(",", $i_bruk) . ')';
            // sideinformasjon - hent loggene på denne siden
            $pagei = new pagei(pagei::ACTIVE_GET, "side", pagei::PER_PAGE, max(50, page_min_side::$active_player->data['up_log_new']));
            $result = $pagei->query("SELECT time, type, note, num FROM users_log WHERE ul_up_id IN (0, " . page_min_side::$active_player->id . "){$where} ORDER BY time DESC, id DESC");
            if ($result->rowCount() == 0) {
                echo '
		<p class="c">Ingen hendelser ble funnet.</p>';
            } else {
                echo '
		<p class="c">Totalt har du <b>' . game::format_number($total) . '</b> hendelse' . ($total == 1 ? '' : 'r') . '.</p>';
                if ($pagei->pages > 1) {
                    echo '
		<p class="c">' . address::make($_GET, "", $pagei) . '</p>';
                }
                // hendelsene
                $logs = array();
                $i = 0;
                $e = $pagei->start;
                while ($row = $result->fetch()) {
                    $day = ess::$b->date->get($row['time'])->format(date::FORMAT_NOTIME);
                    $data = $gamelog->format_log($row['type'], $row['note'], $row['num']);
                    $ny = $e < page_min_side::$active_player->data['up_log_new'];
                    $logs[$day][] = '
				<p><span class="time">' . ($ny ? '<span class="ny">Ny!</span> - ' : '') . '' . ess::$b->date->get($row['time'])->format("H:i") . ':</span> ' . $data . '</p>';
                    $e++;
                }
                foreach ($logs as $day => $items) {
                    echo '
		<div class="bg1_c">
			<h1 class="bg1">' . $day . '<span class="left2"></span><span class="right2"></span></h1>
			<div class="bg1">';
                    foreach ($items as $item) {
                        echo $item;
                    }
                    echo '
			</div>
		</div>';
                }
                echo '
		<p class="c">Viser ' . $pagei->count_page . ' av ' . $pagei->total . ' hendelse' . ($pagei->total == 1 ? '' : 'r') . '</p>';
                if ($pagei->pages > 1) {
                    echo '
		<p class="c">' . address::make($_GET, "", $pagei) . '</p>';
                }
            }
        }
        echo '
	</div>';
    }