Location: PHPKode > projects > PodAdmin - Web-based podcast management > podadmin-0.5.1/act_config.php
<?php

// validation here.  Need to add some more.
$errors = array();

if ( $_POST['host'] == '' ) {
	array_push($errors,"Database host cannot be blank.");
	}
if ( $_POST['database_name'] == '' ) {
	array_push($errors,"Database name cannot be blank.");
	}
if ( $_POST['username'] == '' ) {
	array_push($errors,"Database username cannot be blank.");
	}
if ( $_POST['password'] == '' ) {
	array_push($errors,"Database password cannot be blank.");
	}
if ( $_POST['datadir'] == '' ) {
	array_push($errors,"Data Directory cannot be blank.");
	}
if ( $_POST['dataurl'] == '' ) {
	array_push($errors,"Data Directory URL cannot be blank.");
	}
if ( $_POST['rssoutfile'] == '' ) {
	array_push($errors,"RSS Subscription file cannot be blank.");
	}
if (! is_numeric($_POST['maxitems']) or $_POST['maxitems'] < 1 ) {
	array_push($errors,"Max items must be a number and be greater than zero.");
	}

// if any errors, display the form.
if ($errors) {
	include('dsp_config.php');
	}
else {
	// escape any special characters 
	$fields = array('title', 'link', 'webmaster', 'language', 'copyright');
	foreach ($fields as $field) {
		$_POST[$field] = htmlentities(htmlentities($_POST[$field]));
		}
		
	// copy form data back into the config structure
	$vsf->config->channel->title = $_POST['title'];
	$vsf->config->channel->link = $_POST['link'];
	$vsf->config->channel->webmaster = $_POST['webmaster'];
	$vsf->config->channel->language = $_POST['language'];
	$vsf->config->channel->copyright = $_POST['copyright'];
	$vsf->config->channel->description = $_POST['description'];
	
	$vsf->config->database->host = $_POST['host'];
	$vsf->config->database->database_name = $_POST['database_name'];
	$vsf->config->database->username = $_POST['username'];
	$vsf->config->database->password = $_POST['password'];
	
	$vsf->config->misc->datadir = $_POST['datadir'];
	$vsf->config->misc->dataurl = $_POST['dataurl'];
	$vsf->config->misc->rssoutfile = $_POST['rssoutfile'];
	$vsf->config->misc->rssoutfile['maxitems'] = $_POST['maxitems'];

	if ( $_POST['showDBsetupMenuItem'] ) {
		$vsf->config->misc->showDBsetupMenuItem = 'Yes';
		}
	else {
		$vsf->config->misc->showDBsetupMenuItem = 'No';
		}

	// if the iTunes checkbox was clicked, use the new itunes values
	if ( $_POST['itunes_checkbox'] ) {
		$vsf->config->itunes->enable = 'Yes';
		$vsf->config->itunes->author = $_POST['author'];
		$vsf->config->itunes->keywords = $_POST['keywords'];
		$vsf->config->itunes->subtitle = $_POST['subtitle'];
		$vsf->config->itunes->owner_name = $_POST['owner_name'];
		$vsf->config->itunes->owner_email = $_POST['owner_email'];
		$vsf->config->itunes->image = $_POST['image'];
		
		$vsf->config->itunes->categories = '';
		if ($_POST['itunes_categories']){
			foreach ($_POST['itunes_categories'] as $cat) {
				#print  "$cat<br>\n";
				if (method_exists($vsf->config->itunes->categories,'addChild')) {
					$vsf->config->itunes->categories->addChild("category",htmlentities($cat));
					}
				else {
					//$vsf->config->itunes->categories = "need custom method";
					//dieWithError("Need PHP 5.1.3 or newer");
					addCategory($cat);
					}
				}
			#print_r($vsf->config);
			}  // close foreach
		}  // close if itunes_categories
	else {
		$vsf->config->itunes->enable = 'No';
		}
	
	
	// backup our old file
	@copy($vsf->configfile,"{$vsf->configfile}.bak");
	file_put_contents($vsf->configfile,$vsf->config->asXML());
	
	print "<p style='color: green; font-weight: bold;'>Configuration Updated.</p>";

	// and regenerate the rss file, if the database is setup correctly
	$vsf->connect() or dieWithError("Error connecting to database: " . $vsf->mysql_error);
	$query = "SELECT * FROM episodes LIMIT 1";
    if ( ! mysql_query($query) ) {
		 print "<p style='color: red;'>Warning: database table(s) do not exist yet. 'Use DB Table Setup' menu item to " .
	 	"create tables.  Enable this menu item in the 'Database' section of the config screen if it's been turned off.</p>\n";
		}
	else {
		include('act_genrssfile.php');
		print "<p style='color: green; font-weight: bold;'>Configuration Updated.  RSS file regenerated.</p>";
		}
	
	
	// clear the form before we redisplay
	unset($_POST);
	include('dsp_config.php');
	}
	
// for php less than version 5.1.3, which is when the addChild method was added
function addCategory($newcat) {
	global $vsf;
	// first, convert the SimpleXML object to DOM
	$dom = new DOMDocument;
	$domsxe = dom_import_simplexml($vsf->config);
	$domsxe = $dom->importNode($domsxe,true);
	$domsxe = $dom->appendChild($domsxe);
	
	$tmpcat = $dom->createElement("category");
	
	$dom->itunes->categories->appendChild($tmpcat);
	// then convert back to simpleXML
	$vsf->config = simplexml_import_dom($dom);
	
	}

?>
Return current item: PodAdmin - Web-based podcast management