';
} elseif ($do == "categories") { //if category
$action = $_GET['action'];
//if create new category
if ($action == "new") { //if new category
$data = $_POST;
if (empty($data['name'])) {
$proceed = "no";
$error_messages = '
A name is required for the category!
';
}
//execute SQL function if no errors
if ($proceed != "no") {
new_category($data,$_SESSION['username']);
unset($data);
//success message
$success .= '
The category has been successfully created.
';
}
} elseif($action == "deleteitems") {
$items = $_POST; //get vars
//unset post data move_cat so we can get a clean collection of #s
unset($items['move_cat']);
$move_cat = $_POST['move_cat'];
if (!$items) { //if no items, avoid mysql error by just redirecting
header("Location: preferences.php?do=categories");
}
foreach($items as $key=>$value) { //create list of ids to be deleted
$items_f = $items_f."'$value',";
}
$items_f = substr_replace($items_f,"",-1); //remove last comma in list for SQL
$res = general_query("DELETE FROM ".$databaseinfo['prefix']."categories WHERE id IN (".$items_f.")"); //delete all records where the id is in the list
//log the deletion
log_this('delete_categories','User '.$_SESSION['username'].' has deleted the following categories (ID(s)): '.$items_f.'');
//form sql for deletion of sub cats
$res_subdel = general_query("DELETE FROM ".$databaseinfo['prefix']."categories WHERE cat_parent IN (".$items_f.")"); //delete all records where the id is in the list
//move items to selected cateogry
$res_m = general_query('UPDATE '.$databaseinfo['prefix'].'articles SET article_cat="'.$move_cat.'" WHERE article_cat IN ('.$items_f.')');
header("Location: preferences.php?do=categories&delete_success=1");
}
$globalvars['page_name'] = "categories";
$globalvars['page_image'] = "preferences";
$data['cat_list'] = gen_categories('option','top');
$table_rows = gen_categories('row','');
$move_selected = gen_categories('option','');
if ($_GET['delete_success']) {
$success .= '
The template you selected is now the default template.
';
} else {
$message = '
There was an error switching the template.
';
}
unset($action);
}
if (!$action) {
//we're going to fetch all the available templates.
$tres = general_query('SELECT * FROM '.$databaseinfo['prefix'].'templates'); //execute tsql
while ($trow = mysql_fetch_assoc($tres)) { //get arrays
$row_bg = ($row_bg == $globalvars['altcolor'][2]) ? $globalvars['altcolor'][1] : $globalvars['altcolor'][2]; //current row bg
$trow['timestamp'] = date($globalvars['time_format'],$trow['timestamp']);
if ($trow['template_selected'] == TRUE) { //set the radio button to checked if it's currently selected
$trow['template_selected'] = 'checked="checked"';
}
if ($trow['template_desc'] == NULL) { //if no reason set, we need to set to N/A
$trow['template_desc'] = 'N/A';
}
$template_rows .= '
You must enter a title for this template before continuing.
';
}
if ($continue == TRUE) {
$globalvars['page_name'] = "templates";
$globalvars['page_image'] = "success";
//give $data post vars
$res = edit_template($data,$_SESSION['username']);
//get template id
$tid = $_POST['id'];
//after the edit, redisplay form with edited values
$tres = general_query('SELECT * FROM '.$databaseinfo['prefix'].'templates WHERE id='.$tid.'',1); //execute tsql
$content = template_form($tres);
} else {
$globalvars['page_name'] == 'templates';
$globalvars['page_image'] == 'error';
$content = template_form($data);
}
} elseif ($action == "delete") {
//get tid and delete from db
$tid = clean_data($_GET['tid']);
$dres = general_query('DELETE FROM '.$databaseinfo['prefix'].'templates WHERE id='.$tid.''); //execute tsql
//redirect to templates
header("Location: preferences.php?do=templates&delete_success=1");
}
} elseif ($do == "sef") { //search engine friendly urls page
$globalvars['page_name'] = 'search engine friendly urls';
$globalvars['page_image'] = "preferences";
//edited out by alecwh: .htaccess is not necessary in the /phpns/ directory..., so it's not necessary to check for one.
// if(is_file('.htaccess') ? $fileaccess = @file_get_contents(".htaccess") : $fileaccess = 'There is currently no .htaccess file, please make one!' );
$content = '
The suggested .htaccess file:
Place this \'.htaccess\' file wherever your news is being displayed on your website. This is usually the root of your website, \'/\'. You may also change the \'index.php\' reference to whatever file phpns displays news in.
The .htaccess file is not required for phpns to generate SEF URLs. You can activate using the $phpns[\'sef_override\'] pre-include variable to activate.
';
} elseif ($do == "ban") { //if ban page
$globalvars['page_name'] = "ban options";
$globalvars['page_image'] = "preferences";
if ($_GET['action'] == 'newp') { //if the action is new process
$data = $_POST; //assign post to $data
clean_data($data['reason']); //clean
//if ip is empty or in an incorrect form, display error
if (!$data['ip'] || !preg_match('/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $data['ip'])) {
$error_message = '
Please make sure the IP address is in correct form, or is not blank.
';
}
} elseif ($_GET['action'] == "delete") { //if we're deleting banned ip addresses
$items = $_POST; //get vars
foreach($items as $key=>$value) { //create list of ids to be deleted
$items_f = $items_f."'$value',";
}
$items_f = substr_replace($items_f,"",-1); //remove last comma in list for SQL
$res = general_query('DELETE FROM '.$databaseinfo['prefix'].'banlist WHERE id IN ('.$items_f.')'); //delete query
//success message
$success .= '
The selected ban(s) have been lifted.
';
//log the change
log_this('lift_ban','User '.$_SESSION['username'].' has lifted bans for the following ids: '.$items_f.'');
}
//fetch banned ips
$bres = general_query('SELECT * FROM '.$databaseinfo['prefix'].'banlist'); //fetch query
while ($brow = mysql_fetch_assoc($bres)) { //get arrays
$row_bg = ($row_bg == $globalvars['altcolor'][2]) ? $globalvars['altcolor'][1] : $globalvars['altcolor'][2]; //current row bg
$brow['timestamp'] = date($globalvars['time_format'],$brow['timestamp']);
if ($brow['reason'] == NULL) { //if no reason set, we need to set to N/A
$brow['reason'] = 'N/A';
}
$ip_rows .= '
';
} elseif ($do == "syslog") {
$globalvars['page_name'] = "system log";
$globalvars['page_image'] = "preferences";
//determine pagintation variables and sorting
$page = $_GET['page'];
if (!$page) {
$page = 1;
}
$items_per_page = 20;
$page_start = ($page*$items_per_page) - $items_per_page;
$next_page = $page + 1;
$prev_page = $page - 1;
//get sorting info and view
$sort = $_GET['sort'];
$v = $_GET['v'];
//END OF PAGINATION/SORTING
$content = log_form();
} elseif ($do == "backup") {
$globalvars['page_name'] = "database backup";
$globalvars['page_image'] = "preferences";
if ($_GET['action'] == "backup") {
//mysqldump -u alecwh --password=alecwh phpns2 > database.sql
exec('mysqldump -u '.$databaseinfo['user'].' --password='.$databaseinfo['password'].' '.$databaseinfo['dbname'].' > '.$databaseinfo['dbname'].'.sql');
//log the change
log_this('backup_db','User '.$_SESSION['username'].' has backed up the system database.');
//define filepaths and determine future gz file
$file = $databaseinfo['dbname'].'.sql'; //the current dump
// $file = file_get_contents($file);
/*
COMPRESSION FOR FILE, COMMENTED OUT UNTIL WE CAN SOLIDIFY THE PROCESS.
//encode and write to file process
$data = implode("", file($file));
$gzdata = gzuncompress($data, 9); //encrypt to .gz, most compression possible (9)
$fp = fopen($gz_file_to_produce, "w"); //open to write
fwrite($fp, $gzdata); //write
fclose($fp); //close
>
>
>
> [/color]
*/
//redirect to etc for actual header info
header("Location: etc.php?do=backup");
} elseif ($_GET['action'] == "restore") { //if we're restoring the data
//action for uploaded file, for db restore
$target_path = basename($_FILES['file']['name']);
if (move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
//the file has been uploaded, now we deal wtih manipulation.
//de-gz the file
//THIS WAS THE PROBLEM with .gz compression, the decompression was not widely supported. Maybe support in the future, but for now, we're not dealing with it.
//execute and dump data
exec('mysql -u '.$databaseinfo['user'].' --password='.$databaseinfo['password'].' '.$databaseinfo['dbname'].' < '.$target_path.'');
} else {
//log the change
log_this('backup_restore','User '.$_SESSION['username'].' has restored a previous phpns database.');
$error_message .= '
The system timestamp format has been changed to '".$_POST['sys_time_format']."'
";
//log the change
log_this('system_timestamp','User '.$_SESSION['username'].' has modified the default system timestamp format to "'.$_POST['sys_time_format'].'"');
}
$sys_time_format = load_config('sys_time_format');
$content = '
system timestamp format
'.$message.'
phpns uses the date(); function for formatting the system time. You can find a manual on the function at the php website.
';
//log the change
log_this('global_message','User '.$_SESSION['username'].' has edited the default global message');
}
$global_message = load_config('global_message');
$content = $error_message.'