OSDN Git Service

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