periodical/inc/index.periods.php

131 lines
3.6 KiB
PHP
Raw Normal View History

2021-10-24 07:43:26 +00:00
<?php
/**
* @brief periodical, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
2022-11-14 19:55:22 +00:00
dcPage::check(dcCore::app()->auth->makePermissions([dcAuth::PERMISSION_USAGE, dcAuth::PERMISSION_CONTENT_ADMIN]));
2021-10-24 07:43:26 +00:00
# Objects
2022-11-14 19:55:22 +00:00
$per = new periodical();
2021-10-24 07:43:26 +00:00
# Default values
$action = isset($_POST['action']) ? $_POST['action'] : '';
# Delete periods and related posts links
if ($action == 'deleteperiods' && !empty($_POST['periods'])) {
try {
foreach($_POST['periods'] as $id) {
$id = (integer) $id;
$per->delPeriodPosts($id);
$per->delPeriod($id);
}
2022-11-14 19:55:22 +00:00
dcAdminNotices::addSuccessNotice(
2021-10-24 07:43:26 +00:00
__('Periods removed.')
);
if (!empty($_POST['redir'])) {
http::redirect($_POST['redir']);
} else {
2022-11-14 19:55:22 +00:00
dcCore::app()->adminurl->redirect('admin.plugin.periodical', ['part' => 'periods']);
2021-10-24 07:43:26 +00:00
}
} catch (Exception $e) {
2022-11-14 19:55:22 +00:00
dcCore::app()->error->add($e->getMessage());
2021-10-24 07:43:26 +00:00
}
}
# Delete periods related posts links (without delete periods)
if ($action == 'emptyperiods' && !empty($_POST['periods'])) {
try {
foreach($_POST['periods'] as $id) {
$id = (integer) $id;
$per->delPeriodPosts($id);
}
2022-11-14 19:55:22 +00:00
dcAdminNotices::addSuccessNotice(
2021-10-24 07:43:26 +00:00
__('Periods emptied.')
);
if (!empty($_POST['redir'])) {
http::redirect($_POST['redir']);
} else {
2022-11-14 19:55:22 +00:00
dcCore::app()->adminurl->redirect('admin.plugin.periodical', ['part' => 'periods']);
2021-10-24 07:43:26 +00:00
}
} catch (Exception $e) {
2022-11-14 19:55:22 +00:00
dcCore::app()->error->add($e->getMessage());
2021-10-24 07:43:26 +00:00
}
}
$combo_action = [
__('empty periods') => 'emptyperiods',
__('delete periods') => 'deleteperiods'
];
# Filters
2022-11-14 19:55:22 +00:00
$p_filter = new adminGenericFilter(dcCore::app(), 'periodical');
2021-10-24 07:43:26 +00:00
$p_filter->add('part', 'periods');
$params = $p_filter->params();
# Get periods
try {
$periods = $per->getPeriods($params);
$counter = $per->getPeriods($params, true);
2022-11-14 19:55:22 +00:00
$period_list = new adminPeriodicalList(dcCore::app(), $periods, $counter->f(0));
2021-10-24 07:43:26 +00:00
} catch (Exception $e) {
2022-11-14 19:55:22 +00:00
dcCore::app()->error->add($e->getMessage());
2021-10-24 07:43:26 +00:00
}
# Display
echo
'<html><head><title>' . __('Periodical') . '</title>' .
dcPage::jsLoad(dcPage::getPF('periodical/js/checkbox.js')) .
2022-11-14 19:55:22 +00:00
$p_filter->js(dcCore::app()->adminurl->get('admin.plugin.periodical', ['part' => 'periods'])) .
2021-10-24 07:43:26 +00:00
'</head>' .
'<body>' .
dcPage::breadcrumb([
2021-10-24 22:18:18 +00:00
__('Plugins') => '',
2021-10-24 07:43:26 +00:00
__('Periodical') => ''
]) .
dcPage::notices() .
'<p class="top-add">
2022-11-14 19:55:22 +00:00
<a class="button add" href="' . dcCore::app()->admin->getPageURL() . '&amp;part=period">' . __('New period') . '</a>
2021-10-24 07:43:26 +00:00
</p>';
# Filters
$p_filter->display('admin.plugin.periodical', form::hidden('p', 'periodical') . form::hidden('part', 'periods'));
# Periods list
$period_list->periodDisplay($p_filter,
2022-11-14 19:55:22 +00:00
'<form action="' . dcCore::app()->admin->getPageURL() . '" method="post" id="form-periods">' .
2021-10-24 07:43:26 +00:00
'%s' .
'<div class="two-cols">' .
'<p class="col checkboxes-helpers"></p>' .
'<p class="col right">' . __('Selected periods action:') . ' ' .
form::combo('action', $combo_action) .
'<input type="submit" value="' . __('ok') . '" /></p>' .
2022-11-14 19:55:22 +00:00
dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.periodical', array_merge(['p' => 'periodical'], $p_filter->values(true))) .
dcCore::app()->formNonce() .
2021-10-24 07:43:26 +00:00
'</div>' .
'</form>'
);
dcPage::helpBlock('periodical');
echo '</body></html>';