} if (!empty($_POST['id'])) { // トランザクションを開始 db_transaction(); // 名簿を削除 $resource = delete_members(array('where' => array('id = :id', array('id' => $_POST['id'])))); if (!$resource) { error('データを削除できません。'); } // トランザクションを終了 db_commit(); // リダイレクト redirect('/admin/member?ok=delete'); } elseif (!empty($_POST['list'])) { // トランザクションを開始 db_transaction(); // 名簿を削除 $resource = delete_members(array('where' => 'id IN(' . implode(',', array_map('db_escape', $_POST['list'])) . ')')); if (!$resource) { error('データを削除できません。'); } // トランザクションを終了 db_commit(); // 一括処理セッションを初期化 unset($_SESSION['bulk']); // リダイレクト redirect('/admin/member?page=' . intval($_POST['page']) . '&ok=delete'); } else { // リダイレクト redirect('/admin/member?warning=delete'); }
/** * 教室の削除 * * @param array $queries * @param array $options * * @return resource */ function delete_classes($queries, $options = array()) { $queries = db_placeholder($queries); $options = array('softdelete' => isset($options['softdelete']) ? $options['softdelete'] : true, 'associate' => isset($options['associate']) ? $options['associate'] : false, 'file' => isset($options['file']) ? $options['file'] : false); // 削除するデータのIDを取得 $classes = db_select(array('select' => 'id', 'from' => DATABASE_PREFIX . 'classes AS classes', 'where' => isset($queries['where']) ? $queries['where'] : '', 'limit' => isset($queries['limit']) ? $queries['limit'] : '')); $deletes = array(); foreach ($classes as $class) { $deletes[] = intval($class['id']); } if ($options['associate'] === true) { // 関連するデータを削除 $resource = delete_members(array('where' => 'class_id IN(' . implode($deletes) . ')')); if (!$resource) { return $resource; } } if ($options['softdelete'] === true) { // データを編集 $resource = db_update(array('update' => DATABASE_PREFIX . 'classes AS classes', 'set' => array('deleted' => localdate('Y-m-d H:i:s'), 'code' => array('CONCAT(\'DELETED ' . localdate('YmdHis') . ' \', code)')), 'where' => isset($queries['where']) ? $queries['where'] : '', 'limit' => isset($queries['limit']) ? $queries['limit'] : '')); if (!$resource) { return $resource; } } else { // データを削除 $resource = db_delete(array('delete_from' => DATABASE_PREFIX . 'classes AS classes', 'where' => isset($queries['where']) ? $queries['where'] : '', 'limit' => isset($queries['limit']) ? $queries['limit'] : '')); if (!$resource) { return $resource; } } if ($options['file'] === true) { // 関連するファイルを削除 foreach ($deletes as $delete) { directory_rmdir($GLOBALS['config']['file_targets']['class'] . $delete . '/'); } } return $resource; }