%%policy-backup-admin-html%%

%%preprocess%%
$this->backedup= "Backed up policies:";
$this->policydir= $GLOBALS['beryliumroot']."/code/policies".$folder->name;
if ($folder->name!="/") $this->policydir .= "/";

$this->query= "SELECT obj.* FROM policy AS obj WHERE siteid='$site->id' AND status='posted' AND folderid='$folder->id'";
$this->policyarray= $this->selectObject($this->query);

foreach($this->policyarray AS $key=>$mypolicy) {
	$filepath= "$this->policydir$mypolicy[name]";
	// SECURITY make sure folder exists first...
	$fileout= "%%$mypolicy[name]%%
$site->name : $folder->name (policy #$mypolicy[id])
$mypolicy[updated]

%%prequery%%
$mypolicy[prequery]

%%addons%%
$mypolicy[addons]

%%end of policy%%
";

	$this->backedup .= "<br>$mypolicy[name]";
	
	// if file exists, overwrite it
	// SECURITY we should backup contexts before overwriting them.
	$fp= @fopen($filepath, "w");
	if (@fwrite($fp,$fileout)) {
		berror("updatePolicy(): wrote file successfully.",1);
		$this->backedup .= " written!";
	        fclose($fp);
		}
	else {
		berror("updatePolicy(): unable to save policy file to disk. Check permissions on the berylium/code/policies folder.",1);
		$this->backedup .= " <b>Not written!</b>";
		}	
	}





%%header%%



%%css%%



%%template%%
This should back up all the policies found with $this->query to ($this->policydir).
<hr>
$this->backedup


%%listrow%%
 



%%nullobject%%
This should back up all the policies found with $this->query to ($this->policydir), except it didn't find any policies here in folder: $folder->name.
<hr>
$this->backedup 



%%footer%%



%%postprocess%%



%%end of context%%
