I’m trying to make un-published articles viewable to web-users by making a script with takes the page id (of the article) passes it to the script, changes the published state directly by using $modx->db->update command, open it in a pop up window using javascript and then resetting the published state once it’s ran the javascript popup.
This all works but what is not working is when i use
$modx->sendRedirect($modx->makeUrl($manager_page_id, ’’, $start_url));
To refresh the article manager page without the article_preview params in the url.
When I turn on the redirect command it doesn’t execute the echo $preview_page_url.
Any thoughts?
Cheers
<?php
function preview_page($preview_id, $pub_preview_state)
{
global $modx;
global $site_url;
global $table_prefix;
$id = isset($id) ? intval($id) : $_REQUEST[id];
$manager_page_id = $id;
$start_string = isset($_REQUEST[start]) ? intval($_REQUEST[start]) : 0;
$start_url = "&start=" . $start_string;
echo "<br>OPEN NEW WINDOW WITH ID::" . $preview_id;
echo ":: AND PUBSTATE::" . $pub_preview_state;
echo "<BR>";
$content_table = $table_prefix."site_content";
$fields = array('published' => 1);
$modx->db->update($fields, $content_table, 'id="'.$preview_id.'" ');
$javacall = "javascript:popUp('index.php?id=".$preview_id."');";
$returl = "<script>".$javacall."</script>";
$fields = array('published' => 0);
$modx->db->update($fields, $content_table, 'id="'.$preview_id.'" ');
echo $returl;
$modx->sendRedirect($modx->makeUrl($manager_page_id, '', $start_url));
}
?>