<?php

$get_act = $tools->keyGlobals('act', 'get', 'edit');
$access_type = $tools->keyGlobals('edit', 'get', 'private');

if (!isset($accessTitle[$get_act])) {
  $accessTitle[$get_act] = 'Ошибка доступа';
}

if ($get_act == 'edit') {
    $typeEdit = array(
        'id' => ($access_type == 'comment' ? 'private_komm' : 'private'), 
        'name' => ($access_type == 'comment' ? 'Комментирование доступно' : 'Кто видит запись'), 
    );
}

if ($maps['diary_id'] != 0) {
    $diary = mysql_fetch_assoc(mysql_query("
                      SELECT n.*
                      FROM notes AS n WHERE n.id = " . (int) $maps['diary_id']));  
} else {
    $diary = array('id' => 0, 
                   'private' => $tools->keyGlobals('diary_access', 'sess', 0), 
                   'private_komm' => $tools->keyGlobals('diary_comment', 'sess', 0), 
                   'name' => 'Новая запись', 
                   'msg' => $tools->keyGlobals('diary_message', 'sess', NULL),
            );
}

if (!isset($diary['id'])) {
    header('Location: ?');
    exit;
}

$set['title'] = (isset($accessTitle[$get_act]) ? $accessTitle[$get_act] : 'Ошибка доступа');
require H.'sys/inc/thead.php';
title();
aut();
err();
?>
<ol class="breadcrumb">
  <li><a href="/index.php"><i class="ic ic-home"></i></a></li>
  <li><a href="?"><?= __('Дневники')?></a></li>
  <li>
    <a href="?f=<?= $maps['r']?>&amp;s=<?= $maps['s']?>&amp;q=<?= $maps['search']?>&amp;r=access&amp;u=<?= $maps['u']?>&amp;zsort=<?= $maps['zsort']?>&amp;id=<?= $maps['diary_id']?>">
      <?= $classDiary->get_name($diary['name'], $diary['msg'])?>
    </a>
  </li>
  <li><?= $accessTitle[$get_act]?></li>
</ol>
<?
if ($get_act == 'edit' && $user_id) {
  ?>
  <form class="form-post-access" action="?f=<?= $maps['f']?>&amp;s=<?= $maps['s']?>&amp;q=<?= $maps['search']?>&amp;r=<?= $maps['r']?>&amp;u=<?= $maps['u']?>&amp;page=<?= $maps['page']?>&amp;zsort=<?= $maps['zsort']?>&amp;id=<?= $maps['diary_id']?>&amp;act=edit&amp;edit=<?= $access_type?>" method="POST">
    <div class="access-header">
      <?= $typeEdit['name']?>:
    </div>
  
    <? foreach($accessList AS $key => $value) { ?>
      <label>
        <img src="/style/icons/<?= $value['icon']?>.png" /> 
        <input type="radio" name="<?= $typeEdit['id']?>" value="<?= $key?>" <?= ($diary[$typeEdit['id']] == $key ? 'checked' : '')?> /> 
        <?= $value['name']?>
      </label>
    <? } ?>
    
    <button type="submit" name="access"><?= __('Сохранить')?></button>
  </form>
  <?
} else {
  ?>
  <div class="alert alert-warning">
    <?= __('Автор ограничил доступ к этому дневнику.')?><br />
    <a href="?f=index&amp;s=<?= $maps['s']?>&amp;q=<?= $maps['search']?>&amp;r=<?= $maps['r']?>&amp;u=<?= $maps['u']?>&amp;zsort=<?= $maps['zsort']?>">&larr; <?= __('Вернуться')?></a>
  </div>
  <?  
}
