Location: PHPKode > projects > TikiWikiLite > tikiwikilite/tiki-setup.php
<?php

// $Header: /cvsroot/twlite/lite/tiki-setup.php,v 1.3 2004/08/16 15:54:23 damosoft Exp $


// Copyright (c) 2002-2004, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.


/*!
    \static
*/

//this script may only be included - so its better to die if called directly.
if (strpos($_SERVER["SCRIPT_NAME"],"tiki-setup.php")!=FALSE) {
	header("location: index.php");
}

// include_once("lib/init/setup_inc.php");
include_once("lib/init/initlib.php");

class TikiSetup extends TikiInit {

	function check($tikidomain='') {
		static $checked;
		if ($checked) {
			return;
		}

		$checked = true;

		$errors = '';
        
		if (strpos($_SERVER["SERVER_SOFTWARE"],"IIS")==TRUE){
			$docroot = dirname($_SERVER['PATH_TRANSLATED']);
		} else {
			$docroot = getcwd();
		}

		if (ini_get('session.save_handler') == 'files') {
			$save_path = ini_get('session.save_path');
			$open_basedir=ini_get('open_basedir');
			if (empty($open_basedir)) {
				if (!is_dir($save_path)) {
					$errors .= "The directory '$save_path' does not exist or PHP is not allowed to access it (check open_basedir entry in php.ini).\n";
				} else if (!is_writeable($save_path)) {
					$errors .= "The directory '$save_path' is not writeable.\n";
				}
			}

			if ($errors) {
				$save_path = TikiSetup::tempdir();
				if (is_dir($save_path) && is_writeable($save_path)) {
					ini_set('session.save_path', $save_path);
					$errors = '';
				}
			}
		}

		$wwwuser = '';
		$wwwgroup = '';

		if (TikiSetup::isWindows()) {
			$wwwuser = 'SYSTEM';
			$wwwgroup = 'SYSTEM';
		}
		
		if (function_exists('posix_getuid')) {
			$user = @posix_getpwuid(@posix_getuid());
			$group = @posix_getpwuid(@posix_getgid());
			$wwwuser = $user ? $user['name'] : false;
			$wwwgroup = $group ? $group['name'] : false;
		}

		if (!$wwwuser) {
			$wwwuser = 'nobody (or the user account the web server is running under)';
		}

		if (!$wwwgroup) {
			$wwwgroup = 'nobody (or the group account the web server is running under)';
		}

		static $dirs = array('backups', 'dump', 'img/wiki', 'img/wiki_up', 'modules/cache','temp', 'templates_c' );

		foreach ($dirs as $dir) {
			if (!is_dir("$docroot/$dir/$tikidomain")) {
				$errors .= "The directory '$docroot/$dir/$tikidomain' does not exist.\n";
			} else if (!is_writeable("$docroot/$dir/$tikidomain")) {
				$errors .= "The directory '$docroot/$dir/$tikidomain' is not writeable by $wwwuser.\n";
			}
		}

		if ($errors) {
			$PHP_CONFIG_FILE_PATH = PHP_CONFIG_FILE_PATH;

			ob_start();
			phpinfo (INFO_MODULES);
			$httpd_conf = 'httpd.conf';

			if (preg_match('/Server Root<\/b><\/td><td\s+align="left">([^<]*)</', ob_get_contents(), $m)) {
				$httpd_conf = $m[1] . '/' . $httpd_conf;
			}

			ob_end_clean();

			print "<html><body><h2><font color='red'>TikiWikiLite is not properly set up:</font></h1><pre>$errors";
			if ($tikidomain) {
				$install_link = '?multi='.urlencode($tikidomain);
			}
			if (!TikiSetup::isWindows()) {
				print "You may either chmod the directories above manually to 777, or run one of the sets of commands below.
<b><a href='tiki-install.php$install_link'>Proceed to the Tiki installer</a></b> after you run the commands below.

If you cannot become root, and are NOT part of the group $wwwgroup:
    \$ bash
    \$ cd $docroot
    \$ chmod +x setup.sh
    \$ ./setup.sh yourlogin yourgroup 02777
    Tip: You can find your group using the command 'id'.

If you cannot become root, but are a member of the group $wwwgroup:
    \$ bash
    \$ cd $docroot
    \$ chmod +x setup.sh
    \$ ./setup.sh mylogin $wwwgroup</i>

If you can become root:
    \$ bash
    \$ cd $docroot
    \$ chmod +x setup.sh
    \$ su -c './setup.sh $wwwuser'

If you have problems accessing a directory, check the open_basedir entry in
$PHP_CONFIG_FILE_PATH/php.ini or $httpd_conf.

Once you have executed these commands, this message will disappear!

Note: If you cannot become root, you will not be able to delete certain
files created by apache, and will need to ask your system administrator
to delete them for you if needed.

<a href='http://tikiwikilite.tikiforge.org/InstallTikiLite' target='_blank'>Consult the tikiwikilite installation guide</a> if you need more help.

<b><a href='tiki-install.php'>Proceed to the Tiki installer</a></b> if you've completed the steps above.
</pre></body></html>";
			}

			exit;
		}
	}
}	

TikiSetup::prependIncludePath('lib');
TikiSetup::prependIncludePath('lib/pear');

$tmpDir = TikiInit::tempdir();

class timer {
	function parseMicro($micro) {
		list($micro, $sec) = explode(' ', microtime());

		return $sec + $micro;
	}

	function start($timer = 'default') {
		$this->timer[$timer] = $this->parseMicro(microtime());
	}

	function stop($timer = 'default') {
		return $this->current($timer);
	}

	function elapsed($timer = 'default') {
		return $this->parseMicro(microtime()) - $this->timer[$timer];
	}
}

$tiki_timer = new timer();
$tiki_timer->start();

// for PHP<4.2.0
if (!function_exists('array_fill')) {
	require_once('lib/compat/array_fill.func.php');
}

//num queries has to be global
global $num_queries;
$num_queries=0;

include_once ("tiki-setup_base.php");
TikiSetup::check($tikidomain);

if ( $user ) {
	$tikilib->load_user_cache($user, 'all');
}

//check to see if admin has closed the site
$site_closed = $tikilib->get_preference('site_closed','n');
if ($site_closed == 'y' and $tiki_p_access_closed_site != 'y' and !isset($bypass_siteclose_check)) {
    $site_closed_msg = $tikilib->get_preference('site_closed_msg','Site is closed for maintainance; please come back later.');
    $url = 'tiki-error_simple.php?error=' . urlencode("$site_closed_msg");
    header('location: ' . $url);
    exit;
}

//check to see if max server load threshold is enabled
$use_load_threshold = $tikilib->get_preference('use_load_threshold','n');
// get average server load in the last minute
if ($load = @file('/proc/loadavg')) {
    list($server_load) = explode(' ', $load[0]);
    $smarty->assign('server_load',$server_load);
    if ($use_load_threshold == 'y' and $tiki_p_access_closed_site != 'y' and !isset($bypass_siteclose_check)) {
        $load_threshold = $tikilib->get_preference('load_threshold',3);
        if ($server_load > $load_threshold) {
            $site_busy_msg = $tikilib->get_preference('site_busy_msg','Server is currently too busy; please come back later.');
            $url = 'tiki-error_simple.php?error=' . urlencode($site_busy_msg);
            header('location: ' . $url);
            exit;
        }
    }
}


$appname = "tikiwikilite";

if (!isset($_SESSION["appname"])) {
    //session_register("appname");
    $_SESSION["appname"] = $appname;
}

$smarty->assign("appname", $appname);


if (isset($_REQUEST["PHPSESSID"])) {
    $tikilib->update_session($_REQUEST["PHPSESSID"]);
} elseif (function_exists("session_id")) {
    $tikilib->update_session(session_id());
}

if (file_exists('lib/bablotron.php')) {
	$lib_spellcheck = 'y';
	$wiki_spellcheck = 'n';
	$cms_spellcheck = 'n';
	$blog_spellcheck = 'n';
	$smarty->assign('lib_spellcheck', $lib_spellcheck);
	$smarty->assign('wiki_spellcheck', $wiki_spellcheck);
	$smarty->assign('cms_spellcheck', $cms_spellcheck);
	$smarty->assign('blog_spellcheck', $blog_spellcheck);
}

if (isset($_REQUEST['page'])) { $_REQUEST['page'] = strip_tags($_REQUEST['page']); }

$area = 'tiki';
$system_os = $tikilib->get_preference('system_os', TikiSetup::os());
$smarty->assign('system_os', $system_os);

$error_reporting_level = (int)($tikilib->get_preference('error_reporting_level', E_ALL));
if ($error_reporting_level == 1)
	$error_reporting_level = ($tiki_p_admin == "y") ? E_ALL: 0;
error_reporting($error_reporting_level);

$rememberme = $tikilib->get_preference('rememberme', 'disabled');
$smarty->assign('rememberme', $rememberme);
$remembertime = $tikilib->get_preference('remembertime', 7200);
$smarty->assign('remembertime', $remembertime);

if ($tikilib->get_preference("rssfeed_css","y") <> "y") {
    $smarty->assign("rssfeed_cssparam", "");
}

// Other preferences
$popupLinks = $tikilib->get_preference("popupLinks", 'n');
$anonCanEdit = $tikilib->get_preference("anonCanEdit", 'n');
$modallgroups = $tikilib->get_preference("modallgroups", 'y');
$modseparateanon = $tikilib->get_preference("modseparateanon", 'n');
$change_language = $tikilib->get_preference("change_language", 'y');
$change_theme = $tikilib->get_preference("change_theme", 'y');
//$tikiIndex = $tikilib->get_preference("tikiIndex", 'tiki-index.php');
$cachepages = $tikilib->get_preference("cachepages", 'y');
$cacheimages = $tikilib->get_preference("cacheimages", 'y');
$allowRegister = $tikilib->get_preference("allowRegister", 'n');
$eponymousGroups = $tikilib->get_preference("eponymousGroups", 'n');
$useRegisterPasscode = $tikilib->get_preference("useRegisterPasscode", 'n');
$registerPasscode = $tikilib->get_preference("registerPasscode", '');
$useUrlIndex = $tikilib->get_preference("useUrlIndex", 'n');
$urlIndex = $tikilib->get_preference("urlIndex", '');
$use_proxy = $tikilib->get_preference("use_proxy", 'n');
$proxy_host = $tikilib->get_preference("proxy_host", '');
$proxy_port = $tikilib->get_preference("proxy_port", '');
$session_db = $tikilib->get_preference("session_db", 'n');
$session_lifetime = $tikilib->get_preference("session_lifetime", 0);
$wikiHomePage = $tikilib->get_preference("wikiHomePage", 'Welcome');
$smarty->assign('wikiHomePage', $wikiHomePage);

$wiki_page_regex = $tikilib->get_preference('wiki_page_regex', 'strict');
$smarty->assign('wiki_page_regex', $wiki_page_regex);

// Wiki dump tarball doesn't exist by default
$wiki_dump_exists = 'n';
$dump_path = 'dump';
if ($tikidomain) {
	$dump_path.= '/$tikidomain';
}
if (file_exists($dump_path.'/new.tar')){
	$wiki_dump_exists = 'y';
};
$smarty->assign('wiki_dump_exists', $wiki_dump_exists);

// Please DO NOT modify any of the brackets in the regex(s).
// It may seem redundent but, really, they are ALL REQUIRED.
if ($wiki_page_regex == 'strict') {
    $page_regex = '([A-Za-z0-9_])([\.: A-Za-z0-9_\-])*([A-Za-z0-9_])';
} elseif ($wiki_page_regex == 'full') {
    $page_regex = '([A-Za-z0-9_]|[\x80-\xFF])([\.: A-Za-z0-9_\-]|[\x80-\xFF])*([A-Za-z0-9_]|[\x80-\xFF])';
} else {
    // This is just evil.  The middle section means "anything, as long
    // as it's not a | and isn't followed by ))".  -rlpowell
    $page_regex = '([^|\(\)])([^|](?!\)\)))*?([^|\(\)])';
}

$validateUsers = $tikilib->get_preference("validateUsers", 'n');
$forgotPass = $tikilib->get_preference("forgotPass", 'n');
$title = $tikilib->get_preference("title", "");
$maxRecords = $tikilib->get_preference("maxRecords", 10);
$maxArticles = $tikilib->get_preference("maxArticles", 10);

$smarty->assign('useUrlIndex', $useUrlIndex);
$smarty->assign('urlIndex', $urlIndex);
$smarty->assign('use_proxy', $use_proxy);
$smarty->assign('proxy_host', $proxy_host);
$smarty->assign('proxy_port', $proxy_port);
$smarty->assign('registerPasscode', $registerPasscode);
$smarty->assign('useRegisterPasscode', $useRegisterPasscode);

$smarty->assign('popupLinks', $popupLinks);
$smarty->assign('modallgroups', $modallgroups);
$smarty->assign('modseparateanon', $modseparateanon);
$smarty->assign('change_theme', $change_theme);
$smarty->assign('change_language', $change_language);
$smarty->assign('anonCanEdit', $anonCanEdit);
$smarty->assign('allowRegister', $allowRegister);
$smarty->assign('eponymousGroups', $eponymousGroups);
$smarty->assign('cachepages', $cachepages);
$smarty->assign('cacheimages', $cacheimages);

$smarty->assign('wiki_extras', 'n');

if (!isset($_SERVER['SERVER_NAME'])) {
	$_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
}
$feature_server_name = $tikilib->get_preference('feature_server_name', $_SERVER["SERVER_NAME"]);

//print($_SERVER["REQUEST_URI"]);
$smarty->assign('feature_server_name', $feature_server_name);
$_SERVER["SERVER_NAME"] = $feature_server_name;

// Fix IIS servers not setting what they should set (ay ay IIS, ay ay)
if (!isset($_SERVER['QUERY_STRING']))
    $_SERVER['QUERY_STRING'] = '';

if (!isset($_SERVER['REQUEST_URI']) || empty($_SERVER['REQUEST_URI'])) {
    $_SERVER['REQUEST_URI'] = $_SERVER['PHP_SELF'] . '/' . $_SERVER['QUERY_STRING'];
}

if (!isset($feature_bidi)) {
    $feature_bidi = 'n';
}

$smarty->assign('feature_bidi', $feature_bidi);

/* # not implemented
$http_basic_auth = $tikilib->get_preference('http_basic_auth', '/');
$smarty->assign('http_basic_auth',$http_basic_auth);
*/
$https_login = $tikilib->get_preference('https_login', 'n');
$smarty->assign('https_login', $https_login);
$https_login_required = $tikilib->get_preference('https_login_required', 'n');
$smarty->assign('https_login_required', $https_login_required);

$https_mode = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on';

if ($https_mode) {
    $http_port = 80;

    $https_port = isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : 443;
} else {
    $http_port = isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : 80;

    $https_port = 443;
}

$http_domain = $tikilib->get_preference('http_domain', '');
$smarty->assign('http_domain', $http_domain);
$http_port = $tikilib->get_preference('http_port', $http_port);
$smarty->assign('http_port', $http_port);
$http_prefix = $tikilib->get_preference('http_prefix', '/');
$smarty->assign('http_prefix', $http_prefix);

$https_domain = $tikilib->get_preference('https_domain', '');
$smarty->assign('https_domain', $https_domain);
$https_port = $tikilib->get_preference('https_port', $https_port);
$smarty->assign('https_port', $https_port);
$https_prefix = $tikilib->get_preference('https_prefix', '/');
$smarty->assign('https_prefix', $https_prefix);

$login_url = 'tiki-login.php';
$smarty->assign('login_url', $login_url);

if ($https_login == 'y' || $https_login_required == 'y') {
    $http_login_url = 'http://' . $http_domain;

    if ($http_port != 80)
        $http_login_url .= ':' . $http_port;

    $http_login_url .= $http_prefix . $tikiIndex;

    if (SID)
        $http_login_url .= '?' . SID;

    $edit_data = htmlentities(isset($_REQUEST["edit"]) ? $_REQUEST["edit"] : '', ENT_QUOTES);

    $https_login_url = 'https://' . $https_domain;

    if ($https_port != 443)
        $https_login_url .= ':' . $https_port;

    $https_login_url .= $https_prefix . $tikiIndex;

    if (SID)
        $https_login_url .= '?' . SID;

    $stay_in_ssl_mode = isset($_REQUEST['stay_in_ssl_mode']) ? $_REQUEST['stay_in_ssl_mode'] : '';

    if ($https_login_required == 'y') {
        # only show "Stay in SSL checkbox if we're not already in HTTPS mode"
        $show_stay_in_ssl_mode = !$https_mode ? 'y' : 'n';

        $smarty->assign('show_stay_in_ssl_mode', $show_stay_in_ssl_mode);

        if (!$https_mode) {
            $https_login_url = 'https://' . $https_domain;

            if ($https_port != 443)
                $https_login_url .= ':' . $https_port;

            $https_login_url .= $https_prefix . $login_url;

            if (SID)
                $https_login_url .= '?' . SID;

            $smarty->assign('login_url', $https_login_url);
        } else {
            # We're already in HTTPS mode, so let's stay there
            $stay_in_ssl_mode = 'on';
        }
    } else {
        $smarty->assign('http_login_url', $http_login_url);

        $smarty->assign('https_login_url', $https_login_url);
        # only show "Stay in SSL checkbox if we're not already in HTTPS mode"
        $show_stay_in_ssl_mode = $https_mode ? 'y' : 'n';
    }

    $smarty->assign('show_stay_in_ssl_mode', $show_stay_in_ssl_mode);
    $smarty->assign('stay_in_ssl_mode', $stay_in_ssl_mode);
}

// start of replacement : get all prefs from db once
$tikilib->get_all_preferences();
foreach ($preferences as $name => $val) {
	$$name = $val;
	$smarty->assign("$name", $val);
}

//after prefs update, must check if mailin_autocheck time is elapsed
if($feature_mailin == 'y' && $mailin_autocheck == 'y')
{
  if((time() - $mailin_autocheckLast)/60 > $mailin_autocheckFreq){
    $tikilib->set_preference("mailin_autocheckLast", time());
    include_once("tiki-mailin-code.php");
  }
}

if ($feature_detect_language == "y") {
    $browser_language = detect_browser_language();
    if (!empty($browser_language)) {
	$language = $browser_language;
	$smarty->assign('language', $language);
    }
}

$useGroupHome = $tikilib->get_preference("useGroupHome",'n');
$tikiIndex = $tikilib->get_preference("tikiIndex",'tiki-index.php');
$group = '';

$group = $userlib->get_user_default_group($user);
if($useGroupHome == 'y') {
    $groupHome = $userlib->get_group_home($group);
    if ($groupHome) {
        $tikiIndex = strpos($groupHome,'http://')===0 ? $groupHome : "tiki-index.php?page=".$groupHome;
    }
}

$smarty->assign('tikiIndex',$tikiIndex);

$user_dbl = 'y';

$user_style = $site_style = $tikilib->get_preference("style", 'moreneat.css');
if ($feature_userPreferences == 'y') {
    // Check for FEATURES for the user

    if ($user) {
        $user_dbl = $tikilib->get_user_preference($user, 'user_dbl', 'y');

        if ($change_theme == 'y') {
            $user_style = $tikilib->get_user_preference($user, 'theme', $style);

            if ($user_style) {
									$style = $user_style;
            }
        }

        if ($change_language == 'y') {
            $user_language = $tikilib->get_user_preference($user, 'language', $language);

            if ($user_language) {
                $language = $user_language;
            }
        }
    }

    $smarty->assign('language', $language);
}
if (!(isset($user) && $user)  && isset($saveLanguage) ) { // users not logged that change the preference
	$language = $saveLanguage;
	$smarty->assign('language', $language);
}

$stlstl = split("-|\.", $style);
$style_base = $stlstl[0];

if (!(isset($user) && $user) && isset($saveLanguage) ) { // anonymous that change the preference
	$language = $saveLanguage;
	$smarty->assign('language', $language);
}

if ($lang_use_db != 'y') {
    // check if needed!!!
    global $lang;
}

if ($tikidomain and is_file("styles/$tikidomain/$style")) {
	$style = "$tikidomain/$style";
}
$smarty->assign('style', $style);

$smarty->assign('user_dbl', $user_dbl);

$smarty->assign('user', $user);
$smarty->assign('group', $group);
$smarty->assign('lock', false);
$smarty->assign('title', $title);
$smarty->assign('maxRecords', $maxRecords);

// If we are processing a login then do not generate the challenge
// if we are in any other case then yes.
if (!strstr($_SERVER["REQUEST_URI"], 'tiki-login')) {
    if ($feature_challenge == 'y') {
        $chall = $userlib->generate_challenge();

        $_SESSION["challenge"] = $chall;
        $smarty->assign('challenge', $chall);
    }
}

setDisplayMenu("mymenu");
setDisplayMenu("usrmenu");
setDisplayMenu("friendsmenu");
setDisplayMenu("wikimenu");
setDisplayMenu("admmnu");

if ($user && $feature_usermenu == 'y') {
    if (!isset($_SESSION['usermenu'])) {
        include_once ('lib/usermenu/usermenulib.php');

        $user_menus = $usermenulib->list_usermenus($user, 0, -1, 'position_asc', '');
        $smarty->assign('usr_user_menus', $user_menus['data']);
        $_SESSION['usermenu'] = $user_menus['data'];
    } else {
        $user_menus = $_SESSION['usermenu'];

        $smarty->assign('usr_user_menus', $user_menus);
    }
}

include_once ("tiki-modules.php");

if ($feature_warn_on_edit == 'y') {
    
    if (strstr($_SERVER['REQUEST_URI'], 'tiki-editpage')) {
    	$current_page = 'tiki-editpage';
    } elseif (strstr($_SERVER['REQUEST_URI'], 'tiki-index')) {
    	$current_page = 'tiki-index';
    } else {
    	$current_page = NULL;
    }

    if ($current_page == 'tiki-editpage' || $current_page == 'tiki-index') {
		// initiate all the variables
        $smarty->assign('editpageconflict', 'n');
        $editpageconflict = 'n';
	    $smarty->assign('beingEdited', 'n');
	    $beingedited = 'n';
	    if (!empty($_REQUEST['page'])) {
	        $chkpage = $_REQUEST['page'];
	    } elseif ($current_page == 'tiki-index') {
	    	$chkpage = $wikiHomePage;
	    } else {
	    	$chkpage = NULL;
	    }
	    if (!empty($chkpage)) {
	        if ($current_page == 'tiki-index' && $tikilib->semaphore_is_set($chkpage, $warn_on_edit_time * 60)) {
		        $smarty->assign('semUser', $tikilib->get_semaphore_user($chkpage));
		        $smarty->assign('beingEdited', 'y');
		        $beingedited = 'y';
	        } elseif ($current_page == 'tiki-editpage' && isset($_REQUEST['cancel_edit'])) {
	        	//Unlock the page when cancelling
	        	if (!empty($_SESSION["edit_lock_$chkpage"])) {
		        	$tikilib->semaphore_unset($chkpage, $_SESSION["edit_lock_$chkpage"]);
	        	}
	        } elseif ($current_page == 'tiki-editpage' && !isset($_REQUEST['save'])) {
	        	//When tiki-editpage.php is loading, check to see if there is an editing conflict
	        	if ($current_page == 'tiki-editpage' && $tikilib->semaphore_is_set($chkpage, $warn_on_edit_time * 60) && $tikilib->get_semaphore_user($chkpage) != $user) {
		            $smarty->assign('editpageconflict', 'y');
		            $editpageconflict = 'y';
	        	} else {
	        		//Lock the page that is being edited
		            $_SESSION["edit_lock_$chkpage"] = $tikilib->semaphore_set($chkpage);
	        	}
		        $smarty->assign('semUser', $tikilib->get_semaphore_user($chkpage));
		        $smarty->assign('beingEdited', 'y');
		        $beingedited = 'y';
	        } elseif ($current_page == 'tiki-editpage' && isset($_REQUEST['save'])) {
	        	//Unlock the page when saving
	        	if (!empty($_SESSION["edit_lock_$chkpage"])) {
		        	$tikilib->semaphore_unset($chkpage, $_SESSION["edit_lock_$chkpage"]);
	        	}
	        }
	    }
    }

} else {
	$smarty->assign('beingEdited', 'n');
	$smarty->assign('editpageconflict', 'n');
}


if (isset($_REQUEST["pollVote"])) {
    if ($tiki_p_vote_poll == 'y' && isset($_REQUEST["polls_optionId"])) {
	if( $feature_poll_anonymous == 'y' || $user )
	{
	    $tikilib->poll_vote($user, $_REQUEST["polls_pollId"], $_REQUEST["polls_optionId"]);
	    // Poll vote must go first, or the new vote will be seen as the previous one.
	    $tikilib->register_user_vote($user, 'poll' . $_REQUEST["polls_pollId"], $_REQUEST["polls_optionId"]);
	}
    }

    $pollId = $_REQUEST["polls_pollId"];
    header ("location: tiki-poll_results.php?pollId=$pollId");
}

$ownurl = httpPrefix(). $_SERVER["REQUEST_URI"];
$parsed = parse_url($_SERVER["REQUEST_URI"]);

if (!isset($parsed["query"])) {
    $parsed["query"] = '';
}

parse_str($parsed["query"], $query);
$father = httpPrefix(). $parsed["path"];

if (count($query) > 0) {
    $first = 1;

    foreach ($query as $name => $val) {
	if ($first) {
	    $first = false;

	    $father .= '?' . $name . '=' . $val;
	} else {
	    $father .= '&amp;' . $name . '=' . $val;
	}
    }

    $father .= '&amp;';
} else {
    $father .= '?';
}


$ownurl_father = $father;
$smarty->assign('ownurl', httpPrefix(). $_SERVER["REQUEST_URI"]);

// load lib configs
/*
if ($libdir = opendir('lib')) {
	while (FALSE !== ($libname = readdir($libdir))) {
		$configIncFile = 'lib/'.$libname.'/setup_inc.php';
		if (is_dir( 'lib/'.$libname ) && file_exists( $configIncFile )) {
			include_once( $configIncFile );
		}
	}
}
*/
$allowMsgs = 'n';

if ($user) {
    $allowMsgs = $tikilib->get_user_preference($user, 'allowMsgs', 'y');

    $tasks_useDates = $tikilib->get_user_preference($user, 'tasks_useDates');
    $tasks_maxRecords = $tikilib->get_user_preference($user, 'tasks_maxRecords');
    $smarty->assign('tasks_useDates', $tasks_useDates);
    $smarty->assign('tasks_maxRecords', $tasks_maxRecords);
    $smarty->assign('allowMsgs', $allowMsgs);
}

if ($feature_referer_stats == 'y') {
    // Referer tracking
    if (isset($_SERVER['HTTP_REFERER'])) {
        $pref = parse_url($_SERVER['HTTP_REFERER']);

        if (!strstr($_SERVER["SERVER_NAME"], $pref["host"])) {
            $tikilib->register_referer($pref["host"]);
        }
    }
}

//Check for an update of dynamic vars
if(isset($tiki_p_edit_dynvar) && $tiki_p_edit_dynvar == 'y') {
    if(isset($_REQUEST['_dyn_update'])) { 
        foreach($_REQUEST as $name => $value) {
            if(substr($name,0,4)=='dyn_' and $name!='_dyn_update') {
                $tikilib->update_dynamic_variable(substr($name,4),$_REQUEST[$name]);
            }
        }
    }
}


// Stats
if ($feature_stats == 'y') {
    if ($count_admin_pvs == 'y' || $user != 'admin') {
				if (!isset($section) or ($section != 'chat' and $section != 'livesupport')) { 
            $tikilib->add_pageview();
        }
    }
}

$smarty->assign('uses_tabs', 'n');
$smarty->assign('uses_jscalendar', 'n');
$smarty->assign('uses_phplayers', 'n');

$user_preferences = array();

//print("tiki-setup: before include tiki-handlers.php:".$tiki_timer->elapsed()."<br />");
//tiki-handlers.php is empty right now.  uncomment the line below if you need to use it
//include_once ('tiki-handlers.php');

// no compression at all
$smarty->assign('gzip','Disabled');
$smarty->assign('gzip_handler','none');
// php compression enabled?
if (ini_get('zlib.output_compression') == 1) {
    $smarty->assign('gzip','Enabled');
    $smarty->assign('gzip_handler','php');
// if not, check if tiki compression is enabled
} elseif ($feature_obzip == 'y') {
	// tiki compression is enabled, then let activate the handler
	if ($feature_obzip == 'y') {
	    ob_start ("ob_gzhandler");
			$smarty->assign('gzip_handler','tiki');
    	$smarty->assign('gzip','Enabled');
	}
}

//print("tiki-setup: before include debugger.php:".$tiki_timer->elapsed()."<br />");
/* Include debugger class declaration. So use loggin facility in
 * php files become much easier :)
 */
if ($feature_debug_console == 'y') {
    include_once ('lib/debug/debugger.php');
}
//print("tiki-setup: after include debugger.php:".$tiki_timer->elapsed()."<br />");

$smarty->assign_by_ref('num_queries',$num_queries);

/*
 * Register the search refresh function
 */

if ($feature_search == 'y') {
  include_once("lib/search/refresh.php");
  register_shutdown_function("refresh_search_index");
}

/*
 * Whether to show comments zone on page load by default
 */
if (isset($_REQUEST['comzone'])) {
		$show_comzone=$_REQUEST['comzone'];
		if ($show_comzone=='show') $smarty->assign('show_comzone', 'y');
}

/* trick for use with doc/devtools/cvsup.sh */
if (is_file('.lastup') and is_readable('.lastup')) {
	$lastup = file('.lastup');
	$smarty->assign('lastup',$lastup[0]);
}
function getCookie($name, $section=null, $default=null) {
	if (isset($feature_no_cookie) && $feature_no_cookie == 'y') {
		if (isset($_SESSION['tiki_cookie_jar'])) {// if cookie jar doesn't work
			if (isset($_SESSION['tiki_cookie_jar'][$name]))
				return $_SESSION['tiki_cookie_jar'][$name];
			else
				return $default;
		}
	}
	else if ($section){
		if (isset($_COOKIE[$section])) {
			if (preg_match("/@".$name."\:([^@;]*)/", $_COOKIE[$section], $matches))
				return $matches[1];
			else
				return $default;
		}
		else
			return $default;
	}
	else {
		if (isset($_COOKIE[$name]))
			return $_COOKIE[$name];
		else
			return $default;
	}
}
function setDisplayMenu($name) {
	global $smarty;
	if (getCookie($name, "menu") == 'o') {
		$smarty->assign('mnu_'.$name, 'display:block;');
		$smarty->assign('icn_'.$name, 'o');
}
	else
		$smarty->assign('mnu_'.$name, 'display:none;');
}
?>
Return current item: TikiWikiLite