/** * 名簿の登録 * * @param array $queries * @param array $options * * @return resource */ function insert_members($queries, $options = array()) { $queries = db_placeholder($queries); $options = array('category_sets' => isset($options['category_sets']) ? $options['category_sets'] : array(), 'files' => isset($options['files']) ? $options['files'] : array()); // 初期値を取得 $defaults = default_classes(); if (isset($queries['values']['created'])) { if ($queries['values']['created'] === false) { unset($queries['values']['created']); } } else { $queries['values']['created'] = $defaults['created']; } if (isset($queries['values']['modified'])) { if ($queries['values']['modified'] === false) { unset($queries['values']['modified']); } } else { $queries['values']['modified'] = $defaults['modified']; } // データを登録 $queries['insert_into'] = DATABASE_PREFIX . 'members'; $resource = db_insert($queries); if (!$resource) { return $resource; } // IDを取得 $member_id = db_last_insert_id(); if (isset($options['category_sets'])) { // 分類を登録 foreach ($options['category_sets'] as $category_id) { $resource = insert_category_sets(array('values' => array('category_id' => $category_id, 'member_id' => $member_id))); if (!$resource) { return $resource; } } } if (!empty($options['files'])) { // 関連するファイルを削除 remove_members($member_id, $options['files']); // 関連するファイルを保存 save_members($member_id, $options['files']); } return $resource; }
/** * 教室の編集 * * @param array $queries * @param array $options * * @return resource */ function update_classes($queries, $options = array()) { $queries = db_placeholder($queries); $options = array('id' => isset($options['id']) ? $options['id'] : null, 'update' => isset($options['update']) ? $options['update'] : null, 'files' => isset($options['files']) ? $options['files'] : array()); // 最終編集日時を確認 if (isset($options['id']) && isset($options['update']) && (!isset($queries['set']['modified']) || $queries['set']['modified'] !== false)) { $classes = db_select(array('from' => DATABASE_PREFIX . 'classes', 'where' => array('id = :id AND modified > :update', array('id' => $options['id'], 'update' => $options['update'])))); if (!empty($classes)) { error('編集開始後にデータが更新されています。'); } } // 初期値を取得 $defaults = default_classes(); if (isset($queries['set']['modified'])) { if ($queries['set']['modified'] === false) { unset($queries['set']['modified']); } } else { $queries['set']['modified'] = $defaults['modified']; } // データを編集 $queries['update'] = DATABASE_PREFIX . 'classes'; $resource = db_update($queries); if (!$resource) { return $resource; } // IDを取得 $id = $options['id']; if (!empty($options['files'])) { // 関連するファイルを削除 remove_classes($id, $options['files']); // 関連するファイルを保存 save_classes($id, $options['files']); } return $resource; }
} } else { if (empty($warnings)) { $_SESSION['post']['class'] = $post['class']; // フォワード forward('/admin/class_post'); } else { $_view['class'] = $post['class']; $_view['warnings'] = $warnings; } } } } else { // 初期データを取得 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 { // 投稿セッションを初期化