OSDN Git Service

merged 3.3 beta1
[nucleus-jp/nucleus-jp-ancient.git] / utf8 / nucleus / libs / ADMIN.php
1 <?php
2 /*
3  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4  * Copyright (C) 2002-2006 The Nucleus Group
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  * (see nucleus/documentation/index.html#license for more info)
11  */
12 /**
13  * The code for the Nucleus admin area
14  *
15  * @license http://nucleuscms.org/license.txt GNU General Public License
16  * @copyright Copyright (C) 2002-2006 The Nucleus Group
17  * @version $Id: ADMIN.php,v 1.7 2006-07-12 07:11:47 kimitake Exp $
18  */
19
20 class ADMIN {
21
22         // action currently being executed ($action=xxxx -> action_xxxx method)
23         var $action;
24
25         function ADMIN() {
26
27         }
28
29         /**
30           * Executes an action
31           *
32           * @param $action
33           *             action to be performed
34           */
35         function action($action) {
36                 global $CONF, $manager;
37
38                 // list of action aliases
39                 $alias = array(
40                         'login' => 'overview',
41                         '' => 'overview'
42                 );
43
44                 if ($alias[$action])
45                         $action = $alias[$action];
46
47                 $methodName = 'action_' . $action;
48
49                 $this->action = strtolower($action);
50
51                 // check ticket. All actions need a ticket, unless they are considered to be safe (a safe action
52                 // is an action that requires user interaction before something is actually done)
53                 // all safe actions are in this array:
54                 $aActionsNotToCheck = array('showlogin', 'login', 'overview', 'itemlist', 'blogcommentlist', 'bookmarklet', 'blogsettings', 'banlist', 'deleteblog', 'editmembersettings', 'browseownitems', 'browseowncomments', 'createitem', 'itemedit', 'itemmove', 'categoryedit', 'categorydelete', 'manage', 'actionlog', 'settingsedit', 'backupoverview', 'pluginlist', 'createnewlog', 'usermanagement', 'skinoverview', 'templateoverview', 'skinieoverview', 'itemcommentlist', 'commentedit', 'commentdelete', 'banlistnewfromitem', 'banlistdelete', 'itemdelete', 'manageteam', 'teamdelete', 'banlistnew', 'memberedit', 'memberdelete', 'pluginhelp', 'pluginoptions', 'plugindelete', 'skinedittype', 'skindelete', 'skinedit', 'templateedit', 'templatedelete', 'activate');
55 /*
56                 // the rest of the actions needs to be checked
57                 $aActionsToCheck = array('additem', 'itemupdate', 'itemmoveto', 'categoryupdate', 'categorydeleteconfirm', 'itemdeleteconfirm', 'commentdeleteconfirm', 'teamdeleteconfirm', 'memberdeleteconfirm', 'templatedeleteconfirm', 'skindeleteconfirm', 'banlistdeleteconfirm', 'plugindeleteconfirm', 'batchitem', 'batchcomment', 'batchmember', 'batchcategory', 'batchteam', 'regfile', 'commentupdate', 'banlistadd', 'changemembersettings', 'clearactionlog', 'settingsupdate', 'blogsettingsupdate', 'categorynew', 'teamchangeadmin', 'teamaddmember', 'memberadd', 'addnewlog', 'addnewlog2', 'backupcreate', 'backuprestore', 'pluginup', 'plugindown', 'pluginupdate', 'pluginadd', 'pluginoptionsupdate', 'skinupdate', 'skinclone', 'skineditgeneral', 'templateclone', 'templatenew', 'templateupdate', 'skinieimport', 'skinieexport', 'skiniedoimport', 'skinnew', 'deleteblogconfirm', 'sendping', 'rawping', 'activatesetpwd');
58 */
59                 if (!in_array($this->action, $aActionsNotToCheck))
60                 {
61                         if (!$manager->checkTicket())
62                                 $this->error(_ERROR_BADTICKET);
63                 }
64
65                 if (method_exists($this, $methodName))
66                         call_user_func(array(&$this, $methodName));
67                 else
68                         $this->error(_BADACTION . " ($action)");
69
70         }
71
72
73         function action_showlogin() {
74                 global $error;
75                 $this->action_login($error);
76         }
77
78         function action_login($msg = '', $passvars = 1) {
79                 global $member;
80
81                 // skip to overview when allowed
82                 if ($member->isLoggedIn() && $member->canLogin()) {
83                         $this->action_overview();
84                         exit;
85                 }
86
87                 $this->pagehead();
88
89                 echo '<h2>', _LOGIN ,'</h2>';
90                 if ($msg) echo _MESSAGE , ': ', htmlspecialchars($msg);
91                 ?>
92
93                 <form action="index.php" method="post"><p>
94                 <?php echo _LOGIN_NAME?>: <br /><input name="login"  tabindex="10" />
95                 <br />
96                 <?php echo _LOGIN_PASSWORD?>: <br /><input name="password"  tabindex="20" type="password" />
97                 <br />
98                 <input name="action" value="login" type="hidden" />
99                 <br />
100                 <input type="submit" value="<?php echo _LOGIN?>" tabindex="30" />
101                 <br />
102                 <small>
103                         <input type="checkbox" value="1" name="shared" tabindex="40" id="shared" /><label for="shared"><?php echo _LOGIN_SHARED?></label>
104                         <br /><a href="forgotpassword.html"><?php echo _LOGIN_FORGOT?></a>
105                 </small>
106                 <?php                   // pass through vars
107
108                         $oldaction = postVar('oldaction');
109                         if (  ($oldaction != 'logout')  && ($oldaction != 'login')  && $passvars ) {
110                                 passRequestVars();
111                         }
112
113
114                 ?>
115                 </p></form>
116                 <?php           $this->pagefoot();
117         }
118
119
120         /**
121           * provides a screen with the overview of the actions available
122           */
123         function action_overview($msg = '') {
124                 global $member;
125
126                 $this->pagehead();
127
128                 if ($msg)
129                         echo _MESSAGE , ': ', $msg;
130
131                 /* ---- add items ---- */
132                 echo '<h2>' . _OVERVIEW_YRBLOGS . '</h2>';
133
134                 $showAll = requestVar('showall');
135
136                 if (($member->isAdmin()) && ($showAll == 'yes')) {
137                         // Super-Admins have access to all blogs! (no add item support though)
138                         $query =  'SELECT bnumber, bname, 1 as tadmin, burl, bshortname'
139                                    . ' FROM ' . sql_table('blog')
140                                    . ' ORDER BY bname';
141                 } else {
142                         $query =  'SELECT bnumber, bname, tadmin, burl, bshortname'
143                                    . ' FROM ' . sql_table('blog') . ', ' . sql_table('team')
144                                    . ' WHERE tblog=bnumber and tmember=' . $member->getID()
145                                    . ' ORDER BY bname';
146                 }
147                 $template['content'] = 'bloglist';
148                 $template['superadmin'] = $member->isAdmin();
149                 $amount = showlist($query,'table',$template);
150
151                 if (($showAll != 'yes') && ($member->isAdmin())) {
152                         $total = quickQuery('SELECT COUNT(*) as result FROM ' . sql_table('blog'));
153                         if ($total > $amount)
154                                 echo '<p><a href="index.php?action=overview&amp;showall=yes">Show all blogs</a></p>';
155                 }
156
157                 if ($amount == 0)
158                         echo _OVERVIEW_NOBLOGS;
159
160                 if ($amount != 0) {
161                         echo '<h2>' . _OVERVIEW_YRDRAFTS . '</h2>';
162                         $query =  'SELECT ititle, inumber, bshortname'
163                                    . ' FROM ' . sql_table('item'). ', ' . sql_table('blog')
164                                    . ' WHERE iauthor='.$member->getID().' and iblog=bnumber and idraft=1';
165                         $template['content'] = 'draftlist';
166                         $amountdrafts = showlist($query, 'table', $template);
167                         if ($amountdrafts == 0)
168                                 echo _OVERVIEW_NODRAFTS;
169                 }
170
171                 /* ---- user settings ---- */
172                 echo '<h2>' . _OVERVIEW_YRSETTINGS . '</h2>';
173                 echo '<ul>';
174                 echo '<li><a href="index.php?action=editmembersettings">' . _OVERVIEW_EDITSETTINGS. '</a></li>';
175                 echo '<li><a href="index.php?action=browseownitems">' . _OVERVIEW_BROWSEITEMS.'</a></li>';
176                 echo '<li><a href="index.php?action=browseowncomments">'._OVERVIEW_BROWSECOMM.'</a></li>';
177                 echo '</ul>';
178
179                 /* ---- general settings ---- */
180                 if ($member->isAdmin()) {
181                         echo '<h2>' . _OVERVIEW_MANAGEMENT. '</h2>';
182                         echo '<ul>';
183                         echo '<li><a href="index.php?action=manage">',_OVERVIEW_MANAGE,'</a></li>';
184                         echo '</ul>';
185                 }
186
187
188                 $this->pagefoot();
189         }
190
191         // returns a link to a weblog (takes BLOG object as parameter)
192         function bloglink(&$blog) {
193                 return '<a href="'.htmlspecialchars($blog->getURL()).'" title="'._BLOGLIST_TT_VISIT.'">'.$blog->getName() .'</a>';
194         }
195
196         function action_manage($msg = '') {
197                 global $member;
198
199                 $member->isAdmin() or $this->disallow();
200
201                 $this->pagehead();
202
203                 echo '<p><a href="index.php?action=overview">(',_BACKHOME,')</a></p>';
204
205                 if ($msg)
206                         echo '<p>' , _MESSAGE , ': ', $msg , '</p>';
207
208
209                 echo '<h2>' . _MANAGE_GENERAL. '</h2>';
210
211                 echo '<ul>';
212                 echo '<li><a href="index.php?action=createnewlog">'._OVERVIEW_NEWLOG.'</a></li>';
213                 echo '<li><a href="index.php?action=settingsedit">'._OVERVIEW_SETTINGS.'</a></li>';
214                 echo '<li><a href="index.php?action=usermanagement">'._OVERVIEW_MEMBERS.'</a></li>';
215                 echo '<li><a href="index.php?action=actionlog">'._OVERVIEW_VIEWLOG.'</a></li>';
216                 echo '</ul>';
217
218                 echo '<h2>' . _MANAGE_SKINS . '</h2>';
219                 echo '<ul>';
220                 echo '<li><a href="index.php?action=skinoverview">'._OVERVIEW_SKINS.'</a></li>';
221                 echo '<li><a href="index.php?action=templateoverview">'._OVERVIEW_TEMPLATES.'</a></li>';
222                 echo '<li><a href="index.php?action=skinieoverview">'._OVERVIEW_SKINIMPORT.'</a></li>';
223                 echo '</ul>';
224
225                 echo '<h2>' . _MANAGE_EXTRA . '</h2>';
226                 echo '<ul>';
227                 echo '<li><a href="index.php?action=backupoverview">'._OVERVIEW_BACKUP.'</a></li>';
228                 echo '<li><a href="index.php?action=pluginlist">'._OVERVIEW_PLUGINS.'</a></li>';
229                 echo '</ul>';
230
231                 $this->pagefoot();
232         }
233
234         function action_itemlist($blogid = '') {
235                 global $member, $manager;
236
237                 if ($blogid == '')
238                         $blogid = intRequestVar('blogid');
239
240                 $member->teamRights($blogid) or $member->isAdmin() or $this->disallow();
241
242                 $this->pagehead();
243                 $blog =& $manager->getBlog($blogid);
244
245                 echo '<p><a href="index.php?action=overview">(',_BACKHOME,')</a></p>';
246                 echo '<h2>' . _ITEMLIST_BLOG . ' ' . $this->bloglink($blog) . '</h2>';
247
248                 // start index
249                 if (postVar('start'))
250                         $start = intPostVar('start');
251                 else
252                         $start = 0;
253
254                 if ($start == 0)
255                         echo '<p><a href="index.php?action=createitem&amp;blogid='.$blogid.'">',_ITEMLIST_ADDNEW,'</a></p>';
256
257                 // amount of items to show
258                 if (postVar('amount'))
259                         $amount = intPostVar('amount');
260                 else
261                         $amount = 10;
262
263                 $search = postVar('search');    // search through items
264
265                 $query =  'SELECT bshortname, cname, mname, ititle, ibody, inumber, idraft, itime'
266                            . ' FROM ' . sql_table('item') . ', ' . sql_table('blog') . ', ' . sql_table('member') . ', ' . sql_table('category')
267                            . ' WHERE iblog=bnumber and iauthor=mnumber and icat=catid and iblog=' . $blogid;
268
269                 if ($search)
270                         $query .= ' and ((ititle LIKE "%' . addslashes($search) . '%") or (ibody LIKE "%' . addslashes($search) . '%") or (imore LIKE "%' . addslashes($search) . '%"))';
271
272                 // non-blog-admins can only edit/delete their own items
273                 if (!$member->blogAdminRights($blogid))
274                         $query .= ' and iauthor=' . $member->getID();
275
276
277                 $query .= ' ORDER BY itime DESC'
278                                 . " LIMIT $start,$amount";
279
280                 $template['content'] = 'itemlist';
281                 $template['now'] = $blog->getCorrectTime(time());
282
283
284                 $navList =& new NAVLIST('itemlist', $start, $amount, 0, 1000, $blogid, $search, 0);
285                 $navList->showBatchList('item',$query,'table',$template);
286
287
288                 $this->pagefoot();
289         }
290
291
292         function action_batchitem() {
293                 global $member, $manager;
294
295                 // check if logged in
296                 $member->isLoggedIn() or $this->disallow();
297
298                 // more precise check will be done for each performed operation
299
300                 // get array of itemids from request
301                 $selected = requestIntArray('batch');
302                 $action = requestVar('batchaction');
303
304                 // Show error when no items were selected
305                 if (!is_array($selected) || sizeof($selected) == 0)
306                         $this->error(_BATCH_NOSELECTION);
307
308                 // On move: when no destination blog/category chosen, show choice now
309                 $destCatid = intRequestVar('destcatid');
310                 if (($action == 'move') && (!$manager->existsCategory($destCatid)))
311                         $this->batchMoveSelectDestination('item',$selected);
312
313                 // On delete: check if confirmation has been given
314                 if (($action == 'delete') && (requestVar('confirmation') != 'yes'))
315                         $this->batchAskDeleteConfirmation('item',$selected);
316
317                 $this->pagehead();
318
319                 echo '<a href="index.php?action=overview">(',_BACKHOME,')</a>';
320                 echo '<h2>',_BATCH_ITEMS,'</h2>';
321                 echo '<p>',_BATCH_EXECUTING,' <b>',htmlspecialchars($action),'</b></p>';
322                 echo '<ul>';
323
324
325                 // walk over all itemids and perform action
326                 foreach ($selected as $itemid) {
327                         $itemid = intval($itemid);
328                         echo '<li>',_BATCH_EXECUTING,' <b>',htmlspecialchars($action),'</b> ',_BATCH_ONITEM,' <b>', $itemid, '</b>...';
329
330                         // perform action, display errors if needed
331                         switch($action) {
332                                 case 'delete':
333                                         $error = $this->deleteOneItem($itemid);
334                                         break;
335                                 case 'move':
336                                         $error = $this->moveOneItem($itemid, $destCatid);
337                                         break;
338                                 default:
339                                         $error = _BATCH_UNKNOWN . $action;
340                         }
341
342                         echo '<b>',($error ? $error : _BATCH_SUCCESS),'</b>';
343                         echo '</li>';
344                 }
345
346                 echo '</ul>';
347                 echo '<b>',_BATCH_DONE,'</b>';
348
349                 $this->pagefoot();
350
351
352         }
353
354         function action_batchcomment() {
355                 global $member;
356
357                 // check if logged in
358                 $member->isLoggedIn() or $this->disallow();
359
360                 // more precise check will be done for each performed operation
361
362                 // get array of itemids from request
363                 $selected = requestIntArray('batch');
364                 $action = requestVar('batchaction');
365
366                 // Show error when no items were selected
367                 if (!is_array($selected) || sizeof($selected) == 0)
368                         $this->error(_BATCH_NOSELECTION);
369
370                 // On delete: check if confirmation has been given
371                 if (($action == 'delete') && (requestVar('confirmation') != 'yes'))
372                         $this->batchAskDeleteConfirmation('comment',$selected);
373
374                 $this->pagehead();
375
376                 echo '<a href="index.php?action=overview">(',_BACKHOME,')</a>';
377                 echo '<h2>',_BATCH_COMMENTS,'</h2>';
378                 echo '<p>',_BATCH_EXECUTING,' <b>',htmlspecialchars($action),'</b></p>';
379                 echo '<ul>';
380
381                 // walk over all itemids and perform action
382                 foreach ($selected as $commentid) {
383                         $commentid = intval($commentid);
384                         echo '<li>',_BATCH_EXECUTING,' <b>',htmlspecialchars($action),'</b> ',_BATCH_ONCOMMENT,' <b>', $commentid, '</b>...';
385
386                         // perform action, display errors if needed
387                         switch($action) {
388                                 case 'delete':
389                                         $error = $this->deleteOneComment($commentid);
390                                         break;
391                                 default:
392                                         $error = _BATCH_UNKNOWN . $action;
393                         }
394
395                         echo '<b>',($error ? $error : _BATCH_SUCCESS),'</b>';
396                         echo '</li>';
397                 }
398
399                 echo '</ul>';
400                 echo '<b>',_BATCH_DONE,'</b>';
401
402                 $this->pagefoot();
403
404
405         }
406
407         function action_batchmember() {
408                 global $member;
409
410                 // check if logged in and admin
411                 ($member->isLoggedIn() && $member->isAdmin()) or $this->disallow();
412
413                 // get array of itemids from request
414                 $selected = requestIntArray('batch');
415                 $action = requestVar('batchaction');
416
417                 // Show error when no members selected
418                 if (!is_array($selected) || sizeof($selected) == 0)
419                         $this->error(_BATCH_NOSELECTION);
420
421                 // On delete: check if confirmation has been given
422                 if (($action == 'delete') && (requestVar('confirmation') != 'yes'))
423                         $this->batchAskDeleteConfirmation('member',$selected);
424
425                 $this->pagehead();
426
427                 echo '<a href="index.php?action=usermanagement">(',_MEMBERS_BACKTOOVERVIEW,')</a>';
428                 echo '<h2>',_BATCH_MEMBERS,'</h2>';
429                 echo '<p>',_BATCH_EXECUTING,' <b>',htmlspecialchars($action),'</b></p>';
430                 echo '<ul>';
431
432                 // walk over all itemids and perform action
433                 foreach ($selected as $memberid) {
434                         $memberid = intval($memberid);
435                         echo '<li>',_BATCH_EXECUTING,' <b>',htmlspecialchars($action),'</b> ',_BATCH_ONMEMBER,' <b>', $memberid, '</b>...';
436
437                         // perform action, display errors if needed
438                         switch($action) {
439                                 case 'delete':
440                                         $error = $this->deleteOneMember($memberid);
441                                         break;
442                                 case 'setadmin':
443                                         // always succeeds
444                                         sql_query('UPDATE ' . sql_table('member') . ' SET madmin=1 WHERE mnumber='.$memberid);
445                                         $error = '';
446                                         break;
447                                 case 'unsetadmin':
448                                         // there should always remain at least one super-admin
449                                         $r = sql_query('SELECT * FROM '.sql_table('member'). ' WHERE madmin=1 and mcanlogin=1');
450                                         if (mysql_num_rows($r) < 2)
451                                                 $error = _ERROR_ATLEASTONEADMIN;
452                                         else
453                                                 sql_query('UPDATE ' . sql_table('member') .' SET madmin=0 WHERE mnumber='.$memberid);
454                                         break;
455                                 default:
456                                         $error = _BATCH_UNKNOWN . $action;
457                         }
458
459                         echo '<b>',($error ? $error : _BATCH_SUCCESS),'</b>';
460                         echo '</li>';
461                 }
462
463                 echo '</ul>';
464                 echo '<b>',_BATCH_DONE,'</b>';
465
466                 $this->pagefoot();
467
468
469         }
470
471
472         function action_batchteam() {
473                 global $member;
474
475                 $blogid = intRequestVar('blogid');
476
477                 // check if logged in and admin
478                 ($member->isLoggedIn() && $member->blogAdminRights($blogid)) or $this->disallow();
479
480                 // get array of itemids from request
481                 $selected = requestIntArray('batch');
482                 $action = requestVar('batchaction');
483
484                 // Show error when no members selected
485                 if (!is_array($selected) || sizeof($selected) == 0)
486                         $this->error(_BATCH_NOSELECTION);
487
488                 // On delete: check if confirmation has been given
489                 if (($action == 'delete') && (requestVar('confirmation') != 'yes'))
490                         $this->batchAskDeleteConfirmation('team',$selected);
491
492                 $this->pagehead();
493
494                 echo '<p><a href="index.php?action=manageteam&amp;blogid=',$blogid,'">(',_BACK,')</a></p>';
495
496                 echo '<h2>',_BATCH_TEAM,'</h2>';
497                 echo '<p>',_BATCH_EXECUTING,' <b>',htmlspecialchars($action),'</b></p>';
498                 echo '<ul>';
499
500                 // walk over all itemids and perform action
501                 foreach ($selected as $memberid) {
502                         $memberid = intval($memberid);
503                         echo '<li>',_BATCH_EXECUTING,' <b>',htmlspecialchars($action),'</b> ',_BATCH_ONTEAM,' <b>', $memberid, '</b>...';
504
505                         // perform action, display errors if needed
506                         switch($action) {
507                                 case 'delete':
508                                         $error = $this->deleteOneTeamMember($blogid, $memberid);
509                                         break;
510                                 case 'setadmin':
511                                         // always succeeds
512                                         sql_query('UPDATE '.sql_table('team').' SET tadmin=1 WHERE tblog='.$blogid.' and tmember='.$memberid);
513                                         $error = '';
514                                         break;
515                                 case 'unsetadmin':
516                                         // there should always remain at least one admin
517                                         $r = sql_query('SELECT * FROM '.sql_table('team').' WHERE tadmin=1 and tblog='.$blogid);
518                                         if (mysql_num_rows($r) < 2)
519                                                 $error = _ERROR_ATLEASTONEBLOGADMIN;
520                                         else
521                                                 sql_query('UPDATE '.sql_table('team').' SET tadmin=0 WHERE tblog='.$blogid.' and tmember='.$memberid);
522                                         break;
523                                 default:
524                                         $error = _BATCH_UNKNOWN . $action;
525                         }
526
527                         echo '<b>',($error ? $error : _BATCH_SUCCESS),'</b>';
528                         echo '</li>';
529                 }
530
531                 echo '</ul>';
532                 echo '<b>',_BATCH_DONE,'</b>';
533
534                 $this->pagefoot();
535
536
537         }
538
539
540
541         function action_batchcategory() {
542                 global $member, $manager;
543
544                 // check if logged in
545                 $member->isLoggedIn() or $this->disallow();
546
547                 // more precise check will be done for each performed operation
548
549                 // get array of itemids from request
550                 $selected = requestIntArray('batch');
551                 $action = requestVar('batchaction');
552
553                 // Show error when no items were selected
554                 if (!is_array($selected) || sizeof($selected) == 0)
555                         $this->error(_BATCH_NOSELECTION);
556
557                 // On move: when no destination blog chosen, show choice now
558                 $destBlogId = intRequestVar('destblogid');
559                 if (($action == 'move') && (!$manager->existsBlogID($destBlogId)))
560                         $this->batchMoveCategorySelectDestination('category',$selected);
561
562                 // On delete: check if confirmation has been given
563                 if (($action == 'delete') && (requestVar('confirmation') != 'yes'))
564                         $this->batchAskDeleteConfirmation('category',$selected);
565
566                 $this->pagehead();
567
568                 echo '<a href="index.php?action=overview">(',_BACKHOME,')</a>';
569                 echo '<h2>',BATCH_CATEGORIES,'</h2>';
570                 echo '<p>',_BATCH_EXECUTING,' <b>',htmlspecialchars($action),'</b></p>';
571                 echo '<ul>';
572
573                 // walk over all itemids and perform action
574                 foreach ($selected as $catid) {
575                         $catid = intval($catid);
576                         echo '<li>',_BATCH_EXECUTING,' <b>',htmlspecialchars($action),'</b> ',_BATCH_ONCATEGORY,' <b>', $catid, '</b>...';
577
578                         // perform action, display errors if needed
579                         switch($action) {
580                                 case 'delete':
581                                         $error = $this->deleteOneCategory($catid);
582                                         break;
583                                 case 'move':
584                                         $error = $this->moveOneCategory($catid, $destBlogId);
585                                         break;
586                                 default:
587                                         $error = _BATCH_UNKNOWN . $action;
588                         }
589
590                         echo '<b>',($error ? 'Error: '.$error : _BATCH_SUCCESS),'</b>';
591                         echo '</li>';
592                 }
593
594                 echo '</ul>';
595                 echo '<b>',_BATCH_DONE,'</b>';
596
597                 $this->pagefoot();
598
599         }
600
601         function batchMoveSelectDestination($type, $ids) {
602                 global $manager;
603                 $this->pagehead();
604                 ?>
605                 <h2><?php echo _MOVE_TITLE?></h2>
606                 <form method="post" action="index.php"><div>
607
608                         <input type="hidden" name="action" value="batch<?php echo $type?>" />
609                         <input type="hidden" name="batchaction" value="move" />
610                         <?php
611                                 $manager->addTicketHidden();
612
613                                 // insert selected item numbers
614                                 $idx = 0;
615                                 foreach ($ids as $id)
616                                         echo '<input type="hidden" name="batch[',($idx++),']" value="',intval($id),'" />';
617
618                                 // show blog/category selection list
619                                 $this->selectBlogCategory('destcatid');
620
621                         ?>
622
623
624                         <input type="submit" value="<?php echo _MOVE_BTN?>" onclick="return checkSubmit();" />
625
626                 </div></form>
627                 <?php           $this->pagefoot();
628                 exit;
629         }
630
631         function batchMoveCategorySelectDestination($type, $ids) {
632                 global $manager;
633                 $this->pagehead();
634                 ?>
635                 <h2><?php echo _MOVECAT_TITLE?></h2>
636                 <form method="post" action="index.php"><div>
637
638                         <input type="hidden" name="action" value="batch<?php echo $type?>" />
639                         <input type="hidden" name="batchaction" value="move" />
640                         <?php
641                                 $manager->addTicketHidden();
642
643                                 // insert selected item numbers
644                                 $idx = 0;
645                                 foreach ($ids as $id)
646                                         echo '<input type="hidden" name="batch[',($idx++),']" value="',intval($id),'" />';
647
648                                 // show blog/category selection list
649                                 $this->selectBlog('destblogid');
650
651                         ?>
652
653
654                         <input type="submit" value="<?php echo _MOVECAT_BTN?>" onclick="return checkSubmit();" />
655
656                 </div></form>
657                 <?php           $this->pagefoot();
658                 exit;
659         }
660
661         function batchAskDeleteConfirmation($type, $ids) {
662                 global $manager;
663
664                 $this->pagehead();
665                 ?>
666                 <h2><?php echo _BATCH_DELETE_CONFIRM?></h2>
667                 <form method="post" action="index.php"><div>
668
669                         <input type="hidden" name="action" value="batch<?php echo $type?>" />
670                         <?php $manager->addTicketHidden() ?>
671                         <input type="hidden" name="batchaction" value="delete" />
672                         <input type="hidden" name="confirmation" value="yes" />
673                         <?php                           // insert selected item numbers
674                                 $idx = 0;
675                                 foreach ($ids as $id)
676                                         echo '<input type="hidden" name="batch[',($idx++),']" value="',intval($id),'" />';
677
678                                 // add hidden vars for team & comment
679                                 if ($type == 'team')
680                                 {
681                                         echo '<input type="hidden" name="blogid" value="',intRequestVar('blogid'),'" />';
682                                 }
683                                 if ($type == 'comment')
684                                 {
685                                         echo '<input type="hidden" name="itemid" value="',intRequestVar('itemid'),'" />';
686                                 }
687
688                         ?>
689
690                         <input type="submit" value="<?php echo _BATCH_DELETE_CONFIRM_BTN?>" onclick="return checkSubmit();" />
691
692                 </div></form>
693                 <?php           $this->pagefoot();
694                 exit;
695         }
696
697
698         /**
699           * Inserts a HTML select element with choices for all categories to which the current
700           * member has access
701           */
702         function selectBlogCategory($name, $selected = 0, $tabindex = 0, $showNewCat = 0, $iForcedBlogInclude = -1) {
703                 ADMIN::selectBlog($name, 'category', $selected, $tabindex, $showNewCat, $iForcedBlogInclude);
704         }
705
706         /**
707           * Inserts a HTML select element with choices for all blogs to which the user has access
708           *             mode = 'blog' => shows blognames and values are blogids
709           *             mode = 'category' => show category names and values are catids
710           *
711           * @param $iForcedBlogInclude
712           *             ID of a blog that always needs to be included, without checking if the member is on the blog team (-1 = none)
713           */
714         function selectBlog($name, $mode='blog', $selected = 0, $tabindex = 0, $showNewCat = 0, $iForcedBlogInclude = -1) {
715                 global $member, $CONF;
716
717                 // 0. get IDs of blogs to which member can post items (+ forced blog)
718                 $aBlogIds = array();
719                 if ($iForcedBlogInclude != -1)
720                         $aBlogIds[] = intval($iForcedBlogInclude);
721
722                 if (($member->isAdmin()) && ($CONF['ShowAllBlogs']))
723                         $queryBlogs =  'SELECT bnumber FROM '.sql_table('blog').' ORDER BY bname';
724                 else
725                         $queryBlogs =  'SELECT bnumber FROM '.sql_table('blog').', '.sql_table('team').' WHERE tblog=bnumber and tmember=' . $member->getID();
726                 $rblogids = sql_query($queryBlogs);
727                 while ($o = mysql_fetch_object($rblogids))
728                         if ($o->bnumber != $iForcedBlogInclude)
729                                 $aBlogIds[] = intval($o->bnumber);
730
731                 if (count($aBlogIds) == 0)
732                         return;
733
734                 echo '<select name="',$name,'" tabindex="',$tabindex,'">';
735
736                 // 1. select blogs (we'll create optiongroups)
737                 // (only select those blogs that have the user on the team)
738                 $queryBlogs =  'SELECT bnumber, bname FROM '.sql_table('blog').' WHERE bnumber in ('.implode(',',$aBlogIds).') ORDER BY bname';
739                 $blogs = sql_query($queryBlogs);
740                 if ($mode == 'category') {
741                         if (mysql_num_rows($blogs) > 1)
742                                 $multipleBlogs = 1;
743
744                         while ($oBlog = mysql_fetch_object($blogs)) {
745                                 if ($multipleBlogs)
746                                         echo '<optgroup label="',htmlspecialchars($oBlog->bname),'">';
747
748                                 // show selection to create new category when allowed/wanted
749                                 if ($showNewCat) {
750                                         // check if allowed to do so
751                                         if ($member->blogAdminRights($oBlog->bnumber))
752                                                 echo '<option value="newcat-',$oBlog->bnumber,'">',_ADD_NEWCAT,'</option>';
753                                 }
754
755                                 // 2. for each category in that blog
756                                 $categories = sql_query('SELECT cname, catid FROM '.sql_table('category').' WHERE cblog=' . $oBlog->bnumber . ' ORDER BY cname ASC');
757                                 while ($oCat = mysql_fetch_object($categories)) {
758                                         if ($oCat->catid == $selected)
759                                                 $selectText = ' selected="selected" ';
760                                         else
761                                                 $selectText = '';
762                                         echo '<option value="',$oCat->catid,'" ', $selectText,'>',htmlspecialchars($oCat->cname),'</option>';
763                                 }
764
765                                 if ($multipleBlogs)
766                                         echo '</optgroup>';
767                         }
768                 } else {
769                         // blog mode
770                         while ($oBlog = mysql_fetch_object($blogs)) {
771                                 echo '<option value="',$oBlog->bnumber,'"';
772                                 if ($oBlog->bnumber == $selected)
773                                         echo ' selected="selected"';
774                                 echo'>',htmlspecialchars($oBlog->bname),'</option>';
775                         }
776                 }
777                 echo '</select>';
778
779         }
780
781         function action_browseownitems() {
782                 global $member;
783
784                 $this->pagehead();
785
786                 echo '<p><a href="index.php?action=overview">(',_BACKHOME,')</a></p>';
787                 echo '<h2>' . _ITEMLIST_YOUR. '</h2>';
788
789                 // start index
790                 if (postVar('start'))
791                         $start = postVar('start');
792                 else
793                         $start = 0;
794
795                 // amount of items to show
796                 if (postVar('amount'))
797                         $amount = postVar('amount');
798                 else
799                         $amount = 10;
800
801                 $search = postVar('search');    // search through items
802
803                 $query =  'SELECT bshortname, cname, mname, ititle, ibody, idraft, inumber, itime'
804                            . ' FROM '.sql_table('item').', '.sql_table('blog') . ', '.sql_table('member') . ', '.sql_table('category')
805                            . ' WHERE iauthor='. $member->getID() .' and iauthor=mnumber and iblog=bnumber and icat=catid';
806
807                 if ($search)
808                         $query .= ' and ((ititle LIKE "%' . addslashes($search) . '%") or (ibody LIKE "%' . addslashes($search) . '%") or (imore LIKE "%' . addslashes($search) . '%"))';
809
810                 $query .= ' ORDER BY itime DESC'
811                                 . " LIMIT $start,$amount";
812
813                 $template['content'] = 'itemlist';
814                 $template['now'] = time();
815
816                 $navList =& new NAVLIST('browseownitems', $start, $amount, 0, 1000, $blogid, $search, 0);
817                 $navList->showBatchList('item',$query,'table',$template);
818
819                 $this->pagefoot();
820
821         }
822
823         /**
824           * Show all the comments for a given item
825           */
826         function action_itemcommentlist($itemid = '') {
827                 global $member;
828
829                 if ($itemid == '')
830                         $itemid = intRequestVar('itemid');
831
832                 // only allow if user is allowed to alter item
833                 $member->canAlterItem($itemid) or $this->disallow();
834
835                 $blogid = getBlogIdFromItemId($itemid);
836
837                 $this->pagehead();
838
839                 // start index
840                 if (postVar('start'))
841                         $start = postVar('start');
842                 else
843                         $start = 0;
844
845                 // amount of items to show
846                 if (postVar('amount'))
847                         $amount = postVar('amount');
848                 else
849                         $amount = 10;
850
851                 $search = postVar('search');
852
853                 echo '<p>(<a href="index.php?action=itemlist&amp;blogid=',$blogid,'">',_BACKTOOVERVIEW,'</a>)</p>';
854                 echo '<h2>',_COMMENTS,'</h2>';
855
856                 $query =  'SELECT cbody, cuser, cmail, mname, ctime, chost, cnumber, cip, citem FROM '.sql_table('comment').' LEFT OUTER JOIN '.sql_table('member').' ON mnumber=cmember WHERE citem=' . $itemid;
857
858                 if ($search)
859                         $query .= ' and cbody LIKE "%' . addslashes($search) . '%"';
860
861                 $query .= ' ORDER BY ctime ASC'
862                                 . " LIMIT $start,$amount";
863
864                 $template['content'] = 'commentlist';
865                 $template['canAddBan'] = $member->blogAdminRights(getBlogIDFromItemID($itemid));
866
867                 $navList =& new NAVLIST('itemcommentlist', $start, $amount, 0, 1000, 0, $search, $itemid);
868                 $navList->showBatchList('comment',$query,'table',$template,_NOCOMMENTS);
869
870                 $this->pagefoot();
871         }
872
873         /**
874           * Browse own comments
875           */
876         function action_browseowncomments() {
877                 global $member;
878
879                 // start index
880                 if (postVar('start'))
881                         $start = postVar('start');
882                 else
883                         $start = 0;
884
885                 // amount of items to show
886                 if (postVar('amount'))
887                         $amount = postVar('amount');
888                 else
889                         $amount = 10;
890
891                 $search = postVar('search');
892
893
894                 $query =  'SELECT cbody, cuser, cmail, mname, ctime, chost, cnumber, cip, citem FROM '.sql_table('comment').' LEFT OUTER JOIN '.sql_table('member').' ON mnumber=cmember WHERE cmember=' . $member->getID();
895
896                 if ($search)
897                         $query .= ' and cbody LIKE "%' . addslashes($search) . '%"';
898
899                 $query .= ' ORDER BY ctime DESC'
900                                 . " LIMIT $start,$amount";
901
902                 $this->pagehead();
903
904                 echo '<p><a href="index.php?action=overview">(',_BACKHOME,')</a></p>';
905                 echo '<h2>', _COMMENTS_YOUR ,'</h2>';
906
907                 $template['content'] = 'commentlist';
908                 $template['canAddBan'] = 0;     // doesn't make sense to allow banning yourself
909
910                 $navList =& new NAVLIST('browseowncomments', $start, $amount, 0, 1000, 0, $search, 0);
911                 $navList->showBatchList('comment',$query,'table',$template,_NOCOMMENTS_YOUR);
912
913                 $this->pagefoot();
914         }
915
916         /**
917           * Browse all comments for a weblog
918           */
919         function action_blogcommentlist($blogid = '')
920         {
921                 global $member, $manager;
922
923                 if ($blogid == '')
924                         $blogid = intRequestVar('blogid');
925                 else
926                         $blogid = intval($blogid);
927
928                 $member->teamRights($blogid) or $member->isAdmin() or $this->disallow();
929
930                 // start index
931                 if (postVar('start'))
932                         $start = postVar('start');
933                 else
934                         $start = 0;
935
936                 // amount of items to show
937                 if (postVar('amount'))
938                         $amount = postVar('amount');
939                 else
940                         $amount = 10;
941
942                 $search = postVar('search');            // search through comments
943
944
945                 $query =  'SELECT cbody, cuser, cmail, mname, ctime, chost, cnumber, cip, citem FROM '.sql_table('comment').' LEFT OUTER JOIN '.sql_table('member').' ON mnumber=cmember WHERE cblog=' . intval($blogid);
946
947                 if ($search != '')
948                         $query .= ' and cbody LIKE "%' . addslashes($search) . '%"';
949
950
951                 $query .= ' ORDER BY ctime DESC'
952                                 . " LIMIT $start,$amount";
953
954
955                 $blog =& $manager->getBlog($blogid);
956
957                 $this->pagehead();
958
959                 echo '<p><a href="index.php?action=overview">(',_BACKHOME,')</a></p>';
960                 echo '<h2>', _COMMENTS_BLOG , ' ' , $this->bloglink($blog), '</h2>';
961
962                 $template['content'] = 'commentlist';
963                 $template['canAddBan'] = $member->blogAdminRights($blogid);
964
965                 $navList =& new NAVLIST('blogcommentlist', $start, $amount, 0, 1000, $blogid, $search, 0);
966                 $navList->showBatchList('comment',$query,'table',$template, _NOCOMMENTS_BLOG);
967
968                 $this->pagefoot();
969         }
970
971         /**
972           * Provide a page to item a new item to the given blog
973           */
974         function action_createitem() {
975                 global $member, $manager;
976
977                 $blogid = intRequestVar('blogid');
978
979                 // check if allowed
980                 $member->teamRights($blogid) or $this->disallow();
981
982                 $memberid = $member->getID();
983
984                 $blog =& $manager->getBlog($blogid);
985
986                 $this->pagehead();
987
988                 // generate the add-item form
989                 $formfactory =& new PAGEFACTORY($blogid);
990                 $formfactory->createAddForm('admin');
991
992                 $this->pagefoot();
993         }
994
995         function action_itemedit() {
996                 global $member, $manager;
997
998                 $itemid = intRequestVar('itemid');
999
1000                 // only allow if user is allowed to alter item
1001                 $member->canAlterItem($itemid) or $this->disallow();
1002
1003                 $item =& $manager->getItem($itemid,1,1);
1004                 $blog =& $manager->getBlog(getBlogIDFromItemID($itemid));
1005
1006                 $manager->notify('PrepareItemForEdit', array('item' => &$item));
1007
1008                 if ($blog->convertBreaks()) {
1009                         $item['body'] = removeBreaks($item['body']);
1010                         $item['more'] = removeBreaks($item['more']);
1011                 }
1012
1013                 // form to edit blog items
1014                 $this->pagehead();
1015                 $formfactory =& new PAGEFACTORY($blog->getID());
1016                 $formfactory->createEditForm('admin',$item);
1017                 $this->pagefoot();
1018         }
1019
1020         function action_itemupdate() {
1021                 global $member, $manager, $CONF;
1022
1023                 $itemid = intRequestVar('itemid');
1024                 $catid = postVar('catid');
1025
1026                 // only allow if user is allowed to alter item
1027                 $member->canUpdateItem($itemid, $catid) or $this->disallow();
1028
1029                 $actiontype = postVar('actiontype');
1030
1031                 // delete actions are handled by itemdelete (which has confirmation)
1032                 if ($actiontype == 'delete') {
1033                         $this->action_itemdelete();
1034                         return;
1035                 }
1036
1037                 $body   = postVar('body');
1038                 $title  = postVar('title');
1039                 $more   = postVar('more');
1040                 $closed = intPostVar('closed');
1041
1042                 // default action = add now
1043                 if (!$actiontype)
1044                         $actiontype='addnow';
1045
1046                 // create new category if needed
1047                 if (strstr($catid,'newcat')) {
1048                         // get blogid
1049                         list($blogid) = sscanf($catid,"newcat-%d");
1050
1051                         // create
1052                         $blog =& $manager->getBlog($blogid);
1053                         $catid = $blog->createNewCategory();
1054
1055                         // show error when sth goes wrong
1056                         if (!$catid)
1057                                 $this->doError(_ERROR_CATCREATEFAIL);
1058                 }
1059
1060                 /*
1061                         set some variables based on actiontype
1062
1063                         actiontypes:
1064                                 draft items -> addnow, addfuture, adddraft, delete
1065                                 non-draft items -> edit, changedate, delete
1066
1067                         variables set:
1068                                 $timestamp: set to a nonzero value for future dates or date changes
1069                                 $wasdraft: set to 1 when the item used to be a draft item
1070                                 $publish: set to 1 when the edited item is not a draft
1071                 */
1072                 switch ($actiontype) {
1073                         case 'adddraft':
1074                                 $publish = 0;
1075                                 $wasdraft = 1;
1076                                 $timestamp = 0;
1077                                 break;
1078                         case 'addfuture':
1079                                 $wasdraft = 1;
1080                                 $publish = 1;
1081                                 $timestamp = mktime(postVar('hour'), postVar('minutes'), 0, postVar('month'), postVar('day'), postVar('year'));
1082                                 break;
1083                         case 'addnow':
1084                                 $wasdraft = 1;
1085                                 $publish = 1;
1086                                 $timestamp = 0;
1087                                 break;
1088                         case 'changedate':
1089                                 $timestamp = mktime(postVar('hour'), postVar('minutes'), 0, postVar('month'), postVar('day'), postVar('year'));
1090                                 $publish = 1;
1091                                 $wasdraft = 0;
1092                                 break;
1093                         case 'edit':
1094                         default:
1095                                 $publish = 1;
1096                                 $wasdraft = 0;
1097                                 $timestamp = 0;
1098                 }
1099
1100                 // edit the item for real
1101                 ITEM::update($itemid, $catid, $title, $body, $more, $closed, $wasdraft, $publish, $timestamp);
1102
1103                 $blogid = getBlogIDFromItemID($itemid);
1104                 $blog =& $manager->getBlog($blogid);
1105                 if (!$closed && $publish && $wasdraft && $blog->pingUserland()) {
1106                         $this->action_sendping($blogid);
1107                         return;
1108                 }
1109
1110                 // show category edit window when we created a new category
1111                 // ($catid will then be a new category ID, while postVar('catid') will be 'newcat-x')
1112                 if ($catid != intPostVar('catid')) {
1113                         $this->action_categoryedit(
1114                                 $catid,
1115                                 $blog->getID(),
1116                                 $CONF['AdminURL'] . 'index.php?action=itemlist&blogid=' . getBlogIDFromItemID($itemid)
1117                         );
1118                 } else {
1119                         // TODO: set start item correctly for itemlist
1120                         $this->action_itemlist(getBlogIDFromItemID($itemid));
1121                 }
1122         }
1123
1124         function action_itemdelete() {
1125                 global $member, $manager;
1126
1127                 $itemid = intRequestVar('itemid');
1128
1129                 // only allow if user is allowed to alter item
1130                 $member->canAlterItem($itemid) or $this->disallow();
1131
1132                 if (!$manager->existsItem($itemid,1,1))
1133                         $this->error(_ERROR_NOSUCHITEM);
1134
1135                 $item =& $manager->getItem($itemid,1,1);
1136                 $title = htmlspecialchars(strip_tags($item['title']));
1137                 $body = strip_tags($item['body']);
1138                 $body = htmlspecialchars(shorten($body,300,'...'));
1139
1140                 $this->pagehead();
1141                 ?>
1142                         <h2><?php echo _DELETE_CONFIRM?></h2>
1143
1144                         <p><?php echo _CONFIRMTXT_ITEM?></p>
1145
1146                         <div class="note">
1147                                 <b>"<?php echo  $title ?>"</b>
1148                                 <br />
1149                                 <?php echo $body?>
1150                         </div>
1151
1152                         <form method="post" action="index.php"><div>
1153                                 <input type="hidden" name="action" value="itemdeleteconfirm" />
1154                                 <?php $manager->addTicketHidden() ?>
1155                                 <input type="hidden" name="itemid" value="<?php echo  $itemid; ?>" />
1156                                 <input type="submit" value="<?php echo _DELETE_CONFIRM_BTN?>"  tabindex="10" />
1157                         </div></form>
1158                 <?php
1159                 $this->pagefoot();
1160         }
1161
1162         function action_itemdeleteconfirm() {
1163                 global $member;
1164
1165                 $itemid = intRequestVar('itemid');
1166
1167                 // only allow if user is allowed to alter item
1168                 $member->canAlterItem($itemid) or $this->disallow();
1169
1170                 // get blogid first
1171                 $blogid = getBlogIdFromItemId($itemid);
1172
1173                 // delete item (note: some checks will be performed twice)
1174                 $this->deleteOneItem($itemid);
1175
1176                 $this->action_itemlist($blogid);
1177         }
1178
1179         // deletes one item and returns error if something goes wrong
1180         function deleteOneItem($itemid) {
1181                 global $member, $manager;
1182
1183                 // only allow if user is allowed to alter item (also checks if itemid exists)
1184                 if (!$member->canAlterItem($itemid))
1185                         return _ERROR_DISALLOWED;
1186
1187                 $manager->loadClass('ITEM');
1188                 ITEM::delete($itemid);
1189         }
1190
1191         function action_itemmove() {
1192                 global $member, $manager;
1193
1194                 $itemid = intRequestVar('itemid');
1195
1196                 // only allow if user is allowed to alter item
1197                 $member->canAlterItem($itemid) or $this->disallow();
1198
1199                 $item =& $manager->getItem($itemid,1,1);
1200
1201                 $this->pagehead();
1202                 ?>
1203                         <h2><?php echo _MOVE_TITLE?></h2>
1204                         <form method="post" action="index.php"><div>
1205                                 <input type="hidden" name="action" value="itemmoveto" />
1206                                 <input type="hidden" name="itemid" value="<?php echo  $itemid; ?>" />
1207
1208                                 <?php
1209
1210                                         $manager->addTicketHidden();
1211                                         $this->selectBlogCategory('catid',$item['catid'],10,1);
1212                                 ?>
1213
1214                                 <input type="submit" value="<?php echo _MOVE_BTN?>" tabindex="10000" onclick="return checkSubmit();" />
1215                         </div></form>
1216                 <?php
1217                 $this->pagefoot();
1218         }
1219
1220         function action_itemmoveto() {
1221                 global $member, $manager;
1222
1223                 $itemid = intRequestVar('itemid');
1224                 $catid = requestVar('catid');
1225
1226                 // create new category if needed
1227                 if (strstr($catid,'newcat')) {
1228                         // get blogid
1229                         list($blogid) = sscanf($catid,'newcat-%d');
1230
1231                         // create
1232                         $blog =& $manager->getBlog($blogid);
1233                         $catid = $blog->createNewCategory();
1234
1235                         // show error when sth goes wrong
1236                         if (!$catid)
1237                                 $this->doError(_ERROR_CATCREATEFAIL);
1238                 }
1239
1240                 // only allow if user is allowed to alter item
1241                 $member->canUpdateItem($itemid, $catid) or $this->disallow();
1242
1243                 ITEM::move($itemid, $catid);
1244
1245                 if ($catid != intRequestVar('catid'))
1246                         $this->action_categoryedit($catid, $blog->getID());
1247                 else
1248                         $this->action_itemlist(getBlogIDFromCatID($catid));
1249         }
1250
1251         /**
1252           * Moves one item to a given category (category existance should be checked by caller)
1253           * errors are returned
1254           */
1255         function moveOneItem($itemid, $destCatid) {
1256                 global $member;
1257
1258                 // only allow if user is allowed to move item
1259                 if (!$member->canUpdateItem($itemid, $destCatid))
1260                         return _ERROR_DISALLOWED;
1261
1262                 ITEM::move($itemid, $destCatid);
1263         }
1264
1265         /**
1266           * Adds a item to the chosen blog
1267           */
1268         function action_additem() {
1269                 global $member, $manager, $CONF;
1270
1271                 $manager->loadClass('ITEM');
1272
1273                 $result = ITEM::createFromRequest();
1274
1275                 if ($result['status'] == 'error')
1276                         $this->error($result['message']);
1277
1278                 $blogid = getBlogIDFromItemID($result['itemid']);
1279                 $blog =& $manager->getBlog($blogid);
1280
1281                 $pingUrl = $manager->addTicketToUrl($CONF['AdminURL'] . 'index.php?action=sendping&blogid=' . intval($blogid));
1282
1283                 if ($result['status'] == 'newcategory')
1284                         $this->action_categoryedit(
1285                                 $result['catid'],
1286                                 $blogid,
1287                                 $blog->pingUserland() ? $pingUrl : ''
1288                         );
1289                 elseif ((postVar('actiontype') == 'addnow') && $blog->pingUserland())
1290                         $this->action_sendping($blogid);
1291                 else
1292                         $this->action_itemlist($blogid);
1293         }
1294
1295         /**
1296           * Shows a window that says we're about to ping weblogs.com.
1297           * immediately refresh to the real pinging page, which will
1298           * show an error, or redirect to the blog.
1299           *
1300           * @param $blogid ID of blog for which ping needs to be sent out
1301           */
1302         function action_sendping($blogid = -1) {
1303                 global $member, $manager;
1304
1305                 if ($blogid == -1)
1306                         $blogid = intRequestVar('blogid');
1307
1308                 $member->isLoggedIn() or $this->disallow();
1309
1310                 $rawPingUrl = $manager->addTicketToUrl('index.php?action=rawping&blogid=' . intval($blogid));
1311
1312                 $this->pagehead('<meta http-equiv="refresh" content="1; url='.htmlspecialchars($rawPingUrl).'" />');
1313                 ?>
1314                 <h2>Site Updated, Now pinging weblogs.com</h2>
1315
1316                 <p>
1317                         Pinging weblogs.com! This can a while...
1318                         <br />
1319                         When the ping is complete (and successfull), your weblog will show up in the weblogs.com updates list.
1320                 </p>
1321
1322                 <p>
1323                         If you aren't automatically passed through, <a href="index.php?action=rawping&amp;blogid=<?php echo $blogid?>">try again</a>
1324                 </p>
1325                 <?php           $this->pagefoot();
1326         }
1327
1328         // ping to Weblogs.com
1329         // sends the real ping (can take up to 10 seconds!)
1330         function action_rawping() {
1331                 global $manager;
1332                 // TODO: checks?
1333
1334                 $blogid = intRequestVar('blogid');
1335                 $blog =& $manager->getBlog($blogid);
1336
1337                 $result = $blog->sendUserlandPing();
1338
1339                 $this->pagehead();
1340
1341                 ?>
1342
1343                 <h2>Ping Results</h2>
1344
1345                 <p>The following message was returned by weblogs.com:</p>
1346
1347                 <div class='note'><?php echo  $result ?></div>
1348
1349                 <ul>
1350                         <li><a href="index.php?action=itemlist&amp;blogid=<?php echo $blog->getID()?>">View list of recent items for <?php echo htmlspecialchars($blog->getName())?></a></li>
1351                         <li><a href="<?php echo $blog->getURL()?>">Visit your own site</a></li>
1352                 </ul>
1353
1354                 <?php           $this->pagefoot();
1355         }
1356
1357         /**
1358           * Allows to edit previously made comments
1359           */
1360         function action_commentedit() {
1361                 global $member, $manager;
1362
1363                 $commentid = intRequestVar('commentid');
1364
1365                 $member->canAlterComment($commentid) or $this->disallow();
1366
1367                 $comment = COMMENT::getComment($commentid);
1368
1369                 $manager->notify('PrepareCommentForEdit',array('comment' => &$comment));
1370
1371                 // change <br /> to \n
1372                 $comment['body'] = str_replace('<br />','',$comment['body']);
1373
1374                 $comment['body'] = eregi_replace("<a href=['\"]([^'\"]+)['\"]( rel=\"nofollow\")?>[^<]*</a>","\\1",$comment['body']);
1375
1376                 $this->pagehead();
1377
1378                 ?>
1379                 <h2><?php echo _EDITC_TITLE?></h2>
1380
1381                 <form action="index.php" method="post"><div>
1382
1383                 <input type="hidden" name="action" value="commentupdate" />
1384                 <?php $manager->addTicketHidden(); ?>
1385                 <input type="hidden" name="commentid" value="<?php echo  $commentid; ?>" />
1386                 <table><tr>
1387                         <th colspan="2"><?php echo _EDITC_TITLE?></th>
1388                 </tr><tr>
1389                         <td><?php echo _EDITC_WHO?></td>
1390                         <td>
1391                         <?php                           if ($comment['member'])
1392                                         echo $comment['member'] . " (" . _EDITC_MEMBER . ")";
1393                                 else
1394                                         echo $comment['user'] . " (" . _EDITC_NONMEMBER . ")";
1395                         ?>
1396                         </td>
1397                 </tr><tr>
1398                         <td><?php echo _EDITC_WHEN?></td>
1399                         <td><?php echo  date("Y-m-d @ H:i",$comment['timestamp']); ?></td>
1400                 </tr><tr>
1401                         <td><?php echo _EDITC_HOST?></td>
1402                         <td><?php echo  $comment['host']; ?></td>
1403                 </tr><tr>
1404                         <td><?php echo _EDITC_TEXT?></td>
1405                         <td>
1406                                 <textarea name="body" tabindex="10" rows="10" cols="50"><?php                                   // htmlspecialchars not needed (things should be escaped already)
1407                                         echo $comment['body'];
1408                                 ?></textarea>
1409                         </td>
1410                 </tr><tr>
1411                         <td><?php echo _EDITC_EDIT?></td>
1412                         <td><input type="submit"  tabindex="20" value="<?php echo _EDITC_EDIT?>" onclick="return checkSubmit();" /></td>
1413                 </tr></table>
1414
1415                 </div></form>
1416                 <?php
1417                 $this->pagefoot();
1418         }
1419
1420         function action_commentupdate() {
1421                 global $member, $manager;
1422
1423                 $commentid = intRequestVar('commentid');
1424
1425                 $member->canAlterComment($commentid) or $this->disallow();
1426
1427                 $body = postVar('body');
1428
1429                 // intercept words that are too long
1430                 if (eregi("[a-zA-Z0-9|\.,;:!\?=\/\\]{90,90}",$body) != false)
1431                         $this->error(_ERROR_COMMENT_LONGWORD);
1432
1433                 // check length
1434                 if (strlen($body)<3)
1435                         $this->error(_ERROR_COMMENT_NOCOMMENT);
1436                 if (strlen($body)>5000)
1437                         $this->error(_ERROR_COMMENT_TOOLONG);
1438
1439
1440                 // prepare body
1441                 $body = COMMENT::prepareBody($body);
1442
1443                 // call plugins
1444                 $manager->notify('PreUpdateComment',array('body' => &$body));
1445
1446                 $query =  'UPDATE '.sql_table('comment')
1447                            . " SET cbody='" .addslashes($body). "'"
1448                            . " WHERE cnumber=" . $commentid;
1449                 sql_query($query);
1450
1451                 // get itemid
1452                 $res = sql_query('SELECT citem FROM '.sql_table('comment').' WHERE cnumber=' . $commentid);
1453                 $o = mysql_fetch_object($res);
1454                 $itemid = $o->citem;
1455
1456                 if ($member->canAlterItem($itemid))
1457                         $this->action_itemcommentlist($itemid);
1458                 else
1459                         $this->action_browseowncomments();
1460
1461         }
1462
1463         function action_commentdelete() {
1464                 global $member, $manager;
1465
1466                 $commentid = intRequestVar('commentid');
1467
1468                 $member->canAlterComment($commentid) or $this->disallow();
1469
1470                 $comment = COMMENT::getComment($commentid);
1471
1472                 $body = strip_tags($comment['body']);
1473                 $body = htmlspecialchars(shorten($body, 300, '...'));
1474
1475                 if ($comment['member'])
1476                         $author = $comment['member'];
1477                 else
1478                         $author = $comment['user'];
1479
1480                 $this->pagehead();
1481                 ?>
1482
1483                         <h2><?php echo _DELETE_CONFIRM?></h2>
1484
1485                         <p><?php echo _CONFIRMTXT_COMMENT?></p>
1486
1487                         <div class="note">
1488                         <b><?php echo _EDITC_WHO?>:</b> <?php echo  $author ?>
1489                         <br />
1490                         <b><?php echo _EDITC_TEXT?>:</b> <?php echo  $body ?>
1491                         </div>
1492
1493                         <form method="post" action="index.php"><div>
1494                                 <input type="hidden" name="action" value="commentdeleteconfirm" />
1495                                 <?php $manager->addTicketHidden() ?>
1496                                 <input type="hidden" name="commentid" value="<?php echo  $commentid; ?>" />
1497                                 <input type="submit" tabindex="10" value="<?php echo _DELETE_CONFIRM_BTN?>" />
1498                         </div></form>
1499                 <?php
1500                 $this->pagefoot();
1501         }
1502
1503         function action_commentdeleteconfirm() {
1504                 global $member;
1505
1506                 $commentid = intRequestVar('commentid');
1507
1508                 // get item id first
1509                 $res = sql_query('SELECT citem FROM '.sql_table('comment') .' WHERE cnumber=' . $commentid);
1510                 $o = mysql_fetch_object($res);
1511                 $itemid = $o->citem;
1512
1513                 $error = $this->deleteOneComment($commentid);
1514                 if ($error)
1515                         $this->doError($error);
1516
1517                 if ($member->canAlterItem($itemid))
1518                         $this->action_itemcommentlist($itemid);
1519                 else
1520                         $this->action_browseowncomments();
1521         }
1522
1523         function deleteOneComment($commentid) {
1524                 global $member, $manager;
1525
1526                 $commentid = intval($commentid);
1527
1528                 if (!$member->canAlterComment($commentid))
1529                         return _ERROR_DISALLOWED;
1530
1531                 $manager->notify('PreDeleteComment', array('commentid' => $commentid));
1532
1533                 // delete the comments associated with the item
1534                 $query = 'DELETE FROM '.sql_table('comment').' WHERE cnumber=' . $commentid;
1535                 sql_query($query);
1536
1537                 $manager->notify('PostDeleteComment', array('commentid' => $commentid));
1538
1539                 return '';
1540         }
1541
1542         /**
1543           * Usermanagement main
1544           */
1545         function action_usermanagement() {
1546                 global $member, $manager;
1547
1548                 // check if allowed
1549                 $member->isAdmin() or $this->disallow();
1550
1551                 $this->pagehead();
1552
1553                 echo '<p><a href="index.php?action=manage">(',_BACKTOMANAGE,')</a></p>';
1554
1555                 echo '<h2>' . _MEMBERS_TITLE .'</h2>';
1556
1557                 echo '<h3>' . _MEMBERS_CURRENT .'</h3>';
1558
1559                 // show list of members with actions
1560                 $query =  'SELECT *'
1561                            . ' FROM '.sql_table('member');
1562                 $template['content'] = 'memberlist';
1563                 $template['tabindex'] = 10;
1564
1565                 $batch =& new BATCH('member');
1566                 $batch->showlist($query,'table',$template);
1567
1568                 echo '<h3>' . _MEMBERS_NEW .'</h3>';
1569                 ?>
1570                         <form method="post" action="index.php"><div>
1571
1572                         <input type="hidden" name="action" value="memberadd" />
1573                         <?php $manager->addTicketHidden() ?>
1574
1575                         <table>
1576                         <tr>
1577                                 <th colspan="2"><?php echo _MEMBERS_NEW?></th>
1578                         </tr><tr>
1579                                 <td><?php echo _MEMBERS_DISPLAY?> <?php help('shortnames');?>
1580                                         <br /><small>(This is the name used to logon)</small>
1581                                 </td>
1582                                 <td><input tabindex="10010" name="name" size="16" maxlength="16" /></td>
1583                         </tr><tr>
1584                                 <td><?php echo _MEMBERS_REALNAME?></td>
1585                                 <td><input name="realname" tabindex="10020" size="40" maxlength="60" /></td>
1586                         </tr><tr>
1587                                 <td><?php echo _MEMBERS_PWD?></td>
1588                                 <td><input name="password" tabindex="10030" size="16" maxlength="40" type="password" /></td>
1589                         </tr><tr>
1590                                 <td><?php echo _MEMBERS_REPPWD?></td>
1591                                 <td><input name="repeatpassword" tabindex="10035" size="16" maxlength="40" type="password" /></td>
1592                         </tr><tr>
1593                                 <td><?php echo _MEMBERS_EMAIL?></td>
1594                                 <td><input name="email" tabindex="10040" size="40" maxlength="60" /></td>
1595                         </tr><tr>
1596                                 <td><?php echo _MEMBERS_URL?></td>
1597                                 <td><input name="url" tabindex="10050" size="40" maxlength="100" /></td>
1598                         </tr><tr>
1599                                 <td><?php echo _MEMBERS_SUPERADMIN?> <?php help('superadmin'); ?></td>
1600                                 <td><?php $this->input_yesno('admin',0,10060); ?> </td>
1601                         </tr><tr>
1602                                 <td><?php echo _MEMBERS_CANLOGIN?> <?php help('canlogin'); ?></td>
1603                                 <td><?php $this->input_yesno('canlogin',1,10070); ?></td>
1604                         </tr><tr>
1605                                 <td><?php echo _MEMBERS_NOTES?></td>
1606                                 <td><input name="notes" maxlength="100" size="40" tabindex="10080" /></td>
1607                         </tr><tr>
1608                                 <td><?php echo _MEMBERS_NEW?></td>
1609                                 <td><input type="submit" value="<?php echo _MEMBERS_NEW_BTN?>" tabindex="10090" onclick="return checkSubmit();" /></td>
1610                         </tr></table>
1611
1612                         </div></form>
1613                 <?php
1614                 $this->pagefoot();
1615         }
1616
1617         /**
1618           * Edit member settings
1619           */
1620         function action_memberedit() {
1621                 $this->action_editmembersettings(intRequestVar('memberid'));
1622         }
1623         function action_editmembersettings($memberid = '') {
1624                 global $member, $manager, $CONF;
1625
1626                 if ($memberid == '')
1627                         $memberid = $member->getID();
1628
1629                 // check if allowed
1630                 ($member->getID() == $memberid) or $member->isAdmin() or $this->disallow();
1631
1632                 $extrahead = '<script type="text/javascript" src="javascript/numbercheck.js"></script>';
1633                 $this->pagehead($extrahead);
1634
1635                 // show message to go back to member overview (only for admins)
1636                 if ($member->isAdmin())
1637                         echo '<a href="index.php?action=usermanagement">(' ._MEMBERS_BACKTOOVERVIEW. ')</a>';
1638                 else
1639                         echo '<a href="index.php?action=overview">(' ._BACKHOME. ')</a>';
1640
1641                 echo '<h2>' . _MEMBERS_EDIT . '</h2>';
1642
1643                 $mem = MEMBER::createFromID($memberid);
1644
1645                 ?>
1646                 <form method="post" action="index.php"><div>
1647
1648                 <input type="hidden" name="action" value="changemembersettings" />
1649                 <input type="hidden" name="memberid" value="<?php echo  $memberid; ?>" />
1650                 <?php $manager->addTicketHidden() ?>
1651
1652                 <table><tr>
1653                         <th colspan="2"><?php echo _MEMBERS_EDIT?></th>
1654                 </tr><tr>
1655                         <td><?php echo _MEMBERS_DISPLAY?> <?php help('shortnames');?>
1656                                 <br /><small><?php echo _MEMBERS_DISPLAY_INFO?></small>
1657                         </td>
1658                         <td>
1659                         <?php if ($CONF['AllowLoginEdit'] || $member->isAdmin()) { ?>
1660                                 <input name="name" tabindex="10" maxlength="16" size="16" value="<?php echo  htmlspecialchars($mem->getDisplayName()); ?>" />
1661                         <?php } else {
1662                                 echo htmlspecialchars($member->getDisplayName());
1663                            }
1664                         ?>
1665                         </td>
1666                 </tr><tr>
1667                         <td><?php echo _MEMBERS_REALNAME?></td>
1668                         <td><input name="realname" tabindex="20" maxlength="60" size="40" value="<?php echo  htmlspecialchars($mem->getRealName()); ?>" /></td>
1669                 </tr><tr>
1670                 <?php if ($CONF['AllowLoginEdit'] || $member->isAdmin()) { ?>
1671                         <td><?php echo _MEMBERS_PWD?></td>
1672                         <td><input type="password" tabindex="30" maxlength="40" size="16" name="password" /></td>
1673                 </tr><tr>
1674                         <td><?php echo _MEMBERS_REPPWD?></td>
1675                         <td><input type="password" tabindex="35" maxlength="40" size="16" name="repeatpassword" /></td>
1676                 <?php } ?>
1677                 </tr><tr>
1678                         <td><?php echo _MEMBERS_EMAIL?>
1679                                 <br /><small><?php echo _MEMBERS_EMAIL_EDIT?></small>
1680                         </td>
1681                         <td><input name="email" tabindex="40" size="40" maxlength="60" value="<?php echo  htmlspecialchars($mem->getEmail()); ?>" /></td>
1682                 </tr><tr>
1683                         <td><?php echo _MEMBERS_URL?></td>
1684                         <td><input name="url" tabindex="50" size="40" maxlength="100" value="<?php echo  htmlspecialchars($mem->getURL()); ?>" /></td>
1685                 <?php // only allow to change this by super-admins
1686                    // we don't want normal users to 'upgrade' themselves to super-admins, do we? ;-)
1687                    if ($member->isAdmin()) {
1688                 ?>
1689                         </tr><tr>
1690                                 <td><?php echo _MEMBERS_SUPERADMIN?> <?php help('superadmin'); ?></td>
1691                                 <td><?php $this->input_yesno('admin',$mem->isAdmin(),60); ?></td>
1692                         </tr><tr>
1693                                 <td><?php echo _MEMBERS_CANLOGIN?> <?php help('canlogin'); ?></td>
1694                                 <td><?php $this->input_yesno('canlogin',$mem->canLogin(),70); ?></td>
1695                 <?php } ?>
1696                 </tr><tr>
1697                         <td><?php echo _MEMBERS_NOTES?></td>
1698                         <td><input name="notes" tabindex="80" size="40" maxlength="100" value="<?php echo  htmlspecialchars($mem->getNotes()); ?>" /></td>
1699                 </tr><tr>
1700                         <td><?php echo _MEMBERS_DEFLANG?> <?php help('language'); ?>
1701                         </td>
1702                         <td>
1703
1704                                 <select name="deflang" tabindex="85">
1705                                         <option value=""><?php echo _MEMBERS_USESITELANG?></option>
1706                                 <?php                           // show a dropdown list of all available languages
1707                                 global $DIR_LANG;
1708                                 $dirhandle = opendir($DIR_LANG);
1709                                 while ($filename = readdir($dirhandle)) {
1710                                         if (ereg("^(.*)\.php$",$filename,$matches)) {
1711                                                 $name = $matches[1];
1712                                                 echo "<option value='$name'";
1713                                                 if ($name == $mem->getLanguage())
1714                                                         echo " selected='selected'";
1715                                                 echo ">$name</option>";
1716                                         }
1717                                 }
1718                                 closedir($dirhandle);
1719
1720                                 ?>
1721                                 </select>
1722
1723                         </td>
1724                 </tr>
1725                 <?php
1726                         // plugin options
1727                         $this->_insertPluginOptions('member',$memberid);
1728                 ?>
1729                 <tr>
1730                         <th colspan="2"><?php echo _MEMBERS_EDIT ?></th>
1731                 </tr><tr>
1732                         <td><?php echo _MEMBERS_EDIT?></td>
1733                         <td><input type="submit" tabindex="90" value="<?php echo _MEMBERS_EDIT_BTN?>" onclick="return checkSubmit();" /></td>
1734                 </tr></table>
1735
1736                 </div></form>
1737
1738                 <?php
1739                         echo '<h3>',_PLUGINS_EXTRA,'</h3>';
1740
1741                         $manager->notify(
1742                                 'MemberSettingsFormExtras',
1743                                 array(
1744                                         'member' => &$mem
1745                                 )
1746                         );
1747
1748                 $this->pagefoot();
1749         }
1750
1751
1752         function action_changemembersettings() {
1753                 global $member, $CONF, $manager;
1754
1755                 $memberid = intRequestVar('memberid');
1756
1757                 // check if allowed
1758                 ($member->getID() == $memberid) or $member->isAdmin() or $this->disallow();
1759
1760                 $name                   = trim(postVar('name'));
1761                 $realname               = trim(postVar('realname'));
1762                 $password               = postVar('password');
1763                 $repeatpassword = postVar('repeatpassword');
1764                 $email                  = postVar('email');
1765                 $url                    = postVar('url');
1766
1767                 // Sometimes user didn't prefix the URL with http://, this cause a malformed URL. Let's fix it.
1768                 if (!eregi("^https?://", $url))
1769                         $url = "http://".$url;
1770
1771                 $admin                  = postVar('admin');
1772                 $canlogin               = postVar('canlogin');
1773                 $notes                  = postVar('notes');
1774                 $deflang                = postVar('deflang');
1775
1776                 $mem = MEMBER::createFromID($memberid);
1777
1778                 if ($CONF['AllowLoginEdit'] || $member->isAdmin()) {
1779
1780                         if (!isValidDisplayName($name))
1781                                 $this->error(_ERROR_BADNAME);
1782
1783                         if (($name != $mem->getDisplayName()) && MEMBER::exists($name))
1784                                 $this->error(_ERROR_NICKNAMEINUSE);
1785
1786                         if ($password != $repeatpassword)
1787                                 $this->error(_ERROR_PASSWORDMISMATCH);
1788
1789                         if ($password && (strlen($password) < 6))
1790                                 $this->error(_ERROR_PASSWORDTOOSHORT);
1791                 }
1792
1793                 if (!isValidMailAddress($email))
1794                         $this->error(_ERROR_BADMAILADDRESS);
1795
1796
1797                 if (!$realname)
1798                         $this->error(_ERROR_REALNAMEMISSING);
1799
1800                 if (($deflang != '') && (!checkLanguage($deflang)))
1801                         $this->error(_ERROR_NOSUCHLANGUAGE);
1802
1803                 // check if there will remain at least one site member with both the logon and admin rights
1804                 // (check occurs when taking away one of these rights from such a member)
1805                 if (    (!$admin && $mem->isAdmin() && $mem->canLogin())
1806                          || (!$canlogin && $mem->isAdmin() && $mem->canLogin())
1807                    )
1808                 {
1809                         $r = sql_query('SELECT * FROM '.sql_table('member').' WHERE madmin=1 and mcanlogin=1');
1810                         if (mysql_num_rows($r) < 2)
1811                                 $this->error(_ERROR_ATLEASTONEADMIN);
1812                 }
1813
1814                 if ($CONF['AllowLoginEdit'] || $member->isAdmin()) {
1815                         $mem->setDisplayName($name);
1816                         if ($password)
1817                                 $mem->setPassword($password);
1818                 }
1819
1820                 if ($newpass)
1821                         $mem->setPassword($password);
1822
1823                 $oldEmail = $mem->getEmail();
1824
1825                 $mem->setRealName($realname);
1826                 $mem->setEmail($email);
1827                 $mem->setURL($url);
1828                 $mem->setNotes($notes);
1829                 $mem->setLanguage($deflang);
1830
1831
1832                 // only allow super-admins to make changes to the admin status
1833                 if ($member->isAdmin()) {
1834                         $mem->setAdmin($admin);
1835                         $mem->setCanLogin($canlogin);
1836                 }
1837
1838
1839                 $mem->write();
1840
1841                 // if email changed, generate new password
1842                 if ($oldEmail != $mem->getEmail())
1843                 {
1844                         $mem->sendActivationLink('addresschange', $oldEmail);
1845                         // logout member
1846                         $mem->newCookieKey();
1847                         $member->logout();
1848                         $this->action_login(_MSG_ACTIVATION_SENT, 0);
1849                         return;
1850                 }
1851
1852
1853                 // store plugin options
1854                 $aOptions = requestArray('plugoption');
1855                 NucleusPlugin::_applyPluginOptions($aOptions);
1856                 $manager->notify('PostPluginOptionsUpdate',array('context' => 'member', 'memberid' => $memberid, 'member' => &$mem));
1857
1858                 if (  ( $mem->getID() == $member->getID() )
1859                    && ( $newpass || ( $mem->getDisplayName() != $member->getDisplayName() ) )
1860                    ) {
1861                         $mem->newCookieKey();
1862                         $member->logout();
1863                         $this->action_login(_MSG_LOGINAGAIN, 0);
1864                 } else {
1865                         $this->action_overview(_MSG_SETTINGSCHANGED);
1866                 }
1867         }
1868
1869         function action_memberadd() {
1870                 global $member;
1871
1872                 // check if allowed
1873                 $member->isAdmin() or $this->disallow();
1874
1875                 if (postVar('password') != postVar('repeatpassword'))
1876                         $this->error(_ERROR_PASSWORDMISMATCH);
1877                 if (strlen(postVar('password')) < 6)
1878                         $this->error(_ERROR_PASSWORDTOOSHORT);
1879
1880                 $res = MEMBER::create(postVar('name'), postVar('realname'), postVar('password'), postVar('email'), postVar('url'), postVar('admin'), postVar('canlogin'), postVar('notes'));
1881                 if ($res != 1)
1882                         $this->error($res);
1883
1884                 $this->action_usermanagement();
1885         }
1886
1887         /**
1888          * Account activation
1889          *
1890          * @author dekarma
1891          */
1892         function action_activate() {
1893
1894                 $key = getVar('key');
1895                 $this->_showActivationPage($key);
1896         }
1897
1898         function _showActivationPage($key, $message = '')
1899         {
1900                 global $manager;
1901
1902                 // clean up old activation keys
1903                 MEMBER::cleanupActivationTable();
1904
1905                 // get activation info
1906                 $info = MEMBER::getActivationInfo($key);
1907
1908                 if (!$info)
1909                         $this->error(_ERROR_ACTIVATE);
1910
1911                 $mem = MEMBER::createFromId($info->vmember);
1912
1913                 if (!$mem)
1914                         $this->error(_ERROR_ACTIVATE);
1915
1916                 $text = '';
1917                 $title = '';
1918                 $bNeedsPasswordChange = true;
1919
1920                 switch ($info->vtype)
1921                 {
1922                         case 'forgot':
1923                                 $title = _ACTIVATE_FORGOT_TITLE;
1924                                 $text = _ACTIVATE_FORGOT_TEXT;
1925                                 break;
1926                         case 'register':
1927                                 $title = _ACTIVATE_REGISTER_TITLE;
1928                                 $text = _ACTIVATE_REGISTER_TEXT;
1929                                 break;
1930                         case 'addresschange':
1931                                 $title = _ACTIVATE_CHANGE_TITLE;
1932                                 $text = _ACTIVATE_CHANGE_TEXT;
1933                                 $bNeedsPasswordChange = false;
1934                                 MEMBER::activate($key);
1935                                 break;
1936                 }
1937
1938                 $aVars = array(
1939                         'memberName' => htmlspecialchars($mem->getDisplayName())
1940                 );
1941                 $title = TEMPLATE::fill($title, $aVars);
1942                 $text = TEMPLATE::fill($text, $aVars);
1943
1944                 $this->pagehead();
1945
1946                         echo '<h2>' , $title, '</h2>';
1947                         echo '<p>' , $text, '</p>';
1948
1949                         if ($message != '')
1950                         {
1951                                 echo '<p class="error">',$message,'</p>';
1952                         }
1953
1954                         if ($bNeedsPasswordChange)
1955                         {
1956                                 ?>
1957                                         <div><form action="index.php" method="post">
1958
1959                                                 <input type="hidden" name="action" value="activatesetpwd" />
1960                                                 <?php $manager->addTicketHidden() ?>
1961                                                 <input type="hidden" name="key" value="<?php echo htmlspecialchars($key) ?>" />
1962
1963                                                 <table><tr>
1964                                                         <td><?php echo _MEMBERS_PWD?></td>
1965                                                         <td><input type="password" maxlength="40" size="16" name="password" /></td>
1966                                                 </tr><tr>
1967                                                         <td><?php echo _MEMBERS_REPPWD?></td>
1968                                                         <td><input type="password" maxlength="40" size="16" name="repeatpassword" /></td>
1969                                                 <?php
1970
1971                                                         global $manager;
1972                                                         $manager->notify('FormExtra', array('type' => 'activation', 'member' => $mem));
1973
1974                                                 ?>
1975                                                 </tr><tr>
1976                                                         <td><?php echo _MEMBERS_SETPWD ?></td>
1977                                                         <td><input type='submit' value='<?php echo _MEMBERS_SETPWD_BTN ?>' /></td>
1978                                                 </tr></table>
1979
1980
1981                                         </form></div>
1982
1983                                 <?php
1984
1985                         }
1986
1987                 $this->pagefoot();
1988
1989         }
1990
1991         /**
1992          * Account activation - set password part
1993          *
1994          * @author dekarma
1995          */
1996         function action_activatesetpwd() {
1997
1998                 $key = postVar('key');
1999
2000                 // clean up old activation keys
2001                 MEMBER::cleanupActivationTable();
2002
2003                 // get activation info
2004                 $info = MEMBER::getActivationInfo($key);
2005
2006                 if (!$info || ($info->type == 'addresschange'))
2007                         return $this->_showActivationPage($key, _ERROR_ACTIVATE);
2008
2009                 $mem = MEMBER::createFromId($info->vmember);
2010
2011                 if (!$mem)
2012                         return $this->_showActivationPage($key, _ERROR_ACTIVATE);
2013
2014                 $password               = postVar('password');
2015                 $repeatpassword = postVar('repeatpassword');
2016
2017                 if ($password != $repeatpassword)
2018                         return $this->_showActivationPage($key, _ERROR_PASSWORDMISMATCH);
2019
2020                 if ($password && (strlen($password) < 6))
2021                         return $this->_showActivationPage($key, _ERROR_PASSWORDTOOSHORT);
2022
2023                 $error = '';
2024                 global $manager;
2025                 $manager->notify('ValidateForm', array('type' => 'activation', 'member' => $mem, 'error' => &$error));
2026                 if ($error != '')
2027                         return $this->_showActivationPage($key, $error);
2028
2029
2030                 // set password
2031                 $mem->setPassword($password);
2032                 $mem->write();
2033
2034                 // do the activation
2035                 MEMBER::activate($key);
2036
2037                 $this->pagehead();
2038                         echo '<h2>',_ACTIVATE_SUCCESS_TITLE,'</h2>';
2039                         echo '<p>',_ACTIVATE_SUCCESS_TEXT,'</p>';
2040                 $this->pagefoot();
2041         }
2042
2043         /**
2044           * Manage team
2045           */
2046         function action_manageteam() {
2047                 global $member, $manager;
2048
2049                 $blogid = intRequestVar('blogid');
2050
2051                 // check if allowed
2052                 $member->blogAdminRights($blogid) or $this->disallow();
2053
2054                 $this->pagehead();
2055
2056                 echo "<p><a href='index.php?action=blogsettings&amp;blogid=$blogid'>(",_BACK_TO_BLOGSETTINGS,")</a></p>";
2057
2058                 echo '<h2>' . _TEAM_TITLE . getBlogNameFromID($blogid) . '</h2>';
2059
2060                 echo '<h3>' . _TEAM_CURRENT . '</h3>';
2061
2062
2063
2064                 $query =  'SELECT tblog, tmember, mname, mrealname, memail, tadmin'
2065                            . ' FROM '.sql_table('member').', '.sql_table('team')
2066                            . ' WHERE tmember=mnumber and tblog=' . $blogid;
2067
2068                 $template['content'] = 'teamlist';
2069                 $template['tabindex'] = 10;
2070
2071                 $batch =& new BATCH('team');
2072                 $batch->showlist($query, 'table', $template);
2073
2074                 ?>
2075                         <h3><?php echo _TEAM_ADDNEW?></h3>
2076
2077                         <form method='post' action='index.php'><div>
2078
2079                         <input type='hidden' name='action' value='teamaddmember' />
2080                         <input type='hidden' name='blogid' value='<?php echo  $blogid; ?>' />
2081                         <?php $manager->addTicketHidden() ?>
2082
2083                         <table><tr>
2084                                 <td><?php echo _TEAM_CHOOSEMEMBER?></td>
2085                                 <td><?php                                       // TODO: try to make it so only non-team-members are listed
2086                                         $query =  'SELECT mname as text, mnumber as value'
2087                                                    . ' FROM '.sql_table('member');
2088
2089                                         $template['name'] = 'memberid';
2090                                         $template['tabindex'] = 10000;
2091                                         showlist($query,'select',$template);
2092                                 ?></td>
2093                         </tr><tr>
2094                                 <td><?php echo _TEAM_ADMIN?><?php help('teamadmin'); ?></td>
2095                                 <td><?php $this->input_yesno('admin',0,10020); ?></td>
2096                         </tr><tr>
2097                                 <td><?php echo _TEAM_ADD?></td>
2098                                 <td><input type='submit' value='<?php echo _TEAM_ADD_BTN?>' tabindex="10030" /></td>
2099                         </tr></table>
2100
2101                         </div></form>
2102                 <?php
2103                 $this->pagefoot();
2104         }
2105
2106         /**
2107           * Add member tot tram
2108           */
2109         function action_teamaddmember() {
2110                 global $member, $manager;
2111
2112                 $memberid = intPostVar('memberid');
2113                 $blogid = intPostVar('blogid');
2114                 $admin = intPostVar('admin');
2115
2116                 // check if allowed
2117                 $member->blogAdminRights($blogid) or $this->disallow();
2118
2119                 $blog =& $manager->getBlog($blogid);
2120                 if (!$blog->addTeamMember($memberid, $admin))
2121                         $this->error(_ERROR_ALREADYONTEAM);
2122
2123                 $this->action_manageteam();
2124
2125         }
2126
2127         function action_teamdelete() {
2128                 global $member, $manager;
2129
2130                 $memberid = intRequestVar('memberid');
2131                 $blogid = intRequestVar('blogid');
2132
2133                 // check if allowed
2134                 $member->blogAdminRights($blogid) or $this->disallow();
2135
2136                 $teammem = MEMBER::createFromID($memberid);
2137                 $blog =& $manager->getBlog($blogid);
2138
2139                 $this->pagehead();
2140                 ?>
2141                         <h2><?php echo _DELETE_CONFIRM?></h2>
2142
2143                         <p><?php echo _CONFIRMTXT_TEAM1?><b><?php echo  $teammem->getDisplayName() ?></b><?php echo _CONFIRMTXT_TEAM2?><b><?php echo  htmlspecialchars(strip_tags($blog->getName())) ?></b>
2144                         </p>
2145
2146
2147                         <form method="post" action="index.php"><div>
2148                         <input type="hidden" name="action" value="teamdeleteconfirm" />
2149                         <?php $manager->addTicketHidden() ?>
2150                         <input type="hidden" name="memberid" value="<?php echo  $memberid; ?>" />
2151                         <input type="hidden" name="blogid" value="<?php echo  $blogid; ?>" />
2152                         <input type="submit" tabindex="10" value="<?php echo _DELETE_CONFIRM_BTN?>" />
2153                         </div></form>
2154                 <?php
2155                 $this->pagefoot();
2156         }
2157
2158         function action_teamdeleteconfirm() {
2159                 global $member;
2160
2161                 $memberid = intRequestVar('memberid');
2162                 $blogid = intRequestVar('blogid');
2163
2164                 $error = $this->deleteOneTeamMember($blogid, $memberid);
2165                 if ($error)
2166                         $this->error($error);
2167
2168
2169                 $this->action_manageteam();
2170         }
2171
2172         function deleteOneTeamMember($blogid, $memberid) {
2173                 global $member, $manager;
2174
2175                 $blogid = intval($blogid);
2176                 $memberid = intval($memberid);
2177
2178                 // check if allowed
2179                 if (!$member->blogAdminRights($blogid))
2180                         return _ERROR_DISALLOWED;
2181
2182                 // check if: - there remains at least one blog admin
2183                 //           - (there remains at least one team member)
2184                 $tmem = MEMBER::createFromID($memberid);
2185
2186                 $manager->notify('PreDeleteTeamMember', array('member' => &$mem, 'blogid' => $blogid));
2187
2188                 if ($tmem->isBlogAdmin($blogid)) {
2189                         // check if there are more blog members left and at least one admin
2190                         // (check for at least two admins before deletion)
2191                         $query = 'SELECT * FROM '.sql_table('team') . ' WHERE tblog='.$blogid.' and tadmin=1';
2192                         $r = sql_query($query);
2193                         if (mysql_num_rows($r) < 2)
2194                                 return _ERROR_ATLEASTONEBLOGADMIN;
2195                 }
2196
2197                 $query = 'DELETE FROM '.sql_table('team')." WHERE tblog=$blogid and tmember=$memberid";
2198                 sql_query($query);
2199
2200                 $manager->notify('PostDeleteTeamMember', array('member' => &$mem, 'blogid' => $blogid));
2201
2202                 return '';
2203         }
2204
2205         function action_teamchangeadmin() {
2206                 global $member;
2207
2208                 $blogid = intRequestVar('blogid');
2209                 $memberid = intRequestVar('memberid');
2210
2211                 // check if allowed
2212                 $member->blogAdminRights($blogid) or $this->disallow();
2213
2214                 $mem = MEMBER::createFromID($memberid);
2215
2216                 // don't allow when there is only one admin at this moment
2217                 if ($mem->isBlogAdmin($blogid)) {
2218                         $r = sql_query('SELECT * FROM '.sql_table('team') . " WHERE tblog=$blogid and tadmin=1");
2219                         if (mysql_num_rows($r) == 1)
2220                                 $this->error(_ERROR_ATLEASTONEBLOGADMIN);
2221                 }
2222
2223                 if ($mem->isBlogAdmin($blogid))
2224                         $newval = 0;
2225                 else
2226                         $newval = 1;
2227
2228                 $query = 'UPDATE '.sql_table('team') ." SET tadmin=$newval WHERE tblog=$blogid and tmember=$memberid";
2229                 sql_query($query);
2230
2231                 // only show manageteam if member did not change its own admin privileges
2232                 if ($member->isBlogAdmin($blogid))
2233                         $this->action_manageteam();
2234                 else
2235                         $this->action_overview(_MSG_ADMINCHANGED);
2236         }
2237
2238         function action_blogsettings() {
2239                 global $member, $manager;
2240
2241                 $blogid = intRequestVar('blogid');
2242
2243                 // check if allowed
2244                 $member->blogAdminRights($blogid) or $this->disallow();
2245
2246                 $blog =& $manager->getBlog($blogid);
2247
2248                 $extrahead = '<script type="text/javascript" src="javascript/numbercheck.js"></script>';
2249                 $this->pagehead($extrahead);
2250
2251                 echo '<p><a href="index.php?action=overview">(',_BACKHOME,')</a></p>';
2252                 ?>
2253                 <h2><?php echo _EBLOG_TITLE?>: '<?php echo $this->bloglink($blog)?>'</h2>
2254
2255                 <h3><?php echo _EBLOG_TEAM_TITLE?></h3>
2256
2257                 <p>Members currently on your team:
2258                 <?php
2259                         $res = sql_query('SELECT mname, mrealname FROM ' . sql_table('member') . ',' . sql_table('team') . ' WHERE mnumber=tmember AND tblog=' . intval($blogid));
2260                         $aMemberNames = array();
2261                         while ($o = mysql_fetch_object($res))
2262                                 array_push($aMemberNames, htmlspecialchars($o->mname) . ' (' . htmlspecialchars($o->mrealname). ')');
2263                         echo implode(',', $aMemberNames);
2264                 ?>
2265                 </p>
2266
2267
2268
2269                 <p>
2270                 <a href="index.php?action=manageteam&amp;blogid=<?php echo $blogid?>"><?php echo _EBLOG_TEAM_TEXT?></a>
2271                 </p>
2272
2273                 <h3><?php echo _EBLOG_SETTINGS_TITLE?></h3>
2274
2275                 <form method="post" action="index.php"><div>
2276
2277                 <input type="hidden" name="action" value="blogsettingsupdate" />
2278                 <?php $manager->addTicketHidden() ?>
2279                 <input type="hidden" name="blogid" value="<?php echo  $blogid; ?>" />
2280                 <table><tr>
2281                         <td><?php echo _EBLOG_NAME?></td>
2282                         <td><input name="name" tabindex="10" size="40" maxlength="60" value="<?php echo  htmlspecialchars($blog->getName()) ?>" /></td>
2283                 </tr><tr>
2284                         <td><?php echo _EBLOG_SHORTNAME?> <?php help('shortblogname'); ?>
2285                                 <?php echo _EBLOG_SHORTNAME_EXTRA?>
2286                         </td>
2287                         <td><input name="shortname" tabindex="20" maxlength="15" size="15" value="<?php echo  htmlspecialchars($blog->getShortName()) ?>" /></td>
2288                 </tr><tr>
2289                         <td><?php echo _EBLOG_DESC?></td>
2290                         <td><input name="desc" tabindex="30" maxlength="200" size="40" value="<?php echo  htmlspecialchars($blog->getDescription()) ?>" /></td>
2291                 </tr><tr>
2292                         <td><?php echo _EBLOG_URL?></td>
2293                         <td><input name="url" tabindex="40" size="40" maxlength="100" value="<?php echo  htmlspecialchars($blog->getURL()) ?>" /></td>
2294                 </tr><tr>
2295                         <td><?php echo _EBLOG_DEFSKIN?>
2296                                 <?php help('blogdefaultskin'); ?>
2297                         </td>
2298                         <td>
2299                                 <?php
2300                                         $query =  'SELECT sdname as text, sdnumber as value'
2301                                                    . ' FROM '.sql_table('skin_desc');
2302                                         $template['name'] = 'defskin';
2303                                         $template['selected'] = $blog->getDefaultSkin();
2304                                         $template['tabindex'] = 50;
2305                                         showlist($query,'select',$template);
2306                                 ?>
2307
2308                         </td>
2309                 </tr><tr>
2310                         <td><?php echo _EBLOG_LINEBREAKS?> <?php help('convertbreaks'); ?>
2311                         </td>
2312                         <td><?php $this->input_yesno('convertbreaks',$blog->convertBreaks(),55); ?></td>
2313                 </tr><tr>
2314                         <td><?php echo _EBLOG_ALLOWPASTPOSTING?> <?php help('allowpastposting'); ?>
2315                         </td>
2316                         <td><?php $this->input_yesno('allowpastposting',$blog->allowPastPosting(),57); ?></td>
2317                 </tr><tr>
2318                         <td><?php echo _EBLOG_DISABLECOMMENTS?>
2319                         </td>
2320                         <td><?php $this->input_yesno('comments',$blog->commentsEnabled(),60); ?></td>
2321                 </tr><tr>
2322                         <td><?php echo _EBLOG_ANONYMOUS?>
2323                         </td>
2324                         <td><?php $this->input_yesno('public',$blog->isPublic(),70); ?></td>
2325                 </tr><tr>
2326                         <td><?php echo _EBLOG_NOTIFY?> <?php help('blognotify'); ?></td>
2327                         <td><input name="notify" tabindex="80" maxlength="60" size="40" value="<?php echo  htmlspecialchars($blog->getNotifyAddress()); ?>" /></td>
2328                 </tr><tr>
2329                         <td><?php echo _EBLOG_NOTIFY_ON?></td>
2330                         <td>
2331                                 <input name="notifyComment" value="3" type="checkbox" tabindex="81" id="notifyComment"
2332                                         <?php if  ($blog->notifyOnComment()) echo "checked='checked'" ?>
2333                                 /><label for="notifyComment"><?php echo _EBLOG_NOTIFY_COMMENT?></label>
2334                                 <br />
2335                                 <input name="notifyVote" value="5" type="checkbox" tabindex="82" id="notifyVote"
2336                                         <?php if  ($blog->notifyOnVote()) echo "checked='checked'" ?>
2337                                 /><label for="notifyVote"><?php echo _EBLOG_NOTIFY_KARMA?></label>
2338                                 <br />
2339                                 <input name="notifyNewItem" value="7" type="checkbox" tabindex="83" id="notifyNewItem"
2340                                         <?php if  ($blog->notifyOnNewItem()) echo "checked='checked'" ?>
2341                                 /><label for="notifyNewItem"><?php echo _EBLOG_NOTIFY_ITEM?></label>
2342                         </td>
2343                 </tr><tr>
2344                         <td><?php echo _EBLOG_PING?> <?php help('pinguserland'); ?></td>
2345                         <td><?php $this->input_yesno('pinguserland',$blog->pingUserland(),85); ?></td>
2346                 </tr><tr>
2347                         <td><?php echo _EBLOG_MAXCOMMENTS?> <?php help('blogmaxcomments'); ?></td>
2348                         <td><input name="maxcomments" tabindex="90" size="3" value="<?php echo  htmlspecialchars($blog->getMaxComments()); ?>" /></td>
2349                 </tr><tr>
2350                         <td><?php echo _EBLOG_UPDATE?> <?php help('blogupdatefile'); ?></td>
2351                         <td><input name="update" tabindex="100" size="40" maxlength="60" value="<?php echo  htmlspecialchars($blog->getUpdateFile()) ?>" /></td>
2352                 </tr><tr>
2353                         <td><?php echo _EBLOG_DEFCAT?></td>
2354                         <td>
2355                                 <?php
2356                                         $query =  'SELECT cname as text, catid as value'
2357                                                    . ' FROM '.sql_table('category')
2358                                                    . ' WHERE cblog=' . $blog->getID();
2359                                         $template['name'] = 'defcat';
2360                                         $template['selected'] = $blog->getDefaultCategory();
2361                                         $template['tabindex'] = 110;
2362                                         showlist($query,'select',$template);
2363                                 ?>
2364                         </td>
2365                 </tr><tr>
2366                         <td><?php echo _EBLOG_OFFSET?> <?php help('blogtimeoffset'); ?>
2367                                 <br /><?php echo _EBLOG_STIME?> <b><?php echo  strftime("%H:%M",time()); ?></b>
2368                                 <br /><?php echo _EBLOG_BTIME?> <b><?php echo  strftime("%H:%M",$blog->getCorrectTime()); ?></b>
2369                                 </td>
2370                         <td><input name="timeoffset" tabindex="120" size="3" value="<?php echo  htmlspecialchars($blog->getTimeOffset()); ?>" /></td>
2371                 </tr><tr>
2372                         <td><?php echo _EBLOG_SEARCH?> <?php help('blogsearchable'); ?></td>
2373                         <td><?php $this->input_yesno('searchable',$blog->getSearchable(),122); ?></td>
2374                 </tr>
2375                 <?php
2376                         // plugin options
2377                         $this->_insertPluginOptions('blog',$blogid);
2378                 ?>
2379                 <tr>
2380                         <th colspan="2"><?php echo _EBLOG_CHANGE?></th>
2381                 </tr><tr>
2382                         <td><?php echo _EBLOG_CHANGE?></td>
2383                         <td><input type="submit" tabindex="130" value="<?php echo _EBLOG_CHANGE_BTN?>" onclick="return checkSubmit();" /></td>
2384                 </tr></table>
2385
2386                 </div></form>
2387
2388                 <h3><?php echo _EBLOG_CAT_TITLE?></h3>
2389
2390
2391                 <?php
2392                 $query = 'SELECT * FROM '.sql_table('category').' WHERE cblog='.$blog->getID().' ORDER BY cname';
2393                 $template['content'] = 'categorylist';
2394                 $template['tabindex'] = 200;
2395
2396                 $batch =& new BATCH('category');
2397                 $batch->showlist($query,'table',$template);
2398
2399                 ?>
2400
2401
2402                 <form action="index.php" method="post"><div>
2403                 <input name="action" value="categorynew" type="hidden" />
2404                 <?php $manager->addTicketHidden() ?>
2405                 <input name="blogid" value="<?php echo $blog->getID()?>" type="hidden" />
2406
2407                 <table><tr>
2408                         <th colspan="2"><?php echo _EBLOG_CAT_CREATE?></th>
2409                 </tr><tr>
2410                         <td><?php echo _EBLOG_CAT_NAME?></td>
2411                         <td><input name="cname" size="40" maxlength="40" tabindex="300" /></td>
2412                 </tr><tr>
2413                         <td><?php echo _EBLOG_CAT_DESC?></td>
2414                         <td><input name="cdesc" size="40" maxlength="200" tabindex="310" /></td>
2415                 </tr><tr>
2416                         <td><?php echo _EBLOG_CAT_CREATE?></td>
2417                         <td><input type="submit" value="<?php echo _EBLOG_CAT_CREATE?>" tabindex="320" /></td>
2418                 </tr></table>
2419
2420                 </div></form>
2421
2422                 <?php
2423
2424                         echo '<h3>',_PLUGINS_EXTRA,'</h3>';
2425
2426                         $manager->notify(
2427                                 'BlogSettingsFormExtras',
2428                                 array(
2429                                         'blog' => &$blog
2430                                 )
2431                         );
2432
2433                 $this->pagefoot();
2434         }
2435
2436         function action_categorynew() {
2437                 global $member, $manager;
2438
2439                 $blogid = intRequestVar('blogid');
2440
2441                 $member->blogAdminRights($blogid) or $this->disallow();
2442
2443                 $cname = postVar('cname');
2444                 $cdesc = postVar('cdesc');
2445
2446                 if (!isValidCategoryName($cname))
2447                         $this->error(_ERROR_BADCATEGORYNAME);
2448
2449                 $query = 'SELECT * FROM '.sql_table('category') . ' WHERE cname=\'' . addslashes($cname).'\' and cblog=' . intval($blogid);
2450                 $res = sql_query($query);
2451                 if (mysql_num_rows($res) > 0)
2452                         $this->error(_ERROR_DUPCATEGORYNAME);
2453
2454                 $blog           =& $manager->getBlog($blogid);
2455                 $newCatID       =  $blog->createNewCategory($cname, $cdesc);
2456
2457                 $this->action_blogsettings();
2458         }
2459
2460
2461         function action_categoryedit($catid = '', $blogid = '', $desturl = '') {
2462                 global $member, $manager;
2463
2464                 if ($blogid == '')
2465                         $blogid = intGetVar('blogid');
2466                 else
2467                         $blogid = intval($blogid);
2468                 if ($catid == '')
2469                         $catid = intGetVar('catid');
2470                 else
2471                         $catid = intval($catid);
2472
2473                 $member->blogAdminRights($blogid) or $this->disallow();
2474
2475                 $res = sql_query('SELECT * FROM '.sql_table('category')." WHERE cblog=$blogid AND catid=$catid");
2476                 $obj = mysql_fetch_object($res);
2477
2478                 $cname = $obj->cname;
2479                 $cdesc = $obj->cdesc;
2480
2481                 $extrahead = '<script type="text/javascript" src="javascript/numbercheck.js"></script>';
2482                 $this->pagehead($extrahead);
2483
2484                 ?>
2485                 <h2><?php echo _EBLOG_CAT_UPDATE?> '<?php echo htmlspecialchars($cname)?>'</h2>
2486                 <form method='post' action='index.php'><div>
2487                 <input name="blogid" type="hidden" value="<?php echo $blogid?>" />
2488                 <input name="catid" type="hidden" value="<?php echo $catid?>" />
2489                 <input name="desturl" type="hidden" value="<?php echo htmlspecialchars($desturl) ?>" />
2490                 <input name="action" type="hidden" value="categoryupdate" />
2491                 <?php $manager->addTicketHidden(); ?>
2492
2493                 <table><tr>
2494                         <th colspan="2"><?php echo _EBLOG_CAT_UPDATE ?></th>
2495                 </tr><tr>
2496                         <td><?php echo _EBLOG_CAT_NAME?></td>
2497                         <td><input type="text" name="cname" value="<?php echo htmlspecialchars($cname)?>" size="40" maxlength="40" /></td>
2498                 </tr><tr>
2499                         <td><?php echo _EBLOG_CAT_DESC?></td>
2500                         <td><input type="text" name="cdesc" value="<?php echo htmlspecialchars($cdesc)?>" size="40" maxlength="200" /></td>
2501                 </tr>
2502                 <?php
2503                         // insert plugin options
2504                         $this->_insertPluginOptions('category',$catid);
2505                 ?>
2506                 <tr>
2507                         <th colspan="2"><?php echo _EBLOG_CAT_UPDATE ?></th>
2508                 </tr><tr>
2509                         <td><?php echo _EBLOG_CAT_UPDATE?></td>
2510                         <td><input type="submit" value="<?php echo _EBLOG_CAT_UPDATE_BTN?>" /></td>
2511                 </tr></table>
2512
2513                 </div></form>
2514                 <?php
2515                 $this->pagefoot();
2516         }
2517
2518
2519         function action_categoryupdate() {
2520                 global $member, $manager;
2521
2522                 $blogid = intPostVar('blogid');
2523                 $catid = intPostVar('catid');
2524                 $cname = postVar('cname');
2525                 $cdesc = postVar('cdesc');
2526                 $desturl = postVar('desturl');
2527
2528                 $member->blogAdminRights($blogid) or $this->disallow();
2529
2530                 if (!isValidCategoryName($cname))
2531                         $this->error(_ERROR_BADCATEGORYNAME);
2532
2533                 $query = 'SELECT * FROM '.sql_table('category').' WHERE cname=\'' . addslashes($cname).'\' and cblog=' . intval($blogid) . " and not(catid=$catid)";
2534                 $res = sql_query($query);
2535                 if (mysql_num_rows($res) > 0)
2536                         $this->error(_ERROR_DUPCATEGORYNAME);
2537
2538                 $query =  'UPDATE '.sql_table('category').' SET'
2539                            . " cname='" . addslashes($cname) . "',"
2540                            . " cdesc='" . addslashes($cdesc) . "'"
2541                            . " WHERE catid=" . $catid;
2542
2543                 sql_query($query);
2544
2545                 // store plugin options
2546                 $aOptions = requestArray('plugoption');
2547                 NucleusPlugin::_applyPluginOptions($aOptions);
2548                 $manager->notify('PostPluginOptionsUpdate',array('context' => 'category', 'catid' => $catid));
2549
2550
2551                 if ($desturl) {
2552                         redirect($desturl);
2553                         exit;
2554                 } else {
2555                         $this->action_blogsettings();
2556                 }
2557         }
2558
2559         function action_categorydelete() {
2560                 global $member, $manager;
2561
2562                 $blogid = intRequestVar('blogid');
2563                 $catid = intRequestVar('catid');
2564
2565                 $member->blogAdminRights($blogid) or $this->disallow();
2566
2567                 $blog =& $manager->getBlog($blogid);
2568
2569                 // check if the category is valid
2570                 if (!$blog->isValidCategory($catid))
2571                         $this->error(_ERROR_NOSUCHCATEGORY);
2572
2573                 // don't allow deletion of default category
2574                 if ($blog->getDefaultCategory() == $catid)
2575                         $this->error(_ERROR_DELETEDEFCATEGORY);
2576
2577                 // check if catid is the only category left for blogid
2578                 $query = 'SELECT catid FROM '.sql_table('category').' WHERE cblog=' . $blogid;
2579                 $res = sql_query($query);
2580                 if (mysql_num_rows($res) == 1)
2581                         $this->error(_ERROR_DELETELASTCATEGORY);
2582
2583
2584                 $this->pagehead();
2585                 ?>
2586                         <h2><?php echo _DELETE_CONFIRM?></h2>
2587
2588                         <div>
2589                         <?php echo _CONFIRMTXT_CATEGORY?><b><?php echo  $blog->getCategoryName($catid)?></b>
2590                         </div>
2591
2592                         <form method="post" action="index.php"><div>
2593                         <input type="hidden" name="action" value="categorydeleteconfirm" />
2594                         <?php $manager->addTicketHidden() ?>
2595                         <input type="hidden" name="blogid" value="<?php echo $blogid?>" />
2596                         <input type="hidden" name="catid" value="<?php echo $catid?>" />
2597                         <input type="submit" tabindex="10" value="<?php echo _DELETE_CONFIRM_BTN?>" />
2598                         </div></form>
2599                 <?php
2600                 $this->pagefoot();
2601         }
2602
2603         function action_categorydeleteconfirm() {
2604                 global $member, $manager;
2605
2606                 $blogid = intRequestVar('blogid');
2607                 $catid = intRequestVar('catid');
2608
2609                 $member->blogAdminRights($blogid) or $this->disallow();
2610
2611                 $error = $this->deleteOneCategory($catid);
2612                 if ($error)
2613                         $this->error($error);
2614
2615                 $this->action_blogsettings();
2616         }
2617
2618         function deleteOneCategory($catid) {
2619                 global $manager, $member;
2620
2621                 $catid = intval($catid);
2622
2623                 $manager->notify('PreDeleteCategory', array('catid' => $catid));
2624
2625                 $blogid = getBlogIDFromCatID($catid);
2626
2627                 if (!$member->blogAdminRights($blogid))
2628                         return ERROR_DISALLOWED;
2629
2630                 // get blog
2631                 $blog =& $manager->getBlog($blogid);
2632
2633                 // check if the category is valid
2634                 if (!$blog || !$blog->isValidCategory($catid))
2635                         return _ERROR_NOSUCHCATEGORY;
2636
2637                 $destcatid = $blog->getDefaultCategory();
2638
2639                 // don't allow deletion of default category
2640                 if ($blog->getDefaultCategory() == $catid)
2641                         return _ERROR_DELETEDEFCATEGORY;
2642
2643                 // check if catid is the only category left for blogid
2644                 $query = 'SELECT catid FROM '.sql_table('category').' WHERE cblog=' . $blogid;
2645                 $res = sql_query($query);
2646                 if (mysql_num_rows($res) == 1)
2647                         return _ERROR_DELETELASTCATEGORY;
2648
2649                 // change category for all items to the default category
2650                 $query = 'UPDATE '.sql_table('item')." SET icat=$destcatid WHERE icat=$catid";
2651                 sql_query($query);
2652
2653                 // delete all associated plugin options
2654                 NucleusPlugin::_deleteOptionValues('category', $catid);
2655
2656                 // delete category
2657                 $query = 'DELETE FROM '.sql_table('category').' WHERE catid=' .$catid;
2658                 sql_query($query);
2659
2660                 $manager->notify('PostDeleteCategory', array('catid' => $catid));
2661
2662         }
2663
2664         function moveOneCategory($catid, $destblogid) {
2665                 global $manager, $member;
2666
2667                 $catid = intval($catid);
2668                 $destblogid = intval($destblogid);
2669
2670                 $blogid = getBlogIDFromCatID($catid);
2671
2672                 // mover should have admin rights on both blogs
2673                 if (!$member->blogAdminRights($blogid))
2674                         return _ERROR_DISALLOWED;
2675                 if (!$member->blogAdminRights($destblogid))
2676                         return _ERROR_DISALLOWED;
2677
2678                 // cannot move to self
2679                 if ($blogid == $destblogid)
2680                         return _ERROR_MOVETOSELF;
2681
2682                 // get blogs
2683                 $blog =& $manager->getBlog($blogid);
2684                 $destblog =& $manager->getBlog($destblogid);
2685
2686                 // check if the category is valid
2687                 if (!$blog || !$blog->isValidCategory($catid))
2688                         return _ERROR_NOSUCHCATEGORY;
2689
2690                 // don't allow default category to be moved
2691                 if ($blog->getDefaultCategory() == $catid)
2692                         return _ERROR_MOVEDEFCATEGORY;
2693
2694                 $manager->notify(
2695                         'PreMoveCategory',
2696                         array(
2697                                 'catid' => &$catid,
2698                                 'sourceblog' => &$blog,
2699                                 'destblog' => &$destblog
2700                         )
2701                 );
2702
2703                 // update comments table (cblog)
2704                 $query = 'SELECT inumber FROM '.sql_table('item').' WHERE icat='.$catid;
2705                 $items = sql_query($query);
2706                 while ($oItem = mysql_fetch_object($items)) {
2707                         sql_query('UPDATE '.sql_table('comment').' SET cblog='.$destblogid.' WHERE citem='.$oItem->inumber);
2708                 }
2709
2710                 // update items (iblog)
2711                 $query = 'UPDATE '.sql_table('item').' SET iblog='.$destblogid.' WHERE icat='.$catid;
2712                 sql_query($query);
2713
2714                 // move category
2715                 $query = 'UPDATE '.sql_table('category').' SET cblog='.$destblogid.' WHERE catid='.$catid;
2716                 sql_query($query);
2717
2718                 $manager->notify(
2719                         'PostMoveCategory',
2720                         array(
2721                                 'catid' => &$catid,
2722                                 'sourceblog' => &$blog,
2723                                 'destblog' => $destblog
2724                         )
2725                 );
2726
2727         }
2728
2729         function action_blogsettingsupdate() {
2730                 global $member, $manager;
2731
2732                 $blogid = intRequestVar('blogid');
2733
2734                 $member->blogAdminRights($blogid) or $this->disallow();
2735
2736                 $blog =& $manager->getBlog($blogid);
2737
2738                 $notify                 = trim(postVar('notify'));
2739                 $shortname              = trim(postVar('shortname'));
2740                 $updatefile             = trim(postVar('update'));
2741
2742                 $notifyComment  = intPostVar('notifyComment');
2743                 $notifyVote             = intPostVar('notifyVote');
2744                 $notifyNewItem  = intPostVar('notifyNewItem');
2745
2746                 if ($notifyComment == 0)        $notifyComment = 1;
2747                 if ($notifyVote == 0)           $notifyVote = 1;
2748                 if ($notifyNewItem == 0)        $notifyNewItem = 1;
2749
2750                 $notifyType = $notifyComment * $notifyVote * $notifyNewItem;
2751
2752
2753                 if ($notify) {
2754                         $not =& new NOTIFICATION($notify);
2755                         if (!$not->validAddresses())
2756                                 $this->error(_ERROR_BADNOTIFY);
2757
2758                 }
2759
2760                 if (!isValidShortName($shortname))
2761                         $this->error(_ERROR_BADSHORTBLOGNAME);
2762
2763                 if (($blog->getShortName() != $shortname) && $manager->existsBlog($shortname))
2764                         $this->error(_ERROR_DUPSHORTBLOGNAME);
2765
2766                 // check if update file is writable
2767                 if ($updatefile && !is_writeable($updatefile))
2768                         $this->error(_ERROR_UPDATEFILE);
2769
2770                 $blog->setName(trim(postVar('name')));
2771                 $blog->setShortName($shortname);
2772                 $blog->setNotifyAddress($notify);
2773                 $blog->setNotifyType($notifyType);
2774                 $blog->setMaxComments(postVar('maxcomments'));
2775                 $blog->setCommentsEnabled(postVar('comments'));
2776                 $blog->setTimeOffset(postVar('timeoffset'));
2777                 $blog->setUpdateFile($updatefile);
2778                 $blog->setURL(trim(postVar('url')));
2779                 $blog->setDefaultSkin(intPostVar('defskin'));
2780                 $blog->setDescription(trim(postVar('desc')));
2781                 $blog->setPublic(postVar('public'));
2782                 $blog->setPingUserland(postVar('pinguserland'));
2783                 $blog->setConvertBreaks(intPostVar('convertbreaks'));
2784                 $blog->setAllowPastPosting(intPostVar('allowpastposting'));
2785                 $blog->setDefaultCategory(intPostVar('defcat'));
2786                 $blog->setSearchable(intPostVar('searchable'));
2787
2788                 $blog->writeSettings();
2789
2790                 // store plugin options
2791                 $aOptions = requestArray('plugoption');
2792                 NucleusPlugin::_applyPluginOptions($aOptions);
2793                 $manager->notify('PostPluginOptionsUpdate',array('context' => 'blog', 'blogid' => $blogid, 'blog' => &$blog));
2794
2795
2796                 $this->action_overview(_MSG_SETTINGSCHANGED);
2797         }
2798
2799         function action_deleteblog() {
2800                 global $member, $CONF, $manager;
2801
2802                 $blogid = intRequestVar('blogid');
2803
2804                 $member->blogAdminRights($blogid) or $this->disallow();
2805
2806                 // check if blog is default blog
2807                 if ($CONF['DefaultBlog'] == $blogid)
2808                         $this->error(_ERROR_DELDEFBLOG);
2809
2810                 $blog =& $manager->getBlog($blogid);
2811
2812                 $this->pagehead();
2813                 ?>
2814                         <h2><?php echo _DELETE_CONFIRM?></h2>
2815
2816                         <p><?php echo _WARNINGTXT_BLOGDEL?>
2817                         </p>
2818
2819                         <div>
2820                         <?php echo _CONFIRMTXT_BLOG?><b><?php echo  htmlspecialchars($blog->getName())?></b>
2821                         </div>
2822
2823                         <form method="post" action="index.php"><div>
2824                         <input type="hidden" name="action" value="deleteblogconfirm" />
2825                         <?php $manager->addTicketHidden() ?>
2826                         <input type="hidden" name="blogid" value="<?php echo  $blogid; ?>" />
2827                         <input type="submit" tabindex="10" value="<?php echo _DELETE_CONFIRM_BTN?>" />
2828                         </div></form>
2829                 <?php
2830                 $this->pagefoot();
2831         }
2832
2833         function action_deleteblogconfirm() {
2834                 global $member, $CONF, $manager;
2835
2836                 $blogid = intRequestVar('blogid');
2837
2838                 $manager->notify('PreDeleteBlog', array('blogid' => $blogid));
2839
2840                 $member->blogAdminRights($blogid) or $this->disallow();
2841
2842                 // check if blog is default blog
2843                 if ($CONF['DefaultBlog'] == $blogid)
2844                         $this->error(_ERROR_DELDEFBLOG);
2845
2846                 // delete all comments
2847                 $query = 'DELETE FROM '.sql_table('comment').' WHERE cblog='.$blogid;
2848                 sql_query($query);
2849
2850                 // delete all items
2851                 $query = 'DELETE FROM '.sql_table('item').' WHERE iblog='.$blogid;
2852                 sql_query($query);
2853
2854                 // delete all team members
2855                 $query = 'DELETE FROM '.sql_table('team').' WHERE tblog='.$blogid;
2856                 sql_query($query);
2857
2858                 // delete all bans
2859                 $query = 'DELETE FROM '.sql_table('ban').' WHERE blogid='.$blogid;
2860                 sql_query($query);
2861
2862                 // delete all categories
2863                 $query = 'DELETE FROM '.sql_table('category').' WHERE cblog='.$blogid;
2864                 sql_query($query);
2865
2866                 // delete all associated plugin options
2867                 NucleusPlugin::_deleteOptionValues('blog', $blogid);
2868
2869                 // delete the blog itself
2870                 $query = 'DELETE FROM '.sql_table('blog').' WHERE bnumber='.$blogid;
2871                 sql_query($query);
2872
2873                 $manager->notify('PostDeleteBlog', array('blogid' => $blogid));
2874
2875                 $this->action_overview(_DELETED_BLOG);
2876         }
2877
2878         function action_memberdelete() {
2879                 global $member, $manager;
2880
2881                 $memberid = intRequestVar('memberid');
2882
2883                 ($member->getID() == $memberid) or $member->isAdmin() or $this->disallow();
2884
2885                 $mem = MEMBER::createFromID($memberid);
2886
2887                 $this->pagehead();
2888                 ?>
2889                         <h2><?php echo _DELETE_CONFIRM?></h2>
2890
2891                         <p><?php echo _CONFIRMTXT_MEMBER?><b><?php echo  $mem->getDisplayName() ?></b>
2892                         </p>
2893
2894                         <p>
2895                         Please note that media files will <b>NOT</b> be deleted. (At least not in this Nucleus version)
2896                         </p>
2897
2898                         <form method="post" action="index.php"><div>
2899                         <input type="hidden" name="action" value="memberdeleteconfirm" />
2900                         <?php $manager->addTicketHidden() ?>
2901                         <input type="hidden" name="memberid" value="<?php echo  $memberid; ?>" />
2902                         <input type="submit" tabindex="10" value="<?php echo _DELETE_CONFIRM_BTN?>" />
2903                         </div></form>
2904                 <?php
2905                 $this->pagefoot();
2906         }
2907
2908         function action_memberdeleteconfirm() {
2909                 global $member;
2910
2911                 $memberid = intRequestVar('memberid');
2912
2913                 ($member->getID() == $memberid) or $member->isAdmin() or $this->disallow();
2914
2915                 $error = $this->deleteOneMember($memberid);
2916                 if ($error)
2917                         $this->error($error);
2918
2919                 if ($member->isAdmin())
2920                         $this->action_usermanagement();
2921                 else
2922                         $this->action_overview(_DELETED_MEMBER);
2923         }
2924
2925         // (static)
2926         function deleteOneMember($memberid) {
2927                 global $manager;
2928
2929                 $memberid = intval($memberid);
2930                 $mem = MEMBER::createFromID($memberid);
2931
2932                 if (!$mem->canBeDeleted())
2933                         return _ERROR_DELETEMEMBER;
2934
2935                 $manager->notify('PreDeleteMember', array('member' => &$mem));
2936
2937                 $query = 'DELETE FROM '.sql_table('member').' WHERE mnumber='.$memberid;
2938                 sql_query($query);
2939
2940                 $query = 'DELETE FROM '.sql_table('team').' WHERE tmember='.$memberid;
2941                 sql_query($query);
2942
2943                 $query = 'DELETE FROM '.sql_table('activation').' WHERE vmember='.$memberid;
2944                 sql_query($query);
2945
2946                 // delete all associated plugin options
2947                 NucleusPlugin::_deleteOptionValues('member', $memberid);
2948
2949                 $manager->notify('PostDeleteMember', array('member' => &$mem));
2950
2951                 return '';
2952         }
2953
2954         function action_createnewlog() {
2955                 global $member, $CONF, $manager;
2956
2957                 // Only Super-Admins can do this
2958                 $member->isAdmin() or $this->disallow();
2959
2960                 $this->pagehead();
2961
2962                 echo '<p><a href="index.php?action=manage">(',_BACKTOMANAGE,')</a></p>';
2963                 ?>
2964                 <h2><?php echo _EBLOG_CREATE_TITLE?></h2>
2965
2966                 <h3>_ADMIN_NOTABILIA</h3>
2967
2968                 <p>_ADMIN_PLEASE_READ</p>
2969
2970                 <p>_ADMIN_HOW_TO_ACCESS</p>
2971
2972                 <ol>
2973                         <li>_ADMIN_SIMPLE_WAY</li>
2974                         <li>_ADMIN_DIFFICULT_WAY</li>
2975                 </ol>
2976
2977                 <h3>_ADMIN_HOW_TO_CREATE</h3>
2978
2979                 <p>
2980                 <?php echo _EBLOG_CREATE_TEXT?>
2981                 </p>
2982
2983                 <form method="post" action="index.php"><div>
2984
2985                 <input type="hidden" name="action" value="addnewlog" />
2986                 <?php $manager->addTicketHidden() ?>
2987
2988
2989                 <table><tr>
2990                         <td><?php echo _EBLOG_NAME?></td>
2991                         <td><input name="name" tabindex="10" size="40" maxlength="60" /></td>
2992                 </tr><tr>
2993                         <td><?php echo _EBLOG_SHORTNAME?>
2994                                 <?php help('shortblogname'); ?>
2995                         </td>
2996                         <td><input name="shortname" tabindex="20" maxlength="15" size="15" /></td>
2997                 </tr><tr>
2998                         <td><?php echo _EBLOG_DESC?></td>
2999                         <td><input name="desc" tabindex="30" maxlength="200" size="40" /></td>
3000                 </tr><tr>
3001                         <td><?php echo _EBLOG_DEFSKIN?>
3002                                 <?php help('blogdefaultskin'); ?>
3003                         </td>
3004                         <td>
3005                                 <?php
3006                                         $query =  'SELECT sdname as text, sdnumber as value'
3007                                                    . ' FROM '.sql_table('skin_desc');
3008                                         $template['name'] = 'defskin';
3009                                         $template['tabindex'] = 50;
3010                                         $template['selected'] = $CONF['BaseSkin'];      // set default selected skin to be globally defined base skin
3011                                         showlist($query,'select',$template);
3012                                 ?>
3013                         </td>
3014                 </tr><tr>
3015                         <td><?php echo _EBLOG_OFFSET?>
3016                                 <?php help('blogtimeoffset'); ?>
3017                                 <br /><?php echo _EBLOG_STIME?> <b><?php echo  strftime("%H:%M",time()); ?></b>
3018                         </td>
3019                         <td><input name="timeoffset" tabindex="110" size="3" value="0" /></td>
3020                 </tr><tr>
3021                         <td><?php echo _EBLOG_ADMIN?>
3022                                 <?php help('blogadmin'); ?>
3023                         </td>
3024                         <td><?php echo _EBLOG_ADMIN_MSG?></td>
3025                 </tr><tr>
3026                         <td><?php echo _EBLOG_CREATE?></td>
3027                         <td><input type="submit" tabindex="120" value="<?php echo _EBLOG_CREATE_BTN?>" onclick="return checkSubmit();" /></td>
3028                 </tr></table>
3029
3030                 </div></form>
3031                 <?php
3032                 $this->pagefoot();
3033         }
3034
3035         function action_addnewlog() {
3036                 global $member, $manager, $CONF;
3037
3038                 // Only Super-Admins can do this
3039                 $member->isAdmin() or $this->disallow();
3040
3041                 $bname                  = trim(postVar('name'));
3042                 $bshortname             = trim(postVar('shortname'));
3043                 $btimeoffset    = postVar('timeoffset');
3044                 $bdesc                  = trim(postVar('desc'));
3045                 $bdefskin               = postVar('defskin');
3046
3047                 if (!isValidShortName($bshortname))
3048                         $this->error(_ERROR_BADSHORTBLOGNAME);
3049
3050                 if ($manager->existsBlog($bshortname))
3051                         $this->error(_ERROR_DUPSHORTBLOGNAME);
3052
3053                 $manager->notify(
3054                         'PreAddBlog',
3055                         array(
3056                                 'name' => &$bname,
3057                                 'shortname' => &$bshortname,
3058                                 'timeoffset' => &$btimeoffset,
3059                                 'description' => &$bdescription,
3060                                 'defaultskin' => &$bdefskin
3061                         )
3062                 );
3063
3064
3065                 // add slashes for sql queries
3066                 $bname =                addslashes($bname);
3067                 $bshortname =   addslashes($bshortname);
3068                 $btimeoffset =  addslashes($btimeoffset);
3069                 $bdesc =                addslashes($bdesc);
3070                 $bdefskin =     addslashes($bdefskin);
3071
3072                 // create blog
3073                 $query = 'INSERT INTO '.sql_table('blog')." (bname, bshortname, bdesc, btimeoffset, bdefskin) VALUES ('$bname', '$bshortname', '$bdesc', '$btimeoffset', '$bdefskin')";
3074                 sql_query($query);
3075                 $blogid = mysql_insert_id();
3076                 $blog   =& $manager->getBlog($blogid);
3077
3078                 // create new category
3079                 sql_query('INSERT INTO '.sql_table('category')." (cblog, cname, cdesc) VALUES ($blogid, 'General','Items that do not fit in other categories')");
3080                 $catid = mysql_insert_id();
3081
3082                 // set as default category
3083                 $blog->setDefaultCategory($catid);
3084                 $blog->writeSettings();
3085
3086                 // create team member
3087                 $memberid = $member->getID();
3088                 $query = 'INSERT INTO '.sql_table('team')." (tmember, tblog, tadmin) VALUES ($memberid, $blogid, 1)";
3089                 sql_query($query);
3090
3091
3092                 $blog->additem($blog->getDefaultCategory(),'First Item','ã\81\93ã\82\8cã\81¯ã\81\82ã\81ªã\81\9fã\81Eweblogã\81«ã\81\8aã\81\91ã\82\8bæ\9c\80å\88\9dã\81\82¢ã\82¤ã\83\81E\83 ã\81§ã\81\99ã\80\82è\81\94±ã\81«å\89\8aé\99¤ã\81\97ã\81¦ã\81\81E\81\9fã\81 ã\81\81E\81¦ã\81\8bã\81¾ã\81\81E\81¾ã\81\9bã\82\93ã\80\81E,'',$blogid, $memberid,$blog->getCorrectTime(),0,0,0);
3093
3094                 $manager->notify(
3095                         'PostAddBlog',
3096                         array(
3097                                 'blog' => &$blog
3098                         )
3099                 );
3100
3101                 $manager->notify(
3102                         'PostAddCategory',
3103                         array(
3104                                 'catid' => $catid
3105                         )
3106                 );
3107
3108                 $this->pagehead();
3109                 ?>
3110                 <h2>æ\96°ã\81\97ã\81\84weblogã\81\8cä½\9cæ\81\81\95ã\82\8cã\81¾ã\81\97ã\81\9f</h2>
3111
3112                 <p>æ\96°ã\81\97ã\81\84weblog ã\80\81E?php echo htmlspecialchars($bname)?>ã\80\8dã\81\8cä½\9cæ\81\81\95ã\82\8cã\81¾ã\81\97ã\81\9fã\80\82ç¶\9aã\81\91ã\81¦ã\80\81ã\81\93ã\82\8cã\81«ã\82¢ã\82¯ã\82»ã\82¹ã\81\99ã\82\8bã\81\9fã\82\81ã\81«ä»¥ä¸\8bã\81\81©ã\81¡ã\82\89ã\81\8bã\81®æ\89\8bé \81E\81«é\80²ã\82\93ã\81§ã\81\8fã\81 ã\81\95ã\81\84ã\80\81E/p>
3113
3114                 <ol>
3115                         <li><a href="#index_php">ç°¡å\8d\98ã\81ªæ\96¹æ³\81E ä¸\8bã\81\82³ã\83¼ã\83\89ã\82\92è²¼ä»\98ã\81\91ã\81\81E<code><?php echo htmlspecialchars($bshortname)?>.php</code> ã\81¨ã\81\81E\81\86ã\83\95ã\82¡ã\82¤ã\83«ã\82\92ä½\9cæ\81\81\99ã\82\8b</a></li>
3116                         <li><a href="#skins">é«\98度ã\81ªæ\96¹æ³\81E ç\8f¾å\9c¨ä½¿ç\94¨ã\81\97ã\81¦ã\81\81E\82\8bã\82¹ã\82­ã\83³ã\81«æ\96°ã\81\97ã\81\84weblogã\82\92å±\95é\96\8bã\81\95ã\81\9bã\82\8bã\81\9fã\82\81ã\81Eè¨\98è¿°ã\82\92å\8a ã\81\88ã\82\8b</a></li>
3117                 </ol>
3118
3119                 <h3><a id="index_php">æ\96¹æ³\81E1: <code><?php echo htmlspecialchars($bshortname)?>.php</code> ã\81¨ã\81\81E\81\86ã\83\95ã\82¡ã\82¤ã\83«ã\82\92ä½\9cæ\81E</a></h3>
3120
3121                 <p><code><?php echo htmlspecialchars($bshortname)?>.php</code> ã\81¨ã\81\81E\81\86ã\83\95ã\82¡ã\82¤ã\83«ã\82\92ä½\9cæ\81\81\97ã\81¦ã\80\81中身ã\81«ä»¥ä¸\8bã\81\82³ã\83¼ã\83\89ã\82\92è²¼ã\82\8aä»\98ã\81\91ã\82\81E</p>
3122 <pre><code>&lt;?php
3123
3124 $CONF['Self'] = '<b><?php echo htmlspecialchars($bshortname)?>.php</b>';
3125
3126 include('<i>./config.php</i>');
3127
3128 selectBlog('<b><?php echo htmlspecialchars($bshortname)?></b>');
3129 selector();
3130
3131 ?&gt;</code></pre>
3132
3133                 <p>ã\81\99ã\81§ã\81«ã\81\82ã\82\8b<code>index.php</code>ã\81¨å\90\8cã\81\98ã\83\81E\82£ã\83¬ã\82¯ã\83\88ã\83ªã\81«ã\82¢ã\83\81E\81\83­ã\83¼ã\83\89ã\81\97ã\81¾ã\81\99ã\80\81E/p>
3134
3135                 <p>æ\96°ã\81\97ã\81\84weblogã\81®ä½\9cæ\81\82\92å®\8cäº\81E\81\99ã\82\8bã\81\9fã\82\81ã\81«ã\81¯ã\80\81ä¸\8bã\81«ã\81\93ã\81\83\95ã\82¡ã\82¤ã\83«ã\81®URLã\82\92å\81\8a\9bã\81\97ã\81¦ã\81\8fã\81 ã\81\95ã\81\84ã\80\81E(ã\81\99ã\81§ã\81«ç\94¨æ\84\8fã\81\97ã\81\9få\80¤ã\81§å\90\88ã\81£ã\81¦ã\81\81E\82\8bã\81¨ã\81¯æ\80\9dã\81\84ã\81¾ã\81\99ã\81\8cä¿\9d証ã\81¯ã\81\97ã\81¾ã\81\9bã\82\93):</p>
3136
3137
3138                 <form action="index.php" method="post"><div>
3139                         <input type="hidden" name="action" value="addnewlog2" />
3140                         <?php $manager->addTicketHidden() ?>
3141                         <input type="hidden" name="blogid" value="<?php echo intval($blogid)?>" />
3142                         <table><tr>
3143                                 <td><?php echo _EBLOG_URL?></td>
3144                                 <td><input name="url" maxlength="100" size="40" value="<?php echo htmlspecialchars($CONF['IndexURL'].$bshortname.'.php')?>" /></td>
3145                         </tr><tr>
3146                                 <td><?php echo _EBLOG_CREATE?></td>
3147                                 <td><input type="submit" value="<?php echo _EBLOG_CREATE_BTN?>" onclick="return checkSubmit();" /></td>
3148                         </tr></table>
3149                 </div></form>
3150
3151                 <h3><a id="skins">æ\96¹æ³\81E2: ç\8f¾å\9c¨ä½¿ç\94¨ã\81\97ã\81¦ã\81\81E\82\8bã\82¹ã\82­ã\83³ã\81«æ\96°ã\81\97ã\81\84weblogã\82\92å±\95é\96\8bã\81\99ã\82\8bè¨\98è¿°ã\82\92å\8a ã\81\88ã\82\8b</a></h3>
3152
3153                 <p>æ\96°ã\81\97ã\81\84weblogã\81®ä½\9cæ\81\82\92å®\8cäº\81E\81\99ã\82\8bã\81\9fã\82\81ã\81«ã\81¯ã\80\81ä¸\8bã\81«URLã\82\92å\81\8a\9bã\81\97ã\81¦ã\81\8fã\81 ã\81\95ã\81\84ã\80\81E(大æ\8aµã\81¯æ\97¢å­\98blogã\81¨å\90\8cã\81\98URL)</p>
3154
3155
3156                 <form action="index.php" method="post"><div>
3157                         <input type="hidden" name="action" value="addnewlog2" />
3158                         <?php $manager->addTicketHidden() ?>
3159                         <input type="hidden" name="blogid" value="<?php echo intval($blogid)?>" />
3160                         <table><tr>
3161                                 <td><?php echo _EBLOG_URL?></td>
3162                                 <td><input name="url" maxlength="100" size="40" /></td>
3163                         </tr><tr>
3164                                 <td><?php echo _EBLOG_CREATE?></td>
3165                                 <td><input type="submit" value="<?php echo _EBLOG_CREATE_BTN?>" onclick="return checkSubmit();" /></td>
3166                         </tr></table>
3167                 </div></form>
3168
3169                 <?php           $this->pagefoot();
3170
3171         }
3172
3173         function action_addnewlog2() {
3174                 global $member, $manager;
3175
3176                 $member->blogAdminRights($blogid) or $this->disallow();
3177
3178                 $burl   = requestVar('url');
3179                 $blogid = intRequestVar('blogid');
3180
3181                 $blog =& $manager->getBlog($blogid);
3182                 $blog->setURL(trim($burl));
3183                 $blog->writeSettings();
3184
3185                 $this->action_overview(_MSG_NEWBLOG);
3186         }
3187
3188         function action_skinieoverview() {
3189                 global $member, $DIR_LIBS, $manager;
3190
3191                 $member->isAdmin() or $this->disallow();
3192
3193                 // load skinie class
3194                 include_once($DIR_LIBS . 'skinie.php');
3195
3196                 $this->pagehead();
3197
3198                 echo '<p><a href="index.php?action=manage">(',_BACKTOMANAGE,')</a></p>';
3199
3200         ?>
3201                 <h2><?php echo _SKINIE_TITLE_IMPORT?></h2>
3202
3203                                 <p><label for="skinie_import_local"><?php echo _SKINIE_LOCAL?></label>
3204                                 <?php                                   global $DIR_SKINS;
3205
3206                                         $candidates = SKINIMPORT::searchForCandidates($DIR_SKINS);
3207
3208                                         if (sizeof($candidates) > 0) {
3209                                                 ?>
3210                                                         <form method="post" action="index.php"><div>
3211                                                                 <input type="hidden" name="action" value="skinieimport" />
3212                                                                 <?php $manager->addTicketHidden() ?>
3213                                                                 <input type="hidden" name="mode" value="file" />
3214                                                                 <select name="skinfile" id="skinie_import_local">
3215                                                                 <?php                                                                   foreach ($candidates as $skinname => $skinfile) {
3216                                                                                 $html = htmlspecialchars($skinfile);
3217                                                                                 echo '<option value="',$html,'">',$skinname,'</option>';
3218                                                                         }
3219                                                                 ?>
3220                                                                 </select>
3221                                                                 <input type="submit" value="<?php echo _SKINIE_BTN_IMPORT?>" />
3222                                                         </div></form>
3223                                                 <?php                                   } else {
3224                                                 echo _SKINIE_NOCANDIDATES;
3225                                         }
3226                                 ?>
3227                                 </p>
3228
3229                                 <p><em><?php echo _OR?></em></p>
3230
3231                                 <form method="post" action="index.php"><p>
3232                                         <?php $manager->addTicketHidden() ?>
3233                                         <input type="hidden" name="action" value="skinieimport" />
3234                                         <input type="hidden" name="mode" value="url" />
3235                                         <label for="skinie_import_url"><?php echo _SKINIE_FROMURL?></label>
3236                                         <input type="text" name="skinfile" id="skinie_import_url" size="60" value="http://" />
3237                                         <input type="submit" value="<?php echo _SKINIE_BTN_IMPORT?>" />
3238                                 </p></form>
3239
3240
3241                 <h2><?php echo _SKINIE_TITLE_EXPORT?></h2>
3242                 <form method="post" action="index.php"><div>
3243                         <input type="hidden" name="action" value="skinieexport" />
3244                         <?php $manager->addTicketHidden() ?>
3245
3246                         <p><?php echo _SKINIE_EXPORT_INTRO?></p>
3247
3248                         <table><tr>
3249                                 <th colspan="2"><?php echo _SKINIE_EXPORT_SKINS?></th>
3250                         </tr><tr>
3251         <?php           // show list of skins
3252                 $res = sql_query('SELECT * FROM '.sql_table('skin_desc'));
3253                 while ($skinObj = mysql_fetch_object($res)) {
3254                         $id = 'skinexp' . $skinObj->sdnumber;
3255                         echo '<td><input type="checkbox" name="skin[',$skinObj->sdnumber,']"  id="',$id,'" />';
3256                         echo '<label for="',$id,'">',htmlspecialchars($skinObj->sdname),'</label></td>';
3257                         echo '<td>',htmlspecialchars($skinObj->sddesc),'</td>';
3258                         echo '</tr><tr>';
3259                 }
3260
3261                 echo '<th colspan="2">',_SKINIE_EXPORT_TEMPLATES,'</th></tr><tr>';
3262
3263                 // show list of templates
3264                 $res = sql_query('SELECT * FROM '.sql_table('template_desc'));
3265                 while ($templateObj = mysql_fetch_object($res)) {
3266                         $id = 'templateexp' . $templateObj->tdnumber;
3267                         echo '<td><input type="checkbox" name="template[',$templateObj->tdnumber,']" id="',$id,'" />';
3268                         echo '<label for="',$id,'">',htmlspecialchars($templateObj->tdname),'</label></td>';
3269                         echo '<td>',htmlspecialchars($templateObj->tddesc),'</td>';
3270                         echo '</tr><tr>';
3271                 }
3272
3273         ?>
3274                                 <th colspan="2"><?php echo _SKINIE_EXPORT_EXTRA?></th>
3275                         </tr><tr>
3276                                 <td colspan="2"><textarea cols="40" rows="5" name="info"></textarea></td>
3277                         </tr><tr>
3278                                 <th colspan="2"><?php echo _SKINIE_TITLE_EXPORT?></th>
3279                         </tr><tr>
3280                                 <td colspan="2"><input type="submit" value="<?php echo _SKINIE_BTN_EXPORT?>" /></td>
3281                         </tr></table>
3282                 </div></form>
3283
3284         <?php
3285                 $this->pagefoot();
3286
3287         }
3288
3289         function action_skinieimport() {
3290                 global $member, $DIR_LIBS, $DIR_SKINS, $manager;
3291
3292                 $member->isAdmin() or $this->disallow();
3293
3294                 // load skinie class
3295                 include_once($DIR_LIBS . 'skinie.php');
3296
3297                 $skinFileRaw= postVar('skinfile');
3298                 $mode           = postVar('mode');
3299
3300                 $importer =& new SKINIMPORT();
3301
3302                 // get full filename
3303                 if ($mode == 'file')
3304                 {
3305                         $skinFile = $DIR_SKINS . $skinFileRaw . '/skinbackup.xml';
3306
3307                         // backwards compatibilty (in v2.0, exports were saved as skindata.xml)
3308                         if (!file_exists($skinFile))
3309                                 $skinFile = $DIR_SKINS . $skinFileRaw . '/skindata.xml';
3310                 } else {
3311                         $skinFile = $skinFileRaw;
3312                 }
3313
3314                 // read only metadata
3315                 $error = $importer->readFile($skinFile, 1);
3316
3317
3318                 if ($error) $this->error($error);
3319
3320                 $this->pagehead();
3321
3322                 echo '<p><a href="index.php?action=skinieoverview">(',_BACK,')</a></p>';
3323                 ?>
3324                 <h2><?php echo _SKINIE_CONFIRM_TITLE?></h2>
3325
3326                 <ul>
3327                         <li><p><strong><?php echo _SKINIE_INFO_GENERAL?></strong> <?php echo htmlspecialchars($importer->getInfo())?></p></li>
3328                         <li><p><strong><?php echo _SKINIE_INFO_SKINS?></strong> <?php echo implode(' <em>'._AND.'</em> ',$importer->getSkinNames())?></p></li>
3329                         <li><p><strong><?php echo _SKINIE_INFO_TEMPLATES?></strong> <?php echo implode(' <em>'._AND.'</em> ',$importer->getTemplateNames())?></p></li>
3330                         <li><p><strong style="color: red;"><?php echo _SKINIE_INFO_SKINCLASH?></strong> <?php echo implode(' <em>'._AND.'</em> ',$importer->checkSkinNameClashes())?></p></li>
3331                         <li><p><strong style="color: red;"><?php echo _SKINIE_INFO_TEMPLCLASH?></strong> <?php echo implode(' <em>'._AND.'</em> ',$importer->checkTemplateNameClashes())?></p></li>
3332                 </ul>
3333
3334                 <form method="post" action="index.php"><div>
3335                         <input type="hidden" name="action" value="skiniedoimport" />
3336                         <?php $manager->addTicketHidden() ?>
3337                         <input type="hidden" name="skinfile" value="<?php echo htmlspecialchars(postVar('skinfile'))?>" />
3338                         <input type="hidden" name="mode" value="<?php echo htmlspecialchars($mode)?>" />
3339                         <input type="submit" value="<?php echo _SKINIE_CONFIRM_IMPORT?>" />
3340                         <br />
3341                         <input type="checkbox" name="overwrite" value="1" id="cb_overwrite" /><label for="cb_overwrite"><?php echo _SKINIE_CONFIRM_OVERWRITE?></label>
3342                 </div></form>
3343
3344
3345                 <?php
3346                 $this->pagefoot();
3347         }
3348
3349         function action_skiniedoimport() {
3350                 global $member, $DIR_LIBS, $DIR_SKINS;
3351
3352                 $member->isAdmin() or $this->disallow();
3353
3354                 // load skinie class
3355                 include_once($DIR_LIBS . 'skinie.php');
3356
3357                 $skinFileRaw= postVar('skinfile');
3358                 $mode           = postVar('mode');
3359
3360                 $allowOverwrite = intPostVar('overwrite');
3361
3362                 // get full filename
3363                 if ($mode == 'file')
3364                 {
3365                         $skinFile = $DIR_SKINS . $skinFileRaw . '/skinbackup.xml';
3366
3367                         // backwards compatibilty (in v2.0, exports were saved as skindata.xml)
3368                         if (!file_exists($skinFile))
3369                                 $skinFile = $DIR_SKINS . $skinFileRaw . '/skindata.xml';
3370
3371                 } else {
3372                         $skinFile = $skinFileRaw;
3373                 }
3374
3375                 $importer =& new SKINIMPORT();
3376
3377                 $error = $importer->readFile($skinFile);
3378
3379                 if ($error)
3380                         $this->error($error);
3381
3382                 $error = $importer->writeToDatabase($allowOverwrite);
3383
3384                 if ($error)
3385                         $this->error($error);
3386
3387                 $this->pagehead();
3388
3389                 echo '<p><a href="index.php?action=manage">(',_BACKTOMANAGE,')</a></p>';
3390         ?>
3391                 <h2><?php echo _SKINIE_DONE?></h2>
3392
3393                 <ul>
3394                         <li><p><strong><?php echo _SKINIE_INFO_GENERAL?></strong> <?php echo htmlspecialchars($importer->getInfo())?></p></li>
3395                         <li><p><strong><?php echo _SKINIE_INFO_IMPORTEDSKINS?></strong> <?php echo implode(' <em>'._AND.'</em> ',$importer->getSkinNames())?></p></li>
3396                         <li><p><strong><?php echo _SKINIE_INFO_IMPORTEDTEMPLS?></strong> <?php echo implode(' <em>'._AND.'</em> ',$importer->getTemplateNames())?></p></li>
3397                 </ul>
3398
3399         <?php           $this->pagefoot();
3400
3401         }
3402
3403         function action_skinieexport() {
3404                 global $member, $DIR_LIBS;
3405
3406                 $member->isAdmin() or $this->disallow();
3407
3408                 // load skinie class
3409                 include_once($DIR_LIBS . 'skinie.php');
3410
3411                 $aSkins = requestIntArray('skin');
3412                 $aTemplates = requestIntArray('template');
3413
3414                 if (!is_array($aTemplates)) $aTemplates = array();
3415                 if (!is_array($aSkins)) $aSkins = array();
3416
3417                 $skinList = array_keys($aSkins);
3418                 $templateList = array_keys($aTemplates);
3419
3420                 $info = postVar('info');
3421
3422                 $exporter =& new SKINEXPORT();
3423                 foreach ($skinList as $skinId) {
3424                         $exporter->addSkin($skinId);
3425                 }
3426                 foreach ($templateList as $templateId) {
3427                         $exporter->addTemplate($templateId);
3428                 }
3429                 $exporter->setInfo($info);
3430
3431                 $exporter->export();
3432         }
3433
3434         function action_templateoverview() {
3435                 global $member, $manager;
3436
3437                 $member->isAdmin() or $this->disallow();
3438
3439                 $this->pagehead();
3440
3441                 echo '<p><a href="index.php?action=manage">(',_BACKTOMANAGE,')</a></p>';
3442
3443                 echo '<h2>' . _TEMPLATE_TITLE . '</h2>';
3444                 echo '<h3>' . _TEMPLATE_AVAILABLE_TITLE . '</h3>';
3445
3446                 $query = 'SELECT * FROM '.sql_table('template_desc').' ORDER BY tdname';
3447                 $template['content'] = 'templatelist';
3448                 $template['tabindex'] = 10;
3449                 showlist($query,'table',$template);
3450
3451                 echo '<h3>' . _TEMPLATE_NEW_TITLE . '</h3>';
3452
3453                 ?>
3454                 <form method="post" action="index.php"><div>
3455
3456                 <input name="action" value="templatenew" type="hidden" />
3457                 <?php $manager->addTicketHidden() ?>
3458                 <table><tr>
3459                         <td><?php echo _TEMPLATE_NAME?> <?php help('shortnames');?></td>
3460                         <td><input name="name" tabindex="10010" maxlength="20" size="20" /></td>
3461                 </tr><tr>
3462                         <td><?php echo _TEMPLATE_DESC?></td>
3463                         <td><input name="desc" tabindex="10020" maxlength="200" size="50" /></td>
3464                 </tr><tr>
3465                         <td><?php echo _TEMPLATE_CREATE?></td>
3466                         <td><input type="submit" tabindex="10030" value="<?php echo _TEMPLATE_CREATE_BTN?>" onclick="return checkSubmit();" /></td>
3467                 </tr></table>
3468
3469                 </div></form>
3470
3471                 <?php
3472                 $this->pagefoot();
3473         }
3474
3475         function action_templateedit($msg = '') {
3476                 global $member, $manager;
3477
3478                 $templateid = intRequestVar('templateid');
3479
3480                 $member->isAdmin() or $this->disallow();
3481
3482                 $extrahead = '<script type="text/javascript" src="javascript/templateEdit.js"></script>';
3483                 $extrahead .= '<script type="text/javascript">setTemplateEditText("'.addslashes(_EDITTEMPLATE_EMPTY).'");</script>';
3484
3485                 $this->pagehead($extrahead);
3486
3487                 $templatename = TEMPLATE::getNameFromId($templateid);
3488                 $templatedescription = TEMPLATE::getDesc($templateid);
3489                 $template =& $manager->getTemplate($templatename);
3490
3491                 ?>
3492                 <p>
3493                 <a href="index.php?action=templateoverview">(<?php echo _TEMPLATE_BACK?>)</a>
3494                 </p>
3495
3496                 <h2><?php echo _TEMPLATE_EDIT_TITLE?> '<?php echo  $templatename; ?>'</h2>
3497
3498                 <?php                                   if ($msg) echo "<p>"._MESSAGE.": $msg</p>";
3499                 ?>
3500
3501                 <p><?php echo _TEMPLATE_EDIT_MSG?></p>
3502
3503                 <form method="post" action="index.php">
3504                 <div>
3505
3506                 <input type="hidden" name="action" value="templateupdate" />
3507                 <?php $manager->addTicketHidden() ?>
3508                 <input type="hidden" name="templateid" value="<?php echo  $templateid; ?>" />
3509
3510                 <table><tr>
3511                         <th colspan="2"><?php echo _TEMPLATE_SETTINGS?></th>
3512                 </tr><tr>
3513                         <td><?php echo _TEMPLATE_NAME?> <?php help('shortnames');?></td>
3514                         <td><input name="tname" tabindex="4" size="20" maxlength="20" value="<?php echo  htmlspecialchars($templatename) ?>" /></td>
3515                 </tr><tr>
3516                         <td><?php echo _TEMPLATE_DESC?></td>
3517                         <td><input name="tdesc" tabindex="5" size="50" maxlength="200" value="<?php echo  htmlspecialchars($templatedescription) ?>" /></td>
3518                 </tr><tr>
3519                         <th colspan="2"><?php echo _TEMPLATE_UPDATE?></th>
3520                 </tr><tr>
3521                         <td><?php echo _TEMPLATE_UPDATE?></td>
3522                         <td>
3523                                 <input type="submit" tabindex="6" value="<?php echo _TEMPLATE_UPDATE_BTN?>" onclick="return checkSubmit();" />
3524                                 <input type="reset" tabindex="7" value="<?php echo _TEMPLATE_RESET_BTN?>" />
3525                         </td>
3526                 </tr><tr>
3527                         <th colspan="2"><?php echo _TEMPLATE_ITEMS?> <?php help('templateitems'); ?></th>
3528 <?php   $this->_templateEditRow($template, _TEMPLATE_ITEMHEADER, 'ITEM_HEADER', '', 8);
3529         $this->_templateEditRow($template, _TEMPLATE_ITEMBODY, 'ITEM', '', 9, 1);
3530         $this->_templateEditRow($template, _TEMPLATE_ITEMFOOTER, 'ITEM_FOOTER', '', 10);
3531         $this->_templateEditRow($template, _TEMPLATE_MORELINK, 'MORELINK', 'morelink', 20);
3532         $this->_templateEditRow($template, _TEMPLATE_EDITLINK, 'EDITLINK', 'editlink', 25);
3533         $this->_templateEditRow($template, _TEMPLATE_NEW, 'NEW', 'new', 30);
3534 ?>
3535                 </tr><tr>
3536                         <th colspan="2"><?php echo _TEMPLATE_COMMENTS_ANY?> <?php help('templatecomments'); ?></th>
3537 <?php   $this->_templateEditRow($template, _TEMPLATE_CHEADER, 'COMMENTS_HEADER', 'commentheaders', 40);
3538         $this->_templateEditRow($template, _TEMPLATE_CBODY, 'COMMENTS_BODY', 'commentbody', 50, 1);
3539         $this->_templateEditRow($template, _TEMPLATE_CFOOTER, 'COMMENTS_FOOTER', 'commentheaders', 60);
3540         $this->_templateEditRow($template, _TEMPLATE_CONE, 'COMMENTS_ONE', 'commentwords', 70);
3541         $this->_templateEditRow($template, _TEMPLATE_CMANY, 'COMMENTS_MANY', 'commentwords', 80);
3542         $this->_templateEditRow($template, _TEMPLATE_CMORE, 'COMMENTS_CONTINUED', 'commentcontinued', 90);
3543         $this->_templateEditRow($template, _TEMPLATE_CMEXTRA, 'COMMENTS_AUTH', 'memberextra', 100);
3544 ?>
3545                 </tr><tr>
3546                         <th colspan="2"><?php echo _TEMPLATE_COMMENTS_NONE?> <?php help('templatecomments'); ?></th>
3547 <?php
3548         $this->_templateEditRow($template, _TEMPLATE_CNONE, 'COMMENTS_NONE', '', 110);
3549 ?>
3550                 </tr><tr>
3551                         <th colspan="2"><?php echo _TEMPLATE_COMMENTS_TOOMUCH?> <?php help('templatecomments'); ?></th>
3552 <?php   $this->_templateEditRow($template, _TEMPLATE_CTOOMUCH, 'COMMENTS_TOOMUCH', '', 120);
3553 ?>
3554                 </tr><tr>
3555                         <th colspan="2"><?php echo _TEMPLATE_ARCHIVELIST?> <?php help('templatearchivelists'); ?></th>
3556 <?php   $this->_templateEditRow($template, _TEMPLATE_AHEADER, 'ARCHIVELIST_HEADER', '', 130);
3557         $this->_templateEditRow($template, _TEMPLATE_AITEM, 'ARCHIVELIST_LISTITEM', '', 140);
3558         $this->_templateEditRow($template, _TEMPLATE_AFOOTER, 'ARCHIVELIST_FOOTER', '', 150);
3559 ?>
3560                 </tr><tr>
3561                         <th colspan="2"><?php echo _TEMPLATE_CATEGORYLIST?> <?php help('templatecategorylists'); ?></th>
3562 <?php   $this->_templateEditRow($template, _TEMPLATE_CATHEADER, 'CATLIST_HEADER', '', 160);
3563         $this->_templateEditRow($template, _TEMPLATE_CATITEM, 'CATLIST_LISTITEM', '', 170);
3564         $this->_templateEditRow($template, _TEMPLATE_CATFOOTER, 'CATLIST_FOOTER', '', 180);
3565 ?>
3566                 </tr><tr>
3567                         <th colspan="2"><?php echo _TEMPLATE_DATETIME?></th>
3568 <?php   $this->_templateEditRow($template, _TEMPLATE_DHEADER, 'DATE_HEADER', 'dateheads', 190);
3569         $this->_templateEditRow($template, _TEMPLATE_DFOOTER, 'DATE_FOOTER', 'dateheads', 200);
3570         $this->_templateEditRow($template, _TEMPLATE_DFORMAT, 'FORMAT_DATE', 'datetime', 210);
3571         $this->_templateEditRow($template, _TEMPLATE_TFORMAT, 'FORMAT_TIME', 'datetime', 220);
3572         $this->_templateEditRow($template, _TEMPLATE_LOCALE, 'LOCALE', 'locale', 230);
3573 ?>
3574                 </tr><tr>
3575                         <th colspan="2"><?php echo _TEMPLATE_IMAGE?> <?php help('templatepopups'); ?></th>
3576 <?php   $this->_templateEditRow($template, _TEMPLATE_PCODE, 'POPUP_CODE', '', 240);
3577         $this->_templateEditRow($template, _TEMPLATE_ICODE, 'IMAGE_CODE', '', 250);
3578         $this->_templateEditRow($template, _TEMPLATE_MCODE, 'MEDIA_CODE', '', 260);
3579 ?>
3580                 </tr><tr>
3581                         <th colspan="2"><?php echo _TEMPLATE_SEARCH?></th>
3582 <?php   $this->_templateEditRow($template, _TEMPLATE_SHIGHLIGHT, 'SEARCH_HIGHLIGHT', 'highlight',270);
3583         $this->_templateEditRow($template, _TEMPLATE_SNOTFOUND, 'SEARCH_NOTHINGFOUND', 'nothingfound',280);
3584 ?>
3585                 </tr><tr>
3586                         <th colspan="2"><?php echo _TEMPLATE_UPDATE?></th>
3587                 </tr><tr>
3588                         <td><?php echo _TEMPLATE_UPDATE?></td>
3589                         <td>
3590                                 <input type="submit" tabindex="290" value="<?php echo _TEMPLATE_UPDATE_BTN?>" onclick="return checkSubmit();" />
3591                                 <input type="reset" tabindex="300" value="<?php echo _TEMPLATE_RESET_BTN?>" />
3592                         </td>
3593                 </tr></table>
3594
3595                 </div>
3596                 </form>
3597                 <?php
3598                 $this->pagefoot();
3599         }
3600
3601         function _templateEditRow(&$template, $description, $name, $help = '', $tabindex = 0, $big = 0) {
3602                 static $count = 1;
3603         ?>
3604                 </tr><tr>
3605                         <td><?php echo $description?> <?php if ($help) help('template'.$help); ?></td>
3606                         <td id="td<?php echo $count?>"><textarea class="templateedit" name="<?php echo $name?>" tabindex="<?php echo $tabindex?>" cols="50" rows="<?php echo $big?10:5?>" id="textarea<?php echo $count?>"><?php echo  htmlspecialchars($template[$name]); ?></textarea></td>
3607         <?php           $count++;
3608         }
3609
3610         function action_templateupdate() {
3611                 global $member;
3612
3613                 $templateid = intRequestVar('templateid');
3614
3615                 $member->isAdmin() or $this->disallow();
3616
3617                 $name = postVar('tname');
3618                 $desc = postVar('tdesc');
3619
3620                 if (!isValidTemplateName($name))
3621                         $this->error(_ERROR_BADTEMPLATENAME);
3622
3623                 if ((TEMPLATE::getNameFromId($templateid) != $name) && TEMPLATE::exists($name))
3624                         $this->error(_ERROR_DUPTEMPLATENAME);
3625
3626
3627                 $name = addslashes($name);
3628                 $desc = addslashes($desc);
3629
3630                 // 1. Remove all template parts
3631                 $query = 'DELETE FROM '.sql_table('template').' WHERE tdesc=' . $templateid;
3632                 sql_query($query);
3633
3634                 // 2. Update description
3635                 $query =  'UPDATE '.sql_table('template_desc').' SET'
3636                            . " tdname='" . $name . "',"
3637                            . " tddesc='" . $desc . "'"
3638                            . " WHERE tdnumber=" . $templateid;
3639                 sql_query($query);
3640
3641                 // 3. Add non-empty template parts
3642                 $this->addToTemplate($templateid, 'ITEM_HEADER', postVar('ITEM_HEADER'));
3643                 $this->addToTemplate($templateid, 'ITEM', postVar('ITEM'));
3644                 $this->addToTemplate($templateid, 'ITEM_FOOTER', postVar('ITEM_FOOTER'));
3645                 $this->addToTemplate($templateid, 'MORELINK', postVar('MORELINK'));
3646                 $this->addToTemplate($templateid, 'EDITLINK', postVar('EDITLINK'));
3647                 $this->addToTemplate($templateid, 'NEW', postVar('NEW'));
3648                 $this->addToTemplate($templateid, 'COMMENTS_HEADER', postVar('COMMENTS_HEADER'));
3649                 $this->addToTemplate($templateid, 'COMMENTS_BODY', postVar('COMMENTS_BODY'));
3650                 $this->addToTemplate($templateid, 'COMMENTS_FOOTER', postVar('COMMENTS_FOOTER'));
3651                 $this->addToTemplate($templateid, 'COMMENTS_CONTINUED', postVar('COMMENTS_CONTINUED'));
3652                 $this->addToTemplate($templateid, 'COMMENTS_TOOMUCH', postVar('COMMENTS_TOOMUCH'));
3653                 $this->addToTemplate($templateid, 'COMMENTS_AUTH', postVar('COMMENTS_AUTH'));
3654                 $this->addToTemplate($templateid, 'COMMENTS_ONE', postVar('COMMENTS_ONE'));
3655                 $this->addToTemplate($templateid, 'COMMENTS_MANY', postVar('COMMENTS_MANY'));
3656                 $this->addToTemplate($templateid, 'COMMENTS_NONE', postVar('COMMENTS_NONE'));
3657                 $this->addToTemplate($templateid, 'ARCHIVELIST_HEADER', postVar('ARCHIVELIST_HEADER'));
3658                 $this->addToTemplate($templateid, 'ARCHIVELIST_LISTITEM', postVar('ARCHIVELIST_LISTITEM'));
3659                 $this->addToTemplate($templateid, 'ARCHIVELIST_FOOTER', postVar('ARCHIVELIST_FOOTER'));
3660                 $this->addToTemplate($templateid, 'CATLIST_HEADER', postVar('CATLIST_HEADER'));
3661                 $this->addToTemplate($templateid, 'CATLIST_LISTITEM', postVar('CATLIST_LISTITEM'));
3662                 $this->addToTemplate($templateid, 'CATLIST_FOOTER', postVar('CATLIST_FOOTER'));
3663                 $this->addToTemplate($templateid, 'DATE_HEADER', postVar('DATE_HEADER'));
3664                 $this->addToTemplate($templateid, 'DATE_FOOTER', postVar('DATE_FOOTER'));
3665                 $this->addToTemplate($templateid, 'FORMAT_DATE', postVar('FORMAT_DATE'));
3666                 $this->addToTemplate($templateid, 'FORMAT_TIME', postVar('FORMAT_TIME'));
3667                 $this->addToTemplate($templateid, 'LOCALE', postVar('LOCALE'));
3668                 $this->addToTemplate($templateid, 'SEARCH_HIGHLIGHT', postVar('SEARCH_HIGHLIGHT'));
3669                 $this->addToTemplate($templateid, 'SEARCH_NOTHINGFOUND', postVar('SEARCH_NOTHINGFOUND'));
3670                 $this->addToTemplate($templateid, 'POPUP_CODE', postVar('POPUP_CODE'));
3671                 $this->addToTemplate($templateid, 'MEDIA_CODE', postVar('MEDIA_CODE'));
3672                 $this->addToTemplate($templateid, 'IMAGE_CODE', postVar('IMAGE_CODE'));
3673
3674
3675                 // jump back to template edit
3676                 $this->action_templateedit(_TEMPLATE_UPDATED);
3677
3678         }
3679
3680         function addToTemplate($id, $partname, $content) {
3681                 $partname = addslashes($partname);
3682                 $content = addslashes($content);
3683
3684                 $id = intval($id);
3685
3686                 // don't add empty parts:
3687                 if (!trim($content)) return -1;
3688
3689                 $query = 'INSERT INTO '.sql_table('template')." (tdesc, tpartname, tcontent) "
3690                            . "VALUES ($id, '$partname', '$content')";
3691                 mysql_query($query) or die("Query error: " . mysql_error());
3692                 return mysql_insert_id();
3693         }
3694
3695         function action_templatedelete() {
3696                 global $member, $manager;
3697
3698                 $member->isAdmin() or $this->disallow();
3699
3700                 $templateid = intRequestVar('templateid');
3701                 // TODO: check if template can be deleted
3702
3703                 $this->pagehead();
3704
3705                 $name = TEMPLATE::getNameFromId($templateid);
3706                 $desc = TEMPLATE::getDesc($templateid);
3707
3708                 ?>
3709                         <h2><?php echo _DELETE_CONFIRM?></h2>
3710
3711                         <p>
3712                         <?php echo _CONFIRMTXT_TEMPLATE?><b><?php echo $name?></b> (<?php echo  htmlspecialchars($desc) ?>)
3713                         </p>
3714
3715                         <form method="post" action="index.php"><div>
3716                                 <input type="hidden" name="action" value="templatedeleteconfirm" />
3717                                 <?php $manager->addTicketHidden() ?>
3718                                 <input type="hidden" name="templateid" value="<?php echo  $templateid ?>" />
3719                                 <input type="submit" tabindex="10" value="<?php echo _DELETE_CONFIRM_BTN?>" />
3720                         </div></form>
3721                 <?php
3722                 $this->pagefoot();
3723         }
3724
3725         function action_templatedeleteconfirm() {
3726                 global $member, $manager;
3727
3728                 $templateid = intRequestVar('templateid');
3729
3730                 $member->isAdmin() or $this->disallow();
3731
3732                 $manager->notify('PreDeleteTemplate', array('templateid' => $templateid));
3733
3734                 // 1. delete description
3735                 sql_query('DELETE FROM '.sql_table('template_desc').' WHERE tdnumber=' . $templateid);
3736
3737                 // 2. delete parts
3738                 sql_query('DELETE FROM '.sql_table('template').' WHERE tdesc=' . $templateid);
3739
3740                 $manager->notify('PostDeleteTemplate', array('templateid' => $templateid));
3741
3742                 $this->action_templateoverview();
3743         }
3744
3745         function action_templatenew() {
3746                 global $member;
3747
3748                 $member->isAdmin() or $this->disallow();
3749
3750                 $name = postVar('name');
3751                 $desc = postVar('desc');
3752
3753                 if (!isValidTemplateName($name))
3754                         $this->error(_ERROR_BADTEMPLATENAME);
3755
3756                 if (TEMPLATE::exists($name))
3757                         $this->error(_ERROR_DUPTEMPLATENAME);
3758
3759                 $newTemplateId = TEMPLATE::createNew($name, $desc);
3760
3761                 $this->action_templateoverview();
3762         }
3763
3764         function action_templateclone() {
3765                 global $member;
3766
3767                 $templateid = intRequestVar('templateid');
3768
3769                 $member->isAdmin() or $this->disallow();
3770
3771                 // 1. read old template
3772                 $name = TEMPLATE::getNameFromId($templateid);
3773                 $desc = TEMPLATE::getDesc($templateid);
3774
3775                 // 2. create desc thing
3776                 $name = "cloned" . $name;
3777
3778                 // if a template with that name already exists:
3779                 if (TEMPLATE::exists($name)) {
3780                         $i = 1;
3781                         while (TEMPLATE::exists($name . $i))
3782                                 $i++;
3783                         $name .= $i;
3784                 }
3785
3786                 $newid = TEMPLATE::createNew($name, $desc);
3787
3788                 // 3. create clone
3789                 // go through parts of old template and add them to the new one
3790                 $res = sql_query('SELECT tpartname, tcontent FROM '.sql_table('template').' WHERE tdesc=' . $templateid);
3791                 while ($o = mysql_fetch_object($res)) {
3792                         $this->addToTemplate($newid, $o->tpartname, $o->tcontent);
3793                 }
3794
3795                 $this->action_templateoverview();
3796         }
3797
3798         function action_skinoverview() {
3799                 global $member, $manager;
3800
3801                 $member->isAdmin() or $this->disallow();
3802
3803                 $this->pagehead();
3804
3805                 echo '<p><a href="index.php?action=manage">(',_BACKTOMANAGE,')</a></p>';
3806
3807                 echo '<h2>' . _SKIN_EDIT_TITLE . '</h2>';
3808
3809                 echo '<h3>' . _SKIN_AVAILABLE_TITLE . '</h3>';
3810
3811                 $query = 'SELECT * FROM '.sql_table('skin_desc').' ORDER BY sdname';
3812                 $template['content'] = 'skinlist';
3813                 $template['tabindex'] = 10;
3814                 showlist($query,'table',$template);
3815
3816                 echo '<h3>' . _SKIN_NEW_TITLE . '</h3>';
3817
3818                 ?>
3819                 <form method="post" action="index.php">
3820                 <div>
3821
3822                 <input name="action" value="skinnew" type="hidden" />
3823                 <?php $manager->addTicketHidden() ?>
3824                 <table><tr>
3825                         <td><?php echo _SKIN_NAME?> <?php help('shortnames');?></td>
3826                         <td><input name="name" tabindex="10010" maxlength="20" size="20" /></td>
3827                 </tr><tr>
3828                         <td><?php echo _SKIN_DESC?></td>
3829                         <td><input name="desc" tabindex="10020" maxlength="200" size="50" /></td>
3830                 </tr><tr>
3831                         <td><?php echo _SKIN_CREATE?></td>
3832                         <td><input type="submit" tabindex="10030" value="<?php echo _SKIN_CREATE_BTN?>" onclick="return checkSubmit();" /></td>
3833                 </tr></table>
3834
3835                 </div>
3836                 </form>
3837
3838                 <?php
3839                 $this->pagefoot();
3840         }
3841
3842         function action_skinnew() {
3843                 global $member;
3844
3845                 $member->isAdmin() or $this->disallow();
3846
3847                 $name = trim(postVar('name'));
3848                 $desc = trim(postVar('desc'));
3849
3850                 if (!isValidSkinName($name))
3851                         $this->error(_ERROR_BADSKINNAME);
3852
3853                 if (SKIN::exists($name))
3854                         $this->error(_ERROR_DUPSKINNAME);
3855
3856                 $newId = SKIN::createNew($name, $desc);
3857
3858                 $this->action_skinoverview();
3859         }
3860
3861         function action_skinedit() {
3862                 global $member, $manager;
3863
3864                 $skinid = intRequestVar('skinid');
3865
3866                 $member->isAdmin() or $this->disallow();
3867
3868                 $skin =& new SKIN($skinid);
3869
3870                 $this->pagehead();
3871                 ?>
3872                 <p>
3873                         <a href="index.php?action=skinoverview">(<?php echo _SKIN_BACK?>)</a>
3874                 </p>
3875                 <h2><?php echo _SKIN_EDITONE_TITLE?> '<?php echo  $skin->getName() ?>'</h2>
3876
3877                 <h3><?php echo _SKIN_PARTS_TITLE?></h3>
3878                 <?php echo _SKIN_PARTS_MSG?>
3879                 <ul>
3880                         <li><a tabindex="10" href="index.php?action=skinedittype&amp;skinid=<?php echo  $skinid ?>&amp;type=index"><?php echo _SKIN_PART_MAIN?></a> <?php help('skinpartindex')?></li>
3881                         <li><a tabindex="20" href="index.php?action=skinedittype&amp;skinid=<?php echo  $skinid ?>&amp;type=item"><?php echo _SKIN_PART_ITEM?></a> <?php help('skinpartitem')?></li>
3882                         <li><a tabindex="30" href="index.php?action=skinedittype&amp;skinid=<?php echo  $skinid ?>&amp;type=archivelist"><?php echo _SKIN_PART_ALIST?></a> <?php help('skinpartarchivelist')?></li>
3883                         <li><a tabindex="40" href="index.php?action=skinedittype&amp;skinid=<?php echo  $skinid ?>&amp;type=archive"><?php echo _SKIN_PART_ARCHIVE?></a> <?php help('skinpartarchive')?></li>
3884                         <li><a tabindex="50" href="index.php?action=skinedittype&amp;skinid=<?php echo  $skinid ?>&amp;type=search"><?php echo _SKIN_PART_SEARCH?></a> <?php help('skinpartsearch')?></li>
3885                         <li><a tabindex="60" href="index.php?action=skinedittype&amp;skinid=<?php echo  $skinid ?>&amp;type=error"><?php echo _SKIN_PART_ERROR?></a> <?php help('skinparterror')?></li>
3886                         <li><a tabindex="70" href="index.php?action=skinedittype&amp;skinid=<?php echo  $skinid ?>&amp;type=member"><?php echo _SKIN_PART_MEMBER?></a> <?php help('skinpartmember')?></li>
3887                         <li><a tabindex="75" href="index.php?action=skinedittype&amp;skinid=<?php echo  $skinid ?>&amp;type=imagepopup"><?php echo _SKIN_PART_POPUP?></a> <?php help('skinpartimagepopup')?></li>
3888                 </ul>
3889
3890                 <h3><?php echo _SKIN_GENSETTINGS_TITLE?></h3>
3891                 <form method="post" action="index.php">
3892                 <div>
3893
3894                 <input type="hidden" name="action" value="skineditgeneral" />
3895                 <?php $manager->addTicketHidden() ?>
3896                 <input type="hidden" name="skinid" value="<?php echo  $skinid ?>" />
3897                 <table><tr>
3898                         <td><?php echo _SKIN_NAME?> <?php help('shortnames');?></td>
3899                         <td><input name="name" tabindex="90" value="<?php echo  htmlspecialchars($skin->getName()) ?>" maxlength="20" size="20" /></td>
3900                 </tr><tr>
3901                         <td><?php echo _SKIN_DESC?></td>
3902                         <td><input name="desc" tabindex="100" value="<?php echo  htmlspecialchars($skin->getDescription()) ?>" maxlength="200" size="50" /></td>
3903                 </tr><tr>
3904                         <td><?php echo _SKIN_TYPE?></td>
3905                         <td><input name="type" tabindex="110" value="<?php echo  htmlspecialchars($skin->getContentType()) ?>" maxlength="40" size="20" /></td>
3906                 </tr><tr>
3907                         <td><?php echo _SKIN_INCLUDE_MODE?> <?php help('includemode')?></td>
3908                         <td><?php $this->input_yesno('inc_mode',$skin->getIncludeMode(),120,'skindir','normal',_PARSER_INCMODE_SKINDIR,_PARSER_INCMODE_NORMAL);?></td>
3909                 </tr><tr>
3910                         <td><?php echo _SKIN_INCLUDE_PREFIX?> <?php help('includeprefix')?></td>
3911                         <td><input name="inc_prefix" tabindex="130" value="<?php echo  htmlspecialchars($skin->getIncludePrefix()) ?>" maxlength="40" size="20" /></td>
3912                 </tr><tr>
3913                         <td><?php echo _SKIN_CHANGE?></td>
3914                         <td><input type="submit" tabindex="140" value="<?php echo _SKIN_CHANGE_BTN?>" onclick="return checkSubmit();" /></td>
3915                 </tr></table>
3916
3917                 </div>
3918                 </form>
3919
3920
3921                 <?php           $this->pagefoot();
3922         }
3923
3924         function action_skineditgeneral() {
3925                 global $member;
3926
3927                 $skinid = intRequestVar('skinid');
3928
3929                 $member->isAdmin() or $this->disallow();
3930
3931                 $name = postVar('name');
3932                 $desc = postVar('desc');
3933                 $type = postVar('type');
3934                 $inc_mode = postVar('inc_mode');
3935                 $inc_prefix = postVar('inc_prefix');
3936
3937                 $skin =& new SKIN($skinid);
3938
3939                 // 1. Some checks
3940                 if (!isValidSkinName($name))
3941                         $this->error(_ERROR_BADSKINNAME);
3942
3943                 if (($skin->getName() != $name) && SKIN::exists($name))
3944                         $this->error(_ERROR_DUPSKINNAME);
3945
3946                 if (!$type) $type = 'text/html';
3947                 if (!$inc_mode) $inc_mode = 'normal';
3948
3949                 // 2. Update description
3950                 $skin->updateGeneralInfo($name, $desc, $type, $inc_mode, $inc_prefix);
3951
3952                 $this->action_skinedit();
3953
3954         }
3955
3956         function action_skinedittype($msg = '') {
3957                 global $member, $manager;
3958
3959                 $skinid = intRequestVar('skinid');
3960                 $type = requestVar('type');
3961
3962                 $member->isAdmin() or $this->disallow();
3963
3964                 $skin =& new SKIN($skinid);
3965
3966                 $friendlyNames = SKIN::getFriendlyNames();
3967
3968                 $this->pagehead();
3969                 ?>
3970                 <p>(<a href="index.php?action=skinoverview"><?php echo _SKIN_GOBACK?></a>)</p>
3971
3972                 <h2><?php echo _SKIN_EDITPART_TITLE?> '<?php echo  $skin->getName() ?>': <?php echo  $friendlyNames[$type] ?></h2>
3973
3974                 <?php                   if ($msg) echo "<p>"._MESSAGE.": $msg</p>";
3975                 ?>
3976
3977
3978                 <form method="post" action="index.php">
3979                 <div>
3980
3981                 <input type="hidden" name="action" value="skinupdate" />
3982                 <?php $manager->addTicketHidden() ?>
3983                 <input type="hidden" name="skinid" value="<?php echo  $skinid ?>" />
3984                 <input type="hidden" name="type" value="<?php echo  $type ?>" />
3985
3986                 <input type="submit" value="<?php echo _SKIN_UPDATE_BTN?>" onclick="return checkSubmit();" />
3987                 <input type="reset" value="<?php echo _SKIN_RESET_BTN?>" />
3988                 (skin type: <?php echo  $friendlyNames[$type] ?>)
3989                 <?php help('skinpart' . $type);?>
3990                 <br />
3991
3992                 <textarea class="skinedit" tabindex="10" rows="20" cols="80" name="content"><?php echo  htmlspecialchars($skin->getContent($type)) ?></textarea>
3993
3994                 <br />
3995                 <input type="submit" tabindex="20" value="<?php echo _SKIN_UPDATE_BTN?>" onclick="return checkSubmit();" />
3996                 <input type="reset" value="<?php echo _SKIN_RESET_BTN?>" />
3997                 (skin type: <?php echo  $friendlyNames[$type] ?>)
3998
3999                 <br /><br />
4000                 <?php echo _SKIN_ALLOWEDVARS?>
4001                 <?php                   $actions = SKIN::getAllowedActionsForType($type);
4002
4003                         sort($actions);
4004
4005                         while ($current = array_shift($actions)) {
4006                                 // skip deprecated vars
4007                                 if ($current == 'ifcat') continue;
4008                                 if ($current == 'imagetext') continue;
4009                                 if ($current == 'vars') continue;
4010
4011                                 echo helplink('skinvar-' . $current) . "$current</a>";
4012                                 if (count($actions) != 0) echo ", ";
4013                         }
4014                 ?>
4015                 <br /><br />
4016                 Short blog names:
4017                 <?php                   $query = 'SELECT bshortname, bname FROM '.sql_table('blog');
4018                         showlist($query,'table',array('content'=>'shortblognames'));
4019                 ?>
4020
4021                 <br />
4022                 Template names:
4023                 <?php                   $query = 'SELECT tdname as name, tddesc as description FROM '.sql_table('template_desc');
4024                         showlist($query,'table',array('content'=>'shortnames'));
4025                 ?>
4026
4027
4028                 </div>
4029                 </form>
4030
4031
4032                 <?php           $this->pagefoot();
4033         }
4034
4035         function action_skinupdate() {
4036                 global $member;
4037
4038                 $skinid = intRequestVar('skinid');
4039                 $content = trim(postVar('content'));
4040                 $type = postVar('type');
4041
4042                 $member->isAdmin() or $this->disallow();
4043
4044                 $skin =& new SKIN($skinid);
4045                 $skin->update($type, $content);
4046
4047                 $this->action_skinedittype(_SKIN_UPDATED);
4048         }
4049
4050         function action_skindelete() {
4051                 global $member, $manager, $CONF;
4052
4053                 $skinid = intRequestVar('skinid');
4054
4055                 $member->isAdmin() or $this->disallow();
4056
4057                 // don't allow default skin to be deleted
4058                 if ($skinid == $CONF['BaseSkin'])
4059                         $this->error(_ERROR_DEFAULTSKIN);
4060
4061                 // don't allow deletion of default skins for blogs
4062                 $query = 'SELECT bname FROM '.sql_table('blog').' WHERE bdefskin=' . $skinid;
4063                 $r = sql_query($query);
4064                 if ($o = mysql_fetch_object($r))
4065                         $this->error(_ERROR_SKINDEFDELETE . $o->bname);
4066
4067                 $this->pagehead();
4068
4069                 $skin =& new SKIN($skinid);
4070                 $name = $skin->getName();
4071                 $desc = $skin->getDescription();
4072
4073                 ?>
4074                         <h2><?php echo _DELETE_CONFIRM?></h2>
4075
4076                         <p>
4077                                 <?php echo _CONFIRMTXT_SKIN?><b><?php echo  $name ?></b> (<?php echo  htmlspecialchars($desc)?>)
4078                         </p>
4079
4080                         <form method="post" action="index.php"><div>
4081                                 <input type="hidden" name="action" value="skindeleteconfirm" />
4082                                 <?php $manager->addTicketHidden() ?>
4083                                 <input type="hidden" name="skinid" value="<?php echo  $skinid ?>" />
4084                                 <input type="submit" tabindex="10" value="<?php echo _DELETE_CONFIRM_BTN?>" />
4085                         </div></form>
4086                 <?php
4087                 $this->pagefoot();
4088         }
4089
4090         function action_skindeleteconfirm() {
4091                 global $member, $CONF, $manager;
4092
4093                 $skinid = intRequestVar('skinid');
4094
4095                 $member->isAdmin() or $this->disallow();
4096
4097                 // don't allow default skin to be deleted
4098                 if ($skinid == $CONF['BaseSkin'])
4099                         $this->error(_ERROR_DEFAULTSKIN);
4100
4101                 // don't allow deletion of default skins for blogs
4102                 $query = 'SELECT bname FROM '.sql_table('blog').' WHERE bdefskin=' . $skinid;
4103                 $r = sql_query($query);
4104                 if ($o = mysql_fetch_object($r))
4105                         $this->error(_ERROR_SKINDEFDELETE .$o->bname);
4106
4107                 $manager->notify('PreDeleteSkin', array('skinid' => $skinid));
4108
4109                 // 1. delete description
4110                 sql_query('DELETE FROM '.sql_table('skin_desc').' WHERE sdnumber=' . $skinid);
4111
4112                 // 2. delete parts
4113                 sql_query('DELETE FROM '.sql_table('skin').' WHERE sdesc=' . $skinid);
4114
4115                 $manager->notify('PostDeleteSkin', array('skinid' => $skinid));
4116
4117                 $this->action_skinoverview();
4118         }
4119
4120         function action_skinclone() {
4121                 global $member;
4122
4123                 $skinid = intRequestVar('skinid');
4124
4125                 $member->isAdmin() or $this->disallow();
4126
4127                 // 1. read skin to clone
4128                 $skin =& new SKIN($skinid);
4129
4130                 $name = "clone_" . $skin->getName();
4131
4132                 // if a skin with that name already exists:
4133                 if (SKIN::exists($name)) {
4134                         $i = 1;
4135                         while (SKIN::exists($name . $i))
4136                                 $i++;
4137                         $name .= $i;
4138                 }
4139
4140                 // 2. create skin desc
4141                 $newid = SKIN::createNew(
4142                         $name,
4143                         $skin->getDescription(),
4144                         $skin->getContentType(),
4145                         $skin->getIncludeMode(),
4146                         $skin->getIncludePrefix()
4147                 );
4148
4149
4150                 // 3. clone
4151                 $this->skinclonetype($skin, $newid, 'index');
4152                 $this->skinclonetype($skin, $newid, 'item');
4153                 $this->skinclonetype($skin, $newid, 'archivelist');
4154                 $this->skinclonetype($skin, $newid, 'archive');
4155                 $this->skinclonetype($skin, $newid, 'search');
4156                 $this->skinclonetype($skin, $newid, 'error');
4157                 $this->skinclonetype($skin, $newid, 'member');
4158                 $this->skinclonetype($skin, $newid, 'imagepopup');
4159
4160                 $this->action_skinoverview();
4161
4162         }
4163
4164         function skinclonetype($skin, $newid, $type) {
4165                 $newid = intval($newid);
4166                 $content = $skin->getContent($type);
4167                 if ($content) {
4168                         $query = 'INSERT INTO '.sql_table('skin')." (sdesc, scontent, stype) VALUES ($newid,'". addslashes($content)."', '". addslashes($type)."')";
4169                         sql_query($query);
4170                 }
4171         }
4172
4173         function action_settingsedit() {
4174                 global $member, $manager, $CONF, $DIR_NUCLEUS, $DIR_MEDIA;
4175
4176                 $member->isAdmin() or $this->disallow();
4177
4178                 $this->pagehead();
4179
4180                 echo '<p><a href="index.php?action=manage">(',_BACKTOMANAGE,')</a></p>';
4181                 ?>
4182
4183                 <h2><?php echo _SETTINGS_TITLE?></h2>
4184
4185                 <form action="index.php" method="post">
4186                 <div>
4187
4188                 <input type="hidden" name="action" value="settingsupdate" />
4189                 <?php $manager->addTicketHidden() ?>
4190
4191                 <table><tr>
4192                         <th colspan="2"><?php echo _SETTINGS_SUB_GENERAL?></th>
4193                 </tr><tr>
4194                         <td><?php echo _SETTINGS_DEFBLOG?> <?php help('defaultblog'); ?></td>
4195                         <td>
4196                                 <?php
4197                                         $query =  'SELECT bname as text, bnumber as value'
4198                                                    . ' FROM '.sql_table('blog');
4199                                         $template['name'] = 'DefaultBlog';
4200                                         $template['selected'] = $CONF['DefaultBlog'];
4201                                         $template['tabindex'] = 10;
4202                                         showlist($query,'select',$template);
4203                                 ?>
4204                         </td>
4205                 </tr><tr>
4206                         <td><?php echo _SETTINGS_BASESKIN?> <?php help('baseskin'); ?></td>
4207                         <td>
4208                                 <?php
4209                                         $query =  'SELECT sdname as text, sdnumber as value'
4210                                                    . ' FROM '.sql_table('skin_desc');
4211                                         $template['name'] = 'BaseSkin';
4212                                         $template['selected'] = $CONF['BaseSkin'];
4213                                         $template['tabindex'] = 1;
4214                                         showlist($query,'select',$template);
4215                                 ?>
4216                         </td>
4217                 </tr><tr>
4218                         <td><?php echo _SETTINGS_ADMINMAIL?></td>
4219                         <td><input name="AdminEmail" tabindex="10010" size="40" value="<?php echo  htmlspecialchars($CONF['AdminEmail']) ?>" /></td>
4220                 </tr><tr>
4221                         <td><?php echo _SETTINGS_SITENAME?></td>
4222                         <td><input name="SiteName" tabindex="10020" size="40" value="<?php echo  htmlspecialchars($CONF['SiteName']) ?>" /></td>
4223                 </tr><tr>
4224                         <td><?php echo _SETTINGS_SITEURL?></td>
4225                         <td><input name="IndexURL" tabindex="10030" size="40" value="<?php echo  htmlspecialchars($CONF['IndexURL']) ?>" /></td>
4226                 </tr><tr>
4227                         <td><?php echo _SETTINGS_ADMINURL?></td>
4228                         <td><input name="AdminURL" tabindex="10040" size="40" value="<?php echo  htmlspecialchars($CONF['AdminURL']) ?>" /></td>
4229                 </tr><tr>
4230                         <td><?php echo _SETTINGS_PLUGINURL?> <?php help('pluginurl');?></td>
4231                         <td><input name="PluginURL" tabindex="10045" size="40" value="<?php echo  htmlspecialchars($CONF['PluginURL']) ?>" /></td>
4232                 </tr><tr>
4233                         <td><?php echo _SETTINGS_SKINSURL?> <?php help('skinsurl');?></td>
4234                         <td><input name="SkinsURL" tabindex="10046" size="40" value="<?php echo  htmlspecialchars($CONF['SkinsURL']) ?>" /></td>
4235                 </tr><tr>
4236                         <td><?php echo _SETTINGS_ACTIONSURL?> <?php help('actionurl');?></td>
4237                         <td><input name="ActionURL" tabindex="10047" size="40" value="<?php echo  htmlspecialchars($CONF['ActionURL']) ?>" /></td>
4238                 </tr><tr>
4239                         <td><?php echo _SETTINGS_LANGUAGE?> <?php help('language'); ?>
4240                         </td>
4241                         <td>
4242
4243                                 <select name="Language" tabindex="10050">
4244                                 <?php                           // show a dropdown list of all available languages
4245                                 global $DIR_LANG;
4246                                 $dirhandle = opendir($DIR_LANG);
4247                                 while ($filename = readdir($dirhandle)) {
4248                                         if (ereg("^(.*)\.php$",$filename,$matches)) {
4249                                                 $name = $matches[1];
4250                                                 echo "<option value='$name'";
4251                                                 if ($name == $CONF['Language'])
4252                                                         echo " selected='selected'";
4253                                                 echo ">$name</option>";
4254                                         }
4255                                 }
4256                                 closedir($dirhandle);
4257
4258                                 ?>
4259                                 </select>
4260
4261                         </td>
4262                 </tr><tr>
4263                         <td><?php echo _SETTINGS_DISABLESITE?> <?php help('disablesite'); ?>
4264                         </td>
4265                         <td><?php $this->input_yesno('DisableSite',$CONF['DisableSite'],10060); ?>
4266                                         <br />
4267                                 URL: <input name="DisableSiteURL" tabindex="10070" size="40" value="<?php echo  htmlspecialchars($CONF['DisableSiteURL'])?>" />
4268                         </td>
4269                 </tr><tr>
4270                         <td><?php echo _SETTINGS_DIRS?></td>
4271                         <td><?php echo  htmlspecialchars($DIR_NUCLEUS) ?>
4272                                 <i><?php echo _SETTINGS_SEECONFIGPHP?></i></td>
4273                 </tr><tr>
4274                         <td><?php echo _SETTINGS_DBLOGIN?></td>
4275                         <td><i><?php echo _SETTINGS_SEECONFIGPHP?></i></td>
4276                 </tr><tr>
4277                         <td>
4278                         <?php
4279                                 echo _SETTINGS_JSTOOLBAR
4280                                 /* =_SETTINGS_DISABLEJS
4281
4282                                         I temporary changed the meaning of DisableJsTools, until I can find a good
4283                                         way to select the javascript version to use
4284
4285                                         now, its:
4286                                                 0 : IE
4287                                                 1 : all javascript disabled
4288                                                 2 : 'simpler' javascript (for mozilla/opera/mac)
4289                                 */
4290                            ?>
4291                         </td>
4292                         <td><?php /* $this->input_yesno('DisableJsTools',$CONF['DisableJsTools'],10075); */?>
4293                                 <select name="DisableJsTools" tabindex="10075">
4294                         <?php                                   $extra = ($CONF['DisableJsTools'] == 1) ? 'selected="selected"' : '';
4295                                         echo "<option $extra value='1'>",_SETTINGS_JSTOOLBAR_NONE,"</option>";
4296                                         $extra = ($CONF['DisableJsTools'] == 2) ? 'selected="selected"' : '';
4297                                         echo "<option $extra value='2'>",_SETTINGS_JSTOOLBAR_SIMPLE,"</option>";
4298                                         $extra = ($CONF['DisableJsTools'] == 0) ? 'selected="selected"' : '';
4299                                         echo "<option $extra value='0'>",_SETTINGS_JSTOOLBAR_FULL,"</option>";
4300                         ?>
4301                                 </select>
4302                         </td>
4303                 </tr><tr>
4304                         <td><?php echo _SETTINGS_URLMODE?> <?php help('urlmode');?></td>
4305                                            <td><?php
4306
4307                                            $this->input_yesno('URLMode',$CONF['URLMode'],10077,
4308                                                           'normal','pathinfo',_SETTINGS_URLMODE_NORMAL,_SETTINGS_URLMODE_PATHINFO);
4309
4310                                            echo ' ', _SETTINGS_URLMODE_HELP;
4311
4312                                                          ?>
4313
4314                                            </td>
4315                 </tr><tr>
4316                         <th colspan="2"><?php echo _SETTINGS_MEDIA?> <?php help('media'); ?></th>
4317                 </tr><tr>
4318                         <td><?php echo _SETTINGS_MEDIADIR?></td>
4319                         <td><?php echo  htmlspecialchars($DIR_MEDIA) ?>
4320                                 <i><?php echo _SETTINGS_SEECONFIGPHP?></i>
4321                                 <?php                           if (!is_dir($DIR_MEDIA))
4322                                                 echo "<br /><b>" . _WARNING_NOTADIR . "</b>";
4323                                         if (!is_readable($DIR_MEDIA))
4324                                                 echo "<br /><b>" . _WARNING_NOTREADABLE . "</b>";
4325                                         if (!is_writeable($DIR_MEDIA))
4326                                                 echo "<br /><b>" . _WARNING_NOTWRITABLE . "</b>";
4327                                 ?>
4328                         </td>
4329                 </tr><tr>
4330                         <td><?php echo _SETTINGS_MEDIAURL?></td>
4331                         <td>
4332                                 <input name="MediaURL" tabindex="10080" size="40" value="<?php echo  htmlspecialchars($CONF['MediaURL']) ?>" />
4333                         </td>
4334                 </tr><tr>
4335                         <td><?php echo _SETTINGS_ALLOWUPLOAD?></td>
4336                         <td><?php $this->input_yesno('AllowUpload',$CONF['AllowUpload'],10090); ?></td>
4337                 </tr><tr>
4338                         <td><?php echo _SETTINGS_ALLOWUPLOADTYPES?></td>
4339                         <td>
4340                                 <input name="AllowedTypes" tabindex="10100" size="40" value="<?php echo  htmlspecialchars($CONF['AllowedTypes']) ?>" />
4341                         </td>
4342                 </tr><tr>
4343                         <td><?php echo _SETTINGS_MAXUPLOADSIZE?></td>
4344                         <td>
4345                                 <input name="MaxUploadSize" tabindex="10105" size="40" value="<?php echo  htmlspecialchars($CONF['MaxUploadSize']) ?>" />
4346                         </td>
4347                 </tr><tr>
4348                         <td><?php echo _SETTINGS_MEDIAPREFIX?></td>
4349                         <td><?php $this->input_yesno('MediaPrefix',$CONF['MediaPrefix'],10110); ?></td>
4350
4351                 </tr><tr>
4352                         <th colspan="2"><?php echo _SETTINGS_MEMBERS?></th>
4353                 </tr><tr>
4354                         <td><?php echo _SETTINGS_CHANGELOGIN?></td>
4355                         <td><?php $this->input_yesno('AllowLoginEdit',$CONF['AllowLoginEdit'],10120); ?></td>
4356                 </tr><tr>
4357                         <td><?php echo _SETTINGS_ALLOWCREATE?>
4358                                 <?php help('allowaccountcreation'); ?>
4359                         </td>
4360                         <td><?php $this->input_yesno('AllowMemberCreate',$CONF['AllowMemberCreate'],10130); ?>
4361                         </td>
4362                 </tr><tr>
4363                         <td><?php echo _SETTINGS_NEWLOGIN?> <?php help('allownewmemberlogin'); ?>
4364                                 <br /><?php echo _SETTINGS_NEWLOGIN2?>
4365                         </td>
4366                         <td><?php $this->input_yesno('NewMemberCanLogon',$CONF['NewMemberCanLogon'],10140); ?>
4367                         </td>
4368                 </tr><tr>
4369                         <td><?php echo _SETTINGS_MEMBERMSGS?>
4370                                 <?php help('messageservice'); ?>
4371                         </td>
4372                         <td><?php $this->input_yesno('AllowMemberMail',$CONF['AllowMemberMail'],10150); ?>
4373                         </td>
4374                 </tr><tr>
4375                         <td><?php echo _SETTINGS_NONMEMBERMSGS?>
4376                                 <?php help('messageservice'); ?>
4377                         </td>
4378                         <td><?php $this->input_yesno('NonmemberMail',$CONF['NonmemberMail'],10155); ?>
4379                         </td>
4380                 </tr><tr>
4381                         <td><?php echo _SETTINGS_PROTECTMEMNAMES?>
4382                                 <?php help('protectmemnames'); ?>
4383                         </td>
4384                         <td><?php $this->input_yesno('ProtectMemNames',$CONF['ProtectMemNames'],10156); ?>
4385                         </td>
4386
4387
4388
4389                 </tr><tr>
4390                         <th colspan="2"><?php echo _SETTINGS_COOKIES_TITLE?> <?php help('cookies'); ?></th>
4391                 </tr><tr>
4392                         <td><?php echo _SETTINGS_COOKIEPREFIX?></td>
4393                         <td><input name="CookiePrefix" tabindex="10159" size="40" value="<?php echo  htmlspecialchars($CONF['CookiePrefix'])?>" /></td>
4394                 </tr><tr>
4395                         <td><?php echo _SETTINGS_COOKIEDOMAIN?></td>
4396                         <td><input name="CookieDomain" tabindex="10160" size="40" value="<?php echo  htmlspecialchars($CONF['CookieDomain'])?>" /></td>
4397                 </tr><tr>
4398                         <td><?php echo _SETTINGS_COOKIEPATH?></td>
4399                         <td><input name="CookiePath" tabindex="10170" size="40" value="<?php echo  htmlspecialchars($CONF['CookiePath'])?>" /></td>
4400                 </tr><tr>
4401                         <td><?php echo _SETTINGS_COOKIESECURE?></td>
4402                         <td><?php $this->input_yesno('CookieSecure',$CONF['CookieSecure'],10180); ?></td>
4403                 </tr><tr>
4404                         <td><?php echo _SETTINGS_COOKIELIFE?></td>
4405                         <td><?php $this->input_yesno('SessionCookie',$CONF['SessionCookie'],10190,
4406                                                           1,0,_SETTINGS_COOKIESESSION,_SETTINGS_COOKIEMONTH); ?>
4407                         </td>
4408                 </tr><tr>
4409                         <td><?php echo _SETTINGS_LASTVISIT?></td>
4410                         <td><?php $this->input_yesno('LastVisit',$CONF['LastVisit'],10200); ?></td>
4411
4412
4413
4414                 </tr><tr>
4415                         <th colspan="2"><?php echo _SETTINGS_UPDATE?></th>
4416                 </tr><tr>
4417                         <td><?php echo _SETTINGS_UPDATE?></td>
4418                         <td><input type="submit" tabindex="10210" value="<?php echo _SETTINGS_UPDATE_BTN?>" onclick="return checkSubmit();" /></td>
4419                 </tr></table>
4420
4421                 </div>
4422                 </form>
4423
4424                 <?php
4425                         echo '<h2>',_PLUGINS_EXTRA,'</h2>';
4426
4427                         $manager->notify(
4428                                 'GeneralSettingsFormExtras',
4429                                 array()
4430                         );
4431
4432                 $this->pagefoot();
4433         }
4434
4435         function action_settingsupdate() {
4436                 global $member, $CONF;
4437
4438                 $member->isAdmin() or $this->disallow();
4439
4440                 // check if email address for admin is valid
4441                 if (!isValidMailAddress(postVar('AdminEmail')))
4442                         $this->error(_ERROR_BADMAILADDRESS);
4443
4444
4445                 // save settings
4446                 $this->updateConfig('DefaultBlog',              postVar('DefaultBlog'));
4447                 $this->updateConfig('BaseSkin',                 postVar('BaseSkin'));
4448                 $this->updateConfig('IndexURL',                 postVar('IndexURL'));
4449                 $this->updateConfig('AdminURL',                 postVar('AdminURL'));
4450                 $this->updateConfig('PluginURL',                postVar('PluginURL'));
4451                 $this->updateConfig('SkinsURL',                 postVar('SkinsURL'));
4452                 $this->updateConfig('ActionURL',                postVar('ActionURL'));
4453                 $this->updateConfig('Language',                 postVar('Language'));
4454                 $this->updateConfig('AdminEmail',               postVar('AdminEmail'));
4455                 $this->updateConfig('SessionCookie',    postVar('SessionCookie'));
4456                 $this->updateConfig('AllowMemberCreate',postVar('AllowMemberCreate'));
4457                 $this->updateConfig('AllowMemberMail',  postVar('AllowMemberMail'));
4458                 $this->updateConfig('NonmemberMail',    postVar('NonmemberMail'));
4459                 $this->updateConfig('ProtectMemNames',  postVar('ProtectMemNames'));
4460                 $this->updateConfig('SiteName',                 postVar('SiteName'));
4461                 $this->updateConfig('NewMemberCanLogon',postVar('NewMemberCanLogon'));
4462                 $this->updateConfig('DisableSite',              postVar('DisableSite'));
4463                 $this->updateConfig('DisableSiteURL',   postVar('DisableSiteURL'));
4464                 $this->updateConfig('LastVisit',                postVar('LastVisit'));
4465                 $this->updateConfig('MediaURL',                 postVar('MediaURL'));
4466                 $this->updateConfig('AllowedTypes',             postVar('AllowedTypes'));
4467                 $this->updateConfig('AllowUpload',              postVar('AllowUpload'));
4468                 $this->updateConfig('MaxUploadSize',    postVar('MaxUploadSize'));
4469                 $this->updateConfig('MediaPrefix',              postVar('MediaPrefix'));
4470                 $this->updateConfig('AllowLoginEdit',   postVar('AllowLoginEdit'));
4471                 $this->updateConfig('DisableJsTools',   postVar('DisableJsTools'));
4472                 $this->updateConfig('CookieDomain',             postVar('CookieDomain'));
4473                 $this->updateConfig('CookiePath',               postVar('CookiePath'));
4474                 $this->updateConfig('CookieSecure',             postVar('CookieSecure'));
4475                 $this->updateConfig('URLMode',                  postVar('URLMode'));
4476                 $this->updateConfig('CookiePrefix',             postVar('CookiePrefix'));
4477
4478                 // load new config and redirect (this way, the new language will be used is necessary)
4479                 // note that when changing cookie settings, this redirect might cause the user
4480                 // to have to log in again.
4481                 getConfig();
4482                 redirect($CONF['AdminURL'] . '?action=manage');
4483                 exit;
4484
4485         }
4486
4487
4488         function updateConfig($name, $val) {
4489                 $name = addslashes($name);
4490                 $val = trim(addslashes($val));
4491
4492                 $query = 'UPDATE '.sql_table('config')
4493                            . " SET value='$val'"
4494                            . " WHERE name='$name'";
4495
4496                 mysql_query($query) or die("Query error: " . mysql_error());
4497                 return mysql_insert_id();
4498         }
4499
4500         /**
4501           * Error message
4502           */
4503         function error($msg) {
4504                 $this->pagehead();
4505                 ?>
4506                 <h2>Error!</h2>
4507                 <?php           echo $msg;
4508                 echo "<br />";
4509                 echo "<a href='index.php' onclick='history.back()'>"._BACK."</a>";
4510                 $this->pagefoot();
4511                 exit;
4512         }
4513
4514         function disallow() {
4515                 ACTIONLOG::add(WARNING, _ACTIONLOG_DISALLOWED . serverVar('REQUEST_URI'));
4516
4517                 $this->error(_ERROR_DISALLOWED);
4518         }
4519
4520
4521         function pagehead($extrahead = '') {
4522                 global $member, $nucleus, $CONF, $manager;
4523
4524                 $manager->notify(
4525                         'AdminPrePageHead',
4526                         array(
4527                                 'extrahead' => &$extrahead,
4528                                 'action' => $this->action
4529                         )
4530                 );
4531
4532                 $baseUrl = htmlspecialchars($CONF['AdminURL']);
4533
4534                 ?>
4535                 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4536                 <html xmlns="http://www.w3.org/1999/xhtml">
4537                 <head>
4538                         <meta http-equiv="Content-Type" content="text/html; charset=<?php echo _CHARSET ?>" />
4539                         <title><?php echo htmlspecialchars($CONF['SiteName'])?> - Admin</title>
4540                         <link rel="stylesheet" title="Nucleus Admin Default" type="text/css" href="<?php echo $baseUrl?>styles/admin.css" />
4541                         <link rel="stylesheet" title="Nucleus Admin Default" type="text/css"
4542                         href="<?php echo $baseUrl?>styles/addedit.css" />
4543
4544                         <script type="text/javascript" src="<?php echo $baseUrl?>javascript/edit.js"></script>
4545                         <script type="text/javascript" src="<?php echo $baseUrl?>javascript/admin.js"></script>
4546                         <script type="text/javascript" src="<?php echo $baseUrl?>javascript/compatibility.js"></script>
4547
4548           <meta http-equiv='Pragma' content='no-cache' />
4549           <meta http-equiv='Cache-Control' content='no-cache, must-revalidate' />
4550           <meta http-equiv='Expires' content='-1' />
4551
4552                         <?php echo $extrahead?>
4553                 </head>
4554                 <body>
4555                 <div class="header">
4556                 <h1><?php echo htmlspecialchars($CONF['SiteName'])?></h1>
4557                 </div>
4558                 <div id="container">
4559                 <div id="content">
4560                 <div class="loginname">
4561                 <?php                   if ($member->isLoggedIn())
4562                                 echo _LOGGEDINAS . ' ' . $member->getDisplayName()
4563                                         ." - <a href='index.php?action=logout'>" . _LOGOUT. "</a>"
4564                                         . "<br /><a href='index.php?action=overview'>" . _ADMINHOME . "</a> - ";
4565                         else
4566                                 echo '<a href="index.php?action=showlogin" title="Log in">' , _NOTLOGGEDIN , '</a> <br />';
4567
4568                         echo "<a href='".$CONF['IndexURL']."'>"._YOURSITE."</a>";
4569
4570                         echo '<br />(';
4571
4572                         if ($member->isLoggedIn() && $member->isAdmin())
4573                                 echo '<a href="http://nucleuscms.org/version.php?v=',getNucleusVersion(),'&amp;pl=',getNucleusPatchLevel(),'" title="Check for upgrade">Nucleus CMS ', $nucleus['version'], '</a>';
4574                         else
4575                                 echo 'Nucleus CMS ' , $nucleus['version'];
4576                         echo ')';
4577                 echo '</div>';
4578         }
4579
4580         function pagefoot() {
4581                 global $action, $member, $manager;
4582
4583                 $manager->notify(
4584                         'AdminPrePageFoot',
4585                         array(
4586                                 'action' => $this->action
4587                         )
4588                 );
4589
4590                 if ($member->isLoggedIn() && ($action != 'showlogin')) {
4591                         ?>
4592                         <h2><?php echo  _LOGOUT ?></h2>
4593                         <ul>
4594                                 <li><a href="index.php?action=overview"><?php echo  _BACKHOME?></a></li>
4595                                 <li><a href='index.php?action=logout'><?php echo  _LOGOUT?></a></li>
4596                         </ul>
4597                         <?php           }
4598                 ?>
4599                         <div class="foot">
4600                                 <a href="http://nucleuscms.org/">Nucleus CMS</a> &copy; 2002-2005 The Nucleus Group
4601                                 -
4602                                 <a href="http://nucleuscms.org/donate.php">Donate!</a>
4603                         </div>
4604
4605                         </div><!-- content -->
4606
4607                         <div id="quickmenu">
4608
4609                                 <?php                           // ---- user settings ----
4610                                 if (($action != 'showlogin') && ($member->isLoggedIn())) {
4611                                         echo '<ul>';
4612                                         echo '<li><a href="index.php?action=overview">',_QMENU_HOME,'</a></li>';
4613                                         echo '</ul>';
4614
4615                                         echo '<h2>',_QMENU_ADD,'</h2>';
4616                                         echo '<form method="get" action="index.php"><div>';
4617                                         echo '<input type="hidden" name="action" value="createitem" />';
4618
4619                                                 $showAll = requestVar('showall');
4620                                                 if (($member->isAdmin()) && ($showAll == 'yes')) {
4621                                                         // Super-Admins have access to all blogs! (no add item support though)
4622                                                         $query =  'SELECT bnumber as value, bname as text'
4623                                                                    . ' FROM ' . sql_table('blog')
4624                                                                    . ' ORDER BY bname';
4625                                                 } else {
4626                                                         $query =  'SELECT bnumber as value, bname as text'
4627                                                                    . ' FROM ' . sql_table('blog') . ', ' . sql_table('team')
4628                                                                    . ' WHERE tblog=bnumber and tmember=' . $member->getID()
4629                                                                    . ' ORDER BY bname';
4630                                                 }
4631                                                 $template['name'] = 'blogid';
4632                                                 $template['tabindex'] = 15000;
4633                                                 $template['extra'] = _QMENU_ADD_SELECT;
4634                                                 $template['selected'] = -1;
4635                                                 $template['shorten'] = 10;
4636                                                 $template['shortenel'] = '';
4637                                                 $template['javascript'] = 'onchange="return form.submit()"';
4638                                                 showlist($query,'select',$template);
4639
4640                                         echo '</div></form>';
4641
4642                                         echo '<h2>' . $member->getDisplayName(). '</h2>';
4643                                         echo '<ul>';
4644                                         echo '<li><a href="index.php?action=editmembersettings">',_QMENU_USER_SETTINGS,'</a></li>';
4645                                         echo '<li><a href="index.php?action=browseownitems">',_QMENU_USER_ITEMS,'</a></li>';
4646                                         echo '<li><a href="index.php?action=browseowncomments">',_QMENU_USER_COMMENTS,'</a></li>';
4647                                         echo '</ul>';
4648
4649
4650
4651
4652                                         // ---- general settings ----
4653                                         if ($member->isAdmin()) {
4654
4655                                                 echo '<h2>',_QMENU_MANAGE,'</h2>';
4656
4657                                                 echo '<ul>';
4658                                                 echo '<li><a href="index.php?action=actionlog">',_QMENU_MANAGE_LOG,'</a></li>';
4659                                                 echo '<li><a href="index.php?action=settingsedit">',_QMENU_MANAGE_SETTINGS,'</a></li>';
4660                                                 echo '<li><a href="index.php?action=usermanagement">',_QMENU_MANAGE_MEMBERS,'</a></li>';
4661                                                 echo '<li><a href="index.php?action=createnewlog">',_QMENU_MANAGE_NEWBLOG,'</a></li>';
4662                                                 echo '<li><a href="index.php?action=backupoverview">',_QMENU_MANAGE_BACKUPS,'</a></li>';
4663                                                 echo '<li><a href="index.php?action=pluginlist">',_QMENU_MANAGE_PLUGINS,'</a></li>';
4664                                                 echo '</ul>';
4665
4666                                                 echo '<h2>',_QMENU_LAYOUT,'</h2>';
4667                                                 echo '<ul>';
4668                                                 echo '<li><a href="index.php?action=skinoverview">',_QMENU_LAYOUT_SKINS,'</a></li>';
4669                                                 echo '<li><a href="index.php?action=templateoverview">',_QMENU_LAYOUT_TEMPL,'</a></li>';
4670                                                 echo '<li><a href="index.php?action=skinieoverview">',_QMENU_LAYOUT_IEXPORT,'</a></li>';
4671                                                 echo '</ul>';
4672
4673                                         }
4674
4675                                         $aPluginExtras = array();
4676                                         $manager->notify(
4677                                                 'QuickMenu',
4678                                                 array(
4679                                                         'options' => &$aPluginExtras
4680                                                 )
4681                                         );
4682                                         if (count($aPluginExtras) > 0)
4683                                         {
4684                                                 echo '<h2>', _QMENU_PLUGINS, '</h2>';
4685                                                 echo '<ul>';
4686                                                 foreach ($aPluginExtras as $aInfo)
4687                                                 {
4688                                                         echo '<li><a href="'.htmlspecialchars($aInfo['url']).'" title="'.htmlspecialchars($aInfo['tooltip']).'">'.htmlspecialchars($aInfo['title']).'</a></li>';
4689                                                 }
4690                                                 echo '</ul>';
4691                                         }
4692
4693                                 } else if (($action == 'activate') || ($action == 'activatesetpwd')) {
4694
4695                                         echo '<h2>', _QMENU_ACTIVATE, '</h2>', _QMENU_ACTIVATE_TEXT;
4696                                 } else {
4697                                         // introduction text on login screen
4698                                         echo '<h2>', _QMENU_INTRO, '</h2>', _QMENU_INTRO_TEXT;
4699                                 }
4700                                 ?>
4701                         </div>
4702
4703                         <!-- content / quickmenu container -->
4704                         </div>
4705
4706
4707                         </body>
4708                         </html>
4709                 <?php   }
4710
4711
4712         function action_regfile() {
4713                 global $member, $CONF;
4714
4715                 $blogid = intRequestVar('blogid');
4716
4717                 $member->teamRights($blogid) or $this->disallow();
4718
4719                 // header-code stolen from phpMyAdmin
4720                 // REGEDIT and bookmarklet code stolen from GreyMatter
4721
4722                 $sjisBlogName = getBlogNameFromID($blogid);
4723                 $sjisBlogName = mb_convert_encoding($sjisBlogName, "SJIS", "auto");
4724
4725                 header('Content-Type: application/octetstream');
4726                 header('Content-Disposition: filename="nucleus.reg"');
4727                 header('Pragma: no-cache');
4728                 header('Expires: 0');
4729
4730                 echo "REGEDIT4\n";
4731                 echo "[HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\MenuExt\\Post To &Nucleus (".$sjisBlogName.")]\n";
4732                 echo '@="' . $CONF['AdminURL'] . "bookmarklet.php?action=contextmenucode&blogid=".intval($blogid)."\"\n";
4733                 echo '"contexts"=hex:31';
4734         }
4735
4736         function action_bookmarklet() {
4737                 global $member, $manager;
4738
4739                 $blogid = intRequestVar('blogid');
4740
4741                 $member->teamRights($blogid) or $this->disallow();
4742
4743                 $blog =& $manager->getBlog($blogid);
4744                 $bm = getBookmarklet($blogid);
4745
4746                 $this->pagehead();
4747
4748                 echo '<p><a href="index.php?action=overview">(',_BACKHOME,')</a></p>';
4749
4750                 ?>
4751
4752                 <h2>Bookmarklet<!-- and Right Click Menu --></h2>
4753
4754                 <p>
4755                 Bookmarklet ã\81¨ã\81¯ã\80\81ã\82¯ã\83ªã\83\81E\82¯1å\9b\9eã\81§è¨\98äº\8bã\81\8a\95稿ã\81\8cã\81§ã\81\8dã\82\8bã\82·ã\82¹ã\83\81E\83 ã\81§ã\81\99ã\80\81\81\93ã\81E Bookmarklet ã\82\92ã\82¤ã\83³ã\82¹ã\83\88ã\81\83«ã\81\99ã\82\8bã\81¨ã\80\81ã\83\96ã\83©ã\82¦ã\82¶ã\81®ã\83\81E\81\83«ã\83\90ã\81\81®'add to weblog'ã\83\9cã\82¿ã\83³ã\81\8cå\88©ç\94¨å\8f¯è\83½ã\81¨ã\81ªã\82\8aã\80\81Nucleusã\81®æ\96°è¦\8fã\82¢ã\82¤ã\83\81E\83 ã\81®è¿½å\8a ã\82¦ã\82£ã\83³ã\83\89ã\82¦ã\81\8cã\81\83\81E\81\82¢ã\83\81E\81\81\97ã\81¾ã\81\99ã\80\82ä»»æ\84\8fã\81EWebã\83\9aã\81\82¸ã\82\92é\96\8bã\81\81E\81\9fç\8a¶æ\85\8bã\81§ã\81\93ã\81\83\9cã\82¿ã\83³ã\82\92æ\8a¼ã\81\9bã\81\80\81ã\81\9dã\81®Webã\83\9aã\81\82¸ã\81®ã\82¿ã\82¤ã\83\88ã\83«ã\81¨ã\80\81ã\81\9dã\81®ã\83\9aã\81\82¸ã\81¸ã\81®ã\83ªã\83³ã\82¯ã\82¿ã\82°ã\81\8cã\81\99ã\81§ã\81«å\9f\8bã\82\81è¾¼ã\81¾ã\82\8cã\81\9fç\8a¶æ\85\8bã\81§ã\82¢ã\82¤ã\83\81E\83 è¿½å\8a ã\82¦ã\82£ã\83³ã\83\89ã\82¦ã\81\8cé\96\8bã\81\8dã\80\81ã\81\95ã\82\89ã\81«ã\80\81ã\81\9dã\81®ã\83\9aã\81\82¸å\86\81E\81«å¼\95ç\94¨ã\81\97ã\81\9fã\81\81E\96\87ã\82\92é\81¸æ\8a\9eã\81\97ã\81\9fç\8a¶æ\85\8bã\81§ã\81\82ã\82\8cã\81°ã\81\9dã\81Eå¼\95ç\94¨æ\96\81E\82\82è\87ªå\8b\95ç\9a\84ã\81«å¼\95ç\94¨ã\81\97ã\81¾ã\81\99ã\80
4756                 </p>
4757
4758                 <h3>Bookmarklet</h3>
4759                 <p>
4760                         ä¸\8bã\81\83ªã\83³ã\82¯é\83¨å\88\81E\82\92ã\80\8cã\81\8aæ°\97ã\81«å\85¥ã\82\8aã\80\8dã\82\82ã\81\97ã\81\8fã\81¯ã\83\81E\81\83«ã\83\90ã\81\81«ã\83\89ã\83©ã\83\81E\82°ã\81§ã\81\8dã\81¾ã\81\99ã\80\81Esmall>(ã\81\9dã\81\89\8dã\81«ã\83\81E\82¹ã\83\88ã\81\97ã\81¦ã\81¿ã\81\9fã\81\84å ´å\90\88ã\81\8d\98ç´\94ã\81«ä¸\8bã\81\83ªã\83³ã\82¯ã\82\92ã\82¯ã\83ªã\83\81E\82¯ã\81\97ã\81¦ã\81¿ã\81¦ã\81\8fã\81 ã\81\95ã\81\84)</small>
4761                         <br />
4762                         <br />
4763                         <a href="<?php echo htmlspecialchars($bm)?>">Add to <?php echo $blog->getShortName()?></a> (ほとんどのブラウザで動作しまぁE
4764                 </p>
4765
4766                 <h3>å\8f³ã\82¯ã\83ªã\83\81E\82¯ã\83¡ã\83\8bã\83¥ã\83¼ã\81«ã\82¤ã\83³ã\82¹ã\83\88ã\81\83« (Windowsã\81§IE使ç\94¨æ\99\81E</h3>
4767                 <p>
4768                         <?php
4769                                 $url = 'index.php?action=regfile&blogid=' . intval($blogid);
4770                                 $url = $manager->addTicketToUrl($url);
4771                         ?>
4772                         ã\81\82ã\82\8bã\81\81E\81E<a href="<?php echo htmlspecialchars($url) ?>">å\8f³ã\82¯ã\83ªã\83\81E\82¯ã\83¡ã\83\8bã\83¥ã\83¼</a>ã\81«ã\82¤ã\83³ã\82¹ã\83\88ã\81\83«ã\81\99ã\82\8bã\81\93ã\81¨ã\82\82ã\81§ã\81\8dã\81¾ã\81\81E(ã\80\8cé\96\8bã\81\8fã\80\8dã\82\92é\81¸æ\8a\9eã\81\99ã\82\8cã\81\9b´æ\8e¥ã\83¬ã\82¸ã\82¹ã\83\88ã\83ªã\81«ç\99»é\8c²ã\81\97ã\81¾ã\81\81E
4773                 </p>
4774
4775                 <p>
4776                         ã\81\93ã\81\82¤ã\83³ã\82¹ã\83\88ã\81\83«ã\81\97ã\81\9få\8f³ã\82¯ã\83ªã\83\81E\82¯ã\83¡ã\83\8bã\83¥ã\83¼ã\82\92表示ã\81\99ã\82\8bã\81\9fã\82\81ã\81«ã\81¯IEã\81®å\86\8dèµ·å\8b\95ã\81\8cå¿\81\81ã\81§ã\81\99ã\80
4777                 </p>
4778
4779                 <h3>ã\82¢ã\83³ã\82¤ã\83³ã\82¹ã\83\88ã\81\83«</h3>
4780                 <p>
4781                         ã\80\8cã\81\8aæ°\97ã\81«å\85¥ã\82\8aã\80\8dã\82\82ã\81\97ã\81\8fã\81¯ã\83\81E\81\83«ã\83\90ã\81\81\8bã\82\89æ¶\88ã\81\99ã\81«ã\81¯ã\80\81å\8d\98ã\81«å\89\8aé\99¤ã\81\99ã\82\8bã\81 ã\81\91ã\81§ã\81\99ã\80
4782                 </p>
4783                 
4784                 <p>
4785                         å\8f³ã\82¯ã\83ªã\83\81E\82¯ã\83¡ã\83\8bã\83¥ã\83¼ã\81\8bã\82\89æ¶\88ã\81\97ã\81\9fã\81\84æ\99\82ã\81\80\81以ä¸\8bã\81\89\8bé \81E\82\92è¸\8fã\82\93ã\81§ã\81\8fã\81 ã\81\95ã\81\84:
4786                 </p>
4787
4788                 <ol>
4789                         <li>スタートメニューから「ファイルを指定して実衁E..」を選抁E/li>
4790                         <li>"regedit" と入劁E/li>
4791                         <li>"OK" ボタンを押ぁE/li>
4792                         <li>"\HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt" をツリーの中から検索</li>
4793                         <li>"add to weblog" エントリを削除</li>                          
4794                 </ol>
4795
4796                 <?php
4797                 $this->pagefoot();
4798
4799         }
4800
4801
4802         function action_actionlog() {
4803                 global $member, $manager;
4804
4805                 $member->isAdmin() or $this->disallow();
4806
4807                 $this->pagehead();
4808
4809                 echo '<p><a href="index.php?action=manage">(',_BACKTOMANAGE,')</a></p>';
4810
4811                 $url = $manager->addTicketToUrl('index.php?action=clearactionlog');
4812
4813                 ?>
4814                         <h2><?php echo _ACTIONLOG_CLEAR_TITLE?></h2>
4815                         <p><a href="<?php echo htmlspecialchars($url)?>"><?php echo _ACTIONLOG_CLEAR_TEXT?></a></p>
4816                 <?php
4817                 echo '<h2>' . _ACTIONLOG_TITLE . '</h2>';
4818
4819                 $query =  'SELECT * FROM '.sql_table('actionlog').' ORDER BY timestamp DESC';
4820                 $template['content'] = 'actionlist';
4821                 $amount = showlist($query,'table',$template);
4822
4823                 $this->pagefoot();
4824
4825         }
4826
4827
4828         function action_banlist() {
4829                 global $member, $manager;
4830
4831                 $blogid = intRequestVar('blogid');
4832
4833                 $member->blogAdminRights($blogid) or $this->disallow();
4834
4835                 $blog =& $manager->getBlog($blogid);
4836
4837                 $this->pagehead();
4838
4839                 echo '<p><a href="index.php?action=overview">(',_BACKHOME,')</a></p>';
4840
4841                 echo '<h2>' . _BAN_TITLE . " '". $this->bloglink($blog) ."'</h2>";
4842
4843                 $query =  'SELECT * FROM '.sql_table('ban').' WHERE blogid='.$blogid.' ORDER BY iprange';
4844                 $template['content'] = 'banlist';
4845                 $amount = showlist($query,'table',$template);
4846
4847                 if ($amount == 0)
4848                         echo _BAN_NONE;
4849
4850                 echo '<h2>'._BAN_NEW_TITLE.'</h2>';
4851                 echo "<p><a href='index.php?action=banlistnew&amp;blogid=$blogid'>"._BAN_NEW_TEXT."</a></p>";
4852
4853
4854                 $this->pagefoot();
4855
4856         }
4857
4858
4859         function action_banlistdelete() {
4860                 global $member, $manager;
4861
4862                 $blogid = intRequestVar('blogid');
4863                 $iprange = requestVar('iprange');
4864
4865                 $member->blogAdminRights($blogid) or $this->disallow();
4866
4867                 $blog =& $manager->getBlog($blogid);
4868
4869                 $this->pagehead();
4870                 ?>
4871                         <h2><?php echo _BAN_REMOVE_TITLE?></h2>
4872
4873                         <form method="post" action="index.php">
4874
4875                         <h3><?php echo _BAN_IPRANGE?></h3>
4876
4877                         <p>
4878                                 <?php echo _CONFIRMTXT_BAN?> <?php echo htmlspecialchars($iprange) ?>
4879                                 <input name="iprange" type="hidden" value="<?php echo htmlspecialchars($iprange)?>" />
4880                         </p>
4881
4882                         <h3><?php echo _BAN_BLOGS?></h3>
4883
4884                         <div>
4885                                 <input type="hidden" name="blogid" value="<?php echo $blogid?>" />
4886                                 <input name="allblogs" type="radio" value="0" id="allblogs_one" /><label for="allblogs_one">Only blog '<?php echo htmlspecialchars($blog->getName())?>'</label>
4887                                 <br />
4888                                 <input name="allblogs" type="radio" value="1" checked="checked" id="allblogs_all" /><label for="allblogs_all"><?php echo _BAN_ALLBLOGS?></label>
4889                         </div>
4890
4891                         <h3><?php echo _BAN_DELETE_TITLE?></h3>
4892
4893                         <div>
4894                                 <?php $manager->addTicketHidden() ?>
4895                                 <input type="hidden" name="action" value="banlistdeleteconfirm" />
4896                                 <input type="submit" value="<?php echo _DELETE_CONFIRM_BTN?>" />
4897                         </div>
4898
4899                         </form>
4900                 <?php
4901                 $this->pagefoot();
4902         }
4903
4904         function action_banlistdeleteconfirm() {
4905                 global $member, $manager;
4906
4907                 $blogid = intPostVar('blogid');
4908                 $allblogs = postVar('allblogs');
4909                 $iprange = postVar('iprange');
4910
4911                 $member->blogAdminRights($blogid) or $this->disallow();
4912
4913                 $deleted = array();
4914
4915                 if (!$allblogs) {
4916                         if (BAN::removeBan($blogid, $iprange))
4917                                 array_push($deleted, $blogid);
4918                 } else {
4919                         // get blogs fot which member has admin rights
4920                         $adminblogs = $member->getAdminBlogs();
4921                         foreach ($adminblogs as $blogje) {
4922                                 if (BAN::removeBan($blogje, $iprange))
4923                                         array_push($deleted, $blogje);
4924                         }
4925                 }
4926
4927                 if (sizeof($deleted) == 0)
4928                         $this->error(_ERROR_DELETEBAN);
4929
4930                 $this->pagehead();
4931
4932                 echo '<a href="index.php?action=banlist&amp;blogid=',$blogid,'">(',_BACK,')</a>';
4933                 echo '<h2>'._BAN_REMOVED_TITLE.'</h2>';
4934                 echo "<p>"._BAN_REMOVED_TEXT."</p>";
4935
4936                 echo "<ul>";
4937                 foreach ($deleted as $delblog) {
4938                         $b =& $manager->getBlog($delblog);
4939                         echo "<li>" . htmlspecialchars($b->getName()). "</li>";
4940                 }
4941                 echo "</ul>";
4942
4943                 $this->pagefoot();
4944
4945         }
4946
4947         function action_banlistnewfromitem() {
4948                 $this->action_banlistnew(getBlogIDFromItemID(intRequestVar('itemid')));
4949         }
4950
4951         function action_banlistnew($blogid = '') {
4952                 global $member, $manager;
4953
4954                 if ($blogid == '')
4955                         $blogid = intRequestVar('blogid');
4956
4957                 $ip = requestVar('ip');
4958
4959                 $member->blogAdminRights($blogid) or $this->disallow();
4960
4961                 $blog =& $manager->getBlog($blogid);
4962
4963                 $this->pagehead();
4964                 ?>
4965                 <h2><?php echo _BAN_ADD_TITLE?></h2>
4966
4967
4968                 <form method="post" action="index.php">
4969
4970                 <h3><?php echo _BAN_IPRANGE?></h3>
4971
4972                 <p><?php echo _BAN_IPRANGE_TEXT?></p>
4973
4974                 <div class="note">
4975                 <b>An example</b>: "134.58.253.193" will only block one computer, while "134.58.253" will block 256 IP addresses, including the one from the first example.
4976                 </div>
4977
4978                 <div>
4979                 <?php                   if ($ip) {
4980                 ?>
4981                         <input name="iprange" type="radio" value="<?php echo htmlspecialchars($ip)?>" checked="checked" id="ip_fixed" /><label for="ip_fixed"><?php echo htmlspecialchars($ip)?></label>
4982                         <br />
4983                         <input name="iprange" type="radio" value="custom" id="ip_custom" /><label for="ip_custom">Custom: </label><input name='customiprange' value='<?php echo htmlspecialchars($ip)?>' maxlength='15' size='15' />
4984                 <?php   } else {
4985                                 echo "<input name='iprange' value='custom' type='hidden' />";
4986                                 echo "<input name='customiprange' value='' maxlength='15' size='15' />";
4987                         }
4988                 ?>
4989                 </div>
4990
4991                 <h3><?php echo _BAN_BLOGS?></h3>
4992
4993                 <p><?php echo _BAN_BLOGS_TEXT?></p>
4994
4995                 <div>
4996                         <input type="hidden" name="blogid" value="<?php echo $blogid?>" />
4997                         <input name="allblogs" type="radio" value="0" id="allblogs_one" /><label for="allblogs_one">'<?php echo htmlspecialchars($blog->getName())?>'</label>
4998                         <br />
4999                         <input name="allblogs" type="radio" value="1" checked="checked" id="allblogs_all" /><label for="allblogs_all"><?php echo _BAN_ALLBLOGS?></label>
5000                 </div>
5001
5002                 <h3><?php echo _BAN_REASON_TITLE?></h3>
5003
5004                 <p><?php echo _BAN_REASON_TEXT?></p>
5005
5006                 <div><textarea name="reason" cols="40" rows="5"></textarea></div>
5007
5008                 <h3><?php echo _BAN_ADD_TITLE?></h3>
5009
5010                 <div>
5011                         <input name="action" type="hidden" value="banlistadd" />
5012                         <?php $manager->addTicketHidden() ?>
5013                         <input type="submit" value="<?php echo _BAN_ADD_BTN?>" />
5014                 </div>
5015
5016                 </form>
5017
5018                 <?php           $this->pagefoot();
5019         }
5020
5021         function action_banlistadd() {
5022                 global $member;
5023
5024                 $blogid =               intPostVar('blogid');
5025                 $allblogs =     postVar('allblogs');
5026                 $iprange =              postVar('iprange');
5027                 if ($iprange == "custom")
5028                         $iprange = postVar('customiprange');
5029                 $reason =               postVar('reason');
5030
5031                 $member->blogAdminRights($blogid) or $this->disallow();
5032
5033                 // TODO: check IP range validity
5034
5035                 if (!$allblogs) {
5036                         if (!BAN::addBan($blogid, $iprange, $reason))
5037                                 $this->error(_ERROR_ADDBAN);
5038                 } else {
5039                         // get blogs fot which member has admin rights
5040                         $adminblogs = $member->getAdminBlogs();
5041                         $failed = 0;
5042                         foreach ($adminblogs as $blogje) {
5043                                 if (!BAN::addBan($blogje, $iprange, $reason))
5044                                         $failed = 1;
5045                         }
5046                         if ($failed)
5047                                 $this->error(_ERROR_ADDBAN);
5048                 }
5049
5050                 $this->action_banlist();
5051
5052         }
5053
5054         function action_clearactionlog() {
5055                 global $member;
5056
5057                 $member->isAdmin() or $this->disallow();
5058
5059                 ACTIONLOG::clear();
5060
5061                 $this->action_manage(_MSG_ACTIONLOGCLEARED);
5062         }
5063
5064         function action_backupoverview() {
5065                 global $member, $manager;
5066
5067                 $member->isAdmin() or $this->disallow();
5068
5069                 $this->pagehead();
5070
5071                 echo '<p><a href="index.php?action=manage">(',_BACKTOMANAGE,')</a></p>';
5072                 ?>
5073                 <h2><?php echo _BACKUPS_TITLE?></h2>
5074
5075                 <h3><?php echo _BACKUP_TITLE?></h3>
5076
5077                 <p><?php echo _BACKUP_INTRO?></p>
5078
5079                 <form method="post" action="index.php"><p>
5080                 <input type="hidden" name="action" value="backupcreate" />
5081                 <?php $manager->addTicketHidden() ?>
5082
5083                 <input type="radio" name="gzip" value="1" checked="checked" id="gzip_yes" tabindex="10" /><label for="gzip_yes"><?php echo _BACKUP_ZIP_YES?></label>
5084                 <br />
5085                 <input type="radio" name="gzip" value="0" id="gzip_no" tabindex="10" /><label for="gzip_no" ><?php echo _BACKUP_ZIP_NO?></label>
5086                 <br /><br />
5087                 <input type="submit" value="<?php echo _BACKUP_BTN?>" tabindex="20" />
5088
5089                 </p></form>
5090
5091                 <div class="note"><?php echo _BACKUP_NOTE?></div>
5092
5093
5094                 <h3><?php echo _RESTORE_TITLE?></h3>
5095
5096                 <div class="note"><?php echo _RESTORE_NOTE?></div>
5097
5098                 <p><?php echo _RESTORE_INTRO?></p>
5099
5100                 <form method="post" action="index.php" enctype="multipart/form-data"><p>
5101                         <input type="hidden" name="action" value="backuprestore" />
5102                         <?php $manager->addTicketHidden() ?>
5103                         <input name="backup_file" type="file" tabindex="30" />
5104                         <br /><br />
5105                         <input type="submit" value="<?php echo _RESTORE_BTN?>" tabindex="40" />
5106                         <br /><input type="checkbox" name="letsgo" value="1" id="letsgo" tabindex="50" /><label for="letsgo"><?php echo _RESTORE_IMSURE?></label>
5107                         <br /><?php echo _RESTORE_WARNING?>
5108                 </p></form>
5109
5110                 <?php           $this->pagefoot();
5111         }
5112
5113         function action_backupcreate() {
5114                 global $member, $DIR_LIBS;
5115
5116                 $member->isAdmin() or $this->disallow();
5117
5118                 // use compression ?
5119                 $useGzip = intval(postVar('gzip'));
5120
5121                 include($DIR_LIBS . 'backup.php');
5122
5123                 // try to extend time limit
5124                 // (creating/restoring dumps might take a while)
5125                 @set_time_limit(1200);
5126
5127                 do_backup($useGzip);
5128                 exit;
5129         }
5130
5131
5132         function action_backuprestore() {
5133                 global $member, $DIR_LIBS;
5134
5135                 $member->isAdmin() or $this->disallow();
5136
5137                 if (intPostVar('letsgo') != 1)
5138                         $this->error(_ERROR_BACKUP_NOTSURE);
5139
5140                 include($DIR_LIBS . 'backup.php');
5141
5142                 // try to extend time limit
5143                 // (creating/restoring dumps might take a while)
5144                 @set_time_limit(1200);
5145
5146                 $message = do_restore();
5147                 if ($message != '')
5148                         $this->error($message);
5149
5150                 $this->pagehead();
5151                 ?>
5152                 <h2><?php echo _RESTORE_COMPLETE?></h2>
5153                 <?php           $this->pagefoot();
5154
5155         }
5156
5157
5158         function action_pluginlist() {
5159                 global $member, $manager;
5160
5161                 // check if allowed
5162                 $member->isAdmin() or $this->disallow();
5163
5164                 $this->pagehead();
5165
5166                 echo '<p><a href="index.php?action=manage">(',_BACKTOMANAGE,')</a></p>';
5167
5168                 echo '<h2>' , _PLUGS_TITLE_MANAGE , ' ', help('plugins'), '</h2>';
5169
5170                 echo '<h3>' , _PLUGS_TITLE_INSTALLED , '</h3>';
5171
5172
5173                 $query =  'SELECT * FROM '.sql_table('plugin').' ORDER BY porder ASC';
5174
5175                 $template['content'] = 'pluginlist';
5176                 $template['tabindex'] = 10;
5177                 showlist($query, 'table', $template);
5178
5179                 ?>
5180                         <h3><?php echo _PLUGS_TITLE_UPDATE?></h3>
5181
5182                         <p><?php echo _PLUGS_TEXT_UPDATE?></p>
5183
5184                         <form method="post" action="index.php"><div>
5185                                 <input type="hidden" name="action" value="pluginupdate" />
5186                                 <?php $manager->addTicketHidden() ?>
5187                                 <input type="submit" value="<?php echo _PLUGS_BTN_UPDATE ?>" tabindex="20" />
5188                         </div></form>
5189
5190                         <h3><?php echo _PLUGS_TITLE_NEW?></h3>
5191
5192                         <?php                           // find a list of possibly non-installed plugins
5193                                 $candidates = array();
5194                                 global $DIR_PLUGINS;
5195                                 $dirhandle = opendir($DIR_PLUGINS);
5196                                 while ($filename = readdir($dirhandle)) {
5197                                         if (ereg('^NP_(.*)\.php$',$filename,$matches)) {
5198                                                 $name = $matches[1];
5199                                                 // only show in list when not yet installed
5200                                                 if (mysql_num_rows(sql_query('SELECT * FROM '.sql_table('plugin').' WHERE pfile="NP_'.addslashes($name).'"')) == 0)
5201                                                         array_push($candidates,$name);
5202                                         }
5203                                 }
5204                                 closedir($dirhandle);
5205
5206                                 if (sizeof($candidates) > 0) {
5207                         ?>
5208
5209                         <p><?php echo _PLUGS_ADD_TEXT?></p>
5210
5211
5212                         <form method='post' action='index.php'><div>
5213                                 <input type='hidden' name='action' value='pluginadd' />
5214                                 <?php $manager->addTicketHidden() ?>
5215                                 <select name="filename" tabindex="30">
5216                                 <?php                                   foreach($candidates as $name)
5217                                                 echo '<option value="NP_',$name,'">',htmlspecialchars($name),'</option>';
5218                                 ?>
5219                                 </select>
5220                                 <input type='submit' tabindex="40" value='<?php echo _PLUGS_BTN_INSTALL?>' />
5221                         </div></form>
5222
5223                 <?php                   } else {        // sizeof(candidates) == 0
5224                                 echo '<p>',_PLUGS_NOCANDIDATES,'</p>';
5225                         }
5226
5227                 $this->pagefoot();
5228         }
5229
5230         function action_pluginhelp() {
5231                 global $member, $manager, $DIR_PLUGINS, $CONF;
5232
5233                 // check if allowed
5234                 $member->isAdmin() or $this->disallow();
5235
5236                 $plugid = intGetVar('plugid');
5237
5238                 if (!$manager->pidInstalled($plugid))
5239                         $this->error(_ERROR_NOSUCHPLUGIN);
5240
5241                 $plugName = getPluginNameFromPid($plugid);
5242
5243                 $this->pagehead();
5244
5245                 echo '<p><a href="index.php?action=pluginlist">(',_PLUGS_BACK,')</a></p>';
5246
5247                 echo '<h2>',_PLUGS_HELP_TITLE,': ',htmlspecialchars($plugName),'</h2>';
5248
5249                 $plug =& $manager->getPlugin($plugName);
5250                 $helpFile = $DIR_PLUGINS.$plug->getShortName().'/help.html';
5251
5252                 if (($plug->supportsFeature('HelpPage') > 0) && (@file_exists($helpFile))) {
5253                         @readfile($helpFile);
5254                 } else {
5255                         echo '<p>Error: ', _ERROR_PLUGNOHELPFILE,'</p>';
5256                         echo '<p><a href="index.php?action=pluginlist">(',_BACK,')</a></p>';
5257                 }
5258
5259
5260                 $this->pagefoot();
5261         }
5262
5263
5264         function action_pluginadd() {
5265                 global $member, $manager, $DIR_PLUGINS;
5266
5267                 // check if allowed
5268                 $member->isAdmin() or $this->disallow();
5269
5270                 $name = postVar('filename');
5271
5272                 if ($manager->pluginInstalled($name))
5273                         $this->error(_ERROR_DUPPLUGIN);
5274                 if (!checkPlugin($name))
5275                         $this->error(_ERROR_PLUGFILEERROR . ' (' . $name . ')');
5276
5277                 // check if the plugin dependency is met
5278                 $plugin =& $manager->getPlugin($name);
5279                 $pluginList = $plugin->getPluginDep();
5280                 foreach ($pluginList as $pluginName)
5281                 {
5282
5283                         $res = sql_query('SELECT * FROM '.sql_table('plugin') . ' WHERE pfile="' . $pluginName . '"');
5284                         if (mysql_num_rows($res) == 0)
5285                         {
5286                                 // uninstall plugin again...
5287                                 $this->deleteOnePlugin($plugin->getID());
5288
5289                                 $this->error(_ERROR_INSREQPLUGIN . $pluginName);
5290                         }
5291                 }
5292
5293                 // get number of currently installed plugins
5294                 $numCurrent = mysql_num_rows(sql_query('SELECT * FROM '.sql_table('plugin')));
5295
5296                 // plugin will be added as last one in the list
5297                 $newOrder = $numCurrent + 1;
5298
5299                 $manager->notify(
5300                         'PreAddPlugin',
5301                         array(
5302                                 'file' => &$name
5303                         )
5304                 );
5305
5306                 // do this before calling getPlugin (in case the plugin id is used there)
5307                 $query = 'INSERT INTO '.sql_table('plugin').' (porder, pfile) VALUES ('.$newOrder.',"'.addslashes($name).'")';
5308                 sql_query($query);
5309                 $iPid = mysql_insert_id();
5310
5311                 // need to update the plugin object's pid since we didn't have it above when it's first create....
5312                 $plugin->plugid = $iPid;
5313
5314                 $manager->clearCachedInfo('installedPlugins');
5315
5316                 // call the install method of the plugin
5317                 if (!$plugin)
5318                 {
5319                         sql_query('DELETE FROM ' . sql_table('plugin') . ' WHERE pid='. intval($iPid));
5320                         $manager->clearCachedInfo('installedPlugins');
5321                         $this->error('Plugin could not be loaded, or does not support certain features that are required for it to run on your Nucleus installation (you might want to check the <a href="?action=actionlog">actionlog</a> for more info)');
5322                 }
5323
5324                 // check if plugin needs a newer Nucleus version
5325                 if (getNucleusVersion() < $plugin->getMinNucleusVersion())
5326                 {
5327                         // uninstall plugin again...
5328                         $this->deleteOnePlugin($plugin->getID());
5329
5330                         // ...and show error
5331                         $this->error(_ERROR_NUCLEUSVERSIONREQ . $plugin->getMinNucleusVersion());
5332                 }
5333
5334                 // check if plugin needs a newer Nucleus version
5335                 if ((getNucleusVersion() == $plugin->getMinNucleusVersion()) && (getNucleusPatchLevel() < $plugin->getMinNucleusPatchLevel()))
5336                 {
5337                         // uninstall plugin again...
5338                         $this->deleteOnePlugin($plugin->getID());
5339
5340                         // ...and show error
5341                         $this->error(_ERROR_NUCLEUSVERSIONREQ . $plugin->getMinNucleusVersion() . ' patch ' . $plugin->getMinNucleusPatchLevel());
5342                 }
5343
5344                 $plugin->install();
5345
5346                 $manager->notify(
5347                         'PostAddPlugin',
5348                         array(
5349                                 'plugin' => &$plugin
5350                         )
5351                 );
5352
5353                 // update all events
5354                 $this->action_pluginupdate();
5355         }
5356
5357         function action_pluginupdate() {
5358                 global $member, $manager;
5359
5360                 // check if allowed
5361                 $member->isAdmin() or $this->disallow();
5362
5363                 // delete everything from plugin_events
5364                 sql_query('DELETE FROM '.sql_table('plugin_event'));
5365
5366                 // loop over all installed plugins
5367                 $res = sql_query('SELECT pid, pfile FROM '.sql_table('plugin'));
5368                 while($o = mysql_fetch_object($res)) {
5369                         $pid = $o->pid;
5370                         $plug =& $manager->getPlugin($o->pfile);
5371                         if ($plug)
5372                         {
5373                                 $eventList = $plug->getEventList();
5374                                 foreach ($eventList as $eventName)
5375                                         sql_query('INSERT INTO '.sql_table('plugin_event').' (pid, event) VALUES ('.$pid.', \''.addslashes($eventName).'\')');
5376                         }
5377                 }
5378
5379                 $this->action_pluginlist();
5380         }
5381
5382         function action_plugindelete() {
5383                 global $member, $manager;
5384
5385                 // check if allowed
5386                 $member->isAdmin() or $this->disallow();
5387
5388                 $pid = intGetVar('plugid');
5389
5390                 if (!$manager->pidInstalled($pid))
5391                         $this->error(_ERROR_NOSUCHPLUGIN);
5392
5393                 $this->pagehead();
5394                 ?>
5395                         <h2><?php echo _DELETE_CONFIRM?></h2>
5396
5397                         <p><?php echo _CONFIRMTXT_PLUGIN?> <strong><?php echo getPluginNameFromPid($pid)?></strong>?</p>
5398
5399                         <form method="post" action="index.php"><div>
5400                         <?php $manager->addTicketHidden() ?>
5401                         <input type="hidden" name="action" value="plugindeleteconfirm" />
5402                         <input type="hidden" name="plugid" value="<?php echo $pid; ?>" />
5403                         <input type="submit" tabindex="10" value="<?php echo _DELETE_CONFIRM_BTN?>" />
5404                         </div></form>
5405                 <?php           $this->pagefoot();
5406         }
5407
5408         function action_plugindeleteconfirm() {
5409                 global $member, $manager;
5410
5411                 // check if allowed
5412                 $member->isAdmin() or $this->disallow();
5413
5414                 $pid = intPostVar('plugid');
5415
5416                 $error = $this->deleteOnePlugin($pid, 1);
5417                 if ($error) {
5418                         $this->error($error);
5419                 }
5420
5421                 $this->action_pluginlist();
5422         }
5423
5424         function deleteOnePlugin($pid, $callUninstall = 0) {
5425                 global $manager;
5426
5427                 $pid = intval($pid);
5428
5429                 if (!$manager->pidInstalled($pid))
5430                         return _ERROR_NOSUCHPLUGIN;
5431
5432                 $name = quickQuery('SELECT pfile as result FROM '.sql_table('plugin').' WHERE pid='.$pid);
5433
5434                 // call the unInstall method of the plugin
5435                 if ($callUninstall) {
5436                         $plugin =& $manager->getPlugin($name);
5437                         if ($plugin) $plugin->unInstall();
5438                 }
5439
5440                 // check dependency before delete
5441                 $res = sql_query('SELECT pfile FROM '.sql_table('plugin'));
5442                 while($o = mysql_fetch_object($res)) {
5443                         $plug =& $manager->getPlugin($o->pfile);
5444                         if ($plug)
5445                         {
5446                                 $depList = $plug->getPluginDep();
5447                                 foreach ($depList as $depName)
5448                                 {
5449                                         if ($name == $depName)
5450                                         {
5451                                                 return _ERROR_DELREQPLUGIN . $o->pfile;
5452                                         }
5453                                 }
5454                         }
5455                 }
5456
5457                 $manager->notify('PreDeletePlugin', array('plugid' => $pid));
5458
5459                 // delete all subscriptions
5460                 sql_query('DELETE FROM '.sql_table('plugin_event').' WHERE pid=' . $pid);
5461
5462                 // delete all options
5463                 // get OIDs from plugin_option_desc
5464                 $res = sql_query('SELECT oid FROM ' . sql_table('plugin_option_desc') . ' WHERE opid=' . $pid);
5465                 $aOIDs = array();
5466                 while ($o = mysql_fetch_object($res)) {
5467                         array_push($aOIDs, $o->oid);
5468                 }
5469
5470                 // delete from plugin_option and plugin_option_desc
5471                 sql_query('DELETE FROM '.sql_table('plugin_option_desc').' WHERE opid=' . $pid);
5472                 if (count($aOIDs) > 0)
5473                         sql_query('DELETE FROM '.sql_table('plugin_option').' WHERE oid in ('.implode(',',$aOIDs).')');
5474
5475                 // update order numbers
5476                 $o = mysql_fetch_object(sql_query('SELECT porder FROM '.sql_table('plugin').' WHERE pid=' . $pid));
5477                 sql_query('UPDATE '.sql_table('plugin').' SET porder=(porder - 1) WHERE porder>'.$o->porder);
5478
5479                 // delete row
5480                 sql_query('DELETE FROM '.sql_table('plugin').' WHERE pid='.$pid);
5481
5482                 $manager->clearCachedInfo('installedPlugins');
5483                 $manager->notify('PostDeletePlugin', array('plugid' => $pid));
5484
5485                 return '';
5486         }
5487
5488         function action_pluginup() {
5489                 global $member, $manager;
5490
5491                 // check if allowed
5492                 $member->isAdmin() or $this->disallow();
5493
5494                 $plugid = intGetVar('plugid');
5495
5496                 if (!$manager->pidInstalled($plugid))
5497                         $this->error(_ERROR_NOSUCHPLUGIN);
5498
5499                 // 1. get old order number
5500                 $o = mysql_fetch_object(sql_query('SELECT porder FROM '.sql_table('plugin').' WHERE pid='.$plugid));
5501                 $oldOrder = $o->porder;
5502
5503                 // 2. calculate new order number
5504                 $newOrder = ($oldOrder > 1) ? ($oldOrder - 1) : 1;
5505
5506                 // 3. update plug numbers
5507                 sql_query('UPDATE '.sql_table('plugin').' SET porder='.$oldOrder.' WHERE porder='.$newOrder);
5508                 sql_query('UPDATE '.sql_table('plugin').' SET porder='.$newOrder.' WHERE pid='.$plugid);
5509
5510                 $this->action_pluginlist();
5511         }
5512
5513         function action_plugindown() {
5514                 global $member, $manager;
5515
5516                 // check if allowed
5517                 $member->isAdmin() or $this->disallow();
5518
5519                 $plugid = intGetVar('plugid');
5520                 if (!$manager->pidInstalled($plugid))
5521                         $this->error(_ERROR_NOSUCHPLUGIN);
5522
5523                 // 1. get old order number
5524                 $o = mysql_fetch_object(sql_query('SELECT porder FROM '.sql_table('plugin').' WHERE pid='.$plugid));
5525                 $oldOrder = $o->porder;
5526
5527                 $maxOrder = mysql_num_rows(sql_query('SELECT * FROM '.sql_table('plugin')));
5528
5529                 // 2. calculate new order number
5530                 $newOrder = ($oldOrder < $maxOrder) ? ($oldOrder + 1) : $maxOrder;
5531
5532                 // 3. update plug numbers
5533                 sql_query('UPDATE '.sql_table('plugin').' SET porder='.$oldOrder.' WHERE porder='.$newOrder);
5534                 sql_query('UPDATE '.sql_table('plugin').' SET porder='.$newOrder.' WHERE pid='.$plugid);
5535
5536                 $this->action_pluginlist();
5537         }
5538
5539         function action_pluginoptions($message = '') {
5540                 global $member, $manager;
5541
5542                 // check if allowed
5543                 $member->isAdmin() or $this->disallow();
5544
5545                 $pid = intRequestVar('plugid');
5546                 if (!$manager->pidInstalled($pid))
5547                         $this->error(_ERROR_NOSUCHPLUGIN);
5548
5549                 $extrahead = '<script type="text/javascript" src="javascript/numbercheck.js"></script>';
5550                 $this->pagehead($extrahead);
5551
5552                 ?>
5553                         <p><a href="index.php?action=pluginlist">(<?php echo _PLUGS_BACK?>)</a></p>
5554
5555                         <h2>Options for <?php echo htmlspecialchars(getPluginNameFromPid($pid))?></h2>
5556
5557                         <?php if  ($message) echo $message?>
5558
5559                         <form action="index.php" method="post">
5560                         <div>
5561                                 <input type="hidden" name="action" value="pluginoptionsupdate" />
5562                                 <input type="hidden" name="plugid" value="<?php echo $pid?>" />
5563
5564                 <?php
5565
5566                 $manager->addTicketHidden();
5567
5568                 $aOptions = array();
5569                 $aOIDs = array();
5570                 $query = 'SELECT * FROM ' . sql_table('plugin_option_desc') . ' WHERE ocontext=\'global\' and opid=' . $pid . ' ORDER BY oid ASC';
5571                 $r = sql_query($query);
5572                 while ($o = mysql_fetch_object($r)) {
5573                         array_push($aOIDs, $o->oid);
5574                         $aOptions[$o->oid] = array(
5575                                                 'oid' => $o->oid,
5576                                                 'value' => $o->odef,
5577                                                 'name' => $o->oname,
5578                                                 'description' => $o->odesc,
5579                                                 'type' => $o->otype,
5580                                                 'typeinfo' => $o->oextra,
5581                                                 'contextid' => 0
5582                         );
5583                 }
5584                 // fill out actual values
5585                 if (count($aOIDs) > 0) {
5586                         $r = sql_query('SELECT oid, ovalue FROM ' . sql_table('plugin_option') . ' WHERE oid in ('.implode(',',$aOIDs).')');
5587                         while ($o = mysql_fetch_object($r))
5588                                 $aOptions[$o->oid]['value'] = $o->ovalue;
5589                 }
5590
5591                 // call plugins
5592                 $manager->notify('PrePluginOptionsEdit',array('context' => 'global', 'plugid' => $pid, 'options'=>&$aOptions));
5593
5594                 $template['content'] = 'plugoptionlist';
5595                 $amount = showlist($aOptions,'table',$template);
5596                 if ($amount == 0)
5597                         echo '<p>',_ERROR_NOPLUGOPTIONS,'</p>';
5598
5599                 ?>
5600                         </div>
5601                         </form>
5602                 <?php           $this->pagefoot();
5603
5604
5605
5606         }
5607
5608         function action_pluginoptionsupdate() {
5609                 global $member, $manager;
5610
5611                 // check if allowed
5612                 $member->isAdmin() or $this->disallow();
5613
5614                 $pid = intRequestVar('plugid');
5615                 if (!$manager->pidInstalled($pid))
5616                         $this->error(_ERROR_NOSUCHPLUGIN);
5617
5618                 $aOptions = requestArray('plugoption');
5619                 NucleusPlugin::_applyPluginOptions($aOptions);
5620
5621                 $manager->notify('PostPluginOptionsUpdate',array('context' => 'global', 'plugid' => $pid));
5622
5623                 $this->action_pluginoptions(_PLUGS_OPTIONS_UPDATED);
5624         }
5625
5626         /**
5627           * @static
5628           */
5629         function _insertPluginOptions($context, $contextid = 0) {
5630                 // get all current values for this contextid
5631                 // (note: this might contain doubles for overlapping contextids)
5632                 $aIdToValue = array();
5633                 $res = sql_query('SELECT oid, ovalue FROM ' . sql_table('plugin_option') . ' WHERE ocontextid=' . intval($contextid));
5634                 while ($o = mysql_fetch_object($res)) {
5635                         $aIdToValue[$o->oid] = $o->ovalue;
5636                 }
5637
5638                 // get list of oids per pid
5639                 $query = 'SELECT * FROM ' . sql_table('plugin_option_desc') . ',' . sql_table('plugin')
5640                            . ' WHERE opid=pid and ocontext=\''.addslashes($context).'\' ORDER BY porder, oid ASC';
5641                 $res = sql_query($query);
5642                 $aOptions = array();
5643                 while ($o = mysql_fetch_object($res)) {
5644                         if (in_array($o->oid, array_keys($aIdToValue)))
5645                                 $value = $aIdToValue[$o->oid];
5646                         else
5647                                 $value = $o->odef;
5648
5649                         array_push($aOptions, array(
5650                                 'pid' => $o->pid,
5651                                 'pfile' => $o->pfile,
5652                                 'oid' => $o->oid,
5653                                 'value' => $value,
5654                                 'name' => $o->oname,
5655                                 'description' => $o->odesc,
5656                                 'type' => $o->otype,
5657                                 'typeinfo' => $o->oextra,
5658                                 'contextid' => $contextid,
5659                                 'extra' => ''
5660                         ));
5661                 }
5662
5663                 global $manager;
5664                 $manager->notify('PrePluginOptionsEdit',array('context' => $context, 'contextid' => $contextid, 'options'=>&$aOptions));
5665
5666
5667                 $iPrevPid = -1;
5668                 foreach ($aOptions as $aOption) {
5669
5670                         // new plugin?
5671                         if ($iPrevPid != $aOption['pid']) {
5672                                 $iPrevPid = $aOption['pid'];
5673
5674                                 echo '<tr><th colspan="2">Options for ', htmlspecialchars($aOption['pfile']),'</th></tr>';
5675                         }
5676
5677                         echo '<tr>';
5678                         listplug_plugOptionRow($aOption);
5679                         echo '</tr>';
5680
5681                 }
5682
5683
5684         }
5685
5686         /* helper functions to create option forms etc. */
5687         function input_yesno($name, $checkedval,$tabindex = 0, $value1 = 1, $value2 = 0, $yesval = _YES, $noval = _NO) {
5688                 $id = htmlspecialchars($name);
5689                 $id = str_replace('[','-',$id);
5690                 $id = str_replace(']','-',$id);
5691                 $id1 = $id . htmlspecialchars($value1);
5692                 $id2 = $id . htmlspecialchars($value2);
5693
5694                 echo '<input type="radio" name="', htmlspecialchars($name),'" value="', htmlspecialchars($value1),'" ';
5695                         if ($checkedval == $value1)
5696                                 echo "tabindex='$tabindex' checked='checked'";
5697                         echo ' id="'.$id1.'" /><label for="'.$id1.'">' . $yesval . '</label>';
5698                 echo ' ';
5699                 echo '<input type="radio" name="', htmlspecialchars($name),'" value="', htmlspecialchars($value2),'" ';
5700                         if ($checkedval != $value1)
5701                                 echo "tabindex='$tabindex' checked='checked'";
5702                         echo ' id="'.$id2.'" /><label for="'.$id2.'">' . $noval . '</label>';
5703         }
5704
5705
5706
5707 } // class ADMIN
5708
5709 class ENCAPSULATE {
5710         /**
5711           * Uses $call to call a function using parameters $params
5712           * This function should return the amount of entries shown.
5713           * When entries are show, batch operation handlers are shown too.
5714           * When no entries were shown, $errormsg is used to display an error
5715           *
5716           * Passes on the amount of results found (for further encapsulation)
5717           */
5718         function doEncapsulate($call, $params, $errorMessage = 'No entries') {
5719                 // start output buffering
5720                 ob_start();
5721
5722                 $nbOfRows = call_user_func_array($call, $params);
5723
5724                 // get list contents and stop buffering
5725                 $list = ob_get_contents();
5726                 ob_end_clean();
5727
5728                 if ($nbOfRows > 0) {
5729                         $this->showHead();
5730                         echo $list;
5731                         $this->showFoot();
5732                 } else {
5733                         echo $errorMessage;
5734                 }
5735
5736                 return $nbOfRows;
5737         }
5738 }
5739
5740
5741 /**
5742   * A class used to encapsulate a list of some sort inside next/prev buttons
5743   */
5744 class NAVLIST extends ENCAPSULATE {
5745
5746         function NAVLIST($action, $start, $amount, $minamount, $maxamount, $blogid, $search, $itemid) {
5747                 $this->action = $action;
5748                 $this->start = $start;
5749                 $this->amount = $amount;
5750                 $this->minamount = $minamount;
5751                 $this->maxamount = $maxamount;
5752                 $this->blogid = $blogid;
5753                 $this->search = $search;
5754                 $this->itemid = $itemid;
5755         }
5756
5757         function showBatchList($batchtype, $query, $type, $template, $errorMessage = _LISTS_NOMORE) {
5758                 $batch =& new BATCH($batchtype);
5759
5760                 $this->doEncapsulate(
5761                                 array(&$batch, 'showlist'),
5762                                 array(&$query, $type, $template),
5763                                 $errorMessage
5764                 );
5765
5766         }
5767
5768
5769         function showHead() {
5770                 $this->showNavigation();
5771         }
5772         function showFoot() {
5773                 $this->showNavigation();
5774         }
5775
5776         /**
5777           * Displays a next/prev bar for long tables
5778           */
5779         function showNavigation() {
5780                 $action = $this->action;
5781                 $start = $this->start;
5782                 $amount = $this->amount;
5783                 $minamount = $this->minamount;
5784                 $maxamount = $this->maxamount;
5785                 $blogid = $this->blogid;
5786                 $search = $this->search;
5787                 $itemid = $this->itemid;
5788
5789                 $prev = $start - $amount;
5790                 if ($prev < $minamount) $prev=$minamount;
5791
5792                 // maxamount not used yet
5793         //      if ($start + $amount <= $maxamount)
5794                         $next = $start + $amount;
5795         //      else
5796         //              $next = $start;
5797
5798         ?>
5799         <table class="navigation">
5800         <tr><td>
5801                 <form method="post" action="index.php"><div>
5802                 <input type="submit" value="&lt;&lt; <?php echo  _LISTS_PREV?>" />
5803                 <input type="hidden" name="blogid" value="<?php echo  $blogid; ?>" />
5804                 <input type="hidden" name="itemid" value="<?php echo  $itemid; ?>" />
5805                 <input type="hidden" name="action" value="<?php echo  $action; ?>" />
5806                 <input type="hidden" name="amount" value="<?php echo  $amount; ?>" />
5807                 <input type="hidden" name="search" value="<?php echo  $search; ?>" />
5808                 <input type="hidden" name="start" value="<?php echo  $prev; ?>" />
5809                 </div></form>
5810         </td><td>
5811                 <form method="post" action="index.php"><div>
5812                 <input type="hidden" name="blogid" value="<?php echo  $blogid; ?>" />
5813                 <input type="hidden" name="itemid" value="<?php echo  $itemid; ?>" />
5814                 <input type="hidden" name="action" value="<?php echo  $action; ?>" />
5815                 <input name="amount" size="3" value="<?php echo  $amount; ?>" /> <?php echo _LISTS_PERPAGE?>
5816                 <input type="hidden" name="start" value="<?php echo  $start; ?>" />
5817                 <input type="hidden" name="search" value="<?php echo  $search; ?>" />
5818                 <input type="submit" value="&gt; <?php echo _LISTS_CHANGE?>" />
5819                 </div></form>
5820         </td><td>
5821                 <form method="post" action="index.php"><div>
5822                 <input type="hidden" name="blogid" value="<?php echo  $blogid; ?>" />
5823                 <input type="hidden" name="itemid" value="<?php echo  $itemid; ?>" />
5824                 <input type="hidden" name="action" value="<?php echo  $action; ?>" />
5825                 <input type="hidden" name="amount" value="<?php echo  $amount; ?>" />
5826                 <input type="hidden" name="start" value="0" />
5827                 <input type="text" name="search" value="<?php echo  $search; ?>" size="7" />
5828                 <input type="submit" value="&gt; <?php echo  _LISTS_SEARCH?>" />
5829                 </div></form>
5830         </td><td>
5831                 <form method="post" action="index.php"><div>
5832                 <input type="submit" value="<?php echo _LISTS_NEXT?> &gt; &gt;" />
5833                 <input type="hidden" name="search" value="<?php echo  $search; ?>" />
5834                 <input type="hidden" name="blogid" value="<?php echo  $blogid; ?>" />
5835                 <input type="hidden" name="itemid" value="<?php echo  $itemid; ?>" />
5836                 <input type="hidden" name="action" value="<?php echo  $action; ?>" />
5837                 <input type="hidden" name="amount" value="<?php echo  $amount; ?>" />
5838                 <input type="hidden" name="start" value="<?php echo  $next; ?>" />
5839                 </div></form>
5840         </td></tr>
5841         </table>
5842         <?php   }
5843
5844
5845 }
5846
5847 /**
5848  * A class used to encapsulate a list of some sort in a batch selection
5849  */
5850 class BATCH extends ENCAPSULATE {
5851         function BATCH($type) {
5852                 $this->type = $type;
5853         }
5854
5855         function showHead() {
5856                 ?>
5857                         <form method="post" action="index.php">
5858                 <?php
5859 // TODO: get a list op operations above the list too
5860 // (be careful not to use the same names for the select...)
5861 //              $this->showOperationList();
5862         }
5863
5864         function showFoot() {
5865                 $this->showOperationList();
5866                 ?>
5867                         </form>
5868                 <?php   }
5869
5870         function showOperationList() {
5871                 global $manager;
5872                 ?>
5873                 <div class="batchoperations">
5874                         <?php echo _BATCH_WITH_SEL ?>
5875                         <select name="batchaction">
5876                         <?php                           $options = array();
5877                                 switch($this->type) {
5878                                         case 'item':
5879                                                 $options = array(
5880                                                         'delete'        => _BATCH_ITEM_DELETE,
5881                                                         'move'          => _BATCH_ITEM_MOVE
5882                                                 );
5883                                                 break;
5884                                         case 'member':
5885                                                 $options = array(
5886                                                         'delete'        => _BATCH_MEMBER_DELETE,
5887                                                         'setadmin'      => _BATCH_MEMBER_SET_ADM,
5888                                                         'unsetadmin' => _BATCH_MEMBER_UNSET_ADM
5889                                                 );
5890                                                 break;
5891                                         case 'team':
5892                                                 $options = array(
5893                                                         'delete'        => _BATCH_TEAM_DELETE,
5894                                                         'setadmin'      => _BATCH_TEAM_SET_ADM,
5895                                                         'unsetadmin' => _BATCH_TEAM_UNSET_ADM,
5896                                                 );
5897                                                 break;
5898                                         case 'category':
5899                                                 $options = array(
5900                                                         'delete'        => _BATCH_CAT_DELETE,
5901                                                         'move'          => _BATCH_CAT_MOVE,
5902                                                 );
5903                                                 break;
5904                                         case 'comment':
5905                                                 $options = array(
5906                                                         'delete'        => _BATCH_COMMENT_DELETE,
5907                                                 );
5908                                         break;
5909                                 }
5910                                 foreach ($options as $option => $label) {
5911                                         echo '<option value="',$option,'">',$label,'</option>';
5912                                 }
5913                         ?>
5914                         </select>
5915                         <input type="hidden" name="action" value="batch<?php echo $this->type?>" />
5916                         <?php
5917                                 $manager->addTicketHidden();
5918
5919                                 // add hidden fields for 'team' and 'comment' batchlists
5920                                 if ($this->type == 'team')
5921                                 {
5922                                         echo '<input type="hidden" name="blogid" value="',intRequestVar('blogid'),'" />';
5923                                 }
5924                                 if ($this->type == 'comment')
5925                                 {
5926                                         echo '<input type="hidden" name="itemid" value="',intRequestVar('itemid'),'" />';
5927                                 }
5928
5929                                 echo '<input type="submit" value="',_BATCH_EXEC,'" />';
5930                         ?>(
5931                          <a href="" onclick="if (event &amp;&amp; event.preventDefault) event.preventDefault(); return batchSelectAll(1); "><?php echo _BATCH_SELECTALL?></a> -
5932                          <a href="" onclick="if (event &amp;&amp; event.preventDefault) event.preventDefault(); return batchSelectAll(0); "><?php echo _BATCH_DESELECTALL?></a>
5933                         )
5934                 </div>
5935                 <?php   }
5936
5937         // shortcut :)
5938         function showList($query, $type, $template, $errorMessage = _LISTS_NOMORE) {
5939                 return $this->doEncapsulate(    'showlist',
5940                                                                         array($query, $type, $template),
5941                                                                         $errorMessage
5942                                                                 );
5943         }
5944
5945 }
5946
5947
5948
5949 // can take either an array of objects, or an SQL query
5950 function showlist($query, $type, $template) {
5951
5952         if (is_array($query)) {
5953                 if (sizeof($query) == 0)
5954                         return 0;
5955
5956                 call_user_func('listplug_' . $type, $template, 'HEAD');
5957
5958                 foreach ($query as $currentObj) {
5959                         $template['current'] = $currentObj;
5960                         call_user_func('listplug_' . $type, $template, 'BODY');
5961                 }
5962
5963                 call_user_func('listplug_' . $type, $template, 'FOOT');
5964
5965                 return sizeof($query);
5966
5967         } else {
5968                 $res = sql_query($query);
5969
5970                 // don't do anything if there are no results
5971                 $numrows = mysql_num_rows($res);
5972                 if ($numrows == 0)
5973                         return 0;
5974
5975                 call_user_func('listplug_' . $type, $template, 'HEAD');
5976
5977                 while($template['current'] = mysql_fetch_object($res))
5978                         call_user_func('listplug_' . $type, $template, 'BODY');
5979
5980                 call_user_func('listplug_' . $type, $template, 'FOOT');
5981
5982                 mysql_free_result($res);
5983
5984                 // return amount of results
5985                 return $numrows;
5986         }
5987 }
5988
5989 function listplug_select($template, $type) {
5990         switch($type) {
5991                 case 'HEAD':
5992                         echo '<select name="'.$template['name'].'" tabindex="'.$template['tabindex'].'" '.$template['javascript'].'>';
5993
5994                         // add extra row if needed
5995                         if ($template['extra']) {
5996                                 echo '<option value="',$template['extraval'],'">',$template['extra'],'</option>';
5997                         }
5998
5999                         break;
6000                 case 'BODY':
6001                         $current = $template['current'];
6002
6003                         echo '<option value="' . htmlspecialchars($current->value) . '"';
6004                         if ($template['selected'] == $current->value)
6005                                 echo ' selected="selected" ';
6006                         if ($template['shorten'] > 0) {
6007                                 echo ' title="'. htmlspecialchars($current->text).'"';
6008                                 $current->text = shorten($current->text, $template['shorten'], $template['shortenel']);
6009                         }
6010                         echo '>' . htmlspecialchars($current->text) . '</option>';
6011                         break;
6012                 case 'FOOT':
6013                         echo '</select>';
6014                         break;
6015         }
6016 }
6017
6018 function listplug_table($template, $type) {
6019         switch($type) {
6020                 case 'HEAD':
6021                         echo "<table>";
6022                         echo "<thead><tr>";
6023                         // print head
6024                         call_user_func("listplug_table_" . $template['content'] , $template, 'HEAD');
6025                         echo "</tr></thead><tbody>";
6026                         break;
6027                 case 'BODY':
6028                         // print tabletype specific thingies
6029                         echo "<tr onmouseover='focusRow(this);' onmouseout='blurRow(this);'>";
6030                         call_user_func("listplug_table_" . $template['content'] , $template,  'BODY');
6031                         echo "</tr>";
6032                         break;
6033                 case 'FOOT':
6034                         call_user_func("listplug_table_" . $template['content'] , $template,  'FOOT');
6035                         echo "</tbody></table>";
6036                         break;
6037         }
6038 }
6039
6040 function listplug_table_memberlist($template, $type) {
6041         switch($type) {
6042                 case 'HEAD':
6043                         echo '<th>' . _LIST_MEMBER_NAME . '</th><th>' . _LIST_MEMBER_RNAME . '</th><th>' . _LIST_MEMBER_URL . '</th><th>' . _LIST_MEMBER_ADMIN;
6044                         help('superadmin');
6045                         echo "</th><th>" . _LIST_MEMBER_LOGIN;
6046                         help('canlogin');
6047                         echo "</th><th colspan='2'>" . _LISTS_ACTIONS. "</th>";
6048                         break;
6049                 case 'BODY':
6050                         $current = $template['current'];
6051
6052                         echo '<td>';
6053                         $id = listplug_nextBatchId();
6054                         echo '<input type="checkbox" id="batch',$id,'" name="batch[',$id,']" value="',$current->mnumber,'" />';
6055                         echo '<label for="batch',$id,'">';
6056                         echo "<a href='mailto:", htmlspecialchars($current->memail), "' tabindex='".$template['tabindex']."'>", htmlspecialchars($current->mname), "</a>";
6057                         echo '</label>';
6058                         echo '</td>';
6059                         echo '<td>', htmlspecialchars($current->mrealname), '</td>';
6060                         echo "<td><a href='$current->murl' tabindex='".$template['tabindex']."'>$current->murl</a></td>";
6061                         echo '<td>', ($current->madmin ? _YES : _NO),'</td>';
6062                         echo '<td>', ($current->mcanlogin ? _YES : _NO), '</td>';
6063                         echo "<td><a href='index.php?action=memberedit&amp;memberid=$current->mnumber' tabindex='".$template['tabindex']."'>"._LISTS_EDIT."</a></td>";
6064                         echo "<td><a href='index.php?action=memberdelete&amp;memberid=$current->mnumber' tabindex='".$template['tabindex']."'>"._LISTS_DELETE."</a></td>";
6065                         break;
6066         }
6067 }
6068
6069 function listplug_table_teamlist($template, $type) {
6070         global $manager;
6071         switch($type) {
6072                 case 'HEAD':
6073                         echo "<th>"._LIST_MEMBER_NAME."</th><th>"._LIST_MEMBER_RNAME."</th><th>"._LIST_TEAM_ADMIN;
6074                         help('teamadmin');
6075                         echo "</th><th colspan='2'>"._LISTS_ACTIONS."</th>";
6076                         break;
6077                 case 'BODY':
6078                         $current = $template['current'];
6079
6080                         echo '<td>';
6081                         $id = listplug_nextBatchId();
6082                         echo '<input type="checkbox" id="batch',$id,'" name="batch[',$id,']" value="',$current->tmember,'" />';
6083                         echo '<label for="batch',$id,'">';
6084                         echo "<a href='mailto:", htmlspecialchars($current->memail), "' tabindex='".$template['tabindex']."'>", htmlspecialchars($current->mname), "</a>";
6085                         echo '</label>';
6086                         echo '</td>';
6087                         echo '<td>', htmlspecialchars($current->mrealname), '</td>';
6088                         echo '<td>', ($current->tadmin ? _YES : _NO) , '</td>';
6089                         echo "<td><a href='index.php?action=teamdelete&amp;memberid=$current->tmember&amp;blogid=$current->tblog' tabindex='".$template['tabindex']."'>"._LISTS_DELETE."</a></td>";
6090
6091                         $url = 'index.php?action=teamchangeadmin&memberid=' . intval($current->tmember) . '&blogid=' . intval($current->tblog);
6092                         $url = $manager->addTicketToUrl($url);
6093                         echo "<td><a href='",htmlspecialchars($url),"' tabindex='".$template['tabindex']."'>"._LIST_TEAM_CHADMIN."</a></td>";
6094                         break;
6095         }
6096 }
6097
6098 function encode_desc(&$data)
6099     {   //_$to_entities = get_html_translation_table(HTML_ENTITIES);
6100         $to_entities = get_html_translation_table(HTML_SPECIALCHARS);
6101         $from_entities = array_flip($to_entities);
6102         $data = str_replace('<br />','\n',$data); //hack
6103         $data = strtr($data,$from_entities);
6104         $data = strtr($data,$to_entities);
6105         $data = str_replace('\n','<br />',$data); //hack
6106         return $data;
6107     }
6108
6109 function listplug_table_pluginlist($template, $type) {
6110         global $manager;
6111         switch($type) {
6112                 case 'HEAD':
6113                         echo '<th>'._LISTS_INFO.'</th><th>'._LISTS_DESC.'</th>';
6114                         echo '<th style="white-space:nowrap">'._LISTS_ACTIONS.'</th>';
6115                         break;
6116                 case 'BODY':
6117                         $current = $template['current'];
6118
6119                         $plug =& $manager->getPlugin($current->pfile);
6120                         if ($plug) {
6121                                 echo '<td>';
6122                                         echo '<strong>' , htmlspecialchars($plug->getName()) , '</strong><br />';
6123                                         echo _LIST_PLUGS_AUTHOR, ' ' , htmlspecialchars($plug->getAuthor()) , '<br />';
6124                                         echo _LIST_PLUGS_VER, ' ' , htmlspecialchars($plug->getVersion()) , '<br />';
6125                                         if ($plug->getURL())
6126                                         echo '<a href="',htmlspecialchars($plug->getURL()),'" tabindex="'.$template['tabindex'].'">',_LIST_PLUGS_SITE,'</a><br />';
6127                                 echo '</td>';
6128                                 echo '<td>';
6129                                         echo _LIST_PLUGS_DESC .'<br/>'. encode_desc($plug->getDescription());
6130                                         if (sizeof($plug->getEventList()) > 0) {
6131                                                 echo '<br /><br />',_LIST_PLUGS_SUBS,'<br />',htmlspecialchars(implode($plug->getEventList(),', '));
6132                                                 // check the database to see if it is up-to-date and notice the user if not
6133                                         }
6134                                         if (!$plug->subscribtionListIsUptodate()) {
6135                                                 echo '<br /><br /><strong>',_LIST_PLUG_SUBS_NEEDUPDATE,'</strong>';
6136                                         }
6137                                         if (sizeof($plug->getPluginDep()) > 0)
6138                                                 echo '<br /><br />',_LIST_PLUGS_DEP,'<br />',htmlspecialchars(implode($plug->getPluginDep(),', '));
6139                                 echo '</td>';
6140                         } else {
6141                                 echo '<td colspan="2">Error: plugin file <b>',htmlspecialchars($current->pfile),'.php</b> could not be loaded, or it has been set inactive because it does not support some features (check the <a href="?action=actionlog">actionlog</a> for more info)</td>';
6142                         }
6143                         echo '<td>';
6144
6145                                 $baseUrl = 'index.php?plugid=' . intval($current->pid) . '&action=';
6146                                 $url = $manager->addTicketToUrl($baseUrl . 'pluginup');
6147                                 echo "<a href='",htmlspecialchars($url),"' tabindex='".$template['tabindex']."'>",_LIST_PLUGS_UP,"</a>";
6148                                 $url = $manager->addTicketToUrl($baseUrl . 'plugindown');
6149                                 echo "<br /><a href='",htmlspecialchars($url),"' tabindex='".$template['tabindex']."'>",_LIST_PLUGS_DOWN,"</a>";
6150                                 echo "<br /><a href='index.php?action=plugindelete&amp;plugid=$current->pid' tabindex='".$template['tabindex']."'>",_LIST_PLUGS_UNINSTALL,"</a>";
6151                                 if ($plug && ($plug->hasAdminArea() > 0))
6152                                         echo "<br /><a href='".htmlspecialchars($plug->getAdminURL())."'  tabindex='".$template['tabindex']."'>",_LIST_PLUGS_ADMIN,"</a>";
6153                                 if ($plug && ($plug->supportsFeature('HelpPage') > 0))
6154                                         echo "<br /><a href='index.php?action=pluginhelp&amp;plugid=$current->pid'  tabindex='".$template['tabindex']."'>",_LIST_PLUGS_HELP,"</a>";
6155                                 if (quickQuery('SELECT COUNT(*) AS result FROM '.sql_table('plugin_option_desc').' WHERE ocontext=\'global\' and opid='.$current->pid) > 0)
6156                                         echo "<br /><a href='index.php?action=pluginoptions&amp;plugid=$current->pid'  tabindex='".$template['tabindex']."'>",_LIST_PLUGS_OPTIONS,"</a>";
6157                         echo '</td>';
6158                         break;
6159         }
6160 }
6161
6162 function listplug_table_plugoptionlist($template, $type) {
6163         global $manager;
6164         switch($type) {
6165                 case 'HEAD':
6166                         echo '<th>'._LISTS_INFO.'</th><th>'._LISTS_VALUE.'</th>';
6167                         break;
6168                 case 'BODY':
6169                         $current = $template['current'];
6170                         listplug_plugOptionRow($current);
6171                         break;
6172                 case 'FOOT':
6173                         ?>
6174                         <tr>
6175                                 <th colspan="2"><?php echo _PLUGS_SAVE?></th>
6176                         </tr><tr>
6177                                 <td><?php echo _PLUGS_SAVE?></td>
6178                                 <td><input type="submit" value="<?php echo _PLUGS_SAVE?>" /></td>
6179                         </tr>
6180                         <?php                   break;
6181         }
6182 }
6183
6184 function listplug_plugOptionRow($current) {
6185         $varname = 'plugoption['.$current['oid'].']['.$current['contextid'].']';
6186         // retreive the optionmeta
6187         $meta = NucleusPlugin::getOptionMeta($current['typeinfo']);
6188
6189         // only if it is not a hidden option write the controls to the page
6190         if ($meta['access'] != 'hidden') {
6191                 echo '<td>',htmlspecialchars($current['description']?$current['description']:$current['name']),'</td>';
6192                 echo '<td>';
6193                 switch($current['type']) {
6194                         case 'yesno':
6195                                 ADMIN::input_yesno($varname, $current['value'], 0, 'yes', 'no');
6196                                 break;
6197                         case 'password':
6198                                 echo '<input type="password" size="40" maxlength="128" name="',htmlspecialchars($varname),'" value="',htmlspecialchars($current['value']),'" />';
6199                                 break;
6200                         case 'select':
6201                                 echo '<select name="'.htmlspecialchars($varname).'">';
6202                                 $aOptions = NucleusPlugin::getOptionSelectValues($current['typeinfo']);
6203                                 $aOptions = explode('|', $aOptions);
6204                                 for ($i=0; $i<(count($aOptions)-1); $i+=2) {
6205                                         echo '<option value="'.htmlspecialchars($aOptions[$i+1]).'"';
6206                                         if ($aOptions[$i+1] == $current['value'])
6207                                                 echo ' selected="selected"';
6208                                         echo '>'.htmlspecialchars($aOptions[$i]).'</option>';
6209                                 }
6210                                 echo '</select>';
6211                                 break;
6212                         case 'textarea':
6213                                 //$meta = NucleusPlugin::getOptionMeta($current['typeinfo']);
6214                                 echo '<textarea class="pluginoption" cols="30" rows="5" name="',htmlspecialchars($varname),'"';
6215                                 if ($meta['access'] == 'readonly') {
6216                                         echo ' readonly="readonly"';
6217                                 }
6218                                 echo '>',htmlspecialchars($current['value']),'</textarea>';
6219                                 break;
6220                         case 'text':
6221                         default:
6222                                 //$meta = NucleusPlugin::getOptionMeta($current['typeinfo']);
6223
6224                                 echo '<input type="text" size="40" maxlength="128" name="',htmlspecialchars($varname),'" value="',htmlspecialchars($current['value']),'"';
6225                                 if ($meta['datatype'] == 'numerical') {
6226                                         echo ' onkeyup="checkNumeric(this)" onblur="checkNumeric(this)"';
6227                                 }
6228                                 if ($meta['access'] == 'readonly') {
6229                                         echo ' readonly="readonly"';
6230                                 }
6231                                 echo ' />';
6232                 }
6233                 echo $current['extra'];
6234                 echo '</td>';
6235         }
6236 }
6237
6238 function listplug_table_itemlist($template, $type) {
6239         switch($type) {
6240                 case 'HEAD':
6241                         echo "<th>"._LIST_ITEM_INFO."</th><th>"._LIST_ITEM_CONTENT."</th><th style=\"white-space:nowrap\" colspan='1'>"._LISTS_ACTIONS."</th>";
6242                         break;
6243                 case 'BODY':
6244                         $current = $template['current'];
6245                         $current->itime = strtotime($current->itime);   // string -> unix timestamp
6246
6247                         if ($current->idraft == 1)
6248                                 $cssclass = "class='draft'";
6249
6250                         // (can't use offset time since offsets might vary between blogs)
6251                         if ($current->itime > $template['now'])
6252                                 $cssclass = "class='future'";
6253
6254                         echo "<td $cssclass>",_LIST_ITEM_BLOG,' ', htmlspecialchars($current->bshortname);
6255                         echo "    <br />",_LIST_ITEM_CAT,' ', htmlspecialchars($current->cname);
6256                         echo "    <br />",_LIST_ITEM_AUTHOR, ' ', htmlspecialchars($current->mname);
6257                         echo "    <br />",_LIST_ITEM_DATE," " . date("Y-m-d",$current->itime);
6258                         echo "<br />",_LIST_ITEM_TIME," " . date("H:i",$current->itime);
6259                         echo "</td>";
6260                         echo "<td $cssclass>";
6261
6262                         $id = listplug_nextBatchId();
6263
6264                         echo '<input type="checkbox" id="batch',$id,'" name="batch[',$id,']" value="',$current->inumber,'" />';
6265                         echo '<label for="batch',$id,'">';
6266                         echo "<b>" . htmlspecialchars(strip_tags($current->ititle)) . "</b>";
6267                         echo '</label>';
6268                         echo "<br />";
6269
6270
6271                         $current->ibody = strip_tags($current->ibody);
6272                         $current->ibody = htmlspecialchars(shorten($current->ibody,300,'...'));
6273
6274                         echo "$current->ibody</td>";
6275                         echo "<td style=\"white-space:nowrap\" $cssclass>";
6276                         echo    "<a href='index.php?action=itemedit&amp;itemid=$current->inumber'>"._LISTS_EDIT."</a>";
6277                         echo    "<br /><a href='index.php?action=itemcommentlist&amp;itemid=$current->inumber'>"._LISTS_COMMENTS."</a>";
6278                         echo    "<br /><a href='index.php?action=itemmove&amp;itemid=$current->inumber'>"._LISTS_MOVE."</a>";
6279                         echo    "<br /><a href='index.php?action=itemdelete&amp;itemid=$current->inumber'>"._LISTS_DELETE."</a>";
6280                         echo "</td>";
6281                         break;
6282         }
6283 }
6284
6285 // for batch operations: generates the index numbers for checkboxes
6286 function listplug_nextBatchId() {
6287         static $id = 0;
6288         return $id++;
6289 }
6290
6291 function listplug_table_commentlist($template, $type) {
6292         switch($type) {
6293                 case 'HEAD':
6294                         echo "<th>"._LISTS_INFO."</th><th>"._LIST_COMMENT."</th><th colspan='3'>"._LISTS_ACTIONS."</th>";
6295                         break;
6296                 case 'BODY':
6297                         $current = $template['current'];
6298                         $current->ctime = strtotime($current->ctime);   // string -> unix timestamp
6299
6300                         echo '<td>';
6301                         echo date("Y-m-d@H:i",$current->ctime);
6302                         echo '<br />';
6303                         if ($current->mname)
6304                                 echo htmlspecialchars($current->mname) ,' ', _LIST_COMMENTS_MEMBER;
6305                         else
6306                                 echo htmlspecialchars($current->cuser);
6307                         echo '</td>';
6308
6309
6310                         $current->cbody = strip_tags($current->cbody);
6311                         $current->cbody = htmlspecialchars(shorten($current->cbody, 300, '...'));
6312
6313                         echo '<td>';
6314                         $id = listplug_nextBatchId();
6315                         echo '<input type="checkbox" id="batch',$id,'" name="batch[',$id,']" value="',$current->cnumber,'" />';
6316                         echo '<label for="batch',$id,'">';
6317                         echo $current->cbody;
6318                         echo '</label>';
6319                         echo '</td>';
6320
6321                         echo "<td style=\"white-space:nowrap\"><a href='index.php?action=commentedit&amp;commentid=$current->cnumber'>"._LISTS_EDIT."</a></td>";
6322                         echo "<td style=\"white-space:nowrap\"><a href='index.php?action=commentdelete&amp;commentid=$current->cnumber'>"._LISTS_DELETE."</a></td>";
6323                         if ($template['canAddBan'])
6324                                 echo "<td style=\"white-space:nowrap\"><a href='index.php?action=banlistnewfromitem&amp;itemid=$current->citem&amp;ip=", htmlspecialchars($current->cip), "' title='", htmlspecialchars($current->chost), "'>"._LIST_COMMENT_BANIP."</a></td>";
6325                         break;
6326         }
6327 }
6328
6329
6330 function listplug_table_bloglist($template, $type) {
6331         switch($type) {
6332                 case 'HEAD':
6333                         echo "<th>" . _NAME . "</th><th colspan='7'>" ._LISTS_ACTIONS. "</th>";
6334                         break;
6335                 case 'BODY':
6336                         $current = $template['current'];
6337
6338                         echo "<td title='blogid:$current->bnumber shortname:$current->bshortname'><a href='$current->burl'><img src='images/globe.gif' width='13' height='13' alt='". _BLOGLIST_TT_VISIT."' /></a> " . htmlspecialchars($current->bname) . "</td>";
6339                         echo "<td><a href='index.php?action=createitem&amp;blogid=$current->bnumber' title='" . _BLOGLIST_TT_ADD ."'>" . _BLOGLIST_ADD . "</a></td>";
6340                         echo "<td><a href='index.php?action=itemlist&amp;blogid=$current->bnumber' title='". _BLOGLIST_TT_EDIT."'>". _BLOGLIST_EDIT."</a></td>";
6341                         echo "<td><a href='index.php?action=blogcommentlist&amp;blogid=$current->bnumber' title='". _BLOGLIST_TT_COMMENTS."'>". _BLOGLIST_COMMENTS."</a></td>";
6342                         echo "<td><a href='index.php?action=bookmarklet&amp;blogid=$current->bnumber' title='". _BLOGLIST_TT_BMLET."'>". _BLOGLIST_BMLET . "</a></td>";
6343
6344                         if ($current->tadmin == 1) {
6345                                 echo "<td><a href='index.php?action=blogsettings&amp;blogid=$current->bnumber' title='" . _BLOGLIST_TT_SETTINGS . "'>" ._BLOGLIST_SETTINGS. "</a></td>";
6346                                 echo "<td><a href='index.php?action=banlist&amp;blogid=$current->bnumber' title='" . _BLOGLIST_TT_BANS. "'>". _BLOGLIST_BANS."</a></td>";
6347                         }
6348
6349                         if ($template['superadmin']) {
6350                                 echo "<td><a href='index.php?action=deleteblog&amp;blogid=$current->bnumber' title='". _BLOGLIST_TT_DELETE."'>" ._BLOGLIST_DELETE. "</a></td>";
6351                         }
6352
6353
6354
6355                         break;
6356         }
6357 }
6358
6359 function listplug_table_shortblognames($template, $type) {
6360         switch($type) {
6361                 case 'HEAD':
6362                         echo "<th>" . _NAME . "</th><th>" . _NAME. "</th>";
6363                         break;
6364                 case 'BODY':
6365                         $current = $template['current'];
6366
6367                         echo '<td>' , htmlspecialchars($current->bshortname) , '</td>';
6368                         echo '<td>' , htmlspecialchars($current->bname) , '</td>';
6369
6370                         break;
6371         }
6372 }
6373
6374 function listplug_table_shortnames($template, $type) {
6375         switch($type) {
6376                 case 'HEAD':
6377                         echo "<th>" . _NAME . "</th><th>" . _LISTS_DESC. "</th>";
6378                         break;
6379                 case 'BODY':
6380                         $current = $template['current'];
6381
6382                         echo '<td>' , htmlspecialchars($current->name) , '</td>';
6383                         echo '<td>' , htmlspecialchars($current->description) , '</td>';
6384
6385                         break;
6386         }
6387 }
6388
6389
6390 function listplug_table_categorylist($template, $type) {
6391         switch($type) {
6392                 case 'HEAD':
6393                         echo "<th>"._LISTS_NAME."</th><th>"._LISTS_DESC."</th><th colspan='2'>"._LISTS_ACTIONS."</th>";
6394                         break;
6395                 case 'BODY':
6396                         $current = $template['current'];
6397
6398                         echo '<td>';
6399                         $id = listplug_nextBatchId();
6400                         echo '<input type="checkbox" id="batch',$id,'" name="batch[',$id,']" value="',$current->catid,'" />';
6401                         echo '<label for="batch',$id,'">';
6402                         echo htmlspecialchars($current->cname);
6403                         echo '</label>';
6404                         echo '</td>';
6405
6406                         echo '<td>', htmlspecialchars($current->cdesc), '</td>';
6407                         echo "<td><a href='index.php?action=categorydelete&amp;blogid=$current->cblog&amp;catid=$current->catid' tabindex='".$template['tabindex']."'>"._LISTS_DELETE."</a></td>";
6408                         echo "<td><a href='index.php?action=categoryedit&amp;blogid=$current->cblog&amp;catid=$current->catid' tabindex='".$template['tabindex']."'>"._LISTS_EDIT."</a></td>";
6409
6410                         break;
6411         }
6412 }
6413
6414
6415 function listplug_table_templatelist($template, $type) {
6416         global $manager;
6417         switch($type) {
6418                 case 'HEAD':
6419                         echo "<th>"._LISTS_NAME."</th><th>"._LISTS_DESC."</th><th colspan='3'>"._LISTS_ACTIONS."</th>";
6420                         break;
6421                 case 'BODY':
6422                         $current = $template['current'];
6423
6424                         echo "<td>" , htmlspecialchars($current->tdname), "</td>";
6425                         echo "<td>" , htmlspecialchars($current->tddesc), "</td>";
6426                         echo "<td style=\"white-space:nowrap\"><a href='index.php?action=templateedit&amp;templateid=$current->tdnumber' tabindex='".$template['tabindex']."'>"._LISTS_EDIT."</a></td>";
6427
6428                         $url = $manager->addTicketToUrl('index.php?action=templateclone&templateid=' . intval($current->tdnumber));
6429                         echo "<td style=\"white-space:nowrap\"><a href='",htmlspecialchars($url),"' tabindex='".$template['tabindex']."'>"._LISTS_CLONE."</a></td>";
6430                         echo "<td style=\"white-space:nowrap\"><a href='index.php?action=templatedelete&amp;templateid=$current->tdnumber' tabindex='".$template['tabindex']."'>"._LISTS_DELETE."</a></td>";
6431
6432                         break;
6433         }
6434 }
6435
6436 function listplug_table_skinlist($template, $type) {
6437         global $CONF, $DIR_SKINS, $manager;
6438         switch($type) {
6439                 case 'HEAD':
6440                         echo "<th>"._LISTS_NAME."</th><th>"._LISTS_DESC."</th><th colspan='3'>"._LISTS_ACTIONS."</th>";
6441                         break;
6442                 case 'BODY':
6443                         $current = $template['current'];
6444
6445                         echo '<td>';
6446
6447                         // use a special style for the default skin
6448                         if ($current->sdnumber == $CONF['BaseSkin']) {
6449                                 echo '<strong>',htmlspecialchars($current->sdname),'</strong>';
6450                         } else {
6451                                 echo htmlspecialchars($current->sdname);
6452                         }
6453
6454                         echo '<br /><br />';
6455                         echo _LISTS_TYPE ,': ' , htmlspecialchars($current->sdtype);
6456                         echo '<br />', _LIST_SKINS_INCMODE , ' ' , (($current->sdincmode=='skindir') ?_PARSER_INCMODE_SKINDIR:_PARSER_INCMODE_NORMAL);
6457                         if ($current->sdincpref) echo '<br />' , _LIST_SKINS_INCPREFIX , ' ', htmlspecialchars($current->sdincpref);
6458
6459                         // add preview image when present
6460                         if ($current->sdincpref && @file_exists($DIR_SKINS . $current->sdincpref . 'preview.png'))
6461                         {
6462                                 echo '<br /><br />';
6463
6464                                 $hasEnlargement = @file_exists($DIR_SKINS . $current->sdincpref . 'preview-large.png');
6465                                 if ($hasEnlargement)
6466                                         echo '<a href="',$CONF['SkinsURL'], htmlspecialchars($current->sdincpref),'preview-large.png" title="View larger">';
6467
6468                                 echo '<img class="skinpreview" src="',$CONF['SkinsURL'], htmlspecialchars($current->sdincpref),'preview.png" width="100" height="75" alt="Preview for \'',htmlspecialchars($current->sdname),'\' skin" />';
6469
6470                                 if ($hasEnlargement)
6471                                         echo '</a>';
6472
6473                                 if (@file_exists($DIR_SKINS . $current->sdincpref . 'readme.html'))
6474                                 {
6475                                         echo '<br /><a href="',$CONF['SkinsURL'], htmlspecialchars($current->sdincpref),'readme.html" title="More info on the \'',htmlspecialchars($current->sdname),'\' skin">Readme</a>';
6476                                 }
6477
6478
6479                         }
6480
6481                         echo "</td>";
6482
6483
6484                         echo "<td>" , htmlspecialchars($current->sddesc);
6485                                 // show list of defined parts
6486                                 $r = sql_query('SELECT stype FROM '.sql_table('skin').' WHERE sdesc='.$current->sdnumber . ' ORDER BY stype');
6487                                 $types = array();
6488                                 while ($o = mysql_fetch_object($r))
6489                                         array_push($types,$o->stype);
6490                                 if (sizeof($types) > 0) {
6491                                         $friendlyNames = SKIN::getFriendlyNames();
6492                                         for ($i=0;$i<sizeof($types);$i++) {
6493                                                 $type = $types[$i];
6494                                                 $types[$i] = '<li>' . helpHtml('skinpart'.$type) . ' <a href="index.php?action=skinedittype&amp;skinid='.$current->sdnumber.'&amp;type='.$type.'" tabindex="'.$template['tabindex'].'">' . htmlspecialchars($friendlyNames[$type]) . "</a></li>";
6495                                         }
6496                                         echo '<br /><br />',_LIST_SKINS_DEFINED,' <ul>',implode($types,'') ,'</ul>';
6497                                 }
6498                         echo "</td>";
6499                         echo "<td style=\"white-space:nowrap\"><a href='index.php?action=skinedit&amp;skinid=$current->sdnumber' tabindex='".$template['tabindex']."'>"._LISTS_EDIT."</a></td>";
6500
6501                         $url = $manager->addTicketToUrl('index.php?action=skinclone&skinid=' . intval($current->sdnumber));
6502                         echo "<td style=\"white-space:nowrap\"><a href='",htmlspecialchars($url),"' tabindex='".$template['tabindex']."'>"._LISTS_CLONE."</a></td>";
6503                         echo "<td style=\"white-space:nowrap\"><a href='index.php?action=skindelete&amp;skinid=$current->sdnumber' tabindex='".$template['tabindex']."'>"._LISTS_DELETE."</a></td>";
6504
6505                         break;
6506         }
6507 }
6508
6509 function listplug_table_draftlist($template, $type) {
6510         switch($type) {
6511                 case 'HEAD':
6512                         echo "<th>"._LISTS_BLOG."</th><th>"._LISTS_TITLE."</th><th colspan='2'>"._LISTS_ACTIONS."</th>";
6513                         break;
6514                 case 'BODY':
6515                         $current = $template['current'];
6516
6517                         echo '<td>', htmlspecialchars($current->bshortname) , '</td>';
6518                         echo '<td>', htmlspecialchars(strip_tags($current->ititle)) , '</td>';
6519                         echo "<td><a href='index.php?action=itemedit&amp;itemid=$current->inumber'>"._LISTS_EDIT."</a></td>";
6520                         echo "<td><a href='index.php?action=itemdelete&amp;itemid=$current->inumber'>"._LISTS_DELETE."</a></td>";
6521
6522                         break;
6523         }
6524 }
6525
6526
6527 function listplug_table_actionlist($template, $type) {
6528         switch($type) {
6529                 case 'HEAD':
6530                         echo '<th>'._LISTS_TIME.'</th><th>'._LIST_ACTION_MSG.'</th>';
6531                         break;
6532                 case 'BODY':
6533                         $current = $template['current'];
6534
6535                         echo '<td>' , htmlspecialchars($current->timestamp), '</td>';
6536                         echo '<td>' , htmlspecialchars($current->message), '</td>';
6537
6538                         break;
6539         }
6540 }
6541
6542 function listplug_table_banlist($template, $type) {
6543         switch($type) {
6544                 case 'HEAD':
6545                         echo '<th>'._LIST_BAN_IPRANGE.'</th><th>'. _LIST_BAN_REASON.'</th><th>'._LISTS_ACTIONS.'</th>';
6546                         break;
6547                 case 'BODY':
6548                         $current = $template['current'];
6549
6550                         echo '<td>' , htmlspecialchars($current->iprange) , '</td>';
6551                         echo '<td>' , htmlspecialchars($current->reason) , '</td>';
6552                         echo "<td><a href='index.php?action=banlistdelete&amp;blogid=", intval($current->blogid) , "&amp;iprange=" , htmlspecialchars($current->iprange) , "'>",_LISTS_DELETE,"</a></td>";
6553                         break;
6554         }
6555 }
6556
6557 /**
6558  * Returns the Javascript code for a bookmarklet that works on most modern browsers
6559  *
6560  * @param blogid
6561  */
6562 function getBookmarklet($blogid) {
6563         global $CONF;
6564
6565         // normal
6566         $document = 'document';
6567         $bookmarkletline = "javascript:Q='';x=".$document.";y=window;if(x.selection){Q=x.selection.createRange().text;}else if(y.getSelection){Q=y.getSelection();}else if(x.getSelection){Q=x.getSelection();}wingm=window.open('";
6568         $bookmarkletline .= $CONF['AdminURL'] . "bookmarklet.php?blogid=$blogid";
6569         $bookmarkletline .="&logtext='+escape(Q)+'&loglink='+escape(x.location.href)+'&loglinktitle='+escape(x.title),'nucleusbm','scrollbars=yes,width=600,height=500,left=10,top=10,status=yes,resizable=yes');wingm.focus();";
6570
6571         return $bookmarkletline;
6572 }
6573
6574
6575 ?>