error() static public method

An internal error handler
static public error ( string $msg = null, boolean $exit = false ) : mixed
$msg string The error/success message to return
$exit boolean die after this error?
return mixed
Example #1
0
 public function __construct($dbname, $dbuser, $dbpass, $error = array(NULL, NULL))
 {
     self::$error = new error($error[0], $error[1]);
     $this->json = new Services_JSON();
     $fp = fopen(CWD . "users", "r");
     while (fscanf($fp, "%s\n", $hash)) {
         if ($hash == md5($dbuser . $dbpass)) {
             self::$access = 1;
             break;
         }
         if (self::$access == 0) {
             $this->nouser($dbuser);
         }
     }
     if (self::$access == 1) {
         if (!is_dir(CWD . $dbname)) {
             if (!defined('ADMIN') || ADMIN == 0) {
                 $this->nodb($dbname);
             } else {
                 if (ADMIN == 1) {
                     $this->createdb($dbname);
                 }
             }
         } else {
             self::$db = CWD . $dbname . "/";
         }
     }
 }
Example #2
0
<button onclick="location='/44/login/logout.php'">登出</button>
<?php 
echo getsession("account") . " #" . getsession("id") . " ~" . getsession("name");
?>
<br>
<a href=".">預約單/取消</a> | <a href="search.php">查詢/預約</a> | <a href="view.php">會議室瀏覽</a><br>
<br>
<fieldset><legend>預約單</legend>
<table border=2>
<tr><th><a href=".?sort=0">預約單編號</a></th><th><a href=".?sort=1">使用日期</a><br>(年/月/日)</th><th>使用時段</th><th>會議室編號</th><th>借用人</th><th></th></tr>
<?php 
$A = new db();
$B = new db();
switch (get("sort")) {
    case 0:
        $A->query("select * from reserves where name='" . getsession("id") . "' order by serial") ?: $A->error();
        break;
    case 1:
        $A->query("select * from reserves where name='" . getsession('id') . "' order by date") ?: $A->error();
        break;
}
if ($A->count() > 0) {
    while ($A->fetch()) {
        ?>
<tr>
<td><?php 
        echo $A->element("serial");
        ?>
</td>
<td><?php 
        echo str_replace("-", "/", $A->element("date"));
Example #3
0
<?php

include_once 'phplib/base.php';
if (!db::connect()) {
    echo "Database connection failed, cannot continue. ";
} else {
    $timestamp = time();
    $username = getUsername();
    $range_start = db::escape($_POST['range_start']);
    $range_end = db::escape($_POST['range_end']);
    $report_id = generateMeetingNotesID($range_start, $range_end);
    $notes = db::escape($_POST['weeklynotes']);
    $query = "INSERT INTO meeting_notes (report_id, range_start, range_end, timestamp, user, notes) VALUES ('{$report_id}', '{$range_start}', '{$range_end}', '{$timestamp}', '{$username}', '{$notes}')";
    if (!db::query($query)) {
        echo "Database update failed, error: " . db::error();
    } else {
        Header("Location: {$ROOT_URL}/index.php?meeting_done=hellyeah");
    }
}
Example #4
0
<?php

include $_SERVER["DOCUMENT_ROOT"] . "/44/func/mysql.php";
isroot();
$id = post("id");
$password = post("password");
$name = post("name");
$question = post("question");
$answer = post("answer");
$A = new db();
if (post("delete")) {
    $A->query("delete from accounts where id = '{$id}'") ?: $A->error();
    echo "已刪除";
    redirect("/admin/");
} else {
    if (post("save")) {
        $A->query("update accounts set password='******', name='{$name}', question='{$question}', answer='{$answer}' where id='{$id}'") ?: $A->error();
        echo "已更新";
        redirect("/admin/");
    } else {
        echo "錯誤!!";
    }
}
<?php

include $_SERVER["DOCUMENT_ROOT"] . "/44/func/mysql.php";
ismember();
if (post("delete")) {
    $id = post("id");
    $A = new db();
    $A->query("delete from reserves where id = '{$id}'") ?: $A->error();
    echo "已刪除";
    redirect("/member/.");
} else {
    echo "錯誤!!";
}
        }
        $A->query("update floors set name='{$name}',r1='{$status['0']}',r2='{$status['1']}',r3='{$status['2']}',r4='{$status['3']}',r5='{$status['4']}',r6='{$status['5']}' where id = '{$id}'") ?: $A->error();
        echo "已更新";
    }
} else {
    if (post("delete")) {
        if (post("N")) {
            redirect("/admin/floor.php");
            die("已取消操作!!");
        }
        $id = post("id");
        $A = new db();
        $B = new db();
        $msg = '0';
        if (post("Y")) {
            $A->query("delete from floors where id = '{$id}'") ?: $A->error();
            $B->query("delete from reserves where floor = '{$id}'");
            redirect("/admin/floor.php");
            die("已刪除");
        }
        $B->query("select * from reserves where floor='{$id}'");
        if ($B->count() > 0) {
            while ($B->fetch()) {
                if ($msg == '0') {
                    ?>
                <table border=2>
					<tr>
						<th>預約單編號</th><th>使用日期<br>(年/月/日)</th><th>使用時段</th><th>會議室號碼</th><th>借用人</th>
					</tr>
                <?php 
                }
Example #7
0
<?php

include $_SERVER["DOCUMENT_ROOT"] . "/44/func/mysql.php";
if (post("your_answer") != post("correct_answer")) {
    echo "驗證碼錯誤!";
    session_destroy();
    redirect("/login");
    die;
}
if (post("account") == "admin" && post("password") == "1234") {
    setsession("account", "admin");
    setsession("id", "-1");
    redirect("/admin");
    echo "請稍後...";
} else {
    $A = new db();
    $A->query("select * from accounts where account = '" . post("account") . "' and password = '******'") ?: $A->error();
    if ($A->fetch()) {
        setsession("account", post("account"));
        setsession("id", $A->element("id"));
        setsession("name", $A->element("name"));
        echo "請稍後...";
        redirect("/member");
    } else {
        echo "帳號密碼錯誤!";
        redirect("/login");
    }
}
Example #8
0
        if (count($insert_values) > 0) {
            $insert_values_string = implode(', ', $insert_values);
            $insert_query = "INSERT INTO oncall_weekly (alert_id, range_start, range_end, timestamp, hostname, service, state, contact, output, tag, sleep_state, mtts, sleep_level, sleep_confidence, notes) VALUES {$insert_values_string}";
            if (!db::query($insert_query)) {
                echo "Database insert failed, error: " . db::error();
                logline("Database insert failed, error: " . db::error());
            }
        }
        // NOTE: This doesn't solve for entries that are already duplicated.
        // But this should prevent future entries from being duplicated.
        if (count($update_values) > 0) {
            foreach ($update_values as $update_hash) {
                $set_columns = array();
                foreach ($update_hash as $column => $value) {
                    array_push($set_columns, "{$column}='{$value}'");
                }
                $update_values_string = implode(', ', $set_columns);
                $update_query = "UPDATE oncall_weekly SET {$update_values_string} WHERE alert_id='{$update_hash['alert_id']}'";
                if (!db::query($update_query)) {
                    echo "Database update failed, error: " . db::error();
                    logline("Database update failed, error: " . db::error());
                }
            }
        }
        logline("Everything worked great, redirecting the user with success");
        Header('Location: add.php?oncall_succ=hellyeah');
    } else {
        logline("We didn't find any notifications to process, redirect user back to add page");
        Header('Location: add.php');
    }
}
Example #9
0
    <input type="hidden" name="step" value="3">
    </form></td>
    </tr>
    </table>
    </fieldset>
    <?php 
        break;
    case 3:
        $A = new db();
        $serial = rand(999999, 9999999);
        $date = get("date");
        $section = get("section");
        $floor = get("floor");
        $room = get("room");
        $name = getsession("id");
        $A->query("insert into reserves values ('','{$serial}','{$date}','{$section}','{$floor}','{$room}','{$name}')") ?: $A->error();
        ?>
    <fieldset><legend>已新增以下預約單</legend>
     <table border=2>
    <tr><th>使用日期<br>(年/月/日)</th><th>使用時段</th><th>會議室號碼</th></tr>
    <tr>
    <td><?php 
        echo str_replace("/", "-", get("date"));
        ?>
</td>
    <td><?php 
        echo section(get("section"));
        ?>
</td>
    <td><a href="search.php?step=4&floor=<?php 
        echo get("floor");
Example #10
0
<?php

include $_SERVER["DOCUMENT_ROOT"] . "/44/func/mysql.php";
isroot();
$name = post("name");
$A = new db();
$A->query("insert into floors values('','{$name}',1,1,1,1,1,1)") ?: $A->error();
echo "已新增";
redirect("/admin/floor.php");
Example #11
0
<?php

include $_SERVER["DOCUMENT_ROOT"] . "/44/func/mysql.php";
isroot();
if (!post("account")) {
    die("錯誤!!");
}
$account = post("account");
$password = post("password");
$name = post("name");
$question = post("question");
$answer = post("answer");
$A = new db();
$A->query("select * from accounts where account='{$account}'") ?: $A->error();
if ($A->fetch()) {
    echo "此帳號已存在!!";
} else {
    $A->query("insert into accounts values ('','{$account}','{$password}','{$name}','{$question}','{$answer}')") ?: $A->error();
    echo "已新增";
}
redirect("/admin/");