/** * Update existing event and logs the action * @param int $eventid id in table personal_calendar * @param string $title event title * @param string $start event datetime * @param text $content event details * @param boolean $recursivelly specifies if the update should be applied to all events of the group of recursive events or to the specific one */ function update_event($eventid, $title, $start, $duration, $content, $recursion, $recursivelly = false){ global $uid, $langNotValidInput, $course_id; if (!preg_match('/[0-9]+(:[0-9]+){0,2}/', $duration)) { $duration = '0:00'; } if($recursivelly && !is_null($recursion)){ $oldrec = get_event_recursion($eventid, $course_id); $p = "P".$recursion['repeat'].$recursion['unit']; $e = DateTime::createFromFormat('d-m-Y', $recursion['end'])->format('Y-m-d'); if($oldrec->recursion_period != $p || $oldrec->recursion_end != $e){ delete_recursive_event($eventid); return add_event($title, $content, $start, $duration, $recursion); } } if(!is_null($recursion) && !is_recursive($eventid)) { delete_event($eventid); return add_event($title, $content, $start, $duration, $recursion); } $d1 = DateTime::createFromFormat('d-m-Y H:i', $start); $d2 = DateTime::createFromFormat('d-m-Y H:i:s', $start); $title = trim($title); if(empty($title) || !(($d1 && $d1->format('d-m-Y H:i') == $start) || ($d2 && $d2->format('d-m-Y H:i:s') == $start))) { return array('success'=>false, 'message'=>$langNotValidInput); } else { $start = $d1->format('Y-m-d H:i'); } $where_clause = ($recursivelly)? "WHERE source_event_id = ?d AND course_id = ?d":"WHERE id = ?d AND course_id = ?d"; $startdatetimeformatted = ($recursivelly)? $d1->format('H:i'):$d1->format('Y-m-d H:i'); $start_date_update_clause = ($recursivelly)? "start = CONCAT(date_format(start, '%Y-%m-%d '),?t), ":"start = ?t, "; Database::get()->query("UPDATE agenda SET " . "title = ?s, " . $start_date_update_clause . "duration = ?t, " . "content = ?s " . $where_clause, $title, $startdatetimeformatted, $duration, purify($content), $eventid, $course_id); Log::record($course_id, MODULE_ID_AGENDA, LOG_MODIFY, array('user_id' => $uid, 'id' => $eventid, 'title' => $title, 'recursivelly' => $recursivelly, 'content' => ellipsize_html(canonicalize_whitespace(strip_tags($content)), 50, '+'))); return array('success'=>true, 'message'=>'', 'event'=>$eventid); }
/** * Display a form (like comment or contact form) through an ajax call * * @param array params */ function display_ajax_form($params) { global $rsc_uri, $samedomain_htsrv_url, $ajax_form_number; if (is_recursive($params)) { // The params array contains recursion, don't try to encode, display error message instead // We don't use translation because this situation should not really happen ( Probably it happesn with some wrong skin ) echo '<p style="color:red;font-weight:bold">' . T_('This section can\'t be displayed because wrong params were created by the skin.') . '</p>'; return; } if (empty($ajax_form_number)) { // Set number for ajax form to use unique ID for each new form $ajax_form_number = 0; } $ajax_form_number++; echo '<div id="ajax_form_number_' . $ajax_form_number . '" class="section_requires_javascript">'; // Needs json_encode function to create json type params $json_params = evo_json_encode($params); $ajax_loader = "<p class='ajax-loader'><img src='" . $rsc_uri . "img/ajax-loader2.gif' /><br />" . T_('Form is loading...') . "</p>"; ?> <script type="text/javascript"> // display loader gif until the ajax call returns document.write( <?php echo '"' . $ajax_loader . '"'; ?> ); var ajax_form_offset_<?php echo $ajax_form_number; ?> = jQuery('#ajax_form_number_<?php echo $ajax_form_number; ?> ').offset().top; var request_sent_<?php echo $ajax_form_number; ?> = false; function get_form_<?php echo $ajax_form_number; ?> () { jQuery.ajax({ url: '<?php echo $samedomain_htsrv_url; ?> anon_async.php', type: 'POST', data: <?php echo $json_params; ?> , success: function(result) { jQuery('#ajax_form_number_<?php echo $ajax_form_number; ?> ').html( ajax_debug_clear( result ) ); } }); } function check_and_show_<?php echo $ajax_form_number; ?> () { var window_scrollTop = jQuery(window).scrollTop(); var window_height = jQuery(window).height(); // check if the ajax form is visible, or if it will be visible soon ( 20 pixel ) if( window_scrollTop >= ajax_form_offset_<?php echo $ajax_form_number; ?> - window_height - 20 ) { if( !request_sent_<?php echo $ajax_form_number; ?> ) { request_sent_<?php echo $ajax_form_number; ?> = true; // get the form get_form_<?php echo $ajax_form_number; ?> (); } } } jQuery(window).scroll(function() { check_and_show_<?php echo $ajax_form_number; ?> (); }); jQuery(document).ready( function() { check_and_show_<?php echo $ajax_form_number; ?> (); }); jQuery(window).resize( function() { check_and_show_<?php echo $ajax_form_number; ?> (); }); </script> <noscript> <?php echo '<p>' . T_('This section can only be displayed by javascript enabled browsers.') . '</p>'; ?> </noscript> <?php echo '</div>'; }
'level' => 'primary-label', 'show' => $is_editor))); $navigation[] = array("url" => $_SERVER['SCRIPT_NAME'] . "?course=$course_code", "name" => $langAgenda); $applytogroup = ''; if (isset($id) && $id) { $myrow = Database::get()->querySingle("SELECT * FROM agenda WHERE course_id = ?d AND id = ?d", $course_id, $id); if ($myrow) { $id = $myrow->id; $event_title = $myrow->title; $content = $myrow->content; $startdate = date('d-m-Y H:i', strtotime($myrow->start)); $duration = $myrow->duration; $applytogroup = ''; $is_recursive_event = false; $enddate = ''; if(is_recursive($myrow->id)){ $is_recursive_event = true; $applytogroup = 'no'; $repeatnumber = substr($myrow->recursion_period, 1, strlen($myrow->recursion_period)-2); $repeatperiod = substr($myrow->recursion_period, -1); $repeatend_obj = DateTime::createFromFormat('Y-m-d', $myrow->recursion_end); $enddate = $repeatend_obj->format('d-m-Y'); } } } else { $id = $content = ''; $duration = "0:00"; $startdate = date('d-m-Y H:i', strtotime('now')); $enddate = ''; } $tool_content .= "<div class='form-wrapper'>";
$tool_content .= "<div class='alert {$alerttype} text-center' role='alert'>{$msgresp}</div><br>"; } if (isset($_GET['addEvent']) or isset($_GET['edit'])) { $pageName = $langAddEvent; $tool_content .= action_bar(array(array('title' => $langBack, 'url' => "{$_SERVER['SCRIPT_NAME']}?course={$course_code}", 'icon' => 'fa-reply', 'level' => 'primary-label', 'show' => $is_editor))); $navigation[] = array("url" => $_SERVER['SCRIPT_NAME'] . "?course={$course_code}", "name" => $langAgenda); $rep = ''; if (isset($id) && $id) { $myrow = Database::get()->querySingle("SELECT id, title, content, start, duration FROM agenda WHERE course_id = ?d AND id = ?d", $course_id, $id); if ($myrow) { $id = $myrow->id; $event_title = $myrow->title; $content = $myrow->content; $startdate = date('d-m-Y H:i', strtotime($myrow->start)); $duration = $myrow->duration; $rep = is_recursive($myrow->id) ? 'no' : ''; } } else { $id = $content = $duration = ''; $startdate = date('d-m-Y H:i', strtotime('now')); $enddate = date('d-m-Y', strtotime('now +1 week')); } $tool_content .= "<div class='form-wrapper'>"; $tool_content .= "<form id='agendaform' class='form-horizontal' role='form' method='post' action='{$_SERVER['SCRIPT_NAME']}?course={$course_code}'>\n <input type='hidden' id = 'id' name='id' value='{$id}'>" . "<input type='hidden' name='rep' id='rep' value='{$rep}'>"; @($tool_content .= "\n <div class='form-group'>\n <label for='event_title' class='col-sm-2 control-label'>{$langTitle} :</label>\n <div class='col-sm-10'>\n <input type='text' class='form-control' id='event_title' name='event_title' placeholder='{$langTitle}' value='" . q($event_title) . "'>\n </div>\n </div>\n <div class='input-append date form-group' id='startdatecal' data-date='{$langDate}' data-date-format='dd-mm-yyyy'>\n <label for='startdate' class='col-sm-2 control-label'>{$langDate} :</label>\n <div class='col-xs-10 col-sm-9'> \n <input class='form-control' name='startdate' id='startdate' type='text' value = '" . $startdate . "'>\n </div>\n <div class='col-xs-2 col-sm-1'> \n <span class='add-on'><i class='fa fa-times'></i></span>\n <span class='add-on'><i class='fa fa-calendar'></i></span>\n </div>\n </div>\n <div class='input-append bootstrap-timepicker form-group'>\n <label for='durationcal' class='col-sm-2 control-label'>{$langDuration} <small>{$langInHour}</small></label>\n <div class='col-xs-10 col-sm-9'>\n <input class='form-control' name='duration' id='durationcal' type='text' class='input-small' value='" . $duration . "'>\n </div>\n <div class='col-xs-2 col-sm-1'>\n <span class='add-on'><i class='icon-time'></i></span>\n </div>\n </div>"); if (!isset($_GET['edit'])) { $tool_content .= "<div class='form-group'>\n <label for='Repeat' class='col-sm-2 control-label'>{$langRepeat} {$langEvery}</label>\n <div class='col-sm-2'>\n <select class='form-control' name='frequencynumber'>\n <option value='0'>{$langSelectFromMenu}</option>"; for ($i = 1; $i < 10; $i++) { $tool_content .= "<option value=\"{$i}\">{$i}</option>"; } $tool_content .= "</select></div>";