コード例 #1
0
ファイル: project.php プロジェクト: HomelessCoder/weedo
function downcounter($date)
{
    $check_time = strtotime($date) - time();
    if ($check_time <= 0) {
        return false;
    }
    $days = floor($check_time / 86400);
    $hours = floor($check_time % 86400 / 3600);
    $minutes = floor($check_time % 3600 / 60);
    $seconds = $check_time % 60;
    $str = '';
    if ($days > 0) {
        $str .= declension($days, array('день', 'дня', 'дней')) . ' ';
    }
    // if($hours > 0) $str .= declension($hours,array('час','часа','часов')).' ';
    // if($minutes > 0) $str .= declension($minutes,array('минута','минуты','минут')).' ';
    // if($seconds > 0) $str .= declension($seconds,array('секунда','секунды','секунд'));
    return $str;
}
コード例 #2
0
ファイル: frontend.php プロジェクト: ratmir-by/icms-calendar
function calendar()
{
    $inCore = cmsCore::getInstance();
    $inPage = cmsPage::getInstance();
    $inUser = cmsUser::getInstance();
    $inCore->loadModel('calendar');
    $model = new cms_model_calendar();
    $do = $inCore->request('do', 'str', 'view');
    $cfg = $inCore->loadComponentConfig('calendar');
    if ($do == 'view') {
        $inPage->setTitle("Календарь событий");
        $smarty = $inCore->initSmarty('components', 'com_calendar_view.tpl');
        $guest = TRUE;
        if ($inUser->id == 0 and $cfg['calendar_access'] == "all") {
            $guest = FALSE;
        }
        if ($inUser->id != 0 and $cfg['calendar_access'] == "users") {
            $guest = FALSE;
        }
        if ($inUser->is_admin) {
            $guest = FALSE;
        }
        $catigories = $model->getAllCategories();
        $smarty->assign('guest', $guest);
        $smarty->assign('cfg', $cfg);
        $smarty->assign('catigories', $catigories);
        $smarty->assign('category', "all");
        $smarty->display('com_calendar_view.tpl');
        return;
    }
    if ($do == "category_view") {
        $category_id = $inCore->request('category_id', 'int', 0);
        $smarty = $inCore->initSmarty('components', 'com_calendar_view.tpl');
        $guest = TRUE;
        if ($inUser->id == 0 and $cfg['calendar_access'] == "all") {
            $guest = FALSE;
        }
        if ($inUser->id != 0 and $cfg['calendar_access'] == "users") {
            $guest = FALSE;
        }
        if ($inUser->is_admin) {
            $guest = FALSE;
        }
        $category = $model->getCategory($category_id);
        $catigories = $model->getAllCategories();
        if (!$category) {
            //$inCore->redirect("/calendar");
            print mysql_error();
        }
        $inPage->setTitle("Календарь событий:" . $category['title']);
        $smarty->assign('guest', $guest);
        $smarty->assign('cfg', $cfg);
        $smarty->assign('catigories', $catigories);
        $smarty->assign('category', $category_id);
        $smarty->display('com_calendar_view.tpl');
        return;
    }
    if ($do == 'add') {
        $guest = TRUE;
        if ($inUser->id == 0 and $cfg['calendar_access'] == "all") {
            $guest = FALSE;
        }
        if ($inUser->id != 0 and $cfg['calendar_access'] == "users") {
            $guest = FALSE;
        }
        if ($inUser->is_admin) {
            $guest = FALSE;
        }
        if ($guest) {
            $inCore->redirect('/');
            exit;
        }
        $is_send = $inCore->inRequest('title');
        if ($is_send) {
            $title = $inCore->request('title', 'str');
            $type_raw = $inCore->request('type', 'str');
            $date_start = $inCore->request('date_start', 'str');
            $date_end = $inCore->request('date_end', 'str');
            $hour_start = $inCore->request('hour_start', 'str');
            $hour_end = $inCore->request('hour_end', 'str');
            $min_start = $inCore->request('min_start', 'str');
            $min_end = $inCore->request('min_end', 'str');
            $content = $inCore->request('content', 'str');
            if (!$title || !$type_raw || !$date_start || !$hour_start || !$hour_end || !$min_start || !$min_end) {
                cmsCore::addSessionMessage('Ой, что то не было заполнено...', 'error');
                $inCore->redirectBack();
                exit;
            } else {
                $start_time = strtotime($date_start . ' ' . $hour_start . ':' . $min_start);
                $end_time = strtotime($date_end . ' ' . $hour_end . ':' . $min_end);
                if ($data_end == "" or $date_end < $date_start) {
                    $data_end = $data_start;
                }
                $type_data = explode("_", $type_raw);
                $type = $type_data[0];
                $apx = $type_data[1];
                $event_id = $model->addEvent($inUser->id, $type, $apx, $start_time, $end_time, $title, $content);
                if ($event_id) {
                    if ($type != "private") {
                        cmsActions::log('add_event', array('object' => 'событие', 'object_url' => '/calendar/event' . $event_id . '.html', 'object_id' => $event_id, 'target' => $title, 'target_url' => '/calendar/event' . $event_id . '.html', 'target_id' => '0', 'description' => $title));
                    }
                    cmsCore::addSessionMessage('Ваше мероприятие добавлено!', 'success');
                } else {
                    cmsCore::addSessionMessage('Ошибка добавления!', 'error');
                }
                $inCore->redirect('/calendar');
                exit;
            }
        }
        if ($event['start_time'] == "") {
            $event['start_time'] = time();
        }
        if ($event['end_time'] == "") {
            $event['end_time'] = time();
        }
        $bb_toolbar = cmsPage::getBBCodeToolbar('message', $cfg['img_on'], 'forum');
        $smilies = cmsPage::getSmilesPanel('message');
        $inPage->setTitle("Добавить событие");
        $smarty = $inCore->initSmarty('components', 'com_calendar_add.tpl');
        $smarty->assign('bb_toolbar', $bb_toolbar);
        $smarty->assign('smilies', $smilies);
        $smarty->assign('title', $event['title']);
        $smarty->assign('content', $event['content']);
        $smarty->assign('type', $event['type']);
        $smarty->assign('start_date', date("d.m.Y", $event['start_time']));
        $smarty->assign('start_hour', date("H", $event['start_time']));
        $smarty->assign('start_min', date("i", $event['start_time']));
        $smarty->assign('end_date', date("d.m.Y", $event['end_time']));
        $smarty->assign('end_hour', date("H", $event['end_time']));
        $smarty->assign('end_min', date("i", $event['end_time']));
        $smarty->display('com_calendar_add.tpl');
        return;
    }
    if ($do == "view_event") {
        $event_id = $inCore->request('event_id', 'int', 0);
        /*FOTOLIB*/
        include 'fotolib.class.php';
        $foto = new FotoLib();
        //Проверяем можем ли добавлять фото
        $allow_add_foto = $foto->addAcces("calendar");
        if ($_FILES) {
            $foto->uploadFoto($_FILES, "calendar", $event_id);
        }
        $images = $foto->loadImages("calendar", $event_id);
        /*FOTOLIB*/
        $event = $model->getEvent($event_id);
        if (!$event) {
            cmsCore::addSessionMessage('Ошибка запроса' . mysql_error(), 'error');
            $inCore->redirect('/calendar');
            exit;
        } else {
            if ($event['type'] == 'private' and $event['author_id'] != $inUser->id) {
                cmsCore::addSessionMessage('Ошибка запроса', 'error');
                $inCore->redirect('/calendar');
                exit;
            }
            $msg = $inCore->parseSmiles($event['content'], true);
            if (count($event['parent']) != 0) {
                $delta = $event['end_time'] - $event['start_time'];
                $day = date("d", $event['start_time']);
                $month = date("n", $event['start_time']) - 1;
                //Яваскриптики считают с 0
                $year = date("Y", $event['start_time']);
                if ($delta < 24 * 60 * 60) {
                    $calendar_view = "agendaDay";
                    if (date("d", $event['start_time']) != date("d", $event['end_time'])) {
                        //Если меньше 24 часов но всё же в разные дни включаем недельный вид
                        $calendar_view = "agendaWeek";
                    }
                } elseif ($delta < 7 * 24 * 60 * 60) {
                    $calendar_view = "agendaWeek";
                } else {
                    $calendar_view = "month";
                }
                $events_string = "";
                foreach ($event['parent'] as $parent) {
                    $events_string .= "{\n\t  id    : '" . $parent['id'] . "',\n\t  title : '" . str_replace("'", '"', $parent['title']) . "',\n\t  start : '" . date("Y-m-d H:i:s", $parent['start_time']) . "',\n\t  end   : '" . date("Y-m-d H:i:s", $parent['end_time']) . "',\n\t  url   : '/calendar/event" . $parent['id'] . ".html',";
                    if ($parent['end_time'] - $parent['start_time'] > 60 * 60 * 8) {
                        $events_string .= "allDay: true,";
                    } else {
                        $events_string .= "allDay: false,";
                    }
                    switch ($parent['type']) {
                        case "public":
                            if ($parent['author_id'] == $inUser->id) {
                                $events_string .= "color: '#B9C3BC',\n";
                            } else {
                                $events_string .= "color: '#C3BCB9',\n";
                            }
                            $events_string .= "textColor: '#000000',\n";
                            break;
                        case "private":
                            $events_string .= "color: '#3366CC'\n";
                    }
                    $events_string .= "},";
                }
            }
            $issignup = $model->isSignup($event_id);
            $singups_user = $model->getSingupsUsers($event_id);
            $inPage->setTitle('Просмотр события "' . $event['title'] . '"');
            $smarty = $inCore->initSmarty('components', 'com_calendar_event_view.tpl');
            $smarty->assign('event', $event);
            $smarty->assign('content', $msg);
            $smarty->assign('parent', $event['parent']);
            $smarty->assign('calendar_view', $calendar_view);
            $smarty->assign('events_string', $events_string);
            $smarty->assign('year', $year);
            $smarty->assign('month', $month);
            $smarty->assign('day', $day);
            $smarty->assign('start_time', date("d.m.Y H:i", $event['start_time']));
            $smarty->assign('end_time', date("d.m.Y H:i", $event['end_time']));
            $smarty->assign('issngnup', $issignup);
            $smarty->assign('singups_user', $singups_user);
            $smarty->assign('images', $images);
            //fotolib
            $smarty->assign('allow_add_foto', $allow_add_foto);
            //fotolib
            if ($event['start_time'] - time() < 0) {
                $status = "Прошедшее событие";
            } else {
                if ($event['start_time'] - time() > 86400) {
                    $status = 'Осталось ' . declension(round(($event['start_time'] - time()) / 86400), array("день", "дня", "дней"));
                } else {
                    $status = 'Осталось ' . declension(round(($event['start_time'] - time()) / 3600), array("час", "часа", "часов"));
                }
            }
            $smarty->assign('status', $status);
            if ($inUser->id == $event['author_id'] or $inUser->is_admin) {
                $smarty->assign('admin', TRUE);
            }
            $smarty->display('com_calendar_event_view.tpl');
            $inCore->includeComments();
            comments('calendar', $event_id);
            return;
        }
    }
    if ($do == "delete_event") {
        if ($inUser->id == 0) {
            $inCore->redirect('/');
            exit;
        }
        $event_id = $inCore->request('event_id', 'int', 0);
        $deleted = $model->deleteEvent($event_id);
        if ($deleted) {
            cmsCore::addSessionMessage('Ваше мероприятие удалено!', 'success');
            $inCore->redirect('/calendar');
            exit;
        } else {
            cmsCore::addSessionMessage('Ошибка', 'error');
            $inCore->redirect('/calendar');
            exit;
        }
    }
    if ($do == "edit_event") {
        if ($inUser->id == 0) {
            $inCore->redirect('/');
            exit;
        }
        $event_id = $inCore->request('event_id', 'int', 0);
        $event = $model->getEvent($event_id);
        if ($event["author_id"] != $inUser->id and !$inUser->is_admin) {
            cmsCore::addSessionMessage('Ошибка доступа', 'error');
            $inCore->redirectBack();
            exit;
        }
        $is_send = $inCore->inRequest('title');
        if ($is_send) {
            $title = $inCore->request('title', 'str');
            $type = $inCore->request('type', 'str');
            $date_start = $inCore->request('date_start', 'str');
            $date_end = $inCore->request('date_end', 'str');
            $hour_start = $inCore->request('hour_start', 'str');
            $hour_end = $inCore->request('hour_end', 'str');
            $min_start = $inCore->request('min_start', 'str');
            $min_end = $inCore->request('min_end', 'str');
            $content = $inCore->request('content', 'str');
            if (!$title || !$type || !$date_start || !$hour_start || !$hour_end || !$min_start || !$min_end) {
                cmsCore::addSessionMessage('Ой, что то не было заполнено...', 'error');
                $inCore->redirectBack();
                exit;
            } else {
                $start_time = strtotime($date_start . ' ' . $hour_start . ':' . $min_start);
                if ($data_end == "" or $data_end < $data_start) {
                    $data_end = $data_start;
                }
                $end_time = strtotime($date_end . ' ' . $hour_end . ':' . $min_end);
                if (!is_numeric($type)) {
                    $category_id = "0";
                } else {
                    $category_id = $type;
                    $type = "public";
                }
                $update = $model->updateEvent($event_id, $type, $category_id, $start_time, $end_time, $title, $content);
                if ($update) {
                    cmsCore::addSessionMessage('Ваше мероприятие изменено!', 'success');
                    $inCore->redirect('/calendar/event' . $event_id . '.html');
                    exit;
                } else {
                    cmsCore::addSessionMessage('Ошибка добавления!', 'error');
                    $inCore->redirect('/calendar/edit' . $event_id . '.html');
                    exit;
                }
            }
        } else {
            $event = $model->getEvent($event_id);
            if (!$event) {
                cmsCore::addSessionMessage('Ошибка запроса', 'error');
                $inCore->redirect('/calendar');
                exit;
            }
            if ($event['category_id']) {
                $event['type'] = $event['category_id'];
            }
            $bb_toolbar = cmsPage::getBBCodeToolbar('calendar', 1, 'forum');
            $smilies = cmsPage::getSmilesPanel('calendar');
            //Проверяем присоедиялся ли пользователь ко встрече
            $catigories = $model->getAllCategories();
            $inPage->setTitle("Редактировать событие");
            $smarty = $inCore->initSmarty('components', 'com_calendar_add.tpl');
            $smarty->assign('event', $event);
            $smarty->assign('edit', 1);
            $smarty->assign('catigories', $catigories);
            $smarty->assign('title', $event['title']);
            $smarty->assign('content', $event['content']);
            $smarty->assign('type', $event['type']);
            $smarty->assign('start_date', date("d.m.Y", $event['start_time']));
            $smarty->assign('start_hour', date("H", $event['start_time']));
            $smarty->assign('start_min', date("i", $event['start_time']));
            $smarty->assign('end_date', date("d.m.Y", $event['end_time']));
            $smarty->assign('end_hour', date("H", $event['end_time']));
            $smarty->assign('end_min', date("i", $event['end_time']));
            $smarty->assign('bb_toolbar', $bb_toolbar);
            $smarty->assign('smilies', $smilies);
            $smarty->display('com_calendar_add.tpl');
            return;
        }
    }
    if ($do == "add_parent") {
        if ($inUser->id == 0) {
            $inCore->redirectBack();
            return;
        }
        $event_id = $inCore->request('event_id', 'int', 0);
        $event = $model->getEvent($event_id);
        if (!$event) {
            $inCore->redirectBack();
            return;
        }
        $is_send = $inCore->inRequest('title');
        if ($is_send) {
            $title = $inCore->request('title', 'str');
            $date_start = $inCore->request('date_start', 'str');
            $date_end = $inCore->request('date_end', 'str');
            $hour_start = $inCore->request('hour_start', 'str');
            $hour_end = $inCore->request('hour_end', 'str');
            $min_start = $inCore->request('min_start', 'str');
            $min_end = $inCore->request('min_end', 'str');
            $content = $inCore->request('content', 'str');
            if (!$title || !$date_start || !$hour_start || !$hour_end || !$min_start || !$min_end) {
                cmsCore::addSessionMessage('Ой, что то не было заполнено...', 'error');
                $inCore->redirectBack();
                exit;
            } else {
                $start_time = strtotime($date_start . ' ' . $hour_start . ':' . $min_start);
                $end_time = strtotime($date_end . ' ' . $hour_end . ':' . $min_end);
                if ($data_end == "" or $date_end < $date_start) {
                    $data_end = $data_start;
                }
                $type = $event['type'];
                $model->addEvent($inUser->id, $type, $apx, $start_time, $end_time, $title, $content, $event['id']);
                $inCore->redirect('/calendar/event' . $event['id'] . ".html");
                exit;
            }
        }
        $bb_toolbar = cmsPage::getBBCodeToolbar('message', $cfg['img_on'], 'forum');
        $smilies = cmsPage::getSmilesPanel('message');
        $inPage->setTitle("Добавить вложеное событие");
        $smarty = $inCore->initSmarty('components', 'com_calendar_add.tpl');
        $smarty->assign('bb_toolbar', $bb_toolbar);
        $smarty->assign('smilies', $smilies);
        $smarty->assign('parent', "1");
        $smarty->assign('parent_title', $event['title']);
        $smarty->assign('title', "");
        $smarty->assign('content', "");
        $smarty->assign('type', $event['type']);
        $smarty->assign('start_date', date("d.m.Y", $event['start_time']));
        $smarty->assign('start_hour', date("H", $event['start_time']));
        $smarty->assign('start_min', date("i", $event['start_time']));
        $smarty->assign('end_date', date("d.m.Y", $event['end_time']));
        $smarty->assign('end_hour', date("H", $event['end_time']));
        $smarty->assign('end_min', date("i", $event['end_time']));
        $smarty->display('com_calendar_add.tpl');
        return;
    }
    if ($do == "event_signup") {
        //Если не залогинились то возвращаем обратно
        if ($inUser->id == 0) {
            $inCore->redirectBack();
            return;
        }
        $event_id = $inCore->request('event_id', 'int', 0);
        $event = $model->getEvent($event_id);
        //Если приватное событие то отправляем обратно
        if ($event["type"] == "private") {
            $inCore->redirectBack();
            return;
        }
        //Если мероприятие уже прошло говорим ай-яй-яй
        if ($event['start_time'] - time() < 0) {
            cmsCore::addSessionMessage('Присоединиться к мероприятию уже невозможно', 'error');
            $inCore->redirectBack();
            exit;
        }
        //Проверяем статус присоединения ко встрече
        if ($model->isSignup($event_id)) {
            //Если уже присоединялись то удаляем и выводим статус
            $model->deleteSignup($event_id);
            cmsCore::addSessionMessage('Вы отказались от участия в мероприятии ' . $event["title"], 'success');
            // Добавляем событие в ленту
            cmsActions::log('del_signup', array('object' => $event["title"], 'object_url' => '/calendar/event' . $event_id . '.html', 'object_id' => $event_id, 'target' => '', 'target_url' => '/calendar/event' . $event_id . '.html', 'target_id' => '0', 'description' => ''));
            $inCore->redirect('/calendar/event' . $event_id . '.html');
        } else {
            //Если не присоединялись то добавляем в базу и выводим статус
            //Если уже присоединялись то удаляем и выводим статус
            $model->addSignup($event["id"]);
            cmsCore::addSessionMessage('Вы присоединились к событию ' . $event["title"], 'success');
            // Добавляем событие в ленту
            cmsActions::log('add_signup', array('object' => $event["title"], 'object_url' => '/calendar/event' . $event_id . '.html', 'object_id' => $event["id"], 'target' => '', 'target_url' => '/calendar/event' . $event_id . '.html', 'target_id' => '0', 'description' => ''));
            $inCore->redirect('/calendar/event' . $event_id . '.html');
        }
        return;
    }
    //AJAX
    if ($do == "ajax_add") {
        $guest = TRUE;
        if ($inUser->id == 0 and $cfg['calendar_access'] == "all") {
            $guest = FALSE;
        }
        if ($inUser->id != 0 and $cfg['calendar_access'] == "users") {
            $guest = FALSE;
        }
        if ($inUser->is_admin) {
            $guest = FALSE;
        }
        if (!$guest) {
            $title = iconv("utf8", "cp1251", $inCore->request('title', 'str'));
            $type = $inCore->request('type', 'str');
            $date_start = $inCore->request('date_start', 'str');
            $date_end = $inCore->request('date_end', 'str');
            $hour_start = $inCore->request('hour_start', 'str');
            $hour_end = $inCore->request('hour_end', 'str');
            $min_start = $inCore->request('min_start', 'str');
            $min_end = $inCore->request('min_end', 'str');
            $content = iconv("utf8", "cp1251", $inCore->request('content', 'str'));
            $start_time = strtotime($date_start . ' ' . $hour_start . ':' . $min_start);
            $end_time = strtotime($date_end . ' ' . $hour_end . ':' . $min_end);
            if ($type == "prvate") {
                $category_id = 0;
                $type = "private";
            } else {
                if (is_numeric($type)) {
                    $category_id = $type;
                } else {
                    $category_id = 0;
                }
                $type = "public";
            }
            $event_id = $model->addEvent($inUser->id, $type, $category_id, $start_time, $end_time, $title, $content);
            $output = array();
            if (!$event_id) {
                $output['error'] = TRUE;
                $output['errortext'] = iconv("CP1251", "UTF-8", "Ошибка БД");
            } else {
                $output['error'] = FALSE;
                $event = $model->getEvent($event_id);
                $output['event_id'] = $event_id;
                $output['start'] = $event['start_time'];
                $output['end_time'] = $event['end_time'];
                if ($event['end_time'] - $event['start_time'] > 60 * 60 * 8) {
                    $output['allDay'] = TRUE;
                } else {
                    $output['allDay'] = FALSE;
                }
                $output['bg'] = $event['bg'];
                $output['tx'] = $event['tx'];
                if ($type != "private") {
                    cmsActions::log('add_event', array('object' => 'событие', 'object_url' => '/calendar/event' . $event_id . '.html', 'object_id' => $event_id, 'target' => $title, 'target_url' => '/calendar/event' . $event_id . '.html', 'target_id' => '0', 'description' => $title));
                }
            }
        } else {
            $output['error'] = TRUE;
            $output['errortext'] = iconv("CP1251", "UTF-8", "Ошибка доступа");
        }
        print json_encode($output);
        exit;
    }
    if ($do == "ajax_edit") {
        $type_act = $inCore->request('type', 'str');
        $id = $inCore->request('id', 'int');
        $dayDelta = $inCore->request('dayDelta', 'str');
        $minuteDelta = $inCore->request('minuteDelta', 'str');
        $event = $model->getEvent($id);
        if ($event['author_id'] == $inUser->id) {
            $type = $event['type'];
            $apx = "";
            $start_time = $event['start_time'];
            $end_time = $event['end_time'];
            $title = $event['title'];
            $content = $event['content'];
            $delta = $dayDelta * 24 * 60 * 60 + $minuteDelta * 60;
            if ($type_act == "drop") {
                $start_time = $start_time + $delta;
                $end_time = $end_time + $delta;
            }
            if ($type_act == "resize") {
                $end_time = $end_time + $delta;
            }
            $model->updateEvent($id, $type, $apx, $start_time, $end_time, $title, $content);
        } else {
            print "Ошибка доступа";
        }
        exit;
    }
    if ($do == "ajax_get_event") {
        $starttime = $inCore->request('start', 'int');
        $endtime = $inCore->request('end', 'int');
        $parent_id = $inCore->request('parent_id', 'parent_id');
        $category = $inCore->request('category', 'str');
        if ($category == "all" or !is_numeric($category)) {
            $category = FALSE;
        }
        if (!$parent_id) {
            $parent_id = 0;
        }
        $events = $model->getCalendar($starttime, $endtime, $category, $parent_id);
        $output = array();
        foreach ($events as $data) {
            $data['title'] = iconv("cp1251", "utf8", $data["title"]);
            $data['start'] = date("Y-m-d H:i:s", $data["start_time"]);
            $data['end'] = date("Y-m-d H:i:s", $data["end_time"]);
            $data['url'] = "/calendar/event" . $data['id'] . ".html";
            if ($data["author_id"] == $inUser->id) {
                $data['editable'] = true;
            } else {
                $data['editable'] = false;
            }
            if ($data["end_time"] - $data["start_time"] > 60 * 60 * 8) {
                $data['allDay'] = "true";
            }
            if (!$data['category_id']) {
                switch ($data["type"]) {
                    case "public":
                        $data['color'] = $cfg['public_bg_color'];
                        $data['textColor'] = $cfg['public_tx_color'];
                        break;
                    case "private":
                        $data['color'] = $cfg['private_bg_color'];
                        $data['textColor'] = $cfg['private_tx_color'];
                        break;
                }
            } else {
                $data['color'] = $data['bg'];
                $data['textColor'] = $data['tx'];
            }
            if ($data["type"] == "private" and $data['author_id'] != $inUser->id) {
            } else {
                $output[] = $data;
            }
        }
        print json_encode($output);
        exit;
    }
    if ($do == "isc_calendar") {
        header('Content-type: text/calendar; charset=utf-8');
        header('Content-Disposition: inline; filename=calendar.ics');
        echo "BEGIN:VCALENDAR\n";
        echo "VERSION:2.0\n";
        echo "PRODID:-//hacksw/handcal//NONSGML v1.0//EN'\n";
        $events = $model->getCalendar(time() - 60 * 60 * 24 * 30, time() + 60 * 60 * 24 * 30, 0);
        foreach ($events as $event) {
            if ($event['type'] == "public") {
                $title = iconv("cp1251", "utf8", $event["title"]);
                //$content = iconv("cp1251","utf8",str_replace("\n",'',$event["content"]));
                $dtstart = date("Ymd", $event["start_time"]) . "T" . date("His", $event["start_time"]) . "Z";
                $dtend = date("Ymd", $event["end_time"]) . "T" . date("His", $event["end_time"]) . "Z";
                echo "BEGIN:VEVENT\n";
                echo "DTSTART:{$dtstart}\n";
                echo "DTEND:{$dtend}\n";
                echo "SUMMARY:{$title}\n";
                //echo "DESCRIPTION:$content\n";
                echo "END:VEVENT\n";
            }
        }
        echo "END:VCALENDAR\n";
        exit;
    }
    if ($do == "ajax_add_form") {
        $start = strtotime($inCore->request('start', 'str'));
        $end = strtotime($inCore->request('end', 'str'));
        if (!$inUser->id) {
            print "Ошибка доступа.";
            exit;
        }
        $catigories = $model->getAllCategories();
        $bb_toolbar = cmsPage::getBBCodeToolbar('message', $cfg['img_on'], 'forum');
        $smilies = cmsPage::getSmilesPanel('message');
        $smarty = $inCore->initSmarty('components', 'com_calendar_add.tpl');
        $smarty->assign('catigories', $catigories);
        $smarty->assign('start_date', date("d.m.Y", $start));
        $smarty->assign('start_hour', date("H", $start));
        $smarty->assign('start_min', date("i", $start));
        $smarty->assign('end_date', date("d.m.Y", $end));
        $smarty->assign('end_hour', date("H", $end));
        $smarty->assign('end_min', date("i", $end));
        $smarty->assign('bb_toolbar', $bb_toolbar);
        $smarty->assign('smilies', $smilies);
        $smarty->display('com_calendar_add.tpl');
        exit;
    }
    //   FOTOLIB
    if ($do == "imagerotate") {
        $side = $md5 = $inCore->request('side', 'str');
        $image_id = $inCore->request('image_id', 'int');
        include 'fotolib.class.php';
        $foto = new FotoLib();
        $foto->Rotate($side, $image_id);
        $inCore->redirectBack();
        exit;
    }
    if ($do == "imagedelete") {
        include 'fotolib.class.php';
        $image_id = $inCore->request('image_id', 'int');
        $foto = new FotoLib();
        $foto->Delete($image_id);
        $inCore->redirectBack();
        exit;
    }
}
コード例 #3
0
}
if (!empty($scriptProperties['dateMinutes'])) {
    $minutes = round($delta / 60);
    if ($minutes < $scriptProperties['dateMinutes']) {
        if ($minutes > 0) {
            return declension($minutes, $modx->lexicon('da_minutes', array('minutes' => $minutes)));
        } else {
            return $modx->lexicon('da_minutes_less');
        }
    }
}
if (!empty($scriptProperties['dateHours'])) {
    $hours = round($delta / 3600);
    if ($hours < $scriptProperties['dateHours']) {
        if ($hours > 0) {
            return declension($hours, $modx->lexicon('da_hours', array('hours' => $hours)));
        } else {
            return $modx->lexicon('da_hours_less');
        }
    }
}
if (!empty($scriptProperties['dateDay'])) {
    switch (date('Y-m-d', $date)) {
        case date('Y-m-d'):
            $day = $modx->lexicon('da_today');
            break;
        case date('Y-m-d', mktime(0, 0, 0, date('m'), date('d') - 1, date('Y'))):
            $day = $modx->lexicon('da_yesterday');
            break;
        case date('Y-m-d', mktime(0, 0, 0, date('m'), date('d') + 1, date('Y'))):
            $day = $modx->lexicon('da_tomorrow');
コード例 #4
0
ファイル: page_header.php プロジェクト: ErR163/torrentpier
            $userdata['user_last_privmsg'] = $userdata['user_lastvisit'];
            db_update_userdata($userdata, array('user_last_privmsg' => $userdata['user_lastvisit']));
            $have_new_pm = $userdata['user_new_privmsg'] > 1;
        }
    }
    if (!$have_new_pm && $userdata['user_unread_privmsg']) {
        // synch unread pm count
        if (defined('IN_PM')) {
            $row = DB()->fetch_row("\n\t\t\t\tSELECT COUNT(*) AS pm_count\n\t\t\t\tFROM " . BB_PRIVMSGS . "\n\t\t\t\tWHERE privmsgs_to_userid = " . $userdata['user_id'] . "\n\t\t\t\t\tAND privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . "\n\t\t\t\tGROUP BY privmsgs_to_userid\n\t\t\t");
            $real_unread_pm_count = (int) $row['pm_count'];
            if ($userdata['user_unread_privmsg'] != $real_unread_pm_count) {
                $userdata['user_unread_privmsg'] = $real_unread_pm_count;
                db_update_userdata($userdata, array('user_unread_privmsg' => $real_unread_pm_count));
            }
        }
        $pm_info = declension($userdata['user_unread_privmsg'], $lang['UNREAD_PMS_DECLENSION'], $lang['UNREAD_PMS_FORMAT']);
        $have_unread_pm = true;
    }
}
$template->assign_vars(array('HAVE_NEW_PM' => $have_new_pm, 'HAVE_UNREAD_PM' => $have_unread_pm));
// The following assigns all _common_ variables that may be used at any point in a template
$template->assign_vars(array('SIMPLE_HEADER' => !empty($gen_simple_header), 'CONTENT_ENCODING' => $bb_cfg['lang'][$userdata['user_lang']]['encoding'], 'IN_ADMIN' => defined('IN_ADMIN'), 'SHOW_ADS' => !$logged_in || isset($bb_cfg['show_ads_users'][$user->id]) || !IS_AM && $user->show_ads, 'USER_HIDE_CAT' => BB_SCRIPT == 'index', 'USER_LANG' => $userdata['user_lang'], 'INCLUDE_BBCODE_JS' => !empty($page_cfg['include_bbcode_js']), 'USER_OPTIONS_JS' => IS_GUEST ? '{}' : Zend\Json\Json::encode($user->opt_js), 'USE_TABLESORTER' => !empty($page_cfg['use_tablesorter']), 'SITENAME' => $bb_cfg['sitename'], 'U_INDEX' => BB_ROOT . "index.php", 'T_INDEX' => sprintf($lang['FORUM_INDEX'], $bb_cfg['sitename']), 'IS_GUEST' => IS_GUEST, 'IS_USER' => IS_USER, 'IS_ADMIN' => IS_ADMIN, 'IS_MOD' => IS_MOD, 'IS_AM' => IS_AM, 'FORUM_PATH' => FORUM_PATH, 'FULL_URL' => FULL_URL, 'CURRENT_TIME' => sprintf($lang['CURRENT_TIME'], bb_date(TIMENOW, $bb_cfg['last_visit_date_format'], false)), 'S_TIMEZONE' => preg_replace('/\\(.*?\\)/', '', sprintf($lang['ALL_TIMES'], $lang['TZ'][str_replace(',', '.', floatval($bb_cfg['board_timezone']))])), 'BOARD_TIMEZONE' => $bb_cfg['board_timezone'], 'PM_INFO' => $pm_info, 'PRIVMSG_IMG' => $icon_pm, 'LOGGED_IN' => $logged_in, 'SESSION_USER_ID' => $userdata['user_id'], 'POINTS' => $userdata['user_points'], 'THIS_USER' => profile_url($userdata), 'THIS_AVATAR' => get_avatar($userdata['user_id'], $userdata['avatar_ext_id'], !bf($userdata['user_opt'], 'user_opt', 'dis_avatar')), 'SHOW_LOGIN_LINK' => !defined('IN_LOGIN'), 'AUTOLOGIN_DISABLED' => !$bb_cfg['allow_autologin'], 'S_LOGIN_ACTION' => LOGIN_URL, 'U_CUR_DOWNLOADS' => PROFILE_URL . $userdata['user_id'], 'U_FORUM' => "viewforum.php", 'U_GROUPS' => "group.php", 'U_LOGIN_LOGOUT' => $u_login_logout, 'U_MEMBERLIST' => "memberlist.php", 'U_MODCP' => "modcp.php", 'U_OPTIONS' => "profile.php?mode=editprofile", 'U_PRIVATEMSGS' => PM_URL . "?folder=inbox", 'U_PROFILE' => PROFILE_URL . $userdata['user_id'], 'U_READ_PM' => PM_URL . "?folder=inbox" . ($userdata['user_newest_pm_id'] && $userdata['user_new_privmsg'] == 1 ? "&mode=read&p={$userdata['user_newest_pm_id']}" : ''), 'U_REGISTER' => "profile.php?mode=register", 'U_SEARCH' => "search.php", 'U_SEND_PASSWORD' => "profile.php?mode=sendpassword", 'U_TERMS' => $bb_cfg['terms_and_conditions_url'], 'U_TRACKER' => "tracker.php", 'SHOW_SIDEBAR1' => !empty($page_cfg['show_sidebar1'][BB_SCRIPT]) || $bb_cfg['show_sidebar1_on_every_page'], 'SHOW_SIDEBAR2' => !empty($page_cfg['show_sidebar2'][BB_SCRIPT]) || $bb_cfg['show_sidebar2_on_every_page'], 'HTML_AGREEMENT' => LANG_DIR . 'html/user_agreement.html', 'HTML_COPYRIGHT' => LANG_DIR . 'html/copyright_holders.html', 'HTML_ADVERT' => LANG_DIR . 'html/advert.html', 'HTML_SIDEBAR_1' => LANG_DIR . 'html/sidebar1.html', 'HTML_SIDEBAR_2' => LANG_DIR . 'html/sidebar2.html', 'AVATARS_URL' => 'data/avatars', 'CAT_URL' => BB_ROOT . CAT_URL, 'DOWNLOAD_URL' => BB_ROOT . DOWNLOAD_URL, 'FORUM_URL' => BB_ROOT . FORUM_URL, 'GROUP_URL' => BB_ROOT . GROUP_URL, 'LOGIN_URL' => $bb_cfg['login_url'], 'NEWEST_URL' => '&amp;view=newest#newest', 'PM_URL' => $bb_cfg['pm_url'], 'POST_URL' => BB_ROOT . POST_URL, 'POSTING_URL' => $bb_cfg['posting_url'], 'PROFILE_URL' => BB_ROOT . PROFILE_URL, 'TOPIC_URL' => BB_ROOT . TOPIC_URL, 'AJAX_HTML_DIR' => AJAX_HTML_DIR, 'ONLY_NEW_POSTS' => ONLY_NEW_POSTS, 'ONLY_NEW_TOPICS' => ONLY_NEW_TOPICS, 'BOT_UID' => BOT_UID, 'COOKIE_MARK' => COOKIE_MARK, 'SID' => $userdata['session_id'], 'SID_HIDDEN' => '<input type="hidden" name="sid" value="' . $userdata['session_id'] . '" />', 'CHECKED' => HTML_CHECKED, 'DISABLED' => HTML_DISABLED, 'READONLY' => HTML_READONLY, 'SELECTED' => HTML_SELECTED, 'U_SEARCH_SELF_BY_LAST' => "search.php?uid={$userdata['user_id']}&amp;o=5", 'U_WATCHED_TOPICS' => "profile.php?mode=watch"));
if (!empty($page_cfg['show_torhelp'][BB_SCRIPT]) && !empty($userdata['torhelp'])) {
    $ignore_time = !empty($_COOKIE['torhelp']) ? (int) $_COOKIE['torhelp'] : 0;
    if (TIMENOW > $ignore_time) {
        if ($ignore_time) {
            bb_setcookie('torhelp', '', COOKIE_EXPIRED);
        }
        $sql = "\n\t\t\tSELECT topic_id, topic_title\n\t\t\tFROM " . BB_TOPICS . "\n\t\t\tWHERE topic_id IN(" . $userdata['torhelp'] . ")\n\t\t\tLIMIT 8\n\t\t";
        $torhelp_topics = array();
        foreach (DB()->fetch_rowset($sql) as $row) {
コード例 #5
0
ファイル: forum.index.php プロジェクト: space77/mwfv3_sp
        echo $forumitem['forum_desc'];
        ?>
</span>
            </td>
            <td rowspan="3" class="col3"><span><?php 
        echo $forumitem['num_topics'];
        ?>
</span> <?php 
        echo declension($forumitem['num_topics'], array($lang['l_theme1'], $lang['l_theme2'], $lang['l_theme3']));
        ?>
</td>
            <td rowspan="3" class="col4"><span><?php 
        echo $forumitem['num_posts'];
        ?>
</span> <?php 
        echo declension($forumitem['num_posts'], array($lang['l_post1'], $lang['l_post2'], $lang['l_post3']));
        ?>
</td>
        </tr>
        <tr>
            <td class="col1"><img src="<?php 
        echo $config['template_href'];
        ?>
images/icons/time.gif"></td>
            <td><?php 
        echo $lang['lastreplyin'];
        ?>
 <a href="<?php 
        echo $forumitem['linktolastpost'];
        ?>
" title="<?php 
コード例 #6
0
     }
     if (isset($user_ratio) && isset($min_ratio_warn) && $user_ratio < $min_ratio_warn && TR_RATING_LIMITS || $bt_userdata['u_down_total'] < MIN_DL_FOR_RATIO) {
         $template->assign_vars(array('SHOW_RATIO_WARN' => true, 'RATIO_WARN_MSG' => sprintf($lang['BT_RATIO_WARNING_MSG'], $min_ratio_dl, $bb_cfg['ratio_url_help'])));
     }
 }
 if (!$dl_allowed) {
     $template->assign_block_vars('postrow.attach.tor_reged', array());
     $template->assign_vars(array('TOR_BLOCKED' => true, 'TOR_BLOCKED_MSG' => sprintf($lang['BT_LOW_RATIO_FOR_DL'], round($user_ratio, 2), "search.php?dlu={$bt_user_id}&amp;dlc=1")));
 } else {
     $template->assign_block_vars('postrow.attach.tor_reged', array('DOWNLOAD_NAME' => $display_name, 'TRACKER_LINK' => $tracker_link, 'ATTACH_ID' => $attach_id, 'TOR_SILVER_GOLD' => $tor_type, 'TOR_FROZEN' => !IS_AM ? isset($bb_cfg['tor_frozen'][$tor_info['tor_status']]) && !(isset($bb_cfg['tor_frozen_author_download'][$tor_info['tor_status']]) && $userdata['user_id'] == $tor_info['poster_id']) ? true : '' : '', 'TOR_STATUS_TEXT' => $lang['TOR_STATUS_NAME'][$tor_info['tor_status']], 'TOR_STATUS_ICON' => $bb_cfg['tor_icons'][$tor_info['tor_status']], 'TOR_STATUS_BY' => $tor_info['checked_user_id'] && $is_auth['auth_mod'] ? '<span title="' . bb_date($tor_info['checked_time']) . '"> &middot; ' . profile_url($tor_info) . ' &middot; <i>' . delta_time($tor_info['checked_time']) . $lang['TOR_BACK'] . '</i></span>' : '', 'TOR_STATUS_SELECT' => build_select('sel_status', array_flip($lang['TOR_STATUS_NAME']), TOR_APPROVED), 'TOR_STATUS_REPLY' => $bb_cfg['tor_comment'] && !IS_GUEST && in_array($tor_info['tor_status'], $bb_cfg['tor_reply']) && $userdata['user_id'] == $tor_info['poster_id'] && $t_data['topic_status'] != TOPIC_LOCKED, 'S_UPLOAD_IMAGE' => $upload_image, 'U_DOWNLOAD_LINK' => $download_link, 'DL_LINK_CLASS' => isset($bt_userdata['user_status']) ? $dl_link_css[$bt_userdata['user_status']] : 'genmed', 'DL_TITLE_CLASS' => isset($bt_userdata['user_status']) ? $dl_status_css[$bt_userdata['user_status']] : 'gen', 'FILESIZE' => $tor_file_size, 'MAGNET' => $tor_magnet, 'HASH' => strtoupper(bin2hex($tor_info['info_hash'])), 'DOWNLOAD_COUNT' => sprintf($lang['DOWNLOAD_NUMBER'], $download_count), 'REGED_TIME' => bb_date($tor_info['reg_time']), 'REGED_DELTA' => delta_time($tor_info['reg_time']), 'TORRENT_SIZE' => humn_size($tor_size), 'COMPLETED' => sprintf($lang['DOWNLOAD_NUMBER'], $tor_info['complete_count'])));
     if ($comment) {
         $template->assign_block_vars('postrow.attach.tor_reged.comment', array('COMMENT' => $comment));
     }
 }
 if ($bb_cfg['show_tor_info_in_dl_list']) {
     $template->assign_vars(array('SHOW_DL_LIST' => true, 'SHOW_DL_LIST_TOR_INFO' => true, 'TOR_SIZE' => humn_size($tor_size), 'TOR_LONGEVITY' => delta_time($tor_info['reg_time']), 'TOR_COMPLETED' => declension($tor_info['complete_count'], 'times')));
 }
 // Show peers
 if ($show_peers) {
     // Sorting order in full mode
     if ($s_mode == 'full') {
         $full_mode_order = 'tr.remain';
         $full_mode_sort_dir = 'ASC';
         if (isset($_REQUEST['psortasc'])) {
             $full_mode_sort_dir = 'ASC';
         } else {
             if (isset($_REQUEST['psortdesc'])) {
                 $full_mode_sort_dir = 'DESC';
             }
         }
         if (isset($_REQUEST['porder'])) {
コード例 #7
0
ファイル: functions.php プロジェクト: ErR163/torrentpier
 function spellDelta($first, $last, $from = 'auto')
 {
     if ($last < $first) {
         $old_first = $first;
         $first = $last;
         $last = $old_first;
     }
     if ($from == 'auto') {
         $from = 'year';
         $diff = $last - $first;
         foreach ($this->auto_granularity as $seconds_count => $granule) {
             if ($diff < $seconds_count) {
                 $from = $granule;
                 break;
             }
         }
     }
     // Solve data delta.
     $delta = $this->getDelta($first, $last);
     if (!$delta) {
         return false;
     }
     // Make spellable phrase.
     $parts = array();
     $intervals = $GLOBALS['lang']['DELTA_TIME']['INTERVALS'];
     foreach (array_reverse($delta) as $k => $n) {
         if (!$n) {
             if ($k == $from) {
                 if (!$parts) {
                     $parts[] = declension($n, $this->intervals[$k], $this->format);
                 }
                 break;
             }
             continue;
         }
         $parts[] = declension($n, $this->intervals[$k], $this->format);
         if ($k == $from) {
             break;
         }
     }
     return join(' ', $parts);
 }
コード例 #8
0
function calendar()
{
    $inCore = cmsCore::getInstance();
    $inPage = cmsPage::getInstance();
    $inUser = cmsUser::getInstance();
    $inCore->loadModel('calendar');
    $model = new cms_model_calendar();
    $do = $inCore->request('do', 'str', 'view');
    $cfg = $inCore->loadComponentConfig('calendar');
    if ($do == 'view') {
        $inPage->setTitle("Календарь событий");
        $inPage->addPathway("Календарь", "/calendar");
        $smarty = $inPage->initTemplate('components', 'com_calendar_view.tpl');
        $category_id = $inCore->request('category_id', 'int', 0);
        $can_add = FALSE;
        $moderated = TRUE;
        if ($cfg['group_' . $inUser->group_id]) {
            $can_add = TRUE;
            $moderated = FALSE;
        } elseif ($cfg['m_group_' . $inUser->group_id]) {
            $can_add = TRUE;
            $moderated = TRUE;
        }
        if ($inUser->is_admin) {
            $can_add = TRUE;
        }
        $catigories = $model->getAllCategories();
        if ($category_id) {
            $category = $category_id;
            $cat = $model->getCategory($category);
            $inPage->addPathway($cat['name']);
        } else {
            $category = "all";
        }
        if ($cfg['calendar_view'] == 'afisha') {
            $inCore->redirect('/calendar/list.html');
        }
        $smarty->assign('can_add', $can_add);
        $smarty->assign('cfg', $cfg);
        $smarty->assign('catigories', $catigories);
        $smarty->assign('category', $category);
        $smarty->display('com_calendar_view.tpl');
        return;
    }
    if ($do == "list") {
        $inPage->addPathway("Календарь", "/calendar");
        $inPage->addPathway("Афиша");
        $per_day = 10;
        //Количество сообытий в дне максимум
        $display_days = 5;
        //количество дней которые показывается на странице
        $dayt = 60 * 60 * 24;
        //Продолжительность дня в секундах
        $start_time = strtotime(date('Y-m-d', time()) . " 00:00:00") - $dayt;
        //Определяем утро сегодняшнего дня
        $output = array();
        for ($i = 0; $i < $display_days; $i++) {
            $start = strtotime(date('Y-m-d', $start_time + $dayt * $i));
            $n = date("N", $start + 1);
            //Определяем заголовок блока дня
            if ($i == 0) {
                $day['title'] = "Сегодня";
            } elseif ($i == 1) {
                $day['title'] = "Завтра";
            } else {
                $day['title'] = $inCore->dateFormat(date('Y-m-d H:i:s', $start_time + $dayt * ($i + 1)));
            }
            $day['events'] = $model->getCalendar($start, $start + 86400);
            //Определяем активные встречи за временной период
            $output[] = $day;
        }
        $inPage->setTitle("Календарь событий");
        $smarty = $inPage->initTemplate('components', 'com_calendar_list.tpl');
        $smarty->assign('events', $output);
        $smarty->assign('cfg', $cfg);
        $smarty->display('com_calendar_list.tpl');
    }
    if ($do == "view_event") {
        $event_id = $inCore->request('event_id', 'int', 0);
        $event = $model->getEvent($event_id);
        /*FOTOLIB*/
        include 'fotolib.class.php';
        $foto = new FotoLib();
        //Проверяем можем ли добавлять фото
        $allow_add_foto = $foto->addAcces("calendar", $event);
        if ($_FILES) {
            $foto->uploadFoto($_FILES, "calendar", $event_id);
        }
        $images = $foto->loadImages("calendar", $event_id);
        /*FOTOLIB*/
        if (!$event) {
            cmsCore::addSessionMessage('Ошибка запроса', 'error');
            $inCore->redirect('/calendar');
            exit;
        } elseif ($event['hide'] == 1 and !$inUser->is_admin) {
            cmsCore::addSessionMessage('Ошибка доступа', 'error');
            $inCore->redirect('/calendar');
            exit;
        } else {
            if ($event['type'] == 'private' and $event['author_id'] != $inUser->id) {
                cmsCore::addSessionMessage('Ошибка запроса', 'error');
                $inCore->redirect('/calendar');
                exit;
            }
            $msg = $inCore->parseSmiles($event['content'], true);
            if (count($event['parent']) != 0) {
                $delta = $event['end_time'] - $event['start_time'];
                $day = date("d", $event['start_time']);
                $month = date("n", $event['start_time']) - 1;
                //Яваскриптики считают с 0
                $year = date("Y", $event['start_time']);
                if ($delta < 24 * 60 * 60) {
                    $calendar_view = "agendaDay";
                    if (date("d", $event['start_time']) != date("d", $event['end_time'])) {
                        //Если меньше 24 часов но всё же в разные дни включаем недельный вид
                        $calendar_view = "agendaWeek";
                    }
                } elseif ($delta < 7 * 24 * 60 * 60) {
                    $calendar_view = "agendaWeek";
                } else {
                    $calendar_view = "month";
                }
                $events_string = "";
                foreach ($event['parent'] as $parent) {
                    $events_string .= "{\n\t  id    : '" . $parent['id'] . "',\n\t  title : '" . str_replace("'", '"', $parent['title']) . "',\n\t  start : '" . date("Y-m-d H:i:s", $parent['start_time']) . "',\n\t  end   : '" . date("Y-m-d H:i:s", $parent['end_time']) . "',\n\t  url   : '/calendar/event" . $parent['id'] . ".html',";
                    if ($parent['end_time'] - $parent['start_time'] > 60 * 60 * 8) {
                        $events_string .= "allDay: true,";
                    } else {
                        $events_string .= "allDay: false,";
                    }
                    switch ($parent['type']) {
                        case "public":
                            if ($parent['author_id'] == $inUser->id) {
                                $events_string .= "color: '#B9C3BC',\n";
                            } else {
                                $events_string .= "color: '#C3BCB9',\n";
                            }
                            $events_string .= "textColor: '#000000',\n";
                            break;
                        case "private":
                            $events_string .= "color: '#3366CC'\n";
                    }
                    $events_string .= "},";
                }
            }
            $issignup = $model->isSignup($event_id);
            $singups_user = $model->getSingupsUsers($event_id);
            $inPage->setTitle('Просмотр события "' . $event['title'] . '"');
            $inPage->addPathway("Календарь", "/calendar");
            if ($event['parent_id']) {
                $parent = $model->getEvent($event['parent_id']);
                $inPage->addPathway($parent['title'], "/calendar/event" . $parent['id'] . ".html");
            }
            $inPage->addPathway($event['title'], "/calendar/event" . $event_id . ".html");
            $smarty = $inPage->initTemplate('components', 'com_calendar_event_view.tpl');
            $smarty->assign('user_id', $inUser->id);
            $smarty->assign('event', $event);
            $smarty->assign('content', $msg);
            $smarty->assign('parent', $event['parent']);
            $smarty->assign('calendar_view', $calendar_view);
            $smarty->assign('events_string', $events_string);
            $smarty->assign('year', $year);
            $smarty->assign('month', $month);
            $smarty->assign('day', $day);
            $smarty->assign('start_time', date("d.m.Y H:i", $event['start_time']));
            $smarty->assign('end_time', date("d.m.Y H:i", $event['end_time']));
            $smarty->assign('issngnup', $issignup);
            $smarty->assign('singups_user', $singups_user);
            $smarty->assign('images', $images);
            //fotolib
            $smarty->assign('allow_add_foto', $allow_add_foto);
            //fotolib
            if ($event['start_time'] - time() < 0) {
                $status = "Прошедшее событие";
            } else {
                if ($event['start_time'] - time() > 86400) {
                    $status = 'Осталось ' . declension(round(($event['start_time'] - time()) / 86400), array("день", "дня", "дней"));
                } else {
                    $status = 'Осталось ' . declension(round(($event['start_time'] - time()) / 3600), array("час", "часа", "часов"));
                }
            }
            $smarty->assign('status', $status);
            if ($inUser->id == $event['author_id'] or $inUser->is_admin) {
                $smarty->assign('admin', TRUE);
            }
            $smarty->display('com_calendar_event_view.tpl');
            $inCore->includeComments();
            comments('calendar', $event_id);
            return;
        }
    }
    if ($do == "delete_event") {
        if ($inUser->id == 0) {
            $inCore->redirect('/');
            exit;
        }
        $event_id = $inCore->request('event_id', 'int', 0);
        $deleted = $model->deleteEvent($event_id);
        if ($deleted) {
            cmsCore::addSessionMessage('Ваше мероприятие удалено!', 'success');
            $inCore->redirect('/calendar');
            exit;
        } else {
            cmsCore::addSessionMessage('Ошибка', 'error');
            $inCore->redirect('/calendar');
            exit;
        }
    }
    if ($do == "edit_event") {
        if ($inUser->id == 0) {
            $inCore->redirect('/');
            exit;
        }
        $event_id = $inCore->request('event_id', 'int', 0);
        $event = $model->getEvent($event_id);
        if ($event["author_id"] != $inUser->id and !$inUser->is_admin) {
            cmsCore::addSessionMessage('Ошибка доступа', 'error');
            $inCore->redirectBack();
            exit;
        }
        if ($inUser->is_admin) {
            $can_moderate = true;
        }
        $is_send = $inCore->inRequest('title');
        if ($is_send) {
            $title = $inCore->request('title', 'str');
            $type = $inCore->request('type', 'str');
            $date_start = $inCore->request('date_start', 'str');
            $date_end = $inCore->request('date_end', 'str');
            $hour_start = $inCore->request('hour_start', 'str');
            $hour_end = $inCore->request('hour_end', 'str');
            $min_start = $inCore->request('min_start', 'str');
            $min_end = $inCore->request('min_end', 'str');
            $content = $inCore->request('content', 'str');
            if ($can_moderate) {
                $m_hide = $inCore->request('hide', 'str');
                if ($m_hide == "on") {
                    $hide = 1;
                } else {
                    $hide = 0;
                }
            }
            if (!$title || !$type || !$date_start || !$hour_start || !$hour_end || !$min_start || !$min_end) {
                cmsCore::addSessionMessage('Ой, что то не было заполнено...', 'error');
                $inCore->redirectBack();
                exit;
            } else {
                $start_time = strtotime($date_start . ' ' . $hour_start . ':' . $min_start);
                if ($data_end == "" or $data_end < $data_start) {
                    $data_end = $data_start;
                }
                $end_time = strtotime($date_end . ' ' . $hour_end . ':' . $min_end);
                if (!is_numeric($type)) {
                    $category_id = "0";
                } else {
                    $category_id = $type;
                    $type = "public";
                }
                $update = $model->updateEvent($event_id, $type, $category_id, $start_time, $end_time, $title, $content, $hide);
                if ($update) {
                    cmsCore::addSessionMessage('Ваше мероприятие изменено!', 'success');
                    $inCore->redirect('/calendar/event' . $event_id . '.html');
                    exit;
                } else {
                    cmsCore::addSessionMessage('Ошибка добавления!', 'error');
                    $inCore->redirect('/calendar/edit' . $event_id . '.html');
                    exit;
                }
            }
        } else {
            $event = $model->getEvent($event_id);
            if (!$event) {
                cmsCore::addSessionMessage('Ошибка запроса тут', 'error');
                $inCore->redirect('/calendar');
                exit;
            }
            if ($event['category_id']) {
                $event['type'] = $event['category_id'];
            }
            $bb_toolbar = cmsPage::getBBCodeToolbar('calendar', 1, 'forum');
            $smilies = cmsPage::getSmilesPanel('calendar');
            //Проверяем присоедиялся ли пользователь ко встрече
            $catigories = $model->getAllCategories();
            $inPage->setTitle("Редактировать событие");
            $smarty = $inPage->initTemplate('components', 'com_calendar_add.tpl');
            $smarty->assign('event', $event);
            $smarty->assign('edit', 1);
            $smarty->assign('cfg', $cfg);
            $smarty->assign('catigories', $catigories);
            $smarty->assign('title', $event['title']);
            $smarty->assign('content', $event['content']);
            $smarty->assign('type', $event['type']);
            $smarty->assign('start_date', date("d.m.Y", $event['start_time']));
            $smarty->assign('start_hour', date("H", $event['start_time']));
            $smarty->assign('start_min', date("i", $event['start_time']));
            $smarty->assign('end_date', date("d.m.Y", $event['end_time']));
            $smarty->assign('end_hour', date("H", $event['end_time']));
            $smarty->assign('end_min', date("i", $event['end_time']));
            $smarty->assign('bb_toolbar', $bb_toolbar);
            $smarty->assign('smilies', $smilies);
            $smarty->assign('can_moderate', $can_moderate);
            $smarty->display('com_calendar_add.tpl');
            return;
        }
    }
    if ($do == "event_signup") {
        //Если не залогинились то возвращаем обратно
        if ($inUser->id == 0) {
            $inCore->redirectBack();
            return;
        }
        $event_id = $inCore->request('event_id', 'int', 0);
        $event = $model->getEvent($event_id);
        //Если приватное событие то отправляем обратно
        if ($event["type"] == "private") {
            $inCore->redirectBack();
            return;
        }
        //Если мероприятие уже прошло говорим ай-яй-яй
        if ($event['start_time'] - time() < 0) {
            cmsCore::addSessionMessage('Присоединиться к мероприятию уже невозможно', 'error');
            $inCore->redirectBack();
            exit;
        }
        //Проверяем статус присоединения ко встрече
        if ($model->isSignup($event_id)) {
            //Если уже присоединялись то удаляем и выводим статус
            $model->deleteSignup($event_id);
            cmsCore::addSessionMessage('Вы отказались от участия в мероприятии ' . $event["title"], 'success');
            // Добавляем событие в ленту
            cmsActions::log('del_signup', array('object' => $event["title"], 'object_url' => '/calendar/event' . $event_id . '.html', 'object_id' => $event_id, 'target' => '', 'target_url' => '/calendar/event' . $event_id . '.html', 'target_id' => '0', 'description' => ''));
            $inCore->redirect('/calendar/event' . $event_id . '.html');
        } else {
            //Если не присоединялись то добавляем в базу и выводим статус
            //Если уже присоединялись то удаляем и выводим статус
            $model->addSignup($event["id"]);
            cmsCore::addSessionMessage('Вы присоединились к событию ' . $event["title"], 'success');
            // Добавляем событие в ленту
            cmsActions::log('add_signup', array('object' => $event["title"], 'object_url' => '/calendar/event' . $event_id . '.html', 'object_id' => $event["id"], 'target' => '', 'target_url' => '/calendar/event' . $event_id . '.html', 'target_id' => '0', 'description' => ''));
            $inCore->redirect('/calendar/event' . $event_id . '.html');
        }
        return;
    }
    //AJAX
    if ($do == "ajax_add") {
        $can_add = FALSE;
        $moderated = TRUE;
        if ($cfg['group_' . $inUser->group_id] or $inUser->is_admin) {
            $can_add = TRUE;
            $moderated = FALSE;
        } elseif ($cfg['m_group_' . $inUser->group_id]) {
            $can_add = TRUE;
            $moderated = TRUE;
        }
        if ($can_add) {
            $title = $inCore->request('title', 'str');
            $type = $inCore->request('type', 'str');
            $date_start = $inCore->request('date_start', 'str');
            $date_end = $inCore->request('date_end', 'str');
            $hour_start = $inCore->request('hour_start', 'str');
            $hour_end = $inCore->request('hour_end', 'str');
            $min_start = $inCore->request('min_start', 'str');
            $min_end = $inCore->request('min_end', 'str');
            $content = $inCore->request('content', 'str');
            $parent_id = $inCore->request('parent_id', 'int');
            $m_hide = $inCore->request('hide', 'str');
            if ($m_hide == "on" or $moderated) {
                $hide = 1;
            } else {
                $hide = 0;
            }
            $start_time = strtotime($date_start . ' ' . $hour_start . ':' . $min_start);
            $end_time = strtotime($date_end . ' ' . $hour_end . ':' . $min_end);
            if ($start_hour < $cfg['calendar_minTime']) {
                $output['error'] = TRUE;
                $output['errortext'] = "Событие начинается слишком рано";
            }
            if ($end_hour > $cfg['calendar_maxTime']) {
                $output['error'] = TRUE;
                $output['errortext'] = "Событие заканчивается слишком поздно";
            }
            if ($end_hour == $cfg['calendar_maxTime'] and $end_min != 0) {
                $output['error'] = TRUE;
                $output['errortext'] = "Событие заканчивается слишком поздно";
            }
            if ($type == "private") {
                $category_id = 0;
                $type = "private";
            } else {
                if (is_numeric($type)) {
                    $category_id = $type;
                } else {
                    $category_id = 0;
                }
                $type = "public";
            }
            if ($parent_id) {
                $parent = $model->getEvent($parent_id);
                if (!$parent) {
                    $output['error'] = TRUE;
                    $output['errortext'] = "Родительское событие не найдено";
                } elseif ($parent['user_id'] != $inUser->id or !$inUser->is_admin) {
                    $output['error'] = TRUE;
                    $output['errortext'] = "Ошибка прав доступа";
                } elseif ($parent['hide'] == 1) {
                    $output['error'] = TRUE;
                    $output['errortext'] = "Нельзя добавлять события в скрытое событие";
                }
            }
            if (!$output['error']) {
                $event_id = $model->addEvent($inUser->id, $type, $category_id, $start_time, $end_time, $title, $content, $parent_id, $hide);
            }
            $output = array();
            if (!$event_id) {
                $output['error'] = TRUE;
                $output['errortext'] = "Ошибка БД";
            } else {
                $output['error'] = FALSE;
                $event = $model->getEvent($event_id);
                $output['event_id'] = $event_id;
                $output['start'] = $event['start_time'];
                $output['end'] = $event['end_time'];
                $output['hide'] = $hide;
                if ($event['end_time'] - $event['start_time'] > 60 * 60 * 8) {
                    $output['allDay'] = TRUE;
                } else {
                    $output['allDay'] = FALSE;
                }
                $output['bg'] = $event['bg'];
                $output['tx'] = $event['tx'];
                if ($type != "private" and $hide != 1) {
                    cmsActions::log('add_event', array('object' => 'событие', 'object_url' => '/calendar/event' . $event_id . '.html', 'object_id' => $event_id, 'target' => $title, 'target_url' => '/calendar/event' . $event_id . '.html', 'target_id' => '0', 'description' => $title));
                }
            }
        } else {
            $output['error'] = TRUE;
            $output['errortext'] = "Ошибка доступа";
        }
        print json_encode($output);
        exit;
    }
    if ($do == "ajax_edit") {
        $type_act = $inCore->request('type', 'str');
        $id = $inCore->request('id', 'int');
        $dayDelta = $inCore->request('dayDelta', 'str');
        $minuteDelta = $inCore->request('minuteDelta', 'str');
        $event = $model->getEvent($id);
        if ($event['author_id'] == $inUser->id or $inUser->is_admin) {
            $type = $event['type'];
            $category_id = $event['category_id'];
            $start_time = $event['start_time'];
            $end_time = $event['end_time'];
            $title = $event['title'];
            $content = $event['content'];
            $delta = $dayDelta * 24 * 60 * 60 + $minuteDelta * 60;
            if ($type_act == "drop") {
                $start_time = $start_time + $delta;
                $end_time = $end_time + $delta;
            }
            if ($type_act == "resize") {
                if ($end_time - $start_time > 0) {
                    $end_time = $end_time + $delta;
                } else {
                    print "Ошибка смещения";
                }
            }
            $model->updateEvent($id, $type, $category_id, $start_time, $end_time, $title, $content);
        } else {
            print "Ошибка доступа";
        }
        exit;
    }
    if ($do == "ajax_get_event") {
        $starttime = $inCore->request('start', 'int');
        $endtime = $inCore->request('end', 'int');
        $parent_id = $inCore->request('parent_id', 'parent_id');
        $category = $inCore->request('category', 'int');
        if ($category == "all" and !is_numeric($category)) {
            $category = FALSE;
        }
        if (!$parent_id) {
            $parent_id = 0;
        }
        if ($inUser->is_admin) {
            $show_hidden = true;
        }
        $events = $model->getCalendar($starttime, $endtime, $category, $parent_id, $show_hidden);
        $output = array();
        foreach ($events as $data) {
            $data['start'] = date("Y-m-d H:i:s", $data["start_time"]);
            $data['end'] = date("Y-m-d H:i:s", $data["end_time"]);
            $data['url'] = "/calendar/event" . $data['id'] . ".html";
            //       $data['image'] = "/components/calendar/images/no_image.png";
            if ($data["author_id"] == $inUser->id or $inUser->is_admin) {
                $data['editable'] = true;
            } else {
                $data['editable'] = false;
            }
            if ($data["end_time"] - $data["start_time"] > 60 * 60 * 8) {
                $data['allDay'] = "true";
            }
            if (!$data['category_id']) {
                switch ($data["type"]) {
                    case "public":
                        $data['color'] = $cfg['public_bg_color'];
                        $data['textColor'] = $cfg['public_tx_color'];
                        break;
                    case "private":
                        $data['color'] = $cfg['private_bg_color'];
                        $data['textColor'] = $cfg['private_tx_color'];
                        break;
                }
            } else {
                $data['color'] = $data['bg'];
                $data['textColor'] = $data['tx'];
            }
            if ($data["type"] == "private" and $data['author_id'] != $inUser->id) {
            } else {
                $output[] = $data;
            }
        }
        print json_encode($output);
        exit;
    }
    if ($do == "isc_calendar") {
        header('Content-type: text/calendar; charset=utf-8');
        header('Content-Disposition: inline; filename=calendar.ics');
        echo "BEGIN:VCALENDAR\n";
        echo "VERSION:2.0\n";
        echo "PRODID:-//hacksw/handcal//NONSGML v1.0//EN'\n";
        $events = $model->getCalendar(time() - 60 * 60 * 24 * 30, time() + 60 * 60 * 24 * 30, 0);
        foreach ($events as $event) {
            if ($event['type'] == "public") {
                $title = $event["title"];
                $dtstart = date("Ymd", $event["start_time"] - 60 * 60 * 4) . "T" . date("His", $event["start_time"] - 60 * 60 * 4);
                $dtend = date("Ymd", $event["end_time"] - 60 * 60 * 4) . "T" . date("His", $event["end_time"] - 60 * 60 * 4);
                echo "BEGIN:VEVENT\n";
                echo "DTSTART:{$dtstart}\n";
                echo "DTEND:{$dtend}\n";
                echo "SUMMARY:{$title}\n";
                echo "END:VEVENT\n";
            }
        }
        echo "END:VCALENDAR\n";
        exit;
    }
    if ($do == "ajax_add_form") {
        $start = strtotime($inCore->request('start', 'str'));
        $end = strtotime($inCore->request('end', 'str'));
        if ($start < strtotime('now 00:00:00')) {
            echo 'error';
            exit;
        }
        if (!$cfg['group_' . $inUser->group_id] and !$inUser->is_admin and !$cfg['m_group_' . $inUser->group_id]) {
            echo 'error';
            exit;
        }
        //Коректность времени добавления
        $start_hour = date("H", $start);
        if ($start_hour < $cfg['calendar_minTime']) {
            $start_hour = $cfg['calendar_minTime'];
        }
        $end_hour = date("H", $end);
        $end_min = date("i", $end);
        if ($end_hour > $cfg['calendar_maxTime']) {
            $end_hour = $cfg['calendar_maxTime'];
            $end_min = "00";
        }
        if ($inUser->is_admin) {
            $can_moderate = true;
        }
        $catigories = $model->getAllCategories();
        $bb_toolbar = cmsPage::getBBCodeToolbar('message', $cfg['img_on'], 'forum');
        $smilies = cmsPage::getSmilesPanel('message');
        $smarty = $inPage->initTemplate('components', 'com_calendar_add.tpl');
        $smarty->assign('catigories', $catigories);
        $smarty->assign('start_date', date("d.m.Y", $start));
        $smarty->assign('start_hour', $start_hour);
        $smarty->assign('start_min', date("i", $start));
        $smarty->assign('end_date', date("d.m.Y", $end));
        $smarty->assign('end_hour', $end_hour);
        $smarty->assign('end_min', $end_min);
        $smarty->assign('can_moderate', $can_moderate);
        $smarty->assign('bb_toolbar', $bb_toolbar);
        $smarty->assign('smilies', $smilies);
        $smarty->assign('cfg', $cfg);
        //print_r($cfg);
        $smarty->display('com_calendar_add.tpl');
        exit;
    }
    if ($do == "ajax_get_config") {
        print json_encode($cfg);
        exit;
    }
    //   FOTOLIB
    if ($do == "imagerotate") {
        $side = $md5 = $inCore->request('side', 'str');
        $image_id = $inCore->request('image_id', 'int');
        include 'fotolib.class.php';
        $foto = new FotoLib();
        $foto->Rotate($side, $image_id);
        $inCore->redirectBack();
        exit;
    }
    if ($do == "imagedelete") {
        include 'fotolib.class.php';
        $image_id = $inCore->request('image_id', 'int');
        $foto = new FotoLib();
        $foto->Delete($image_id);
        $inCore->redirectBack();
        exit;
    }
    if ($do == "ajax_format_date") {
        print cmsCore::dateFormat(date('Y-m-d H:i:s', $inCore->request('time', 'int')), 0, 0, 0);
        exit;
    }
}