<?php
/*
	Copyright(c) 2010 Shift Tech Inc. All Rights Reserved.
 	http://www.shift-tech.jp/

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

require_once ('PcController.php');
class AdminController extends PcController {

	/**
      * @var array	ログイン済みユーザー情報
      */
    var $uinfo;

	function AdminController()
	{
		$this->__construct();
	}
	function __construct()
	{
		PcController::__construct();

		$this->view_path = "pc/admin";
		$this->view = new View($this->view_path);

		//if($_SERVER['PHP_SELF'] != "/admin/login.php") {
		if(!ereg("/admin/login.php",$_SERVER['PHP_SELF'])) {
			if(!isset($_SESSION["usr_info"])) {
				//header("location:/admin/login.php");
				header("location:".BINGOTOPURL."/admin/login.php");
				exit();
			} else {
				$this->uinfo = $_SESSION['usr_info'];
				//ページ管理リンク先取得
				$_SESSION['usr_info']['editable_sidx_code'] = 1;
				if($_SESSION["usr_info"]["usr_kanri"]!=1){
					require_once (LIB_PATH.'/common/sectionIdxDB.php');
					$sectionIdxDB = New sectionIdxDB();
					$list = array(); //セクションリスト
					$list = $sectionIdxDB->getlistAll($_SESSION["usr_info"]["usr_code"]);
					if(is_array($list)&&count($list)>0) {
						foreach($list as $key => $val) {
							$_SESSION['usr_info']['editable_sidx_code'] = $val["sidx_code_tmp"];
							break;
						}
					}
				}
				//モジュール管理メニュー取得
				require_once (LIB_PATH.'/common/moduleDB.php');
				$moduleDB = New moduleDB();
				$this->view->assign("modulemenulists", $moduleDB->getMenulist());
				
				$this->view->assign("usr_info", $_SESSION['usr_info']);
			}
		}
		
		$this->GlobalAssign(&$this->view);
		$this->view->assign("JS",  BASE_PATH.'/app/view/pc/_common/js.tpl');
        //ヘッダフッタ設定(管理ページ用）
        $tmpl_path = BASE_PATH.'/app/view/pc/admin/_common/';
        $this->view->assign("HEAD",  $tmpl_path.'head.tpl');
        $this->view->assign("HEADER",  $tmpl_path.'header.tpl');
		$this->view->assign("FOOTER",  $tmpl_path.'footer.tpl');
		$this->view->assign("DISPERR", $tmpl_path.'disperr.tpl');
		$this->view->assign("USR_PROF_IMG_PATH", USR_PROF_IMG_PATH);
		$this->view->assign("MODULES_DIR", MODULES_DIR);
		
		
		//installディレクトリ削除チェック
		$instdirchk = true;
		if(is_dir(BASE_PATH."/install")) {
			$instdirchk = false;
		}
		$this->view->assign("instdirchk", $instdirchk);
		
		//コンテナ、ユニット用CSSがなければ作成
		if(!file_exists(CACHE_PATH.'/AllUnits.css')) {
			require_once (LIB_PATH.'/common/pageunitDB.php');
			$pageunitDB = new pageunitDB();
			$pageunitDB->putAllUnitsCSS($pageunitDB->makeAllUnitsCSS());
		}
    }
}

?>