Location: PHPKode > projects > Write2Left > Base/Rebuild.php
<?php
/*
+------------------------------------------------------
| Write2Left
| (c) timdorr
| http://www.write2left.com
| hide@address.com
| See License.txt for license info
|------------------------------------------------------
| Script: Rebuild.php
| Description:
|   Rebuilds log files in case of weirdness
| Created Jul-22-2003
+------------------------------------------------------
*/

/* Class: Rebuild
 * Description:
 *   Driver for our rebuild-o-matic 3000™
 */
class Rebuild
{
	var $skin = "";
	var $menu = true;
	var $result = '';
	
	function run()
	{
		global $W2L, $userinfo, $output, $db;
		
		// Do skin related stuff
		require( "./Skin/Rebuild.php" );
		$this->skin = new Skin_Rebuild();
		$output->page_title = "Rebuild Log Files";
		
		$output->add( $this->skin->body_top( $userinfo->log_name ) );
		
		// Handle methods now to deal with submitted posts
		if ( array_key_exists( 'M', $W2L->input ) )
		{
			if( $W2L->input['M'] == 'dobuild' )
			{
				if( !array_key_exists( 'do_templates', $W2L->input ) )
					$W2L->input['do_templates'] = 0;
				if( !array_key_exists( 'do_index', $W2L->input ) )
					$W2L->input['do_index'] = 0;
				if( !array_key_exists( 'do_archive', $W2L->input ) )
					$W2L->input['do_archive'] = 0;
				if( !array_key_exists( 'do_item', $W2L->input ) )
					$W2L->input['do_item'] = 0;
					
					$this->build( $W2L->input['do_templates'], 
								  $W2L->input['do_index'],
								  $W2L->input['do_archive'],
								  $W2L->input['do_item'] );
			}
		}
		
		// Show whatever result we get, if any
		if( $this->result != "" )
			$output->add( "<div class=\"message\">\n" . $this->result . "\n</div><br />\n" );
		
		
		$output->add( $this->skin->rebuild_form() );
		
		$output->add( $this->skin->body_bottom() );
	}
	
	//================
	// Does the actual rebuilding
	//================
	function build( $do_tmp, $do_idx, $do_arc, $do_itm )
	{
		global $W2L, $db, $userinfo;
		
		// Get the Build Manager out and ready
		require( "./Build/BuildManager.php" );
		
		if( $do_tmp == 1 )
		{
			// Get and build our templates
			$id = $db->query( "SELECT * FROM w2l_templates 
								  		WHERE log_id={$userinfo->log_id}" );
			while( $row = $db->fetch_array( $id ) )
				$this->result .= $BM->build_page( $row['temp_id'] );
		}
			
		// Do indicies
		if( $do_idx == 1 )
			$this->result .= $BM->cache_data( "Index",   $userinfo->log_id ); 
			
		// Do archives
		if( $do_arc == 1 )	
			$this->result .= $BM->cache_data( "Archive", $userinfo->log_id );
		
		// Do items
		if( $do_itm == 1 )
			$this->result .= $BM->cache_data( "Item", $userinfo->log_id );
		
		if( $this->result == '' )
			$this->result = 'Rebuild successful!'; 
	}
	
}

$driver = new Rebuild();
?>
Return current item: Write2Left