Example #1
0
    /**
     * Crewside
     */
    protected static function page_crew()
    {
        global $__server, $_lang;
        ess::$b->page->add_title("Crew");
        $subpage2 = getval("b");
        redirect::store(page_min_side::addr(NULL, $subpage2 != "" ? "b=" . $subpage2 : ''));
        ess::$b->page->add_css('
.minside_crew_links .active { color: #CCFF00 }');
        $links = array();
        $links[] = '<a href="' . htmlspecialchars(page_min_side::addr(NULL, "", "player")) . '">Min spiller</a>';
        $links[] = '<a href="' . htmlspecialchars(page_min_side::addr(NULL, "")) . '"' . ($subpage2 == "" ? ' class="active"' : '') . '>Oversikt / logg</a>';
        if (access::has("forum_mod")) {
            $links[] = '<a href="' . htmlspecialchars(page_min_side::addr(NULL, "b=addlog")) . '"' . ($subpage2 == "addlog" ? ' class="active"' : '') . '>Nytt notat</a>';
        }
        $links[] = '<a href="' . htmlspecialchars(page_min_side::addr(NULL, "b=blokk")) . '"' . ($subpage2 == "blokk" ? ' class="active"' : '') . '>Blokkeringer</a>';
        if (access::has("mod")) {
            $links[] = '<a href="' . htmlspecialchars(page_min_side::addr(NULL, "b=banka")) . '"' . ($subpage2 == "banka" ? ' class="active"' : '') . '>Bankpassord</a>';
        }
        if (access::has("mod")) {
            $links[] = '<a href="' . htmlspecialchars(page_min_side::addr(NULL, "b=birth")) . '"' . ($subpage2 == "birth" ? ' class="active"' : '') . '>Fødselsdato</a>';
        }
        if (access::has("mod")) {
            $links[] = '<a href="' . htmlspecialchars(page_min_side::addr("set", "b=pass")) . '">Passord</a>';
        }
        if (access::has("admin")) {
            $links[] = '<a href="' . htmlspecialchars(page_min_side::addr(NULL, "b=level")) . '"' . ($subpage2 == "level" ? ' class="active"' : '') . '>Tilgangsnivå</a>';
        }
        $links[] = '<a href="' . htmlspecialchars(page_min_side::addr(NULL, "b=send_email")) . '"' . ($subpage2 == "send_email" ? ' class="active"' : '') . '>Send e-post</a>';
        $links[] = '<a href="' . htmlspecialchars(page_min_side::addr(NULL, "b=warning")) . '"' . ($subpage2 == "warning" ? ' class="active"' : '') . '>Gi advarsel</a>';
        echo '
	<p class="c minside_crew_links">' . implode(" | ", $links) . '</p>';
        if ($subpage2 == "") {
            // javascript for rapporteringer
            ess::$b->page->add_js_domready('
	var w = $("minside_reports");
	var xhr = new Request({
		url: relative_path + "/ajax/minside_report",
		data: { u_id: ' . page_min_side::$active_user->id . ' },
		evalScripts: function(script)
		{
			ajax.js += script;
		}
	});
	xhr.addEvent("success", function(text)
	{
		w.set("html", text);
		w.getElements(".pagenumbers").each(function(elm)
		{
			elm.addEvent("set_page", function(s) { load(null, s, true); });
		});
		ajax.refresh();
	});
	xhr.addEvent("failure", function(x)
	{
		var p = new Element("p", {html: "Feil: " + x}).inject(w.empty());
	});
	function load(a, s, goto)
	{
		if (a !== null) xhr.options.data.a = a;
		if (s) xhr.options.data.s = s;
		if (goto) w.getParent().goto(-10);
		w.set("html", "<p>Laster inn data..</p>");
		xhr.send();
	}
	$("minside_reports_from").addEvent("click", function() { load("from", 1, true); });
	$("minside_reports_to").addEvent("click", function() { load("to", 1, true); });
	$("minside_reports_all").addEvent("click", function() { load("", 1, true); });
	load();');
            // css for rapporteringer
            ess::$b->page->add_css('
.rap_wrap {
	margin: 1em 0;
	background-color: #222222;
	position: relative;
	overflow: auto;
}
.rap_time {
	position: absolute;
	top: 8px;
	right: 5px;
	margin: 0;
	color: #777777;
}
.rap_time span {
	color: #EEEEEE;
}
.rap_w {
	margin: 0;
	padding: 5px;
	background-color: #282828;
}
.rap_u {
	font-size: 14px;
}

.rap_wrap .col2_w { margin: 0 }
.rap_wrap .col_w.left { width: 40% }
.rap_wrap .col_w.right { width: 60% }
.rap_wrap .col_w.left .col { margin: 0 0 0 5px }
.rap_wrap .col_w.right .col { margin: 5px 5px 5px 0 }

.rap_note {
	background-color: #1C1C1C;
	padding: 5px !important;
	overflow: auto;
	border: 1px dotted #525252
}
');
            // faner
            ess::$b->page->add_js_domready('
	$$(".minside_fane_link").addEvent("click", function(elm)
	{
		$$(".minside_fane").setStyle("display", "none");
		$$(".minside_fane_link").removeClass("minside_fane_active");
		this.addClass("minside_fane_active");
		$(this.get("rel")).setStyle("display", "");
	});
	$$(".minside_fane_active").fireEvent("click");');
            ess::$b->page->add_css('
.minside_fane_active, .minside_fane_active:hover {
	color: #CCFF00;
}');
            echo '
	<div class="col2_w">
		<div class="col_w left">
			<div class="col">
				<div class="bg1_c">
					<h1 class="bg1">Oversikt<span class="left2"></span><span class="right2"></span></h1>
					<div class="bg1">';
            // hent blokkeringer for brukeren
            $result = \Kofradia\DB::get()->query("SELECT ub_id, ub_type, ub_time_expire, ub_reason FROM users_ban WHERE ub_u_id = " . page_min_side::$active_user->id . " AND ub_time_expire > " . time());
            if ($result->rowCount() > 0) {
                while ($row = $result->fetch()) {
                    $access = access::has(blokkeringer::$types[$row['ub_type']]['access']);
                    echo '
						<p>Blokkert: ' . ($access ? '<a href="' . htmlspecialchars(page_min_side::addr(NULL, "b=blokk&t={$row['ub_type']}")) . '">' : '') . htmlspecialchars(blokkeringer::$types[$row['ub_type']]['title']) . ($access ? '</a>' : '') . ' (til ' . ess::$b->date->get($row['ub_time_expire'])->format(date::FORMAT_SEC) . ', ' . game::counter($row['ub_time_expire'] - time()) . ')</p>';
                }
            }
            echo '
						<p>Trykk deg inn på de forskjellige spillerene til brukeren for å se informasjon knyttet opp mot dem.</p>
					</div>
				</div>
			</div>
		</div>
		<div class="col_w right">
			<div class="col">
				<div class="bg1_c">
					<h1 class="bg1">Crewnotat for brukeren<span class="left2"></span><span class="right2"></span></h1>
					<p class="h_right"><a href="' . htmlspecialchars(page_min_side::addr(NULL, "b=enote")) . '">rediger</a></p>
					<div class="bg1">
						<p>Her kan hvem som helst i crewet legge til eller endre et notat for denne brukeren for å memorere ting som har med <u>brukeren</u> å gjøre.</p>' . (empty(page_min_side::$active_user->data['u_note_crew']) ? '
						<p>Ingen notat er registrert.</p>' : '
						<div class="p">' . game::bb_to_html(page_min_side::$active_user->data['u_note_crew']) . '</div>') . '
					</div>
				</div>
			</div>
		</div>
	</div>
	<p class="c"><a class="minside_fane_link minside_fane_active" rel="minside_fane2">Loggoppføringer</a> | <a class="minside_fane_link" rel="minside_fane1">Rapporteringer</a></p>
	<div id="minside_fane1" class="minside_fane">
		<p class="c">Filter: <a id="minside_reports_from">Brukerens egne rapporteringer</a> | <a id="minside_reports_to">Andres rapporteringer</a> | <a id="minside_reports_all">Alle</a></p>
		<div id="minside_reports">
			<p>Laster inn..</p>
		</div>
	</div>
	<div id="minside_fane2" class="minside_fane">
	<p class="c">Loggoppføringer for denne brukeren</p>';
            // hent loggene for denne brukeren
            $pagei = new pagei(pagei::ACTIVE_GET, "side", pagei::PER_PAGE, 50);
            $result = $pagei->query("SELECT lc_id, lc_up_id, lc_time, lc_lca_id, lc_a_up_id, lc_log FROM log_crew JOIN users_players ON up_u_id = " . page_min_side::$active_user->id . " WHERE lc_a_up_id = up_id ORDER BY lc_time DESC");
            // ingen handlinger?
            if ($result->rowCount() == 0) {
                echo '
	<p class="c">Ingen oppføringer eksisterer.</p>';
            } else {
                $rows = array();
                while ($row = $result->fetch()) {
                    $rows[$row['lc_id']] = $row;
                }
                $data = crewlog::load_summary_data($rows);
                $logs = array();
                foreach ($data as $row) {
                    // hent sammendrag
                    $summary = crewlog::make_summary($row, NULL, $row['lc_a_up_id'] != page_min_side::$active_player->id);
                    $day = ess::$b->date->get($row['lc_time'])->format(date::FORMAT_NOTIME);
                    $logs[$day][] = '<p><span class="time">' . ess::$b->date->get($row['lc_time'])->format("H:i") . ':</span> ' . $summary . '</p>';
                }
                ess::$b->page->add_css('.crewlog .time { color: #888888; padding-right: 5px }');
                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 crewlog">
			' . implode('
			', $items) . '
		</div>
	</div>';
                }
                echo '
	<p class="c">' . $pagei->pagenumbers() . '</p>';
            }
            echo '
	</div>';
        } elseif ($subpage2 == "addlog" && access::has("forum_mod")) {
            // legge til?
            if (isset($_POST['notat'])) {
                $notat = trim(postval("notat"));
                $notat_bb = trim(game::bb_to_html($notat));
                if (empty($notat_bb)) {
                    ess::$b->page->add_message("Notatet kan ikke være tomt.", "error");
                } else {
                    // legg til i crewloggen
                    crewlog::log("user_add_note", page_min_side::$active_player->id, $notat);
                    ess::$b->page->add_message("Notatet ble registrert.");
                    redirect::handle(page_min_side::addr());
                }
            }
            ess::$b->page->add_title("Nytt notat");
            ess::$b->page->add_js_domready('$("notat_felt").focus();');
            echo '
	<div class="bg1_c">
		<h1 class="bg1">Legg til notat i crewloggen<span class="left2"></span><span class="right2"></span></h1>
		<div class="bg1">
			<p>Notat: (Vil bli lagt til som vanlig logg i <a href="' . htmlspecialchars(page_min_side::addr(NULL)) . '">Crewloggen</a>.)</p>
			<form action="" method="post">
				<p><textarea name="notat" id="notat_felt" rows="10" cols="30" style="width: 98%; overflow: auto">' . htmlspecialchars(postval("notat")) . '</textarea></p>
				<p>' . show_sbutton("Legg til notat") . '</p>
			</form>
		</div>
	</div>';
        } elseif ($subpage2 == "blokk") {
            ess::$b->page->add_title("Blokkeringer");
            $type = false;
            if (isset($_GET['t'])) {
                // kontroller type
                $type_id = intval($_GET['t']);
                // fant ikke?
                if (!isset(blokkeringer::$types[$type_id])) {
                    ess::$b->page->add_message("Ugyldig type '.{$type_id}.'.", "error");
                } else {
                    $type = blokkeringer::$types[$type_id];
                    // har vi tilgang til å gjøre noe med denne blokkeringen?
                    if (!access::has($type['access'])) {
                        ess::$b->page->add_message('Du har ikke tilgang til denne typen blokkering. (' . htmlspecialchars($type['title']) . ')', "error");
                        $type = false;
                    }
                }
            }
            // vise en type blokkering?
            if ($type) {
                redirect::store(page_min_side::addr(NULL, "b=blokk&t={$type_id}"));
                // sjekk om det er en aktiv blokkering for denne typen
                $active = blokkeringer::check($type_id, page_min_side::$active_user->id);
                if ($active) {
                    // hent informasjon om blokkeringen
                    $info = blokkeringer::get_info($active['ub_id']);
                }
                // handling: legg til blokkering
                if (isset($_POST['add']) && $active) {
                    ess::$b->page->add_message("Det er allerede en blokkering på brukeren som varer til " . ess::$b->date->get($active['ub_time_expire'])->format() . ".", "error");
                } elseif (isset($_POST['add'])) {
                    // kontroller verdier
                    $date_type = isset($_POST['date_type']) && $_POST['date_type'] == "abs" ? "abs" : "rel";
                    $rel_weeks = intval(postval("rel_weeks"));
                    $rel_days = intval(postval("rel_days"));
                    $rel_hours = intval(postval("rel_hours"));
                    $rel_mins = intval(postval("rel_mins"));
                    $abs_date = postval("abs_date");
                    $abs_time = postval("abs_time");
                    // sjekk type og verdiene
                    $expire = false;
                    // bestemt dato/tidspunkt
                    if ($date_type == "abs") {
                        // kontroller datoen
                        if (!($abs_date_m = check_date($abs_date, "%y-%m-%d"))) {
                            ess::$b->page->add_message('Datoen du skrev inn er ikke gyldig.', "error");
                        } elseif (!($abs_time_m = check_date($abs_time, "%h:%i:%s"))) {
                            ess::$b->page->add_message('Tidspunktet du skrev inn er ikke gyldig.', "error");
                        } else {
                            // ok
                            $date = ess::$b->date->get();
                            $date->setTime($abs_time_m[1], $abs_time_m[2], $abs_time_m[3]);
                            $date->setDate($abs_date_m[1], $abs_date_m[2], $abs_date_m[3]);
                            $expire = $date->format("U");
                        }
                    } else {
                        // sjekk uker
                        if ($rel_weeks < 0 || $rel_weeks > 9) {
                            ess::$b->page->add_message('Antall uker kan ikke være under 0 eller over 9.', "error");
                        } elseif ($rel_days < 0 || $rel_days > 6) {
                            ess::$b->page->add_message('Antall dager kan ikke være under 0 eller over 6.', "error");
                        } elseif ($rel_hours < 0 || $rel_hours > 23) {
                            ess::$b->page->add_message('Antall timer kan ikke være under 0 eller over 23.', "error");
                        } elseif ($rel_mins < 0 || $rel_mins > 59) {
                            ess::$b->page->add_message('Antall minutter kan ikke være under 0 eller over 59.', "error");
                        } else {
                            // ok
                            $expire = time() + $rel_weeks * 604800 + $rel_days * 86400 + $rel_hours * 3600 + $rel_mins * 60;
                        }
                    }
                    // sjekke videre?
                    if ($expire) {
                        // sjekk at datoen er minst 1 min fremover i tid
                        if ($expire < time() + 60) {
                            ess::$b->page->add_message('Du kan ikke legge til en blokkering for mindre enn 1 minutt.', "error");
                        } else {
                            // kontroller begrunnelse og intern informasjon
                            $log = trim(postval("log"));
                            $note = trim(postval("note"));
                            // mangler begrunnelse?
                            if ($log == "") {
                                ess::$b->page->add_message('Mangler begrunnelse.', "error");
                            } elseif ($note == "") {
                                ess::$b->page->add_message("Mangler intern informasjon", "error");
                            } else {
                                // forsøk å legg til blokkeringen
                                $add = blokkeringer::add(page_min_side::$active_user->id, $type_id, $expire, $log, $note);
                                if ($add !== true) {
                                    ess::$b->page->add_message("Det er allerede en blokkering på brukeren som varer til " . ess::$b->date->get($add['ub_time_expire'])->format() . ".", "error");
                                } else {
                                    // legg til crewlogg
                                    crewlog::log("user_ban_active", page_min_side::$active_player->id, $log, array("type" => $type_id, "time_end" => $expire, "note" => $note));
                                    ess::$b->page->add_message('Brukeren er nå blokkert til ' . ess::$b->date->get($expire)->format() . '. (' . htmlspecialchars($type['title']) . ')');
                                    redirect::handle();
                                }
                            }
                        }
                    }
                } elseif (isset($_POST['edit']) && !$active) {
                    // ingen blokkering å redigere?
                    ess::$b->page->add_message("Brukeren har ikke lengre denne blokkeringen.", "error");
                } elseif (isset($_POST['edit'])) {
                    // godkjent handling?
                    if (isset($_POST['log_change'])) {
                        // kontroller verdier
                        $date = postval("date");
                        $time = postval("time");
                        // kontroller datoen
                        if (!($date_m = check_date($date, "%y-%m-%d"))) {
                            ess::$b->page->add_message('Datoen du skrev inn er ikke gyldig.', "error");
                        } elseif (!($time_m = check_date($time, "%h:%i:%s"))) {
                            ess::$b->page->add_message('Tidspunktet du skrev inn er ikke gyldig.', "error");
                        } else {
                            $date = ess::$b->date->get();
                            $date->setTime($time_m[1], $time_m[2], $time_m[3]);
                            $date->setDate($date_m[1], $date_m[2], $date_m[3]);
                            $expire = $date->format("U");
                            // sjekk at datoen er minst 1 min fremover i tid
                            if ($expire < time() + 60) {
                                ess::$b->page->add_message('Du kan ikke legge til en blokkering for mindre enn 1 minutt.', "error");
                            } else {
                                // kontroller begrunnelse for utestengelse, begrunnelse for endring og intern informasjon
                                $log_ban = trim(postval("log_ban"));
                                $log_change = trim(postval("log_change"));
                                $note = trim(postval("note"));
                                // mangler begrunnelse for endring?
                                if ($log_change == "") {
                                    ess::$b->page->add_message('Mangler begrunnelse for endring.', "error");
                                } elseif ($log_ban == "") {
                                    ess::$b->page->add_message('Mangler begrunnelse for utestengelse.', "error");
                                } elseif ($note == "") {
                                    ess::$b->page->add_message('Mangler intern informasjon.', "error");
                                } elseif ($expire == $info['ub_time_expire'] && $log_ban == $info['ub_reason'] && $note == $info['ub_note']) {
                                    ess::$b->page->add_message('Ingen endringer ble utført.', "error");
                                } else {
                                    // oppdater blokkeringen
                                    $edit = blokkeringer::edit($active['ub_id'], $expire, $log_ban, $note);
                                    if ($edit == 0) {
                                        ess::$b->page->add_message("Blokkeringen kunne ikke bli oppdatert. Den er mest sannsynlig ikke lengre aktiv.", "error");
                                    } else {
                                        // legg til crewlogg
                                        $data = array("type" => $type_id, "time_end_old" => $info['ub_time_expire'], "log_old" => $info['ub_reason'], "note_old" => $info['ub_note']);
                                        if ($expire != $info['ub_time_expire']) {
                                            $data["time_end_new"] = $expire;
                                        }
                                        if ($log_ban != $info['ub_reason']) {
                                            $data["log_new"] = $log_ban;
                                        }
                                        if ($note != $info['ub_note']) {
                                            $data["note_new"] = $note;
                                        }
                                        crewlog::log("user_ban_change", page_min_side::$active_player->id, $log_change, $data);
                                        ess::$b->page->add_message('Du har oppdatert blokkeringen. Brukeren er nå blokkert til ' . ess::$b->date->get($expire)->format() . '. (' . htmlspecialchars($type['title']) . ')');
                                        redirect::handle();
                                    }
                                }
                            }
                        }
                    }
                } elseif (isset($_POST['delete']) && !$active) {
                    // ingen blokkering å slette?
                    ess::$b->page->add_message("Brukeren har ikke lengre denne blokkeringen.", "error");
                } elseif (isset($_POST['delete'])) {
                    // godkjent handling?
                    if (isset($_POST['log'])) {
                        $log = trim(postval("log"));
                        // mangler logg?
                        if ($log == "") {
                            ess::$b->page->add_message('Mangler begrunnelse.', "error");
                        } else {
                            // fjern blokkeringen
                            $delete = blokkeringer::delete($active['ub_id']);
                            if ($delete == 0) {
                                ess::$b->page->add_message("Blokkeringen kunne ikke bli oppdatert. Den er mest sannsynlig ikke lengre aktiv.", "error");
                            } else {
                                // legg til crewlogg
                                crewlog::log("user_ban_delete", page_min_side::$active_player->id, $log, array("type" => $type_id, "time_end" => $info['ub_time_expire'], "log" => $info['ub_reason'], "note" => $info['ub_note']));
                                ess::$b->page->add_message('Du har fjernet blokkeringen. (' . htmlspecialchars($type['title']) . ')');
                                redirect::handle();
                            }
                        }
                    }
                }
                echo '
	<div class="bg1_c" style="width: 350px">
		<h1 class="bg1">Blokkering: ' . htmlspecialchars($type['title']) . '<span class="left2"></span><span class="right2"></span></h1>
		<div class="bg1">
			<boxes />
			<p class="r">Tilgangsnivå: ' . access::name($type['access']) . '</p>
			<p><u>Hensikt:</u> ' . $type['description'] . '</p>';
                // blokkert?
                if ($active) {
                    echo '
			<p>Brukeren er blokkert.</p>
			<dl class="dd_right">
				<dt>Lagt til</dt>
				<dd>' . ess::$b->date->get($info['ub_time_added'])->format(date::FORMAT_SEC) . '<br />' . game::timespan($info['ub_time_added'], game::TIME_ABS | game::TIME_ALL, 5) . '</dd>
				<dt>Utestengt til</dt>
				<dd>' . ess::$b->date->get($info['ub_time_expire'])->format(date::FORMAT_SEC) . '<br />' . game::counter($info['ub_time_expire'] - time()) . '</dd>
			</dl>
			<div class="section">
				<h2>Begrunnelse</h2>
				<div class="p">' . (($reason = game::bb_to_html($info['ub_reason'])) == "" ? 'Ikke oppgitt.' : $reason) . '</div>
				<h2>Intern informasjon</h2>
				<div class="p">' . (($note = game::bb_to_html($info['ub_note'])) == "" ? 'Ikke oppgitt.' : $note) . '</div>
			</div>';
                    // handling: redigere blokkering
                    if (isset($_POST['edit'])) {
                        echo '
			<p>Du er i ferd med å endre blokkeringen til brukeren.</p>
			<form action="" method="post">
				<dl class="dd_right dl_2x">
					<dt>Til</dt>
					<dd>
						Dato:
						<input type="text" name="date" id="ban_date" value="' . htmlspecialchars(postval("date", ess::$b->date->get($info['ub_time_expire'])->format("Y-m-d"))) . '" class="styled w80" />
						<input type="text" name="time" id="ban_time" value="' . htmlspecialchars(postval("time", ess::$b->date->get($info['ub_time_expire'])->format("H:i:s"))) . '" class="styled w80" />
					</dd>
					<dt>Begrunnelse for endring</dt>
					<dd><textarea name="log_change" cols="30" rows="5">' . htmlspecialchars(postval("log_change")) . '</textarea></dd>
					<dt>Begrunnelse for blokkering</dt>
					<dd><textarea name="log_ban" cols="30" rows="5">' . htmlspecialchars(postval("log_ban", $info['ub_reason'])) . '</textarea></dd>
					<dt>Intern informasjon</dt>
					<dd><textarea name="note" cols="30" rows="5">' . htmlspecialchars(postval("note", $info['ub_note'])) . '</textarea></dd>
					<dd>
						' . show_sbutton("Lagre endringer", 'name="edit"') . '
						' . show_sbutton("Avbryt") . '
					</dd>
				</dl>
			</form>';
                    } elseif (isset($_POST['delete'])) {
                        echo '
			<p>Du er i ferd med å fjerne blokkeringen til brukeren.</p>
			<form action="" method="post">
				<dl class="dd_right dl_2x">
					<dt>Begrunnelse for fjerning</dt>
					<dd><textarea name="log" cols="30" rows="5">' . htmlspecialchars(postval("log")) . '</textarea></dd>
					<form action="" method="post">
						<dd>
							' . show_sbutton("Fjern", 'name="delete"') . '
							' . show_sbutton("Avbryt") . '
						</dd>
					</form>
				</dl>
			</form>';
                    } else {
                        echo '
			<form action="" method="post">
				<p>
					' . show_sbutton("Endre", 'name="edit"') . '
					' . show_sbutton("Fjern", 'name="delete"') . '
					<a href="' . htmlspecialchars(page_min_side::addr(NULL, "b=blokk")) . '" class="button">Tilbake</a>
				</p>
			</form>';
                    }
                } else {
                    $date_type = isset($_POST['type']) && $_POST['type'] == "abs" ? "abs" : "rel";
                    $hide_rel = $date_type == "rel" ? '' : ' hide';
                    $hide_abs = $date_type == "abs" ? '' : ' hide';
                    echo '
			<p>Brukeren har ingen aktiv blokkering.</p>
			<form action="" method="post">
				<input type="hidden" name="date_type" value="' . $date_type . '" />
				<dl class="dd_right dl_2x">
					<dt class="date_rel' . $hide_rel . '">Varighet (<a href="#" onclick="handleClass(\'.date_abs\', \'.date_rel\', event, this.parentNode.parentNode); $(\'date_type\').value=\'abs\'">velg dato</a>)</dt>
					<dd class="date_rel' . $hide_rel . '">
						<input type="text" name="rel_weeks" class="styled w30 r" style="width: 10px" value="' . intval(postval("rel_weeks")) . '" maxlength="1" /> uker
						<input type="text" name="rel_days" class="styled w30 r" style="width: 10px" value="' . intval(postval("rel_days")) . '" maxlength="1" /> dager
						<input type="text" name="rel_hours" class="styled w30 r" style="width: 17px" value="' . intval(postval("rel_hours")) . '" maxlength="2" /> timer
						<input type="text" name="rel_mins" class="styled w30 r" style="width: 17px" value="' . intval(postval("rel_mins")) . '" maxlength="2" /> minutter
					</dd>
					<dt class="date_abs' . $hide_abs . '">Til (<a href="#" onclick="handleClass(\'.date_rel\', \'.date_abs\', event, this.parentNode.parentNode); $(\'date_type\').value=\'rel\'">velg varighet</a>)</dt>
					<dd class="date_abs' . $hide_abs . '">
						Dato:
						<input type="text" name="abs_date" value="' . htmlspecialchars(postval("abs_date", ess::$b->date->get()->format("Y-m-d"))) . '" class="styled w80" />
						<input type="text" name="abs_time" value="' . htmlspecialchars(postval("abs_time", ess::$b->date->get()->format("H:i:s"))) . '" class="styled w60" />
					</dd>
					<dt>Begrunnelse</dt>
					<dd><textarea name="log" cols="30" rows="5">' . htmlspecialchars(postval("log")) . '</textarea></dd>
					<dt>Intern informasjon</dt>
					<dd><textarea name="note" cols="30" rows="5">' . htmlspecialchars(postval("note")) . '</textarea></dd>
					<dd>
						' . show_sbutton("Legg til blokkering", 'name="add"') . '
						<a href="' . htmlspecialchars(page_min_side::addr(NULL, "a=blokk")) . '" class="button">Tilbake</a>
					</dd>
				</dl>
			</form>';
                }
                echo '
		</div>
	</div>';
            } else {
                // filtrer ut de blokkeringene vi har tilgang til å sette
                $types = blokkeringer::$types;
                $links = array();
                foreach ($types as $id => $type) {
                    if (!access::has($type['access'])) {
                        continue;
                    }
                    $links[$type['title']] = '
				<li><a href="' . htmlspecialchars(page_min_side::addr(NULL, "b=blokk&t={$id}")) . '" title="' . htmlspecialchars($type['description']) . '">' . htmlspecialchars($type['title']) . '</a></li>';
                }
                // sorter
                ksort($links);
                $links = implode('', $links);
                // vis oversikt
                echo '
	<div class="bg1_c" style="width: 350px">
		<h1 class="bg1">Blokkeringer<span class="left2"></span><span class="right2"></span></h1>
		<div class="bg1">
			<p>Velg type:</p>';
                if ($links == '') {
                    echo '
			<p>Du har ikke tilgang til noen blokkeringstyper.</p>';
                } else {
                    echo '
			<ul>' . $links . '
			</ul>';
                }
                echo '
		</div>
	</div>';
                // hent alle aktive blokkeringer
                $result = \Kofradia\DB::get()->query("SELECT ub_type, ub_time_expire, ub_reason FROM users_ban WHERE ub_u_id = " . page_min_side::$active_user->id . " AND ub_time_expire > " . time() . " ORDER BY ub_time_expire");
                if ($result->rowCount() > 0) {
                    echo '
	<div class="bg1_c" style="width: 350px">
		<h1 class="bg1">Aktive blokkeringer<span class="left2"></span><span class="right2"></span></h1>
		<div class="bg1">
			<table class="table tablem" style="width: 100%">
				<thead>
					<tr>
						<th>Type</th>
						<th>Dato</th>
						<th>Begrunnelse</th>
					</tr>
				</thead>
				<tbody>';
                    $i = 0;
                    while ($row = $result->fetch()) {
                        $type = blokkeringer::get_type($row['ub_type']);
                        $access = access::has($type['access']);
                        echo '
					<tr' . (++$i % 2 == 0 ? ' class="color"' : '') . '>
						<td>' . ($access ? '<a href="' . htmlspecialchars(page_min_side::addr(NULL, "b=blokk&t={$row['ub_type']}")) . '">' : '') . htmlspecialchars($type['title']) . ($access ? '</a>' : '') . '</td>
						<td>
							' . ess::$b->date->get($row['ub_time_expire'])->format(date::FORMAT_SEC) . '<br />
							(' . game::timespan($row['ub_time_expire'], game::TIME_ABS | game::TIME_ALL, 5) . ')
						</td>
						<td>' . game::format_data($row['ub_reason'], "bb-opt", "Ingen begrunnelse gitt.") . '</td>
					</tr>';
                    }
                    echo '
				</tbody>
			</table>
		</div>
	</div>';
                }
            }
        } elseif ($subpage2 == "send_email") {
            ess::$b->page->add_title("Send e-post");
            // har tekst?
            $show_form = true;
            if (isset($_POST['text']) && !isset($_POST['edit'])) {
                $subject = trim(postval("subject"));
                $text = trim(postval("text"));
                // mangler emne?
                if (empty($subject)) {
                    ess::$b->page->add_message("Du må fylle ut emnefeltet.", "error");
                } elseif (empty($text)) {
                    ess::$b->page->add_message("Du må fylle ut innholdet.", "error");
                } else {
                    $email_subject = $subject;
                    $email_text = $text . "\n\n--\n" . login::$user->player->data['up_name'] . "\nwww.kofradia.no\n\nDenne meldingen ble sendt til " . page_min_side::$active_user->data['u_email'] . " som tilhører " . page_min_side::$active_player->data['up_name'];
                    // godkjent?
                    if (isset($_POST['send'])) {
                        // send e-posten
                        $email = new email();
                        $email->text = $email_text;
                        $email->headers['BCC'] = "*****@*****.**";
                        $email->headers['Reply-To'] = "*****@*****.**";
                        $email->send(page_min_side::$active_user->data['u_email'], $email_subject);
                        // legg til crewlogg
                        crewlog::log("user_send_email", page_min_side::$active_player->id, NULL, array("email" => page_min_side::$active_user->data['u_email'], "email_subject" => $email_subject, "email_content" => $email_text));
                        ess::$b->page->add_message("E-posten ble sendt til " . htmlspecialchars(page_min_side::$active_user->data['u_email']) . ".");
                        redirect::handle(page_min_side::addr(""));
                    }
                    echo '
	<div class="bg1_c" style="width: 400px">
		<h1 class="bg1">Send e-post<span class="left2"></span><span class="right2"></span></h1>
		<div class="bg1">
			<p><b>Mottaker:</b> ' . htmlspecialchars(page_min_side::$active_user->data['u_email']) . '</p>
			<p><b>Emne:</b> ' . htmlspecialchars($email_subject) . '</p>
			<p style="font-family: monospace">' . nl2br(htmlspecialchars($email_text)) . '</p>
			<form action="" method="post">
				<input type="hidden" id="email_subject" name="subject" value="' . htmlspecialchars($subject) . '" />
				<input type="hidden" id="email_text" name="text" value="' . htmlspecialchars($text) . '" />
				<p>' . show_sbutton("Send e-posten", 'name="send"') . ' ' . show_sbutton("Tilbake / endre", 'name="edit"') . '</p>
			</form>
		</div>
	</div>';
                    $show_form = false;
                }
            }
            if ($show_form) {
                ess::$b->page->add_js_domready('$("email_subject").focus();');
                echo '
	<div class="bg1_c" style="width: 400px">
		<h1 class="bg1">Send e-post<span class="left2"></span><span class="right2"></span></h1>
		<div class="bg1">
			<boxes />
			<p>Her sender du e-post til brukeren på vegne av Kofradia. Avsender vil være den normale avsendere all e-post fra Kofradia blir sendt fra.</p>
			<form action="" method="post">
				<dl class="dd_right dl_2x">
					<dt>Mottaker</dt>
					<dd>' . htmlspecialchars(page_min_side::$active_user->data['u_email']) . '</dd>
					<dt>Emne</dt>
					<dd><input type="text" value="' . htmlspecialchars(postval("subject")) . '" name="subject" id="email_subject" class="styled w200" /></dd>
					<dt>Innhold</dt>
					<dd><textarea name="text" id="email_text" cols="50" rows="10">' . htmlspecialchars(postval("text", "Hei,\n\n")) . '</textarea></dd>
					<dd>' . show_sbutton("Forhåndsvis / fortsett") . '</dd>
				</dl>
			</form>
		</div>
	</div>';
            }
        } elseif ($subpage2 == "warning") {
            ess::$b->page->add_title("Gi advarsel til brukeren");
            $types = crewlog::$user_warning_types;
            // legge til advarsel?
            if (isset($_POST['log'])) {
                $log = trim(postval("log"));
                $note = trim(postval("note"));
                $type = postval("type");
                $priority = (int) postval("priority");
                $notify = isset($_POST['notify']);
                if (empty($log) || empty($note)) {
                    ess::$b->page->add_message("Både begrunnelse og intern informasjon må fylles ut.", "error");
                } elseif (!isset($types[$type])) {
                    ess::$b->page->add_message("Ugyldig kategori.", "error");
                } elseif ($priority < 1 || $priority > 3) {
                    ess::$b->page->add_message("Ugylig alvorlighet.", "error");
                } else {
                    $data = array("type" => $types[$type], "note" => $note, "priority" => $priority);
                    // legge til spillerlogg?
                    if ($notify) {
                        $data['notified'] = 1;
                        $data['notified_id'] = player::add_log_static(gamelog::$items['advarsel'], urlencode($types[$type]) . ':' . urlencode($log), NULL, page_min_side::$active_player->id);
                        ess::$b->page->add_message("Advarselen ble lagret. Brukeren ble informert.");
                    } else {
                        ess::$b->page->add_message("Advarselen ble lagret. Du har ikke informert brukeren om denne advarselen.");
                    }
                    // legg til advarselen
                    crewlog::log("user_warning", page_min_side::$active_player->id, $log, $data);
                    redirect::handle();
                }
            }
            echo '
	<div class="bg1_c" style="width: 400px">
		<h1 class="bg1">Gi advarsel til brukeren<span class="left2"></span><span class="right2"></span></h1>
		<div class="bg1">
			<form action="" method="post">
				<boxes />
				<p>Dette kan benyttes som et verktøy for å gi advarsler til brukere. Det kan velges om brukeren skal motta advarselen eller ikke. Hvis man ikke velger å informere brukeren om noe, blir det alikevel søkbart i crewloggen for brukeren.</p>
				<p>Alvorligheten av advarselen blir benyttet for å automatisere en poengsum brukeren får avhengig av antall advarseler. En advarsel med høy alvorlighet varer lenger og teller mer enn en med lav alvorlighet.</p>
				<dl class="dd_right">
					<dt>Kategori</dt>
					<dd>
						<select name="type">';
            $type = isset($_POST['type']) && isset($types[$_POST['type']]) ? intval($_POST['type']) : false;
            if ($type === false) {
                echo '
							<option value="">Velg ..</option>';
            }
            foreach ($types as $key => $row) {
                echo '
							<option value="' . $key . '"' . ($key === $type ? ' selected="selected"' : '') . '>' . htmlspecialchars($row) . '</option>';
            }
            echo '
						</select>
					</dd>
					<dt>Alvorlighet/prioritet</dt>
					<dd>
						<select name="priority">';
            $priority = isset($_POST['priority']) && is_numeric($_POST['priority']) && $_POST['priority'] >= 1 && $_POST['priority'] <= 3 ? $_POST['priority'] : 2;
            echo '
							<option value="1"' . ($priority == 1 ? ' selected="selected"' : '') . '>Lav</option>
							<option value="2"' . ($priority == 2 ? ' selected="selected"' : '') . '>Moderat</option>
							<option value="3"' . ($priority == 3 ? ' selected="selected"' : '') . '>Høy</option>
						</select>
					</dd>
				</dl>
				<p>Begrunnelse:</p>
				<p><textarea name="log" rows="10" cols="30" style="width: 98%">' . htmlspecialchars(postval("log")) . '</textarea></p>
				<p>Intern informasjon:</p>
				<p><textarea name="note" rows="10" cols="30" style="width: 98%">' . htmlspecialchars(postval("note")) . '</textarea></p>
				<p><input type="checkbox" name="notify"' . ($_SERVER['REQUEST_METHOD'] == "POST" && !isset($_POST['notify']) ? '' : ' checked="checked"') . ' id="warning_notify" /><label for="warning_notify"> Gi brukeren informasjon om denne advarselen. Kun kategori og begrunnelse vil bli oppgitt til brukeren som en logg i hendelser.</label></p>
				<p class="c">' . show_sbutton("Lagre") . '</p>
			</form>
		</div>
	</div>';
            // analyser advarsler
            $lca_id = crewlog::$actions['user_warning'][0];
            $pagei = new pagei(pagei::ACTIVE_GET, "side", pagei::PER_PAGE, 15);
            $result = $pagei->query("\n\t\t\t\tSELECT lc_id, lc_up_id, lc_time, lc_log, lcd_data_int\n\t\t\t\tFROM log_crew\n\t\t\t\t\tJOIN users_players ON lc_a_up_id = up_id AND up_u_id = " . page_min_side::$active_user->id . "\n\t\t\t\t\tLEFT JOIN log_crew_data ON lcd_lc_id = lc_id AND lcd_lce_id = 5\n\t\t\t\tWHERE lc_lca_id = {$lca_id} AND (lcd_data_int IS NULL OR lcd_data_int = 0)\n\t\t\t\tORDER BY lc_time DESC");
            $data = array();
            while ($row = $result->fetch()) {
                $data[$row['lc_id']] = $row;
            }
            // sett opp data
            $data = crewlog::load_summary_data($data);
            echo '
	<div class="bg1_c ' . (count($data) == 0 ? 'xsmall' : 'medium') . '">
		<h1 class="bg1">Tidligere advarsler<span class="left2"></span><span class="right2"></span></h1>
		<div class="bg1">';
            if (count($data) == 0) {
                echo '
			<p>Brukeren har ingen tidligere advarsler.</p>';
            } else {
                ess::$b->page->add_css('
.advarsel { border: 1px solid #292929; margin: 10px 0; padding: 0 10px }');
                foreach ($data as $row) {
                    $priority = $row['data']['priority'] == 1 ? "lav" : ($row['data']['priority'] == 2 ? "moderat" : "høy");
                    echo '
			<div class="advarsel">
				<p><b>' . ess::$b->date->get($row['lc_time'])->format() . '</b>: ' . $row['data']['type'] . ' (alvorlighet: <b>' . $priority . '</b>):</p>
				<ul>
					<li>' . game::format_data($row['lc_log']) . '</li>
					<li>Internt notat: ' . game::format_data($row['data']['note']) . '</li>
				</ul>
				<p>' . (empty($row['data']['notified']) ? 'Ble IKKE varslet.' : 'Ble varslet.') . ' Av <user id="' . $row['lc_up_id'] . '" /></p>
			</div>';
                }
                echo '
			<p class="c">' . $pagei->pagenumbers() . '</p>';
            }
            echo '
		</div>
	</div>';
        } elseif ($subpage2 == "enote") {
            ess::$b->page->add_title("Endre notat for bruker");
            // lagre endringer?
            if (isset($_POST['notat'])) {
                $notat = postval("notat");
                if ($notat == page_min_side::$active_user->data['u_note_crew']) {
                    ess::$b->page->add_message("Ingen endringer ble utført.", "error");
                } else {
                    \Kofradia\DB::get()->exec("UPDATE users SET u_note_crew = " . \Kofradia\DB::quote($notat) . " WHERE u_id = " . page_min_side::$active_user->id);
                    // legg til crewlogg
                    crewlog::log("user_note_crew", page_min_side::$active_player->id, NULL, array("note_old" => page_min_side::$active_user->data['u_note_crew'], "note_diff" => diff::make(page_min_side::$active_user->data['u_note_crew'], $notat)));
                    ess::$b->page->add_message("Notatet ble endret.");
                    redirect::handle();
                }
            }
            echo '
	<div class="bg1_c" style="width: 400px">
		<h1 class="bg1">Endre crewnotat for bruker<span class="left2"></span><span class="right2"></span></h1>
		<div class="bg1">
			<form action="" method="post">
				<p>Dette endrer notatet som er tilknyttet brukeren. Du kan også tilknytte <a href="' . htmlspecialchars(page_min_side::addr(NULL, "b=enote", "player")) . '">informasjon til spilleren</a>, hvis det heller er ønskelig.</p>
				<p>Notat:</p>
				<p><textarea name="notat" rows="10" cols="30" style="width: 98%">' . htmlspecialchars(page_min_side::$active_user->data['u_note_crew']) . '</textarea></p>
				<p class="c">' . show_sbutton("Lagre") . '</p>
			</form>
		</div>
	</div>';
        } elseif ($subpage2 == "level" && access::has("admin")) {
            // nivåer man kan bytte til
            static $levels = array(1 => "Vanlig bruker", 14 => "Skjult nostat (crewtilgang)", -4 => "Ressurs", 12 => "Ressurs (nostat)", 13 => "Utvikler", 4 => "Forummoderator", 6 => "Forummoderator (nostat)", 5 => "Moderator", 11 => "Seniormoderator");
            if (access::has("sadmin")) {
                $levels[7] = "Administrator";
            }
            if (access::has("sadmin")) {
                $levels[8] = "Superadministrator";
            }
            // kan vi ikke endre brukernivået til denne brukeren?
            if (!isset($levels[page_min_side::$active_user->data['u_access_level']])) {
                ess::$b->page->add_message("Du har ikke rettigheter til å endre tilgangsnivået til denne brukeren.", "error");
                redirect::handle(page_min_side::addr());
            }
            // endre brukernivå?
            if (isset($_POST['level'])) {
                $level = intval($_POST['level']);
                $log = trim(postval("log"));
                // samme brukernivå?
                if ($level == page_min_side::$active_user->data['u_access_level']) {
                    ess::$b->page->add_message("Du må velge et nytt tilgangsnivå.", "error");
                } elseif (!isset($levels[$level])) {
                    ess::$b->page->add_message("Ugyldig tilgangsnivå.");
                } elseif (empty($log)) {
                    ess::$b->page->add_message("Mangler begrunnelse.");
                } else {
                    // endre tilgangsnivå
                    $old = page_min_side::$active_user->data['u_access_level'];
                    if (page_min_side::$active_user->change_level($level, isset($_POST['no_update_up']))) {
                        // e-post logg
                        sysreport::log("Endring av tilgangsnivå: " . login::$user->player->data['up_name'] . " endret tilgangsnivået til " . page_min_side::$active_user->data['u_email'] . " (" . page_min_side::$active_player->data['up_name'] . ") fra {$levels[$old]} til {$levels[$level]} {$__server['path']}/min_side?u_id=" . page_min_side::$active_user->id . "\n\nBegrunnelse: " . strip_tags(game::format_data($log)), "Kofradia: Endring av tilgangsnivå for " . page_min_side::$active_user->data['u_email'] . " (" . page_min_side::$active_player->data['up_name'] . ")");
                        // finn totalt beløp spilleren har
                        $result = \Kofradia\DB::get()->query("SELECT up_cash + up_bank FROM users_players WHERE up_id = " . page_min_side::$active_player->id);
                        $money = $result->fetchColumn(0);
                        // crewlogg
                        $data = array("level_old" => $old, "level_old_text" => $levels[$old], "level_new" => $level, "level_new_text" => $levels[$level], "money" => $money, "points" => page_min_side::$active_player->data['up_points']);
                        if (page_min_side::$active_player->active && !isset($_POST['no_update_up'])) {
                            $data['up_id'] = page_min_side::$active_player->id;
                        }
                        crewlog::log("user_level", page_min_side::$active_player->id, $log, $data);
                        putlog("CREWCHAN", "%bEndring av tilgangsnivå%b: " . login::$user->player->data['up_name'] . " endret tilgangsnivået til " . page_min_side::$active_user->data['u_email'] . " (" . page_min_side::$active_player->data['up_name'] . ") fra {$levels[$old]} til {$levels[$level]} {$__server['path']}/min_side?u_id=" . page_min_side::$active_user->id);
                        ess::$b->page->add_message('Tilgangsnivået ble endret fra <b>' . htmlspecialchars($levels[$old]) . '</b> til <b>' . htmlspecialchars($levels[$level]) . '</b>.');
                    } else {
                        ess::$b->page->add_message("Tilgangsnivået kunne ikke endres.", "error");
                    }
                    redirect::handle();
                }
            }
            echo '
	<div class="bg1_c" style="width: 350px">
		<h1 class="bg1">Endre tilgangsnivå for bruker<span class="left2"></span><span class="right2"></span></h1>
		<div class="bg1">' . (page_min_side::$active_player->active ? '
			<p>Dette vil automatisk berøre spilleren ' . page_min_side::$active_player->profile_link() . '.<p>' : '
			<p>Dette vil kun ha innvirkning på brukeren, siden det ikke er noen aktiv spiller.</p>') . '
			<form action="" method="post">
				<dl class="dd_right">
					<dt>Nåværende tilgangsnivå</dt>
					<dd>' . $levels[page_min_side::$active_user->data['u_access_level']] . '</dd>
					<dt>Nytt tilgangsnivå</dt>
					<dd>
						<select name="level">';
            $level = intval(postval("level", page_min_side::$active_user->data['u_access_level']));
            foreach ($levels as $id => $name) {
                echo '
							<option value="' . $id . '"' . ($level == $id ? ' selected="selected"' : '') . '>' . htmlspecialchars($name) . '</option>';
            }
            echo '
						</select>
					</dd>
					<dt>Begrunnelse</dt>
					<dd><textarea name="log" id="log" cols="30" rows="5">' . htmlspecialchars(postval("log")) . '</textarea></dd>
				</dl>' . (page_min_side::$active_player->active ? '
				<p><input type="checkbox" id="no_update_up" name="no_update_up"' . (isset($_POST['no_update_up']) ? ' checked="checked"' : '') . ' /><label for="no_update_up"> Ikke oppdater det visuelle tilgangsnivået til ' . page_min_side::$active_player->profile_link() . '</label></p>' : '') . '
				<p class="c">' . show_sbutton("Endre tilgangsnivå") . '</p>
			</form>
		</div>
	</div>';
        } elseif ($subpage2 == "banka" && access::has("mod")) {
            // lagre nytt passord
            if (isset($_POST['bank_auth'])) {
                $bank_auth = postval("bank_auth");
                $log = trim(postval("log"));
                // for kort?
                if (mb_strlen($bank_auth) < 6) {
                    ess::$b->page->add_message("Passordet må inneholde minst 6 tegn.", "error");
                } elseif (password::verify_hash($bank_auth, page_min_side::$active_user->data['u_bank_auth'], 'bank_auth')) {
                    ess::$b->page->add_message("Passordet er det samme som nåværende.", "error");
                } elseif ($log == "") {
                    ess::$b->page->add_message("Mangler begrunnelse.", "error");
                } else {
                    $newpass = password::hash($bank_auth, null, 'bank_auth');
                    \Kofradia\DB::get()->exec("UPDATE users SET u_bank_auth = " . \Kofradia\DB::quote($newpass) . " WHERE u_id = " . page_min_side::$active_user->id);
                    // crewlogg
                    crewlog::log("user_bank_auth", page_min_side::$active_player->id, $log, array("pass_old" => page_min_side::$active_user->data['u_bank_auth'], "pass_new" => $newpass));
                    ess::$b->page->add_message("Bankpassordet ble endret.");
                    redirect::handle();
                }
            }
            ess::$b->page->add_title("Endre bankpassord");
            echo '
	<div class="bg1_c" style="width: 350px">
		<h1 class="bg1">Endre bankpassord<span class="left2"></span><span class="right2"></span></h1>
		<div class="bg1">
			<form action="" method="post" autocomplete="off">
				<dl class="dd_right">
					<dt>Nytt bankpassord</dt>
					<dd><input type="password" id="bank_auth" class="styled w120" /></dd>
					<dt>Begrunnelse for endring</dt>
					<dd><textarea name="log" id="log" cols="30" rows="5">' . htmlspecialchars(postval("log")) . '</textarea></dd>
				</dl>
				<p class="c">' . show_sbutton("Lagre") . '</p>
			</form>
		</div>
	</div>';
        } elseif ($subpage2 == "phone" && access::has("mod")) {
            // lagre nytt nummer?
            if (isset($_POST['phone'])) {
                $phone = postval("phone");
                $log = trim(postval("log"));
                if (!preg_match("/^47\\d{8}\$/Du", $phone) && $phone != "") {
                    ess::$b->page->add_message("Ugyldig telefonnummer. Må bestå av 10 tall inkludert 47 først.", "error");
                } else {
                    // kontroller at nummeret ikke er lagt inn fra før
                    $result = \Kofradia\DB::get()->query("SELECT u_id, u_email, up_id, up_name, up_access_level FROM users, users_players WHERE u_phone = " . \Kofradia\DB::quote($phone) . " AND u_id != " . page_min_side::$active_user->id . " AND up_id = u_active_up_id LIMIT 1");
                    if ($result->rowCount() > 0) {
                        $row = $result->fetch();
                        ess::$b->page->add_message('Nummeret er allerede i bruk av <a href="min_side?u_id=' . $row['u_id'] . '">' . htmlspecialchars($row['u_email']) . '</a> (' . game::profile_link($row['up_id'], $row['up_name'], $row['up_access_level']) . ').', "error");
                    } elseif ($phone == page_min_side::$active_user->data['u_phone']) {
                        ess::$b->page->add_message("Nummeret er det samme som nåværende nummer.", "error");
                    } elseif ($log == "") {
                        ess::$b->page->add_message("Mangler logg melding.");
                    } else {
                        // lagre nytt nummer
                        \Kofradia\DB::get()->exec("UPDATE users SET u_phone = " . \Kofradia\DB::quote($phone) . " WHERE u_id = " . page_min_side::$active_user->id);
                        crewlog::log("user_phone", page_min_side::$active_player->id, $log, array("phone_old" => page_min_side::$active_user->data['u_phone'], "phone_new" => $phone));
                        ess::$b->page->add_message('Mobilnummeret ble endret fra <b>' . (empty(page_min_side::$active_user->data['u_phone']) ? 'tomt' : htmlspecialchars(page_min_side::$active_user->data['u_phone'])) . '</b> til <b>' . (empty($phone) ? 'tomt' : $phone) . '</b>.');
                    }
                }
            }
            ess::$b->page->add_title("Endre mobilnummer");
            echo '
	<div class="bg1_c" style="width: 350px">
		<h1 class="bg1">Endre mobilnummer<span class="left2"></span><span class="right2"></span></h1>
		<div class="bg1">
			<p>Her endrer du mobilnummeret til brukeren. Dette kan bli brukt til å sende ut forskjellig informasjon.</p>
			<form action="" method="post">
				<dl class="dd_right dl_2x">
					<dt>Nåværende nummer</dt>
					<dd>' . (empty(page_min_side::$active_user->data['u_phone']) ? 'Tomt' : htmlspecialchars(page_min_side::$active_user->data['u_phone'])) . '</dd>
					<dt>Nytt nummer</dt>
					<dd><input type="text" maxlength="10" value="' . htmlspecialchars(postval("phone", page_min_side::$active_user->data['u_phone'])) . '" name="phone" class="styled w80" /></dd>
					<dt>Begrunnelse for endring</dt>
					<dd><textarea name="log" cols="30" rows="5">' . htmlspecialchars(postval("log")) . '</textarea></dd>
				</dl>
				<p class="c">' . show_sbutton("Lagre") . '</p>
			</form>
		</div>
	</div>';
        } elseif ($subpage2 == "birth" && access::has("mod")) {
            // lagre ny fødselsdato?
            if (isset($_POST['birth_day']) && isset($_POST['birth_month']) && isset($_POST['birth_year'])) {
                $birth = postval("birth");
                // sjekk fødselsdato
                $birth_day = intval(postval("birth_day"));
                $birth_month = intval(postval("birth_month"));
                $birth_year = intval(postval("birth_year"));
                $date = ess::$b->date->get();
                $n_day = $date->format("j");
                $n_month = $date->format("n");
                $n_year = $date->format("Y");
                $age = $n_year - $birth_year - ($n_month < $birth_month || $birth_month == $n_month && $n_day < $birth_day ? 1 : 0);
                $birth = $birth_year . "-" . str_pad($birth_month, 2, "0", STR_PAD_LEFT) . "-" . str_pad($birth_day, 2, "0", STR_PAD_LEFT);
                // sjekk om fødselsdatoen er gyldig
                $birth_date = ess::$b->date->get();
                $birth_date->setDate($birth_year, $birth_month, $birth_day);
                $birth_valid = $birth_date->format("Y-m-d") == $birth;
                $log = trim(postval("log"));
                // ugyldig dag?
                if ($birth_day < 0 || $birth_day > 31) {
                    ess::$b->page->add_message("Du må velge en gyldig dag.", "error");
                } elseif ($birth_month < 0 || $birth_month > 12) {
                    ess::$b->page->add_message("Du må velge en gyldig måned.", "error");
                } elseif (($birth_year < 1900 || $birth_year > $n_year) && $birth_year !== 0) {
                    ess::$b->page->add_message("Du må velge et gyldig år.", "error");
                } elseif (!$birth_valid && $birth !== '0-00-00') {
                    ess::$b->page->add_message("Datoen du fylte inn for fødselsdatoen din eksisterer ikke.");
                } elseif ($birth == page_min_side::$active_user->data['u_birth']) {
                    ess::$b->page->add_message("Fødselsdatoen ble ikke endret.", "error");
                } elseif ($log == "") {
                    ess::$b->page->add_message("Mangler begrunnelse.", "error");
                } else {
                    // oppdater
                    \Kofradia\DB::get()->exec("UPDATE users SET u_birth = " . \Kofradia\DB::quote($birth) . " WHERE u_id = " . page_min_side::$active_user->id);
                    // legg til crewlogg
                    crewlog::log("user_birth", page_min_side::$active_player->id, $log, array("birth_old" => page_min_side::$active_user->data['u_birth'], "birth_new" => $birth));
                    // alder
                    if ($age < 13) {
                        ess::$b->page->add_message("Fødselsdatoen ble satt til <b>{$birth}</b> ({$age} år). Brukeren oppfyller <u>ikke</u> kravet om alder jf. betingelsene.");
                    } else {
                        ess::$b->page->add_message("Fødselsdatoen ble satt til <b>{$birth}</b> ({$age} år).");
                    }
                    redirect::handle();
                }
            }
            $birth = explode("-", page_min_side::$active_user->data['u_birth']);
            $birth_day = isset($birth[2]) ? intval($birth[2]) : 0;
            $birth_month = isset($birth[1]) ? intval($birth[1]) : 0;
            $birth_year = isset($birth[0]) ? intval($birth[0]) : 0;
            ess::$b->page->add_title("Endre fødselsdato");
            echo '
	<div class="bg1_c" style="width: 350px">
		<h1 class="bg1">Endre fødselsdato<span class="left2"></span><span class="right2"></span></h1>
		<div class="bg1">
			<form action="" method="post">
				<dl class="dd_right dl_2x">
					<dt>Nåværende fødselsdato</dt>
					<dd>' . (empty(page_min_side::$active_user->data['u_birth']) ? 'Ikke registrert' : htmlspecialchars(page_min_side::$active_user->data['u_birth'])) . '</dd>
					<dt>Ny fødselsdato</dt>
					<dd>
						<select name="birth_day">
							<option value="">Dag</option>
							<option value="0">0</option>';
            $active = postval("birth_day", $birth_day);
            for ($i = 1; $i <= 31; $i++) {
                echo '
							<option value="' . $i . '"' . ($i == $active ? ' selected="selected"' : '') . '>' . $i . '</option>';
            }
            echo '
						</select>
						<select name="birth_month">
							<option value="">Måned</option>
							<option value="0">Tom</option>';
            $active = postval("birth_month", $birth_month);
            for ($i = 1; $i <= 12; $i++) {
                echo '
							<option value="' . $i . '"' . ($i == $active ? ' selected="selected"' : '') . '>' . ucfirst($_lang['months'][$i]) . '</option>';
            }
            echo '
						</select>
						<select name="birth_year">
							<option value="">År</option>
							<option value="0">0000</option>';
            $active = postval("birth_year", $birth_year);
            for ($i = ess::$b->date->get()->format("Y"); $i >= 1900; $i--) {
                echo '
							<option value="' . $i . '"' . ($i == $active ? ' selected="selected"' : '') . '>' . $i . '</option>';
            }
            echo '
						</select>
					</dd>
					<dt>Begrunnelse for endring</dt>
					<dd><textarea name="log" id="log" cols="30" rows="5">' . htmlspecialchars(postval("log")) . '</textarea></dd>
				</dl>
				<p class="c">' . show_sbutton("Lagre") . '</p>
			</form>
		</div>
	</div>';
        }
    }
Example #2
0
    /**
     * Vis logger
     */
    protected function show_logs()
    {
        $filters = "";
        if ($this->filter_actions) {
            $filters .= " AND lc_lca_id IN (" . implode(",", $this->filter_actions) . ")";
        }
        if ($this->filter_time_before) {
            $filters .= " AND lc_time <= {$this->filter_time_before}";
        }
        if ($this->filter_time_after) {
            $filters .= " AND lc_time >= {$this->filter_time_after}";
        }
        if ($this->filter_by_up) {
            $filters .= " AND lc_up_id" . (isset($_POST['by_invert']) ? ' NOT' : '') . " IN (" . $this->get_full_up_list($this->filter_by_up) . ")";
        }
        if ($this->filter_a_up) {
            $filters .= " AND lc_a_up_id" . (isset($_POST['a_invert']) ? ' NOT' : '') . " IN (" . $this->get_full_up_list($this->filter_a_up) . ")";
        }
        $pagei = new pagei(pagei::ACTIVE_GET, "side", pagei::ACTIVE_POST, "side", pagei::PER_PAGE, 100);
        $result = $pagei->query("\n\t\t\tSELECT lc_id, lc_up_id, lc_time, lc_lca_id, lc_a_up_id, lc_log\n\t\t\tFROM log_crew\n\t\t\tWHERE 1{$filters}\n\t\t\tORDER BY lc_time DESC");
        $rows = array();
        while ($row = $result->fetch()) {
            $rows[$row['lc_id']] = $row;
        }
        $data = crewlog::load_summary_data($rows);
        $logs = array();
        foreach ($data as $row) {
            // hent sammendrag
            $summary = crewlog::make_summary($row);
            $day = ess::$b->date->get($row['lc_time'])->format(date::FORMAT_NOTIME);
            $logs[$day][] = '<p><span class="time"><a href="' . ess::$s['relative_path'] . '/crew/crewlogg?lc_id=' . $row['lc_id'] . '">' . ess::$b->date->get($row['lc_time'])->format("H:i") . '</a>:</span> ' . $summary . '</p>';
        }
        ess::$b->page->add_css('
		h1.crewlog { margin: 30px auto 20px }
		div.crewlog { margin: 0 30px }
		.crewlog .time { color: #888888; padding-right: 5px }
		');
        if ($this->filters_active) {
            echo '
		<p class="c">Fant ' . fwords("%d oppføring", "%d oppføringer", $pagei->total) . ' som passet til filteret.</p>';
        }
        echo '
		<p class="c">' . $pagei->pagenumbers($this->filters_active ? "input" : null) . '</p>
		<div class="crewlog">';
        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">
					' . implode('
					', $items) . '
				</div>
			</div>';
        }
        echo '
			<p class="c">' . $pagei->pagenumbers($this->filters_active ? "input" : null) . '</p>
		</div>';
    }
Example #3
0
    /**
     * Felt for advarsel
     */
    protected static function advarsel_input($kategori = null)
    {
        $active = !empty($_POST['a_active']);
        $types = crewlog::$user_warning_types;
        $types_name = crewlog::$user_warning_types_name;
        ess::$b->page->add_js_domready('
	$("advarsel_inactive").getElement("a").addEvent("click", function(event)
	{
		$("advarsel_inactive").addClass("hide");
		$("advarsel_active").removeClass("hide");
		$("a_active").set("value", "1");
		event.stop();
	});
	$("advarsel_active").getElement("a").addEvent("click", function(event)
	{
		$("advarsel_inactive").removeClass("hide");
		$("advarsel_active").addClass("hide");
		$("a_active").set("value", "0");
		event.stop();
	});');
        $html = '
<div id="advarsel_inactive"' . ($active ? ' class="hide"' : '') . '>
	<p class="c"><a href="#">Legg til advarsel sammen med endringen</a></p>
</div>
<div id="advarsel_active"' . (!$active ? ' class="hide"' : '') . '>
	<p class="c"><a href="#">Ikke legg til advarsel</a></p>
	<div class="bg1_c" style="width: 400px">
		<h1 class="bg1">Gi advarsel til brukeren<span class="left2"></span><span class="right2"></span></h1>
		<div class="bg1">
			<form action="" method="post">
				<input type="hidden" name="a_active" id="a_active" value="' . ($active ? 1 : 0) . '" />
				<dl class="dd_right">';
        if ($kategori) {
            if (!isset($types_name[$kategori])) {
                throw new HSException("Ugyldig kategori.");
            }
            $html .= '
					<dt>Kategori</dt>
					<dd>' . htmlspecialchars($types[$types_name[$kategori]]) . '</dd>';
        } else {
            $html .= '
					<dt>Kategori</dt>
					<dd>
						<select name="a_type">';
            $type = isset($_POST['a_type']) && isset($types[$_POST['a_type']]) ? intval($_POST['a_type']) : false;
            if ($type === false) {
                $html .= '
							<option value="">Velg ..</option>';
            }
            foreach ($types as $key => $row) {
                $html .= '
							<option value="' . $key . '"' . ($key === $type ? ' selected="selected"' : '') . '>' . htmlspecialchars($row) . '</option>';
            }
            $html .= '
						</select>
					</dd>';
        }
        $html .= '
					<dt>Alvorlighet/prioritet</dt>
					<dd>
						<select name="a_priority">';
        $priority = isset($_POST['a_priority']) && is_numeric($_POST['a_priority']) && $_POST['a_priority'] >= 1 && $_POST['a_priority'] <= 3 ? $_POST['a_priority'] : 2;
        $html .= '
							<option value="1"' . ($priority == 1 ? ' selected="selected"' : '') . '>Lav</option>
							<option value="2"' . ($priority == 2 ? ' selected="selected"' : '') . '>Moderat</option>
							<option value="3"' . ($priority == 3 ? ' selected="selected"' : '') . '>Høy</option>
						</select>
					</dd>
				</dl>
				<p>Begrunnelse for advarsel</p>
				<p><textarea name="a_log" rows="10" cols="30" style="width: 98%">' . htmlspecialchars(postval("a_log")) . '</textarea></p>
				<p><input type="checkbox" name="a_notify"' . ($_SERVER['REQUEST_METHOD'] == "POST" && !isset($_POST['a_notify']) ? '' : ' checked="checked"') . ' id="warning_notify" /><label for="warning_notify"> Gi brukeren informasjon om denne advarselen. Kun kategori og begrunnelse vil bli oppgitt til brukeren som en logg i hendelser.</label></p>
			</form>
		</div>
	</div>';
        // analyser advarsler
        $lca_id = crewlog::$actions['user_warning'][0];
        $pagei = new pagei(pagei::ACTIVE_GET, "side", pagei::PER_PAGE, 15);
        $result = $pagei->query("\n\t\t\tSELECT lc_id, lc_up_id, lc_time, lc_log, lcd_data_int\n\t\t\tFROM log_crew\n\t\t\t\tJOIN users_players ON lc_a_up_id = up_id AND up_u_id = " . page_min_side::$active_user->id . "\n\t\t\t\tLEFT JOIN log_crew_data ON lcd_lc_id = lc_id AND lcd_lce_id = 5\n\t\t\tWHERE lc_lca_id = {$lca_id} AND (lcd_data_int IS NULL OR lcd_data_int = 0)\n\t\t\tORDER BY lc_time DESC");
        $data = array();
        while ($row = $result->fetch()) {
            $data[$row['lc_id']] = $row;
        }
        // sett opp data
        $data = crewlog::load_summary_data($data);
        $html .= '
	<div class="bg1_c ' . (count($data) == 0 ? 'xsmall' : 'xmedium') . '">
		<h1 class="bg1">Tidligere advarsler<span class="left2"></span><span class="right2"></span></h1>
		<div class="bg1">';
        if (count($data) == 0) {
            $html .= '
			<p>Brukeren har ingen tidligere advarsler.</p>';
        } else {
            ess::$b->page->add_css('
.advarsel { border: 1px solid #292929; margin: 10px 0; padding: 0 10px }');
            foreach ($data as $row) {
                $priority = $row['data']['priority'] == 1 ? "lav" : ($row['data']['priority'] == 2 ? "moderat" : "høy");
                $html .= '
			<div class="advarsel">
				<p><b>' . ess::$b->date->get($row['lc_time'])->format() . '</b>: ' . $row['data']['type'] . ' (alvorlighet: <b>' . $priority . '</b>):</p>
				<ul>
					<li>' . game::format_data($row['lc_log']) . '</li>
					<li>Internt notat: ' . game::format_data($row['data']['note']) . '</li>
				</ul>
				<p>' . (empty($row['data']['notified']) ? 'Ble IKKE varslet.' : 'Ble varslet.') . ' Av <user id="' . $row['lc_up_id'] . '" /></p>
			</div>';
            }
            // TODO: AJAX på sidevalg
            $html .= '
			<p class="c">' . $pagei->pagenumbers() . '</p>';
            if ($pagei->pages > 1) {
                $html .= '
			<p class="c dark">(Sidene åpner i samme vindu, så pass på hvis du har fylt inn feltene ovenfor.)</p>';
            }
        }
        $html .= '
		</div>
	</div>
</div>';
        return $html;
    }