';
+ echo '
';
+ echo '';
+
+ return;
+ }
+ }
+ else if ( isset($_POST['action']['del_confirm']) )
+ {
+ $delete_id = intval($_POST['delete_id']);
+ if ( empty($delete_id) )
+ {
+ echo 'Hack attempt';
+ return;
+ }
+ // Obtain group name
+ $q = $db->sql_query('SELECT pg_name FROM '.table_prefix.'page_groups WHERE pg_id=' . $delete_id . ';');
+ if ( !$q )
+ $db->_die();
+ if ( $db->numrows() < 1 )
+ {
+ echo 'Page group dun exist.';
+ return;
+ }
+ $row = $db->fetchrow();
+ $db->free_result();
+ $pg_name = $row['pg_name'];
+ unset($row);
+ // Delete the group
+ $q = $db->sql_query('DELETE FROM '.table_prefix.'page_groups WHERE pg_id=' . $delete_id . ';');
+ if ( !$q )
+ $db->_die();
+ $q = $db->sql_query('DELETE FROM '.table_prefix.'page_group_members WHERE pg_id=' . $delete_id . ';');
+ if ( !$q )
+ $db->_die();
+ echo "
The group ".'"'."$pg_name".'"'." has been deleted.
";
+ }
+ else if ( isset($_POST['action']['edit']) && !isset($_POST['action']['noop']) )
+ {
+ if ( isset($_POST['action']['edit_save']) )
+ {
+ }
+
+ if ( isset($_POST['action']['edit']['add_page']) && isset($_GET['src']) && $_GET['src'] == 'ajax' )
+ {
+ $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
+ $return = array('successful' => false);
+
+ //
+ // Add the specified page to the group
+ //
+
+ // Get ID of the group
+ $edit_id = intval($_POST['pg_id']);
+ if ( !$edit_id )
+ {
+ $return = array('mode' => 'error', 'text' => 'Hack attempt');
+ echo $json->encode($return);
+ return;
+ }
+
+ // Run some validation - check that page exists and that it's not already in the group
+ $page = $_POST['new_page'];
+ if ( empty($page) )
+ {
+ $return = array('mode' => 'error', 'text' => 'Please enter a page title.');
+ echo $json->encode($return);
+ return;
+ }
+
+ if ( !isPage($page) )
+ {
+ $return = array('mode' => 'error', 'text' => 'The page you are trying to add (' . htmlspecialchars($page) . ') does not exist.');
+ echo $json->encode($return);
+ return;
+ }
+
+ list($page_id, $namespace) = RenderMan::strToPageID($page);
+ $page_id = sanitize_page_id($page_id);
+
+ $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 . '\';');
+ if ( !$q )
+ {
+ $return = array('mode' => 'error', 'text' => $db->get_error());
+ echo $json->encode($return);
+ return;
+ }
+ if ( $db->numrows() > 0 )
+ {
+ $return = array('mode' => 'error', 'text' => 'The page you are trying to add is already in this group.');
+ echo $json->encode($return);
+ return;
+ }
+
+ $q = $db->sql_query('INSERT INTO '.table_prefix.'page_group_members(pg_id, page_id, namespace) VALUES(' . $edit_id . ', \'' . $db->escape($page_id) . '\', \'' . $namespace . '\');');
+ if ( !$q )
+ {
+ $return = array('mode' => 'error', 'text' => $db->get_error());
+ echo $json->encode($return);
+ return;
+ }
+
+ $title = "($namespace) " . get_page_title($paths->nslist[$namespace] . $page_id);
+
+ $return = array('mode' => 'info', 'text' => 'The page has been added to the specified group.', 'successful' => true, 'title' => $title, 'member_id' => $db->insert_id());
+
+ echo $json->encode($return);
+ return;
+ }
+
+ if ( isset($_POST['action']['edit_save']) )
+ {
+ $edit_id = $_POST['action']['edit'];
+ }
+ else
+ {
+ $edit_id = array_keys($_POST['action']['edit']);
+ $edit_id = intval($edit_id[0]);
+ }
+
+ if ( empty($edit_id) )
+ {
+ echo 'Hack attempt';
+ return;
+ }
+
+ if ( isset($_POST['action']['edit_save']['do_rm']) )
+ {
+ $vals = array_keys($_POST['action']['edit_save']['rm']);
+ $good = array();
+ foreach ( $vals as $id )
+ {
+ if ( strval(intval($id)) == $id )
+ $good[] = $id;
+ }
+ $subquery = 'pg_member_id=' . implode(' OR pg_member_id=', $good);
+ $sql = 'DELETE FROM '.table_prefix."page_group_members WHERE ( $subquery ) AND pg_id=$edit_id;";
+ if ( !$db->sql_query($sql) )
+ {
+ $db->_die();
+ }
+ echo '
The requested page group members have been deleted.
';
+ }
+
+ // Fetch information about page group
+ $q = $db->sql_query('SELECT pg_name, pg_type, pg_target FROM '.table_prefix.'page_groups WHERE pg_id=' . $edit_id . ';');
+ if ( !$q )
+ $db->_die();
+
+ if ( $db->numrows() < 1 )
+ {
+ echo 'Bad request - can\'t load page group from database.';
+ return;
+ }
+
+ $row = $db->fetchrow();
+ $db->free_result();
+
+ echo '
';
+
+ // This needs to be outside of the form.
+ echo '
';
+
+ return;
+ }
+ else if ( isset($_POST['action']['noop']) )
+ {
+ // Do nothing - skip to main form (noop is usually invoked by a cancel button in a form above)
+ }
+ else
+ {
+ echo '
Invalid format of $_POST[action].
';
+ }
+ }
+ // No action defined - show default menu
+
+ echo '
Manage page groups
';
+ echo '
Enano\'s page grouping system allows you to build sets of pages that can be controlled by a single ACL rule. This makes managing features such as a members-only section of your site a lot easier. If you don\'t use the ACL system, you probably don\'t need to use page groups.
';
+
+ $q = $db->sql_query('SELECT pg_id, pg_type, pg_name, pg_target FROM '.table_prefix.'page_groups;');
+ if ( !$q )
+ $db->_die();
+
+ echo '
';
+
+}
+
+?>