<?php
 require_once('includes/incl.php');
 $conn = ConnectToDatabese();
 $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
 total_io_log_begin('adminka.php','ADMFRAMEID,DOLGN');

 if (file_exists('plugins/sys/on_adminka_begin.php'))
 {
    include('plugins/sys/on_adminka_begin.php');
 }

 if (!@nrs_strlen($ADMFRAMEID)) $ADMFRAMEID=0;

 include_once('cls/trights.php');
 global $rights;
 $rights = new TRights();
 $rights->conn = $conn;
 $rights->Init();

 include_once('adm/cklog.php');

 if (!@nrs_strlen($DOLGN)) $DOLGN='';

 if (!@nrs_strlen($GOTO)) $GOTO='';
 if ($GOTO) $_SESSION['redirect_request_after_login'] = $GOTO;

 if (nrs_strlen($DOLGN))
 {
   $l=0;
   if ($DOLGN=='SENDADMMES')
   {
     global $ADMMES,$LOGIN_ERROR;
     $LOGIN_ERROR = doSendAdminMessage($conn,$ADMMES);
	 if (!$LOGIN_ERROR) $LOGIN_ERROR = 'Сообщение отправлено администратору';
   } elseif($DOLGN=='REMPAS')
   {
     global $LOGOREM,$LOGIN_ERROR;
     $LOGIN_ERROR = doSendTempPasMessage($conn,$LOGOREM);
   }
   else $l = doLogin($conn);
   if (!$l)
   {
     include('adm/loginf.php');
     total_io_log_end();
     die();
   }
 }

 $current_user_id = check_user($conn);
 if (!$current_user_id)
 {
   if (!$ADMFRAMEID)
   {
     include('adm/loginf.php');
     die();
   }
   die('Незарегистрированный пользователь');
 }


 //Пододжка фреймов
 if ($ADMFRAMEID==0)
 {
    //frameborder="2"'; border="2"  BORDERCOLOR="#FFFFFF"
   global $m_conf;  $charset='utf-8';
   if (array_key_exists('charset',$m_conf))  $charset= $m_conf['charset'];

  $default_style = $rights->GetVal('interface_style_css','wo_main.css');

  $system_name = 'CMS.Webolla';
  global $m_conf;
  if (array_key_exists('systemname',$m_conf))  $system_name = $m_conf['systemname'];


   $s = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
     <html xmlns=\"http://www.w3.org/1999/xhtml\">
        <head>
         <title>$system_name</title>
		 <meta name=\"robots\" content=\"noindex,nofollow\">
         <meta http-equiv=\"Content-Type\" content=\"text/html; charset=$charset\" />
         <link rel=\"stylesheet\" type=\"text/css\" href=\"styles/wo_main.css\">";
   if ($default_style && ($default_style!='wo_main.css')) $s .= " <link rel=\"stylesheet\" type=\"text/css\" href=\"styles/$default_style\">";

   $s .= "
        </head>
		<frameset rows=\"41px,*\" cols=\"*\" id=\"toplineFrameset\" border=\"1\" BORDERCOLOR=\"#707070\" >
          <frame id=\"frame_lineinfo\" src=\"adminka.php?ADMFRAMEID=2\"
           name=\"frame_lineinfo\" scrolling=\"no\"/>
		  </frame>";

  $mainFrameContent = "admrout.php?ROUTFILE=startpage.php";
  $sp_id = $rights->get_start_page();
  if ($sp_id)
  {
    $ones_ref = GetFieldFromSQL($conn,"SELECT ONEREF FROM SYS_START_PAGE WHERE ID=$sp_id",'');
    if (nrs_strlen($ones_ref)) $mainFrameContent = $ones_ref;
  }

	if( isset( $_SESSION['redirect_request_after_login'] ) )
  {
	 	$mainFrameContent = $_SESSION['redirect_request_after_login'];
		unset( $_SESSION['redirect_request_after_login'] );
	}
	$s .= " <frameset cols=\"240px,*\" rows=\"*\" id=\"mainFrameset\" border=\"3\" BORDERCOLOR=\"#707070\" >
        <frame id=\"frame_navigation\"
        src=\"adminka.php?ADMFRAMEID=1\"
        name=\"frame_navigation\" />
        <frame  id=\"frame_content\"
        src=\"{$mainFrameContent}\"
        name=\"frame_content\" />";

   $s .= "
     </frameset>
    <noframes>
        <body>
            <p>Для работы Админки нужен браузер с поддержкой <b>фреймов</b>.</p>
        </body>
    </noframes>
</frameset>
";
   total_io_log_end();
   die($s);
 }

 //Левый фрейм - навигация
 if ($ADMFRAMEID==1)
 {
     include('adm/admmenu.php');
     total_io_log_end();
     die();
 } elseif ($ADMFRAMEID==2)
 {
     include('adm/topline.php');
     total_io_log_end();
     die();
 }

 total_io_log_end();
?>
