Esempio n. 1
0
/**
 * ユーザのオートログイン
 *
 * @param string $session_id
 *
 * @return array
 */
function service_user_autologin($session_id)
{
    // セッションを取得
    $users = select_sessions(array('select' => 'user_id, keep', 'where' => array('id = :id AND expire > :expire', array('id' => $session_id, 'expire' => localdate('Y-m-d H:i:s')))));
    $session = false;
    $user_id = null;
    if (!empty($users)) {
        // セッションを更新
        $new_session_id = rand_string();
        $resource = update_sessions(array('set' => array('id' => $new_session_id, 'agent' => $_SERVER['HTTP_USER_AGENT'], 'expire' => localdate('Y-m-d H:i:s', time() + $GLOBALS['config']['cookie_expire'])), 'where' => array('id = :id', array('id' => $session_id))));
        if ($resource) {
            cookie_set('auth[session]', $new_session_id, time() + $GLOBALS['config']['cookie_expire']);
        } else {
            error('データを編集できません。');
        }
        if ($users[0]['keep']) {
            // ユーザを更新
            $resource = update_users(array('set' => array('loggedin' => localdate('Y-m-d H:i:s')), 'where' => array('id = :id', array('id' => $users[0]['user_id']))));
            if (!$resource) {
                error('データを編集できません。');
            }
            $session = true;
            $user_id = $users[0]['user_id'];
        }
    }
    return array($session, $user_id);
}
Esempio n. 2
0
/**
 * メールの送信
 *
 * @param string $to
 * @param string $subject
 * @param string $message
 * @param array  $headers
 * @param array  $files
 *
 * @return bool
 */
function service_mail_send($to, $subject, $message, $headers = array(), $files = array())
{
    if ($GLOBALS['config']['mail_send'] === true) {
        return mail_send($to, $subject, $message, $headers);
    } else {
        $text = '――――――――――――――――――――' . "\n";
        $text .= 'to: ' . $to . "\n";
        $text .= '――――――――――――――――――――' . "\n";
        $text .= 'subject: ' . $subject . "\n";
        $text .= '――――――――――――――――――――' . "\n";
        $text .= $message;
        return file_put_contents(MAIN_APPLICATION_PATH . 'mails/' . localdate('YmdHis') . '_' . $to . '.txt', $text);
    }
}
Esempio n. 3
0
function siteevent_virtual_date($vals)
{
    if ($vals->until_date > $vals->date) {
        if (substr($vals->date, 0, 4) != substr($vals->until_date, 0, 4)) {
            // separate year
            $out = localdate('M j, Y', strtotime($vals->date));
            $out .= ' – ';
            $out .= localdate('M j, Y', strtotime($vals->until_date));
        } else {
            // same year
            $out = localdate('M j', strtotime($vals->date));
            $out .= ' – ';
            $out .= localdate('M j, Y', strtotime($vals->until_date));
        }
        return $out;
    }
    return localdate('M j, Y', strtotime($vals->date));
}
Esempio n. 4
0
/**
 * セッションの初期値
 *
 * @return array
 */
function default_sessions()
{
    return array('id' => null, 'created' => localdate('Y-m-d H:i:s'), 'modified' => localdate('Y-m-d H:i:s'), 'user_id' => 0, 'agent' => null, 'keep' => 0, 'twostep' => 0, 'expire' => localdate('Y-m-d H:i:s'));
}
Esempio n. 5
0
<?php

// ログイン確認
if (!preg_match('/^(index|logout)$/', $_REQUEST['_work'])) {
    if (empty($_SESSION['auth']['user']['id']) || localdate() - $_SESSION['auth']['user']['time'] > $GLOBALS['config']['login_expire']) {
        $referer = '/' . implode('/', $_params);
        if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] !== '') {
            $referer .= '?' . $_SERVER['QUERY_STRING'];
        }
        // リダイレクト
        redirect('/user/logout?referer=' . rawurlencode($referer));
    } else {
        $_SESSION['auth']['user']['time'] = localdate();
    }
}
Esempio n. 6
0
            }
            // セッションを更新
            if ($flag === true) {
                $resource = update_sessions(array('set' => array('id' => $session, 'user_id' => $_SESSION['auth']['user']['id'], 'agent' => $_SERVER['HTTP_USER_AGENT'], 'keep' => $keep, 'twostep' => $twostep, 'expire' => localdate('Y-m-d H:i:s', time() + $GLOBALS['config']['cookie_expire'])), 'where' => array('id = :id', array('id' => $_COOKIE['auth']['session']))));
                if (!$resource) {
                    error('データを編集できません。');
                }
            } else {
                $resource = insert_sessions(array('values' => array('id' => $session, 'user_id' => $_SESSION['auth']['user']['id'], 'agent' => $_SERVER['HTTP_USER_AGENT'], 'keep' => $keep, 'twostep' => $twostep, 'expire' => localdate('Y-m-d H:i:s', time() + $GLOBALS['config']['cookie_expire']))));
                if (!$resource) {
                    error('データを登録できません。');
                }
            }
            cookie_set('auth[session]', $session, localdate() + $GLOBALS['config']['cookie_expire']);
            // 古いセッションを削除
            $resource = delete_sessions(array('where' => array('expire < :expire', array('expire' => localdate('Y-m-d H:i:s')))));
            if (!$resource) {
                error('データを削除できません。');
            }
            // トランザクションを終了
            db_commit();
        }
    }
} else {
    $_view['user'] = array('username' => '', 'password' => '', 'session' => null);
}
// ログイン確認
if (!empty($_SESSION['auth']['user']['id'])) {
    if ($_REQUEST['_work'] === 'index') {
        if (isset($_GET['referer']) && regexp_match('^\\/', $_GET['referer'])) {
            $url = $_GET['referer'];
Esempio n. 7
0
<?php

// 設定ファイル
import('app/config.php');
if (is_file(MAIN_PATH . MAIN_APPLICATION_PATH . 'app/config.local.php')) {
    import('app/config.local.php');
}
// オートログイン
if (empty($_SESSION['auth']['session']) && !empty($_COOKIE['auth']['session'])) {
    list($session, $user_id) = service_user_autologin($_COOKIE['auth']['session']);
    if ($session === true) {
        $_SESSION['auth']['session'] = $session;
        $_SESSION['auth']['user'] = array('id' => $user_id, 'time' => localdate());
    }
}
// ユーザ存在確認
if (!empty($_SESSION['auth']['user']['id'])) {
    $users = select_users(array('where' => array('id = :id', array('id' => $_SESSION['auth']['user']['id']))));
    if (empty($users)) {
        unset($_SESSION['auth']['user']);
        // リダイレクト
        redirect('/user');
    } else {
        $_view['_user'] = $users[0];
    }
}
Esempio n. 8
0
    ?>
</td>
                    <td><?php 
    h($user['profile_name']);
    ?>
</td>
                    <td><?php 
    h($user['email']);
    if ($user['email_activated'] == 0) {
        ?>
(存在未確認)<?php 
    }
    ?>
</td>
                    <td><?php 
    h($user['loggedin'] ? localdate('Y/m/d H:i', $user['loggedin']) : '-');
    ?>
</td>
                    <td><a href="<?php 
    t(MAIN_FILE);
    ?>
/admin/user_form?id=<?php 
    t($user['id']);
    ?>
">編集</a></td>
                </tr>
                <?php 
}
?>
            </tbody>
        </table>
Esempio n. 9
0
><?php 
        t($value);
        ?>
</option>
                                <?php 
    }
    ?>
                            </select>
                        </dd>
                    <dt>生年月日</dt>
                        <dd>
                            <div id="validate_birthday">
                                <select name="birthday[year]">
                                    <option value=""></option>
                                    <?php 
    e(ui_datetime($_view['member']['birthday'], 'year', array('suffix' => '年', 'from' => localdate('Y') - 20, 'to' => localdate('Y') - 10)));
    ?>
                                </select>
                                <select name="birthday[month]">
                                    <option value=""></option>
                                    <?php 
    e(ui_datetime($_view['member']['birthday'], 'month', array('suffix' => '月')));
    ?>
                                </select>
                                <select name="birthday[day]">
                                    <option value=""></option>
                                    <?php 
    e(ui_datetime($_view['member']['birthday'], 'day', array('suffix' => '日')));
    ?>
                                </select>
                            </div>
Esempio n. 10
0
/**
 * ユーザの初期値
 *
 * @return array
 */
function default_users()
{
    return array('id' => null, 'created' => localdate('Y-m-d H:i:s'), 'modified' => localdate('Y-m-d H:i:s'), 'deleted' => null, 'username' => '', 'password' => null, 'password_salt' => null, 'email' => '', 'email_activated' => 0, 'loggedin' => null, 'failed' => null, 'failed_last' => null, 'token' => null, 'token_code' => null, 'token_expire' => null, 'twostep' => 0, 'twostep_email' => null, 'twostep_code' => null, 'twostep_expire' => null);
}
Esempio n. 11
0
/**
 * プロフィールの初期値
 *
 * @return array
 */
function default_profiles()
{
    return array('id' => null, 'created' => localdate('Y-m-d H:i:s'), 'modified' => localdate('Y-m-d H:i:s'), 'deleted' => null, 'user_id' => 0, 'name' => null, 'text' => null, 'memo' => null);
}
Esempio n. 12
0
 } else {
     $warnings = array();
 }
 // 入力データを検証&登録
 if (isset($_POST['_type']) && $_POST['_type'] === 'json') {
     if (empty($warnings)) {
         ok();
     } else {
         warning($warnings);
     }
 } else {
     if (empty($warnings)) {
         // トランザクションを開始
         db_transaction();
         // パスワード再発行用URLを通知
         $resource = update_users(array('set' => array('token' => rand_string(), 'token_code' => rand_number(1000, 9999), 'token_expire' => localdate('Y-m-d H:i:s', time() + 60 * 60 * 24)), 'where' => array('email = :email', array('email' => $_POST['email']))));
         if (!$resource) {
             error('指定されたメールアドレスが見つかりません。');
         }
         $users = select_users(array('where' => array('email = :email', array('email' => $_POST['email']))));
         // メール送信内容を作成
         $_view['url'] = $GLOBALS['config']['http_url'] . MAIN_FILE . '/password/form?key=' . rawurlencode($users[0]['email']) . '&token=' . $users[0]['token'];
         $_SESSION['expect']['token_code'] = $users[0]['token_code'];
         $to = $users[0]['email'];
         $subject = $GLOBALS['config']['mail_subjects']['password/send'];
         $message = view('mail/password/send.php', true);
         $headers = $GLOBALS['config']['mail_headers'];
         // メールを送信
         if (service_mail_send($to, $subject, $message, $headers) === false) {
             error('メールを送信できません。');
         }
Esempio n. 13
0
    if (empty($_GET['id'])) {
        $_view['class'] = default_classes();
    } else {
        $classes = select_classes(array('where' => array('id = :id', array('id' => $_GET['id']))));
        if (empty($classes)) {
            warning('編集データが見つかりません。');
        } else {
            $_view['class'] = $classes[0];
        }
    }
    if (isset($_GET['_type']) && $_GET['_type'] === 'json') {
        // 教室情報を取得
        header('Content-Type: application/json; charset=' . MAIN_CHARSET);
        echo json_encode(array('status' => 'OK', 'data' => $_view, 'files' => array('image_01' => $_view['class']['image_01'] ? file_mimetype($_view['class']['image_01']) : null, 'image_02' => $_view['class']['image_02'] ? file_mimetype($_view['class']['image_02']) : null, 'document' => $_view['class']['document'] ? file_mimetype($_view['class']['document']) : null)));
        exit;
    } else {
        // 投稿セッションを初期化
        unset($_SESSION['post']);
        unset($_SESSION['file']);
    }
    // 編集開始日時を記録
    if (!empty($_GET['id'])) {
        $_SESSION['update']['class'] = localdate('Y-m-d H:i:s');
    }
}
// タイトル
if (empty($_GET['id'])) {
    $_view['title'] = '教室登録';
} else {
    $_view['title'] = '教室編集';
}
Esempio n. 14
0
function sitegallery_filter_date($ts)
{
    return localdate('F, Y', $ts);
}
Esempio n. 15
0
/**
 * 名簿の初期値
 *
 * @return array
 */
function default_members()
{
    return array('id' => null, 'created' => localdate('Y-m-d H:i:s'), 'modified' => localdate('Y-m-d H:i:s'), 'deleted' => null, 'class_id' => 0, 'name' => '', 'name_kana' => '', 'grade' => 0, 'birthday' => null, 'email' => null, 'tel' => null, 'memo' => null, 'image_01' => null, 'image_02' => null, 'public' => 1, 'category_sets' => array());
}
Esempio n. 16
0
            } else {
                warning($warnings);
            }
        } else {
            if (empty($warnings)) {
                $_SESSION['post']['profile'] = $post['profile'];
                // フォワード
                forward('/admin/profile_post');
            } else {
                $_view['profile'] = $post['profile'];
                $_view['warnings'] = $warnings;
            }
        }
    }
} else {
    // 初期データを取得
    $profiles = select_profiles(array('where' => array('user_id = :user_id', array('user_id' => $_GET['user_id']))));
    if (empty($profiles)) {
        warning('編集データが見つかりません。');
    } else {
        $_view['profile'] = $profiles[0];
    }
    // 投稿セッションを初期化
    unset($_SESSION['post']);
    // 編集開始日時を記録
    if (!empty($_GET['user_id'])) {
        $_SESSION['update']['profile'] = localdate('Y-m-d H:i:s');
    }
}
// タイトル
$_view['title'] = 'プロフィール編集';
Esempio n. 17
0
?>
</div></div>
		<div class="row"><span>Group:</span><div><?php 
echo $level[getint($user['priv'])];
?>
</div></div>
		<div class="row"><span>E-mail addr:</span><div><?php 
echo $user['email'];
?>
</div></div>
		<div class="row"><span>Date created:</span><div><?php 
echo localdate($user['created']);
?>
</div></div>
		<div class="row"><span>Last login:</span><div><?php 
echo localdate($user['last_login']);
?>
</div></div>
		<div class="row"><span>
			<form action="home" method="get">
				<input type="hidden" name="action" value="logout">
				<button class="btn brd">Logout</button>
			</form>
		</span><div></div></div>
		<?php 
if ($admin) {
    ?>
		<div class="admin">
			<h3>Administration</h3>
			<form action="account" method="post">
			<div class="row"><span>User</span><div>Permissions</div></div>
Esempio n. 18
0
            ok();
        } else {
            warning($warnings);
        }
    } else {
        if (empty($warnings)) {
            $_SESSION['post']['user'] = $post['user'];
            // フォワード
            forward('/password/post');
        } else {
            $_view['user'] = $post['user'];
            $_view['key'] = $post['user']['key'];
            $_view['warnings'] = $warnings;
        }
    }
} else {
    // パスワード再発行用URLを検証
    $users = select_users(array('select' => 'token_expire', 'where' => array('email = :email AND token = :token', array('email' => $_GET['key'], 'token' => $_GET['token']))));
    if (empty($users)) {
        error('不正なアクセスです。');
    }
    if (localdate(null, $users[0]['token_expire']) < localdate()) {
        error('URLの有効期限が終了しています。');
    }
    $_view['user'] = array('password' => '');
    $_view['key'] = $_GET['key'];
    // 投稿セッションを初期化
    unset($_SESSION['post']);
}
// タイトル
$_view['title'] = 'パスワード再登録';
Esempio n. 19
0
File: ui.php Progetto: refirio/levis
/**
 * Get a form parts for time/date.
 *
 * @param mixed  $timestamp
 * @param string $type
 * @param array  $option
 *
 * @return string
 */
function ui_datetime($timestamp, $type = '', $option = array())
{
    if (!isset($option['format'])) {
        $option['format'] = '%01d';
    }
    if (!isset($option['prefix'])) {
        $option['prefix'] = '';
    }
    if (!isset($option['suffix'])) {
        $option['suffix'] = '';
    }
    if (!isset($option['from'])) {
        $option['from'] = 0;
    }
    if (!isset($option['to'])) {
        $option['to'] = 0;
    }
    if (!isset($option['step'])) {
        $option['step'] = 1;
    }
    switch ($type) {
        case 'year':
            $value = $timestamp ? intval(localdate('Y', $timestamp)) : null;
            $from = $option['from'] ? $option['from'] : date('Y') - 10;
            $to = $option['to'] ? $option['to'] : date('Y') + 10;
            break;
        case 'month':
            $value = $timestamp ? intval(localdate('m', $timestamp)) : null;
            $from = $option['from'] ? $option['from'] : 1;
            $to = $option['to'] ? $option['to'] : 12;
            break;
        case 'day':
            $value = $timestamp ? intval(localdate('d', $timestamp)) : null;
            $from = $option['from'] ? $option['from'] : 1;
            $to = $option['to'] ? $option['to'] : 31;
            break;
        case 'hour':
            $value = $timestamp ? intval(localdate('H', $timestamp)) : null;
            $from = $option['from'] ? $option['from'] : 0;
            $to = $option['to'] ? $option['to'] : 23;
            break;
        case 'minute':
            $value = $timestamp ? intval(localdate('i', $timestamp)) : null;
            $from = $option['from'] ? $option['from'] : 0;
            $to = $option['to'] ? $option['to'] : 59;
            break;
        case 'second':
            $value = $timestamp ? intval(localdate('s', $timestamp)) : null;
            $from = $option['from'] ? $option['from'] : 0;
            $to = $option['to'] ? $option['to'] : 59;
            break;
        default:
            return '<option value="">ui_datetime: Incorrect value was specified.</option>';
    }
    if ($regexp = regexp_match('^(\\d\\d\\d\\d)\\-(\\d\\d)\\-(\\d\\d)', $timestamp)) {
        $year = intval($regexp[1]);
        $month = intval($regexp[2]);
        $day = intval($regexp[3]);
        if (!checkdate($month, $day, $year)) {
            if ($regexp = regexp_match('(\\d\\d)\\:(\\d\\d)\\:(\\d\\d)$', $timestamp)) {
                $hour = intval($regexp[1]);
                $minute = intval($regexp[2]);
                $second = intval($regexp[3]);
            } else {
                $hour = 0;
                $minute = 0;
                $second = 0;
            }
            switch ($type) {
                case 'year':
                    $value = $year;
                    break;
                case 'month':
                    $value = $month;
                    break;
                case 'day':
                    $value = $day;
                    break;
                case 'hour':
                    $value = $hour;
                    break;
                case 'minute':
                    $value = $minute;
                    break;
                case 'second':
                    $value = $second;
                    break;
                default:
            }
        }
    }
    $datetime = '';
    for ($i = $from; $i <= $to; $i += $option['step']) {
        $datetime .= '<option value="' . sprintf('%02d', $i) . '"' . ($value !== null && $i == $value ? ' selected="selected"' : '') . '>' . $option['prefix'] . sprintf($option['format'], $i) . $option['suffix'] . '</option>';
    }
    return $datetime;
}
Esempio n. 20
0
 /**
  * Formats a timestamp provided in ISO format (YYYY-MM-DD HH:MM:SS) in
  * the new format specified.
  * 
  * @access	public
  * @param	string	$date
  * @param	string	$format
  * @return	string
  * 
  */
 function timestamp($timestamp = '', $format = 'M j, Y h:i:s a')
 {
     if (empty($timestamp)) {
         $timestamp = localdate('YmdHis');
     }
     if ($timestamp == '00000000000000' || $timestamp == '0000-00-00 00:00:00') {
         return intl_get('Empty');
     }
     if (is_array($format)) {
         if (ereg('^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$', $timestamp, $regs)) {
             $unix = mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
         } elseif (ereg('^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$', $timestamp, $regs)) {
             $unix = mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
         } else {
             return $timestamp;
         }
         if (!empty($format['today']) && date('Y-m-d') == date('Y-m-d', $unix)) {
             return localdate($format['today'], $unix);
         } elseif (!empty($format['yesterday']) && date('Y-m-d', time() - 86400) == date('Y-m-d', $unix)) {
             return localdate($format['yesterday'], $unix);
         } elseif (!empty($format['tomorrow']) && date('Y-m-d', time() + 86400) == date('Y-m-d', $unix)) {
             return localdate($format['tomorrow'], $unix);
         } elseif (!empty($format['this week']) && date('Y-W', time()) == date('Y-W', $unix)) {
             return localdate($format['this week'], $unix);
         } elseif (!empty($format['other'])) {
             return localdate($format['other'], $unix);
         }
     } else {
         if (ereg('^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$', $timestamp, $regs)) {
             return localdate($format, mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]));
         } elseif (ereg('^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$', $timestamp, $regs)) {
             return localdate($format, mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]));
         } else {
             return $timestamp;
         }
     }
 }
Esempio n. 21
0
/**
 * Log the message to a logs.
 *
 * @param string      $type
 * @param string|null $message
 *
 * @return void
 */
function logging($type = 'message', $message = null)
{
    $log = clientip() . ' ' . clientip(true) . ' [' . localdate('Y-m-d H:i:s') . '] ' . $_SERVER['REQUEST_URI'];
    if ($type === 'get') {
        if ($fp = fopen(LOGGING_PATH . 'get/' . localdate('Ymd') . '.log', 'a')) {
            fwrite($fp, $log . "\n");
            fclose($fp);
        }
    } elseif ($type === 'post' || $type === 'files') {
        $directory = LOGGING_PATH . $type . '/' . localdate('Ymd') . '/';
        if (!is_dir($directory)) {
            if (mkdir($directory, 0707)) {
                chmod($directory, 0707);
            }
        }
        if ($type === 'post') {
            $data = $_POST;
        } elseif ($type === 'files') {
            $data = $_FILES;
        }
        if ($fp = fopen($directory . localdate('His') . '.log', 'a')) {
            fwrite($fp, $log . "\n" . print_r($data, true) . "\n");
            fclose($fp);
        }
    } else {
        $message = regexp_replace("\r", '\\r', $message);
        $message = regexp_replace("\n", '\\n', $message);
        if ($message === null) {
            $message = '-';
        }
        if ($fp = fopen(LOGGING_PATH . 'message/' . localdate('Ymd') . '.log', 'a')) {
            fwrite($fp, $log . ' ' . $message . "\n");
            fclose($fp);
        }
    }
    return;
}
Esempio n. 22
0
<?php

// ログイン確認
if (!preg_match('/^(index|logout)$/', $_REQUEST['_work'])) {
    if (empty($_SESSION['auth']['administrator']['id']) || localdate() - $_SESSION['auth']['administrator']['time'] > $GLOBALS['config']['login_expire']) {
        $referer = '/' . implode('/', $_params);
        if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] !== '') {
            $referer .= '?' . $_SERVER['QUERY_STRING'];
        }
        // リダイレクト
        redirect('/admin/logout?referer=' . rawurlencode($referer));
    } else {
        $_SESSION['auth']['administrator']['time'] = localdate();
    }
}
Esempio n. 23
0
/**
 * 教室の初期値
 *
 * @return array
 */
function default_classes()
{
    return array('id' => null, 'created' => localdate('Y-m-d H:i:s'), 'modified' => localdate('Y-m-d H:i:s'), 'deleted' => null, 'code' => '', 'name' => '', 'memo' => null, 'image_01' => null, 'image_02' => null, 'document' => null, 'sort' => 0);
}
Esempio n. 24
0
            $_view['member'] = $members[0];
        }
    }
    if (isset($_GET['_type']) && $_GET['_type'] === 'json') {
        // 名簿情報を取得
        header('Content-Type: application/json; charset=' . MAIN_CHARSET);
        echo json_encode(array('status' => 'OK', 'data' => $_view, 'files' => array('image_01' => $_view['member']['image_01'] ? file_mimetype($_view['member']['image_01']) : null, 'image_02' => $_view['member']['image_02'] ? file_mimetype($_view['member']['image_02']) : null)));
        exit;
    } else {
        // 投稿セッションを初期化
        unset($_SESSION['post']);
        unset($_SESSION['file']);
    }
    // 編集開始日時を記録
    if (!empty($_GET['id'])) {
        $_SESSION['update']['member'] = localdate('Y-m-d H:i:s');
    }
}
if (empty($_POST['view']) || $_POST['view'] !== 'preview') {
    // 名簿の表示用データ作成
    $_view['member'] = view_members($_view['member']);
}
// 教室を取得
$_view['classes'] = select_classes(array('order_by' => 'sort, id'));
// 分類を取得
$_view['categories'] = select_categories(array('order_by' => 'sort, id'));
// タイトル
if (empty($_GET['id'])) {
    $_view['title'] = '名簿登録';
} else {
    $_view['title'] = '名簿編集';
Esempio n. 25
0
            forward('/admin/category_post');
        } else {
            $_view['category'] = $post['category'];
            $_view['warnings'] = $warnings;
        }
    }
} else {
    // 初期データを取得
    if (empty($_GET['id'])) {
        $_view['category'] = default_categories();
    } else {
        $categories = select_categories(array('where' => array('id = :id', array('id' => $_GET['id']))));
        if (empty($categories)) {
            warning('編集データが見つかりません。');
        } else {
            $_view['category'] = $categories[0];
        }
    }
    // 投稿セッションを初期化
    unset($_SESSION['post']);
    // 編集開始日時を記録
    if (!empty($_GET['id'])) {
        $_SESSION['update']['category'] = localdate('Y-m-d H:i:s');
    }
}
// タイトル
if (empty($_GET['id'])) {
    $_view['title'] = '分類登録';
} else {
    $_view['title'] = '分類編集';
}
Esempio n. 26
0
File: db.php Progetto: refirio/levis
/**
 * Export SQL to the file.
 *
 * @param string|null $file
 * @param string|null $target
 * @param bool        $combined
 */
function db_export($file = null, $target = null, $combined = true)
{
    $resource = db_query(db_sql('table_list'));
    $results = db_result($resource);
    $tables = array();
    foreach ($results as $result) {
        $tables[] = array_shift($result);
    }
    $text = '-- Database: ' . DATABASE_NAME . ' (' . DATABASE_TYPE . ")\n";
    $text .= '-- Datetime: ' . localdate('Y-m-d H:i:s') . "\n";
    $text .= '-- Host: ' . gethostbyaddr(clientip()) . "\n";
    $text .= "\n";
    foreach ($tables as $table) {
        if ($target === null || $target === $table) {
            $resource = db_query(db_sql('table_create', $table));
            $results = db_result($resource);
            if (DATABASE_TYPE === 'pdo_mysql' || DATABASE_TYPE === 'mysql') {
                $text .= "DROP TABLE IF EXISTS " . $table . ";\n";
                $text .= $results[0]['Create Table'] . ";\n";
                $text .= "\n";
            } elseif (DATABASE_TYPE === 'pdo_pgsql' || DATABASE_TYPE === 'pgsql') {
                $text .= "DROP TABLE IF EXISTS " . $table . ";\n";
                $text .= $results[0]['case'] . ";\n";
                $text .= "\n";
            } elseif (DATABASE_TYPE === 'pdo_sqlite' || DATABASE_TYPE === 'pdo_sqlite2' || DATABASE_TYPE === 'sqlite') {
                $text .= "DROP TABLE IF EXISTS " . $table . ";\n";
                $text .= $results[0]['sql'] . ";\n";
                $text .= "\n";
            }
            $resource = db_query('SELECT * FROM ' . $table . ';');
            $results = db_result($resource);
            $values = array();
            $i = 0;
            foreach ($results as $result) {
                $inserts = array();
                foreach ($result as $data) {
                    if ($data === null) {
                        $inserts[] = 'NULL';
                    } else {
                        $inserts[] = db_escape($data);
                    }
                }
                if ($combined === true) {
                    $values[intval($i / 50)][] = '(' . implode(', ', $inserts) . ')';
                } else {
                    $text .= "INSERT INTO " . $table . " VALUES(" . implode(', ', $inserts) . ");\n";
                }
                $i++;
            }
            if ($combined === true && !empty($values)) {
                foreach ($values as $value) {
                    $text .= "INSERT INTO " . $table . " VALUES\n";
                    $text .= implode(",\n", $value);
                    $text .= ";\n";
                }
            }
            $text .= "\n";
        }
    }
    if ($file === null) {
        if ($target === null) {
            $filename = DATABASE_NAME . '.sql';
        } else {
            $filename = DATABASE_NAME . '-' . $target . '.sql';
        }
        header('Content-Type: text/plain');
        header('Content-Disposition: attachment; filename="' . $filename . '"');
        echo $text;
        exit;
    } else {
        if (file_put_contents($file, $text) === false) {
            error('db: Export file can\'t write');
        }
    }
    return;
}
Esempio n. 27
0
<?php

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // ログイン
    foreach ($GLOBALS['config']['administrators'] as $username => $information) {
        if ($_POST['username'] === $username && $_POST['password'] === $information['password']) {
            if (empty($information['address']) || in_array(clientip(), $information['address'])) {
                $_SESSION['auth']['administrator'] = array('id' => $_POST['username'], 'time' => localdate());
                break;
            }
        }
    }
    if (empty($_SESSION['auth']['administrator']['id'])) {
        $_view['administrator'] = $_POST;
        $_view['warnings'] = array('ユーザ名もしくはパスワードが違います。');
    }
} else {
    $addresses = array();
    foreach ($GLOBALS['config']['administrators'] as $information) {
        if (!empty($information['address'])) {
            $addresses = array_merge($addresses, $information['address']);
        }
    }
    if (!empty($addresses) && !in_array(clientip(), $addresses)) {
        error('不正なアクセスです。');
    }
    $_view['administrator'] = array('username' => '', 'password' => '');
}
// ログイン確認
if (!empty($_SESSION['auth']['administrator']['id'])) {
    if ($_REQUEST['_work'] === 'index') {
Esempio n. 28
0
    ?>
                <tr>
                    <td><?php 
    h($member['name']);
    ?>
</td>
                    <td><?php 
    h($member['name_kana']);
    ?>
</td>
                    <td><?php 
    h($GLOBALS['config']['options']['member']['grades'][$member['grade']]);
    ?>
</td>
                    <td><?php 
    h(localdate('Y年m月d日', $member['birthday']));
    ?>
</td>
                    <td><?php 
    h($member['email']);
    ?>
</td>
                    <td><?php 
    h($member['tel']);
    ?>
</td>
                    <td>
                        <?php 
    if ($member['image_01']) {
        ?>
                        <a href="<?php 
Esempio n. 29
0
/**
 * 分類の初期値
 *
 * @return array
 */
function default_categories()
{
    return array('id' => null, 'created' => localdate('Y-m-d H:i:s'), 'modified' => localdate('Y-m-d H:i:s'), 'deleted' => null, 'name' => '', 'sort' => 0);
}