-
Notifications
You must be signed in to change notification settings - Fork 1
/
editnews.php
140 lines (131 loc) · 4.8 KB
/
editnews.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
/**
* Popup window for Editing news items
*
* Genmod: Genealogy Viewer
* Copyright (C) 2005 - 2012 Genmod Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @package Genmod
* @version $Id: editnews.php 29 2022-07-17 13:18:20Z Boudewijn $
*/
/**
* Inclusion of the configuration file
*/
require("config.php");
$username = $gm_username;
if (empty($username)) {
PrintSimpleHeader("");
print GM_LANG_access_denied;
PrintSimpleFooter();
exit;
}
/**
* Inclusion of the CK Editor
*/
$useCK = file_exists("modules/CKEditor/ckeditor.php");
if($useCK){
include("modules/CKEditor/ckeditor.php");
}
if (!isset($action)) $action="compose";
PrintSimpleHeader(GM_LANG_edit_news);
if (empty($uname)) $uname = get_gedcom_from_id(GedcomConfig::$GEDCOMID);
if ($action=="compose") {
?>
<script language="JavaScript" type="text/javascript">
<!--
function checkForm(frm) {
if (frm.title.value=="") {
alert('<?php print GM_LANG_enter_title; ?>');
document.messageform.title.focus();
return false;
}
<?php if (! $useCK) { //will be empty for FCK. FIXME, use FCK API to check for content.
?>
if (frm.text.value=="") {
alert('<?php print GM_LANG_enter_text; ?>');
document.messageform.text.focus();
return false;
}
<?php } ?>
return true;
}
//-->
</script>
<?php
print "<form name=\"messageform\" method=\"post\" onsubmit=\"return checkForm(this);";
print "\">\n";
if (isset($news_id)) {
$news = NewsController::getNewsItem($news_id);
}
else {
$news_id="";
$news = new News();
$news->username = $uname;
$news->date = time()-$_SESSION["timediff"];
$news->title = "";
$news->text = "";
}
print "<input type=\"hidden\" name=\"action\" value=\"save\" />\n";
print "<input type=\"hidden\" name=\"uname\" value=\"".$news->username."\" />\n";
print "<input type=\"hidden\" name=\"news_id\" value=\"".$news->id."\" />\n";
print "<input type=\"hidden\" name=\"date\" value=\"".$news->date."\" />\n";
print "<table class=\"NavBlockTable\">\n";
print "<tr><td colspan=\"2\" class=\"NavBlockHeader\">".GM_LANG_edit_news."</td>";
print "<tr><td class=\"NavBlockLabel\">".GM_LANG_title."</td><td class=\"NavBlockField\"><input type=\"text\" name=\"title\" size=\"50\" value=\"".$news->title."\" /><br /></td></tr>\n";
print "<tr><td class=\"NavBlockLabel\">".GM_LANG_article_text."</td>";
print "<td class=\"NavBlockField\">";
if ($useCK) { // use CKeditor module
$trans = get_html_translation_table(HTML_SPECIALCHARS);
$trans = array_flip($trans);
$news->text = strtr($news->text, $trans);
// $news->text = nl2br($news->text); This causes extra line breaks in CKEditor!
?><script type="text/javascript" src="modules/CKEditor/ckeditor.js"></script><?php
$oCKeditor = new CKEditor();
$oCKeditor->BasePath = 'modules/CKEditor/';
$oCKeditor->config["height"] = 450;
$oCKEditor->config["enterMode"] = "br";
$oCKEditor->config["ShiftEnterMode"] = "p";
$oCKeditor->config['language'] = $language_settings[$LANGUAGE]["lang_short_cut"];
$oCKeditor->editor("text", $news->text) ;
} else { //use standard textarea
print "<textarea name=\"text\" cols=\"80\" rows=\"10\">".$news->text."</textarea>";
}
print "</td></tr>\n";
print "<tr><td class=\"NavBlockFooter\" colspan=\"2\"><input type=\"submit\" value=\"".GM_LANG_save."\" /></td></tr>\n";
print "</table>\n";
print "</form>\n";
}
else if ($action=="save") {
$news = NewsController::getNewsItem($news_id);
if (!is_object($news)) $news = new News();
$date=time()-$_SESSION["timediff"];
if (empty($title)) $title="No Title";
if (empty($text)) $text="No Text";
$news->username = $uname;
$news->date=$date;
$news->title = $title;
$news->text = $text;
if ($news->addNews()) {
print GM_LANG_news_saved;
}
}
else if ($action=="delete") {
if (NewsController::DeleteNews($news_id)) print GM_LANG_news_deleted;
}
print "<div class=\"CloseWindow\"><a href=\"#\" onclick=\"if (window.opener.refreshpage) window.opener.refreshpage(); window.close();\">".GM_LANG_close_window."</a></div>";
PrintSimpleFooter();
?>