[Top level directory]     [Classes]     [Functions]     [Constants]     [Variables]

XMB Open Source Forum Software - PHP Cross Reference

title

Body

[close]

/ -> cp2.php (source)

   1  <?php
   2  /**
   3   * eXtreme Message Board
   4   * XMB 1.9.11
   5   *
   6   * Developed And Maintained By The XMB Group
   7   * Copyright (c) 2001-2010, The XMB Group
   8   * http://www.xmbforum.com
   9   *
  10   * Sponsored By iEntry, Inc.
  11   * http://www.ientry.com
  12   *
  13   * This program is free software; you can redistribute it and/or
  14   * modify it under the terms of the GNU General Public License
  15   * as published by the Free Software Foundation; either version 2
  16   * of the License, or (at your option) any later version.
  17   *
  18   * This program is distributed in the hope that it will be useful,
  19   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21   * GNU General Public License for more details.
  22   *
  23   * You should have received a copy of the GNU General Public License
  24   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  25   *
  26   **/
  27  
  28  define('X_SCRIPT', 'cp2.php');
  29  
  30  require  'header.php';
  31  require  ROOT.'include/admin.inc.php';
  32  
  33  header('X-Robots-Tag: noindex');
  34  
  35  loadtemplates('error_nologinsession');
  36  eval('$css = "'.template('css').'";');
  37  
  38  $action = postedVar('action', '', FALSE, FALSE, FALSE, 'g');
  39  
  40  if (X_ADMIN) {
  41      if ($action == 'templates' && onSubmit('download')) {
  42          $code = '';
  43          $templates = $db->query("SELECT * FROM ".X_PREFIX."templates ORDER BY name ASC");
  44          while($template = $db->fetch_array($templates)) {
  45              $template['template'] = trim($template['template']);
  46              $template['name'] = trim($template['name']);
  47  
  48              if ($template['name'] != '') {
  49                  $template['template'] = stripslashes($template['template']);
  50                  $code.= $template['name'].'|#*XMB TEMPLATE*#|'."\r\n".$template['template']."\r\n\r\n".'|#*XMB TEMPLATE FILE*#|';
  51              }
  52          }
  53          header("Content-disposition: attachment; filename=templates.xmb");
  54          header("Content-Length: ".strlen($code));
  55          header("Content-type: unknown/unknown");
  56          header("Pragma: no-cache");
  57          header("Expires: 0");
  58          echo $code;
  59          exit();
  60      }
  61  
  62      $download = getInt('download');
  63      if ($action == "themes" && $download) {
  64          $contents = array();
  65          $query = $db->query("SELECT * FROM ".X_PREFIX."themes WHERE themeid='$download'");
  66          $themebits = $db->fetch_array($query);
  67          foreach($themebits as $key=>$val) {
  68              if (!is_integer($key) && $key != 'themeid' && $key != 'dummy') {
  69                  $contents[] = $key.'='.$val;
  70              }
  71          }
  72          $name = str_replace(' ', '+', $themebits['name']);
  73          header("Content-Type: application/x-ms-download");
  74          header("Content-Disposition: filename=\"$name-theme.xmb\"");
  75          echo implode("\r\n", $contents);
  76          exit();
  77      }
  78      if ($action == "lang" && $download) {
  79          require ('include/translation.inc.php');
  80          $devname = '';
  81          $contents = exportTranslation($download, $devname);
  82          if ($contents === FALSE) {
  83              error($lang['generic_missing']);
  84          }
  85          header("Content-Type: application/x-ms-download");
  86          header("Content-Disposition: filename=\"$devname.lang.php\"");
  87          echo $contents;
  88          exit();
  89      }
  90  }
  91  
  92  nav($lang['textcp']);
  93  
  94  eval('echo "'.template('header').'";');
  95  echo '<script language="JavaScript" type="text/javascript" src="./js/admin.js"></script>';
  96  
  97  if (!X_ADMIN) {
  98      eval('echo "'.template('error_nologinsession').'";');
  99      end_time();
 100      eval('echo "'.template('footer').'";');
 101      exit();
 102  }
 103  
 104  $auditaction = $_SERVER['REQUEST_URI'];
 105  $aapos = strpos($auditaction, "?");
 106  if ($aapos !== false) {
 107      $auditaction = substr($auditaction, $aapos + 1);
 108  }
 109  $auditaction = addslashes("$onlineip|#|$auditaction");
 110  audit($xmbuser, $auditaction, 0, 0);
 111  
 112  displayAdminPanel();
 113  
 114  if ($action == 'restrictions') {
 115      if (noSubmit('restrictedsubmit')) {
 116          ?>
 117          <tr bgcolor="<?php echo $altbg2?>">
 118          <td align="center">
 119          <form method="post" action="cp2.php?action=restrictions">
 120          <table align="center" border="0" cellspacing="0" cellpadding="0" width="80%">
 121          <tr>
 122          <td bgcolor="<?php echo $bordercolor?>">
 123          <table border="0" cellspacing="<?php echo $THEME['borderwidth']?>" cellpadding="<?php echo $tablespace?>" width="100%">
 124          <tr class="category">
 125          <td><span class="smalltxt"><strong><font color="<?php echo $cattext?>"><?php echo $lang['textdeleteques']?></font></strong></span></td>
 126          <td><span class="smalltxt"><strong><font color="<?php echo $cattext?>"><?php echo $lang['restrictedname']?></font></strong></span></td>
 127          <td><span class="smalltxt"><strong><font color="<?php echo $cattext?>">case-sensitive</font></strong></span></td>
 128          <td><span class="smalltxt"><strong><font color="<?php echo $cattext?>">partial-match</font></strong></span></td>
 129          </tr>
 130          <?php
 131          $query = $db->query("SELECT * FROM ".X_PREFIX."restricted ORDER BY id");
 132          while($restricted = $db->fetch_array($query)) {
 133              if ($restricted['case_sensitivity'] == 1) {
 134                  $case_check = 'checked="checked"';
 135              } else {
 136                  $case_check = '';
 137              }
 138  
 139              if ($restricted['partial'] == 1) {
 140                  $partial_check = 'checked="checked"';
 141              } else {
 142                  $partial_check = '';
 143              }
 144              ?>
 145              <tr class="tablerow">
 146              <td bgcolor="<?php echo $altbg2?>"><input type="checkbox" name="delete<?php echo $restricted['id']?>" value="<?php echo $restricted['id']?>" /></td>
 147              <td bgcolor="<?php echo $altbg2?>"><input type="text" size="30" name="name<?php echo $restricted['id']?>" value="<?php echo $restricted['name']?>" /></td>
 148              <td bgcolor="<?php echo $altbg2?>"><input type="checkbox" name="case<?php echo $restricted['id']?>" value="<?php echo $restricted['id']?>" <?php echo $case_check?> /></td>
 149              <td bgcolor="<?php echo $altbg2?>"><input type="checkbox" name="partial<?php echo $restricted['id']?>" value="<?php echo $restricted['id']?>" <?php echo $partial_check?> /></td>
 150              </tr>
 151              <?php
 152          }
 153          ?>
 154          <tr>
 155          <td bgcolor="<?php echo $altbg2?>" colspan="4"><img src="./images/pixel.gif" alt="" /></td>
 156          </tr>
 157          <tr class="tablerow">
 158          <td bgcolor="<?php echo $altbg2?>" colspan="4" align="left">
 159          <table border="0" width="100%">
 160          <tr class="category">
 161          <td colspan="2"><span class="smalltxt"><strong><font color="<?php echo $cattext?>"><?php echo $lang['textnewcode']?></font></strong></span></td>
 162          </tr>
 163          <tr class="tablerow">
 164          <td colspan="2"><span class="smalltxt"><?php echo $lang['newrestriction']?></span></td>
 165          </tr>
 166          <tr>
 167          <td colspan="2"><span class="smalltxt"><?php echo $lang['newrestrictionwhy']?></span></td>
 168          </tr>
 169          <tr>
 170          <td colspan="2">&nbsp;</td>
 171          </tr>
 172          <tr>
 173          <td><span class="smalltxt">name:</span></td>
 174          <td><input type="text" size="30" name="newname" /></td>
 175          </tr>
 176          <tr>
 177          <td><span class="smalltxt">case-sensitive:</span></td>
 178          <td><input type="checkbox" name="newcase" value="1" /></td>
 179          </tr>
 180          <tr>
 181          <td><span class="smalltxt">partial-match:</span></td>
 182          <td><input type="checkbox" name="newpartial" value="1" checked="checked" /></td>
 183          </tr>
 184          </table>
 185          </td>
 186          </tr>
 187          </table>
 188          </td>
 189          </tr>
 190          </table><br />
 191          <div align="center"><input class="submit" type="submit" name="restrictedsubmit" value="<?php echo $lang['textsubmitchanges']?>" /></div>
 192          </form>
 193          </td>
 194          </tr>
 195          <?php
 196      } else {
 197          $queryrestricted = $db->query("SELECT id FROM ".X_PREFIX."restricted");
 198          while($restricted = $db->fetch_array($queryrestricted)) {
 199              $name = postedVar('name'.$restricted['id'], '', FALSE, TRUE);
 200              $delete = getInt('delete'.$restricted['id'], 'p');
 201              $case = getInt('case'.$restricted['id'], 'p');
 202              $partial = getInt('partial'.$restricted['id'], 'p');
 203              if ($partial) {
 204                  $partial = 1;
 205              }
 206              if ($case) {
 207                  $case = 1;
 208              }
 209              if ($delete) {
 210                  $db->query("DELETE FROM ".X_PREFIX."restricted WHERE id=$delete");
 211              } else {
 212                  $db->query("UPDATE ".X_PREFIX."restricted SET name='$name', case_sensitivity='$case', partial='$partial' WHERE id=".$restricted['id']);
 213              }
 214          }
 215  
 216          $newname = postedVar('newname', '', FALSE, TRUE);
 217          $newcase = getInt('newcase', 'p');
 218          $newpartial = getInt('newpartial', 'p');
 219          if (!empty($newname)) {
 220              if ($newpartial) {
 221                  $newpartial = 1;
 222              }
 223              if ($newcase) {
 224                  $newcase = 1;
 225              }
 226              $db->query("INSERT INTO ".X_PREFIX."restricted (`name`, `case_sensitivity`, `partial`) VALUES ('$newname', '$newcase', '$newpartial')");
 227          }
 228          echo '<tr bgcolor="'.$altbg2.'" class="ctrtablerow"><td>'.$lang['restrictedupdate'].'</td></tr>';
 229          redirect($full_url.'cp2.php?action=restrictions', 2);
 230      }
 231  }
 232  
 233  // Management for Translation Database
 234  if ($action == 'lang') {
 235      if (noSubmit('importsubmit') And noSubmit('edit') And noSubmit('editsubmit') And noSubmit('detail') And noSubmit('deletesubmit')) {
 236          // Default screen: Language List, Options to Install, Uninstall, and Export.
 237          ?>
 238          <tr bgcolor="<?php echo $altbg2?>">
 239          <td align="center">
 240          <form method="POST" action="cp2.php?action=lang" name="theme_main">
 241          <table cellspacing="0" cellpadding="0" border="0" width="500" align="center">
 242          <tr>
 243          <td bgcolor="<?php echo $bordercolor?>">
 244          <table border="0" cellspacing="<?php echo $THEME['borderwidth']?>" cellpadding="<?php echo $tablespace?>" width="100%">
 245          <tr class="category">
 246          <td align="center"><strong><font color="<?php echo $cattext?>"><?php echo $lang['textdeleteques']?></font></strong></td>
 247          <td><strong><font color="<?php echo $cattext?>"><?php echo $lang['textlanguage']; ?></font></strong></td>
 248          <td><strong><font color="<?php echo $cattext?>"><?php echo $lang['translation_name']; ?></font></strong></td>
 249          <td><strong><font color="<?php echo $cattext?>"><?php echo $lang['numberusing']?></font></strong></td>
 250          </tr>
 251          <?php
 252  
 253          $query = $db->query("SELECT b.devname, b.langid, t.cdata, COUNT(m.uid) AS cnt "
 254                            . "FROM ".X_PREFIX."lang_base AS b "
 255                            . "LEFT JOIN ".X_PREFIX."lang_text AS t USING (langid) "
 256                            . "INNER JOIN ".X_PREFIX."lang_keys AS k USING (phraseid) "
 257                            . "LEFT JOIN ".X_PREFIX."members AS m ON m.langfile = b.devname "
 258                            . "WHERE k.langkey='language' "
 259                            . "GROUP BY b.langid, b.devname, t.cdata ORDER BY b.devname ASC");
 260  
 261          while($themeinfo = $db->fetch_array($query)) {
 262              $themeid = $themeinfo['langid'];
 263              $members = $themeinfo['cnt'];
 264              if ($themeinfo['devname'] == $langfile Or $themeinfo['devname'] == $SETTINGS['langfile']) {
 265                  $disabledelete = ' disabled="disabled"';
 266              } else {
 267                  $disabledelete = '';
 268              }
 269  
 270              ?>
 271              <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 272              <td align="center"><input type="checkbox" name="lang_delete[]" value="<?php echo $themeinfo['langid']?>"<?php echo $disabledelete; ?> /></td>
 273              <td><input type="text" name="langname[<?php echo $themeinfo['langid']?>]" value="<?php echo $themeinfo['cdata']?>" readonly="readonly" /></td>
 274              <td>
 275              <input type="text" name="devname[<?php echo $themeinfo['langid']?>]" value="<?php echo $themeinfo['devname']?>" readonly="readonly" />
 276              <a href="cp2.php?action=lang&amp;detail=<?php echo $themeinfo['langid']?>">
 277              <?php echo $lang['textdetails']?></a>
 278              -
 279              <a href="cp2.php?action=lang&amp;download=<?php echo $themeinfo['langid']?>">
 280              <?php echo $lang['textdownload']?>
 281              </a>
 282              </td>
 283              <td><?php echo $members?></td>
 284              </tr>
 285              <?php
 286          }
 287          ?>
 288          <tr bgcolor="<?php echo $altbg2?>">
 289          <td colspan="4"><img src="./images/pixel.gif" alt="" /></td>
 290          </tr>
 291          <tr>
 292          <td colspan="4" bgcolor="<?php echo $altbg2?>" class="ctrtablerow"><input type="submit" name="deletesubmit" value="<?php echo $lang['textsubmitchanges']?>" class="submit" /></td>
 293          </tr>
 294          </table>
 295          </td>
 296          </tr>
 297          </table>
 298          </form>
 299          <br />
 300  
 301  
 302          <form method="post" action="cp2.php?action=lang">
 303          <table cellspacing="0" cellpadding="0" border="0" width="500" align="center">
 304          <tr>
 305          <td bgcolor="<?php echo $bordercolor?>">
 306          <table border="0" cellspacing="<?php echo $THEME['borderwidth']?>" cellpadding="<?php echo $tablespace?>" width="100%">
 307          <tr class="category">
 308          <td align="center"><strong><font color="<?php echo $cattext?>"><?php echo "{$lang['textedit']} - $langfile"?></font></strong></td>
 309          </tr>
 310          <tr>
 311          <td bgcolor="<?php echo $altbg2?>" class="tablerow">
 312          <?php
 313          $query = $db->query("SELECT * FROM ".X_PREFIX."lang_keys ORDER BY langkey");
 314          echo '<select name="phraseid"><option value="default">'.$lang['translation_select'].'</option>';
 315          while($template = $db->fetch_array($query)) {
 316              echo '<option value="'.$template['phraseid'].'">'.$template['langkey']."</option>\r\n";
 317          }
 318          echo '</select>&nbsp;&nbsp;';
 319          $db->free_result($query);
 320          ?>
 321          </td>
 322          </tr>
 323          <tr>
 324          <td bgcolor="<?php echo $altbg2?>" class="tablerow">
 325          <input type="submit" class="submit" name="edit" value="<?php echo $lang['textedit']?>" />&nbsp;
 326          </td>
 327          </tr>
 328          </table>
 329          </td>
 330          </tr>
 331          </table>
 332          </form>
 333  
 334  
 335          <br />
 336          <form method="post" action="cp2.php?action=lang" enctype="multipart/form-data">
 337          <table cellspacing="0" cellpadding="0" border="0" width="500" align="center">
 338          <tr>
 339          <td bgcolor="<?php echo $bordercolor?>">
 340          <table border="0" cellspacing="<?php echo $THEME['borderwidth']?>" cellpadding="<?php echo $tablespace?>" width="100%">
 341          <tr class="category">
 342          <td colspan="2" align="center"><strong><font color="<?php echo $cattext?>"><?php echo $lang['translation_import']; ?></font></strong></td>
 343          </tr>
 344          <tr class="tablerow">
 345          <td bgcolor="<?php echo $altbg1?>"><?php echo $lang['generic_file']; ?></td>
 346          <td bgcolor="<?php echo $altbg2?>"><input name="themefile" type="file" /></td>
 347          </tr>
 348          <tr>
 349          <td bgcolor="<?php echo $altbg2?>" class="tablerow" align="center" colspan="2"><input type="submit" class="submit" name="importsubmit" value="<?php echo $lang['translation_import']; ?>" /></td>
 350          </tr>
 351          </table>
 352          </td>
 353          </tr>
 354          </table>
 355          </form>
 356          </td>
 357          </tr>
 358          <?php
 359      }
 360  
 361      if (onSubmit('importsubmit') && isset($_FILES['themefile']['tmp_name'])) { // Handle upload of new translation file.
 362  
 363          // Retrieve uploaded file
 364          require ('include/attach.inc.php');
 365          $filename = '';
 366          $filetype = '';
 367          $filesize = 0;
 368          $upload = get_attached_file('themefile', $filename, $filetype, $filesize, FALSE);
 369          if ($upload === FALSE) {
 370              error($lang['langimportfail'], FALSE);
 371          }
 372  
 373          // Install uploaded file
 374          require ('include/translation.inc.php');
 375          $result = installNewTranslation($upload);
 376  
 377          echo '<tr bgcolor="'.$altbg2.'" class="ctrtablerow"><td>';
 378          if ($result) {
 379              echo $lang['langimportsuccess'];
 380          } else {
 381              echo $lang['langimportfail'];
 382          }
 383          echo '</td></tr>';
 384      }
 385  
 386      if (onSubmit('edit') && noSubmit('editsubmit')) {
 387          $phraseid = getInt('phraseid', 'r');
 388          $result = $db->query("SELECT * FROM ".X_PREFIX."lang_keys WHERE phraseid=$phraseid");
 389          if ($db->num_rows($result) == 0) {
 390              error($lang['generic_missing'], FALSE);
 391          }
 392          $row = $db->fetch_array($result);
 393          $langkey = $row['langkey'];
 394  
 395          $result = $db->query("SELECT t.cdata "
 396                             . "FROM ".X_PREFIX."lang_text AS t "
 397                             . "LEFT JOIN ".X_PREFIX."lang_base AS b USING (langid) "
 398                             . "WHERE t.phraseid=$phraseid AND b.devname='$langfile'");
 399          if ($db->num_rows($result) == 1) {
 400              $row = $db->fetch_array($result);
 401              $value = cdataOut($row['cdata']); //Escape for use in the form field.
 402          } else {
 403              $value = '';
 404          }
 405  
 406          ?>
 407          <tr bgcolor="<?php echo $altbg2?>">
 408          <td align="center">
 409          <form method="post" action="cp2.php?action=lang">
 410          <table cellspacing="0" cellpadding="0" border="0" width="550" align="center">
 411          <tr>
 412          <td bgcolor="<?php echo $bordercolor?>">
 413          <table border="0" cellspacing="<?php echo $THEME['borderwidth']?>" cellpadding="<?php echo $tablespace?>" width="100%">
 414          <tr class="category">
 415          <td><strong><font color="<?php echo $cattext?>"><?php echo $lang['translations']; ?></font></strong></td>
 416          </tr>
 417          <tr class="ctrtablerow" bgcolor="<?php echo $altbg2?>">
 418          <td><?php echo $lang['translation_phrase'].':'; ?>&nbsp;<strong><?php echo "$langkey ($langfile)"; ?></strong></td>
 419          </tr>
 420          <tr class="ctrtablerow" bgcolor="<?php echo $altbg1?>">
 421          <td><textarea cols="100" rows="15" name="templatenew">
 422  <?php // Linefeed required here - Do not edit!
 423          echo $value;
 424          ?></textarea></td>
 425          </tr>
 426          <tr class="ctrtablerow" bgcolor="<?php echo $altbg2?>">
 427          <td>
 428           <input type="submit" name="editsubmit" class="submit" value="<?php echo $lang['textsubmitchanges']?>" />
 429           <input type="hidden" name="phraseid" value="<?php echo $phraseid; ?>">
 430          </td>
 431          </tr>
 432          </table>
 433          </td>
 434          </tr>
 435          </table>
 436          </form>
 437          </td>
 438          </tr>
 439          <?php
 440  
 441      }
 442  
 443      if (onSubmit('editsubmit')) {
 444          require ('include/translation.inc.php');
 445  
 446          $phraseid = getInt('phraseid', 'p');
 447          $newvalue = postedVar('templatenew', '', FALSE); // HTML is always allowed in translations.
 448  
 449          if (!setLangValue($phraseid, $newvalue)) {
 450              error($lang['generic_missing'], FALSE);
 451          }
 452  
 453          echo '<tr bgcolor="'.$altbg2.'" class="ctrtablerow"><td>'.$lang['translation_update'].'</td></tr>';
 454          redirect($full_url.'cp2.php?action=lang', 2, X_REDIRECT_JS);
 455      }
 456  
 457      if (onSubmit('detail')) {
 458          $langid = getInt('detail');
 459  
 460          $result = $db->query("SELECT devname FROM ".X_PREFIX."lang_base WHERE langid='$langid'");
 461          if ($db->num_rows($result) == 0) {
 462              error($lang['generic_missing'], FALSE);
 463          }
 464          $row = $db->fetch_array($result);
 465          $db->free_result($result);
 466          $devname = $row['devname'];
 467  
 468          $db->query("UPDATE ".X_PREFIX."members SET langfile='$devname' WHERE username='$xmbuser'");
 469  
 470          $query = "SELECT k.langkey, k.phraseid, COUNT(t.cdata) AS phrasecount "
 471                 . "FROM ".X_PREFIX."lang_keys AS k "
 472                 . "CROSS JOIN ".X_PREFIX."lang_base AS b "
 473                 . "LEFT JOIN ".X_PREFIX."lang_text AS t USING (phraseid, langid) "
 474                 . "WHERE b.langid=$langid "
 475                 . "GROUP BY k.phraseid, k.langkey ORDER BY k.langkey";
 476          $query = $db->query($query);
 477  
 478          ?>
 479          <tr bgcolor="<?php echo $altbg2?>">
 480          <td align="center">
 481          <table cellspacing="0" cellpadding="0" border="0" width="500" align="center">
 482          <tr>
 483          <td bgcolor="<?php echo $bordercolor?>">
 484          <table border="0" cellspacing="<?php echo $THEME['borderwidth']?>" cellpadding="<?php echo $tablespace?>" width="100%">
 485          <tr class="category">
 486          <td align="center"><strong><font color="<?php echo $cattext?>"><?php echo $lang['translation_phrase']; ?></font></strong></td>
 487          <td colspan="2" align="center"><strong><font color="<?php echo $cattext?>"><?php echo $devname; ?></font></strong></td>
 488          </tr>
 489          <?php
 490  
 491          while($row = $db->fetch_array($query)) {
 492              $langkey = $row['langkey'];
 493  
 494              ?>
 495              <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 496              <td><?php echo $langkey; ?></td>
 497              <?php if ($row['phrasecount'] == 0) { ?>
 498              <td></td>
 499              <td><a href="cp2.php?action=lang&amp;edit=edit&amp;phraseid=<?php echo $row['phraseid']; ?>"><?php echo $lang['textnewcode']; ?></a></td>
 500              </tr>
 501              <?php } else { ?>
 502              <td><a href="cp2.php?action=lang&amp;edit=edit&amp;phraseid=<?php echo $row['phraseid']; ?>"><?php echo $lang['textedit']; ?></a></td>
 503              <td></td>
 504              </tr>
 505              <?php }
 506          }
 507          ?>
 508          </table>
 509          </td>
 510          </tr>
 511          </table>
 512          </td>
 513          </tr>
 514          <?php
 515      }
 516  
 517      if (onSubmit('deletesubmit')) {
 518          $theme_delete = postedArray('lang_delete', 'int');
 519          $result = $db->query("SELECT langid FROM ".X_PREFIX."lang_base WHERE devname='$langfile' OR devname='{$SETTINGS['langfile']}'");
 520          $lockIDs = array();
 521          while($row = $db->fetch_array($result)) {
 522              $lockIDs[] = $row['langid'];
 523          }
 524  
 525          if ($theme_delete) {
 526              foreach($theme_delete as $deleteid) {
 527                  if (!in_array($deleteid, $lockIDs)) {
 528                      $db->query("DELETE FROM ".X_PREFIX."lang_text WHERE langid=$deleteid");
 529                      $db->query("DELETE FROM ".X_PREFIX."lang_base WHERE langid=$deleteid");
 530                  }
 531              }
 532              $db->query('OPTIMIZE TABLE '.X_PREFIX.'lang_text');
 533          }
 534          echo '<tr bgcolor="'.$altbg2.'" class="ctrtablerow"><td>'.$lang['translation_delete'].'</td></tr>';
 535      }
 536  }
 537  
 538  if ($action == 'themes') {
 539      $single = '';
 540      $single_str = postedVar('single', '', FALSE, FALSE, FALSE, 'g');
 541      $single_int = getInt('single');
 542      $newtheme = postedVar('newtheme');
 543  
 544      if (noSubmit('themesubmit') && $single_str == '' && noSubmit('importsubmit')) {
 545          ?>
 546          <tr bgcolor="<?php echo $altbg2?>">
 547          <td>
 548          <form method="POST" action="cp2.php?action=themes" name="theme_main">
 549          <table cellspacing="0" cellpadding="0" border="0" width="500" align="center">
 550          <tr>
 551          <td bgcolor="<?php echo $bordercolor?>">
 552          <table border="0" cellspacing="<?php echo $THEME['borderwidth']?>" cellpadding="<?php echo $tablespace?>" width="100%">
 553          <tr class="category">
 554          <td align="center"><strong><font color="<?php echo $cattext?>"><?php echo $lang['textdeleteques']?></font></strong></td>
 555          <td><strong><font color="<?php echo $cattext?>"><?php echo $lang['textthemename']?></font></strong></td>
 556          <td><strong><font color="<?php echo $cattext?>"><?php echo $lang['numberusing']?></font></strong></td>
 557          </tr>
 558          <?php
 559          $themeMem = array(0=>0);
 560          $tq = $db->query("SELECT theme, count(theme) as cnt FROM ".X_PREFIX."members GROUP BY theme");
 561          while($t = $db->fetch_array($tq)) {
 562              $themeMem[((int)$t['theme'])] = $t['cnt'];
 563          }
 564  
 565          $query = $db->query("SELECT name, themeid FROM ".X_PREFIX."themes ORDER BY name ASC");
 566          while($themeinfo = $db->fetch_array($query)) {
 567              $themeid = $themeinfo['themeid'];
 568              if (!isset($themeMem[$themeid])) {
 569                  $themeMem[$themeid] = 0;
 570              }
 571  
 572              if ($themeinfo['themeid'] == $SETTINGS['theme']) {
 573                  $members = ($themeMem[$themeid]+$themeMem[0]);
 574                  $disable = 'disabled="disabled"';
 575              } else {
 576                  $members = $themeMem[$themeid];
 577                  $disable = '';
 578              }
 579  
 580              ?>
 581              <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 582              <td align="center"><input type="checkbox" name="theme_delete[]" value="<?php echo $themeinfo['themeid']?>" <?php echo $disable; ?> /></td>
 583              <td>
 584              <input type="text" name="theme_name[<?php echo $themeinfo['themeid']?>]" value="<?php echo $themeinfo['name']?>" />
 585              <a href="cp2.php?action=themes&amp;single=<?php echo $themeinfo['themeid']?>">
 586              <?php echo $lang['textdetails']?></a>
 587              -
 588              <a href="cp2.php?action=themes&amp;download=<?php echo $themeinfo['themeid']?>">
 589              <?php echo $lang['textdownload']?>
 590              </a>
 591              </td>
 592              <td><?php echo $members?></td>
 593              </tr>
 594              <?php
 595          }
 596          ?>
 597          <tr bgcolor="<?php echo $altbg2?>">
 598          <td colspan="3"><img src="./images/pixel.gif" alt="" /></td>
 599          </tr>
 600          <tr bgcolor="<?php echo $altbg1?>" class="tablerow">
 601          <td colspan="3">
 602          <a href="cp2.php?action=themes&amp;single=anewtheme1">
 603              <strong><?php echo $lang['textnewtheme']?></strong>
 604          </a>
 605           -
 606          <a href="#" onclick="setCheckboxes('theme_main', 'theme_delete[]', true); return false;">
 607              <?php echo $lang['checkall']?>
 608          </a>
 609           -
 610          <a href="#" onclick="setCheckboxes('theme_main', 'theme_delete[]', false); return false;">
 611              <?php echo $lang['uncheckall']?>
 612          </a>
 613           -
 614          <a href="#" onclick="invertSelection('theme_main', 'theme_delete[]'); return false;">
 615              <?php echo $lang['invertselection']?>
 616          </a>
 617          </td>
 618          </tr>
 619          <tr>
 620          <td bgcolor="<?php echo $altbg2?>" class="ctrtablerow" colspan="3"><input type="submit" name="themesubmit" value="<?php echo $lang['textsubmitchanges']?>" class="submit" /></td>
 621          </tr>
 622          </table>
 623          </td>
 624          </tr>
 625          </table>
 626          </form>
 627          <br />
 628          <form method="post" action="cp2.php?action=themes" enctype="multipart/form-data">
 629          <table cellspacing="0" cellpadding="0" border="0" width="500" align="center">
 630          <tr>
 631          <td bgcolor="<?php echo $bordercolor?>">
 632          <table border="0" cellspacing="<?php echo $THEME['borderwidth']?>" cellpadding="<?php echo $tablespace?>" width="100%">
 633          <tr class="header">
 634          <td colspan="2"><?php echo $lang['textimporttheme']?></td>
 635          </tr>
 636          <tr class="tablerow">
 637          <td bgcolor="<?php echo $altbg1?>"><?php echo $lang['textthemefile']?></td>
 638          <td bgcolor="<?php echo $altbg2?>"><input name="themefile" type="file" /></td>
 639          </tr>
 640          <tr>
 641          <td bgcolor="<?php echo $altbg2?>" class="tablerow" align="center" colspan="2"><input type="submit" class="submit" name="importsubmit" value="<?php echo $lang['textimporttheme']; ?>" /></td>
 642          </tr>
 643          </table>
 644          </td>
 645          </tr>
 646          </table>
 647          </form>
 648          </td>
 649          </tr>
 650          <?php
 651      }
 652  
 653      if (onSubmit('importsubmit') && isset($_FILES['themefile']['tmp_name'])) {
 654          if (!is_uploaded_file($_FILES['themefile']['tmp_name'])) {
 655              error($lang['textthemeimportfail'], FALSE);
 656          }
 657          $themebits = readFileAsINI($_FILES['themefile']['tmp_name']);
 658          $start = "INSERT INTO ".X_PREFIX."themes";
 659  
 660          $keysql = array();
 661          $valsql = array();
 662          foreach($themebits as $key=>$val) {
 663              if ($key == 'themeid') {
 664                  $val = '';
 665              } else if ($key == 'name') {
 666                  $dbname = $db->escape_var($val);
 667              }
 668              $keysql[] = $db->escape_var($key);
 669              $valsql[] = "'".$db->escape_var($val)."'";
 670          }
 671  
 672          $keysql = implode(', ', $keysql);
 673          $valsql = implode(', ', $valsql);
 674  
 675          $query = $db->query("SELECT COUNT(themeid) FROM ".X_PREFIX."themes WHERE name='$dbname'");
 676          if ($db->result($query, 0) > 0) {
 677              error($lang['theme_already_exists'], false, '</td></tr></table></td></tr></table>');
 678          }
 679  
 680          $sql = "INSERT INTO ".X_PREFIX."themes ($keysql) VALUES ($valsql);";
 681          $query = $db->query($sql);
 682  
 683          echo '<tr bgcolor="'.$altbg2.'" class="ctrtablerow"><td>';
 684          if (!$query) {
 685              echo $lang['textthemeimportfail'];
 686          } else {
 687              echo $lang['textthemeimportsuccess'];
 688          }
 689          echo '</td></tr>';
 690      } else if (onSubmit('themesubmit')) {
 691          $theme_delete = postedArray('theme_delete', 'int');
 692          $theme_name = postedArray('theme_name', 'string', 'javascript', TRUE, TRUE, TRUE);
 693  
 694          $number_of_themes = $db->result($db->query("SELECT count(themeid) FROM ".X_PREFIX."themes"), 0);
 695  
 696          if ($theme_delete && count($theme_delete) >= $number_of_themes) {
 697              error($lang['delete_all_themes'], false, '</td></tr></table></td></tr></table>');
 698          }
 699  
 700          if ($theme_delete) {
 701              foreach($theme_delete as $themeid) {
 702                  if ($themeid != $SETTINGS['theme']) {
 703                      $db->query("UPDATE ".X_PREFIX."members SET theme=0 WHERE theme='$themeid'");
 704                      $db->query("UPDATE ".X_PREFIX."forums SET theme=0 WHERE theme='$themeid'");
 705                      $db->query("DELETE FROM ".X_PREFIX."themes WHERE themeid='$themeid'");
 706                  }
 707              }
 708          }
 709  
 710          foreach($theme_name as $themeid=>$name) {
 711              $db->query("UPDATE ".X_PREFIX."themes SET name='$name' WHERE themeid='$themeid'");
 712          }
 713          echo '<tr bgcolor="'.$altbg2.'" class="ctrtablerow"><td>'.$lang['themeupdate'].'</td></tr>';
 714      }
 715  
 716      if ($single_int > 0) {
 717          $query = $db->query("SELECT * FROM ".X_PREFIX."themes WHERE themeid='$single_int'");
 718          $themestuff = $db->fetch_array($query);
 719          $db->free_result($query);
 720          ?>
 721          <tr bgcolor="<?php echo $altbg2?>">
 722          <td>
 723          <form method="post" action="cp2.php?action=themes&amp;single=submit">
 724          <table cellspacing="0" cellpadding="0" border="0" width="93%" align="center">
 725          <tr>
 726          <td bgcolor="<?php echo $bordercolor?>">
 727          <table border="0" cellspacing="<?php echo $THEME['borderwidth']?>" cellpadding="<?php echo $tablespace?>" width="100%">
 728          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 729          <td><?php echo $lang['texthemename']?></td>
 730          <td colspan="2"><input type="text" name="namenew" value="<?php echo $themestuff['name']?>" /></td>
 731          </tr>
 732          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 733          <td><?php echo $lang['textbgcolor']?></td>
 734          <td><input type="text" name="bgcolornew" value="<?php echo $themestuff['bgcolor']?>" /></td>
 735          <td bgcolor="<?php echo $themestuff['bgcolor']?>">&nbsp;</td>
 736          </tr>
 737          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 738          <td><?php echo $lang['textaltbg1']?></td>
 739          <td><input type="text" name="altbg1new" value="<?php echo $themestuff['altbg1']?>" /></td>
 740          <td bgcolor="<?php echo $themestuff['altbg1']?>">&nbsp;</td>
 741          </tr>
 742          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 743          <td><?php echo $lang['textaltbg2']?></td>
 744          <td><input type="text" name="altbg2new" value="<?php echo $themestuff['altbg2']?>" /></td>
 745          <td bgcolor="<?php echo $themestuff['altbg2']?>">&nbsp;</td>
 746          </tr>
 747          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 748          <td><?php echo $lang['textlink']?></td>
 749          <td><input type="text" name="linknew" value="<?php echo $themestuff['link']?>" /></td>
 750          <td bgcolor="<?php echo $themestuff['link']?>">&nbsp;</td>
 751          </tr>
 752          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 753          <td><?php echo $lang['textborder']?></td>
 754          <td><input type="text" name="bordercolornew" value="<?php echo $themestuff['bordercolor']?>" /></td>
 755          <td bgcolor="<?php echo $themestuff['bordercolor']?>">&nbsp;</td>
 756          </tr>
 757          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 758          <td><?php echo $lang['textheader']?></td>
 759          <td><input type="text" name="headernew" value="<?php echo $themestuff['header']?>" /></td>
 760          <td bgcolor="<?php echo $themestuff['header']?>">&nbsp;</td>
 761          </tr>
 762          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 763          <td><?php echo $lang['textheadertext']?></td>
 764          <td><input type="text" name="headertextnew" value="<?php echo $themestuff['headertext']?>" /></td>
 765          <td bgcolor="<?php echo $themestuff['headertext']?>">&nbsp;</td>
 766          </tr>
 767          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 768          <td><?php echo $lang['texttop']?></td>
 769          <td><input type="text" name="topnew" value="<?php echo $themestuff['top']?>" /></td>
 770          <td bgcolor="<?php echo $themestuff['top']?>">&nbsp;</td>
 771          </tr>
 772          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 773          <td><?php echo $lang['textcatcolor']?></td>
 774          <td><input type="text" name="catcolornew" value="<?php echo $themestuff['catcolor']?>" /></td>
 775          <td bgcolor="<?php echo $themestuff['catcolor']?>">&nbsp;</td>
 776          </tr>
 777          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 778          <td><?php echo $lang['textcattextcolor']?></td>
 779          <td><input type="text" name="cattextnew" value="<?php echo $themestuff['cattext']?>" /></td>
 780          <td bgcolor="<?php echo $themestuff['cattext']?>">&nbsp;</td>
 781          </tr>
 782          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 783          <td><?php echo $lang['texttabletext']?></td>
 784          <td><input type="text" name="tabletextnew" value="<?php echo $themestuff['tabletext']?>" /></td>
 785          <td bgcolor="<?php echo $themestuff['tabletext']?>">&nbsp;</td>
 786          </tr>
 787          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 788          <td><?php echo $lang['texttext']?></td>
 789          <td><input type="text" name="textnew" value="<?php echo $themestuff['text']?>" /></td>
 790          <td bgcolor="<?php echo $themestuff['text']?>">&nbsp;</td>
 791          </tr>
 792          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 793          <td><?php echo $lang['textborderwidth']?></td>
 794          <td colspan="2"><input type="text" name="borderwidthnew" value="<?php echo $themestuff['borderwidth']?>" size="2" /></td>
 795          </tr>
 796          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 797          <td><?php echo $lang['textwidth']?></td>
 798          <td colspan="2"><input type="text" name="tablewidthnew" value="<?php echo $themestuff['tablewidth']?>" size="3" /></td>
 799          </tr>
 800          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 801          <td><?php echo $lang['textspace']?></td>
 802          <td colspan="2"><input type="text" name="tablespacenew" value="<?php echo $themestuff['tablespace']?>" size="2" /></td>
 803          </tr>
 804          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 805          <td><?php echo $lang['textfont']?></td>
 806          <td colspan="2"><input type="text" name="fnew" value="<?php echo htmlspecialchars($themestuff['font'])?>" /></td>
 807          </tr>
 808          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 809          <td><?php echo $lang['textbigsize']?></td>
 810          <td colspan="2"><input type="text" name="fsizenew" value="<?php echo $themestuff['fontsize']?>" size="4" /></td>
 811          </tr>
 812          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 813          <td><?php echo $lang['textboardlogo']?></td>
 814          <td colspan="2"><input type="text"  value="<?php echo $themestuff['boardimg']?>" name="boardlogonew" /></td>
 815          </tr>
 816          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 817          <td><?php echo $lang['imgdir']?></td>
 818          <td colspan="2"><input type="text"  value="<?php echo $themestuff['imgdir']?>" name="imgdirnew" /></td>
 819          </tr>
 820          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 821          <td><?php echo $lang['imgdiradm']?></td>
 822          <td colspan="2"><input type="text"  value="<?php echo $themestuff['admdir']?>" name="admdirnew" /></td>
 823          </tr>
 824          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 825          <td><?php echo $lang['smdir']?></td>
 826          <td colspan="2"><input type="text"  value="<?php echo $themestuff['smdir']?>" name="smdirnew" /></td>
 827          </tr>
 828          <tr>
 829          <td bgcolor="<?php echo $altbg2?>" class="ctrtablerow" colspan="3"><input type="submit" class="submit" value="<?php echo $lang['textsubmitchanges']?>" /><input type="hidden" name="orig" value="<?php echo $single_int?>" /></td>
 830          </tr>
 831          </table>
 832          </td>
 833          </tr>
 834          </table>
 835          </form>
 836          </td>
 837          </tr>
 838          <?php
 839      } else if ($single_str == "anewtheme1") {
 840          ?>
 841          <tr bgcolor="<?php echo $altbg2?>">
 842          <td align="center">
 843          <form method="post" action="cp2.php?action=themes&amp;single=submit">
 844          <table cellspacing="0" cellpadding="0" border="0" width="93%" align="center">
 845          <tr>
 846          <td bgcolor="<?php echo $bordercolor?>">
 847          <table border="0" cellspacing="<?php echo $THEME['borderwidth']?>" cellpadding="<?php echo $tablespace?>" width="100%">
 848          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 849          <td><?php echo $lang['texthemename']?></td>
 850          <td><input type="text" name="namenew" /></td>
 851          </tr>
 852          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 853          <td><?php echo $lang['textbgcolor']?></td>
 854          <td><input type="text" name="bgcolornew" /></td>
 855          </tr>
 856          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 857          <td><?php echo $lang['textaltbg1']?></td>
 858          <td><input type="text" name="altbg1new" /></td>
 859          </tr>
 860          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 861          <td><?php echo $lang['textaltbg2']?></td>
 862          <td><input type="text" name="altbg2new" /></td>
 863          </tr>
 864          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 865          <td><?php echo $lang['textlink']?></td>
 866          <td><input type="text" name="linknew" /></td>
 867          </tr>
 868          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 869          <td><?php echo $lang['textborder']?></td>
 870          <td><input type="text" name="bordercolornew" /></td>
 871          </tr>
 872          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 873          <td><?php echo $lang['textheader']?></td>
 874          <td><input type="text" name="headernew" /></td>
 875          </tr>
 876          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 877          <td><?php echo $lang['textheadertext']?></td>
 878          <td><input type="text" name="headertextnew" /></td>
 879          </tr>
 880          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 881          <td><?php echo $lang['texttop']?></td>
 882          <td><input type="text" name="topnew" /></td>
 883          </tr>
 884          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 885          <td><?php echo $lang['textcatcolor']?></td>
 886          <td><input type="text" name="catcolornew" /></td>
 887          </tr>
 888          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 889          <td><?php echo $lang['textcattextcolor']?></td>
 890          <td><input type="text" name="cattextnew" /></td>
 891          </tr>
 892          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 893          <td><?php echo $lang['texttabletext']?></td>
 894          <td><input type="text" name="tabletextnew" /></td>
 895          </tr>
 896          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 897          <td><?php echo $lang['texttext']?></td>
 898          <td><input type="text" name="textnew" /></td>
 899          </tr>
 900          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 901          <td><?php echo $lang['textborderwidth']?></td>
 902          <td><input type="text" name="borderwidthnew" size="2" /></td>
 903          </tr>
 904          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 905          <td><?php echo $lang['textwidth']?></td>
 906          <td><input type="text" name="tablewidthnew" size="3" /></td>
 907          </tr>
 908          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 909          <td><?php echo $lang['textspace']?></td>
 910          <td><input type="text" name="tablespacenew" size="2" /></td>
 911          </tr>
 912          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 913          <td><?php echo $lang['textfont']?></td>
 914          <td><input type="text" name="fnew" /></td>
 915          </tr>
 916          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 917          <td><?php echo $lang['textbigsize']?></td>
 918          <td><input type="text" name="fsizenew" size="4" /></td>
 919          </tr>
 920          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 921          <td><?php echo $lang['textboardlogo']?></td>
 922          <td><input type="text" name="boardlogonew" value="<?php echo $boardimg?>" /></td>
 923          </tr>
 924          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 925          <td><?php echo $lang['imgdir']?></td>
 926          <td><input type="text" name="imgdirnew" value="images" /></td>
 927          </tr>
 928          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 929          <td><?php echo $lang['imgdiradm']?></td>
 930          <td><input type="text" name="admdirnew" value="images/admin" /></td>
 931          </tr>
 932          <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
 933          <td><?php echo $lang['smdir']?></td>
 934          <td><input type="text" name="smdirnew" value="images/smilies" /></td>
 935          </tr>
 936          <tr class="ctrtablerow">
 937          <td bgcolor="<?php echo $altbg2?>" colspan="2"><input class="submit" type="submit" value="<?php echo $lang['textsubmitchanges']?>" /><input type="hidden" name="newtheme" value="true" /></td>
 938          </tr>
 939          </table>
 940          </td>
 941          </tr>
 942          </table>
 943          </form>
 944          </td>
 945          </tr>
 946          <?php
 947      } else if ($single_str == "submit" && !$newtheme) {
 948          $namenew = postedVar('namenew');
 949          $bgcolornew = postedVar('bgcolornew');
 950          $altbg1new = postedVar('altbg1new');
 951          $altbg2new = postedVar('altbg2new');
 952          $linknew = postedVar('linknew');
 953          $bordercolornew = postedVar('bordercolornew');
 954          $headernew = postedVar('headernew');
 955          $headertextnew = postedVar('headertextnew');
 956          $topnew = postedVar('topnew');
 957          $catcolornew = postedVar('catcolornew');
 958          $cattextnew = postedVar('cattextnew');
 959          $tabletextnew = postedVar('tabletextnew');
 960          $textnew = postedVar('textnew');
 961          $borderwidthnew = postedVar('borderwidthnew');
 962          $tablewidthnew = postedVar('tablewidthnew');
 963          $tablespacenew = postedVar('tablespacenew');
 964          $fnew = postedVar('fnew');
 965          $fsizenew = postedVar('fsizenew');
 966          $boardlogonew = postedVar('boardlogonew');
 967          $imgdirnew = postedVar('imgdirnew');
 968          $admdirnew = postedVar('admdirnew');
 969          $smdirnew = postedVar('smdirnew');
 970  
 971          $db->query("UPDATE ".X_PREFIX."themes SET name='$namenew', bgcolor='$bgcolornew', altbg1='$altbg1new', altbg2='$altbg2new', link='$linknew', bordercolor='$bordercolornew', header='$headernew', headertext='$headertextnew', top='$topnew', catcolor='$catcolornew', tabletext='$tabletextnew', text='$textnew', borderwidth='$borderwidthnew', tablewidth='$tablewidthnew', tablespace='$tablespacenew', fontsize='$fsizenew', font='$fnew', boardimg='$boardlogonew', imgdir='$imgdirnew', smdir='$smdirnew', cattext='$cattextnew', admdir='$admdirnew' WHERE themeid='$orig'");
 972          echo '<tr bgcolor="'.$altbg2.'" class="ctrtablerow"><td>'.$lang['themeupdate'].'</td></tr>';
 973      } else if ($single_str == "submit" && $newtheme) {
 974          $namenew = postedVar('namenew');
 975          $bgcolornew = postedVar('bgcolornew');
 976          $altbg1new = postedVar('altbg1new');
 977          $altbg2new = postedVar('altbg2new');
 978          $linknew = postedVar('linknew');
 979          $bordercolornew = postedVar('bordercolornew');
 980          $headernew = postedVar('headernew');
 981          $headertextnew = postedVar('headertextnew');
 982          $topnew = postedVar('topnew');
 983          $catcolornew = postedVar('catcolornew');
 984          $cattextnew = postedVar('cattextnew');
 985          $tabletextnew = postedVar('tabletextnew');
 986          $textnew = postedVar('textnew');
 987          $borderwidthnew = postedVar('borderwidthnew');
 988          $tablewidthnew = postedVar('tablewidthnew');
 989          $tablespacenew = postedVar('tablespacenew');
 990          $fnew = postedVar('fnew');
 991          $fsizenew = postedVar('fsizenew');
 992          $boardlogonew = postedVar('boardlogonew');
 993          $imgdirnew = postedVar('imgdirnew');
 994          $admdirnew = postedVar('admdirnew');
 995          $smdirnew = postedVar('smdirnew');
 996  
 997          $db->query("INSERT INTO ".X_PREFIX."themes (name, bgcolor, altbg1, altbg2, link, bordercolor, header, headertext, top, catcolor, tabletext, text, borderwidth, tablewidth, tablespace, font, fontsize, boardimg, imgdir, smdir, cattext, admdir) VALUES('$namenew', '$bgcolornew', '$altbg1new', '$altbg2new', '$linknew', '$bordercolornew', '$headernew', '$headertextnew', '$topnew', '$catcolornew', '$tabletextnew', '$textnew', '$borderwidthnew', '$tablewidthnew', '$tablespacenew', '$fnew', '$fsizenew', '$boardlogonew', '$imgdirnew', '$smdirnew', '$cattextnew', '$admdirnew')");
 998          echo '<tr bgcolor="'.$altbg2.'" class="ctrtablerow"><td>'.$lang['themeupdate'].'</td></tr>';
 999      }
1000  }
1001  
1002  if ($action == "smilies") {
1003      if (noSubmit('smiliesubmit')) {
1004          ?>
1005          <tr bgcolor="<?php echo $altbg2?>">
1006          <td align="center">
1007          <form method="post" action="cp2.php?action=smilies">
1008          <table cellspacing="0" cellpadding="0" border="0" width="500" align="center">
1009          <tr>
1010          <td bgcolor="<?php echo $bordercolor?>">
1011          <table border="0" cellspacing="<?php echo $THEME['borderwidth']?>" cellpadding="<?php echo $tablespace?>" width="100%">
1012          <tr>
1013          <td class="category" colspan="4" align="left"><font color="<?php echo $cattext?>"><strong><?php echo $lang['smilies']?></strong></font></td>
1014          </tr>
1015          <tr class="header">
1016          <td align="center"><?php echo $lang['textdeleteques']?></td>
1017          <td><?php echo $lang['textsmiliecode']?></td>
1018          <td><?php echo $lang['textsmiliefile']?></td>
1019          <td align="center"><?php echo $lang['smilies']?></td>
1020          </tr>
1021          <?php
1022          $query = $db->query("SELECT code, id, url FROM ".X_PREFIX."smilies WHERE type='smiley'");
1023          while($smilie = $db->fetch_array($query)) {
1024              ?>
1025              <tr>
1026              <td bgcolor="<?php echo $altbg2?>" align="center" class="tablerow"><input type="checkbox" name="smdelete[<?php echo $smilie['id']?>]" value="1" /></td>
1027              <td bgcolor="<?php echo $altbg2?>" class="tablerow"><input type="text" name="smcode[<?php echo $smilie['id']?>]" value="<?php echo $smilie['code']?>" /></td>
1028              <td bgcolor="<?php echo $altbg2?>" class="tablerow"><input type="text" name="smurl[<?php echo $smilie['id']?>]" value="<?php echo $smilie['url']?>" /></td>
1029              <td bgcolor="<?php echo $altbg2?>" align="center" class="tablerow"><img src="<?php echo $smdir?>/<?php echo $smilie['url']?>" alt="<?php echo $smilie['code']?>" /></td>
1030              </tr>
1031              <?php
1032          }
1033          $db->free_result($query);
1034          ?>
1035          <tr>
1036          <td bgcolor="<?php echo $altbg2?>" colspan="4"><img src="./images/pixel.gif" alt="" /></td>
1037          </tr>
1038          <tr bgcolor="<?php echo $altbg1?>" class="tablerow">
1039          <td><?php echo $lang['textnewsmilie']?></td>
1040          <td><input type="text" name="newcode" /></td>
1041          <td colspan="2"><input type="text" name="newurl1" /></td>
1042          </tr>
1043          <tr class="ctrtablerow">
1044          <td bgcolor="<?php echo $altbg1?>"><input type="checkbox" name="autoinsertsmilies" value="1" /></td>
1045          <td bgcolor="<?php echo $altbg1?>" colspan="3"><?php echo $lang['autoinsertsmilies']?> (<?php echo $smdir?>)?</td>
1046          </tr>
1047          <tr>
1048          <td bgcolor="<?php echo $altbg2?>" colspan="4" align="left"><img src="./images/pixel.gif" alt="" /></td>
1049          </tr>
1050          <tr>
1051          <td colspan="4" class="header"><?php echo $lang['picons']?></td>
1052          </tr>
1053          <tr class="header">
1054          <td align="center"><?php echo $lang['textdeleteques']?></td>
1055          <td colspan="2" align="left"><?php echo $lang['textsmiliefile']?></td>
1056          <td align="center"><?php echo $lang['picons']?></td>
1057          </tr>
1058          <?php
1059          $query = $db->query("SELECT * FROM ".X_PREFIX."smilies WHERE type='picon' ORDER BY id");
1060          while($smilie = $db->fetch_array($query)) {
1061              ?>
1062              <tr>
1063              <td bgcolor="<?php echo $altbg2?>" align="center" class="tablerow"><input type="checkbox" name="pidelete[<?php echo $smilie['id']?>]" value="1" /></td>
1064              <td colspan="2" align="left" bgcolor="<?php echo $altbg2?>" class="tablerow"><input type="text" name="piurl[<?php echo $smilie['id']?>]" value="<?php echo $smilie['url']?>" /></td>
1065              <td bgcolor="<?php echo $altbg2?>" align="center" class="tablerow"><img src="<?php echo $smdir?>/<?php echo $smilie['url']?>" alt="<?php echo $smilie['url']?>" /></td>
1066              </tr>
1067              <?php
1068          }
1069          $db->free_result($query);
1070          ?>
1071          <tr>
1072          <td bgcolor="<?php echo $altbg2?>" colspan="4"><img src="./images/pixel.gif" alt="" /></td>
1073          </tr>
1074          <tr bgcolor="<?php echo $altbg1?>" class="tablerow">
1075          <td colspan="4" align="left"><?php echo $lang['textnewpicon']?>&nbsp;&nbsp;<input type="text" name="newurl2" /></td>
1076          </tr>
1077          <tr class="tablerow">
1078          <td bgcolor="<?php echo $altbg1?>" align="center"><input type="checkbox" name="autoinsertposticons" value="1" /></td>
1079          <td bgcolor="<?php echo $altbg1?>" colspan="3"><?php echo $lang['autoinsertposticons']?> (<?php echo $smdir?>)?</td>
1080          </tr>
1081          <tr>
1082          <td class="ctrtablerow" bgcolor="<?php echo $altbg2?>" colspan="4"><input type="submit" class="submit" name="smiliesubmit" value="<?php echo $lang['textsubmitchanges']?>" /></td>
1083          </tr>
1084          </table>
1085          </td>
1086          </tr>
1087          </table>
1088          </form>
1089          </td>
1090          </tr>
1091          <?php
1092      } else {
1093          $smdelete = postedArray('smdelete', 'int');
1094          $smcode = postedArray('smcode', 'string', 'javascript', TRUE, TRUE, TRUE);
1095          $smurl = postedArray('smurl', 'string', 'javascript', TRUE, TRUE, TRUE);
1096  
1097          $newcode = postedVar('newcode');
1098          $newurl1 = postedVar('newurl1');
1099          $autoinsertsmilies = formInt('autoinsertsmilies');
1100  
1101          $pidelete = postedArray('pidelete', 'int');
1102          $piurl = postedArray('piurl', 'string', 'javascript', TRUE, TRUE, TRUE);
1103  
1104          $newurl2 = postedVar('newurl2');
1105          $autoinsertposticons = formInt('autoinsertposticons');
1106  
1107          if ($smcode) {
1108              foreach($smcode as $key=>$val) {
1109                  if (count(array_keys($smcode, $val)) > 1) {
1110                      error($lang['smilieexists'], false, '</td></tr></table></td></tr></table><br />');
1111                  }
1112              }
1113          }
1114  
1115          $querysmilie = $db->query("SELECT id FROM ".X_PREFIX."smilies WHERE type='smiley'");
1116          while($smilie = $db->fetch_array($querysmilie)) {
1117              $id = $smilie['id'];
1118              if (isset($smdelete[$id]) && $smdelete[$id] == 1) {
1119                  $query = $db->query("DELETE FROM ".X_PREFIX."smilies WHERE id='$id'");
1120                  continue;
1121              }
1122              $query = $db->query("UPDATE ".X_PREFIX."smilies SET code='$smcode[$id]', url='$smurl[$id]' WHERE id='$smilie[id]' AND type='smiley'");
1123          }
1124  
1125          if ($piurl) {
1126              foreach($piurl as $key=>$val) {
1127                  if (count(array_keys($piurl, $val)) > 1) {
1128                      error($lang['piconexists'], false, '</td></tr></table></td></tr></table><br />');
1129                  }
1130              }
1131          }
1132  
1133          $querysmilie = $db->query("SELECT id FROM ".X_PREFIX."smilies WHERE type='picon'");
1134          while($picon = $db->fetch_array($querysmilie)) {
1135              $id = $picon['id'];
1136              if (isset($pidelete[$id]) && $pidelete[$id] == 1) {
1137                  $query = $db->query("DELETE FROM ".X_PREFIX."smilies WHERE id='$picon[id]'");
1138                  continue;
1139              }
1140              $query = $db->query("UPDATE ".X_PREFIX."smilies SET url='$piurl[$id]' WHERE id='$picon[id]' AND type='picon'");
1141          }
1142  
1143          if ($newcode) {
1144              if ($db->result($db->query("SELECT count(id) FROM ".X_PREFIX."smilies WHERE code='$newcode'"), 0) > 0) {
1145                  error($lang['smilieexists'], false, '</td></tr></table></td></tr></table><br />');
1146              }
1147              $query = $db->query("INSERT INTO ".X_PREFIX."smilies (type, code, url) VALUES ('smiley', '$newcode', '$newurl1')");
1148          }
1149  
1150          if ($autoinsertsmilies) {
1151              $smilies_count = $newsmilies_count = 0;
1152              $smiley_url = array();
1153              $smiley_code = array();
1154              $query = $db->query("SELECT * FROM ".X_PREFIX."smilies WHERE type = 'smiley'");
1155              while($smiley = $db->fetch_array($query)) {
1156                  $smiley_url[] = $smiley['url'];
1157                  $smiley_code[] = $smiley['code'];
1158              }
1159              $db->free_result($query);
1160  
1161              $dir = opendir($smdir);
1162              while($smiley = readdir($dir)) {
1163                  if ($smiley != '.' && $smiley != '..' && (strpos($smiley, '.gif') || strpos($smiley, '.jpg') || strpos($smiley, '.jpeg') || strpos($smiley, '.bmp') || strpos($smiley, '.png'))) {
1164                      $newsmiley_url = $smiley;
1165                      $newsmiley_code = $smiley;
1166                      $newsmiley_code = str_replace(array('.gif','.jpg','.jpeg','.bmp','.png','_'), array('','','','','',' '), $newsmiley_code);
1167                      $newsmiley_code = ':' . $newsmiley_code . ':';
1168                      if (!in_array($newsmiley_url, $smiley_url) && !in_array($newsmiley_code, $smiley_code)) {
1169                          $query = $db->query("INSERT INTO ".X_PREFIX."smilies (type, code, url) VALUES ('smiley', '$newsmiley_code', '$newsmiley_url')");
1170                          $newsmilies_count++;
1171                      }
1172                      $smilies_count++;
1173                  }
1174              }
1175              closedir($dir);
1176              echo '<tr bgcolor="'.$altbg2.'" class="ctrtablerow"><td>'.$newsmilies_count.' / '.$smilies_count.' '.$lang['smiliesadded'].'</td></tr>';
1177          }
1178  
1179          if ($newurl2) {
1180              if ($db->result($db->query("SELECT count(id) FROM ".X_PREFIX."smilies WHERE url='$newurl2' AND type='picon'"), 0) > 0) {
1181                  error($lang['piconexists'], false, '</td></tr></table></td></tr></table><br />');
1182              }
1183              $query = $db->query("INSERT INTO ".X_PREFIX."smilies (type, code, url) VALUES ('picon', '', '$newurl2')");
1184          }
1185  
1186          if ($autoinsertposticons) {
1187              $posticons_count = $newposticons_count = 0;
1188              $posticon_url = array();
1189              $query = $db->query("SELECT * FROM ".X_PREFIX."smilies WHERE type='picon'");
1190              while($picon = $db->fetch_array($query)) {
1191                  $posticon_url[] = $picon['url'];
1192              }
1193              $db->free_result($query);
1194  
1195              $dir = opendir($smdir);
1196              while($picon = readdir($dir)) {
1197                  if ($picon != '.' && $picon != '..' && (strpos($picon, '.gif') || strpos($picon, '.jpg') || strpos($picon, '.jpeg') || strpos($picon, '.bmp') || strpos($picon, '.png'))) {
1198                      $newposticon_url = $picon;
1199                      $newposticon_url = str_replace(' ', '%20', $newposticon_url);
1200                      if (!in_array($newposticon_url, $posticon_url)) {
1201                          $query = $db->query("INSERT INTO ".X_PREFIX."smilies (type, code, url) VALUES ('picon', '', '$newposticon_url')");
1202                          $newposticons_count++;
1203                      }
1204                      $posticons_count++;
1205                  }
1206              }
1207              closedir($dir);
1208              echo '<tr bgcolor="'.$altbg2.'" class="ctrtablerow"><td>'.$newposticons_count.' / '.$posticons_count.' '.$lang['posticonsadded'].'</td></tr>';
1209          }
1210          echo '<tr bgcolor="'.$altbg2.'" class="ctrtablerow"><td>'.$lang['smilieupdate'].'</td></tr>';
1211      }
1212  }
1213  
1214  if ($action == 'censor') {
1215      if (noSubmit('censorsubmit')) {
1216          ?>
1217          <tr bgcolor="<?php echo $altbg2?>">
1218          <td align="center">
1219          <form method="post" action="cp2.php?action=censor">
1220          <table cellspacing="0" cellpadding="0" border="0" width="450" align="center">
1221          <tr>
1222          <td style="background-color: <?php echo $bordercolor?>">
1223          <table border="0" cellspacing="<?php echo $THEME['borderwidth']?>" cellpadding="<?php echo $tablespace?>" width="100%">
1224          <tr class="category">
1225          <td width="4%" align="center"><font style="color: <?php echo $cattext?>"><strong><?php echo $lang['textdeleteques']?></strong></font></td>
1226          <td align="left"><font style="color: <?php echo $cattext?>"><strong><?php echo $lang['textcensorfind']?></strong></font></td>
1227          <td align="left"><font style="color: <?php echo $cattext?>"><strong><?php echo $lang['textcensorreplace']?></strong></font></td>
1228          </tr>
1229          <?php
1230          $query = $db->query("SELECT * FROM ".X_PREFIX."words ORDER BY id");
1231          while($censor = $db->fetch_array($query)) {
1232              ?>
1233              <tr class="tablerow" bgcolor="<?php echo $altbg2?>">
1234              <td align="center"><input type="checkbox" name="delete<?php echo $censor['id']?>" value="<?php echo $censor['id']?>" /></td>
1235              <td align="left"><input type="text" size="20" name="find<?php echo $censor['id']?>" value="<?php echo $censor['find']?>" /></td>
1236              <td align="left"><input type="text" size="20" name="replace<?php echo $censor['id']?>" value="<?php echo $censor['replace1']?>" /></td>
1237              </tr>
1238              <?php
1239          }
1240          $db->free_result($query);
1241          ?>
1242          <tr bgcolor="<?php echo $altbg2?>">
1243          <td colspan="3"><img src="./images/pixel.gif" alt="" /></td>
1244          </tr>
1245          <tr bgcolor="<?php echo $altbg1?>" class="tablerow">
1246          <td align="center"><strong><?php echo $lang['textnewcode']?></strong></td>
1247          <td align="left"><input type="text" size="20" name="newfind" /></td>
1248          <td align="left"><input type="text" size="20" name="newreplace" /></td>
1249          </tr>
1250          <tr>
1251          <td colspan="3" class="ctrtablerow" bgcolor="<?php echo $altbg2?>"><input type="submit" class="submit" name="censorsubmit" value="<?php echo $lang['textsubmitchanges']?>" /></td>
1252          </tr>
1253          </table>
1254          </td>
1255          </tr>
1256          </table>
1257          </form>
1258          </td>
1259          </tr>
1260          <?php
1261      }
1262  
1263      if (onSubmit('censorsubmit')) {
1264          $newfind = postedVar('newfind', 'javascript');
1265          $newreplace = postedVar('newreplace', 'javascript');
1266          $querycensor = $db->query("SELECT id FROM ".X_PREFIX."words");
1267          while($censor = $db->fetch_array($querycensor)) {
1268              $find = postedVar('find'.$censor['id']);
1269              $replace = postedVar('replace'.$censor['id']);
1270              $delete = formInt('delete'.$censor['id']);
1271  
1272              if ($delete) {
1273                  $db->query("DELETE FROM ".X_PREFIX."words WHERE id=$delete");
1274              }
1275  
1276              if ($find) {
1277                  $db->query("UPDATE ".X_PREFIX."words SET find='$find', replace1='$replace' WHERE id='$censor[id]'");
1278              }
1279          }
1280          $db->free_result($querycensor);
1281  
1282          if ($newfind) {
1283              $db->query("INSERT INTO ".X_PREFIX."words (find, replace1) VALUES ('$newfind', '$newreplace')");
1284          }
1285          echo '<tr bgcolor="'.$altbg2.'" class="ctrtablerow"><td>'.$lang['censorupdate'].'</td></tr>';
1286      }
1287  }
1288  
1289  if ($action == "ranks") {
1290      if (noSubmit('rankssubmit')) {
1291          ?>
1292          <tr bgcolor="<?php echo $altbg2?>">
1293          <td align="center">
1294          <form method="post" action="cp2.php?action=ranks">
1295          <table cellspacing="0" cellpadding="0" border="0" width="650" align="center">
1296          <tr>
1297          <td bgcolor="<?php echo $bordercolor?>">
1298          <table border="0" cellspacing="<?php echo $THEME['borderwidth']?>" cellpadding="<?php echo $tablespace?>" width="100%">
1299          <tr>
1300          <td class="category" align="center"><strong><font color="<?php echo $cattext?>"><?php echo $lang['textdeleteques']?></font></strong></td>
1301          <td class="category" align="left"><strong><font color="<?php echo $cattext?>"><?php echo $lang['textcusstatus']?></font></strong></td>
1302          <td class="category"><strong><font color="<?php echo $cattext?>"><?php echo $lang['textposts']?></font></strong></td>
1303          <td class="category"><strong><font color="<?php echo $cattext?>"><?php echo $lang['textstars']?></font></strong></td>
1304          <td class="category"><strong><font color="<?php echo $cattext?>"><?php echo $lang['textallowavatars']?></font></strong></td>
1305          <td class="category"><strong><font color="<?php echo $cattext?>"><?php echo $lang['textavatar']?></font></strong></td>
1306          </tr>
1307          <?php
1308          $avatarno = $avataryes = '';
1309          $query = $db->query("SELECT * FROM ".X_PREFIX."ranks ORDER BY stars");
1310          while($rank = $db->fetch_array($query)) {
1311              if ($rank['title'] == 'Super Administrator' || $rank['title'] == 'Administrator' || $rank['title'] == 'Super Moderator' || $rank['title'] == 'Moderator') {
1312                  $staff_disable = 'disabled';
1313              } else {
1314                  $staff_disable = '';
1315              }
1316  
1317              if ($rank['allowavatars'] == 'yes') {
1318                  $avataryes = "selected=\"selected\"";
1319              } else {
1320                  $avatarno = "selected=\"selected\"";
1321              }
1322              ?>
1323              <tr bgcolor="<?php echo $altbg2?>" class="tablerow">
1324              <td class="tablerow" align="center"><input type="checkbox" name="delete[<?php echo $rank['id']?>]" value="<?php echo $rank['id']?>" <?php echo $staff_disable?> /></td>
1325              <td class="tablerow" align="left"><input type="text" name="title[<?php echo $rank['id']?>]" value="<?php echo attrOut($rank['title']); ?>" <?php echo $staff_disable?>/></td>
1326              <td class="tablerow"><input type="text" name="posts[<?php echo $rank['id']?>]" value="<?php echo $rank['posts']?>" <?php echo $staff_disable?> size="5" /></td>
1327              <td class="tablerow"><input type="text" name="stars[<?php echo $rank['id']?>]" value="<?php echo $rank['stars']?>" size="4" /></td>
1328              <td class="tablerow"><select name="allowavatars[<?php echo $rank['id']?>]">
1329              <option value="yes" <?php echo $avataryes?>><?php echo $lang['texton']?></option>
1330              <option value="no" <?php echo $avatarno?>><?php echo $lang['textoff']?></option>
1331              </select><input type="hidden" name="id[<?php echo $rank['id']?>]" value="<?php echo $rank['id']?>" /></td>
1332              <td class="tablerow"><input type="text" name="avaurl[<?php echo $rank['id']?>]" value="<?php echo $rank['avatarrank']?>" size="20" /></td>
1333              </tr>
1334              <?php
1335              $avataryes = $avatarno = '';
1336          }
1337          ?>
1338          <tr bgcolor="<?php echo $altbg2?>"><td colspan="6"> </td></tr>
1339          <tr bgcolor="<?php echo $altbg1?>" class="tablerow">
1340          <td colspan="2"><?php echo $lang['textnewrank']?>&nbsp;&nbsp;<input type="text" name="newtitle" /></td>
1341          <td class="tablerow"><input type="text" name="newposts" size="5" /></td>
1342          <td class="tablerow"><input type="text" name="newstars" size="4" /></td>
1343          <td class="tablerow"><select name="newallowavatars"><option value="yes"><?php echo $lang['texton']?></option>
1344          <option value="no"><?php echo $lang['textoff']?></option></select></td>
1345          <td class="tablerow"><input type="text" name="newavaurl" size="20" /></td>
1346          </tr>
1347          <tr>
1348          <td align="center" colspan="6" class="tablerow" bgcolor="<?php echo $altbg2?>"><input type="submit" name="rankssubmit" class="submit" value="<?php echo $lang['textsubmitchanges']?>" /></td>
1349          </tr>
1350          </table>
1351          </td>
1352          </tr>
1353          </table>
1354          </form>
1355          </td>
1356          </tr>
1357          <?php
1358      } else {
1359          $id = postedArray('id', 'int');
1360          $delete = postedArray('delete', 'int');
1361          $title = postedArray('title', 'string', '', FALSE);
1362          $posts = postedArray('posts', 'int');
1363          $stars = postedArray('stars', 'int');
1364          $allowavatars = postedArray('allowavatars', 'yesno');
1365          $avaurl = postedArray('avaurl', 'string', 'javascript', TRUE, TRUE, TRUE);
1366          $newtitle = postedVar('newtitle', '', FALSE);
1367          $newposts = formInt('newposts');
1368          $newstars = formInt('newstars');
1369          $newallowavatars = formYesNo('newallowavatars');
1370          $newavaurl = postedVar('newavaurl', 'javascript', TRUE, TRUE, TRUE);
1371  
1372          $query = $db->query("SELECT * FROM ".X_PREFIX."ranks");
1373          $staffranks = array();
1374          while($ranks = $db->fetch_array($query)) {
1375              if ($ranks['title'] == 'Super Administrator' || $ranks['title'] == 'Administrator' || $ranks['title'] == 'Super Moderator' || $ranks['title'] == 'Moderator') {
1376                  $title[$ranks['id']] = $ranks['title'];
1377                  $posts[$ranks['id']] = 0;
1378                  if ((int) $stars[$ranks['id']] == 0) {
1379                      $stars[$ranks['id']] = 1;
1380                  }
1381                  $staffranks[] = $ranks['title'];
1382              }
1383          }
1384  
1385          $i = 0;
1386  
1387          if ($delete) {
1388              $del = implode(', ', $delete);
1389              $db->query("DELETE FROM ".X_PREFIX."ranks WHERE id IN ($del)");
1390          }
1391  
1392          foreach($id as $key=>$val) {
1393              $posts[$key] = (in_array($title[$key], $staffranks)) ? (int) -1 : $posts[$key];
1394              $db->query("UPDATE ".X_PREFIX."ranks SET title='$title[$key]', posts='$posts[$key]', stars='$stars[$key]', allowavatars='$allowavatars[$key]', avatarrank='$avaurl[$key]' WHERE id='$key'");
1395          }
1396  
1397          if ($newtitle) {
1398              $db->query("INSERT INTO ".X_PREFIX."ranks (title, posts, stars, allowavatars, avatarrank) VALUES ('$newtitle', '$newposts', '$newstars', '$newallowavatars', '$newavaurl')");
1399          }
1400          echo '<tr bgcolor="'.$altbg2.'" class="ctrtablerow"><td>'.$lang['rankingsupdate'].'</td></tr>';
1401      }
1402  }
1403  
1404  if ($action == "newsletter") {
1405      if (noSubmit('newslettersubmit')) {
1406          ?>
1407          <tr bgcolor="<?php echo $altbg2?>">
1408          <td>
1409          <form method="post" action="cp2.php?action=newsletter">
1410          <table cellspacing="0" cellpadding="0" border="0" width="550" align="center">
1411          <tr>
1412          <td bgcolor="<?php echo $bordercolor?>">
1413          <table border="0" cellspacing="<?php echo $THEME['borderwidth']?>" cellpadding="<?php echo $tablespace?>" width="100%">
1414          <tr class="category">
1415          <td colspan="2"><strong><font color="<?php echo $cattext?>"><?php echo $lang['textnewsletter']?></font></strong></td>
1416          </tr>
1417          <tr>
1418          <td bgcolor="<?php echo $altbg1?>" class="tablerow"><?php echo $lang['textsubject']?></td>
1419          <td bgcolor="<?php echo $altbg2?>" class="tablerow"><input type="text" name="newssubject" size="80" bgcolor="<?php echo $altbg1?>" /></td>
1420          </tr>
1421          <tr>
1422          <td bgcolor="<?php echo $altbg1?>" class="tablerow" valign="top"><?php echo $lang['textmessage']?></td>
1423          <td bgcolor="<?php echo $altbg2?>" class="tablerow"><textarea cols="80" rows="10" name="newsmessage" bgcolor="<?php echo $altbg1?>" ></textarea></td>
1424          </tr>
1425          <tr>
1426          <td bgcolor="<?php echo $altbg1?>" class="tablerow" valign="top"><?php echo $lang['textsendvia']?></td>
1427          <td bgcolor="<?php echo $altbg2?>" class="tablerow"><input type="radio" value="email" name="sendvia" bgcolor="<?php echo $altbg1?>" /> <?php echo $lang['textemail']?><br /><input type="radio" value="u2u" checked="checked" name="sendvia" bgcolor="<?php echo $altbg1?>" /> <?php echo $lang['textu2u']?></td>
1428          </tr>
1429          <tr>
1430          <td bgcolor="<?php echo $altbg1?>" class="tablerow" valign="top"><?php echo $lang['textsendto']?></td>
1431          <td bgcolor="<?php echo $altbg2?>" class="tablerow"><input type="radio" value="all" checked="checked" name="to" /> <?php echo $lang['textsendall']?><br />
1432          <input type="radio" value="staff" name="to" /> <?php echo $lang['textsendstaff']?><br />
1433          <input type="radio" value="admin" name="to" /> <?php echo $lang['textsendadmin']?><br />
1434          <input type="radio" value="supermod" name="to" /> <?php echo $lang['textsendsupermod']?><br />
1435          <input type="radio" value="mod" name="to" /> <?php echo $lang['textsendmod']?></td>
1436          </tr>
1437          <tr>
1438          <td bgcolor="<?php echo $altbg1?>" class="tablerow" valign="top"><?php echo $lang['textfaqextra']?></td>
1439          <td bgcolor="<?php echo $altbg2?>" class="tablerow">
1440          <input type="checkbox" value="yes" checked="checked" name="newscopy" /> <?php echo $lang['newsreccopy']?><br />
1441          <select name="wait" bgcolor="<?php echo $altbg1?>">
1442          <option value="0">0</option>
1443          <option value="50">50</option>
1444          <option value="100">100</option>
1445          <option value="150">150</option>
1446          <option value="200">200</option>
1447          <option value="250">250</option>
1448          <option value="500">500</option>
1449          <option value="1000">1000</option>
1450          </select>
1451          <?php echo $lang['newswait']?><br />
1452          </td>
1453          </tr>
1454          <tr>
1455          <td align="center" colspan="2" class="tablerow" bgcolor="<?php echo $altbg2?>"><input type="submit" class="submit" name="newslettersubmit" value="<?php echo $lang['textsubmitchanges']?>" /></td>
1456          </tr>
1457          </table>
1458          </td>
1459          </tr>
1460          </table>
1461          </form>
1462          </td>
1463          </tr>
1464          <?php
1465      } else {
1466          @set_time_limit(0);
1467          $newssubject = postedVar('newssubject');
1468          $newsmessage = postedVar('newsmessage');
1469          $sendvia = postedVar('sendvia', '', FALSE, FALSE);
1470          $to = postedVar('to', '', FALSE, FALSE);
1471          $newscopy = formYesNo('newscopy');
1472          $wait = formInt('wait');
1473  
1474          if ($newscopy != 'yes') {
1475              $tome = "AND NOT username='$xmbuser'";
1476          } else {
1477              $tome = "OR username='$xmbuser'";
1478          }
1479  
1480          if ($to == "all") {
1481              $query = $db->query("SELECT username, email FROM ".X_PREFIX."members WHERE newsletter='yes' $tome ORDER BY uid");
1482          } else if ($to == "staff") {
1483              $query = $db->query("SELECT username, email FROM ".X_PREFIX."members WHERE (status='Super Administrator' OR status='Administrator' OR status='Super Moderator' OR status='Moderator') $tome ORDER BY uid");
1484          } else if ($to == "admin") {
1485              $query = $db->query("SELECT username, email FROM ".X_PREFIX."members WHERE (status='Administrator' OR status = 'Super Administrator') $tome ORDER BY uid");
1486          } else if ($to == "supermod") {
1487              $query = $db->query("SELECT username, email FROM ".X_PREFIX."members WHERE status='Super moderator' $tome ORDER by uid");
1488          } else if ($to == "mod") {
1489              $query = $db->query("SELECT username, email FROM ".X_PREFIX."members WHERE status='Moderator' $tome ORDER BY uid");
1490          }
1491  
1492          if ($sendvia == "u2u") {
1493              while($memnews = $db->fetch_array($query)) {
1494                  $db->query("INSERT INTO ".X_PREFIX."u2u (msgto, msgfrom, type, owner, folder, subject, message, dateline, readstatus, sentstatus) VALUES ('".$db->escape_var($memnews['username'])."', '$xmbuser', 'incoming', '".$db->escape_var($memnews['username'])."', 'Inbox', '$newssubject', '$newsmessage', '" . time() . "', 'no', 'yes')");
1495              }
1496              echo "<tr bgcolor=\"$altbg2\" class=\"tablerow\"><td align=\"center\">$lang[newslettersubmit]</td></tr>";
1497          } else {
1498              $rawnewssubject = postedVar('newssubject', '', FALSE, FALSE);
1499              $rawnewsmessage = postedVar('newsmessage', '', FALSE, FALSE);
1500              $rawuser = htmlspecialchars_decode($self['username'], ENT_QUOTES);
1501              $rawbbname = htmlspecialchars_decode($bbname, ENT_NOQUOTES);
1502              $headers = array();
1503              $headers[] = smtpHeaderFrom($rawbbname, $adminemail);
1504              $headers[] = 'X-Mailer: PHP';
1505              $headers[] = 'X-AntiAbuse: Board servername - '.$cookiedomain;
1506              $headers[] = 'X-AntiAbuse: Username - '.$rawuser;
1507              $headers[] = 'Content-Type: text/plain; charset='.$charset;
1508              $headers = implode("\r\n", $headers);
1509  
1510              $i = 0;
1511              $total = 0;
1512              @ignore_user_abort(1);
1513              @set_time_limit(0);
1514              @ob_implicit_flush(1);
1515  
1516              while($memnews = $db->fetch_array($query)) {
1517                  if ($i > 0 && $i == $wait) {
1518                      sleep(3);
1519                      $i = 0;
1520                  } else {
1521                      if ($total % 250 == 0) {
1522                          error_log("XMB Notice: $total newsletter e-mails transmitted by $rawuser");
1523                      }
1524                      $i++;
1525                  }
1526  
1527                  $rawemail = htmlspecialchars_decode($memnews['email'], ENT_QUOTES);
1528                  altMail($rawemail, '['.$rawbbname.'] '.$rawnewssubject, $rawnewsmessage, $headers);
1529                  $total++;
1530              }
1531              error_log("XMB Notice: $total newsletter e-mails transmitted by $rawuser");
1532              echo "<tr bgcolor=\"$altbg2\" class=\"tablerow\"><td align=\"center\">$lang[newslettersubmit] {$lang['textsent']} $total</td></tr>";
1533          }
1534      }
1535  }
1536  
1537  if ($action == "prune") {
1538      if (noSubmit('pruneSubmit')) {
1539          $forumselect = forumList('pruneFromList[]', true, false);
1540          ?>
1541          <tr bgcolor="<?php echo $altbg2?>">
1542          <td align="center">
1543          <form method="post" action="cp2.php?action=prune">
1544          <table cellspacing="0" cellpadding="0" border="0" width="550">
1545          <tr>
1546          <td bgcolor="<?php echo $bordercolor?>">
1547          <table border="0" cellspacing="<?php echo $THEME['borderwidth']?>" cellpadding="<?php echo $tablespace?>" width="100%" style="vertical-align: top;">
1548          <tr>
1549          <td class="category" colspan="2">
1550          <strong>
1551          <span style="color: <?php echo $cattext?>">
1552          <?php echo $lang['textprune']?>
1553          </span>
1554          </strong>
1555          </td>
1556          </tr>
1557          <tr>
1558          <td class="tablerow" style="background-color: <?php echo $altbg1?>;">
1559          <?php echo $lang['pruneby']?>
1560          </td>
1561          <td class="tablerow" style="background-color: <?php echo $altbg2?>;">
1562          <table>
1563          <tr>
1564          <td>
1565          <input type="checkbox" name="pruneByDate[check]" value="1" checked="checked" />
1566          </td>
1567          <td>
1568          <select name="pruneByDate[type]">
1569          <option value="more"><?php echo $lang['prunemorethan']?></option>
1570          <option value="is"><?php echo $lang['pruneexactly']?></option>
1571          <option value="less"><?php echo $lang['prunelessthan']?></option>
1572          </select>
1573          <input type="text" name="pruneByDate[date]" value="100" /> <?php echo $lang['daysold']?>
1574          </td>
1575          </tr>
1576          <tr>
1577          <td>
1578          <input type="checkbox" name="pruneByPosts[check]" value="1" />
1579          </td>
1580          <td>
1581          <select name="pruneBy[posts][type]">
1582          <option value="more"><?php echo $lang['prunemorethan']?></option>
1583          <option value="is"><?php echo $lang['pruneexactly']?></option>
1584          <option value="less"><?php echo $lang['prunelessthan']?></option>
1585          </select>
1586          <input type="text" name="pruneByPosts[posts]" value="10" /> <?php echo $lang['memposts']?>
1587          </td>
1588          </tr>
1589          </table>
1590          </td>
1591          </tr>
1592          <tr>
1593          <td class="tablerow" style="background-color: <?php echo $altbg1?>;">
1594          <?php echo $lang['prunefrom']?>
1595          </td>
1596          <td class="tablerow" style="background-color: <?php echo $altbg2?>;">
1597          <table>
1598          <tr>
1599          <td>
1600          <input type="radio" name="pruneFrom" value="all" />
1601          </td>
1602          <td>
1603          <?php echo $lang['textallforumsandsubs']?>
1604          </td>
1605          </tr>
1606          <tr>
1607          <td>
1608          <input type="radio" name="pruneFrom" value="list" />
1609          </td>
1610          <td>
1611          <?php echo $forumselect?>
1612          </td>
1613          </tr>
1614          <tr>
1615          <td>
1616          <input type="radio" name="pruneFrom" value="fid" checked="checked" />
1617          </td>
1618          <td>
1619          <?php echo $lang['prunefids']?> <input type="text" name="pruneFromFid" /> <span class="smalltxt">(<?php echo $lang['seperatebycomma']?>)</span>
1620          </td>
1621          </tr>
1622          </table>
1623          </td>
1624          </tr>
1625          <tr>
1626          <td class="tablerow" style="background-color: <?php echo $altbg1?>;">
1627          <?php echo $lang['pruneposttypes']?>
1628          </td>
1629          <td class="tablerow" style="background-color: <?php echo $altbg2?>;">
1630          <input type="checkbox" name="pruneType[normal]" value="1" checked="checked" /> <?php echo $lang['prunenormal']?><br />
1631          <input type="checkbox" name="pruneType[closed]" value="1" checked="checked" /> <?php echo $lang['pruneclosed']?><br />
1632          <input type="checkbox" name="pruneType[topped]" value="1" /> <?php echo $lang['prunetopped']?><br />
1633          </td>
1634          </tr>
1635          <tr>
1636          <td class="ctrtablerow" style="background-color: <?php echo $altbg2?>;" colspan="2"><input type="submit" name="pruneSubmit" value="<?php echo $lang['textprune']?>" /></td>
1637          </tr>
1638          </table>
1639          </td>
1640          </tr>
1641          </table>
1642          </form>
1643          </td>
1644          </tr>
1645          <?php
1646      } else {
1647          $pruneByDate = postedArray('pruneByDate');
1648          $pruneByPosts = postedArray('pruneByPosts');
1649          $pruneFrom = postedVar('pruneFrom', '', FALSE, FALSE);
1650          $pruneFromList = postedArray('pruneFromList', 'int');
1651          $pruneFromFid = postedVar('pruneFromFid', '', FALSE, FALSE);
1652          $pruneType = postedArray('pruneType', 'int');
1653  
1654          $queryWhere = array();
1655          // let's check what to prune first
1656          switch($pruneFrom) {
1657              case 'all':
1658                  break;
1659              case 'list':
1660                  $fs = array();
1661                  foreach($pruneFromList as $fid) {
1662                      if ($fid > 0) {
1663                          $fs[] = $fid;
1664                      }
1665                  }
1666                  $fs = array_unique($fs);
1667                  if (count($fs) < 1) {
1668                      error($lang['nopruneforums'], false, '</td></tr></table></td></tr></table><br />');
1669                  }
1670                  $queryWhere[] = 'fid IN ('.implode(',', $fs).')';
1671                  break;
1672              case 'fid':
1673                  $fs = array();
1674                  $fids = explode(',', $pruneFromFid);
1675                  foreach($fids as $fid) {
1676                      if ($fid > 0) {
1677                          $fs[] = $fid;
1678                      }
1679                  }
1680                  $fs = array_unique($fs);
1681                  if (count($fs) < 1) {
1682                      error($lang['nopruneforums'], false, '</td></tr></table></td></tr></table><br />');
1683                  }
1684                  $queryWhere[] = 'fid IN ('.implode(',', $fs).')';
1685                  break;
1686              default:
1687                  error($lang['nopruneforums'], false, '</td></tr></table></td></tr></table><br />');
1688          }
1689  
1690          $sign = '';
1691          if (isset($pruneByPosts['check']) && $pruneByPosts['check'] == "1") {
1692              switch($pruneByPosts['type']) {
1693                  case 'less':
1694                      $sign = '<';
1695                      break;
1696                  case 'is':
1697                      $sign = '=';
1698                      break;
1699                  case 'more':
1700                  default:
1701                      $sign = '>';
1702                      break;
1703              }
1704              $queryWhere[] = 'replies '.$sign.' '.(int) ($pruneByPosts['posts']-1);
1705          }
1706  
1707          if (isset($pruneByDate['check']) && $pruneByDate['check'] == 1) {
1708              switch($pruneByDate['type']) {
1709                  case 'less':
1710                      $queryWhere[] = 'lastpost >= '.(time()-(24*3600*$pruneByDate['date']));
1711                      break;
1712                  case 'is':
1713                      $queryWhere[] = 'lastpost >= '.(time()-(24*3600*($pruneByDate['date']-1))).' AND lastpost <= '.(time()-(24*3600*($pruneByDate['date'])));
1714                      break;
1715                  case 'more':
1716                  default:
1717                      $queryWhere[] = 'lastpost <= '.(time()-(24*3600*$pruneByDate['date']));
1718                      break;
1719              }
1720          } else if ($sign == '') {
1721              $queryWhere[] = '1=0'; //Neither 'prune by' option was set, prune should abort.
1722          }
1723  
1724          if (!isset($pruneType['closed']) || $pruneType['closed'] != 1) {
1725              $queryWhere[] = "closed != 'yes'";
1726          }
1727  
1728          if (!isset($pruneType['topped']) || $pruneType['topped'] != 1) {
1729              $queryWhere[] = 'topped != 1';
1730          }
1731  
1732          if (!isset($pruneType['normal']) || $pruneType['normal'] != 1) {
1733              $queryWhere[] = "(topped == 1 OR closed == 'yes')";
1734          }
1735  
1736          if (count($queryWhere) > 0) {
1737              require ('include/attach-admin.inc.php');
1738              $tids = array();
1739              $queryWhere = implode(' AND ', $queryWhere);
1740              $q = $db->query("SELECT tid FROM ".X_PREFIX."threads WHERE ".$queryWhere);
1741              if ($db->num_rows($q) > 0) {
1742                  while($t = $db->fetch_array($q)) {
1743                      $tids[] = $t['tid'];
1744                  }
1745                  $tids = implode(',', $tids);
1746                  deleteMultiThreadAttachments($tids); // Must delete attachments before posts!
1747                  $db->query("DELETE FROM ".X_PREFIX."posts WHERE tid IN ($tids)");
1748                  $db->query("DELETE FROM ".X_PREFIX."favorites WHERE tid IN ($tids)");
1749  
1750                  $db->query("DELETE FROM d, r, v "
1751                           . "USING ".X_PREFIX."vote_desc AS d "
1752                           . "LEFT JOIN ".X_PREFIX."vote_results AS r ON r.vote_id = d.vote_id "
1753                           . "LEFT JOIN ".X_PREFIX."vote_voters AS v  ON v.vote_id = d.vote_id "
1754                           . "WHERE d.topic_id IN ($tids)");
1755  
1756                  $db->query("DELETE FROM ".X_PREFIX."threads WHERE tid IN ($tids)");
1757              }
1758          } else {
1759              $db->query("TRUNCATE TABLE ".X_PREFIX."attachments");
1760              $db->query("TRUNCATE TABLE ".X_PREFIX."posts");
1761              $db->query("TRUNCATE TABLE ".X_PREFIX."favorites");
1762              $db->query("TRUNCATE TABLE ".X_PREFIX."vote_results");
1763              $db->query("TRUNCATE TABLE ".X_PREFIX."vote_voters");
1764              $db->query("TRUNCATE TABLE ".X_PREFIX."vote_desc");
1765              $db->query("TRUNCATE TABLE ".X_PREFIX."threads");
1766              $db->query("UPDATE ".X_PREFIX."members SET postnum=0");
1767              $db->query("UPDATE ".X_PREFIX."forums SET posts=0, threads=0, lastpost=''");
1768          }
1769          echo "<tr bgcolor=\"$altbg2\" class=\"tablerow\"><td align=\"center\">$lang[forumpruned]</td></tr>";
1770      }
1771  }
1772  
1773  if ($action == "templates") {
1774      if (noSubmit('edit') && noSubmit('editsubmit') && noSubmit('delete') && noSubmit('deletesubmit') && noSubmit('new') && noSubmit('restore') && noSubmit('restoresubmit')) {
1775          ?>
1776          <tr bgcolor="<?php echo $altbg2?>">
1777          <td align="center">
1778          <form method="post" action="cp2.php?action=templates">
1779          <table cellspacing="0" cellpadding="0" border="0" width="80%" align="center">
1780          <tr>
1781          <td bgcolor="<?php echo $bordercolor?>">
1782          <table border="0" cellspacing="<?php echo $THEME['borderwidth']?>" cellpadding="<?php echo $tablespace?>" width="100%">
1783          <tr class="category">
1784          <td><strong><font color="<?php echo $cattext?>"><?php echo $lang['templates']?></font></strong></td>
1785          </tr>
1786          <tr>
1787          <td bgcolor="<?php echo $altbg2?>" class="tablerow">
1788          <input type="text" name="newtemplatename" size="30" maxlength="50" />&nbsp;&nbsp;
1789          <input type="submit" class="submit" name="new" value="<?php echo $lang['newtemplate']?>" />
1790          </td>
1791          </tr>
1792          <tr>
1793          <td bgcolor="<?php echo $altbg2?>" class="tablerow">
1794          <?php
1795          $query = $db->query("SELECT id, name FROM ".X_PREFIX."templates ORDER BY name");
1796          echo '<select name="tid"><option value="default">'.$lang['selecttemplate'].'</option>';
1797          while($template = $db->fetch_array($query)) {
1798              if (!empty($template['name'])) {
1799                  echo '<option value="'.intval($template['id']).'">'.$template['name']."</option>\r\n";
1800              }
1801          }
1802          echo '</select>&nbsp;&nbsp;';
1803          $db->free_result($query);
1804          ?>
1805          </td>
1806          </tr>
1807          <tr>
1808          <td bgcolor="<?php echo $altbg2?>" class="tablerow">
1809          <input type="submit" class="submit" name="edit" value="<?php echo $lang['textedit']?>" />&nbsp;
1810          <input type="submit" class="submit" name="delete" value="<?php echo $lang['deletebutton']?>" />&nbsp;
1811          <input type="submit" class="submit" name="restore" value="<?php echo $lang['textrestoredeftemps']?>" />&nbsp;
1812          <input type="submit" class="submit" name="download" value="<?php echo $lang['textdownloadtemps']?>" />
1813          </td>
1814          </tr>
1815          </table>
1816          </td>
1817          </tr>
1818          </table>
1819          </form>
1820          </td>
1821          </tr>
1822          <?php
1823      }
1824  
1825      if (onSubmit('restore')) {
1826          ?>
1827          <tr bgcolor="<?php echo $altbg2?>">
1828          <td align="center">
1829          <form method="post" action="cp2.php?action=templates">
1830          <table cellspacing="0" cellpadding="0" border="0" width="550" align="center">
1831          <tr>
1832          <td bgcolor="<?php echo $bordercolor?>">
1833          <table border="0" cellspacing="<?php echo $THEME['borderwidth']?>" cellpadding="<?php echo $tablespace?>" width="100%">
1834          <tr class="category">
1835          <td><strong><font color="<?php echo $cattext?>"><?php echo $lang['templates']?></font></strong></td>
1836          </tr>
1837          <tr>
1838          <td bgcolor="<?php echo $altbg1?>" class="ctrtablerow"><?php echo $lang['templaterestoreconfirm']?></td>
1839          </tr>
1840          <tr>
1841          <td bgcolor="<?php echo $altbg2?>" class="ctrtablerow"><input type="submit" class="submit" name="restoresubmit" value="<?php echo $lang['textyes']?>" /></td>
1842          </tr>
1843          </table>
1844          </td>
1845          </tr>
1846          </table>
1847          </form>
1848          </td>
1849          </tr>
1850          <?php
1851      }
1852  
1853      if (onSubmit('restoresubmit')) {
1854          if (!file_exists('./templates.xmb')) {
1855              error($lang['no_templates'], false, '</td></tr></table></td></tr></table><br />');
1856          }
1857  
1858          $templates = explode("|#*XMB TEMPLATE FILE*#|", file_get_contents(ROOT.'templates.xmb'));
1859  
1860          $db->query("TRUNCATE ".X_PREFIX."templates");
1861  
1862          $values = array();
1863          foreach($templates as $val) {
1864              $template = explode("|#*XMB TEMPLATE*#|", $val);
1865              $template[1] = isset($template[1]) ? addslashes(ltrim($template[1])) : '';
1866              $values[] = "('".$db->escape_var($template[0])."', '".$db->escape_var($template[1])."')";
1867          }
1868          unset($templates);
1869          if (count($values) > 0) {
1870              $values = implode(', ', $values);
1871              $db->query("INSERT INTO ".X_PREFIX."templates (name, template) VALUES $values");
1872          }
1873  
1874          $db->query("DELETE FROM ".X_PREFIX."templates WHERE name=''");
1875          echo '<tr bgcolor="'.$altbg2.'" class="ctrtablerow"><td>'.$lang['templatesrestoredone'].'</td></tr>';
1876          redirect($full_url.'cp2.php?action=templates', 2, X_REDIRECT_JS);
1877      }
1878  
1879      if (onSubmit('edit') && noSubmit('editsubmit')) {
1880          $tid = postedVar('tid', '', FALSE, FALSE);
1881          if ($tid == 'default') {
1882              error($lang['selecttemplate'], false, '</td></tr></table></td></tr></table><br />');
1883          }
1884          $tid = formInt('tid');
1885          ?>
1886          <tr bgcolor="<?php echo $altbg2?>">
1887          <td align="center">
1888          <form method="post" action="cp2.php?action=templates&amp;tid=<?php echo $tid?>">
1889          <table cellspacing="0" cellpadding="0" border="0" width="550" align="center">
1890          <tr>
1891          <td bgcolor="<?php echo $bordercolor?>">
1892          <table border="0" cellspacing="<?php echo $THEME['borderwidth']?>" cellpadding="<?php echo $tablespace?>" width="100%">
1893          <tr class="category">
1894          <td><strong><font color="<?php echo $cattext?>"><?php echo $lang['templates']?></font></strong></td>
1895          </tr>
1896          <?php
1897          $query = $db->query("SELECT * FROM ".X_PREFIX."templates WHERE id=$tid ORDER BY name");
1898          $template = $db->fetch_array($query);
1899          $db->free_result($query);
1900          ?>
1901          <tr class="ctrtablerow" bgcolor="<?php echo $altbg2?>">
1902          <td><?php echo $lang['templatename']?>&nbsp;<strong><?php echo $template['name']; ?></strong></td>
1903          </tr>
1904          <tr class="ctrtablerow" bgcolor="<?php echo $altbg1?>">
1905          <td><textarea cols="100" rows="30" name="templatenew">
1906  <?php // Linefeed required here - Do not edit!
1907          echo cdataOut(stripslashes($template['template']));
1908          ?></textarea></td>
1909          </tr>
1910          <tr class="ctrtablerow" bgcolor="<?php echo $altbg2?>">
1911          <td><input type="submit" name="editsubmit" class="submit" value="<?php echo $lang['textsubmitchanges']?>" /></strong></td>
1912          </tr>
1913          </table>
1914          </td>
1915          </tr>
1916          </table>
1917          </form>
1918          </td>
1919          </tr>
1920          <?php
1921      }
1922  
1923      if (onSubmit('editsubmit')) {
1924          $tid = postedVar('tid', '', FALSE, FALSE, FALSE, 'g');
1925          $namenew = postedVar('namenew');
1926          //Templates are historically double-slashed.
1927          $templatenew = $db->escape(addslashes(postedVar('templatenew', '', FALSE, FALSE)));
1928  
1929          if ($tid == 'new') {
1930              if (!$namenew) {
1931                  error($lang['templateempty'], false, '</td></tr></table></td></tr></table><br />');
1932              } else {
1933                  $check = $db->query("SELECT name FROM ".X_PREFIX."templates WHERE name='$namenew'");
1934                  if ($db->num_rows($check) != 0) {
1935                      error($lang['templateexists'], false, '</td></tr></table></td></tr></table><br />');
1936                  } else {
1937                      $db->query("INSERT INTO ".X_PREFIX."templates (name, template) VALUES ('$namenew', '$templatenew')");
1938                  }
1939              }
1940          } else {
1941              $tid = getInt('tid');
1942              $db->query("UPDATE ".X_PREFIX."templates SET template='$templatenew' WHERE id=$tid");
1943          }
1944          echo '<tr bgcolor="'.$altbg2.'" class="ctrtablerow"><td>'.$lang['templatesupdate'].'</td></tr>';
1945          redirect($full_url.'cp2.php?action=templates', 2, X_REDIRECT_JS);
1946      }
1947  
1948      if (onSubmit('delete')) {
1949          if ($tid == 'default') {
1950              error($lang['selecttemplate'], false, '</td></tr></table></td></tr></table><br />');
1951          }
1952          $tid = getInt('tid', 'r');
1953          ?>
1954          <tr bgcolor="<?php echo $altbg2?>">
1955          <td align="center">
1956          <form method="post" action="cp2.php?action=templates&amp;tid=<?php echo $tid?>">
1957          <table cellspacing="0" cellpadding="0" border="0" width="550" align="center">
1958          <tr>
1959          <td bgcolor="<?php echo $bordercolor?>">
1960          <table border="0" cellspacing="<?php echo $THEME['borderwidth']?>" cellpadding="<?php echo $tablespace?>" width="100%">
1961          <tr>
1962          <td class="category"><strong><font color="<?php echo $cattext?>"><?php echo $lang['templates']?></font></strong></td>
1963          </tr>
1964          <tr bgcolor="<?php echo $altbg1?>" class="ctrtablerow">
1965          <td><?php echo $lang['templatedelconfirm']?></td>
1966          </tr>
1967          <tr bgcolor="<?php echo $altbg2?>" class="ctrtablerow">
1968          <td><input type="submit" class="submit" name="deletesubmit" value="<?php echo $lang['textyes']?>" /></td>
1969          </tr>
1970          </table>
1971          </td>
1972          </tr>
1973          </table>
1974          </form>
1975          </td>
1976          </tr>
1977          <?php
1978      }
1979  
1980      if (onSubmit('deletesubmit')) {
1981