// ChangeCreatedonDate -- Works with all version of modx
// Created By: Ralph Dahlgren
// Last Updated: 2005-09-14
// Changes the createdon and editedon dates and author settings of a document
$header = '
<html>
<head>
<title>MODx</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="media/style/MODx/style.css?" />
<script type="text/javascript" language="JavaScript" src="media/script/cb2.js"></script>
</head>
<body>
<br />
<br />
<br />
<div class="sectionHeader"><img src="media/images/misc/dot.gif" alt="." /> Results</div><div class="sectionBody">
';
$footer = '
</div>
</body>
</html>
';
if( isset($_POST['submit']) && is_numeric($_POST['docid']) && isset($_POST['newdate']) ){
$tbl = $modx->dbConfig['dbase'].".".$modx->dbConfig['table_prefix'];
$sql = "UPDATE ".$tbl."site_content SET ";
if($_POST['modCreatedon']) $sql .= "createdon=".strtotime($_POST['newdate']).", ";
if($_POST['modEditedon']) $sql .= "editedon=".strtotime($_POST['newdate'])." ";
$sql .= "WHERE id=".$_POST['docid'].";";
if(!$modx->dbQuery($sql)){
$output = "".$header."Update failed... Check your document ID and Date/Time format and try again...".$footer."";
} else {
$output = "".$header."Document Date/Time/Author were successful updated...".$footer."";
}
} else {
$output = '
<html>
<head>
<title>MODx</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="media/style/MODx/style.css?" />
<script type="text/javascript" language="JavaScript" src="media/script/cb2.js"></script>
</head>
<body>
<br />
<br />
<br />
<div class="sectionHeader"><img src="media/images/misc/dot.gif" alt="." /> Update Document Info</div><div class="sectionBody">
<p>This form allows you to change the createdon and editedon dates of a specific document based on its document ID. The documents author reference will automatically be changed to that of the user submitting this information.</p>
<form name="modCreatedon" id="modCreatedon" method="post" action="">
<p><label>ID of document to be modified:</label>
<input type="text" name="docid" id="docid" value="" />
(ex: 123 - Must be numeric and must exist)</p>
<p><label>New createdon/editedon date:</label>
<input type="text" name="newdate" id="newdate" value="" />
(See examples below)</p>
<p><label>Change createdon date:</label>
<input type="checkbox" name="modCreatedon" id="modCreatedon" checked="checked" value="true" /></p>
<p><label>Change editedon date:</label>
<input type="checkbox" name="modEditedon" id="modEditedon" checked="checked" value="true" /></p>
<p>Date Examples:</p>
<ul>
<li>19 Dec 1994 9:20pm</li>
<li>December 19th, 1994</li>
<li>12/19/1994 21:20:00 (Hyphens cannot be used with this format)</li>
<li>19941219 2120 </li>
<li>1994/12/19 or 1994-12-19</li>
<li>now, yesterday, Monday, or last Friday</li>
<li>+2 days or -1 week [minute(s),hour(s),day(s),month(s),year(s) from the current time]</li>
</ul>
<p>Time values are optional and will default to 00:00:00 if ommitted.</p>
<p>Some Date/Time formats cannot contain commas or they will produce a NULL timestamp value.</p>
<p>Visit <a href="http://www.gnu.org/software/tar/manual/html_chapter/tar_7.html" target="_blank"> http://www.gnu.org/software/tar/manual/html_chapter/tar_7.html</a> for more information about formatting.</p>
<input type="submit" name="submit" id="submit" value="Submit" />
<input type="reset" name="reset" id="reset" value="Reset" />
</form>
</div>
</body>
</html>
';
}
echo $output;
Well the benefit to me is that I can change the creation date of news items so they are listed in the order I wish them to be. For example, historical news items I wanted to be shown as created on those dates.
Hope somebody can help me out in understanding the benefit.
