auth->makePermissions([dcAuth::PERMISSION_USAGE, dcAuth::PERMISSION_CONTENT_ADMIN])); # Objects $per = new periodical(); # Default values $action = isset($_POST['action']) ? $_POST['action'] : ''; $starting_script = ''; # Default value for period $period_id = null; $period_title = __('One post per day'); $period_pub_nb = 1; $period_pub_int = 'day'; $period_curdt = date('Y-m-d H:i', time()); $period_enddt = date('Y-m-d H:i', time() + 31536000); //one year $bad_period_curdt = false; $bad_period_enddt = false; # Get period if (!empty($_REQUEST['period_id'])) { $rs = $per->getPeriods([ 'periodical_id' => $_REQUEST['period_id'] ]); if ($rs->isEmpty()) { dcCore::app()->error->add(__('This period does not exist.')); $period_id = null; } else { $period_id = $rs->periodical_id; $period_title = $rs->periodical_title; $period_pub_nb = $rs->periodical_pub_nb; $period_pub_int = $rs->periodical_pub_int; $period_curdt = date('Y-m-d H:i', strtotime($rs->periodical_curdt)); $period_enddt = date('Y-m-d H:i', strtotime($rs->periodical_enddt)); } } # Set period if ($action == 'setperiod') { # Get POST values if (!empty($_POST['period_title'])) { $period_title = $_POST['period_title']; } if (!empty($_POST['period_pub_nb'])) { $period_pub_nb = abs((integer) $_POST['period_pub_nb']); } if (!empty($_POST['period_pub_int']) && in_array($_POST['period_pub_int'], $per->getTimesCombo()) ) { $period_pub_int = $_POST['period_pub_int']; } if (!empty($_POST['period_curdt'])) { try { $period_curdt = strtotime($_POST['period_curdt']); if ($period_curdt == false || $period_curdt == -1) { $bad_period_curdt = true; throw new Exception(__('Invalid date')); } $period_curdt = date('Y-m-d H:i', $period_curdt); } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } } if (!empty($_POST['period_enddt'])) { try { $period_enddt = strtotime($_POST['period_enddt']); if ($period_enddt == false || $period_enddt == -1) { $bad_period_enddt = true; throw new Exception(__('Invalid date')); } $period_enddt = date('Y-m-d H:i', $period_enddt); } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } } # Check period title and dates $old_titles = $per->getPeriods([ 'periodical_title' => $period_title ]); if (!$old_titles->isEmpty()) { while($old_titles->fetch()) { if (!$period_id || $old_titles->periodical_id != $period_id) { dcCore::app()->error->add(__('Period title is already taken')); } } } if (empty($period_title)) { dcCore::app()->error->add(__('Period title is required')); } if (strtotime($period_curdt) > strtotime($period_enddt)) { dcCore::app()->error->add(__('Start date must be older than end date')); } # If no error, set period if (!dcCore::app()->error->flag()) { $cur = $per->openCursor(); $cur->periodical_title = $period_title; $cur->periodical_curdt = $period_curdt; $cur->periodical_enddt = $period_enddt; $cur->periodical_pub_int = $period_pub_int; $cur->periodical_pub_nb = $period_pub_nb; # Update period if ($period_id) { $per->updPeriod($period_id, $cur); dcAdminNotices::addSuccessNotice( __('Period successfully updated.') ); # Create period } else { $period_id = $per->addPeriod($cur); dcAdminNotices::addSuccessNotice( __('Period successfully created.') ); } if (!empty($_POST['redir'])) { http::redirect($_POST['redir']); } else { dcCore::app()->adminurl->redirect('admin.plugin.periodical', ['part' => 'period', 'period_id' => $period_id], '#period'); } } } # Actions on related posts if (!dcCore::app()->error->flag() && $period_id && $action && !empty($_POST['periodical_entries'])) { # Publish posts if ($action == 'publish') { try { foreach($_POST['periodical_entries'] as $id) { $id = (integer) $id; dcCore::app()->blog->updPostStatus($id, 1); $per->delPost($id); } dcAdminNotices::addSuccessNotice( __('Entries successfully published.') ); if (!empty($_POST['redir'])) { http::redirect($_POST['redir']); } else { dcCore::app()->adminurl->redirect('admin.plugin.periodical', ['part' => 'period', 'period_id' => $period_id], '#posts'); } } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } } # Unpublish posts if ($action == 'unpublish') { try { foreach($_POST['periodical_entries'] as $id) { $id = (integer) $id; dcCore::app()->blog->updPostStatus($id,0); $per->delPost($id); } dcAdminNotices::addSuccessNotice( __('Entries successfully unpublished.') ); if (!empty($_POST['redir'])) { http::redirect($_POST['redir']); } else { dcCore::app()->adminurl->redirect('admin.plugin.periodical', ['part' => 'period', 'period_id' => $period_id], '#posts'); } } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } } # Remove posts from periodical if ($action == 'remove_post_periodical') { try { foreach($_POST['periodical_entries'] as $id) { $id = (integer) $id; $per->delPost($id); } dcAdminNotices::addSuccessNotice( __('Entries successfully removed.') ); if (!empty($_POST['redir'])) { http::redirect($_POST['redir']); } else { dcCore::app()->adminurl->redirect('admin.plugin.periodical', ['part' => 'period', 'period_id' => $period_id], '#posts'); } } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } } } # Prepare combos for posts list if ($period_id) { # Filters $post_filter = new adminPostFilter(); $post_filter->add('part', 'period'); $params = $post_filter->params(); $params['periodical_id'] = $period_id; $params['no_content'] = true; # Get posts try { $posts = $per->getPosts($params); $counter = $per->getPosts($params, true); $post_list = new adminPeriodicalList(dcCore::app(), $posts, $counter->f(0)); } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } $starting_script = dcPage::jsLoad(dcPage::getPF('periodical/js/checkbox.js')) . $post_filter->js(dcCore::app()->adminurl->get('admin.plugin.periodical', ['part' => 'period', 'period_id' => $period_id], '&').'#posts'); } # Display echo '