plugins/admin/PageGroups.php
changeset 81 d7fc25acd3f3
parent 80 cb7dde69c301
child 117 7cfdbb2fd17a
equal deleted inserted replaced
80:cb7dde69c301 81:d7fc25acd3f3
   402       if ( !$q )
   402       if ( !$q )
   403         $db->_die();
   403         $db->_die();
   404       $q = $db->sql_query('DELETE FROM '.table_prefix.'page_group_members WHERE pg_id=' . $delete_id . ';');
   404       $q = $db->sql_query('DELETE FROM '.table_prefix.'page_group_members WHERE pg_id=' . $delete_id . ';');
   405       if ( !$q )
   405       if ( !$q )
   406         $db->_die();
   406         $db->_die();
   407       echo "<div class='info-box'>The group ".'"'."$pg_name".'"'." has been deleted.</div>";
   407       echo "<div class='info-box'>The group ".'"'.htmlspecialchars("$pg_name").'"'." has been deleted.</div>";
   408     }
   408     }
   409     else if ( isset($_POST['action']['edit']) && !isset($_POST['action']['noop']) )
   409     else if ( isset($_POST['action']['edit']) && !isset($_POST['action']['noop']) )
   410     {
   410     {
   411       if ( isset($_POST['action']['edit_save']) )
   411       if ( isset($_POST['action']['edit_save']) )
   412       {
   412       {
   437           $return = array('mode' => 'error', 'text' => 'Please enter a page title.');
   437           $return = array('mode' => 'error', 'text' => 'Please enter a page title.');
   438           echo $json->encode($return);
   438           echo $json->encode($return);
   439           return;
   439           return;
   440         }
   440         }
   441         
   441         
       
   442         /*
       
   443         // We're gonna allow adding nonexistent pages for now
   442         if ( !isPage($page) )
   444         if ( !isPage($page) )
   443         {
   445         {
   444           $return = array('mode' => 'error', 'text' => 'The page you are trying to add (' . htmlspecialchars($page) . ') does not exist.');
   446           $return = array('mode' => 'error', 'text' => 'The page you are trying to add (' . htmlspecialchars($page) . ') does not exist.');
   445           echo $json->encode($return);
   447           echo $json->encode($return);
   446           return;
   448           return;
   447         }
   449         }
       
   450         */
   448         
   451         
   449         list($page_id, $namespace) = RenderMan::strToPageID($page);
   452         list($page_id, $namespace) = RenderMan::strToPageID($page);
   450         $page_id = sanitize_page_id($page_id);
   453         $page_id = sanitize_page_id($page_id);
       
   454         
       
   455         if ( !isset($paths->namespace[$namespace]) )
       
   456         {
       
   457           $return = array('mode' => 'error', 'text' => 'Invalid namespace return from RenderMan::strToPageID()');
       
   458           echo $json->encode($return);
       
   459           return;
       
   460         }
   451         
   461         
   452         $q = $db->sql_query('SELECT "x" FROM '.table_prefix.'page_group_members WHERE pg_id=' . $edit_id . ' AND page_id=\'' . $db->escape($page_id) . '\' AND namespace=\'' . $namespace . '\';');
   462         $q = $db->sql_query('SELECT "x" FROM '.table_prefix.'page_group_members WHERE pg_id=' . $edit_id . ' AND page_id=\'' . $db->escape($page_id) . '\' AND namespace=\'' . $namespace . '\';');
   453         if ( !$q )
   463         if ( !$q )
   454         {
   464         {
   455           $return = array('mode' => 'error', 'text' => $db->get_error());
   465           $return = array('mode' => 'error', 'text' => $db->get_error());
   477         
   487         
   478         echo $json->encode($return);
   488         echo $json->encode($return);
   479         return;
   489         return;
   480       }
   490       }
   481       
   491       
   482       if ( isset($_POST['action']['edit_save']) )
   492       if ( isset($_POST['action']['edit_save']) && isset($_POST['pg_name']) )
   483       {
   493       {
   484         $edit_id = $_POST['action']['edit'];
   494         $edit_id = $_POST['action']['edit'];
       
   495         $edit_id = intval($edit_id);
       
   496         if ( !empty($edit_id) )
       
   497         {
       
   498           // Update group name
       
   499           $new_name = $_POST['pg_name'];
       
   500           if ( empty($new_name) )
       
   501           {
       
   502             echo '<div class="error-box">Please enter a valid name for this group.</div>';
       
   503           }
       
   504           else
       
   505           {
       
   506             $q = $db->sql_query('SELECT pg_name FROM '.table_prefix.'page_groups WHERE pg_id=' . $edit_id . ';');
       
   507             if ( !$q )
       
   508               $db->_die();
       
   509             $row = $db->fetchrow();
       
   510             $db->free_result();
       
   511             if ( $new_name != $row['pg_name'] )
       
   512             {
       
   513               $new_name = $db->escape(trim($new_name));
       
   514               $q = $db->sql_query('UPDATE '.table_prefix.'page_groups SET pg_name=\'' . $new_name . '\' WHERE pg_id=' . $edit_id . ';');
       
   515               if ( !$q )
       
   516                 $db->_die();
       
   517               else
       
   518                 echo '<div class="info-box">The group name was updated successfully.</div>';
       
   519             }
       
   520             if ( $_POST['pg_type'] == PAGE_GRP_TAGGED )
       
   521             {
       
   522               $target = $_POST['pg_target'];
       
   523               $target = sanitize_tag($target);
       
   524               if ( empty($target) )
       
   525               {
       
   526                 echo '<div class="error-box">Please enter a valid tag.</div>';
       
   527               }
       
   528               else
       
   529               {
       
   530                 $target = $db->escape($target);
       
   531                 $q = $db->sql_query('UPDATE '.table_prefix.'page_groups SET pg_target=\'' . $target . '\' WHERE pg_id=' . $edit_id . ';');
       
   532                 if ( !$q )
       
   533                   $db->_die();
       
   534                 else
       
   535                   echo '<div class="info-box">The affecting tag was updated.</div>';
       
   536               }
       
   537             }
       
   538             else if ( $_POST['pg_type'] == PAGE_GRP_CATLINK )
       
   539             {
       
   540               $target = $_POST['pg_target'];
       
   541               if ( empty($target) )
       
   542               {
       
   543                 echo '<div class="error-box">No category ID specified on POST URI.</div>';
       
   544               }
       
   545               else
       
   546               {
       
   547                 $target = $db->escape($target);
       
   548                 $q = $db->sql_query('UPDATE '.table_prefix.'page_groups SET pg_target=\'' . $target . '\' WHERE pg_id=' . $edit_id . ';');
       
   549                 if ( !$q )
       
   550                   $db->_die();
       
   551                 else
       
   552                   echo '<div class="info-box">The affecting category was updated.</div>';
       
   553               }
       
   554             }
       
   555           }
       
   556         }
       
   557       }
       
   558       else if ( isset($_POST['action']['edit_save']) )
       
   559       {
       
   560         $edit_id = $_POST['action']['edit'];
       
   561         $edit_id = intval($edit_id);
   485       }
   562       }
   486       else
   563       else
   487       {
   564       {
   488         $edit_id = array_keys($_POST['action']['edit']);
   565         $edit_id = array_keys($_POST['action']['edit']);
   489         $edit_id = intval($edit_id[0]);
   566         $edit_id = intval($edit_id[0]);
   493       {
   570       {
   494         echo 'Hack attempt';
   571         echo 'Hack attempt';
   495         return;
   572         return;
   496       }
   573       }
   497       
   574       
   498       if ( isset($_POST['action']['edit_save']['do_rm']) )
   575       if ( isset($_POST['action']['edit_save']['do_rm']) && !isset($_POST['pg_name']) )
   499       {
   576       {
   500         $vals = array_keys($_POST['action']['edit_save']['rm']);
   577         $vals = array_keys($_POST['action']['edit_save']['rm']);
   501         $good = array();
   578         $good = array();
   502         foreach ( $vals as $id )
   579         foreach ( $vals as $id )
   503         {
   580         {
   504           if ( strval(intval($id)) == $id )
   581           if ( strval(intval($id)) == $id )
   505             $good[] = $id;
   582             $good[] = $id;
   506         }
   583         }
   507         $subquery = ( count($good) > 0 ) ? 'pg_member_id=' . implode(' OR pg_member_id=', $good) : "'foo'='foo'";
   584         $subquery = ( count($good) > 0 ) ? 'pg_member_id=' . implode(' OR pg_member_id=', $good) : "'foo'='bar'";
   508         $sql = 'DELETE FROM '.table_prefix."page_group_members WHERE ( $subquery ) AND pg_id=$edit_id;";
   585         if ( $subquery == "'foo'='bar'" )
   509         if ( !$db->sql_query($sql) )
   586         {
   510         {
   587           echo '<div class="warning-box">No pages were selected for deletion, and thus none were deleted.</div>';
   511           $db->_die();
   588         }
   512         }
   589         else
   513         echo '<div class="info-box">The requested page group members have been deleted.</div>';
   590         {
       
   591           $sql = 'DELETE FROM '.table_prefix."page_group_members WHERE ( $subquery ) AND pg_id=$edit_id;";
       
   592           if ( !$db->sql_query($sql) )
       
   593           {
       
   594             $db->_die();
       
   595           }
       
   596           echo '<div class="info-box">The requested page group members have been deleted.</div>';
       
   597         }
   514       }
   598       }
   515       
   599       
   516       // Fetch information about page group
   600       // Fetch information about page group
   517       $q = $db->sql_query('SELECT pg_name, pg_type, pg_target FROM '.table_prefix.'page_groups WHERE pg_id=' . $edit_id . ';');
   601       $q = $db->sql_query('SELECT pg_name, pg_type, pg_target FROM '.table_prefix.'page_groups WHERE pg_id=' . $edit_id . ';');
   518       if ( !$q )
   602       if ( !$q )
   527       $row = $db->fetchrow();
   611       $row = $db->fetchrow();
   528       $db->free_result();
   612       $db->free_result();
   529       
   613       
   530       echo '<form name="pg_edit_frm" action="'.makeUrl($paths->nslist['Special'].'Administration', 'module='.$paths->cpage['module']).'" method="post" onsubmit="if(!submitAuthorized) return false;" enctype="multipart/form-data">';
   614       echo '<form name="pg_edit_frm" action="'.makeUrl($paths->nslist['Special'].'Administration', 'module='.$paths->cpage['module']).'" method="post" onsubmit="if(!submitAuthorized) return false;" enctype="multipart/form-data">';
   531       echo '<input type="hidden" name="action[edit]" value="' . $edit_id . '" />';
   615       echo '<input type="hidden" name="action[edit]" value="' . $edit_id . '" />';
       
   616       echo '<input type="hidden" name="pg_type" value="' . $row['pg_type'] . '" />';
   532       echo '<div class="tblholder">
   617       echo '<div class="tblholder">
   533               <table border="0" cellspacing="1" cellpadding="4">
   618               <table border="0" cellspacing="1" cellpadding="4">
   534                 <tr>
   619                 <tr>
   535                   <th colspan="3">Editing page group: ' . htmlspecialchars($row['pg_name']) . '</th>
   620                   <th colspan="3">Editing page group: ' . htmlspecialchars($row['pg_name']) . '</th>
   536                 </tr>';
   621                 </tr>';
   551       // You can guess which one I dreaded.
   636       // You can guess which one I dreaded.
   552       
   637       
   553       switch ( $row['pg_type'] )
   638       switch ( $row['pg_type'] )
   554       {
   639       {
   555         case PAGE_GRP_NORMAL:
   640         case PAGE_GRP_NORMAL:
       
   641           
   556           // You have guessed correct.
   642           // You have guessed correct.
   557           // *Sits in chair for 10 minutes listening to the radio in an effort to put off writing the code you see below*
   643           // *Sits in chair for 10 minutes listening to the radio in an effort to put off writing the code you see below*
   558           
   644           
   559           echo '<tr><th colspan="3" class="subhead"><input type="submit" name="action[edit_save]" value="Save group name" /></th></tr>';
   645           echo '<tr><th colspan="3" class="subhead"><input type="submit" name="action[edit_save]" value="Save group name" /></th></tr>';
       
   646           echo '</table></div>';
       
   647           echo '</form>';
       
   648           echo '<form name="pg_static_rm_frm" action="'.makeUrl($paths->nslist['Special'].'Administration', 'module='.$paths->cpage['module']).'" method="post" enctype="multipart/form-data">';
       
   649           echo '<input type="hidden" name="action[edit]" value="' . $edit_id . '" />';
       
   650           echo '<div class="tblholder">
       
   651                   <table border="0" cellspacing="1" cellpadding="4">
       
   652                     <tr>
       
   653                       <th colspan="3">Remove pages from this group</th>
       
   654                     </tr>';
   560           
   655           
   561           $q = $db->sql_query('SELECT m.pg_member_id,m.page_id,m.namespace FROM '.table_prefix.'page_group_members AS m
   656           $q = $db->sql_query('SELECT m.pg_member_id,m.page_id,m.namespace FROM '.table_prefix.'page_group_members AS m
   562                                  LEFT JOIN '.table_prefix.'pages AS p
   657                                  LEFT JOIN '.table_prefix.'pages AS p
   563                                    ON ( p.urlname = m.page_id AND p.namespace = m.namespace )
   658                                    ON ( p.urlname = m.page_id AND p.namespace = m.namespace )
   564                                  WHERE m.pg_id=' . $edit_id . ';');
   659                                  WHERE m.pg_id=' . $edit_id . ';');
   687           
   782           
   688           $ajax_page_add = true;
   783           $ajax_page_add = true;
   689           
   784           
   690           break;
   785           break;
   691         case PAGE_GRP_TAGGED:
   786         case PAGE_GRP_TAGGED:
       
   787           echo '<tr>
       
   788                   <td class="row2">
       
   789                     Include pages with this tag:
       
   790                   </td>
       
   791                   <td class="row1">
       
   792                     <input type="text" name="pg_target" value="' . htmlspecialchars($row['pg_target']) . '" size="30" />
       
   793                   </td>
       
   794                 </tr>';
       
   795           break;
       
   796         case PAGE_GRP_CATLINK:
       
   797           
       
   798           // Build category list
       
   799           $q = $db->sql_query('SELECT name,urlname FROM '.table_prefix.'pages WHERE namespace=\'Category\';');
       
   800           if ( !$q )
       
   801             $db->_die();
       
   802           
       
   803           if ( $db->numrows() < 1 )
       
   804           {
       
   805             $catlist = 'There aren\'t any categories on this site.';
       
   806           }
       
   807           else
       
   808           {
       
   809             $catlist = '<select name="pg_target">';
       
   810             while ( $catrow = $db->fetchrow() )
       
   811             {
       
   812               $selected = ( $catrow['urlname'] == $row['pg_target'] ) ? ' selected="selected"' : '';
       
   813               $catlist .= '<option value="' . htmlspecialchars($catrow['urlname']) . '"' . $selected . '>' . htmlspecialchars($catrow['name']) . '</option>';
       
   814             }
       
   815             $catlist .= '</select>';
       
   816           }
       
   817           
       
   818           echo '<tr>
       
   819                   <td class="row2">
       
   820                     Include pages that are in this category:<br />
       
   821                     <small><b>Reminder:</b> Enano does not automatically place any access controls on the category. If you
       
   822                            don\'t want users to be able to freely add and remove pages from the category (assuming Wiki Mode is enabled
       
   823                            for the category) then you need to enable protection on the category using the button on the more options menu.
       
   824                            </small>
       
   825                   </td>
       
   826                   <td class="row1">
       
   827                     ' . $catlist . '
       
   828                   </td>
       
   829                 </tr>';
       
   830           
   692           break;
   831           break;
   693       }
   832       }
   694       
   833       
   695       if ( $ajax_page_add )
   834       if ( $ajax_page_add )
   696       {
   835       {