コード例 #1
0
ファイル: schedule.php プロジェクト: kstm-su/syllabus
<?php

include_once '../lib/util.php';
$db = new DBAdmin();
$db->truncate('schedule');
echo 'Updating `schedule` table ... ';
$q = $db->selectAll('htmldata');
$db->begin();
while ($row = $q->fetch_assoc()) {
    $schedules = trim(kana($row['schedule']));
    if ($schedules === '') {
        $db->insert('schedule', array('id' => $row['id']));
    }
    foreach (explode(' ', $schedules) as $schedule) {
        if ($schedule) {
            preg_match('/^(?:(集)|(日|月|火|水|木|金|土))?(?:(?:(\\d+)|(不定))' . '(後)?(?:~(\\d+)(前)?)?)?$/', $schedule, $m);
            if ($m) {
                $m = array_pad($m, 8, 0);
                for ($i = (int) $m[3]; $i <= max((int) $m[6], (int) $m[3]); $i++) {
                    $data = array('id' => $row['id'], 'day' => $m[2] ? mb_strpos('日月火水木金土', $m[2]) : NULL, 'period' => $i ? $i : NULL, 'early' => $i == $m[6] && (bool) $m[7], 'late' => $i == $m[3] && (bool) $m[5], 'intensive' => (bool) $m[1], 'irregular' => (bool) $m[4], 'description' => $schedule);
                    $db->insert('schedule', $data);
                }
            } else {
                echo "{$schedule}\n";
            }
        }
    }
    echo "{$row['id']}";
}
$db->commit();
$db->close();
コード例 #2
0
ファイル: summary.php プロジェクト: kstm-su/syllabus
<?php

include_once '../lib/util.php';
$db = new DBAdmin();
echo 'Updating `summary` table ... ';
$table = $db->query('SELECT `list`.`id`, `list`.`year`,
	`department`.`department_id`, `htmldata`.`code`, `htmldata`.`title`,
	`htmldata`.`title_english`, `htmldata`.`credit`, `htmldata`.`target`,
	`htmldata`.`style`, `htmldata`.`note`, `htmldata`.`public`,
	`htmldata`.`ches` FROM `list` LEFT JOIN `htmldata`
	ON `list`.`id` = `htmldata`.`id` LEFT JOIN `department`
	ON `list`.`department_code` = `department`.`department_code`
	ORDER BY `list`.`id`');
$db->begin();
while ($row = $table->fetch_assoc()) {
    $row = array_map(function ($s) {
        return trim(kana($s));
    }, $row);
    if ($row['code'] === '') {
        $row['code'] = NULL;
    }
    $db->replace('summary', $row);
    echo "{$row['id']}";
}
$db->commit();
$db->close();
echo " " . PRINT_OK . PHP_EOL;
コード例 #3
0
ファイル: list.php プロジェクト: kstm-su/syllabus
$src = file_get_contents(SEARCH_URL);
echo PRINT_OK . PHP_EOL;
$html = htmlobject($src);
$tr = $html->body->form->table->tbody->tr->td->table->tbody->tr;
$year = (int) $tr[1]->td[1]->input['value'];
$departments = $tr[0]->td[1]->select->option;
/* 年度を更新 */
$db->query('INSERT INTO `config` (`name`, `value`) VALUES (\'year\', ?)
	ON DUPLICATE KEY UPDATE `name` = \'year\', `value` = ?', $year, $year);
/* 部局リストの更新 */
echo 'Updating `department` table ... ';
$db->begin();
foreach ($departments as $department) {
    $code = (string) $department['value'];
    if ($code) {
        $name = kana((string) $department);
        $db->insert('department', array('department_code' => $code, 'name' => $name));
    }
}
$db->commit();
echo PRINT_OK . PHP_EOL;
/* 講義データのリストを取得 */
echo 'Updating `list` table ... ';
$postdata = array('MODE' => 0, 'STARTNO' => 0, 'NENDO' => $year, 'CODE_JYOUKEN' => 0, 'BtKENSAKU' => 0);
for ($i = 0, $j = -1;; $j = -1) {
    $src = post_request(SEARCH_URL, $postdata);
    $html = htmlobject($src);
    $tr = $html->body->form->table[1]->tbody->tr;
    if (count($tr) <= 1) {
        echo "{$i} " . PRINT_OK . PHP_EOL;
        break;
コード例 #4
0
ファイル: search.php プロジェクト: kstm-su/syllabus
header("Content-Type: application/json; charset=UTF-8; Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Origin: *");
//公開前にパーミッション設定と、dbクラスのパスの置き換えを行うこと
require_once '../lib/util.php';
$db = new DBGuest();
//対応予定のオプション一覧です。
$SerchOptions = array("id", "year", "code", "subject", "title", "teacher", "staff", "season", "semester", "schedule", "location", "room", "classroom", "unit", "credit", "target", "style", "department", "word");
//曜日の配列です。順番が大事(mon->2)なので、追加は構わないが、挿入するときはよく注意すること。
//$dweek=array("sun","mon","tue","wed","thu","fri","sat");
$dweek = array("su", "mo", "tu", "we", "th", "fr", "sa");
$input = array_map(function ($req) {
    if (is_array($req)) {
        return array_map('kana', $req);
    }
    return array(kana($req));
}, $_REQUEST);
$query = "";
$summaryquery = "";
//idをそれぞれで検索するクエリをここに入れて、最後に統合します。
$queryarray = array();
foreach ($SerchOptions as $SerchOption) {
    if (isset($input[$SerchOption])) {
        if (is_array($input[$SerchOption])) {
            switch ($SerchOption) {
                /*こちらで振った独自idでの検索です。
                 *このid検索はid[]=55でidが55の授業にヒットさせることができる他、id[]=1..100で1以上100以下のidにヒットさせることができます。
                 * */
                case "id":
                    $input[$SerchOption] = array_map(function ($x) {
                        return explode(",", $x);
コード例 #5
0
ファイル: textdata.php プロジェクト: kstm-su/syllabus
        $pattern = '/^【(.*?)】\\n(?:\\-{50}\\n\\s*([\\s\\S]*?))?\\s*$/';
        preg_match($pattern, $paragraph, $matches);
        if (isset($matches[1]) === FALSE) {
            $matches[1] = '';
        }
        if (isset($matches[2]) === FALSE) {
            $matches[2] = NULL;
        }
        list(, $key, $value) = $matches;
        if (!$key && !$value) {
            continue;
        }
        /* 英数字を半角に、カタカナを全角に変換 */
        $key = trim(kana($key));
        if (!is_null($value)) {
            $value = trim(kana($value));
        }
        if (isset($data[$key])) {
            if (!is_null($value)) {
                $data[$key] .= "\n{$value}";
            }
        } else {
            $data[$key] = $value;
        }
    }
    foreach ($data as $key => $value) {
        /* DBに追加 */
        $db->insert('textdata', array('id' => $row['id'], 'key' => $key, 'value' => $value));
    }
    echo "{$row['id']}";
}
コード例 #6
0
ファイル: htmldata.php プロジェクト: kstm-su/syllabus
    $data['code'] = $tmp[1]->table->tbody->tr[0]->td[3];
    $data['public'] = (int) (strpos($tmp[0], '市民開放授業') !== FALSE);
    $data['ches'] = (int) (strpos($tmp[0], '県内大学') !== FALSE);
    $tmp = $tmp[1]->table->tbody->tr;
    $data['title'] = $tmp[1]->td[1];
    if (substr($data['code'], 0, 1) !== 'M') {
        $data['title_english'] = $tmp[2]->td;
        $data['teacher'] = $tmp[3]->td[1];
        $data['sub_teacher'] = $tmp[3]->td[3];
        $data['semester'] = $tmp[4]->td[1];
        $data['schedule'] = $tmp[4]->td[3];
        $data['classroom'] = $tmp[4]->td[5];
        $data['credit'] = $tmp[4]->td[7];
        $data['target'] = $tmp[5]->td[1];
        $data['style'] = $tmp[5]->td[3];
        $data['note'] = $tmp[5]->td[5];
    } else {
        $data['teacher'] = $tmp[2]->td[1];
        $data['semester'] = $tmp[3]->td[3];
        $data['schedule'] = $tmp[3]->td[5];
        $data['classroom'] = $tmp[4]->td[3];
        $data['credit'] = (double) kana($tmp[4]->td[1]);
        $data['target'] = $tmp[3]->td[1];
        $data['note'] = $tmp[1]->td[3];
    }
    $db->replace('htmldata', $data);
    echo "{$row['id']}";
}
$db->commit();
$db->close();
echo " " . PRINT_OK . PHP_EOL;
コード例 #7
0
ファイル: teacher.php プロジェクト: kstm-su/syllabus
    }
}
echo 'Updating `teacher` table ... ';
$q = $db->selectAll('htmldata');
$db->begin();
while ($row = $q->fetch_assoc()) {
    $teacher = trim($row['teacher']);
    if ($teacher) {
        $teachers = preg_split('/  |,| (?![A-Z])/', $teacher);
        foreach ($teachers as $i => $teacher) {
            $teacher = trim(kana($teacher));
            if ($teacher && $teacher !== '他') {
                $db->insert('staff', array('name' => $teacher));
                insertTeacher($db, $row['id'], $teacher, !$i);
            }
        }
    }
    $sub = $row['sub_teacher'];
    $sub = kana($sub);
    foreach (explode('・', $sub) as $teacher) {
        $teacher = trim($teacher);
        if ($teacher) {
            $db->insert('staff', array('name' => $teacher));
            insertTeacher($db, $row['id'], $teacher, FALSE);
        }
    }
    echo "{$row['id']}";
}
$db->commit();
$db->close();
echo " " . PRINT_OK . PHP_EOL;
コード例 #8
0
ファイル: index.php プロジェクト: KohtaHorike/showa
function h($str)
{
    return htmlspecialchars($str, ENT_QUOTES);
}
function kana($str)
{
    return mb_convert_kana($str, "rna");
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $postflg = "1";
    $dbh = connectDb();
    //	var_dump($_POST);
    if (isset($_POST["submit"])) {
        $company = h($_POST["company"]);
        $kname = h($_POST["kname"]);
        $email = kana(h($_POST["email"]));
        $tel = h($_POST["tel"]);
        $memo = h($_POST["memo"]);
        //登録開始
        try {
            $dbh->beginTransaction();
            //開始
            $sql = "INSERT INTO inquiry(name,company,email,phone,memo,created,modified) \n\t\t\tVALUES(:name,:company,:email,:phone,:memo,now(),now())";
            $stmt = $dbh->prepare($sql);
            $stmt->bindParam(":name", $kname, PDO::PARAM_STR);
            $stmt->bindParam(":company", $company, PDO::PARAM_STR);
            $stmt->bindParam(":email", $email, PDO::PARAM_STR);
            $stmt->bindParam(":phone", $tel, PDO::PARAM_STR);
            $stmt->bindParam(":memo", $memo, PDO::PARAM_STR);
            $stmt->execute();
            $dbh->commit();
コード例 #9
0
ファイル: semester.php プロジェクト: kstm-su/syllabus
<?php

include_once '../lib/util.php';
$db = new DBAdmin();
echo 'Updating `semester` table ... ';
$q = $db->selectAll('htmldata');
$db->begin();
while ($row = $q->fetch_assoc()) {
    $desc = trim(kana($row['semester']));
    if ($desc) {
        $full = strpos($desc, '通年') !== FALSE;
        $first = $full || strpos($desc, '前期') !== FALSE;
        $second = $full || strpos($desc, '後期') !== FALSE;
        $intensive = strpos($desc, '集中') !== FALSE;
        $db->insert('semester', array('first' => $first, 'second' => $second, 'intensive' => $intensive, 'description' => $desc));
    }
    $db->query('UPDATE `summary` SET `semester_id` =
		(SELECT `semester_id` FROM `semester` WHERE `description` = ?)
		WHERE `id` = ?', $desc, $row['id']);
}
$db->commit();
$db->close();
echo " " . PRINT_OK . PHP_EOL;
コード例 #10
0
ファイル: classroom.php プロジェクト: kstm-su/syllabus
<?php

include_once '../lib/util.php';
$db = new DBAdmin();
$db->truncate('room');
$db->truncate('classroom');
echo 'Updating `classroom` table ... ';
$q = $db->query('SELECT `list`.`id`, `list`.`place`, `htmldata`.`classroom`
	FROM `list` JOIN `htmldata` ON `list`.`id` = `htmldata`.`id`');
$db->begin();
while ($row = $q->fetch_assoc()) {
    $place = kana($row['place']);
    $rooms = trim(kana($row['classroom']));
    $did = $db->single('SELECT `department_id` FROM `department`
		WHERE `name` = ?', $place);
    if (is_null($did)) {
        if ($place) {
            $did = $db->single('SELECT `department_id` FROM `department` WHERE ' . implode(' AND ', array_map(function ($s) use($db) {
                return "`name` LIKE '%" . $db->escape($s) . "%'";
            }, preg_split('/\\(|\\)/', $place))));
        }
    }
    foreach (explode(' ', $rooms) as $room) {
        if (is_null($did) && !$room) {
            continue;
        }
        $db->insert('room', array('department_id' => $did, 'name' => $room));
        $did = is_null($did) ? 'IS NULL' : "= '" . $db->escape($did) . "'";
        $rid = $db->single("SELECT `room_id` FROM `room`\n\t\t\tWHERE `department_id` {$did} AND `name` = ?", $room);
        $db->insert('classroom', array('id' => $row['id'], 'room_id' => $rid));
    }