<?php
/*
+------------------------------------------------------
| neocms 1.0
| (c) 2002 timdorr
| http://www.neowin.net
| hide@address.com
| See License.txt for license info
|------------------------------------------------------
| Script: Weblogs.php
| Description:
| The weblog manager
| Created Jul-01-2003
+------------------------------------------------------
*/
/* Class: Weblogs
* Description:
* Driver for our weblog manager page
*/
class Weblogs
{
var $skin = "";
var $menu = true;
var $error = 0;
function run()
{
global $W2L, $userinfo, $output, $db, $func;
// Do skin related stuff
require( "./Skin/Weblogs.php" );
$this->skin = new Skin_Weblogs();
$output->page_title = "Weblog Manager";
$output->loc_add( "Weblog Manager" );
$output->add( $this->skin->body_top() );
// Handle sub methods
if( array_key_exists( 'M', $W2L->input ) )
{
if( $W2L->input['M'] == 'Add' )
$this->error = $this->add_log();
if( $W2L->input['M'] == 'Delete' )
$this->del_log( $W2L->input['log_id'] );
if( $W2L->input['M'] == 'DoDelete' )
$this->do_del_log( $W2L->input['log_id'] );
}
// Print the list of logss
$id = $func->get_logs_sql_id();
$output->add( $this->skin->log_list_head() );
while( $log = $db->fetch_array( $id ) )
{
$output->add( $this->skin->log_list_item( $log['log_id'], $log['name'] ) );
}
$output->add( $this->skin->log_list_foot() );
// Handle form errors for the add log form
if( $this->error != 0 )
{
if( $this->error == 1 )
$output->add( $this->skin->error( "All fields are required" ) );
// If we're coming back after an error, refill the form
$W2L->input['name'] = array_key_exists( 'name', $W2L->input ) ? $W2L->input['name'] : '';
$W2L->input['path'] = array_key_exists( 'path', $W2L->input ) ? $W2L->input['path'] : '';
$W2L->input['cache_path'] = array_key_exists( 'cache_path', $W2L->input ) ? $W2L->input['cache_path'] : '';
$W2L->input['url'] = array_key_exists( 'url', $W2L->input ) ? $W2L->input['url'] : '';
}
else
{
$W2L->input['name'] = '';
$W2L->input['path'] = '';
$W2L->input['cache_path'] = '';
$W2L->input['url'] = '';
}
$output->add( $this->skin->new_log_form( $W2L->input['name'],
$W2L->input['path'],
$W2L->input['cache_path'],
$W2L->input['url'] ) );
$output->add( $this->skin->body_bottom() );
}
//================
// Adds a log to the database
//================
function add_log()
{
global $W2L, $userinfo, $db, $output;
// Let's play Match the Password!
if( $W2L->input['name'] == "" ||
$W2L->input['path'] == "" ||
$W2L->input['cache_path'] == "" ||
$W2L->input['url'] == "" )
{
return 1;
}
$W2L->input['path'] = str_replace( "\", '\\\\', $W2L->input['path'] );
$W2L->input['cache_path'] = str_replace( "\", '\\\\', $W2L->input['cache_path'] );
$W2L->input['url'] = str_replace( "\", '\\\\', $W2L->input['url'] );
// Store the new user
$db->query( "INSERT INTO w2l_logs VALUES
( NULL,
'{$W2L->input['name']}',
'{$W2L->input['path']}',
'{$W2L->input['cache_path']}',
'{$W2L->input['url']}',
{$W2L->input['timezone']},
{$userinfo->id},
'','',0,7,'F j, Y, g:i a',0,'0','0','0','0','0','','','1' )" );
$new_log_id = $db->insert_id();
$id = $db->query( "SELECT * FROM w2l_users" );
while( $user = $db->fetch_array( $id ) )
{
$db->query( "INSERT INTO w2l_editors
( `user_id`, `log_id` )
VALUES
( $user[user_id], $new_log_id )" );
}
$db->query( "UPDATE w2l_editors SET can_access='1',
can_post='1',
can_edit='1',
can_config='1',
can_upload='1',
can_template='1',
can_notify='1',
can_mail='1',
can_moderate='1',
can_editors='1'
WHERE user_id = {$userinfo->id}
AND log_id = $new_log_id" );
$output->add( '<div class="message">Weblog added</div><br />' );
}
//================
// Prompts to delete a log from the database
//================
function del_log( $log_id )
{
global $db, $output;
$log = $db->query_fetch( "SELECT name FROM w2l_logs WHERE log_id = $log_id" );
$output->add( $this->skin->del_confirm( $log['name'], $log_id ) );
}
//================
// Deletes a log from the database
//================
function do_del_log( $log_id )
{
global $db;
$db->query( "DELETE FROM w2l_logs WHERE log_id = $log_id" );
$db->query( "DELETE FROM w2l_posts WHERE log_id = $log_id" );
$db->query( "DELETE FROM w2l_comments WHERE log_id = $log_id" );
$db->query( "DELETE FROM w2l_categories WHERE log_id = $log_id" );
$db->query( "DELETE FROM w2l_templates WHERE log_id = $log_id" );
$db->query( "DELETE FROM w2l_editors WHERE log_id = $log_id" );
}
}
$driver = new Weblogs();
?>