| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
if( !empty($setmodules) )</span> |
|---|
| 4 |
<span class="code-keyword">{ |
|---|
| 5 |
$filename = basename(__FILE__); |
|---|
| 6 |
$module['general']['news'] = $filename; |
|---|
| 7 |
return; |
|---|
| 8 |
} |
|---|
| 9 |
|
|---|
| 10 |
define('IN_PHPBB', 1); |
|---|
| 11 |
|
|---|
| 12 |
$root_path = '../';</span> |
|---|
| 13 |
<span class="code-lang"> |
|---|
| 14 |
require ($root_path . 'extension.inc'); |
|---|
| 15 |
require ('./pagestart.' . $phpEx); |
|---|
| 16 |
require ($root_path . 'include/bbcode/bbcode.lib.php'); |
|---|
| 17 |
|
|---|
| 18 |
$action = request_var('action', '');</span> |
|---|
| 19 |
<span class="code-lang"> |
|---|
| 20 |
if ( $action == 'delete' ) { |
|---|
| 21 |
$confirm = isset($_POST['confirm']); |
|---|
| 22 |
$cancel = isset($_POST['cancel']); |
|---|
| 23 |
$id = request_var('id', 0); |
|---|
| 24 |
|
|---|
| 25 |
if ( $confirm ) { |
|---|
| 26 |
require($root_path . 'include/functions_delete.php'); |
|---|
| 27 |
|
|---|
| 28 |
delete_news($id); |
|---|
| 29 |
|
|---|
| 30 |
$cache->destroy('sql', NEWS_TABLE); |
|---|
| 31 |
|
|---|
| 32 |
$message = $lang['news_sucefully_deleted'] . "<br /><br />" . sprintf($lang['click_return_news_admin'], "<a href=\"" . append_sid("admin_news.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>"); |
|---|
| 33 |
trigger_error($message); |
|---|
| 34 |
} |
|---|
| 35 |
elseif ( !$cancel ) { |
|---|
| 36 |
$template->set_filenames(array( |
|---|
| 37 |
'body' => '../admin/confirm_body.tpl') |
|---|
| 38 |
); |
|---|
| 39 |
|
|---|
| 40 |
$hidden_fields = '<input type="hidden" name="action" value="delete" /><input type="hidden" name="id" value="' . $id . '" />'; |
|---|
| 41 |
|
|---|
| 42 |
$template->assign_vars(array( |
|---|
| 43 |
'MESSAGE_TITLE' => $lang['confirm'], |
|---|
| 44 |
'MESSAGE_TEXT' => $lang['confirm_delete_news'], |
|---|
| 45 |
|
|---|
| 46 |
'S_CONFIRM_ACTION' => append_sid("admin_news.$phpEx"), |
|---|
| 47 |
'S_HIDDEN_FIELDS' => $hidden_fields) |
|---|
| 48 |
); |
|---|
| 49 |
$template->display('body'); |
|---|
| 50 |
include('./page_footer_admin.'.$phpEx); |
|---|
| 51 |
} |
|---|
| 52 |
} |
|---|
| 53 |
|
|---|
| 54 |
elseif ( $action == 'add' ) { |
|---|
| 55 |
$body = request_var('body', ''); |
|---|
| 56 |
$title = request_var('title', ''); |
|---|
| 57 |
$added = request_var('added', time()); |
|---|
| 58 |
$news_disable_comments = request_var('news_disable_comments', 0); |
|---|
| 59 |
$news_announce_until = request_var('news_announce_until', 0); |
|---|
| 60 |
$news_announce_userclasses = request_var('news_announce_userclasses', array( 0 => 0)); |
|---|
| 61 |
|
|---|
| 62 |
if (!$body || !$title) { |
|---|
| 63 |
trigger_error($lang['post_something']); |
|---|
| 64 |
} |
|---|
| 65 |
|
|---|
| 66 |
if ( sizeof($news_announce_userclasses) && $news_announce_userclasses[0] != 'all' ) { |
|---|
| 67 |
$news_announce_userclasses = implode(',', $news_announce_userclasses); |
|---|
| 68 |
} |
|---|
| 69 |
else { |
|---|
| 70 |
$news_announce_userclasses = ''; |
|---|
| 71 |
} |
|---|
| 72 |
|
|---|
| 73 |
$db->sql_query('INSERT INTO ' . NEWS_TABLE . ' ' . $db->sql_build_array('INSERT', array( |
|---|
| 74 |
'userid' => $userdata['uid'], |
|---|
| 75 |
'added' => $added, |
|---|
| 76 |
'body' => $body, |
|---|
| 77 |
'title' => $title, |
|---|
| 78 |
'news_announce_time' => $news_announce_until, |
|---|
| 79 |
'news_disable_comments' => $news_disable_comments, |
|---|
| 80 |
'news_announce_user_classes' => $news_announce_userclasses )) |
|---|
| 81 |
); |
|---|
| 82 |
$cache->destroy('sql', NEWS_TABLE); |
|---|
| 83 |
$message = $lang['news_sucefully_added'] . '<br /><br />' . sprintf($lang['click_return_news_admin'], "<a href=\"" . append_sid("admin_news.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>"); |
|---|
| 84 |
trigger_error($message); |
|---|
| 85 |
} |
|---|
| 86 |
|
|---|
| 87 |
elseif ( $action == 'edit' ) { |
|---|
| 88 |
$template->set_filenames(array( |
|---|
| 89 |
'news_tpl' => '../admin/admin_news_edit_body.html') |
|---|
| 90 |
); |
|---|
| 91 |
$newsid = request_var('id', 0); |
|---|
| 92 |
|
|---|
| 93 |
$sql = 'SELECT * FROM ' . NEWS_TABLE . ' WHERE id = ' . $newsid; |
|---|
| 94 |
$result = $db->sql_query($sql); |
|---|
| 95 |
if ( !($arr = $db->sql_fetchrow($result)) ) { |
|---|
| 96 |
trigger_error(sprintf($lang['invalid_id'], $newsid)); |
|---|
| 97 |
} |
|---|
| 98 |
|
|---|
| 99 |
if ( isset($_POST['submit']) ) { |
|---|
| 100 |
$body = request_var('body', ''); |
|---|
| 101 |
$title = request_var('title', ''); |
|---|
| 102 |
$news_disable_comments = request_var('news_disable_comments', 0); |
|---|
| 103 |
$news_announce_until = request_var('news_announce_until', 0); |
|---|
| 104 |
$news_announce_userclasses = request_var('news_announce_userclasses', array( 0 => 0)); |
|---|
| 105 |
|
|---|
| 106 |
if ( !$body || !$title ) { |
|---|
| 107 |
trigger_error($lang['post_something']); |
|---|
| 108 |
} |
|---|
| 109 |
if ( sizeof($news_announce_userclasses) && $news_announce_userclasses[0] != 'all' ) { |
|---|
| 110 |
$news_announce_userclasses = implode(',', $news_announce_userclasses); |
|---|
| 111 |
} |
|---|
| 112 |
else { |
|---|
| 113 |
$news_announce_userclasses = ''; |
|---|
| 114 |
} |
|---|
| 115 |
$db->sql_query('UPDATE ' . NEWS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', array( |
|---|
| 116 |
'body' => $body, |
|---|
| 117 |
'title' => $title, |
|---|
| 118 |
'added' => time(), |
|---|
| 119 |
'news_announce_time' => $news_announce_until, |
|---|
| 120 |
'news_disable_comments' => $news_disable_comments, |
|---|
| 121 |
'news_announce_user_classes' => $news_announce_userclasses)) . ' WHERE id = ' . $newsid |
|---|
| 122 |
); |
|---|
| 123 |
$cache->destroy('sql', NEWS_TABLE); |
|---|
| 124 |
$message = $lang['news_sucefully_edited'] . "<br /><br />" . sprintf($lang['click_return_news_admin'], "<a href=\"" . append_sid("admin_news.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>"); |
|---|
| 125 |
trigger_error($message); |
|---|
| 126 |
} |
|---|
| 127 |
|
|---|
| 128 |
else { |
|---|
| 129 |
$n_a_u_c = explode(',', $arr['news_announce_user_classes']); |
|---|
| 130 |
$user_classes_options = '<option value="all"' . ( $n_a_u_c[0] == '' ? ' selected="selected"' : '' ) . '>' . $lang['all'] . '</option>'; |
|---|
| 131 |
$i = 0; |
|---|
| 132 |
while ( $c = get_user_class_name($i) ) { |
|---|
| 133 |
$user_classes_options .= '<option value="' . $i . '"' . ( in_array(strval($i), $n_a_u_c, true) ? ' selected="selected"' : '' ) . '>' . $c . '</option>'; |
|---|
| 134 |
++$i; |
|---|
| 135 |
} |
|---|
| 136 |
$template->assign_vars(array( |
|---|
| 137 |
'S_FORM_ACTION' => append_sid('admin_news.php?action=edit&id=' . $newsid), |
|---|
| 138 |
'NEWS_ID' => $newsid, |
|---|
| 139 |
'TITLE' => $arr['title'], |
|---|
| 140 |
'BODY' => $arr['body'], |
|---|
| 141 |
'ANNOUNCE_UNTIL' => $arr['news_announce_time'], |
|---|
| 142 |
'USER_CLASSES_OPTIONS' => $user_classes_options, |
|---|
| 143 |
'NEWS_DISABLE_COMMENTS' => $arr['news_disable_comments'] |
|---|
| 144 |
)); |
|---|
| 145 |
|
|---|
| 146 |
$template->display('news_tpl'); |
|---|
| 147 |
include('./page_footer_admin.'.$phpEx); |
|---|
| 148 |
} |
|---|
| 149 |
} |
|---|
| 150 |
|
|---|
| 151 |
else { |
|---|
| 152 |
$template->set_filenames(array( |
|---|
| 153 |
'news_tpl' => '../admin/admin_news_body.html' |
|---|
| 154 |
)); |
|---|
| 155 |
|
|---|
| 156 |
$sql = 'SELECT n.*, u.name AS username |
|---|
| 157 |
FROM ' . NEWS_TABLE . ' n, ' . USERS_TABLE . ' u |
|---|
| 158 |
WHERE n.userid = u.uid ORDER BY added DESC'; |
|---|
| 159 |
$result = $db->sql_query($sql); |
|---|
| 160 |
|
|---|
| 161 |
$user_classes_options = '<option value="all">' . $lang['all'] . '</option>'; |
|---|
| 162 |
$i = 0; |
|---|
| 163 |
while ( $c = get_user_class_name($i) ) { |
|---|
| 164 |
$user_classes_options .= '<option value="' . $i . '">' . $c . '</option>'; |
|---|
| 165 |
++$i; |
|---|
| 166 |
} |
|---|
| 167 |
$template->assign_vars(array( |
|---|
| 168 |
'S_FROM_ACTION' => append_sid('admin_news.' . $phpEx . '?action=add'), |
|---|
| 169 |
'USER_CLASSES_OPTIONS' => $user_classes_options |
|---|
| 170 |
)); |
|---|
| 171 |
|
|---|
| 172 |
$i = 0; |
|---|
| 173 |
|
|---|
| 174 |
if ( $row = $db->sql_fetchrow($result) ) { |
|---|
| 175 |
do { |
|---|
| 176 |
$n_a_u_c = explode(',', $row['news_announce_user_classes']); |
|---|
| 177 |
|
|---|
| 178 |
if ( $n_a_u_c[0] != '' ) { |
|---|
| 179 |
$j = 0; |
|---|
| 180 |
$classes = ''; |
|---|
| 181 |
while ( $c = get_user_class_name($j) ) { |
|---|
| 182 |
if ( in_array(strval($j), $n_a_u_c, true) ) { |
|---|
| 183 |
$classes .= ( $classes ? ', ' . $c : $c ); |
|---|
| 184 |
} |
|---|
| 185 |
++$j; |
|---|
| 186 |
} |
|---|
| 187 |
} |
|---|
| 188 |
else { |
|---|
| 189 |
$classes = $lang['all']; |
|---|
| 190 |
} |
|---|
| 191 |
|
|---|
| 192 |
$body = $row['body']; |
|---|
| 193 |
|
|---|
| 194 |
$bb_code = new bbcode($body); |
|---|
| 195 |
$body = $bb_code->get_html(); |
|---|
| 196 |
|
|---|
| 197 |
$body .= '<br /><i>' . sprintf($lang['news_view_by_classes'], $classes) . '</i>'; |
|---|
| 198 |
$added = create_date($row['added']); |
|---|
| 199 |
$added .= '<br />' . get_elapsed_time($row['added']); |
|---|
| 200 |
$news_announce_until = $row['added'] + ( $row['news_announce_time'] * 24 * 60 * 60 ); |
|---|
| 201 |
|
|---|
| 202 |
$template->assign_block_vars('news_row', array( |
|---|
| 203 |
'U_USERDETAILS' => append_sid($root_path . 'userdetails.php?id=' . $row['userid']), |
|---|
| 204 |
'U_EDIT' => append_sid('admin_news.' . $phpEx . '?action=edit&id=' . $row['id']), |
|---|
| 205 |
'U_DELETE' => append_sid('admin_news.' . $phpEx . '?action=delete&id=' . $row['id']), |
|---|
| 206 |
'TD_CLASS' => ( $i % 2 ) ? $theme['td_class1'] : $theme['td_class2'], |
|---|
| 207 |
'TITLE' => $row['title'], |
|---|
| 208 |
'NEWS_ID' => $row['id'], |
|---|
| 209 |
'POSTER_ID' => $row['userid'], |
|---|
| 210 |
'BODY' => $body, |
|---|
| 211 |
'ADDED' => $added, |
|---|
| 212 |
'POSTER_NAME' => $row['username'], |
|---|
| 213 |
'ANNOUNCE_UNTIL' => ( !empty($row['news_announce_time']) ? create_date($news_announce_until) . '<br />(' . $row['news_announce_time'] . ' ' . $lang['days'] . ')' : $lang['no_announce_until'] ) |
|---|
| 214 |
)); |
|---|
| 215 |
++$i; |
|---|
| 216 |
} |
|---|
| 217 |
while ( $row = $db->sql_fetchrow($result) ); |
|---|
| 218 |
} |
|---|
| 219 |
else { |
|---|
| 220 |
$template->assign_block_vars('no_news', array()); |
|---|
| 221 |
} |
|---|
| 222 |
|
|---|
| 223 |
$template->display('news_tpl'); |
|---|
| 224 |
include('./page_footer_admin.'.$phpEx); |
|---|
| 225 |
} |
|---|
| 226 |
?> |
|---|
| 227 |
|
|---|