plugins/SpecialAdmin.php
changeset 345 4ccdfeee9a11
parent 343 eefe9ab7fe7c
child 347 299a90e28abc
equal deleted inserted replaced
344:be6c5fdd9203 345:4ccdfeee9a11
    39       ));
    39       ));
    40   ');
    40   ');
    41 
    41 
    42 // Admin pages that were too enormous to be in this file were split off into the plugins/admin/ directory in 1.0.1
    42 // Admin pages that were too enormous to be in this file were split off into the plugins/admin/ directory in 1.0.1
    43 require(ENANO_ROOT . '/plugins/admin/PageManager.php');
    43 require(ENANO_ROOT . '/plugins/admin/PageManager.php');
       
    44 require(ENANO_ROOT . '/plugins/admin/PageEditor.php');
    44 require(ENANO_ROOT . '/plugins/admin/PageGroups.php');
    45 require(ENANO_ROOT . '/plugins/admin/PageGroups.php');
    45 require(ENANO_ROOT . '/plugins/admin/SecurityLog.php');
    46 require(ENANO_ROOT . '/plugins/admin/SecurityLog.php');
    46 require(ENANO_ROOT . '/plugins/admin/UserManager.php');
    47 require(ENANO_ROOT . '/plugins/admin/UserManager.php');
    47 
    48 
    48 // function names are IMPORTANT!!! The name pattern is: page_<namespace ID>_<page URLname, without namespace>
    49 // function names are IMPORTANT!!! The name pattern is: page_<namespace ID>_<page URLname, without namespace>
   159           </div>';
   160           </div>';
   160   }
   161   }
   161   
   162   
   162   // Security log
   163   // Security log
   163   echo '<h3>' . $lang->get('acphome_heading_seclog') . '</h3>';
   164   echo '<h3>' . $lang->get('acphome_heading_seclog') . '</h3>';
       
   165   echo '<p>' . $lang->get('acphome_msg_seclog_info') . '</p>';
   164   $seclog = get_security_log(5);
   166   $seclog = get_security_log(5);
   165   echo $seclog;
   167   echo $seclog;
   166   
   168   
   167   echo '<p><a href="#" onclick="ajaxPage(\''.$paths->nslist['Admin'].'SecurityLog\'); return false;">' . $lang->get('acphome_btn_seclog_full') . '</a></p>';
   169   echo '<p><a href="#" onclick="ajaxPage(\''.$paths->nslist['Admin'].'SecurityLog\'); return false;">' . $lang->get('acphome_btn_seclog_full') . '</a></p>';
   168   
   170   
  1226     '<a style="color: white;" href="' . makeUrlNS('Special', 'Administration', 'module=' . $paths->cpage['module'] . '&show_system=yes', true) . '">' . $lang->get('acppl_btn_show_system') . '</a>' ;
  1228     '<a style="color: white;" href="' . makeUrlNS('Special', 'Administration', 'module=' . $paths->cpage['module'] . '&show_system=yes', true) . '">' . $lang->get('acppl_btn_show_system') . '</a>' ;
  1227     echo '<tr><th colspan="6" class="subhead">'.$showhide_link.'</th></tr>';
  1229     echo '<tr><th colspan="6" class="subhead">'.$showhide_link.'</th></tr>';
  1228     echo '</table></div>';
  1230     echo '</table></div>';
  1229 }
  1231 }
  1230 
  1232 
  1231 /*
  1233 function page_Admin_DBBackup()
  1232 function page_Admin_PageManager()
       
  1233 {
  1234 {
  1234   global $db, $session, $paths, $template, $plugins; // Common objects
  1235   global $db, $session, $paths, $template, $plugins; // Common objects
  1235   global $lang;
  1236   global $lang;
  1236   if ( $session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN )
  1237   if ( $session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN )
  1237   {
  1238   {
  1239     echo '<h3>' . $lang->get('adm_err_not_auth_title') . '</h3>';
  1240     echo '<h3>' . $lang->get('adm_err_not_auth_title') . '</h3>';
  1240     echo '<p>' . $lang->get('adm_err_not_auth_body', array( 'login_link' => $login_link )) . '</p>';
  1241     echo '<p>' . $lang->get('adm_err_not_auth_body', array( 'login_link' => $login_link )) . '</p>';
  1241     return;
  1242     return;
  1242   }
  1243   }
  1243   
  1244   
  1244   echo '<h2>Page management</h2>';
  1245   if ( ENANO_DBLAYER != 'MYSQL' )
  1245   
  1246     die('<h3>' . $lang->get('acpdb_err_not_supported_title') . '</h3>
  1246   if ( isset($_POST['search']) || isset($_POST['select']) || ( isset($_GET['source']) && $_GET['source'] == 'ajax' ) )
  1247           <p>' . $lang->get('acpdb_err_not_supported_desc') . '</p>');
  1247   {
  1248   
  1248     // The object of the game: using only the text a user entered, guess the page ID and namespace. *sigh* I HATE writing search algorithms...
  1249   if(isset($_GET['submitting']) && $_GET['submitting'] == 'yes' && defined('ENANO_DEMO_MODE') )
  1249     $source = ( isset($_GET['source']) ) ? $_GET['source'] : false;
  1250   {
  1250     if ( $source == 'ajax' )
  1251     redirect(makeUrlComplete('Special', 'Administration'), $lang->get('acpdb_err_demo_mode_title'), $lang->get('acpdb_err_demo_mode_desc'), 5);
  1251     {
  1252   }
  1252       $_POST['search'] = true;
  1253   
  1253       $_POST['page_url'] = $_GET['page_id'];
  1254   global $system_table_list;
  1254     }
  1255   if(isset($_GET['submitting']) && $_GET['submitting'] == 'yes')
  1255     if ( isset($_POST['search']) )
  1256   {
  1256     {
  1257     
  1257       $pid = $_POST['page_url'];
  1258     if(defined('SQL_BACKUP_CRYPT'))
  1258     }
  1259       // Try to increase our time limit
  1259     elseif ( isset($_POST['select']) )
  1260       @set_time_limit(0);
  1260     {
  1261     // Do the actual export
  1261       $pid = $_POST['page_force_url'];
  1262     $aesext = ( defined('SQL_BACKUP_CRYPT') ) ? '.tea' : '';
  1262     }
  1263     $filename = 'enano_backup_' . enano_date('ymd') . '.sql' . $aesext;
  1263     else
  1264     ob_start();
  1264     {
  1265     // Spew some headers
  1265       echo 'Internal error selecting page search terms';
  1266     $headdate = enano_date('F d, Y \a\t h:i a');
  1266       return false;
  1267     echo <<<HEADER
  1267     }
  1268 -- Enano CMS SQL backup
  1268     // Look for a namespace prefix in the urlname, and assign a different namespace, if necessary
  1269 -- Generated on {$headdate} by {$session->username}
  1269     $k = array_keys($paths->nslist);
  1270 
  1270     for ( $i = 0; $i < sizeof($paths->nslist); $i++ )
  1271 HEADER;
  1271     {
  1272     // build the table list
  1272       $ln = strlen($paths->nslist[$k[$i]]);
  1273     $base = ( isset($_POST['do_system_tables']) ) ? $system_table_list : Array();
  1273       if(substr($pid, 0, $ln) == $paths->nslist[$k[$i]])
  1274     $add  = ( isset($_POST['additional_tables'])) ? $_POST['additional_tables'] : Array();
  1274       {
  1275     $tables = array_merge($base, $add);
  1275         $ns = $k[$i];
  1276     
  1276         $page_id = substr($pid, $ln, strlen($pid));
  1277     // Log it!
  1277       }
  1278     $e = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,date_string,author,edit_summary,page_text) VALUES(\'security\', \'db_backup\', '.time().', \''.enano_date('d M Y h:i a').'\', \''.$db->escape($session->username).'\', \''.$db->escape($_SERVER['REMOTE_ADDR']).'\', \'' . $db->escape(implode(', ', $tables)) . '\')');
  1278     }
  1279     if ( !$e )
  1279     // The namespace is in $ns and the page name or ID (we don't know which yet) is in $page_id
  1280       $db->_die();
  1280     // Now, iterate through $paths->pages searching for a page with this name or ID
  1281     
  1281     for ( $i = 0; $i < sizeof($paths->pages) / 2; $i++ )
  1282     foreach($tables as $i => $t)
  1282     {
  1283     {
  1283       if ( !isset($final_pid) )
  1284       if(!preg_match('#^([a-z0-9_]+)$#i', $t))
  1284       {
  1285         die('Hacking attempt');
  1285         if ( $paths->pages[$i]['urlname_nons'] == str_replace(' ', '_', $page_id) )
  1286       // if($t == table_prefix.'files' && isset($_POST['do_data']))
  1286         {
  1287       //   unset($tables[$i]);
  1287           $final_pid = str_replace(' ', '_', $page_id);
  1288     }
  1288         }
  1289     foreach($tables as $t)
  1289         else if ( $paths->pages[$i]['name'] == $page_id )
  1290     {
  1290         {
  1291       // THE FOLLOWING COMMENT DOES NOT APPLY AS OF 1.0.
  1291           $final_pid = $paths->pages[$i]['urlname_nons'];
  1292       // Sorry folks - this script CAN'T backup enano_files and enano_search_index due to the sheer size of the tables.
  1292         }
  1293       // If encryption is enabled the log data will be excluded too.
  1293         else if ( strtolower($paths->pages[$i]['urlname_nons']) == strtolower(str_replace(' ', '_', $page_id)) )
  1294       $result = export_table(
  1294         {
  1295         $t,
  1295           $final_pid = $paths->pages[$i]['urlname_nons'];
  1296         isset($_POST['do_struct']),
  1296         }
  1297         ( isset($_POST['do_data']) ),
  1297         else if ( strtolower($paths->pages[$i]['name']) == strtolower(str_replace('_', ' ', $page_id)) )
  1298         false
  1298         {
  1299         ) . "\n";
  1299           $final_pid = $paths->pages[$i]['urlname_nons'];
  1300       if ( !$result )
  1300         }
  1301       {
  1301         if ( isset($final_pid) )
  1302         $db->_die();
  1302         {
  1303       }
  1303           $_POST['name'] = $paths->pages[$i]['name'];
  1304       echo $result;
  1304           $_POST['urlname'] = $paths->pages[$i]['urlname_nons'];
  1305     }
  1305         }
  1306     $data = ob_get_contents();
  1306       }
  1307     ob_end_clean();
  1307     }
  1308     if(defined('SQL_BACKUP_CRYPT'))
  1308     if ( !isset($final_pid) )
  1309     {
  1309     {
  1310       // Free some memory, we don't need this stuff any more
  1310       echo 'The page you searched for cannot be found. <a href="#" onclick="ajaxPage(\''.$paths->nslist['Admin'].'PageManager\'); return false;">Back</a>';
  1311       $db->close();
  1311       return false;
  1312       unset($paths, $db, $template, $plugins);
  1312     }
  1313       $tea = new TEACrypt();
  1313     $_POST['namespace'] = $ns;
  1314       $data = $tea->encrypt($data, $session->private_key);
  1314     $_POST['old_namespace'] = $ns;
  1315     }
  1315     $_POST['page_id'] = $final_pid;
  1316     header('Content-disposition: attachment; filename='.$filename.'');
  1316     $_POST['old_page_id'] = $final_pid;
  1317     header('Content-type: application/octet-stream');
  1317     if ( !isset($paths->pages[$paths->nslist[$_POST['namespace']].$_POST['urlname']]) )
  1318     header('Content-length: '.strlen($data));
  1318     {
  1319     echo $data;
  1319       echo 'The page you searched for cannot be found. <a href="#" onclick="ajaxPage(\''.$paths->nslist['Admin'].'PageManager\'); return false;">Back</a>';
  1320     exit;
  1320       return false;
  1321   }
  1321     }
  1322   else
  1322   }
  1323   {
  1323   
  1324     // Show the UI
  1324   if ( isset($_POST['page_id']) && isset($_POST['namespace']) && !isset($_POST['cancel']) )
  1325     echo '<form action="'.makeUrlNS('Admin', 'DBBackup', 'submitting=yes', true).'" method="post" enctype="multipart/form-data">';
  1325   {
       
  1326     $cpage = $paths->pages[$paths->nslist[$_POST['old_namespace']].$_POST['old_page_id']];
       
  1327     if(isset($_POST['submit']))
       
  1328     {
       
  1329       switch(true)
       
  1330       {
       
  1331         case true:
       
  1332           // Create a list of things to update
       
  1333           $page_info = Array(
       
  1334               'name'=>$_POST['name'],
       
  1335               'urlname'=>sanitize_page_id($_POST['page_id']),
       
  1336               'namespace'=>$_POST['namespace'],
       
  1337               'special'=>isset($_POST['special']) ? '1' : '0',
       
  1338               'visible'=>isset($_POST['visible']) ? '1' : '0',
       
  1339               'comments_on'=>isset($_POST['comments_on']) ? '1' : '0',
       
  1340               'protected'=>isset($_POST['protected']) ? '1' : '0'
       
  1341             );
       
  1342           
       
  1343           $updating_urlname_or_namespace = ( $page_info['namespace'] != $cpage['namespace'] || $page_info['urlname'] != $cpage['urlname_nons'] );
       
  1344           
       
  1345           if ( !isset($paths->nslist[ $page_info['namespace'] ]) )
       
  1346           {
       
  1347             echo '<div class="error-box">The namespace you selected is not properly registered.</div>';
       
  1348             break;
       
  1349           }
       
  1350           if ( isset($paths->pages[ $paths->nslist[$page_info['namespace']] . $page_info[ 'urlname' ] ]) && $updating_urlname_or_namespace )
       
  1351           {
       
  1352             echo '<div class="error-box">There is already a page that exists with that URL string and namespace.</div>';
       
  1353             break;
       
  1354           }
       
  1355           // Build the query
       
  1356           $q = 'UPDATE '.table_prefix.'pages SET ';
       
  1357           $k = array_keys($page_info);
       
  1358           foreach($k as $c)
       
  1359           {
       
  1360             $q .= $c.'=\''.$db->escape($page_info[$c]).'\',';
       
  1361           }
       
  1362           $q = substr($q, 0, strlen($q)-1);
       
  1363           // Build the WHERE statements
       
  1364           $q .= ' WHERE ';
       
  1365           $k = array_keys($cpage);
       
  1366           if ( !isset($cpage) )
       
  1367             die('[internal] no cpage');
       
  1368           foreach($k as $c)
       
  1369           {
       
  1370             if($c != 'urlname_nons' && $c != 'urlname' && $c != 'really_protected')
       
  1371             {
       
  1372               $q .= $c.'=\''.$db->escape($cpage[$c]).'\' AND ';
       
  1373             }
       
  1374             else if($c == 'urlname')
       
  1375             {
       
  1376               $q .= $c.'=\''.$db->escape($cpage['urlname_nons']).'\' AND ';
       
  1377             }
       
  1378           }
       
  1379           // Trim off the last " AND " and append a semicolon
       
  1380           $q = substr($q, 0, strlen($q)-5) . ';';
       
  1381           // Send the completed query to MySQL
       
  1382           $e = $db->sql_query($q);
       
  1383           if(!$e) $db->_die('The page data could not be updated.');
       
  1384           // Update any additional tables
       
  1385           $q = Array(
       
  1386             'UPDATE '.table_prefix.'categories SET page_id=\''.$page_info['urlname'].'\',namespace=\''.$page_info['namespace'].'\' WHERE page_id=\'' . $db->escape($_POST['old_page_id']) . '\' AND namespace=\'' . $db->escape($_POST['old_namespace']) . '\';',
       
  1387             'UPDATE '.table_prefix.'comments   SET page_id=\''.$page_info['urlname'].'\',namespace=\''.$page_info['namespace'].'\' WHERE page_id=\'' . $db->escape($_POST['old_page_id']) . '\' AND namespace=\'' . $db->escape($_POST['old_namespace']) . '\';',
       
  1388             'UPDATE '.table_prefix.'logs       SET page_id=\''.$page_info['urlname'].'\',namespace=\''.$page_info['namespace'].'\' WHERE page_id=\'' . $db->escape($_POST['old_page_id']) . '\' AND namespace=\'' . $db->escape($_POST['old_namespace']) . '\';',
       
  1389             'UPDATE '.table_prefix.'page_text  SET page_id=\''.$page_info['urlname'].'\',namespace=\''.$page_info['namespace'].'\' WHERE page_id=\'' . $db->escape($_POST['old_page_id']) . '\' AND namespace=\'' . $db->escape($_POST['old_namespace']) . '\';',
       
  1390             'UPDATE '.table_prefix.'acl        SET page_id=\''.$page_info['urlname'].'\',namespace=\''.$page_info['namespace'].'\' WHERE page_id=\'' . $db->escape($_POST['old_page_id']) . '\' AND namespace=\'' . $db->escape($_POST['old_namespace']) . '\';'
       
  1391             );
       
  1392           foreach($q as $cq)
       
  1393           {
       
  1394             $e = $db->sql_query($cq);
       
  1395             if(!$e) $db->_die('Some of the additional tables containing page information could not be updated.');
       
  1396           }
       
  1397           // Update $cpage
       
  1398           $cpage = $page_info;
       
  1399           $cpage['urlname_nons'] = $cpage['urlname'];
       
  1400           $cpage['urlname'] = $paths->nslist[$cpage['namespace']].$cpage['urlname'];
       
  1401           $_POST['old_page_id'] = $page_info['urlname'];
       
  1402           $_POST['old_namespace'] = $page_info['namespace'];
       
  1403           echo '<div class="info-box">Your changes have been saved.</div>';
       
  1404           break;
       
  1405       }
       
  1406     } elseif(isset($_POST['delete'])) {
       
  1407       $q = Array(
       
  1408         'DELETE FROM '.table_prefix.'categories WHERE page_id=\'' . $db->escape($_POST['old_page_id']) . '\' AND namespace=\'' . $db->escape($_POST['old_namespace']) . '\';',
       
  1409         'DELETE FROM '.table_prefix.'comments   WHERE page_id=\'' . $db->escape($_POST['old_page_id']) . '\' AND namespace=\'' . $db->escape($_POST['old_namespace']) . '\';',
       
  1410         'DELETE FROM '.table_prefix.'logs       WHERE page_id=\'' . $db->escape($_POST['old_page_id']) . '\' AND namespace=\'' . $db->escape($_POST['old_namespace']) . '\';',
       
  1411         'DELETE FROM '.table_prefix.'page_text  WHERE page_id=\'' . $db->escape($_POST['old_page_id']) . '\' AND namespace=\'' . $db->escape($_POST['old_namespace']) . '\';',
       
  1412         );
       
  1413       foreach($q as $cq)
       
  1414       {
       
  1415         $e = $db->sql_query($cq);
       
  1416         if(!$e) $db->_die('Some of the additional tables containing page information could not be updated.');
       
  1417       }
       
  1418       
       
  1419       if(!$db->sql_query(
       
  1420         'DELETE FROM '.table_prefix.'pages WHERE urlname="'.$db->escape($_POST['old_page_id']).'" AND namespace="'.$db->escape($_POST['old_namespace']).'";'
       
  1421       )) $db->_die('The page could not be deleted.');
       
  1422       echo '<div class="info-box">This page has been deleted.</p><p><a href="javascript:ajaxPage(\''.$paths->nslist['Admin'].'PageManager\');">Return to Page manager</a><br /><a href="javascript:ajaxPage(\''.$paths->nslist['Admin'].'Home\');">Admin home</a></div>';
       
  1423       return;
       
  1424     }
       
  1425     $url = makeUrlNS('Special', 'Administration', 'module='.$paths->cpage['module'], true);
       
  1426     echo '<form action="'.$url.'" method="post">';
       
  1427     ?>
  1326     ?>
  1428     <h3>Modify page: <?php echo htmlspecialchars($_POST['name']); ?></h3>
  1327     <p><?php echo $lang->get('acpdb_intro'); ?></p>
  1429      <table border="0">
  1328     <p><label><input type="checkbox" name="do_system_tables" checked="checked" /> <?php echo $lang->get('acpdb_lbl_system_tables'); ?></label><p>
  1430        <tr>
  1329     <p><?php echo $lang->get('acpdb_lbl_additional_tables'); ?></p>
  1431          <td>Namespace:</td>
  1330     <p><select name="additional_tables[]" multiple="multiple">
  1432          <td>
  1331        <?php
  1433            <select name="namespace">
  1332          if ( ENANO_DBLAYER == 'MYSQL' )
  1434              <?php
  1333          {
  1435              $nm = array_keys($paths->nslist);
  1334            $q = $db->sql_query('SHOW TABLES;') or $db->_die('Somehow we were denied the request to get the list of tables.');
  1436              foreach ( $nm as $ns )
  1335          }
  1437              {
  1336          else if ( ENANO_DBLAYER == 'PGSQL' )
  1438                if ( $ns != 'Special' && $ns != 'Admin' )
  1337          {
  1439                {
  1338            $q = $db->sql_query('SELECT relname FROM pg_stat_user_tables ORDER BY relname;') or $db->_die('Somehow we were denied the request to get the list of tables.');
  1440                  echo '<option ';
  1339          }
  1441                  if ( $_POST['namespace'] == $ns )
  1340          while($row = $db->fetchrow_num())
  1442                  echo 'selected="selected" ';
  1341          {
  1443                  echo 'value="'.$ns.'">';
  1342            if(!in_array($row[0], $system_table_list)) echo '<option value="'.$row[0].'">'.$row[0].'</option>';
  1444                  if ( $paths->nslist[$ns] == '' )
  1343          }
  1445                    echo '[No prefix]';
  1344        ?>
  1446                  else
  1345        </select>
  1447                    echo $paths->nslist[$ns];
  1346        </p>
  1448                  echo '</option>';
  1347     <p><label><input type="checkbox" name="do_struct" checked="checked" /> <?php echo $lang->get('acpdb_lbl_include_structure'); ?></label><br />
  1449                }
  1348        <label><input type="checkbox" name="do_data"   checked="checked" /> <?php echo $lang->get('acpdb_lbl_include_data'); ?></label>
  1450              } ?>
  1349        </p>
  1451            </select>
  1350     <p><input type="submit" value="<?php echo $lang->get('acpdb_btn_create_backup'); ?>" /></p>
  1452          </td>
       
  1453        </tr>
       
  1454        <tr>
       
  1455          <td>
       
  1456            Page title:
       
  1457          </td>
       
  1458          <td>
       
  1459            <input type="text" name="name" value="<?php echo htmlspecialchars($cpage['name']); ?>" />
       
  1460          </td>
       
  1461        </tr>
       
  1462        <tr>
       
  1463          <td>
       
  1464            Page URL string:<br />
       
  1465            <small>No spaces, and don't enter the namespace prefix (e.g. User:).<br />
       
  1466                   Changing this value is usually not a good idea, especially for templates and project pages.</small>
       
  1467           </td>
       
  1468           <td>
       
  1469             <input type="text" name="page_id" value="<?php echo htmlspecialchars(dirtify_page_id($cpage['urlname_nons'])); ?>" />
       
  1470           </td>
       
  1471        </tr>
       
  1472        <tr>
       
  1473          <td></td>
       
  1474          <td>
       
  1475            <input <?php if($cpage['comments_on']) echo 'checked="checked"'; ?> name="comments_on" type="checkbox" id="cmt" />
       
  1476            <label for="cmt">Enable comments for this page</label>
       
  1477          </td>
       
  1478        </tr>
       
  1479        <tr>
       
  1480          <td></td>
       
  1481          <td>
       
  1482            <input <?php if($cpage['special']) echo 'checked="checked"'; ?> name="special" type="checkbox" id="spc" />
       
  1483            <label for="spc">Bypass the template engine for this page</label><br />
       
  1484            <small>This option enables you to use your own HTML headers and other code. It is recommended that only advanced users enable this feature. As with other Enano pages, you may use PHP code in your pages, meaning you can use Enano's API on the page.</small>
       
  1485          </td>
       
  1486        </tr>
       
  1487        <tr>
       
  1488          <td></td>
       
  1489          <td>
       
  1490            <input <?php if($cpage['visible']) echo 'checked="checked"'; ?> name="visible" type="checkbox" id="vis" />
       
  1491            <label for="vis">Allow this page to be shown in page lists</label><br />
       
  1492            <small>Unchecking this checkbox prevents the page for being indexed for searching. The index is rebuilt each time a page is saved, and you can force an index rebuild by going to the page <?php echo $paths->nslist['Special']; ?>SearchRebuild.</small>
       
  1493          </td>
       
  1494        </tr>
       
  1495        <tr>
       
  1496          <td></td>
       
  1497          <td>
       
  1498            <input <?php if($cpage['protected']) echo 'checked="checked"'; ?> name="protected" type="checkbox" id="prt" />
       
  1499            <label for="prt">Prevent non-administrators from editing this page</label><br />
       
  1500            <small>This option only has an effect when Wiki Mode is enabled.</small>
       
  1501          </td>
       
  1502        </tr>
       
  1503        <tr>
       
  1504          <td></td>
       
  1505          <td>
       
  1506            <input type="submit" name="delete" value="Delete page" style="color: red" onclick="return confirm('Do you REALLY want to delete this page?')" />
       
  1507          </td>
       
  1508        </tr>
       
  1509        <tr>
       
  1510          <td colspan="2" style="text-align: center;">
       
  1511            <hr />
       
  1512          </td>
       
  1513        </tr>
       
  1514        <tr>
       
  1515          <td colspan="2" style="text-align: right;">
       
  1516            <input type="hidden" name="old_page_id" value="<?php echo htmlspecialchars($_POST['old_page_id']); ?>" />
       
  1517            <input type="hidden" name="old_namespace" value="<?php echo htmlspecialchars($_POST['old_namespace']); ?>" />
       
  1518            <input type="Submit" name="submit" value="Save changes" style="font-weight: bold;" />
       
  1519            <input type="submit" name="cancel" value="Cancel changes" />
       
  1520          </td>
       
  1521        </tr>
       
  1522      </table>
       
  1523     <?php
  1351     <?php
  1524     echo '</form>';
  1352     echo '</form>';
  1525   }
  1353   }
  1526   else
       
  1527   {
       
  1528     echo '<h3>Please select a page</h3>';
       
  1529     echo '<form action="'.makeUrl($paths->nslist['Special'].'Administration', 'module='.$paths->cpage['module']).'" method="post" onsubmit="if(!submitAuthorized) return false;" enctype="multipart/form-data">';
       
  1530     ?>
       
  1531       <p>Search for page title (remember prefixes like User: and File:) <?php echo $template->pagename_field('page_url'); ?>  <input type="submit" style="font-weight: bold;" name="search" value="Search" /></p>
       
  1532       <p>Select page title from a list: <select name="page_force_url">
       
  1533       <?php
       
  1534         for($i=0;$i<sizeof($paths->pages)/2;$i++)
       
  1535         {
       
  1536           if($paths->pages[$i]['namespace'] != 'Admin' && $paths->pages[$i]['namespace'] != 'Special') echo '<option value="'.$paths->nslist[$paths->pages[$i]['namespace']].$paths->pages[$i]['urlname_nons'].'">'.htmlspecialchars($paths->nslist[$paths->pages[$i]['namespace']].$paths->pages[$i]['name']).'</option>'."\n";
       
  1537         }
       
  1538       ?>
       
  1539       </select>  <input type="submit" name="select" value="Select" /></p>
       
  1540     <?php
       
  1541     echo '</form>';
       
  1542     
       
  1543   }
       
  1544 }
  1354 }
  1545 */
       
  1546 
  1355 
  1547 function page_Admin_PageEditor()
  1356 /*
  1548 {
  1357  * Admin:PageManager sources are in /plugins/admin/PageManager.php.
  1549   global $db, $session, $paths, $template, $plugins; // Common objects
  1358  */
  1550   global $lang;
  1359 
  1551   if ( $session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN )
  1360 /*
  1552   {
  1361  * Admin:PageEditor sources are in /plugins/admin/PageEditor.php.
  1553     $login_link = makeUrlNS('Special', 'Login/' . $paths->nslist['Special'] . 'Administration', 'level=' . USER_LEVEL_ADMIN, true);
  1362  */
  1554     echo '<h3>' . $lang->get('adm_err_not_auth_title') . '</h3>';
       
  1555     echo '<p>' . $lang->get('adm_err_not_auth_body', array( 'login_link' => $login_link )) . '</p>';
       
  1556     return;
       
  1557   }
       
  1558   
       
  1559   
       
  1560   echo '<h2>Edit page content</h2>';
       
  1561   
       
  1562   if(isset($_POST['search']) || isset($_POST['select'])) {
       
  1563     // The object of the game: using only the text a user entered, guess the page ID and namespace. *sigh* I HATE writing search algorithms...
       
  1564     if(isset($_POST['search'])) $pid = $_POST['page_url'];
       
  1565     elseif(isset($_POST['select'])) $pid = $_POST['page_force_url'];
       
  1566     else { echo 'Internal error selecting page search terms'; return false; }
       
  1567     // Look for a namespace prefix in the urlname, and assign a different namespace, if necessary
       
  1568     $k = array_keys($paths->nslist);
       
  1569     for($i=0;$i<sizeof($paths->nslist);$i++)
       
  1570     {
       
  1571       $ln = strlen($paths->nslist[$k[$i]]);
       
  1572       if(substr($pid, 0, $ln) == $paths->nslist[$k[$i]])
       
  1573       {
       
  1574         $ns = $k[$i];
       
  1575         $page_id = substr($pid, $ln, strlen($pid));
       
  1576       }
       
  1577     }
       
  1578     // The namespace is in $ns and the page name or ID (we don't know which yet) is in $page_id
       
  1579     // Now, iterate through $paths->pages searching for a page with this name or ID
       
  1580     for($i=0;$i<sizeof($paths->pages)/2;$i++)
       
  1581     {
       
  1582       if(!isset($final_pid))
       
  1583       {
       
  1584         if    ($paths->pages[$i]['urlname_nons'] == str_replace(' ', '_', $page_id)) $final_pid = str_replace(' ', '_', $page_id);
       
  1585         elseif($paths->pages[$i]['name'] == $page_id) $final_pid = $paths->pages[$i]['urlname_nons'];
       
  1586         elseif(strtolower($paths->pages[$i]['urlname_nons']) == strtolower(str_replace(' ', '_', $page_id))) $final_pid = $paths->pages[$i]['urlname_nons'];
       
  1587         elseif(strtolower($paths->pages[$i]['name']) == strtolower(str_replace('_', ' ', $page_id))) $final_pid = $paths->pages[$i]['urlname_nons'];
       
  1588         if(isset($final_pid)) { $_POST['name'] = $paths->pages[$i]['name']; $_POST['urlname'] = $paths->pages[$i]['urlname_nons']; }
       
  1589       }
       
  1590     }
       
  1591     if(!isset($final_pid)) { echo 'The page you searched for cannot be found. <a href="#" onclick="ajaxPage(\''.$paths->nslist['Admin'].'PageManager\'); return false;">Back</a>'; return false; }
       
  1592     $_POST['namespace'] = $ns;
       
  1593     $_POST['page_id'] = $final_pid;
       
  1594     if(!isset($paths->pages[$paths->nslist[$_POST['namespace']].$_POST['urlname']])) { echo 'The page you searched for cannot be found. <a href="#" onclick="ajaxPage(\''.$paths->nslist['Admin'].'PageManager\'); return false;">Back</a>'; return false; }
       
  1595   }
       
  1596   
       
  1597   if(isset($_POST['page_id']) && !isset($_POST['cancel']))
       
  1598   {
       
  1599     echo '<form name="main" action="'.makeUrl($paths->nslist['Special'].'Administration', 'module='.$paths->cpage['module']).'" method="post">';
       
  1600     if(!isset($_POST['content']) || isset($_POST['revert'])) $content = RenderMan::getPage($_POST['page_id'], $_POST['namespace'], 0, false, false, false, false);
       
  1601     else $content = $_POST['content'];
       
  1602     if(isset($_POST['save']))
       
  1603     {
       
  1604       $data = $content;
       
  1605       $id = md5( microtime() . mt_rand() );
       
  1606       
       
  1607       $minor = isset($_POST['minor']) ? 'true' : 'false';
       
  1608       $q='INSERT INTO '.table_prefix.'logs(log_type,action,time_id,date_string,page_id,namespace,page_text,char_tag,author,edit_summary,minor_edit) VALUES(\'page\', \'edit\', '.time().', \''.date('d M Y h:i a').'\', \'' . $db->escape($_POST['page_id']) . '\', \'' . $db->escape($_POST['namespace']) . '\', \''.$db->escape($data).'\', \''.$id.'\', \''.$session->username.'\', \''.$db->escape(htmlspecialchars($_POST['summary'])).'\', '.$minor.');';
       
  1609       if(!$db->sql_query($q)) $db->_die('The history (log) entry could not be inserted into the logs table.');
       
  1610       
       
  1611       $query = 'UPDATE '.table_prefix.'page_text SET page_text=\''.$db->escape($data).'\',char_tag=\''.$id.'\' WHERE page_id=\'' . $db->escape($_POST['page_id']) . '\' AND namespace=\'' . $db->escape($_POST['namespace']) . '\';';
       
  1612       $e = $db->sql_query($query);
       
  1613       if(!$e) echo '<div class="warning-box">The page data could not be saved. MySQL said: '.mysql_error().'<br /><br />Query:<br /><pre>'.$query.'</pre></div>';
       
  1614       else echo '<div class="info-box">Your page has been saved. <a href="'.makeUrlNS($_POST['namespace'], $_POST['page_id']).'">View page...</a></div>';
       
  1615     } elseif(isset($_POST['preview'])) {
       
  1616       echo '<h3>Preview</h3><p><b>Reminder:</b> This is only a preview; your changes to this page have not yet been saved.</p><div style="margin: 1em; padding: 10px; border: 1px dashed #606060; background-color: #F8F8F8; max-height: 200px; overflow: auto;">'.RenderMan::render($content).'</div>';
       
  1617     }
       
  1618     ?>
       
  1619     <p>
       
  1620     <textarea name="content" rows="20" cols="60" style="width: 100%;"><?php echo htmlspecialchars($content); ?></textarea><br />
       
  1621     Edit summary: <input name="summary" value="<?php if(isset($_POST['summary'])) echo htmlspecialchars($_POST['summary']); ?>" size="40" /><br />
       
  1622     <label><input type="checkbox" name="minor" <?php if(isset($_POST['minor'])) echo 'checked="checked" '; ?>/>  This is a minor edit</label>
       
  1623     </p>
       
  1624     <p>
       
  1625     <input type="hidden" name="page_id" value="<?php echo htmlspecialchars($_POST['page_id']); ?>" />
       
  1626     <input type="hidden" name="namespace" value="<?php echo htmlspecialchars($_POST['namespace']); ?>" />
       
  1627     <input type="submit" name="save" value="Save changes" style="font-weight: bold;" />&nbsp;&nbsp;<input type="submit" name="preview" value="Show preview" />&nbsp;&nbsp;<input type="submit" name="revert" value="Revert changes" onclick="return confirm('Do you really want to revert your changes?');" />&nbsp;&nbsp;<input type="submit" name="cancel" value="Cancel" onclick="return confirm('Do you really want to cancel your changes?');" />
       
  1628     </p>
       
  1629     <?php
       
  1630     echo '</form>';
       
  1631   } else {
       
  1632     echo '<h3>Please select a page</h3>';
       
  1633     echo '<form action="'.makeUrl($paths->nslist['Special'].'Administration', 'module='.$paths->cpage['module']).'" method="post" onsubmit="if(!submitAuthorized) return false;" enctype="multipart/form-data">';
       
  1634     ?>
       
  1635       <p>Search for page title (remember prefixes like User: and File:) <?php echo $template->pagename_field('page_url'); ?>  <input type="submit" style="font-weight: bold;" name="search" value="Search" /></p>
       
  1636       <p>Select page title from a list: <select name="page_force_url">
       
  1637       <?php
       
  1638         for ( $i = 0; $i < sizeof($paths->pages) / 2; $i++ )
       
  1639         {
       
  1640           if($paths->pages[$i]['namespace'] != 'Admin' && $paths->pages[$i]['namespace'] != 'Special') echo '<option value="'.$paths->nslist[$paths->pages[$i]['namespace']].$paths->pages[$i]['urlname_nons'].'">'.$paths->nslist[$paths->pages[$i]['namespace']].$paths->pages[$i]['name'].'</option>'."\n";
       
  1641         }
       
  1642       ?>
       
  1643       </select>  <input type="submit" name="select" value="Select" /></p>
       
  1644     <?php
       
  1645     echo '</form>';
       
  1646   }
       
  1647 }
       
  1648 
  1363 
  1649 function page_Admin_ThemeManager() 
  1364 function page_Admin_ThemeManager() 
  1650 {
  1365 {
  1651   
  1366   
  1652   global $db, $session, $paths, $template, $plugins; // Common objects
  1367   global $db, $session, $paths, $template, $plugins; // Common objects
  1674    <p>Install, uninstall, and manage Enano themes.</p>
  1389    <p>Install, uninstall, and manage Enano themes.</p>
  1675   ');
  1390   ');
  1676   if(isset($_POST['disenable'])) {
  1391   if(isset($_POST['disenable'])) {
  1677     $q = 'SELECT enabled FROM '.table_prefix.'themes WHERE theme_id=\'' . $db->escape($_POST['theme_id']) . '\'';
  1392     $q = 'SELECT enabled FROM '.table_prefix.'themes WHERE theme_id=\'' . $db->escape($_POST['theme_id']) . '\'';
  1678     $s = $db->sql_query($q);
  1393     $s = $db->sql_query($q);
  1679     if(!$s) die('Error selecting enabled/disabled state value: '.mysql_error().'<br /><u>SQL:</u><br />'.$q);
  1394     if(!$s) die('Error selecting enabled/disabled state value: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
  1680     $r = $db->fetchrow_num($s);
  1395     $r = $db->fetchrow_num($s);
  1681     $db->free_result();
  1396     $db->free_result();
  1682     if($r[0] == 1) $e = 0;
  1397     if($r[0] == 1) $e = 0;
  1683     else $e = 1;
  1398     else $e = 1;
  1684     $s=true;
  1399     $s=true;
  1690     }
  1405     }
  1691     $db->free_result();
  1406     $db->free_result();
  1692     if($s) {
  1407     if($s) {
  1693     $q = 'UPDATE '.table_prefix.'themes SET enabled='.$e.' WHERE theme_id=\'' . $db->escape($_POST['theme_id']) . '\'';
  1408     $q = 'UPDATE '.table_prefix.'themes SET enabled='.$e.' WHERE theme_id=\'' . $db->escape($_POST['theme_id']) . '\'';
  1694     $a = $db->sql_query($q);
  1409     $a = $db->sql_query($q);
  1695     if(!$a) die('Error updating enabled/disabled state value: '.mysql_error().'<br /><u>SQL:</u><br />'.$q);
  1410     if(!$a) die('Error updating enabled/disabled state value: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
  1696     else echo('<div class="info-box">The theme "'.$_POST['theme_id'].'" has been  '. ( ( $e == '1' ) ? 'enabled' : 'disabled' ).'.</div>');
  1411     else echo('<div class="info-box">The theme "'.$_POST['theme_id'].'" has been  '. ( ( $e == '1' ) ? 'enabled' : 'disabled' ).'.</div>');
  1697     }
  1412     }
  1698   }
  1413   }
  1699   elseif(isset($_POST['edit'])) {
  1414   elseif(isset($_POST['edit'])) {
  1700     
  1415     
  1713     }
  1428     }
  1714     $lk = array_keys($list);
  1429     $lk = array_keys($list);
  1715     
  1430     
  1716     $q = 'SELECT theme_name,default_style FROM '.table_prefix.'themes WHERE theme_id=\''.$db->escape($_POST['theme_id']).'\'';
  1431     $q = 'SELECT theme_name,default_style FROM '.table_prefix.'themes WHERE theme_id=\''.$db->escape($_POST['theme_id']).'\'';
  1717     $s = $db->sql_query($q);
  1432     $s = $db->sql_query($q);
  1718     if(!$s) die('Error selecting name value: '.mysql_error().'<br /><u>SQL:</u><br />'.$q);
  1433     if(!$s) die('Error selecting name value: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
  1719     $r = $db->fetchrow_num($s);
  1434     $r = $db->fetchrow_num($s);
  1720     $db->free_result();
  1435     $db->free_result();
  1721     echo('<form action="'.makeUrl($paths->nslist['Special'].'Administration', 'module='.$paths->cpage['module']).'" method="post">');
  1436     echo('<form action="'.makeUrl($paths->nslist['Special'].'Administration', 'module='.$paths->cpage['module']).'" method="post">');
  1722     echo('<div class="question-box">
  1437     echo('<div class="question-box">
  1723           Theme name displayed to users: <input type="text" name="name" value="'.$r[0].'" /><br /><br />
  1438           Theme name displayed to users: <input type="text" name="name" value="'.$r[0].'" /><br /><br />
  1734     echo('</form>');
  1449     echo('</form>');
  1735   }
  1450   }
  1736   elseif(isset($_POST['editsave'])) {
  1451   elseif(isset($_POST['editsave'])) {
  1737     $q = 'UPDATE '.table_prefix.'themes SET theme_name=\'' . $db->escape($_POST['name']) . '\',default_style=\''.$db->escape($_POST['defaultcss']).'\' WHERE theme_id=\'' . $db->escape($_POST['theme_id']) . '\'';
  1452     $q = 'UPDATE '.table_prefix.'themes SET theme_name=\'' . $db->escape($_POST['name']) . '\',default_style=\''.$db->escape($_POST['defaultcss']).'\' WHERE theme_id=\'' . $db->escape($_POST['theme_id']) . '\'';
  1738     $s = $db->sql_query($q);
  1453     $s = $db->sql_query($q);
  1739     if(!$s) die('Error updating name value: '.mysql_error().'<br /><u>SQL:</u><br />'.$q);
  1454     if(!$s) die('Error updating name value: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
  1740     else echo('<div class="info-box">Theme data updated.</div>');
  1455     else echo('<div class="info-box">Theme data updated.</div>');
  1741   }
  1456   }
  1742   elseif(isset($_POST['up'])) {
  1457   elseif(isset($_POST['up'])) {
  1743     // If there is only one theme or if the selected theme is already at the top, do nothing
  1458     // If there is only one theme or if the selected theme is already at the top, do nothing
  1744     $q = 'SELECT theme_order FROM '.table_prefix.'themes ORDER BY theme_order;';
  1459     $q = 'SELECT theme_order FROM '.table_prefix.'themes ORDER BY theme_order;';
  1745     $s = $db->sql_query($q);
  1460     $s = $db->sql_query($q);
  1746     if(!$s) die('Error selecting order information: '.mysql_error().'<br /><u>SQL:</u><br />'.$q);
  1461     if(!$s) die('Error selecting order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
  1747     $q = 'SELECT theme_order FROM '.table_prefix.'themes WHERE theme_id=\''.$db->escape($_POST['theme_id']).'\'';
  1462     $q = 'SELECT theme_order FROM '.table_prefix.'themes WHERE theme_id=\''.$db->escape($_POST['theme_id']).'\'';
  1748     $sn = $db->sql_query($q);
  1463     $sn = $db->sql_query($q);
  1749     if(!$sn) die('Error selecting order information: '.mysql_error().'<br /><u>SQL:</u><br />'.$q);
  1464     if(!$sn) die('Error selecting order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
  1750     $r = $db->fetchrow_num($sn);
  1465     $r = $db->fetchrow_num($sn);
  1751     if( /* check for only one theme... */ $db->numrows($s) < 2 || $r[0] == 1 /* ...and check if this theme is already at the top */ ) { echo('<div class="warning-box">This theme is already at the top of the list, or there is only one theme installed.</div>'); } else {
  1466     if( /* check for only one theme... */ $db->numrows($s) < 2 || $r[0] == 1 /* ...and check if this theme is already at the top */ ) { echo('<div class="warning-box">This theme is already at the top of the list, or there is only one theme installed.</div>'); } else {
  1752       // Get the order IDs of the selected theme and the theme before it
  1467       // Get the order IDs of the selected theme and the theme before it
  1753       $q = 'SELECT theme_order FROM '.table_prefix.'themes WHERE theme_id=\'' . $db->escape($_POST['theme_id']) . '\'';
  1468       $q = 'SELECT theme_order FROM '.table_prefix.'themes WHERE theme_id=\'' . $db->escape($_POST['theme_id']) . '\'';
  1754       $s = $db->sql_query($q);
  1469       $s = $db->sql_query($q);
  1755       if(!$s) die('Error selecting order information: '.mysql_error().'<br /><u>SQL:</u><br />'.$q);
  1470       if(!$s) die('Error selecting order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
  1756       $r = $db->fetchrow_num($s);
  1471       $r = $db->fetchrow_num($s);
  1757       $r = $r[0];
  1472       $r = $r[0];
  1758       $rb = $r - 1;
  1473       $rb = $r - 1;
  1759       // Thank God for jEdit's rectangular selection and the ablity to edit multiple lines at the same time ;)
  1474       // Thank God for jEdit's rectangular selection and the ablity to edit multiple lines at the same time ;)
  1760       $q = 'UPDATE '.table_prefix.'themes SET theme_order=0 WHERE theme_order='.$rb.'';      /* Check for errors... <sigh> */ $s = $db->sql_query($q); if(!$s) die('Error updating order information: '.mysql_error().'<br /><u>SQL:</u><br />'.$q);
  1475       $q = 'UPDATE '.table_prefix.'themes SET theme_order=0 WHERE theme_order='.$rb.'';      /* Check for errors... <sigh> */ $s = $db->sql_query($q); if(!$s) die('Error updating order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
  1761       $q = 'UPDATE '.table_prefix.'themes SET theme_order='.$rb.' WHERE theme_order='.$r.''; /* Check for errors... <sigh> */ $s = $db->sql_query($q); if(!$s) die('Error updating order information: '.mysql_error().'<br /><u>SQL:</u><br />'.$q);
  1476       $q = 'UPDATE '.table_prefix.'themes SET theme_order='.$rb.' WHERE theme_order='.$r.''; /* Check for errors... <sigh> */ $s = $db->sql_query($q); if(!$s) die('Error updating order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
  1762       $q = 'UPDATE '.table_prefix.'themes SET theme_order='.$r.' WHERE theme_order=0';       /* Check for errors... <sigh> */ $s = $db->sql_query($q); if(!$s) die('Error updating order information: '.mysql_error().'<br /><u>SQL:</u><br />'.$q);
  1477       $q = 'UPDATE '.table_prefix.'themes SET theme_order='.$r.' WHERE theme_order=0';       /* Check for errors... <sigh> */ $s = $db->sql_query($q); if(!$s) die('Error updating order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
  1763       echo('<div class="info-box">Theme moved up.</div>');
  1478       echo('<div class="info-box">Theme moved up.</div>');
  1764     }
  1479     }
  1765     $db->free_result($s);
  1480     $db->free_result($s);
  1766     $db->free_result($sn);
  1481     $db->free_result($sn);
  1767   }
  1482   }
  1768   elseif(isset($_POST['down'])) {
  1483   elseif(isset($_POST['down'])) {
  1769     // If there is only one theme or if the selected theme is already at the top, do nothing
  1484     // If there is only one theme or if the selected theme is already at the top, do nothing
  1770     $q = 'SELECT theme_order FROM '.table_prefix.'themes ORDER BY theme_order;';
  1485     $q = 'SELECT theme_order FROM '.table_prefix.'themes ORDER BY theme_order;';
  1771     $s = $db->sql_query($q);
  1486     $s = $db->sql_query($q);
  1772     if(!$s) die('Error selecting order information: '.mysql_error().'<br /><u>SQL:</u><br />'.$q);
  1487     if(!$s) die('Error selecting order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
  1773     $r = $db->fetchrow_num($s);
  1488     $r = $db->fetchrow_num($s);
  1774     if( /* check for only one theme... */ $db->numrows($s) < 2 || $r[0] == $db->numrows($s) /* ...and check if this theme is already at the bottom */ ) { echo('<div class="warning-box">This theme is already at the bottom of the list, or there is only one theme installed.</div>'); } else {
  1489     if( /* check for only one theme... */ $db->numrows($s) < 2 || $r[0] == $db->numrows($s) /* ...and check if this theme is already at the bottom */ ) { echo('<div class="warning-box">This theme is already at the bottom of the list, or there is only one theme installed.</div>'); } else {
  1775       // Get the order IDs of the selected theme and the theme before it
  1490       // Get the order IDs of the selected theme and the theme before it
  1776       $q = 'SELECT theme_order FROM '.table_prefix.'themes WHERE theme_id=\''.$db->escape($_POST['theme_id']).'\'';
  1491       $q = 'SELECT theme_order FROM '.table_prefix.'themes WHERE theme_id=\''.$db->escape($_POST['theme_id']).'\'';
  1777       $s = $db->sql_query($q);
  1492       $s = $db->sql_query($q);
  1778       if(!$s) die('Error selecting order information: '.mysql_error().'<br /><u>SQL:</u><br />'.$q);
  1493       if(!$s) die('Error selecting order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
  1779       $r = $db->fetchrow_num($s);
  1494       $r = $db->fetchrow_num($s);
  1780       $r = $r[0];
  1495       $r = $r[0];
  1781       $rb = $r + 1;
  1496       $rb = $r + 1;
  1782       // Thank God for jEdit's rectangular selection and the ablity to edit multiple lines at the same time ;)
  1497       // Thank God for jEdit's rectangular selection and the ablity to edit multiple lines at the same time ;)
  1783       $q = 'UPDATE '.table_prefix.'themes SET theme_order=0 WHERE theme_order='.$rb.'';      /* Check for errors... <sigh> */ $s = $db->sql_query($q); if(!$s) die('Error updating order information: '.mysql_error().'<br /><u>SQL:</u><br />'.$q);
  1498       $q = 'UPDATE '.table_prefix.'themes SET theme_order=0 WHERE theme_order='.$rb.'';      /* Check for errors... <sigh> */ $s = $db->sql_query($q); if(!$s) die('Error updating order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
  1784       $q = 'UPDATE '.table_prefix.'themes SET theme_order='.$rb.' WHERE theme_order='.$r.''; /* Check for errors... <sigh> */ $s = $db->sql_query($q); if(!$s) die('Error updating order information: '.mysql_error().'<br /><u>SQL:</u><br />'.$q);
  1499       $q = 'UPDATE '.table_prefix.'themes SET theme_order='.$rb.' WHERE theme_order='.$r.''; /* Check for errors... <sigh> */ $s = $db->sql_query($q); if(!$s) die('Error updating order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
  1785       $q = 'UPDATE '.table_prefix.'themes SET theme_order='.$r.' WHERE theme_order=0';       /* Check for errors... <sigh> */ $s = $db->sql_query($q); if(!$s) die('Error updating order information: '.mysql_error().'<br /><u>SQL:</u><br />'.$q);
  1500       $q = 'UPDATE '.table_prefix.'themes SET theme_order='.$r.' WHERE theme_order=0';       /* Check for errors... <sigh> */ $s = $db->sql_query($q); if(!$s) die('Error updating order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
  1786       echo('<div class="info-box">Theme moved down.</div>');
  1501       echo('<div class="info-box">Theme moved down.</div>');
  1787     }
  1502     }
  1788   }
  1503   }
  1789   else if(isset($_POST['uninstall'])) 
  1504   else if(isset($_POST['uninstall'])) 
  1790   {
  1505   {
  1791     $q = 'SELECT * FROM '.table_prefix.'themes;';
  1506     $q = 'SELECT * FROM '.table_prefix.'themes;';
  1792     $s = $db->sql_query($q);
  1507     $s = $db->sql_query($q);
  1793     if ( !$s )
  1508     if ( !$s )
  1794     {
  1509     {
  1795       die('Error getting theme count: '.mysql_error().'<br /><u>SQL:</u><br />'.$q);
  1510       die('Error getting theme count: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
  1796     }
  1511     }
  1797     $n = $db->numrows($s);
  1512     $n = $db->numrows($s);
  1798     $db->free_result();
  1513     $db->free_result();
  1799     
  1514     
  1800     if ( $_POST['theme_id'] == 'oxygen' )
  1515     if ( $_POST['theme_id'] == 'oxygen' )
  1811       {
  1526       {
  1812         $q = 'DELETE FROM '.table_prefix.'themes WHERE theme_id=\''.$db->escape($_POST['theme_id']).'\' LIMIT 1;';
  1527         $q = 'DELETE FROM '.table_prefix.'themes WHERE theme_id=\''.$db->escape($_POST['theme_id']).'\' LIMIT 1;';
  1813         $s = $db->sql_query($q);
  1528         $s = $db->sql_query($q);
  1814         if ( !$s )
  1529         if ( !$s )
  1815         {
  1530         {
  1816           die('Error deleting theme data: '.mysql_error().'<br /><u>SQL:</u><br />'.$q);
  1531           die('Error deleting theme data: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
  1817         }
  1532         }
  1818         else
  1533         else
  1819         {
  1534         {
  1820           echo('<div class="info-box">Theme uninstalled.</div>');
  1535           echo('<div class="info-box">Theme uninstalled.</div>');
  1821         }
  1536         }
  1823     }
  1538     }
  1824   }
  1539   }
  1825   elseif(isset($_POST['install'])) {
  1540   elseif(isset($_POST['install'])) {
  1826     $q = 'SELECT theme_id FROM '.table_prefix.'themes;';
  1541     $q = 'SELECT theme_id FROM '.table_prefix.'themes;';
  1827     $s = $db->sql_query($q);
  1542     $s = $db->sql_query($q);
  1828     if(!$s) die('Error getting theme count: '.mysql_error().'<br /><u>SQL:</u><br />'.$q);
  1543     if(!$s) die('Error getting theme count: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
  1829     $n = $db->numrows($s);
  1544     $n = $db->numrows($s);
  1830     $n++;
  1545     $n++;
  1831     $theme_id = $_POST['theme_id'];
  1546     $theme_id = $_POST['theme_id'];
  1832     $theme = Array();
  1547     $theme = Array();
  1833     include('./themes/'.$theme_id.'/theme.cfg');
  1548     include('./themes/'.$theme_id.'/theme.cfg');
  1857       
  1572       
  1858       if ( $default_style )
  1573       if ( $default_style )
  1859       {
  1574       {
  1860         $q = 'INSERT INTO '.table_prefix.'themes(theme_id,theme_name,theme_order,enabled,default_style) VALUES(\''.$db->escape($theme['theme_id']).'\', \''.$db->escape($theme['theme_name']).'\', '.$n.', 1, \'' . $db->escape($default_style) . '\')';
  1575         $q = 'INSERT INTO '.table_prefix.'themes(theme_id,theme_name,theme_order,enabled,default_style) VALUES(\''.$db->escape($theme['theme_id']).'\', \''.$db->escape($theme['theme_name']).'\', '.$n.', 1, \'' . $db->escape($default_style) . '\')';
  1861         $s = $db->sql_query($q);
  1576         $s = $db->sql_query($q);
  1862         if(!$s) die('Error inserting theme data: '.mysql_error().'<br /><u>SQL:</u><br />'.$q);
  1577         if(!$s) die('Error inserting theme data: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
  1863         else echo('<div class="info-box">Theme "'.$theme['theme_name'].'" installed.</div>');
  1578         else echo('<div class="info-box">Theme "'.$theme['theme_name'].'" installed.</div>');
  1864       }
  1579       }
  1865       else
  1580       else
  1866       {
  1581       {
  1867         echo '<div class="error-box">Could not determine the default style for the theme.</div>';
  1582         echo '<div class="error-box">Could not determine the default style for the theme.</div>';
  1874     <p>
  1589     <p>
  1875       <select name="theme_id">
  1590       <select name="theme_id">
  1876         ');
  1591         ');
  1877         $q = 'SELECT theme_id,theme_name,enabled FROM '.table_prefix.'themes ORDER BY theme_order';
  1592         $q = 'SELECT theme_id,theme_name,enabled FROM '.table_prefix.'themes ORDER BY theme_order';
  1878         $s = $db->sql_query($q);
  1593         $s = $db->sql_query($q);
  1879         if(!$s) die('Error selecting theme data: '.mysql_error().'<br /><u>Attempted SQL:</u><br />'.$q);
  1594         if(!$s) die('Error selecting theme data: '.$db->get_error().'<br /><u>Attempted SQL:</u><br />'.$q);
  1880         while ( $r = $db->fetchrow_num($s) ) {
  1595         while ( $r = $db->fetchrow_num($s) ) {
  1881           if($r[2] < 1) $r[1] .= ' (disabled)';
  1596           if($r[2] < 1) $r[1] .= ' (disabled)';
  1882           echo('<option value="'.$r[0].'">'.$r[1].'</option>');
  1597           echo('<option value="'.$r[0].'">'.$r[1].'</option>');
  1883         }
  1598         }
  1884         $db->free_result();
  1599         $db->free_result();
  1893     for($i=0;$i<sizeof($l);$i++) {
  1608     for($i=0;$i<sizeof($l);$i++) {
  1894       if(is_file('./themes/'.$l[$i].'/theme.cfg') && file_exists('./themes/'.$l[$i].'/theme.cfg')) {
  1609       if(is_file('./themes/'.$l[$i].'/theme.cfg') && file_exists('./themes/'.$l[$i].'/theme.cfg')) {
  1895         include('./themes/'.$l[$i].'/theme.cfg');
  1610         include('./themes/'.$l[$i].'/theme.cfg');
  1896         $q = 'SELECT * FROM '.table_prefix.'themes WHERE theme_id=\''.$theme['theme_id'].'\'';
  1611         $q = 'SELECT * FROM '.table_prefix.'themes WHERE theme_id=\''.$theme['theme_id'].'\'';
  1897         $s = $db->sql_query($q);
  1612         $s = $db->sql_query($q);
  1898         if(!$s) die('Error selecting list of currently installed themes: '.mysql_error().'<br /><u>Attempted SQL:</u><br />'.$q);
  1613         if(!$s) die('Error selecting list of currently installed themes: '.$db->get_error().'<br /><u>Attempted SQL:</u><br />'.$q);
  1899         if($db->numrows($s) < 1) {
  1614         if($db->numrows($s) < 1) {
  1900           $obb .= '<option value="'.$theme['theme_id'].'">'.$theme['theme_name'].'</option>';
  1615           $obb .= '<option value="'.$theme['theme_id'].'">'.$theme['theme_name'].'</option>';
  1901         }
  1616         }
  1902         $db->free_result();
  1617         $db->free_result();
  1903       }
  1618       }
  1933       return;
  1648       return;
  1934     }
  1649     }
  1935     echo '<form action="'.makeUrl($paths->nslist['Special'].'Administration', 'module='.$paths->cpage['module']).'" method="post" onsubmit="if(!submitAuthorized) return false;" enctype="multipart/form-data">';
  1650     echo '<form action="'.makeUrl($paths->nslist['Special'].'Administration', 'module='.$paths->cpage['module']).'" method="post" onsubmit="if(!submitAuthorized) return false;" enctype="multipart/form-data">';
  1936     echo '<div class="tblholder">
  1651     echo '<div class="tblholder">
  1937           <table border="0" style="width:100%;" cellspacing="1" cellpadding="4">
  1652           <table border="0" style="width:100%;" cellspacing="1" cellpadding="4">
  1938           <tr><th colspan="2">Creating group: '.$_POST['create_group_name'].'</th></tr>
  1653           <tr><th colspan="2">Creating group: '.htmlspecialchars($_POST['create_group_name']).'</th></tr>
  1939           <tr>
  1654           <tr>
  1940             <td class="row1">Group moderator</td><td class="row1">' . $template->username_field('group_mod') . '</td>
  1655             <td class="row1">Group moderator</td><td class="row1">' . $template->username_field('group_mod') . '</td>
  1941           </tr>
  1656           </tr>
  1942           <tr><td class="row2">Group status</td><td class="row2">
  1657           <tr><td class="row2">Group status</td><td class="row2">
  1943             <label><input type="radio" name="group_status" value="'.GROUP_CLOSED.'" checked="checked" /> Closed to new members</label><br />
  1658             <label><input type="radio" name="group_status" value="'.GROUP_CLOSED.'" checked="checked" /> Closed to new members</label><br />
  1945             <label><input type="radio" name="group_status" value="'.GROUP_OPEN.'" /> Members can join freely</label><br />
  1660             <label><input type="radio" name="group_status" value="'.GROUP_OPEN.'" /> Members can join freely</label><br />
  1946             <label><input type="radio" name="group_status" value="'.GROUP_HIDDEN.'" /> Group is hidden</label>
  1661             <label><input type="radio" name="group_status" value="'.GROUP_HIDDEN.'" /> Group is hidden</label>
  1947           </td></tr>
  1662           </td></tr>
  1948           <tr>
  1663           <tr>
  1949             <th class="subhead" colspan="2">
  1664             <th class="subhead" colspan="2">
  1950               <input type="hidden" name="create_group_name" value="'.$_POST['create_group_name'].'" />
  1665               <input type="hidden" name="create_group_name" value="'.htmlspecialchars($_POST['create_group_name']).'" />
  1951               <input type="submit" name="do_create_stage2" value="Create group" />
  1666               <input type="submit" name="do_create_stage2" value="Create group" />
  1952             </th>
  1667             </th>
  1953           </tr>
  1668           </tr>
  1954           </table>
  1669           </table>
  1955           </div>';
  1670           </div>';
  2018     if(!$e)
  1733     if(!$e)
  2019     {
  1734     {
  2020       echo $db->get_error();
  1735       echo $db->get_error();
  2021       return;
  1736       return;
  2022     }
  1737     }
       
  1738     $g_name = htmlspecialchars($_POST['create_group_name']);
  2023     echo "<div class='info-box'>
  1739     echo "<div class='info-box'>
  2024             <b>Information</b><br />
  1740             <b>Information</b><br />
  2025             The group {$_POST['create_group_name']} has been created successfully.
  1741             The group {$g_name} has been created successfully.
  2026           </div>";
  1742           </div>";
  2027   }
  1743   }
  2028   if(isset($_POST['do_edit']) || isset($_POST['edit_do']))
  1744   if(isset($_POST['do_edit']) || isset($_POST['edit_do']))
  2029   {
  1745   {
  2030     // Fetch the group name
  1746     // Fetch the group name
  2037     if($db->numrows() < 1)
  1753     if($db->numrows() < 1)
  2038     {
  1754     {
  2039       echo '<p>Error: couldn\'t look up group name</p>';
  1755       echo '<p>Error: couldn\'t look up group name</p>';
  2040     }
  1756     }
  2041     $row = $db->fetchrow();
  1757     $row = $db->fetchrow();
  2042     $name = $row['group_name'];
  1758     $name = htmlspecialchars($row['group_name']);
  2043     $db->free_result();
  1759     $db->free_result();
  2044     if(isset($_POST['edit_do']))
  1760     if(isset($_POST['edit_do']))
  2045     {
  1761     {
  2046       if(isset($_POST['edit_do']['del_group']))
  1762       if(isset($_POST['edit_do']['del_group']))
  2047       {
  1763       {
  2085         {
  1801         {
  2086           echo '<div class="info-box" style="margin: 0 0 10px 0;"">
  1802           echo '<div class="info-box" style="margin: 0 0 10px 0;"">
  2087                   The group name has been updated.
  1803                   The group name has been updated.
  2088                 </div>';
  1804                 </div>';
  2089         }
  1805         }
  2090         $name = $_POST['group_name'];
  1806         $name = htmlspecialchars($_POST['group_name']);
  2091         
  1807         
  2092       }
  1808       }
  2093       $q = $db->sql_query('SELECT member_id FROM '.table_prefix.'group_members
  1809       $q = $db->sql_query('SELECT member_id FROM '.table_prefix.'group_members
  2094                              WHERE group_id='.intval($_POST['group_edit_id']).';');
  1810                              WHERE group_id='.intval($_POST['group_edit_id']).';');
  2095       if(!$q)
  1811       if(!$q)
  2138                     The user "'.$_POST['edit_add_username'].'" has been added to this usergroup.
  1854                     The user "'.$_POST['edit_add_username'].'" has been added to this usergroup.
  2139                   </div>';
  1855                   </div>';
  2140           }
  1856           }
  2141         }
  1857         }
  2142         else
  1858         else
  2143           echo '<div class="warning-box"><b>The user "'.$_POST['edit_add_username'].'" could not be added.</b><br />This username does not exist.</div>';
  1859           echo '<div class="warning-box"><b>The user "'.htmlspecialchars($_POST['edit_add_username']).'" could not be added.</b><br />This username does not exist.</div>';
  2144       }
  1860       }
  2145     }
  1861     }
  2146     $sg_disabled = ( $row['system_group'] == 1 ) ? ' value="Can\'t delete system group" disabled="disabled" style="color: #FF9773" ' : ' value="Delete this group" style="color: #FF3713" ';
  1862     $sg_disabled = ( $row['system_group'] == 1 ) ? ' value="Can\'t delete system group" disabled="disabled" style="color: #FF9773" ' : ' value="Delete this group" style="color: #FF3713" ';
  2147     echo '<form action="'.makeUrl($paths->nslist['Special'].'Administration', 'module='.$paths->cpage['module']).'" method="post" onsubmit="if(!submitAuthorized) return false;" enctype="multipart/form-data">';
  1863     echo '<form action="'.makeUrl($paths->nslist['Special'].'Administration', 'module='.$paths->cpage['module']).'" method="post" onsubmit="if(!submitAuthorized) return false;" enctype="multipart/form-data">';
  2148     echo '<div class="tblholder">
  1864     echo '<div class="tblholder">
  2159               <input type="submit" name="edit_do[del_group]" '.$sg_disabled.' />
  1875               <input type="submit" name="edit_do[del_group]" '.$sg_disabled.' />
  2160             </th>
  1876             </th>
  2161           </tr>
  1877           </tr>
  2162           </table>
  1878           </table>
  2163           </div>
  1879           </div>
  2164           <input type="hidden" name="group_edit_id" value="'.$_POST['group_edit_id'].'" />';
  1880           <input type="hidden" name="group_edit_id" value="'.htmlspecialchars($_POST['group_edit_id']).'" />';
  2165     echo '</form>';
  1881     echo '</form>';
  2166     echo '<form action="'.makeUrl($paths->nslist['Special'].'Administration', 'module='.$paths->cpage['module']).'" method="post" onsubmit="if(!submitAuthorized) return false;" enctype="multipart/form-data">';
  1882     echo '<form action="'.makeUrl($paths->nslist['Special'].'Administration', 'module='.$paths->cpage['module']).'" method="post" onsubmit="if(!submitAuthorized) return false;" enctype="multipart/form-data">';
  2167     echo '<div class="tblholder">
  1883     echo '<div class="tblholder">
  2168           <table border="0" style="width:100%;" cellspacing="1" cellpadding="4">
  1884           <table border="0" style="width:100%;" cellspacing="1" cellpadding="4">
  2169           <tr><th colspan="3">Edit group members</th></tr>';
  1885           <tr><th colspan="3">Edit group members</th></tr>';
  2202       }
  1918       }
  2203     }
  1919     }
  2204     $db->free_result();
  1920     $db->free_result();
  2205     echo '</table>
  1921     echo '</table>
  2206           </div>
  1922           </div>
  2207           <input type="hidden" name="group_edit_id" value="'.$_POST['group_edit_id'].'" />';
  1923           <input type="hidden" name="group_edit_id" value="'.htmlspecialchars($_POST['group_edit_id']).'" />';
  2208     echo '</form>';
  1924     echo '</form>';
  2209     echo '<form action="'.makeUrl($paths->nslist['Special'].'Administration', 'module='.$paths->cpage['module']).'" method="post" onsubmit="if(!submitAuthorized) return false;" enctype="multipart/form-data">';
  1925     echo '<form action="'.makeUrl($paths->nslist['Special'].'Administration', 'module='.$paths->cpage['module']).'" method="post" onsubmit="if(!submitAuthorized) return false;" enctype="multipart/form-data">';
  2210     echo '<div class="tblholder">
  1926     echo '<div class="tblholder">
  2211           <table border="0" style="width:100%;" cellspacing="1" cellpadding="4">
  1927           <table border="0" style="width:100%;" cellspacing="1" cellpadding="4">
  2212             <tr>
  1928             <tr>
  2227                 <input type="submit" name="edit_do[add_member]" value="Add user to group" />
  1943                 <input type="submit" name="edit_do[add_member]" value="Add user to group" />
  2228               </th>
  1944               </th>
  2229             </tr>
  1945             </tr>
  2230           </table>
  1946           </table>
  2231           </div>
  1947           </div>
  2232           <input type="hidden" name="group_edit_id" value="'.$_POST['group_edit_id'].'" />';
  1948           <input type="hidden" name="group_edit_id" value="'.htmlspecialchars($_POST['group_edit_id']).'" />';
  2233     echo '</form>';
  1949     echo '</form>';
  2234     return;
  1950     return;
  2235   }
  1951   }
  2236   echo '<h3>Manage Usergroups</h3>';
  1952   echo '<h3>Manage Usergroups</h3>';
  2237   echo '<form action="'.makeUrl($paths->nslist['Special'].'Administration', 'module='.$paths->cpage['module']).'" method="post" onsubmit="if(!submitAuthorized) return false;" enctype="multipart/form-data">';
  1953   echo '<form action="'.makeUrl($paths->nslist['Special'].'Administration', 'module='.$paths->cpage['module']).'" method="post" onsubmit="if(!submitAuthorized) return false;" enctype="multipart/form-data">';
  2678       
  2394       
  2679     </table>
  2395     </table>
  2680   </div>
  2396   </div>
  2681   <?php
  2397   <?php
  2682   echo '</form>';
  2398   echo '</form>';
  2683 }
       
  2684 
       
  2685 function page_Admin_DBBackup()
       
  2686 {
       
  2687   global $db, $session, $paths, $template, $plugins; // Common objects
       
  2688   global $lang;
       
  2689   if ( $session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN )
       
  2690   {
       
  2691     $login_link = makeUrlNS('Special', 'Login/' . $paths->nslist['Special'] . 'Administration', 'level=' . USER_LEVEL_ADMIN, true);
       
  2692     echo '<h3>' . $lang->get('adm_err_not_auth_title') . '</h3>';
       
  2693     echo '<p>' . $lang->get('adm_err_not_auth_body', array( 'login_link' => $login_link )) . '</p>';
       
  2694     return;
       
  2695   }
       
  2696   
       
  2697   if ( ENANO_DBLAYER != 'MYSQL' )
       
  2698     die('<h3>Not supported</h3>
       
  2699           <p>This function is only supported under the MySQL database driver.</p>');
       
  2700   
       
  2701   if(isset($_GET['submitting']) && $_GET['submitting'] == 'yes' && defined('ENANO_DEMO_MODE') )
       
  2702   {
       
  2703     redirect(makeUrlComplete('Special', 'Administration'), 'Access denied', 'You\'ve got to be kidding me. Forget it, kid.', 4 );
       
  2704   }
       
  2705   
       
  2706   global $system_table_list;
       
  2707   if(isset($_GET['submitting']) && $_GET['submitting'] == 'yes')
       
  2708   {
       
  2709     
       
  2710     if(defined('SQL_BACKUP_CRYPT'))
       
  2711       // Try to increase our time limit
       
  2712       @set_time_limit(0);
       
  2713     // Do the actual export
       
  2714     $aesext = ( defined('SQL_BACKUP_CRYPT') ) ? '.tea' : '';
       
  2715     $filename = 'enano_backup_' . date('ymd') . '.sql' . $aesext;
       
  2716     ob_start();
       
  2717     // Spew some headers
       
  2718     $headdate = date('F d, Y \a\t h:i a');
       
  2719     echo <<<HEADER
       
  2720 -- Enano CMS SQL backup
       
  2721 -- Generated on {$headdate} by {$session->username}
       
  2722 
       
  2723 HEADER;
       
  2724     // build the table list
       
  2725     $base = ( isset($_POST['do_system_tables']) ) ? $system_table_list : Array();
       
  2726     $add  = ( isset($_POST['additional_tables'])) ? $_POST['additional_tables'] : Array();
       
  2727     $tables = array_merge($base, $add);
       
  2728     
       
  2729     // Log it!
       
  2730     $e = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,date_string,author,edit_summary,page_text) VALUES(\'security\', \'db_backup\', '.time().', \''.date('d M Y h:i a').'\', \''.$db->escape($session->username).'\', \''.$db->escape($_SERVER['REMOTE_ADDR']).'\', \'' . $db->escape(implode(', ', $tables)) . '\')');
       
  2731     if ( !$e )
       
  2732       $db->_die();
       
  2733     
       
  2734     foreach($tables as $i => $t)
       
  2735     {
       
  2736       if(!preg_match('#^([a-z0-9_]+)$#i', $t))
       
  2737         die('Hacking attempt');
       
  2738       // if($t == table_prefix.'files' && isset($_POST['do_data']))
       
  2739       //   unset($tables[$i]);
       
  2740     }
       
  2741     foreach($tables as $t)
       
  2742     {
       
  2743       // THE FOLLOWING COMMENT DOES NOT APPLY AS OF 1.0.
       
  2744       // Sorry folks - this script CAN'T backup enano_files and enano_search_index due to the sheer size of the tables.
       
  2745       // If encryption is enabled the log data will be excluded too.
       
  2746       $result = export_table(
       
  2747         $t,
       
  2748         isset($_POST['do_struct']),
       
  2749         ( isset($_POST['do_data']) ),
       
  2750         false
       
  2751         ) . "\n";
       
  2752       if ( !$result )
       
  2753       {
       
  2754         $db->_die();
       
  2755       }
       
  2756       echo $result;
       
  2757     }
       
  2758     $data = ob_get_contents();
       
  2759     ob_end_clean();
       
  2760     if(defined('SQL_BACKUP_CRYPT'))
       
  2761     {
       
  2762       // Free some memory, we don't need this stuff any more
       
  2763       $db->close();
       
  2764       unset($paths, $db, $template, $plugins);
       
  2765       $tea = new TEACrypt();
       
  2766       $data = $tea->encrypt($data, $session->private_key);
       
  2767     }
       
  2768     header('Content-disposition: attachment, filename="'.$filename.'";');
       
  2769     header('Content-type: application/transact-sql');
       
  2770     header('Content-length: '.strlen($data));
       
  2771     echo $data;
       
  2772     exit;
       
  2773   }
       
  2774   else
       
  2775   {
       
  2776     // Show the UI
       
  2777     echo '<form action="'.makeUrlNS('Admin', 'DBBackup', 'submitting=yes', true).'" method="post" enctype="multipart/form-data">';
       
  2778     ?>
       
  2779     <p>This page allows you to back up your Enano database should something go miserably wrong.</p>
       
  2780     <p><label><input type="checkbox" name="do_system_tables" checked="checked" />  Export tables that are part of the Enano core</label><p>
       
  2781     <p>Additional tables to export:</p>
       
  2782     <p><select name="additional_tables[]" multiple="multiple">
       
  2783        <?php
       
  2784          if ( ENANO_DBLAYER == 'MYSQL' )
       
  2785          {
       
  2786            $q = $db->sql_query('SHOW TABLES;') or $db->_die('Somehow we were denied the request to get the list of tables.');
       
  2787          }
       
  2788          else if ( ENANO_DBLAYER == 'PGSQL' )
       
  2789          {
       
  2790            $q = $db->sql_query('SELECT relname FROM pg_stat_user_tables ORDER BY relname;') or $db->_die('Somehow we were denied the request to get the list of tables.');
       
  2791          }
       
  2792          while($row = $db->fetchrow_num())
       
  2793          {
       
  2794            if(!in_array($row[0], $system_table_list)) echo '<option value="'.$row[0].'">'.$row[0].'</option>';
       
  2795          }
       
  2796        ?>
       
  2797        </select>
       
  2798        </p>
       
  2799     <p><label><input type="checkbox" name="do_struct" checked="checked" /> Include table structure</label><br />
       
  2800        <label><input type="checkbox" name="do_data"   checked="checked" /> Include table data</label>
       
  2801        </p>
       
  2802     <p><input type="submit" value="Create backup" /></p>
       
  2803     <?php
       
  2804     echo '</form>';
       
  2805   }
       
  2806 }
  2399 }
  2807 
  2400 
  2808 function page_Admin_AdminLogout()
  2401 function page_Admin_AdminLogout()
  2809 {
  2402 {
  2810   global $db, $session, $paths, $template, $plugins; // Common objects
  2403   global $db, $session, $paths, $template, $plugins; // Common objects