* @uses includes.php
* @uses $CFG
* @param int $page_ident  The identity key for the page.
**/
// Note, this is ../ insead of ../../../ because we're called by files in /_folio, and not from the folder that this
//	page is actually residing inside of.
require_once '../includes.php';
$url = url;
// Load variables
$page_ident = required_param('page_ident', PARAM_INT);
//	Get the record security and page information.
$page = folio_page_select($page_ident);
$permissions = folio_page_security_select($page_ident);
if (!$page) {
    error("Invalid page {$page_ident} passed to page_delete_post");
}
if (isloggedin() & folio_page_permission($page, $permissions, 'delete')) {
    // Permission to delete granted.
    // Turn all records with the same page_ident and newest=1 to newest = 0, effectively deleting the page.
    set_field('folio_page', 'newest', 0, 'page_ident', $page_ident, 'newest', 1);
} else {
    var_dump($page);
    var_dump($permissions);
    error('You do not have permission to delete this page');
}
global $redirect_url;
$username = run('users:id_to_name', $page->user_ident);
$redirect_url = url . $username . '/page/';
// Create 'delete' rss record.
rss_additem($page->user_ident, $username, $_SESSION['userid'], $_SESSION['name'], $_SESSION['username'], 'page', $page->page_ident, '', 'Deleted ' . $page->title, $_SESSION['username'] . ' deleted the page "' . $page->title . '"', $url . $username . '/page/', 'PUBLIC');
		div.innerHTML += "<li>Server response: " + o.responseText + "</li>";
		div.innerHTML += "<li>Argument object: Object ( [foo] => " + o.argument.foo +
						 " [bar] => " + o.argument.bar +" )</li>";
*/
require_once "../../../includes.php";
$comment = new StdClass();
$comment->item_ident = required_param('item_ident', 0, PARAM_INT);
$comment->item_type = folio_clean(required_param('item_type'));
$comment->item_title = folio_page_decodetitle(folio_clean(required_param('item_title')));
$comment->item_owner_ident = required_param('item_owner_ident', 0, PARAM_INT);
$comment->item_owner_name = required_param('item_owner_name');
$comment->item_owner_username = required_param('item_owner_username');
$comment->access = folio_clean(required_param('access'));
$comment->body = required_param('body');
$comment->posted = time();
$url = required_param('url');
if (isloggedin()) {
    $comment->creator_username = $_SESSION['username'];
    $comment->creator_name = $_SESSION['name'];
    $comment->creator_ident = $_SESSION['userid'];
} else {
    $comment->creator_username = '';
    $comment->creator_name = 'Anonymous';
    $comment->creator_ident = -1;
}
// Insert new record into db.
insert_record('folio_comment', $comment);
// Create RSS record
rss_additem($comment->item_owner_ident, $comment->item_owner_username, $comment->creator_ident, $comment->creator_name, $comment->creator_username, $comment->item_type . '_comment', $comment->item_ident, '', 'Comment by ' . $comment->creator_username . ' on ' . $comment->item_title, $comment->body, $url);
// Return wrapped up.
echo "<b><font color='#800517'>Comment posted. It will show next time you load the page.</font></b>";
// The security ident needs to be set by page_edit_security_post before this can run.
if (!isset($security_ident)) {
    error('Page_Edit_post.php must be called after page_edit_security_post so that the former knows the security information');
}
$page = new StdClass();
$page->title = folio_clean(required_param('page_title'));
$page->body = required_param('page_body');
$page->page_ident = required_param('page_ident', PARAM_INT);
$page->security_ident = $security_ident;
$page->parentpage_ident = required_param('parentpage_ident', PARAM_INT);
$page->newest = 1;
$page->created = time();
$page->user_ident = required_param('user_ident');
$username = required_param('username');
// If the user isn't logged in, then set to -1 (anonymous)
// Otherwise, set the last updater to their logged in information.
if (isloggedin()) {
    $page->creator_ident = $_SESSION['userid'];
} else {
    $page->creator_ident = -1;
}
// Modify old record by converting all records matching the conditions (folio, page, newest) to newest=false.
set_field('folio_page', 'newest', 0, 'newest', 1, 'page_ident', $page->page_ident);
//var_dump( $page );
// Insert new record into db.
$insert_id = insert_record('folio_page', $page, true, 'page_ident');
// Set redirect
$redirect_url = url . $username . '/page/' . folio_page_encodetitle(required_param('page_title'));
// Create RSS record
rss_additem($page->user_ident, $username, $page->creator_ident, $_SESSION['name'], $_SESSION['username'], 'page', $insert_id, '', $page->title, folio_page_makelinks($username, $page->body), $redirect_url, optional_param('folio_control_page_edit_security_custom', 'PUBLIC'));