Esempio n. 1
0
function ModifyHolidays()
{
    global $sourcedir, $scripturl, $txt, $context;
    // Submitting something...
    if (isset($_REQUEST['delete']) && !empty($_REQUEST['holiday'])) {
        checkSession();
        foreach ($_REQUEST['holiday'] as $id => $value) {
            $_REQUEST['holiday'][$id] = (int) $id;
        }
        // Now the IDs are "safe" do the delete...
        require_once $sourcedir . '/Subs-Calendar.php';
        removeHolidays($_REQUEST['holiday']);
    }
    $listOptions = array('id' => 'holiday_list', 'title' => $txt['current_holidays'], 'items_per_page' => 20, 'base_href' => $scripturl . '?action=admin;area=managecalendar;sa=holidays', 'default_sort_col' => 'name', 'get_items' => array('file' => $sourcedir . '/Subs-Calendar.php', 'function' => 'list_getHolidays'), 'get_count' => array('file' => $sourcedir . '/Subs-Calendar.php', 'function' => 'list_getNumHolidays'), 'no_items_label' => $txt['holidays_no_entries'], 'columns' => array('name' => array('header' => array('value' => $txt['holidays_title']), 'data' => array('sprintf' => array('format' => '<a href="' . $scripturl . '?action=admin;area=managecalendar;sa=editholiday;holiday=%1$d">%2$s</a>', 'params' => array('id_holiday' => false, 'title' => false))), 'sort' => array('default' => 'title', 'reverse' => 'title DESC')), 'date' => array('header' => array('value' => $txt['date']), 'data' => array('function' => create_function('$rowData', '
						global $txt;

						// Recurring every year or just a single year?
						$year = $rowData[\'year\'] == \'0004\' ? sprintf(\'(%1$s)\', $txt[\'every_year\']) : $rowData[\'year\'];

						// Construct the date.
						return sprintf(\'%1$d %2$s %3$s\', $rowData[\'day\'], $txt[\'months\'][(int) $rowData[\'month\']], $year);
					'), 'class' => 'windowbg'), 'sort' => array('default' => 'event_date', 'reverse' => 'event_date DESC')), 'check' => array('header' => array('value' => '<input type="checkbox" onclick="invertAll(this, this.form);" class="input_check" />'), 'data' => array('sprintf' => array('format' => '<input type="checkbox" name="holiday[%1$d]" class="input_check" />', 'params' => array('id_holiday' => false)), 'style' => 'text-align: center'))), 'form' => array('href' => $scripturl . '?action=admin;area=managecalendar;sa=holidays'), 'additional_rows' => array(array('position' => 'below_table_data', 'value' => '
					<a href="' . $scripturl . '?action=admin;area=managecalendar;sa=editholiday" style="margin: 0 1em">[' . $txt['holidays_add'] . ']</a>
					<input type="submit" name="delete" value="' . $txt['quickmod_delete_selected'] . '" class="button_submit" />', 'style' => 'text-align: right;')));
    require_once $sourcedir . '/Subs-List.php';
    createList($listOptions);
    //loadTemplate('ManageCalendar');
    $context['page_title'] = $txt['manage_holidays'];
    // Since the list is the only thing to show, use the default list template.
    $context['default_list'] = 'holiday_list';
    $context['sub_template'] = 'show_list';
}
 /**
  * This function is used for adding/editing a specific holiday
  *
  * @uses ManageCalendar template, edit_holiday sub template
  */
 public function action_editholiday()
 {
     global $txt, $context;
     //We need this, really..
     require_once SUBSDIR . '/Calendar.subs.php';
     loadTemplate('ManageCalendar');
     $context['is_new'] = !isset($_REQUEST['holiday']);
     $context['page_title'] = $context['is_new'] ? $txt['holidays_add'] : $txt['holidays_edit'];
     $context['sub_template'] = 'edit_holiday';
     // Cast this for safety...
     if (isset($_REQUEST['holiday'])) {
         $_REQUEST['holiday'] = (int) $_REQUEST['holiday'];
     }
     // Submitting?
     if (isset($_POST[$context['session_var']]) && (isset($_REQUEST['delete']) || $_REQUEST['title'] != '')) {
         checkSession();
         // Not too long good sir?
         $_REQUEST['title'] = Util::substr($_REQUEST['title'], 0, 60);
         $_REQUEST['holiday'] = isset($_REQUEST['holiday']) ? (int) $_REQUEST['holiday'] : 0;
         if (isset($_REQUEST['delete'])) {
             removeHolidays($_REQUEST['holiday']);
         } else {
             $date = strftime($_REQUEST['year'] <= 4 ? '0004-%m-%d' : '%Y-%m-%d', mktime(0, 0, 0, $_REQUEST['month'], $_REQUEST['day'], $_REQUEST['year']));
             if (isset($_REQUEST['edit'])) {
                 editHoliday($_REQUEST['holiday'], $date, $_REQUEST['title']);
             } else {
                 insertHoliday($date, $_REQUEST['title']);
             }
         }
         redirectexit('action=admin;area=managecalendar;sa=holidays');
     }
     // Default states...
     if ($context['is_new']) {
         $context['holiday'] = array('id' => 0, 'day' => date('d'), 'month' => date('m'), 'year' => '0000', 'title' => '');
     } else {
         $context['holiday'] = getHoliday($_REQUEST['holiday']);
     }
     // Last day for the drop down?
     $context['holiday']['last_day'] = (int) strftime('%d', mktime(0, 0, 0, $context['holiday']['month'] == 12 ? 1 : $context['holiday']['month'] + 1, 0, $context['holiday']['month'] == 12 ? $context['holiday']['year'] + 1 : $context['holiday']['year']));
 }