{* если сгруппировано *}
{if $is_grouped}
  <table class="calendar_week_type calendar_table">
  <tr>
    <th width="50">&nbsp;</th>
    {foreach from=$month_head key=shortname item=one_day name=header}
      <th class="header_events_column" group_key="{$shortname}" id="week_header{$shortname}">{$one_day|default:'&nbsp;'}</th>
    {/foreach}
  </tr>
  <tr>
    <th style="border-top: 1px solid transparent; border-left: 1px solid transparent; border-right: 1px solid transparent;">&nbsp;</th>
    <th colspan="7">&nbsp;</th>
  </tr>
  {foreach from=$month_days key=key item=day_info name=strings}
    <tr class="month_str{$smarty.foreach.strings.iteration}">
      <td class="week_time{if $smarty.foreach.strings.iteration eq $calendar.cur_day} today_day_week{/if}"
          id="week_time{$smarty.foreach.strings.iteration}">
          {$key}
      </td>
      {foreach from=$month_head key=shortname item=week_head_one_day name=header}
        {if !isset($day_info.data[$shortname])}
          <td class="week_top month_cell{$shortname}{if $smarty.foreach.strings.iteration eq $calendar.cur_day} today_day_week{/if}"
            id="cell_{$day_info.formatted_date}"
            onclick="addEvent('{$day_info.formatted_date|replace:'_':'.'}', event)" width="5000" style="position: relative; height: 150px;"></td>
        {else}
          <td class="month_cell{$shortname}{if $smarty.foreach.strings.iteration eq $calendar.cur_day} today_day_week{/if}"
            id="cell_{$day_info.formatted_date}_{$shortname}"
            data-group-key="{$shortname}"
            data-group-name="{$week_head_one_day}"
            onclick="addEvent('{$day_info.formatted_date}_{$shortname}', event)"
            style="position: relative; height: 150px;" width="5000">
            {foreach from=$day_info.data[$shortname] item=one_event name=days_top key=mount_day_num}
              {if $smarty.foreach.days_top.iteration lte 6}
              <div draggable="true"
                event_length="{$one_event.length}"
                is_background="{$one_event.background}"
                class="calendar_event_line calendar_event_line_{$one_event.date_field}_{$one_event.line_id}_{$one_event.event_id} calendar_offset_{$one_event.line_id}_{$one_event.event_id} calendar_event_id{$one_event.event_id}"
                id="calendar_event_line_{$one_event.date_field}_{$one_event.line_id}_{$one_event.event_id}_{$smarty.foreach.days_top.iteration}_{$shortname}"
                style="top: 0; box-sizing: border-box; width: 100%;{if !$one_event.background} border: 1px solid {$one_event.color};{/if}"
                data-date_field_id="{$one_event.date_field}"
                data-period_field_id="{$one_event.period_field}"
                data-event_id="{$one_event.event_id}"
                data-line_id="{$one_event.line_id}"
              >
                <div {if $config['display_calendar_events'] == '0'}onclick="viewOneEvent({$one_event.event_id}, {$one_event.line_id}, event); event.cancelBubble = true;"{/if}
                  onmouseover="highlightEvent(true, {$one_event.event_id}, {$one_event.line_id})"
                  onmouseout="highlightEvent(false, {$one_event.event_id}, {$one_event.line_id})"
                  id="c_event_layout{$one_event.event_id}_{$one_event.line_id}"
                  class="c_event_layout c_event_layout{$one_event.event_id}_{$one_event.line_id} c_event_layout{$one_event.event_id}"{if $one_event.background} style="padding: 1px 4px;"{/if}>
                  {if $one_event.data.mount_date && !$one_event.prev}{$one_event.data.mount_date}{/if}{$one_event.data.mount}
                  </div>
                  {if $config['display_calendar_events'] == '1'}
                    <div class="hoverEventBlock">
                        <div class="cal_event_header">
                            <b class="one_event_date_block"></b>
                        </div>
                        <div class="event_hover--block">
                            <div class="event_datefields"></div>
                            <div class="event_fields"></div>
                        </div>
                        <div class="cal_event_footer">
                            <a href="">Перейти к записи »</a>
                        </div>
                    </div>
                    <script>hoverEvent({$one_event.event_id}, {$one_event.line_id}, event, {$one_event.date_field});</script>
                {/if}
              </div>
              {elseif $smarty.foreach.days_top.iteration eq 7}
                <div class="hidden_items_events">
                    <a href="calendar.php?id={$calendar.id}&day={$day_info.day}&month={$day_info.month}&year={$day_info.year}"
                      onclick="event.cancelBubble = true;">{$lang.More} {{$day_info.data[$shortname]|@count} - 6}&raquo;
                    </a>
                </div>
              {/if}
            {/foreach}

          </td>
        {/if}
      {/foreach}
    </tr>
  {/foreach}
</table>
<style>
  .hidden_items_events {
    background-color: #fff;
    border-radius: 7px;
    bottom: 0;
    margin: 3px 3px 2px;
    z-index: 400;
  }

  .hidden_items_events:hover{
    background-color: #e9e9e9;
  }

  .hidden_items_events a {
    padding: 3px 7px;
  }

  .hidden_items_events a:hover{
    color: #484848;
  }
</style>
{else}
  <table class="calendar_month_type calendar_table">
    <tr>
        <th>{$lang.Mon}</th>
        <th>{$lang.Tue}</th>
        <th>{$lang.Wed}</th>
        <th>{$lang.Thu}</th>
        <th>{$lang.Fri}</th>
        <th>{$lang.Sat}</th>
        <th>{$lang.Sun}</th>
    </tr>
    {foreach from=$month_days item=one_str name=calendar_str key=k_str}
        <tr id="month_str{$k_str}">
            {foreach from=$one_str item=one_cell name=calendar_cell key=k_cell}
                {if $k_cell neq 'cur_week'}
                    <td {if $one_cell.today} class="today_cell"{/if}
                      id="cell_{$one_cell.day}_{$one_cell.month}_{$one_cell.year}"
                      class="month_cell{$k_cell}"
                      onclick="addEvent('{$one_cell.day}.{$one_cell.month}.{$one_cell.year}', event)"
                    >
                        <div id="quadr_{$one_cell.day}_{$one_cell.month}_{$one_cell.year}">
                            <div id="q_short_header_{$one_cell.day}_{$one_cell.month}_{$one_cell.year}"
                                class="day_quadr{if $one_cell.cur} cur_day{/if}"><span
                                        style="cursor: pointer"
                                        onclick="jumpToDay({$one_cell.day}, {$one_cell.month}, {$one_cell.year}); event.cancelBubble = true;">{$one_cell.day}{if $one_cell.day eq 1} {$one_cell.month_name}{/if}</span>
                            </div>
                            <div id="q_full_header_{$one_cell.day}_{$one_cell.month}_{$one_cell.year}"
                                class="c_event_layout" onclick="event.cancelBubble = true;"
                                style="z-index: 400; display: none; border-bottom: 1px solid black; background: {$color_scheme.color3} !important; font-size: 12px !important; padding: 0px 5px; cursor: default;">
                                <span style="float: right; cursor: pointer"
                                      onclick="hideAllRecords()">x</span>
                                {$one_cell.day} {$one_cell.month_name}
                            </div>
                            {foreach from=$one_cell.events key=offset item=one_group_str name=offsets}
                                {foreach from=$one_group_str key=time item=one_event name=times}
                                    {if $one_event.is_view}
                                        {if $offset lte 6}
                                            <div 
                                              draggable="true" 
                                              event_length="{$one_event.length}"
                                              is_background="{$one_event.background}"
                                              style="margin-top: {$offset * 17}px;{if !$one_event.background} border: 1px solid {$one_event.color};{/if}"
                                              class="calendar_event_line calendar_event_line_{$one_event.date_field}_{$one_event.line_id}_{$one_event.event_id} calendar_offset_{$one_event.line_id}_{$one_event.event_id} calendar_event_id{$one_event.event_id}"
                                              id="calendar_event_line_{$one_event.date_field}_{$one_event.line_id}_{$one_event.event_id}_{$k_str}_{$k_cell}"
                                              data-date_field_id="{$one_event.date_field}"
                                              data-period_field_id="{$one_event.period_field}"
                                              data-event_id="{$one_event.event_id}"
                                              data-line_id="{$one_event.line_id}"
                                            >
                                                <div {if $config['display_calendar_events'] == '0'}onclick="viewOneEvent({$one_event.event_id}, {$one_event.line_id}, event, {$k_str}, {$k_cell}); event.cancelBubble = true;"{/if}
                                                    onmouseover="highlightEvent(true, {$one_event.event_id}, {$one_event.line_id})"
                                                    onmouseout="highlightEvent(false, {$one_event.event_id}, {$one_event.line_id})"
                                                    id="c_event_layout{$one_event.event_id}_{$one_event.line_id}_{$k_str}_{$k_cell}"
                                                    class="c_event_layout c_event_layout{$one_event.event_id}_{$one_event.line_id} c_event_layout{$one_event.event_id}"{if $one_event.background} style="padding: 1px 4px;"{/if}>
                                                    {if $one_event.data.mount_date && !$one_event.prev}{$one_event.data.mount_date}{/if}{$one_event.data.mount}
                                                </div>
                                                {if $config['display_calendar_events'] == '1'}
                                                    <div class="hoverEventBlock">
                                                        <div class="cal_event_header">
                                                            <b class="one_event_date_block"></b>
                                                        </div>
                                                        <div class="event_hover--block">
                                                            <div class="event_datefields"></div>
                                                            <div class="event_fields"></div>
                                                        </div>
                                                        <div class="cal_event_footer">
                                                            <a href="">Перейти к записи »</a>
                                                        </div>
                                                    </div>
                                                    <script>hoverEvent({$one_event.event_id}, {$one_event.line_id}, event, {$one_event.date_field}, {$k_str}, {$k_cell});</script>
                                                {/if}
                                                <div class="prev_event_arrow"
                                                    style="z-index: 15; position: absolute; margin: -16px 0px 0px -1{if $one_event.background}6{else}7{/if}px; {if $one_event.prev}border: 8px solid transparent; border-right: 8px solid {if $one_event.background}rgba({$one_event.color_r}, {$one_event.color_g}, {$one_event.color_b}, 0.1){else}{$one_event.color}{/if}{/if}"></div>
                                                <div class="next_event_arrow"
                                                    style="z-index: 15; position: absolute; margin: -16px 0px 0px 0px; {if $one_event.next}border: 8px solid transparent; border-left: 8px solid {if $one_event.background}rgba({$one_event.color_r}, {$one_event.color_g}, {$one_event.color_b}, 0.1){else}{$one_event.color}{/if}{/if}"></div>
                                            </div>
                                        {/if}
                                    {/if}
                                {/foreach}
                            {/foreach}
                            {if $one_cell.count gt $calendar.day_event_count}
                                <div class="hidden_items_events">
                                    <a href="calendar.php?id={$calendar.id}&day={$one_cell.day}&month={$one_cell.month}&year={$one_cell.year}"
                                      onclick="event.cancelBubble = true;">{$lang.More} {$one_cell.count - $calendar.day_event_count}&raquo;</a>
                                </div>
                            {/if}
                        </div>
                    </td>
                {/if}
            {/foreach}
        </tr>
    {/foreach}
  </table>
{/if}
