Esempio n. 1
0
/**
 * Show the form for adding a new agenda item. This is the same function that is used whenever we are editing an
 * agenda item. When the id parameter is empty (default behaviour), then we show an empty form, else we are editing and
 * we have to retrieve the information that is in the database and use this information in the forms.
 * @author Patrick Cool <*****@*****.**>, Ghent University
 * @param integer id, the id of the agenda item we are editing. By default this is empty which means that we are adding an
 * 		 agenda item.
 * @deprecated
 */
function show_add_form($id = '', $type = null)
{
    $htmlHeadXtra[] = to_javascript();
    $course_info = null;
    $agendaObj = new Agenda();
    // if the id is set then we are editing an agenda item
    if (!empty($id)) {
        $course_info = api_get_course_info();
        if (!empty($course_info)) {
            $agendaObj->set_course($course_info);
            $agendaObj->type = 'course';
        } else {
            if (api_is_platform_admin() && $type == 'platform') {
                $agendaObj->type = 'admin';
            } else {
                $agendaObj->type = 'personal';
            }
        }
        $agendaItem = $agendaObj->get_event($id);
        $title = $agendaItem['title'];
        $content = $agendaItem['description'];
        // start date
        if ($agendaItem['start_date'] != '0000-00-00 00:00:00') {
            $agendaItem['start_date'] = api_get_local_time($agendaItem['start_date']);
            list($datepart, $timepart) = explode(" ", $agendaItem['start_date']);
            list($year, $month, $day) = explode("-", $datepart);
            list($hours, $minutes, $seconds) = explode(":", $timepart);
        }
        // end date
        if (!empty($agendaItem['end_date']) && $agendaItem['end_date'] != '0000-00-00 00:00:00') {
            $agendaItem['end_date'] = api_get_local_time($agendaItem['end_date']);
            list($datepart, $timepart) = explode(" ", $agendaItem['end_date']);
            list($end_year, $end_month, $end_day) = explode("-", $datepart);
            list($end_hours, $end_minutes, $end_seconds) = explode(":", $timepart);
        } else {
            if ($agendaItem['all_day']) {
                $end_year = $year;
                $end_month = $month;
                $end_day = $day;
                $end_hours = $hours;
                $end_minutes = $minutes;
                $end_seconds = $seconds;
            }
        }
        // attachments
        //edit_added_resources("Agenda", $id);
        //$to = $item_2_edit['to'];
    } else {
        $to = load_edit_users(TOOL_CALENDAR_EVENT, $id);
    }
    // we start a completely new item, we do not come from the resource linker
    if (isset($_GET['originalresource']) && $_GET['originalresource'] !== "no" and $_GET['action'] == "add") {
        $_SESSION["formelements"] = null;
        unset_session_resources();
    }
    $origin = isset($_GET['origin']) ? Security::remove_XSS($_GET['origin']) : null;
    $action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : null;
    $idAttach = isset($_GET['id_attach']) ? Security::remove_XSS($_GET['id_attach']) : null;
    $course_url = empty($course_info) ? null : api_get_cidreq();
    $id = isset($id) ? intval($id) : null;
    $url = api_get_self() . '?type=' . Security::remove_XSS($type) . '&origin=' . $origin . '&' . $course_url . '&sort=asc&toolgroup=' . api_get_group_id() . '&action=' . Security::remove_XSS($_GET['action']);
    $form = new FormValidator('new_calendar_item', 'post', $url, null, array('enctype' => 'multipart/form-data'));
    $form->addElement('hidden', 'id', $id);
    $form->addElement('hidden', 'action', $action);
    $form->addElement('hidden', 'id_attach', $idAttach);
    $form->addElement('hidden', 'sort', 'asc');
    $form->addElement('hidden', 'submit_event', 'ok');
    // The form title
    if (isset($id) and $id != '') {
        $form_title = get_lang('ModifyCalendarItem');
    } else {
        $form_title = get_lang('AddCalendarItem');
    }
    $form->addElement('header', $form_title);
    $form->addElement('text', 'title', get_lang('ItemTitle'));
    // selecting the users / groups
    $group_id = api_get_group_id();
    if (empty($id)) {
        if (isset($group_id) && !empty($group_id)) {
            $form->addElement('hidden', 'selected_form[0]', "GROUP:'.{$group_id}.'");
            $form->addElement('hidden', 'To', 'true');
            //$form .= '<input type="hidden" name="selected_form[0]" value="GROUP:'.$group_id.'"/>';
            //$form .= '<input type="hidden" name="To" value="true"/>';
        } else {
            $agendaObj->show_to_form($form, $to);
        }
    }
    // start date and time
    $form->addElement('text', 'start_date', get_lang('StartDate'));
    $form->addElement('text', 'end_date', get_lang('EndDate'));
    // Repeating the calendar item
    if (empty($id)) {
        $form->addElement('label', null, '<a href="javascript://" onclick="return plus_repeated_event();"><span id="plus2">
             <img style="vertical-align:middle;" src="../img/div_show.gif" alt="" />&nbsp;' . get_lang('RepeatEvent') . '</span>
            </a>');
        $form->addElement('html', '<div id="options2" style="display: none;">');
        $form->addElement('checkbox', 'repeat', get_lang('RepeatEvent'));
        $form->addElement('select', 'repeat_type', get_lang('RepeatType'), $agendaObj->getRepeatTypes());
        $form->addElement('text', 'repeat_end_day', get_lang('RepeatEnd'));
        $form->addElement('html', '</div>');
    }
    if (isset($agendaItem['all_day'])) {
        $checked = null;
        if ($agendaItem['all_day']) {
            $checked = 'checked';
        }
        $form->addElement('checkbox', 'all_day', get_lang('AllDay'));
    }
    $form->addElement('html_editor', 'content', get_lang('Description'));
    $form->addElement('checkbox', 'add_announcement', get_lang('AddAnnouncement') . '&nbsp(' . get_lang('SendMail') . ')');
    if ($agendaObj->type == 'course') {
        // File attachment
        $form->addElement('file', 'user_upload', get_lang('AddAnAttachment'));
        $form->addElement('textarea', 'file_comment', get_lang('Comment'));
        $form->add_progress_bar();
    }
    if (isset($_GET['id'])) {
        $text = get_lang('ModifyEvent');
    } else {
        $text = get_lang('AgendaAdd');
    }
    $form->addElement('button', 'submit', $text);
    return $form->return_form();
}
Esempio n. 2
0
/**
 * Show the form for adding a new agenda item. This is the same function that is used whenever we are editing an
 * agenda item. When the id parameter is empty (default behaviour), then we show an empty form, else we are editing and
 * we have to retrieve the information that is in the database and use this information in the forms.
 * @author Patrick Cool <*****@*****.**>, Ghent University
 * @param integer id, the id of the agenda item we are editing. By default this is empty which means that we are adding an
 * 		 agenda item.
 */
function show_add_form($id = '', $type = null)
{
    $showImg = Display::return_icon('div_show.gif');
    $hideImg = Display::return_icon('div_hide.gif');
    $MonthsLong = api_get_months_long();
    $htmlHeadXtra[] = to_javascript();
    // the default values for the forms
    if (!isset($_GET['originalresource'])) {
        $day = date('d');
        $month = date('m');
        $year = date('Y');
        $hours = 9;
        $minutes = '00';
        $title = null;
        $content = null;
        $repeat = false;
    } else {
        // we are coming from the resource linker so there might already have been some information in the form.
        // When we clicked on the button to add resources we stored every form information into a session and now we
        // are doing the opposite thing: getting the information out of the session and putting it into variables to
        // display it in the forms.
        $title = $form_elements['title'];
        $content = $form_elements['content'];
        $id = $form_elements['id'];
        $to = $form_elements['to'];
        $repeat = $form_elements['repeat'];
    }
    //	switching the send to all/send to groups/send to users
    if (isset($_POST['To']) && $_POST['To']) {
        $day = $_POST['fday'];
        $month = $_POST['fmonth'];
        $year = $_POST['fyear'];
        $hours = $_POST['fhour'];
        $minutes = $_POST['fminute'];
        $end_day = $_POST['end_fday'];
        $end_month = $_POST['end_fmonth'];
        $end_year = $_POST['end_fyear'];
        $end_hours = $_POST['end_fhour'];
        $end_minutes = $_POST['end_fminute'];
        $title = $_POST['title'];
        $content = $_POST['content'];
        // the invisible fields
        $action = $_POST['action'];
        $id = $_POST['id'];
        $repeat = !empty($_POST['repeat']) ? true : false;
    }
    $default_no_empty_end_date = 0;
    $course_info = null;
    // if the id is set then we are editing an agenda item
    if (!empty($id)) {
        $course_info = api_get_course_info();
        $agendaObj = new Agenda();
        if (!empty($course_info)) {
            $agendaObj->set_course($course_info);
            $agendaObj->type = 'course';
        } else {
            if (api_is_platform_admin() && $type == 'platform') {
                $agendaObj->type = 'admin';
            } else {
                $agendaObj->type = 'personal';
            }
        }
        $agendaItem = $agendaObj->get_event($id);
        $title = $agendaItem['title'];
        $content = $agendaItem['description'];
        // start date
        if ($agendaItem['start_date'] != '0000-00-00 00:00:00') {
            $agendaItem['start_date'] = api_get_local_time($agendaItem['start_date']);
            list($datepart, $timepart) = explode(" ", $agendaItem['start_date']);
            list($year, $month, $day) = explode("-", $datepart);
            list($hours, $minutes, $seconds) = explode(":", $timepart);
        }
        // end date
        if (!empty($agendaItem['end_date']) && $agendaItem['end_date'] != '0000-00-00 00:00:00') {
            $agendaItem['end_date'] = api_get_local_time($agendaItem['end_date']);
            list($datepart, $timepart) = explode(" ", $agendaItem['end_date']);
            list($end_year, $end_month, $end_day) = explode("-", $datepart);
            list($end_hours, $end_minutes, $end_seconds) = explode(":", $timepart);
        }
    } else {
        $to = load_edit_users(TOOL_CALENDAR_EVENT, $id);
    }
    $content = stripslashes($content);
    $title = stripslashes($title);
    $origin = isset($_GET['origin']) ? Security::remove_XSS($_GET['origin']) : null;
    $course_url = empty($course_info) ? null : api_get_cidreq();
    // The form title
    if (isset($id) and $id != '') {
        $form_title = get_lang('ModifyCalendarItem');
    } else {
        $form_title = get_lang('AddCalendarItem');
    }
    $url = api_get_self() . '?type=' . Security::remove_XSS($type) . '&origin=' . $origin . '&' . $course_url . "&sort=asc&toolgroup=" . api_get_group_id() . '&action=' . Security::remove_XSS($_GET['action']);
    $idAttach = isset($_REQUEST['id_attach']) ? intval($_REQUEST['id_attach']) : null;
    $form = new FormValidator('new_calendar_item', 'post', $url, array('enctype' => 'multipart/form-data'));
    $form->addElement('header', $form_title);
    $form->addElement('hidden', 'id', $id);
    $form->addElement('hidden', 'action', Security::remove_XSS($_GET['action']));
    $form->addElement('hidden', 'id_attach', $idAttach);
    $form->addElement('hidden', 'sort', 'asc');
    $form->addElement('hidden', 'submit_event', 'ok');
    $form->addElement('text', 'title', get_lang('ItemTitle'));
    // selecting the users / groups
    $group_id = api_get_group_id();
    if (empty($id)) {
        CourseManager::addUserGroupMultiSelect($form, array());
    }
    $form->addElement('datepicker', 'start_date', get_lang('StartDate'), array('form_name' => $form->getAttribute('name')));
    $form->addElement('datepicker', 'end_date', get_lang('EndDate'), array('form_name' => $form->getAttribute('name')));
    // Repeating the calendar item
    if (empty($id)) {
        $form->addElement('label', null, '
            <a href="javascript://" onclick="return plus_repeated_event();">
            <span id="plus2">
            ' . $showImg . '&nbsp;' . get_lang('RepeatEvent') . '
            </span></a>');
        $form->addElement('html', '<div id="options2" style="display:none">');
        $form->addElement('checkbox', 'repeat', null, get_lang('RepeatEvent'));
        $options = array('daily' => get_lang('RepeatDaily'), 'weekly' => get_lang('RepeatWeekly'), 'monthlyByDate' => get_lang('RepeatMonthlyByDate'), 'yearly' => get_lang('RepeatYearly'));
        $form->addElement('select', 'repeat_type', get_lang('RepeatType'), $options);
        $form->addElement('datepicker', 'repeat_end_day', get_lang('RepeatEnd'));
        $form->addElement('html', '</div>');
        if (isset($agendaItem['all_day'])) {
            $checked = null;
            if ($agendaItem['all_day']) {
                $checked = 'checked';
            }
            $form->addElement('checkbox', 'all_day', null, get_lang('AllDay'));
        }
        $form->addElement('html_editor', 'content', get_lang('Description'));
        if (isset($agendaObj) && $agendaObj->type == 'course') {
            $form->addElement('file', 'user_upload', null, get_lang('AddAnAttachment'));
            $form->addElement('text', 'file_comment', null, get_lang('Comment'));
        }
        if (isset($_GET['id'])) {
            $class = 'save';
            $text = get_lang('ModifyEvent');
        } else {
            $class = 'add';
            $text = get_lang('AgendaAdd');
        }
        $form->addElement('button', 'submit', $text);
        $form->display();
    }
}