| 1 |
/*************************************************************************** |
/* SPDX-License-Identifier: GPL-3.0-or-later */ |
| 2 |
article_del.c - description |
/* |
| 3 |
------------------- |
* article_del |
| 4 |
copyright : (C) 2004-2025 by Leaflet |
* - user interactive feature to delete article |
| 5 |
email : leaflet@leafok.com |
* |
| 6 |
***************************************************************************/ |
* Copyright (C) 2004-2026 Leaflet <leaflet@leafok.com> |
| 7 |
|
*/ |
| 8 |
/*************************************************************************** |
|
| 9 |
* * |
#ifdef HAVE_CONFIG_H |
| 10 |
* This program is free software; you can redistribute it and/or modify * |
#include "config.h" |
| 11 |
* it under the terms of the GNU General Public License as published by * |
#endif |
|
* the Free Software Foundation; either version 3 of the License, or * |
|
|
* (at your option) any later version. * |
|
|
* * |
|
|
***************************************************************************/ |
|
| 12 |
|
|
| 13 |
#include "article_del.h" |
#include "article_del.h" |
| 14 |
#include "database.h" |
#include "database.h" |
|
#include "log.h" |
|
| 15 |
#include "io.h" |
#include "io.h" |
| 16 |
|
#include "log.h" |
| 17 |
#include "screen.h" |
#include "screen.h" |
| 18 |
#include "user_priv.h" |
#include "user_priv.h" |
| 19 |
#include <ctype.h> |
#include <ctype.h> |
| 33 |
|
|
| 34 |
if (p_section == NULL || p_article == NULL) |
if (p_section == NULL || p_article == NULL) |
| 35 |
{ |
{ |
| 36 |
log_error("NULL pointer error\n"); |
log_error("NULL pointer error"); |
| 37 |
} |
} |
| 38 |
|
|
| 39 |
if (p_article->excerption) // Delete is not allowed |
if (p_article->excerption) // Delete is not allowed |
| 40 |
{ |
{ |
| 41 |
clearscr(); |
clearscr(); |
| 42 |
moveto(1, 1); |
moveto(1, 1); |
| 43 |
prints("该文章无法被删除,请联系版主。"); |
prints("璇ユ枃绔犳棤娉曡鍒犻櫎锛岃鑱旂郴鐗堜富銆"); |
| 44 |
press_any_key(); |
press_any_key(); |
| 45 |
|
|
| 46 |
return 0; |
return 0; |
| 48 |
|
|
| 49 |
clearscr(); |
clearscr(); |
| 50 |
moveto(1, 1); |
moveto(1, 1); |
| 51 |
prints("真的要删除文章?(Y)是, (N)否 [N]: "); |
prints("鐪熺殑瑕佸垹闄ゆ枃绔狅紵(Y)鏄, (N)鍚 [N]: "); |
| 52 |
iflush(); |
iflush(); |
| 53 |
|
|
| 54 |
for (ch = 0; !SYS_server_exit; ch = igetch_t(MAX_DELAY_TIME)) |
for (ch = 0; !SYS_server_exit; ch = igetch_t(BBS_max_user_idle_time)) |
| 55 |
{ |
{ |
| 56 |
switch (toupper(ch)) |
switch (toupper(ch)) |
| 57 |
{ |
{ |
| 59 |
case KEY_TIMEOUT: |
case KEY_TIMEOUT: |
| 60 |
goto cleanup; |
goto cleanup; |
| 61 |
case CR: |
case CR: |
|
igetch_reset(); |
|
| 62 |
case KEY_ESC: |
case KEY_ESC: |
| 63 |
case 'N': |
case 'N': |
| 64 |
return 0; |
return 0; |
| 79 |
db = db_open(); |
db = db_open(); |
| 80 |
if (db == NULL) |
if (db == NULL) |
| 81 |
{ |
{ |
| 82 |
log_error("db_open() error: %s\n", mysql_error(db)); |
log_error("db_open() error: %s", mysql_error(db)); |
| 83 |
ret = -1; |
ret = -1; |
| 84 |
goto cleanup; |
goto cleanup; |
| 85 |
} |
} |
| 87 |
// Begin transaction |
// Begin transaction |
| 88 |
if (mysql_query(db, "SET autocommit=0") != 0) |
if (mysql_query(db, "SET autocommit=0") != 0) |
| 89 |
{ |
{ |
| 90 |
log_error("SET autocommit=0 error: %s\n", mysql_error(db)); |
log_error("SET autocommit=0 error: %s", mysql_error(db)); |
| 91 |
ret = -1; |
ret = -1; |
| 92 |
goto cleanup; |
goto cleanup; |
| 93 |
} |
} |
| 94 |
|
|
| 95 |
if (mysql_query(db, "BEGIN") != 0) |
if (mysql_query(db, "BEGIN") != 0) |
| 96 |
{ |
{ |
| 97 |
log_error("Begin transaction error: %s\n", mysql_error(db)); |
log_error("Begin transaction error: %s", mysql_error(db)); |
| 98 |
ret = -1; |
ret = -1; |
| 99 |
goto cleanup; |
goto cleanup; |
| 100 |
} |
} |
| 105 |
|
|
| 106 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 107 |
{ |
{ |
| 108 |
log_error("Query article status error: %s\n", mysql_error(db)); |
log_error("Query article status error: %s", mysql_error(db)); |
| 109 |
ret = -1; |
ret = -1; |
| 110 |
goto cleanup; |
goto cleanup; |
| 111 |
} |
} |
| 112 |
if ((rs = mysql_use_result(db)) == NULL) |
if ((rs = mysql_use_result(db)) == NULL) |
| 113 |
{ |
{ |
| 114 |
log_error("Get article status data failed\n"); |
log_error("Get article status data failed"); |
| 115 |
ret = -1; |
ret = -1; |
| 116 |
goto cleanup; |
goto cleanup; |
| 117 |
} |
} |
| 131 |
|
|
| 132 |
clearscr(); |
clearscr(); |
| 133 |
moveto(1, 1); |
moveto(1, 1); |
| 134 |
prints("该文章已被删除,请稍后刷新列表。"); |
prints("璇ユ枃绔犲凡琚垹闄わ紝璇风◢鍚庡埛鏂板垪琛ㄣ"); |
| 135 |
press_any_key(); |
press_any_key(); |
| 136 |
|
|
| 137 |
goto cleanup; |
goto cleanup; |
| 141 |
{ |
{ |
| 142 |
clearscr(); |
clearscr(); |
| 143 |
moveto(1, 1); |
moveto(1, 1); |
| 144 |
prints("该文章无法被删除,请联系版主。"); |
prints("璇ユ枃绔犳棤娉曡鍒犻櫎锛岃鑱旂郴鐗堜富銆"); |
| 145 |
press_any_key(); |
press_any_key(); |
| 146 |
|
|
| 147 |
goto cleanup; |
goto cleanup; |
| 156 |
|
|
| 157 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 158 |
{ |
{ |
| 159 |
log_error("Update article status error: %s\n", mysql_error(db)); |
log_error("Update article status error: %s", mysql_error(db)); |
| 160 |
ret = -1; |
ret = -1; |
| 161 |
goto cleanup; |
goto cleanup; |
| 162 |
} |
} |
| 177 |
|
|
| 178 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 179 |
{ |
{ |
| 180 |
log_error("Update exp error: %s\n", mysql_error(db)); |
log_error("Update exp error: %s", mysql_error(db)); |
| 181 |
ret = -1; |
ret = -1; |
| 182 |
goto cleanup; |
goto cleanup; |
| 183 |
} |
} |
| 192 |
|
|
| 193 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 194 |
{ |
{ |
| 195 |
log_error("Add log error: %s\n", mysql_error(db)); |
log_error("Add log error: %s", mysql_error(db)); |
| 196 |
ret = -1; |
ret = -1; |
| 197 |
goto cleanup; |
goto cleanup; |
| 198 |
} |
} |
| 206 |
|
|
| 207 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 208 |
{ |
{ |
| 209 |
log_error("Update article error: %s\n", mysql_error(db)); |
log_error("Update article error: %s", mysql_error(db)); |
| 210 |
ret = -1; |
ret = -1; |
| 211 |
goto cleanup; |
goto cleanup; |
| 212 |
} |
} |
| 215 |
// Commit transaction |
// Commit transaction |
| 216 |
if (mysql_query(db, "COMMIT") != 0) |
if (mysql_query(db, "COMMIT") != 0) |
| 217 |
{ |
{ |
| 218 |
log_error("Commit transaction error: %s\n", mysql_error(db)); |
log_error("Commit transaction error: %s", mysql_error(db)); |
| 219 |
ret = -1; |
ret = -1; |
| 220 |
goto cleanup; |
goto cleanup; |
| 221 |
} |
} |
| 225 |
|
|
| 226 |
clearscr(); |
clearscr(); |
| 227 |
moveto(1, 1); |
moveto(1, 1); |
| 228 |
prints("删除成功,请在%d秒后刷新列表。", BBS_section_list_load_interval); |
prints("鍒犻櫎鎴愬姛锛岃鍦%d绉掑悗鍒锋柊鍒楄〃銆", BBS_section_list_load_interval); |
| 229 |
press_any_key(); |
press_any_key(); |
| 230 |
ret = 1; // Success |
ret = 1; // Success |
| 231 |
|
|