1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* $Id: entry.php v 1.0 8 May 2004 hsalazar Exp $ |
4
|
|
|
* Module: Lexikon - glossary module |
5
|
|
|
* Version: v 1.00 |
6
|
|
|
* Release Date: 8 May 2004 |
7
|
|
|
* Author: hsalazar |
8
|
|
|
* Modifs: Yerres |
9
|
|
|
* Licence: GNU |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
include( "admin_header.php" ); |
13
|
|
|
$myts =& MyTextSanitizer::getInstance(); |
14
|
|
|
xoops_cp_header(); |
15
|
|
|
$indexAdmin = new ModuleAdmin(); |
16
|
|
|
echo $indexAdmin->addNavigation('entry.php'); |
17
|
|
|
$indexAdmin->addItemButton(_AM_LEXIKON_CREATEENTRY, 'entry.php?op=add', 'add'); |
18
|
|
|
echo $indexAdmin->renderButton('left'); |
19
|
|
|
|
20
|
|
|
$op = ''; |
21
|
|
|
#if ( isset( $_GET['op'] ) ) $op = $_GET['op']; |
|
|
|
|
22
|
|
|
#if ( isset( $_POST['op'] ) ) $op = $_POST['op']; |
23
|
|
|
error_reporting(E_ALL); |
24
|
|
|
error_reporting(E_ERROR | E_WARNING | E_PARSE); |
25
|
|
|
/* -- Available operations -- */ |
26
|
|
|
function entryDefault() { |
|
|
|
|
27
|
|
|
global $xoopsUser, $xoopsConfig, $xoopsDB, $xoopsModuleConfig, $xoopsModule, $entryID, $pathIcon16; |
|
|
|
|
28
|
|
|
include_once XOOPS_ROOT_PATH . "/class/xoopslists.php"; |
29
|
|
|
include_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
30
|
|
|
xoops_load('XoopsUserUtility'); |
31
|
|
|
// lx_adminMenu(2, _AM_LEXIKON_ENTRIES); |
|
|
|
|
32
|
|
|
|
33
|
|
|
$startentry = isset( $_GET['startentry'] ) ? intval( $_GET['startentry'] ) : 0; |
34
|
|
|
$startcat = isset( $_GET['startcat'] ) ? intval( $_GET['startcat'] ) : 0; |
|
|
|
|
35
|
|
|
$startsub = isset( $_GET['startsub'] ) ? intval( $_GET['startsub'] ) : 0; |
|
|
|
|
36
|
|
|
$datesub = isset( $_GET['datesub'] ) ? intval( $_GET['datesub'] ) : 0; |
|
|
|
|
37
|
|
|
|
38
|
|
|
$myts =& MyTextSanitizer::getInstance(); |
39
|
|
|
|
40
|
|
|
$result01 = $xoopsDB -> query( "SELECT COUNT(*) |
41
|
|
|
FROM " . $xoopsDB -> prefix( "lxcategories" ) . " " ); |
42
|
|
|
list( $totalcategories ) = $xoopsDB -> fetchRow( $result01 ); |
|
|
|
|
43
|
|
|
|
44
|
|
|
$result02 = $xoopsDB -> query( "SELECT COUNT(*) |
45
|
|
|
FROM " . $xoopsDB -> prefix( "lxentries" ) . " |
46
|
|
|
WHERE submit = 0" ); |
47
|
|
|
list( $totalpublished ) = $xoopsDB -> fetchRow( $result02 ); |
48
|
|
|
|
49
|
|
|
$result03 = $xoopsDB -> query( "SELECT COUNT(*) |
50
|
|
|
FROM " . $xoopsDB -> prefix( "lxentries" ) . " |
51
|
|
|
WHERE submit = '1' AND request = '0' " ); |
52
|
|
|
list( $totalsubmitted ) = $xoopsDB -> fetchRow( $result03 ); |
|
|
|
|
53
|
|
|
|
54
|
|
|
$result04 = $xoopsDB -> query( "SELECT COUNT(*) |
55
|
|
|
FROM " . $xoopsDB -> prefix( "lxentries" ) . " |
56
|
|
|
WHERE submit = '1' AND request = '1' " ); |
57
|
|
|
list( $totalrequested ) = $xoopsDB -> fetchRow( $result04 ); |
|
|
|
|
58
|
|
|
|
59
|
|
|
// echo "<table width='100%' class='outer' style=\"margin-top: 6px; clear:both;\" cellspacing='2' cellpadding='3' border='0' ><tr>"; |
60
|
|
|
// echo "<td class='odd'>" . _AM_LEXIKON_TOTALENTRIES . "</td><td align='center' class='even'>" . $totalpublished . "</td>"; |
61
|
|
|
// if ($xoopsModuleConfig['multicats'] == 1) { |
62
|
|
|
// echo "<td class='odd'>" . _AM_LEXIKON_TOTALCATS . "</td><td align='center' class='even'>" . $totalcategories . "</td>"; |
63
|
|
|
// } |
64
|
|
|
// echo "<td class='odd'>" . _AM_LEXIKON_TOTALSUBM . "</td><td align='center' class='even'>" . $totalsubmitted . "</td> |
65
|
|
|
// <td class='odd'>" . _AM_LEXIKON_TOTALREQ . "</td><td align='center' class='even'>" . $totalrequested . "</td> |
66
|
|
|
// </tr></table> |
67
|
|
|
// <br /><br />"; |
68
|
|
|
// |
69
|
|
|
/** |
70
|
|
|
* Code to show existing terms |
71
|
|
|
**/ |
72
|
|
|
|
73
|
|
|
// create existing terms table |
74
|
|
|
$resultA1 = $xoopsDB -> query( "SELECT COUNT(*) |
75
|
|
|
FROM " . $xoopsDB -> prefix( "lxentries" ) . " |
76
|
|
|
WHERE submit = 0" ); |
77
|
|
|
list( $numrows ) = $xoopsDB -> fetchRow( $resultA1 ); |
78
|
|
|
|
79
|
|
|
$sql = "SELECT entryID, categoryID, term, uid, datesub, offline |
80
|
|
|
FROM ".$xoopsDB->prefix('lxentries')." |
81
|
|
|
WHERE submit = 0 |
82
|
|
|
ORDER BY entryID DESC"; |
83
|
|
|
$resultA2 = $xoopsDB -> query( $sql, $xoopsModuleConfig['perpage'], $startentry ); |
84
|
|
|
$result = $xoopsDB->query($sql, $xoopsModuleConfig['perpage']); |
|
|
|
|
85
|
|
|
|
86
|
|
|
echo " <table class='outer' width='100%' border='0'> |
87
|
|
|
<tr> |
88
|
|
|
<td colspan='7' class='odd'> |
89
|
|
|
<strong>". _AM_LEXIKON_SHOWENTRIES . ' (' . $totalpublished . ')'. "</strong></td></TR>"; |
90
|
|
|
echo "<tr>"; |
91
|
|
|
|
92
|
|
|
echo "<th width='40' align='center'><b>" . _AM_LEXIKON_ENTRYID . "</A></b></td>"; |
93
|
|
|
if ($xoopsModuleConfig['multicats'] == 1) { |
94
|
|
|
echo "<th width='20%' align='center'><b>" . _AM_LEXIKON_ENTRYCATNAME . "</b></td>"; |
95
|
|
|
} |
96
|
|
|
echo "<th width='*' align='center'><b>" . _AM_LEXIKON_ENTRYTERM . "</b></td> |
97
|
|
|
<th width='90' align='center'><b>" . _AM_LEXIKON_SUBMITTER . "</b></td> |
98
|
|
|
<th width='90' align='center'><b>" . _AM_LEXIKON_ENTRYCREATED . "</b></td> |
99
|
|
|
<th width='30' align='center'><b>" . _AM_LEXIKON_STATUS . "</b></td> |
100
|
|
|
<th width='60' align='center'><b>" . _AM_LEXIKON_ACTION . "</b></td> |
101
|
|
|
</tr>"; |
102
|
|
|
$class = "odd"; |
103
|
|
|
if ( $numrows > 0 ) // That is, if there ARE entries in the system |
104
|
|
|
|
105
|
|
|
{ |
106
|
|
|
while ( list( $entryID, $categoryID, $term, $uid, $created, $offline ) = $xoopsDB -> fetchrow( $resultA2 ) ) { |
107
|
|
|
$resultA3 = $xoopsDB -> query( "SELECT name |
108
|
|
|
FROM " . $xoopsDB -> prefix( "lxcategories" ) . " |
109
|
|
|
WHERE categoryID = '$categoryID'" ); |
110
|
|
|
list( $name ) = $xoopsDB -> fetchrow( $resultA3 ); |
111
|
|
|
|
112
|
|
|
$sentby = XoopsUserUtility::getUnameFromId($uid); |
113
|
|
|
$catname = $myts -> htmlSpecialChars( $name ); |
114
|
|
|
$term = $myts -> htmlSpecialChars( $term ); |
115
|
|
|
$created= formatTimestamp( $created, 's' ); |
116
|
|
|
$modify = "<a href='entry.php?op=mod&entryID=" . $entryID . "'><img src=" . $pathIcon16."/edit.png width='16' height='16' ALT='"._AM_LEXIKON_EDITENTRY."'></a>"; |
117
|
|
|
$delete = "<a href='entry.php?op=del&entryID=" . $entryID . "'><img src=" . $pathIcon16."/delete.png width='16' height='16' ALT='"._AM_LEXIKON_DELETEENTRY."'></a>"; |
118
|
|
|
|
119
|
|
View Code Duplication |
if ( $offline == 0 ) { |
|
|
|
|
120
|
|
|
$status = "<img src=" . XOOPS_URL . "/modules/" . $xoopsModule->dirname() . "/images/icon/on.gif alt='"._AM_LEXIKON_ENTRYISON."'>"; |
121
|
|
|
} else { |
122
|
|
|
$status = "<img src=" . XOOPS_URL . "/modules/" . $xoopsModule->dirname() . "/images/icon/off.gif alt='"._AM_LEXIKON_ENTRYISOFF."'>"; |
123
|
|
|
} |
124
|
|
|
echo "<tr class='" . $class . "'>"; |
125
|
|
|
$class = ($class == "even") ? "odd" : "even"; |
126
|
|
|
|
127
|
|
|
echo "<td align='center'>" . $entryID . "</td>"; |
128
|
|
|
|
129
|
|
|
if ($xoopsModuleConfig['multicats'] == 1) { |
130
|
|
|
echo "<td class='odd' align='left'>" . $catname . "</td>"; |
131
|
|
|
} |
132
|
|
|
//echo "<td class='$class'align='left'>" . $term . "</td>"; |
|
|
|
|
133
|
|
|
echo "<td class='odd'align='left'><a href='../entry.php?entryID=" . $entryID . "'>" . $term . "</td> |
134
|
|
|
<td class='odd' align='center'>" . $sentby . "</td> |
135
|
|
|
<td class='odd' align='center'>" . $created . "</td> |
136
|
|
|
<td class='odd' align='center'>" . $status . "</td> |
137
|
|
|
<td class='even' align='center'> $modify $delete </td> |
138
|
|
|
</tr></DIV>"; |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
else // that is, $numrows = 0, there's no entries yet |
142
|
|
|
{ |
143
|
|
|
echo "<tr>"; |
144
|
|
|
echo "<td class='odd' align='center' colspan= '7'>"._AM_LEXIKON_NOTERMS."</td>"; |
145
|
|
|
echo "</tr></DIV>"; |
146
|
|
|
} |
147
|
|
|
echo "</table>\n"; |
148
|
|
|
$pagenav = new XoopsPageNav( $numrows, $xoopsModuleConfig['perpage'], $startentry, 'startentry'); |
149
|
|
|
echo '<div style="text-align:right;">' . $pagenav -> renderNav(8) . '</div>'; |
150
|
|
|
echo "<br /><BR>\n"; |
151
|
|
|
echo "</div>"; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
// -- Edit function -- |
155
|
|
|
function entryEdit( $entryID = '' ) { |
156
|
|
|
global $xoopsUser, $xoopsConfig, $xoopsDB, $xoopsModuleConfig, $xoopsModule, $init; |
|
|
|
|
157
|
|
|
$myts =& MyTextSanitizer::getInstance(); |
158
|
|
|
/** |
159
|
|
|
* Clear all variables before we start |
160
|
|
|
*/ |
161
|
|
|
if(!isset($block)) { $block = 1; } |
|
|
|
|
162
|
|
|
if(!isset($html)) { $html = 1; } |
|
|
|
|
163
|
|
|
if(!isset($smiley)) { $smiley = 1; } |
|
|
|
|
164
|
|
|
if(!isset($xcodes)) { $xcodes = 1; } |
|
|
|
|
165
|
|
|
if(!isset($breaks)) { $breaks = 1; } |
|
|
|
|
166
|
|
|
if(!isset($offline)) { $offline = 0; } |
|
|
|
|
167
|
|
|
if(!isset($submit)) { $submit = 0; } |
|
|
|
|
168
|
|
|
if(!isset($request)) { $request = 0; } |
|
|
|
|
169
|
|
|
if(!isset($notifypub)) { $notifypub = 1; } |
|
|
|
|
170
|
|
|
if(!isset($categoryID)) { $categoryID = 1; } |
|
|
|
|
171
|
|
|
if(!isset($term)) { $term = ""; } |
|
|
|
|
172
|
|
|
if(!isset($init)) { $init = ""; } |
173
|
|
|
if (!isset($definition)) { |
|
|
|
|
174
|
|
|
$definition = _AM_LEXIKON_WRITEHERE; |
175
|
|
|
} |
176
|
|
|
if(!isset($ref)) { $ref = ""; } |
|
|
|
|
177
|
|
|
if(!isset($url)) { $url = ""; } |
|
|
|
|
178
|
|
|
if(!isset($datesub)) { $datesub = 0; } |
|
|
|
|
179
|
|
|
|
180
|
|
|
// If there is a parameter, and the id exists, retrieve data: we're editing an entry |
181
|
|
|
if ( $entryID ) { |
182
|
|
|
$result = $xoopsDB -> query( " |
183
|
|
|
SELECT categoryID, term, init, definition, ref, url, uid, submit, datesub, html, smiley, xcodes, breaks, block, offline, notifypub, request |
184
|
|
|
FROM " . $xoopsDB -> prefix( "lxentries" ) . " |
185
|
|
|
WHERE entryID = '$entryID'" ); |
186
|
|
|
list( $categoryID, $term, $init, $definition, $ref, $url, $uid, $submit, $datesub, $html, $smiley, $xcodes, $breaks, $block, $offline, $notifypub, $request ) = $xoopsDB -> fetchrow( $result ); |
|
|
|
|
187
|
|
|
|
188
|
|
|
if ( !$xoopsDB -> getRowsNum( $result ) ) { |
189
|
|
|
redirect_header( "index.php", 1, _AM_LEXIKON_NOENTRYTOEDIT ); |
190
|
|
|
exit(); |
|
|
|
|
191
|
|
|
} |
192
|
|
|
$term = $myts->stripSlashesGPC($myts->htmlSpecialChars($term)); |
193
|
|
|
|
194
|
|
|
// lx_adminMenu(2, _AM_LEXIKON_ADMINENTRYMNGMT); |
|
|
|
|
195
|
|
|
|
196
|
|
|
echo "<h3 style=\"color: #2F5376; margin-top: 6px; \">" . _AM_LEXIKON_ADMINENTRYMNGMT . "</h3>"; |
197
|
|
|
$sform = new XoopsThemeForm( _AM_LEXIKON_MODENTRY . ": $term" , "op", xoops_getenv( 'PHP_SELF' ) ); |
198
|
|
|
} else // there's no parameter, so we're adding an entry |
199
|
|
|
{ |
200
|
|
|
$result01 = $xoopsDB -> query( "SELECT COUNT(*) FROM " . $xoopsDB -> prefix( "lxcategories" ) . " " ); |
201
|
|
|
list( $totalcats ) = $xoopsDB -> fetchRow( $result01 ); |
202
|
|
|
if ( $totalcats == 0 && $xoopsModuleConfig['multicats'] == 1 ) { |
203
|
|
|
redirect_header( "index.php", 1, _AM_LEXIKON_NEEDONECOLUMN ); |
204
|
|
|
exit(); |
|
|
|
|
205
|
|
|
} |
206
|
|
|
// lx_adminMenu(2, _AM_LEXIKON_ADMINENTRYMNGMT); |
|
|
|
|
207
|
|
|
$uid = $xoopsUser->getVar('uid'); |
208
|
|
|
echo "<h3 style=\"color: #2F5376; margin-top: 6px; \">" . _AM_LEXIKON_ADMINENTRYMNGMT . "</h3>"; |
209
|
|
|
$sform = new XoopsThemeForm( _AM_LEXIKON_NEWENTRY, "op", xoops_getenv( 'PHP_SELF' ) ); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
$sform -> setExtra( 'enctype="multipart/form-data"' ); |
213
|
|
|
// Category selector |
214
|
|
|
if ($xoopsModuleConfig['multicats'] == 1) { |
215
|
|
|
$mytree = new XoopsTree( $xoopsDB->prefix( "lxcategories" ), "categoryID" , "0" ); |
216
|
|
|
$categoryselect = new XoopsFormSelect(_AM_LEXIKON_CATNAME, 'categoryID', $categoryID); |
217
|
|
|
$tbl = array(); |
|
|
|
|
218
|
|
|
$tbl = $mytree->getChildTreeArray(0,'name'); |
219
|
|
View Code Duplication |
foreach($tbl as $oneline) { |
|
|
|
|
220
|
|
|
if ($oneline['prefix']=='.') { |
221
|
|
|
$oneline['prefix']=''; |
222
|
|
|
} |
223
|
|
|
$oneline['prefix'] = str_replace('.','-',$oneline['prefix']); |
224
|
|
|
$categoryselect->addOption($oneline['categoryID'], $oneline['prefix'].' '.$oneline['name']); |
225
|
|
|
} |
226
|
|
|
$sform->addElement($categoryselect,true); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
// Author selector |
230
|
|
|
ob_start(); |
231
|
|
|
lx_getuserForm( intval($uid) ); |
232
|
|
|
$sform -> addElement( new XoopsFormLabel( _AM_LEXIKON_AUTHOR, ob_get_contents() ) ); |
233
|
|
|
ob_end_clean(); |
234
|
|
|
|
235
|
|
|
// Initial selector |
236
|
|
|
ob_start(); |
237
|
|
|
lx_getinit( intval($init) ); |
238
|
|
|
$sform -> addElement( new XoopsFormLabel( _AM_LEXIKON_INIT, ob_get_contents() ) ); |
239
|
|
|
ob_end_clean(); |
240
|
|
|
|
241
|
|
|
// Term, definition, reference and related URL |
242
|
|
|
$sform -> addElement( new XoopsFormText( _AM_LEXIKON_ENTRYTERM, 'term', 50, 80, $term ), true ); |
243
|
|
|
|
244
|
|
|
// set editor according to the module's option "form_options" |
245
|
|
|
$editor = lx_getWysiwygForm( _AM_LEXIKON_ENTRYDEF, 'definition', $definition, 15, 60 ); |
246
|
|
|
if ($definition == _MD_LEXIKON_WRITEHERE) { |
247
|
|
|
$editor -> setExtra( 'onfocus="this.select()"' ); |
248
|
|
|
} |
249
|
|
|
$sform -> addElement( $editor,true ); |
250
|
|
|
unset($editor); |
251
|
|
|
|
252
|
|
|
$sform -> addElement( new XoopsFormTextArea( _AM_LEXIKON_ENTRYREFERENCE, 'ref', $ref, 5, 60 ), false ); |
253
|
|
|
$sform -> addElement( new XoopsFormText( _AM_LEXIKON_ENTRYURL, 'url', 50, 80, $url ), false ); |
254
|
|
|
|
255
|
|
|
// tags of this term - for module 'Tag' |
256
|
|
|
$module_handler = xoops_gethandler('module'); |
257
|
|
|
$tagsModule = $module_handler->getByDirname("tag"); |
258
|
|
|
if (is_object($tagsModule)) { |
259
|
|
|
include_once XOOPS_ROOT_PATH."/modules/tag/include/formtag.php"; |
260
|
|
|
$sform->addElement(new XoopsFormTag("item_tag", 60, 255, $entryID, $catid = 0)); |
261
|
|
|
} |
262
|
|
|
// Code to take entry offline, for maintenance purposes |
263
|
|
|
$offline_radio = new XoopsFormRadioYN(_AM_LEXIKON_SWITCHOFFLINE, 'offline', $offline, ' '._AM_LEXIKON_YES.'', ' '._AM_LEXIKON_NO.''); |
264
|
|
|
$sform -> addElement($offline_radio); |
265
|
|
|
|
266
|
|
|
// Code to put entry in block |
267
|
|
|
$block_radio = new XoopsFormRadioYN( _AM_LEXIKON_BLOCK, 'block', $block , ' ' . _AM_LEXIKON_YES . '', ' ' . _AM_LEXIKON_NO . '' ); |
268
|
|
|
$sform -> addElement( $block_radio ); |
269
|
|
|
|
270
|
|
|
// VARIOUS OPTIONS |
271
|
|
|
$options_tray = new XoopsFormElementTray(_AM_LEXIKON_OPTIONS,'<br />'); |
272
|
|
|
if ($submit) { |
273
|
|
|
$notify_checkbox = new XoopsFormCheckBox('', 'notifypub', $notifypub); |
274
|
|
|
$notify_checkbox->addOption(1, _AM_LEXIKON_NOTIFYPUBLISH); |
275
|
|
|
$options_tray->addElement($notify_checkbox); |
276
|
|
|
}else{ |
277
|
|
|
$notifypub=0; |
|
|
|
|
278
|
|
|
} |
279
|
|
|
$html_checkbox = new XoopsFormCheckBox( '', 'html', $html ); |
280
|
|
|
$html_checkbox -> addOption( 1, _AM_LEXIKON_DOHTML ); |
281
|
|
|
$options_tray -> addElement( $html_checkbox ); |
282
|
|
|
|
283
|
|
|
$smiley_checkbox = new XoopsFormCheckBox( '', 'smiley', $smiley ); |
284
|
|
|
$smiley_checkbox -> addOption( 1, _AM_LEXIKON_DOSMILEY ); |
285
|
|
|
$options_tray -> addElement( $smiley_checkbox ); |
286
|
|
|
|
287
|
|
|
$xcodes_checkbox = new XoopsFormCheckBox( '', 'xcodes', $xcodes ); |
288
|
|
|
$xcodes_checkbox -> addOption( 1, _AM_LEXIKON_DOXCODE ); |
289
|
|
|
$options_tray -> addElement( $xcodes_checkbox ); |
290
|
|
|
|
291
|
|
|
$breaks_checkbox = new XoopsFormCheckBox( '', 'breaks', $breaks ); |
292
|
|
|
$breaks_checkbox -> addOption( 1, _AM_LEXIKON_BREAKS ); |
293
|
|
|
$options_tray -> addElement( $breaks_checkbox ); |
294
|
|
|
|
295
|
|
|
$sform -> addElement( $options_tray ); |
296
|
|
|
|
297
|
|
|
$sform -> addElement( new XoopsFormHidden( 'entryID', $entryID ) ); |
298
|
|
|
|
299
|
|
|
$button_tray = new XoopsFormElementTray( '', '' ); |
300
|
|
|
$hidden = new XoopsFormHidden( 'op', 'addentry' ); |
301
|
|
|
$button_tray -> addElement( $hidden ); |
302
|
|
|
|
303
|
|
View Code Duplication |
if ( !$entryID ) // there's no entryID? Then it's a new entry |
|
|
|
|
304
|
|
|
{ |
305
|
|
|
|
306
|
|
|
$butt_create = new XoopsFormButton( '', '', _AM_LEXIKON_CREATE, 'submit' ); |
307
|
|
|
$butt_create->setExtra('onclick="this.form.elements.op.value=\'addentry\'"'); |
308
|
|
|
$button_tray->addElement( $butt_create ); |
309
|
|
|
|
310
|
|
|
$butt_clear = new XoopsFormButton( '', '', _AM_LEXIKON_CLEAR, 'reset' ); |
311
|
|
|
$button_tray->addElement( $butt_clear ); |
312
|
|
|
|
313
|
|
|
$butt_cancel = new XoopsFormButton( '', '', _AM_LEXIKON_CANCEL, 'button' ); |
314
|
|
|
$butt_cancel->setExtra('onclick="history.go(-1)"'); |
315
|
|
|
$button_tray->addElement( $butt_cancel ); |
316
|
|
|
} else // else, we're editing an existing entry |
317
|
|
|
{ |
318
|
|
|
$butt_create = new XoopsFormButton( '', '', _AM_LEXIKON_MODIFY, 'submit' ); |
319
|
|
|
$butt_create->setExtra('onclick="this.form.elements.op.value=\'addentry\'"'); |
320
|
|
|
$button_tray->addElement( $butt_create ); |
321
|
|
|
|
322
|
|
|
$butt_cancel = new XoopsFormButton( '', '', _AM_LEXIKON_CANCEL, 'button' ); |
323
|
|
|
$butt_cancel->setExtra('onclick="history.go(-1)"'); |
324
|
|
|
$button_tray->addElement( $butt_cancel ); |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
$sform -> addElement( $button_tray ); |
328
|
|
|
$sform -> display(); |
329
|
|
|
unset( $hidden ); |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
/* Save */ |
333
|
|
|
function entrySave ($entryID = '') { |
|
|
|
|
334
|
|
|
Global $xoopsUser, $xoopsConfig, $xoopsModuleConfig, $xoopsModule, $xoopsDB; |
|
|
|
|
335
|
|
|
$myts =& MyTextSanitizer::getInstance(); |
336
|
|
|
$entryID = isset($_POST['entryID']) ? intval($_POST['entryID']) : intval($_GET['entryID']); |
337
|
|
|
if ($xoopsModuleConfig['multicats'] == 1) { |
338
|
|
|
$categoryID = isset($_POST['categoryID']) ? intval($_POST['categoryID']) : intval($_GET['categoryID']); |
339
|
|
|
} else { |
340
|
|
|
$categoryID = 1; |
341
|
|
|
} |
342
|
|
|
$block = isset($_POST['block']) ? intval($_POST['block']) : intval($_GET['block']); |
343
|
|
|
$breaks = isset($_POST['breaks']) ? intval($_POST['breaks']) : intval($_GET['breaks']); |
344
|
|
|
|
345
|
|
|
$html = isset($_POST['html']) ? intval($_POST['html']) : intval($_GET['html']); |
346
|
|
|
$smiley = isset($_POST['smiley']) ? intval($_POST['smiley']) : intval($_GET['smiley']); |
347
|
|
|
$xcodes = isset($_POST['xcodes']) ? intval($_POST['xcodes']) : intval($_GET['xcodes']); |
348
|
|
|
$offline = isset($_POST['offline']) ? intval($_POST['offline']) : intval($_GET['offline']); |
349
|
|
|
$init= $myts->addslashes($_POST['init']); |
350
|
|
|
$term = $myts->addSlashes(xoops_trim($_POST['term'])); |
351
|
|
|
//$definition = $myts -> xoopsCodeDecode($_POST['definition'], $allowimage = 1); |
|
|
|
|
352
|
|
|
//$ref = isset($_POST['ref']) ? $myts->addSlashes($_POST['ref']) : ''; |
|
|
|
|
353
|
|
|
$definition = $myts -> xoopsCodeDecode($myts->censorString($_POST['definition']), $allowimage = 1); |
354
|
|
|
$ref = isset($_POST['ref']) ? $myts->addSlashes($myts->censorString($_POST['ref'])) : ''; |
355
|
|
|
$url = isset($_POST['url']) ? $myts->addSlashes($_POST['url']) : ''; |
356
|
|
|
|
357
|
|
|
$date = time(); |
358
|
|
|
$submit = 0; |
359
|
|
|
//$notifypub = 0; |
|
|
|
|
360
|
|
|
$notifypub = isset($_POST['notifypub']) ? intval($_POST['notifypub']) : intval($_GET['notifypub']); |
361
|
|
|
$request = 0; |
362
|
|
|
$uid = isset($_POST['author']) ? intval($_POST['author']) : $xoopsUser->uid(); |
363
|
|
|
|
364
|
|
|
//-- module Tag |
365
|
|
|
$module_handler = xoops_gethandler('module'); |
366
|
|
|
$tagsModule = $module_handler->getByDirname("tag"); |
367
|
|
|
if (is_object($tagsModule)) { |
368
|
|
|
$tag_handler = xoops_getmodulehandler('tag', 'tag'); |
369
|
|
|
$tag_handler->updateByItem($_POST["item_tag"], $entryID, $xoopsModule->getVar("dirname"), $catid =0); |
370
|
|
|
} |
371
|
|
|
// Save to database |
372
|
|
|
if ( !$entryID ) { |
373
|
|
|
// verify that the term does not exists |
374
|
|
View Code Duplication |
if (lx_TermExists($term,$xoopsDB->prefix('lxentries'))) redirect_header("javascript:history.go(-1)", 2, _AM_LEXIKON_ITEMEXISTS . "<br />" . $term ); |
|
|
|
|
375
|
|
|
if ( $xoopsDB -> query( "INSERT INTO " . $xoopsDB -> prefix( "lxentries" ) . " (entryID, categoryID, term, init, definition, ref, url, uid, submit, datesub, html, smiley, xcodes, breaks, block, offline, notifypub, request ) VALUES ('', '$categoryID', '$term', '$init', '$definition', '$ref', '$url', '$uid', '$submit', '$date', '$html', '$smiley', '$xcodes', '$breaks', '$block', '$offline', '$notifypub', '$request' )" ) ) { |
376
|
|
|
$newid = $xoopsDB->getInsertId(); |
377
|
|
|
// Increment author's posts count (only if it's a new definition) |
378
|
|
View Code Duplication |
if (is_object($xoopsUser) && empty($entryID)) { |
|
|
|
|
379
|
|
|
$member_handler = &xoops_gethandler('member'); |
380
|
|
|
$submitter =& $member_handler -> getUser($uid); |
381
|
|
|
if (is_object($submitter) ) { |
382
|
|
|
$submitter -> setVar('posts',$submitter -> getVar('posts') + 1); |
383
|
|
|
$res=$member_handler -> insertUser($submitter, true); |
|
|
|
|
384
|
|
|
unset($submitter); |
385
|
|
|
} |
386
|
|
|
} |
387
|
|
|
// trigger Notification only if its a new definition |
388
|
|
View Code Duplication |
if(!empty($xoopsModuleConfig['notification_enabled']) ){ |
|
|
|
|
389
|
|
|
global $xoopsModule; |
|
|
|
|
390
|
|
|
if ($newid == 0) { |
391
|
|
|
$newid = $xoopsDB->getInsertId(); |
392
|
|
|
} |
393
|
|
|
$notification_handler =& xoops_gethandler('notification'); |
394
|
|
|
$tags = array(); |
395
|
|
|
$shortdefinition = $myts -> htmlSpecialChars(xoops_substr( strip_tags( $definition ),0,45)); |
396
|
|
|
$tags['ITEM_NAME'] = $term; |
397
|
|
|
$tags['ITEM_BODY'] = $shortdefinition; |
398
|
|
|
$tags['DATESUB'] = formatTimestamp( $date, 'd M Y' ); |
399
|
|
|
$tags['ITEM_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/entry.php?entryID='. $newid; |
400
|
|
|
$sql = "SELECT name FROM " . $xoopsDB->prefix("lxcategories") . " WHERE categoryID=" . $categoryID; |
401
|
|
|
$result = $xoopsDB->query($sql); |
402
|
|
|
$row = $xoopsDB->fetchArray($result); |
403
|
|
|
$tags['CATEGORY_NAME'] = $row['name']; |
404
|
|
|
$tags['CATEGORY_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/category.php?categoryID=' . $categoryID; |
405
|
|
|
$notification_handler->triggerEvent('global', 0, 'new_post', $tags); |
406
|
|
|
$notification_handler->triggerEvent('category', $categoryID, 'new_post', $tags); |
407
|
|
|
//$notification_handler->triggerEvent('term', $newid, 'approve', $tags); |
|
|
|
|
408
|
|
|
} |
409
|
|
|
lx_calculateTotals(); |
410
|
|
|
redirect_header( "entry.php", 1, _AM_LEXIKON_ENTRYCREATEDOK ); |
411
|
|
|
} else { |
412
|
|
|
redirect_header( "index.php", 1, _AM_LEXIKON_ENTRYNOTCREATED ); |
413
|
|
|
} |
414
|
|
|
} else { // That is, $entryID exists, thus we're editing an entry |
415
|
|
|
if ( $xoopsDB -> query( "UPDATE " . $xoopsDB -> prefix( "lxentries" ) . " SET term = '$term', categoryID = '$categoryID', init = '$init', definition = '$definition', ref = '$ref', url = '$url', uid = '$uid', submit = '$submit', datesub = '$date', html = '$html', smiley = '$smiley', xcodes = '$xcodes', breaks = '$breaks', block = '$block', offline = '$offline', notifypub = '$notifypub', request = '$request' WHERE entryID = '$entryID'" ) ) { |
416
|
|
|
// trigger Notification only if its a new submission |
417
|
|
View Code Duplication |
if(!empty($xoopsModuleConfig['notification_enabled']) ){ |
|
|
|
|
418
|
|
|
global $xoopsModule; |
|
|
|
|
419
|
|
|
$notification_handler =& xoops_gethandler('notification'); |
420
|
|
|
$tags = array(); |
421
|
|
|
$shortdefinition = $myts -> htmlSpecialChars(xoops_substr( strip_tags( $definition ),0,45)); |
422
|
|
|
$tags['ITEM_NAME'] = $term; |
423
|
|
|
$tags['ITEM_BODY'] = $shortdefinition; |
424
|
|
|
$tags['DATESUB'] = formatTimestamp( $date, 'd M Y' ); |
425
|
|
|
$tags['ITEM_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/entry.php?entryID='. $entryID; |
426
|
|
|
$sql = "SELECT name FROM " . $xoopsDB->prefix("lxcategories") . " WHERE categoryID=" . $categoryID; |
427
|
|
|
$result = $xoopsDB->query($sql); |
428
|
|
|
$row = $xoopsDB->fetchArray($result); |
429
|
|
|
$tags['CATEGORY_NAME'] = $row['name']; |
430
|
|
|
$tags['CATEGORY_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/category.php?categoryID=' . $categoryID; |
431
|
|
|
$notification_handler->triggerEvent('global', 0, 'new_post', $tags); |
432
|
|
|
$notification_handler->triggerEvent('category', $categoryID, 'new_post', $tags); |
433
|
|
|
$notification_handler->triggerEvent('term', $entryID, 'approve', $tags); |
434
|
|
|
} |
435
|
|
|
|
436
|
|
|
lx_calculateTotals(); |
437
|
|
|
if ($notifypub == '0'){ |
438
|
|
|
redirect_header( "entry.php", 1, _AM_LEXIKON_ENTRYMODIFIED ); |
439
|
|
|
exit(); |
|
|
|
|
440
|
|
|
} else { |
441
|
|
|
$user = new XoopsUser($uid); |
442
|
|
|
$userMessage = sprintf(_MD_LEXIKON_GOODDAY2, $user->getVar('uname')); |
443
|
|
|
$userMessage .= "\n\n"; |
444
|
|
|
if ($request == '1'){$userMessage .= sprintf(_MD_LEXIKON_CONFREQ,$xoopsConfig['sitename']); |
445
|
|
|
} else { $userMessage .= sprintf(_MD_LEXIKON_CONFSUB);} |
446
|
|
|
$userMessage .= "\n"; |
447
|
|
|
$userMessage .= sprintf(_MD_LEXIKON_APPROVED,$xoopsConfig['sitename']); |
448
|
|
|
$userMessage .= "\n\n"; |
449
|
|
|
$userMessage .= sprintf(_MD_LEXIKON_REGARDS); |
450
|
|
|
$userMessage .= "\n"; |
451
|
|
|
$userMessage .= "__________________\n"; |
452
|
|
|
$userMessage .= "".$xoopsConfig['sitename']." "._MD_LEXIKON_WEBMASTER."\n"; |
453
|
|
|
$userMessage .= "".$xoopsConfig['adminmail'].""; |
454
|
|
|
$xoopsMailer =& getMailer(); |
455
|
|
|
$xoopsMailer->useMail(); |
456
|
|
|
$xoopsMailer->setToEmails($user->getVar('email')); |
457
|
|
|
$xoopsMailer->setFromEmail($xoopsConfig['adminmail']); |
458
|
|
|
//$xoopsMailer->setFromName($xoopsConfig['sitename']." - "._MI_LEXIKON_MD_NAME); |
|
|
|
|
459
|
|
|
$xoopsMailer->setFromName($xoopsConfig['sitename']." - ".$xoopsModule->name()); |
460
|
|
|
if ($request == '1'){ $conf_subject = sprintf(_MD_LEXIKON_SUBJECTREQ,$xoopsConfig['sitename']); |
461
|
|
|
} else { $conf_subject = sprintf(_MD_LEXIKON_SUBJECTSUB,$xoopsConfig['sitename']);} |
462
|
|
|
$xoopsMailer->setSubject($conf_subject); |
463
|
|
|
$xoopsMailer->setBody($userMessage); |
464
|
|
|
$xoopsMailer->send(); |
465
|
|
|
$messagesent = sprintf(_AM_LEXIKON_SENTCONFIRMMAIL,$user->getVar('uname')); |
466
|
|
|
|
467
|
|
|
redirect_header( "entry.php", 1, $messagesent ); |
468
|
|
|
exit(); |
|
|
|
|
469
|
|
|
} |
470
|
|
|
redirect_header( "entry.php", 1, _AM_LEXIKON_ENTRYMODIFIED ); |
|
|
|
|
471
|
|
|
} else { |
472
|
|
|
redirect_header( "index.php", 1, _AM_LEXIKON_ENTRYNOTUPDATED ); |
473
|
|
|
} |
474
|
|
|
} |
475
|
|
|
} |
476
|
|
|
|
477
|
|
|
function entryDelete($entryID = '') { |
|
|
|
|
478
|
|
|
global $xoopsDB, $xoopsModule; |
|
|
|
|
479
|
|
|
$entryID = isset($_POST['entryID']) ? intval($_POST['entryID']) : intval($_GET['entryID']); |
480
|
|
|
$ok = isset($_POST['ok']) ? intval($_POST['ok']) : 0; |
481
|
|
|
$result = $xoopsDB -> query( "SELECT entryID, term, uid FROM " . $xoopsDB -> prefix( "lxentries" ) . " WHERE entryID = $entryID" ); |
482
|
|
|
list( $entryID, $term, $uid ) = $xoopsDB -> fetchrow( $result ); |
483
|
|
|
|
484
|
|
|
// confirmed, so delete |
485
|
|
|
if ( $ok == 1 ) { |
486
|
|
|
$result = $xoopsDB -> query( "DELETE FROM " .$xoopsDB -> prefix("lxentries")." WHERE entryID = $entryID"); |
|
|
|
|
487
|
|
|
xoops_comment_delete( $xoopsModule->getVar('mid'), $entryID ); |
488
|
|
|
// delete notifications |
489
|
|
|
xoops_notification_deletebyitem($xoopsModule->getVar('mid'), 'term', $entryID); |
490
|
|
|
// update user posts |
491
|
|
|
if (!empty($uid)) { |
492
|
|
|
$submitter = new xoopsUser($uid); |
493
|
|
|
$member_handler =& xoops_gethandler('member'); |
494
|
|
|
$member_handler->updateUserByField($submitter, 'posts', $submitter->getVar('posts') - 1); |
495
|
|
|
} |
496
|
|
|
redirect_header("entry.php",1,sprintf( _AM_LEXIKON_ENTRYISDELETED, $term ) ); |
497
|
|
|
exit(); |
|
|
|
|
498
|
|
|
} else { |
499
|
|
|
//xoops_cp_header(); |
500
|
|
|
xoops_confirm(array('op' => 'del', 'entryID' => $entryID, 'ok' => 1, 'term' => $term ), 'entry.php', _AM_LEXIKON_DELETETHISENTRY . "<br /><br>" . $term, _AM_LEXIKON_DELETE ); |
501
|
|
|
xoops_cp_footer(); |
502
|
|
|
} |
503
|
|
|
// break; |
504
|
|
|
exit(); |
|
|
|
|
505
|
|
|
} |
506
|
|
|
|
507
|
|
|
/* -- Available operations -- */ |
508
|
|
|
$op = 'default'; |
509
|
|
View Code Duplication |
if (isset($_POST['op'])) { |
|
|
|
|
510
|
|
|
$op=$_POST['op']; |
511
|
|
|
} else { |
512
|
|
|
if (isset($_GET['op'])) { |
513
|
|
|
$op=$_GET['op']; |
514
|
|
|
} |
515
|
|
|
} |
516
|
|
|
switch ( $op ) { |
517
|
|
|
case "mod": |
518
|
|
|
$entryID = ( isset( $_GET['entryID'] ) ) ? intval($_GET['entryID']) : intval($_POST['entryID']); |
519
|
|
|
entryEdit($entryID); |
520
|
|
|
break; |
521
|
|
|
|
522
|
|
|
case "add": |
523
|
|
|
entryEdit(); |
524
|
|
|
break; |
525
|
|
|
|
526
|
|
|
case "addentry": |
527
|
|
|
entrySave(); |
528
|
|
|
break; |
529
|
|
|
|
530
|
|
|
case "del": |
531
|
|
|
entryDelete(); |
532
|
|
|
break;// |
533
|
|
|
|
534
|
|
|
case "default": |
535
|
|
|
default: |
536
|
|
|
entryDefault(); |
537
|
|
|
break; |
538
|
|
|
} |
539
|
|
|
xoops_cp_footer(); |
540
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.