OSDN Git Service

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