Пример #1
0
 /**
  * Constructor
  */
 function HTML_QuickForm_datepickerdate($elementName = null, $elementLabel = null, $attributes = null)
 {
     global $myMinYear, $myMaxYear;
     $js_form_name = $attributes['form_name'];
     unset($attributes['form_name']);
     HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
     $this->_persistantFreeze = true;
     $this->_appendName = true;
     $this->_type = 'datepicker';
     $popup_link = '<a href="javascript:openCalendar(\'' . $js_form_name . '\',\'' . $elementName . '\')"><img src="' . api_get_path(WEB_IMG_PATH) . 'calendar_select.gif" style="vertical-align:middle;" alt="Select Date" /></a>';
     $special_chars = array('D', 'l', 'd', 'M', 'F', 'm', 'y', 'H', 'a', 'A', 's', 'i', 'h', 'g', ' ');
     foreach ($special_chars as $index => $char) {
         $popup_link = str_replace($char, "\\" . $char, $popup_link);
     }
     $lang_code = api_get_language_isocode();
     // If translation not available in PEAR::HTML_QuickForm_date, add the Chamilo-translation
     if (!array_key_exists($lang_code, $this->_locale)) {
         $this->_locale[$lang_code]['months_long'] = api_get_months_long();
     }
     $this->_options['format'] = 'dFY ' . $popup_link;
     $this->_options['minYear'] = date('Y') - 5;
     $this->_options['maxYear'] = date('Y') + 10;
     $this->_options['language'] = $lang_code;
     //$this->_options['addEmptyOption'] = true;
     //$this->_options['emptyOptionValue'] = 0;
     //$this->_options['emptyOptionText'] = ' -- ';
 }
Пример #2
0
    /**
     * Constructor
     */
    public function HTML_QuickForm_datepicker($elementName = null, $elementLabel = null, $attributes = null, $optionIncrement = null)
    {
        $js_form_name = api_get_unique_id();
        HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
        $this->_persistantFreeze = true;
        $this->_appendName = true;
        $this->_type = 'datepicker';
        $popup_link = '<a href="javascript:openCalendar(\'' . $js_form_name . '\',\'' . $elementName . '\')">
		<img src="' . api_get_path(WEB_IMG_PATH) . 'calendar_select.gif" style="vertical-align:middle;" alt="Select Date" /></a>';
        $hour_minute_devider = get_lang("HourMinuteDivider");
        $special_chars = array('D', 'l', 'd', 'M', 'F', 'm', 'y', 'H', 'a', 'A', 's', 'i', 'h', 'g', ' ');
        foreach ($special_chars as $char) {
            $popup_link = str_replace($char, "\\" . $char, $popup_link);
            $hour_minute_devider = str_replace($char, "\\" . $char, $hour_minute_devider);
        }
        $lang_code = api_get_language_isocode();
        // If translation not available in PEAR::HTML_QuickForm_date, add the Chamilo-translation
        if (!array_key_exists($lang_code, $this->_locale)) {
            $this->_locale[$lang_code]['months_long'] = api_get_months_long();
        }
        $this->_options['format'] = 'dFY ' . $popup_link . '   H ' . $hour_minute_devider . ' i';
        $this->_options['minYear'] = date('Y') - 5;
        $this->_options['maxYear'] = date('Y') + 10;
        $this->_options['language'] = $lang_code;
        if (isset($optionIncrement)) {
            $this->_options['optionIncrement']['i'] = intval($optionIncrement);
        }
    }
Пример #3
0
 /**
  * Show some stats about the number of logins
  * @param string $type month, hour or day
  */
 static function print_login_stats($type)
 {
     $table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
     $access_url_rel_user_table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
     $current_url_id = api_get_current_access_url_id();
     if (api_is_multiple_url_enabled()) {
         $table_url = ", {$access_url_rel_user_table}";
         $where_url = " WHERE login_user_id=user_id AND access_url_id='" . $current_url_id . "'";
         $where_url_last = ' AND login_date > DATE_SUB(NOW(),INTERVAL 1 %s)';
     } else {
         $table_url = '';
         $where_url = '';
         $where_url_last = ' WHERE login_date > DATE_SUB(NOW(),INTERVAL 1 %s)';
     }
     switch ($type) {
         case 'month':
             $months = api_get_months_long();
             $period = get_lang('PeriodMonth');
             $sql = "SELECT DATE_FORMAT( login_date, '%Y-%m' ) AS stat_date , count( login_id ) AS number_of_logins FROM " . $table . $table_url . $where_url . " GROUP BY stat_date ORDER BY login_date ";
             $sql_last_x = "SELECT DATE_FORMAT( login_date, '%Y-%m' ) AS stat_date , count( login_id ) AS number_of_logins FROM " . $table . $table_url . $where_url . sprintf($where_url_last, 'YEAR') . " GROUP BY stat_date ORDER BY login_date ";
             break;
         case 'hour':
             $period = get_lang('PeriodHour');
             $sql = "SELECT DATE_FORMAT( login_date, '%H' ) AS stat_date , count( login_id ) AS number_of_logins FROM " . $table . $table_url . $where_url . " GROUP BY stat_date ORDER BY stat_date ";
             $sql_last_x = "SELECT DATE_FORMAT( login_date, '%H' ) AS stat_date , count( login_id ) AS number_of_logins FROM " . $table . $table_url . $where_url . sprintf($where_url_last, 'DAY') . " GROUP BY stat_date ORDER BY stat_date ";
             break;
         case 'day':
             $week_days = api_get_week_days_long();
             $period = get_lang('PeriodDay');
             $sql = "SELECT DATE_FORMAT( login_date, '%w' ) AS stat_date , count( login_id ) AS number_of_logins FROM " . $table . $table_url . $where_url . " GROUP BY stat_date ORDER BY DATE_FORMAT( login_date, '%w' ) ";
             $sql_last_x = "SELECT DATE_FORMAT( login_date, '%w' ) AS stat_date , count( login_id ) AS number_of_logins FROM " . $table . $table_url . $where_url . sprintf($where_url_last, 'WEEK') . " GROUP BY stat_date ORDER BY DATE_FORMAT( login_date, '%w' ) ";
             break;
     }
     $res_last_x = Database::query($sql_last_x);
     $result_last_x = array();
     while ($obj = Database::fetch_object($res_last_x)) {
         $stat_date = $obj->stat_date;
         switch ($type) {
             case 'month':
                 $stat_date = explode('-', $stat_date);
                 $stat_date[1] = $months[$stat_date[1] - 1];
                 $stat_date = implode(' ', $stat_date);
                 break;
             case 'day':
                 $stat_date = $week_days[$stat_date];
                 break;
         }
         $result_last_x[$stat_date] = $obj->number_of_logins;
     }
     Statistics::print_stats(get_lang('LastLogins') . ' (' . $period . ')', $result_last_x, true);
     flush();
     //flush web request at this point to see something already while the full data set is loading
     echo '<br />';
     $res = Database::query($sql);
     $result = array();
     while ($obj = Database::fetch_object($res)) {
         $stat_date = $obj->stat_date;
         switch ($type) {
             case 'month':
                 $stat_date = explode('-', $stat_date);
                 $stat_date[1] = $months[$stat_date[1] - 1];
                 $stat_date = implode(' ', $stat_date);
                 break;
             case 'day':
                 $stat_date = $week_days[$stat_date];
                 break;
         }
         $result[$stat_date] = $obj->number_of_logins;
     }
     Statistics::print_stats(get_lang('AllLogins') . ' (' . $period . ')', $result, true);
 }
Пример #4
0
$current_course_tool = TOOL_BLOGS;
/* 	ACCESS RIGHTS */
// notice for unauthorized people.
api_protect_course_script(true);
//session
if (isset($_GET['id_session'])) {
    $_SESSION['id_session'] = intval($_GET['id_session']);
}
$lib_path = api_get_path(LIBRARY_PATH);
require_once $lib_path . 'blog.lib.php';
require_once $lib_path . 'fckeditor/fckeditor.php';
$blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
$nameTools = get_lang('Blogs');
$DaysShort = api_get_week_days_short();
$DaysLong = api_get_week_days_long();
$MonthsLong = api_get_months_long();
$current_page = $_GET['action'];
/*
	PROCESSING
*/
$safe_post_title = Security::remove_XSS($_POST['post_title']);
$safe_post_file_comment = Security::remove_XSS($_POST['post_file_comment']);
$safe_post_full_text = Security::remove_XSS(stripslashes(api_html_entity_decode($_POST['post_full_text'])), COURSEMANAGERLOWSECURITY);
$safe_comment_text = Security::remove_XSS(stripslashes(api_html_entity_decode($_POST['comment_text'])), COURSEMANAGERLOWSECURITY);
$safe_comment_title = Security::remove_XSS($_POST['comment_title']);
$safe_task_name = Security::remove_XSS($_POST['task_name']);
$safe_task_description = Security::remove_XSS($_POST['task_description']);
if (!empty($_POST['new_post_submit']) and !empty($_POST['post_title'])) {
    Blog::create_post($safe_post_title, $safe_post_full_text, $safe_post_file_comment, $blog_id);
    $return_message = array('type' => 'confirmation', 'message' => get_lang('BlogAdded'));
}
Пример #5
0
 /**
  * @author Sebastien Piraux <*****@*****.**>
  * @param sql : a sql query (as a string)
  * @return month_array
  * @desc        Return an assoc array.  Keys are the days, values are
  * the number of time this hours was found.
  * key "total" return the sum of all number of time days
  * appear
  */
 public static function monthTab($sql)
 {
     $MonthsLong = api_get_months_long();
     $month_array = array('total' => 0);
     $res = Database::query($sql);
     if ($res !== false) {
         // init tab with all months
         for ($i = 0; $i < 12; $i++) {
             $month_array[$MonthsLong[$i]] = 0;
         }
         while ($row = Database::fetch_row($res)) {
             $date_array = getdate($row[0]);
             $month_array[$MonthsLong[$date_array['mon'] - 1]]++;
             $month_array['total']++;
         }
         Database::free_result($res);
     }
     return $month_array;
 }
Пример #6
0
        }
        $extra_field_data = UserManager::get_extra_user_data_by_field(api_get_user_id(), 'google_calendar_url');
        if (!empty($extra_field_data) && isset($extra_field_data['google_calendar_url']) && !empty($extra_field_data['google_calendar_url'])) {
            $tpl->addGlobal('use_google_calendar', 1);
            $tpl->addGlobal('google_calendar_url', $extra_field_data['google_calendar_url']);
        }
        $this_section = SECTION_MYAGENDA;
        if (!api_is_anonymous()) {
            $can_add_events = 1;
        }
        break;
}
//Setting translations
$day_short = api_get_week_days_short();
$days = api_get_week_days_long();
$months = api_get_months_long();
$months_short = api_get_months_short();
//Setting calendar translations
$tpl->addGlobal('month_names', json_encode($months));
$tpl->addGlobal('month_names_short', json_encode($months_short));
$tpl->addGlobal('day_names', json_encode($days));
$tpl->addGlobal('day_names_short', json_encode($day_short));
$tpl->addGlobal('button_text', json_encode(array('today' => get_lang('Today'), 'month' => get_lang('Month'), 'week' => get_lang('Week'), 'day' => get_lang('Day'))));
//see http://docs.jquery.com/UI/Datepicker/$.datepicker.formatDate
$tpl->addGlobal('js_format_date', 'D d M yy');
$region_value = api_get_language_isocode();
if ($region_value == 'en') {
    $region_value = 'en-GB';
}
$tpl->addGlobal('region_value', $region_value);
$export_icon = api_get_path(WEB_IMG_PATH) . 'img/export.png';
Пример #7
0
/**
 * @param $prefix
 * @param string $default
 * @return string
 */
function draw_date_picker($prefix, $default = '')
{
    if (empty($default)) {
        $default = api_get_local_time();
    }
    $parts = explode(' ', $default);
    list($d_year, $d_month, $d_day) = explode('-', $parts[0]);
    list($d_hour, $d_minute) = explode(':', $parts[1]);

    $minute = range(10, 59);
    array_unshift($minute, '00', '01', '02', '03', '04', '05', '06', '07', '08', '09');
    $date_form = make_select($prefix.'_day', array_combine(range(1, 31), range(1, 31)), $d_day);
    $date_form .= make_select($prefix.'_month', array_combine(range(1, 12), api_get_months_long()), $d_month);
    $date_form .= make_select($prefix.'_year', array($d_year => $d_year, $d_year + 1 => $d_year + 1), $d_year).'&nbsp;&nbsp;&nbsp;&nbsp;';
    $date_form .= make_select($prefix.'_hour', array_combine(range(0, 23), range(0, 23)), $d_hour).' : ';
    $date_form .= make_select($prefix.'_minute', $minute, $d_minute);
    return $date_form;
}
Пример #8
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();
    }
}