plugins/SpecialAdmin.php
changeset 74 68469a95658d
parent 73 0a74676a2f2f
child 80 cb7dde69c301
equal deleted inserted replaced
73:0a74676a2f2f 74:68469a95658d
    37       \'namespace\'=>\'Special\',
    37       \'namespace\'=>\'Special\',
    38       \'special\'=>0,\'visible\'=>0,\'comments_on\'=>0,\'protected\'=>1,\'delvotes\'=>0,\'delvote_ips\'=>\'\',
    38       \'special\'=>0,\'visible\'=>0,\'comments_on\'=>0,\'protected\'=>1,\'delvotes\'=>0,\'delvote_ips\'=>\'\',
    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
       
    43 require(ENANO_ROOT . '/plugins/admin/PageGroups.php');
       
    44 
    42 // function names are IMPORTANT!!! The name pattern is: page_<namespace ID>_<page URLname, without namespace>
    45 // function names are IMPORTANT!!! The name pattern is: page_<namespace ID>_<page URLname, without namespace>
    43 
    46 
    44 function page_Admin_Home() {
    47 function page_Admin_Home() {
    45   global $db, $session, $paths, $template, $plugins; // Common objects
    48   global $db, $session, $paths, $template, $plugins; // Common objects
    46   if ( $session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN )
    49   if ( $session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN )
   136         case "activ_bad": echo 'Failed account activation'; break;
   139         case "activ_bad": echo 'Failed account activation'; break;
   137         case "auth_bad": echo 'Failed regular user logon'; break;
   140         case "auth_bad": echo 'Failed regular user logon'; break;
   138         case "sql_inject": echo 'SQL injection attempt<div style="max-width: 90%; clip: rect(0px,auto,auto,0px); overflow: auto; display: block; font-size: smaller;">Offending query: ' . htmlspecialchars($r['page_text']) . '</div>'; break;
   141         case "sql_inject": echo 'SQL injection attempt<div style="max-width: 90%; clip: rect(0px,auto,auto,0px); overflow: auto; display: block; font-size: smaller;">Offending query: ' . htmlspecialchars($r['page_text']) . '</div>'; break;
   139         case "db_backup": echo 'Database backup created<br /><small>Tables: ' . $r['page_text'] . '</small>'; break;
   142         case "db_backup": echo 'Database backup created<br /><small>Tables: ' . $r['page_text'] . '</small>'; break;
   140         case "install_enano": echo "Installed Enano version {$r['page_text']}"; break;
   143         case "install_enano": echo "Installed Enano version {$r['page_text']}"; break;
       
   144         case "upgrade_enano": echo "Upgraded Enano to version {$r['page_text']}"; break;
   141       }
   145       }
   142       echo '</td><td class="'.$cls.'">'.date('d M Y h:i a', $r['time_id']).'</td><td class="'.$cls.'">'.$r['author'].'</td><td class="'.$cls.'" style="cursor: pointer;" onclick="ajaxReverseDNS(this);" title="Click for reverse DNS info">'.$r['edit_summary'].'</td></tr>';
   146       echo '</td><td class="'.$cls.'">'.date('d M Y h:i a', $r['time_id']).'</td><td class="'.$cls.'">'.$r['author'].'</td><td class="'.$cls.'" style="cursor: pointer;" onclick="ajaxReverseDNS(this);" title="Click for reverse DNS info">'.$r['edit_summary'].'</td></tr>';
   143     }
   147     }
   144     $db->free_result();
   148     $db->free_result();
   145   }
   149   }
  1706       ?>
  1710       ?>
  1707       </select>  <input type="submit" name="select" value="Select" /></p>
  1711       </select>  <input type="submit" name="select" value="Select" /></p>
  1708     <?php
  1712     <?php
  1709     echo '</form>';
  1713     echo '</form>';
  1710   }
  1714   }
  1711 }
       
  1712 
       
  1713 function page_Admin_PageGroups()
       
  1714 {
       
  1715   global $db, $session, $paths, $template, $plugins; // Common objects
       
  1716   if ( $session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN )
       
  1717   {
       
  1718     echo '<h3>Error: Not authenticated</h3><p>It looks like your administration session is invalid or you are not authorized to access this administration page. Please <a href="' . makeUrlNS('Special', 'Login/' . $paths->nslist['Special'] . 'Administration', 'level=' . USER_LEVEL_ADMIN, true) . '">re-authenticate</a> to continue.</p>';
       
  1719     return;
       
  1720   }
       
  1721   
       
  1722   if ( isset($_POST['action']) )
       
  1723   {
       
  1724     if ( isset($_POST['action']['create']) || isset($_POST['action']['create_stage2']) )
       
  1725     {
       
  1726       switch ( isset($_POST['action']['create_stage2']) )
       
  1727       {
       
  1728         case true:
       
  1729           if ( empty($_POST['pg_name']) || empty($_POST['group_type']) )
       
  1730           {
       
  1731             echo '<div class="error-box">Please enter a name for the page group.</div>';
       
  1732             return;
       
  1733           }
       
  1734           if ( $_POST['group_type'] == PAGE_GRP_TAGGED && empty($_POST['member_tag']) )
       
  1735           {
       
  1736             echo '<div class="error-box">Please enter a page tag.</div>';
       
  1737             return;
       
  1738           }
       
  1739           if ( $_POST['group_type'] == PAGE_GRP_CATLINK && empty($_POST['member_cat']) )
       
  1740           {
       
  1741             echo '<div class="error-box">Please create a category page before linking a page group to a category.</div>';
       
  1742             return;
       
  1743           }
       
  1744           if ( $_POST['group_type'] == PAGE_GRP_NORMAL && empty($_POST['member_page_0']) )
       
  1745           {
       
  1746             echo '<div class="error-box">Please specify at least one page to place in this group.</div>';
       
  1747             return;
       
  1748           }
       
  1749           if ( $_POST['group_type'] != PAGE_GRP_TAGGED && $_POST['group_type'] != PAGE_GRP_CATLINK && $_POST['group_type'] != PAGE_GRP_NORMAL )
       
  1750           {
       
  1751             echo '<div class="error-box">Umm, you sent an invalid group type. I\'d put a real error message here but this will only be shown if you try to hack the system.</div>';
       
  1752             return;
       
  1753           }
       
  1754           // All checks passed, create the group
       
  1755           switch($_POST['group_type'])
       
  1756           {
       
  1757             case PAGE_GRP_TAGGED:
       
  1758               $name = $db->escape($_POST['pg_name']);
       
  1759               $tag  = $db->escape($_POST['member_tag']);
       
  1760               $sql = 'INSERT INTO '.table_prefix.'page_groups(pg_type,pg_name,pg_target) VALUES(' . PAGE_GRP_TAGGED . ', \'' . $name . '\', \'' . $tag . '\');';
       
  1761               $q = $db->sql_query($sql);
       
  1762               if ( !$q )
       
  1763                 $db->_die();
       
  1764               break;
       
  1765             case PAGE_GRP_CATLINK:
       
  1766               $name = $db->escape($_POST['pg_name']);
       
  1767               $cat  = $db->escape($_POST['member_cat']);
       
  1768               $sql = 'INSERT INTO '.table_prefix.'page_groups(pg_type,pg_name,pg_target) VALUES(' . PAGE_GRP_CATLINK . ', \'' . $name . '\', \'' . $cat . '\');';
       
  1769               $q = $db->sql_query($sql);
       
  1770               if ( !$q )
       
  1771                 $db->_die();
       
  1772               break;
       
  1773             case PAGE_GRP_NORMAL:
       
  1774               $name = $db->escape($_POST['pg_name']);
       
  1775               $sql = 'INSERT INTO '.table_prefix.'page_groups(pg_type,pg_name) VALUES(' . PAGE_GRP_NORMAL . ', \'' . $name . '\');';
       
  1776               $q = $db->sql_query($sql);
       
  1777               if ( !$q )
       
  1778                 $db->_die();
       
  1779               
       
  1780               $ins_id = $db->insert_id();
       
  1781               
       
  1782               // Page list
       
  1783               $keys = array_keys($_POST);
       
  1784               $arr_pages = array();
       
  1785               foreach ( $keys as $val )
       
  1786               {
       
  1787                 if ( preg_match('/^member_page_([0-9]+?)$/', $val) && !empty($_POST[$val]) )
       
  1788                 {
       
  1789                   $arr_pages[] = $_POST[$val];
       
  1790                 }
       
  1791               }
       
  1792               $arr_sql = array();
       
  1793               foreach ( $arr_pages as $page )
       
  1794               {
       
  1795                 list($id, $ns) = RenderMan::strToPageID($page);
       
  1796                 $id = sanitize_page_id($id);
       
  1797                 $arr_sql[] = '(' . $ins_id . ',\'' . $db->escape($id) . '\', \'' . $ns . '\')';
       
  1798               }
       
  1799               $sql = 'INSERT INTO '.table_prefix.'page_group_members(pg_id,page_id,namespace) VALUES' . implode(',', $arr_sql) . ';';
       
  1800               $q = $db->sql_query($sql);
       
  1801               if ( !$q )
       
  1802                 $db->_die();
       
  1803               break;
       
  1804           }
       
  1805           echo '<div class="info-box">The page group "' . htmlspecialchars($_POST['pg_name']) . '" has been created.</div>';
       
  1806           break;
       
  1807       }
       
  1808       // A little Javascript magic
       
  1809       ?>
       
  1810       <script language="javascript" type="text/javascript">
       
  1811         function pg_create_typeset(selector)
       
  1812         {
       
  1813           var pg_normal  = <?php echo PAGE_GRP_NORMAL; ?>;
       
  1814           var pg_tagged  = <?php echo PAGE_GRP_TAGGED; ?>;
       
  1815           var pg_catlink = <?php echo PAGE_GRP_CATLINK; ?>;
       
  1816           var selection = false;
       
  1817           // Get selection
       
  1818           for ( var i = 0; i < selector.childNodes.length; i++ )
       
  1819           {
       
  1820             var child = selector.childNodes[i];
       
  1821             if ( !child || child.tagName != 'OPTION' )
       
  1822             {
       
  1823               continue;
       
  1824             }
       
  1825             if ( child.selected )
       
  1826             {
       
  1827               selection = child.value;
       
  1828             }
       
  1829           }
       
  1830           if ( !selection )
       
  1831           {
       
  1832             alert('Cannot get field value');
       
  1833             return true;
       
  1834           }
       
  1835           selection = parseInt(selection);
       
  1836           if ( selection != pg_normal && selection != pg_tagged && selection != pg_catlink )
       
  1837           {
       
  1838             alert('Invalid field value');
       
  1839             return true;
       
  1840           }
       
  1841           
       
  1842           // We have the selection and it's validated; show the appropriate field group
       
  1843           
       
  1844           if ( selection == pg_normal )
       
  1845           {
       
  1846             document.getElementById('pg_create_title_catlink').style.display = 'none';
       
  1847             document.getElementById('pg_create_catlink_1').style.display = 'none';
       
  1848             document.getElementById('pg_create_catlink_2').style.display = 'none';
       
  1849             
       
  1850             document.getElementById('pg_create_title_tagged').style.display = 'none';
       
  1851             document.getElementById('pg_create_tagged_1').style.display = 'none';
       
  1852             document.getElementById('pg_create_tagged_2').style.display = 'none';
       
  1853             
       
  1854             document.getElementById('pg_create_title_normal').style.display = 'inline';
       
  1855             document.getElementById('pg_create_normal_1').style.display = 'block';
       
  1856             document.getElementById('pg_create_normal_2').style.display = 'block';
       
  1857           }
       
  1858           else if ( selection == pg_catlink )
       
  1859           {
       
  1860             document.getElementById('pg_create_title_catlink').style.display = 'inline';
       
  1861             document.getElementById('pg_create_catlink_1').style.display = 'block';
       
  1862             document.getElementById('pg_create_catlink_2').style.display = 'block';
       
  1863             
       
  1864             document.getElementById('pg_create_title_tagged').style.display = 'none';
       
  1865             document.getElementById('pg_create_tagged_1').style.display = 'none';
       
  1866             document.getElementById('pg_create_tagged_2').style.display = 'none';
       
  1867             
       
  1868             document.getElementById('pg_create_title_normal').style.display = 'none';
       
  1869             document.getElementById('pg_create_normal_1').style.display = 'none';
       
  1870             document.getElementById('pg_create_normal_2').style.display = 'none';
       
  1871           }
       
  1872           else if ( selection == pg_tagged )
       
  1873           {
       
  1874             document.getElementById('pg_create_title_catlink').style.display = 'none';
       
  1875             document.getElementById('pg_create_catlink_1').style.display = 'none';
       
  1876             document.getElementById('pg_create_catlink_2').style.display = 'none';
       
  1877             
       
  1878             document.getElementById('pg_create_title_tagged').style.display = 'inline';
       
  1879             document.getElementById('pg_create_tagged_1').style.display = 'block';
       
  1880             document.getElementById('pg_create_tagged_2').style.display = 'block';
       
  1881             
       
  1882             document.getElementById('pg_create_title_normal').style.display = 'none';
       
  1883             document.getElementById('pg_create_normal_1').style.display = 'none';
       
  1884             document.getElementById('pg_create_normal_2').style.display = 'none';
       
  1885           }
       
  1886         
       
  1887         }
       
  1888         
       
  1889         // Set to pg_normal on page load
       
  1890         var pg_createform_init = function()
       
  1891         {
       
  1892           document.getElementById('pg_create_title_catlink').style.display = 'none';
       
  1893           document.getElementById('pg_create_catlink_1').style.display = 'none';
       
  1894           document.getElementById('pg_create_catlink_2').style.display = 'none';
       
  1895           
       
  1896           document.getElementById('pg_create_title_tagged').style.display = 'none';
       
  1897           document.getElementById('pg_create_tagged_1').style.display = 'none';
       
  1898           document.getElementById('pg_create_tagged_2').style.display = 'none';
       
  1899           
       
  1900           document.getElementById('pg_create_title_normal').style.display = 'inline';
       
  1901           document.getElementById('pg_create_normal_1').style.display = 'block';
       
  1902           document.getElementById('pg_create_normal_2').style.display = 'block';
       
  1903         }
       
  1904         
       
  1905         addOnloadHook(pg_createform_init);
       
  1906         
       
  1907         function pg_create_more_fields()
       
  1908         {
       
  1909           var targettd = document.getElementById('pg_create_normal_2');
       
  1910           var id = 0;
       
  1911           for ( var i = 0; i < targettd.childNodes.length; i++ )
       
  1912           {
       
  1913             var child = targettd.childNodes[i];
       
  1914             if ( child.tagName == 'INPUT' )
       
  1915             {
       
  1916               if ( child.type == 'button' )
       
  1917               {
       
  1918                 var newInp = document.createElement('input');
       
  1919                 // <input type="text" name="member_page_1" id="pg_create_member_1" onkeyup="return ajaxPageNameComplete(this);" size="30" /><br />
       
  1920                 newInp.type    = 'text';
       
  1921                 newInp.name    = 'member_page_' + id;
       
  1922                 newInp.id      = 'pg_create_member_' + id;
       
  1923                 newInp.onkeyup = function(e) { return ajaxPageNameComplete(this); };
       
  1924                 newInp.size    = '30';
       
  1925                 newInp.style.marginTop = '3px';
       
  1926                 targettd.insertBefore(newInp, child);
       
  1927                 targettd.insertBefore(document.createElement('br'), child);
       
  1928                 break;
       
  1929               }
       
  1930               else // if ( child.type == 'text' )
       
  1931               {
       
  1932                 id++;
       
  1933               }
       
  1934             }
       
  1935           }
       
  1936         }
       
  1937         
       
  1938       </script>
       
  1939       <?php
       
  1940       
       
  1941       // Build category list
       
  1942       $q = $db->sql_query('SELECT name,urlname FROM '.table_prefix.'pages WHERE namespace=\'Category\';');
       
  1943       if ( !$q )
       
  1944         $db->_die();
       
  1945       
       
  1946       if ( $db->numrows() < 1 )
       
  1947       {
       
  1948         $catlist = 'There aren\'t any categories on this site.';
       
  1949       }
       
  1950       else
       
  1951       {
       
  1952         $catlist = '<select name="member_cat">';
       
  1953         while ( $row = $db->fetchrow() )
       
  1954         {
       
  1955           $catlist .= '<option value="' . htmlspecialchars($row['urlname']) . '">' . htmlspecialchars($row['name']) . '</option>';
       
  1956         }
       
  1957         $catlist .= '</select>';
       
  1958       }
       
  1959       
       
  1960       echo '<form action="'.makeUrl($paths->nslist['Special'].'Administration', 'module='.$paths->cpage['module']).'" method="post" onsubmit="if(!submitAuthorized) return false;" enctype="multipart/form-data">';
       
  1961       
       
  1962       echo '<div class="tblholder">
       
  1963             <table border="0" cellspacing="1" cellpadding="4">
       
  1964               <tr>
       
  1965               <th colspan="2">Create page group</th>
       
  1966               </tr>';
       
  1967       
       
  1968       // Name
       
  1969       echo '<tr>
       
  1970               <td class="row2">
       
  1971               Group name:<br />
       
  1972               <small>This should be short, descriptive, and human-readable.</small>
       
  1973               </td>
       
  1974               <td class="row1">
       
  1975               <input type="text" name="pg_name" size="30" />
       
  1976               </td>
       
  1977             </tr>';
       
  1978             
       
  1979       // Group type
       
  1980       echo '<tr>
       
  1981               <td class="row2">
       
  1982               Group type:
       
  1983               </td>
       
  1984               <td class="row1">
       
  1985               <select name="group_type" onchange="pg_create_typeset(this);">
       
  1986                 <option value="' . PAGE_GRP_NORMAL  . '" selected="selected">Static group of pages</option>
       
  1987                 <option value="' . PAGE_GRP_TAGGED  . '">Group of pages with one tag</option>
       
  1988                 <option value="' . PAGE_GRP_CATLINK . '">Link to category</option>
       
  1989               </select>
       
  1990               </td>
       
  1991             </tr>';
       
  1992             
       
  1993       // Titles
       
  1994       echo '<tr>
       
  1995               <th colspan="2">
       
  1996                 <span id="pg_create_title_normal">
       
  1997                   Static group of pages
       
  1998                 </span>
       
  1999                 <span id="pg_create_title_tagged">
       
  2000                   Group of commonly tagged pages
       
  2001                 </span>
       
  2002                 <span id="pg_create_title_catlink">
       
  2003                   Mirror a category
       
  2004                 </span>
       
  2005               </th>
       
  2006             </tr>';
       
  2007       
       
  2008       echo '<tr>
       
  2009               <td class="row2">
       
  2010                 <div id="pg_create_normal_1">
       
  2011                   Member pages:<br />
       
  2012                   <small>Click the "plus" button to add more fields.</small>
       
  2013                 </div>
       
  2014                 <div id="pg_create_catlink_1">
       
  2015                   Include pages in this category:<br />
       
  2016                   <small>Pages in subcategories are <u>not</u> included, however subcategory pages themselves are.</small>
       
  2017                 </div>
       
  2018                 <div id="pg_create_tagged_1">
       
  2019                   Include pages with this tag:
       
  2020                 </div>
       
  2021               </td>';
       
  2022             
       
  2023       echo '  <td class="row1">
       
  2024                 <div id="pg_create_normal_2" />
       
  2025                   <input type="text" style="margin-top: 3px;" name="member_page_0" id="pg_create_member_0" onkeyup="return ajaxPageNameComplete(this);" size="30" /><br />
       
  2026                   <input type="text" style="margin-top: 3px;" name="member_page_1" id="pg_create_member_1" onkeyup="return ajaxPageNameComplete(this);" size="30" /><br />
       
  2027                   <input type="text" style="margin-top: 3px;" name="member_page_2" id="pg_create_member_2" onkeyup="return ajaxPageNameComplete(this);" size="30" /><br />
       
  2028                   <input type="text" style="margin-top: 3px;" name="member_page_3" id="pg_create_member_3" onkeyup="return ajaxPageNameComplete(this);" size="30" /><br />
       
  2029                   <input type="text" style="margin-top: 3px;" name="member_page_4" id="pg_create_member_4" onkeyup="return ajaxPageNameComplete(this);" size="30" /><br />
       
  2030                   <input type="button" onclick="pg_create_more_fields(); return false;" style="margin-top: 5px;" value="&nbsp;&nbsp;+&nbsp;&nbsp;" />
       
  2031                 </div>
       
  2032                 <div id="pg_create_tagged_2">
       
  2033                   <input type="text" name="member_tag" size="30" />
       
  2034                 </div>
       
  2035                 <div id="pg_create_catlink_2">
       
  2036                   ' . $catlist . '
       
  2037                 </div>
       
  2038               </td>
       
  2039             </tr>';
       
  2040             
       
  2041       // Submit button
       
  2042       echo '<tr>
       
  2043               <th class="subhead" colspan="2"><input type="submit" name="action[create_stage2]" value="Create page group" style="font-weight: bold;" /> <input type="submit" name="action[noop]" value="Cancel" style="font-weight: normal;" /></th>
       
  2044             </tr>';
       
  2045             
       
  2046       echo '</table>
       
  2047             </div>';
       
  2048       
       
  2049       echo '</form>';
       
  2050       return;
       
  2051     }
       
  2052     else if ( isset($_POST['action']['del']) )
       
  2053     {
       
  2054       // Confirmation to delete a group (this is really only a stub)
       
  2055       
       
  2056       $delete_id = array_keys($_POST['action']['del']);
       
  2057       $delete_id = intval($delete_id[0]);
       
  2058       
       
  2059       if ( !empty($delete_id) )
       
  2060       {
       
  2061         echo '<form action="'.makeUrl($paths->nslist['Special'].'Administration', 'module='.$paths->cpage['module']).'" method="post" onsubmit="if(!submitAuthorized) return false;" enctype="multipart/form-data">';
       
  2062         echo '<input type="hidden" name="delete_id" value="' . $delete_id . '" />';
       
  2063         echo '<div class="tblholder">';
       
  2064         echo '  <table border="0" cellspacing="1" cellpadding="4">';
       
  2065         echo '    <tr><th>Confirm deletion</th></tr>';
       
  2066         echo '    <tr><td class="row2" style="text-align: center; padding: 20px 0;">Are you sure you want to delete this page group?</td></tr>';
       
  2067         echo '    <tr><td class="row1" style="text-align: center;">';
       
  2068         echo '        <input type="submit" name="action[del_confirm]" value="Yes, delete group" style="font-weight: bold;" />';
       
  2069         echo '        <input type="submit" name="action[noop]" value="Cancel" style="font-weight: normal;" />';
       
  2070         echo '        </td></tr>';
       
  2071         echo '  </table>';
       
  2072         echo '</form>';
       
  2073         
       
  2074         return;
       
  2075       }
       
  2076     }
       
  2077     else if ( isset($_POST['action']['del_confirm']) )
       
  2078     {
       
  2079       $delete_id = intval($_POST['delete_id']);
       
  2080       if ( empty($delete_id) )
       
  2081       {
       
  2082         echo 'Hack attempt';
       
  2083         return;
       
  2084       }
       
  2085       // Obtain group name
       
  2086       $q = $db->sql_query('SELECT pg_name FROM '.table_prefix.'page_groups WHERE pg_id=' . $delete_id . ';');
       
  2087       if ( !$q )
       
  2088         $db->_die();
       
  2089       if ( $db->numrows() < 1 )
       
  2090       {
       
  2091         echo 'Page group dun exist.';
       
  2092         return;
       
  2093       }
       
  2094       $row = $db->fetchrow();
       
  2095       $pg_name = $row['pg_name'];
       
  2096       unset($row);
       
  2097       // Delete the group
       
  2098       $q = $db->sql_query('DELETE FROM '.table_prefix.'page_groups WHERE pg_id=' . $delete_id . ';');
       
  2099       if ( !$q )
       
  2100         $db->_die();
       
  2101       $q = $db->sql_query('DELETE FROM '.table_prefix.'page_group_members WHERE pg_id=' . $delete_id . ';');
       
  2102       if ( !$q )
       
  2103         $db->_die();
       
  2104       echo "<div class='info-box'>The group ".'"'."$pg_name".'"'." has been deleted.</div>";
       
  2105     }
       
  2106     else if ( isset($_POST['action']['edit']) )
       
  2107     {
       
  2108       return;
       
  2109     }
       
  2110     else if ( isset($_POST['action']['noop']) )
       
  2111     {
       
  2112       // Do nothing
       
  2113     }
       
  2114     else
       
  2115     {
       
  2116       echo '<div class="error-box">Invalid format of $_POST[action].</div>';
       
  2117     }
       
  2118   }
       
  2119   // No action defined - show default menu
       
  2120   $q = $db->sql_query('SELECT pg_id, pg_type, pg_name, pg_target FROM '.table_prefix.'page_groups;');
       
  2121   if ( !$q )
       
  2122     $db->_die();
       
  2123 
       
  2124   echo '<form action="'.makeUrl($paths->nslist['Special'].'Administration', 'module='.$paths->cpage['module']).'" method="post" onsubmit="if(!submitAuthorized) return false;" enctype="multipart/form-data">';
       
  2125   
       
  2126   echo '<div class="tblholder">
       
  2127           <table border="0" cellspacing="1" cellpadding="4">
       
  2128             <tr>
       
  2129               <th>Group name</th>
       
  2130               <th>Type</th>
       
  2131               <th>Target</th>
       
  2132               <th colspan="2">Actions</th>
       
  2133             </tr>';
       
  2134   
       
  2135   if ( $row = $db->fetchrow() )
       
  2136   {
       
  2137     do
       
  2138     {
       
  2139       $name = htmlspecialchars($row['pg_name']);
       
  2140       $type = 'Invalid';
       
  2141       switch ( $row['pg_type'] )
       
  2142       {
       
  2143         case PAGE_GRP_CATLINK:
       
  2144           $type = 'Link to category';
       
  2145           break;
       
  2146         case PAGE_GRP_TAGGED:
       
  2147           $type = 'Set of tagged pages';
       
  2148           break;
       
  2149         case PAGE_GRP_NORMAL:
       
  2150           $type = 'Static set of pages';
       
  2151           break;
       
  2152       }
       
  2153       $target = '';
       
  2154       if ( $row['pg_type'] == PAGE_GRP_TAGGED )
       
  2155       {
       
  2156         $target = 'Tag: ' . htmlspecialchars($row['pg_target']);
       
  2157       }
       
  2158       else if ( $row['pg_type'] == PAGE_GRP_CATLINK )
       
  2159       {
       
  2160         $target = 'Category: ' . htmlspecialchars(get_page_title($paths->nslist['Category'] . sanitize_page_id($row['pg_target'])));
       
  2161       }
       
  2162       $btn_edit = '<input type="submit" name="action[edit][' . $row['pg_id'] . ']" value="Edit" />';
       
  2163       $btn_del = '<input type="submit" name="action[del][' . $row['pg_id'] . ']" value="Delete" />';
       
  2164       // stupid jEdit bug/hack
       
  2165       $quot = '"';
       
  2166       echo "<tr>
       
  2167               <td class={$quot}row1{$quot}>$name</td>
       
  2168               <td class={$quot}row2{$quot}>$type</td>
       
  2169               <td class={$quot}row1{$quot}>$target</td>
       
  2170               <td class={$quot}row3{$quot} style={$quot}text-align: center;{$quot}>$btn_edit</td>
       
  2171               <td class={$quot}row3{$quot} style={$quot}text-align: center;{$quot}>$btn_del</td>
       
  2172             </tr>";
       
  2173     }
       
  2174     while ( $row = $db->fetchrow() );
       
  2175   }
       
  2176   else
       
  2177   {
       
  2178     echo '  <tr><td class="row3" colspan="5" style="text-align: center;">No page groups defined.</td></tr>';
       
  2179   }
       
  2180   
       
  2181   echo '    <tr>
       
  2182               <th class="subhead" colspan="5">
       
  2183                 <input type="submit" name="action[create]" value="Create new group" />
       
  2184               </th>
       
  2185             </tr>';
       
  2186   
       
  2187   echo '  </table>
       
  2188         </div>';
       
  2189         
       
  2190   echo '</form>';          
       
  2191     
       
  2192 }
  1715 }
  2193 
  1716 
  2194 function page_Admin_ThemeManager() 
  1717 function page_Admin_ThemeManager() 
  2195 {
  1718 {
  2196   
  1719