File manager - Edit - /home/missmand/public_html/learning/old/main/couple/agenda.php
Back
<?php /* For licensing terms, see /license.txt */ /** * Fonctions CRUD for agenda in cooperation * @author Batiste Roger <batiste.roger@live.fr> * @package chamilo.couple */ require_once '../inc/global.inc.php'; require_once(api_get_path(SYS_PATH) . 'main/couple/model.php'); require_once(api_get_path(SYS_PATH) . 'main/couple/tool.php'); require_once(api_get_path(SYS_PATH) . 'main/couple/error.php'); require_once(api_get_path(SYS_PATH) . 'main/couple/logs.php'); define('TABLE_TOOL_AGENDA', 'couple_tool_agenda'); function agenda_is_valid_date ($date) { return preg_match( '`^\d{1,2}-\d{1,2}-\d{4}$`' , $date) || empty($date); } function agenda_is_valid_time ($time) { return preg_match( '`^\d{1,2}:\d{1,2}$`' , $time) || empty($time); } function agenda_are_dates_and_types_valid ($date1, $time1, $date2, $time2) { return agenda_is_valid_date($date1) && agenda_is_valid_date($date2) && agenda_is_valid_time($time1) && agenda_is_valid_time($time2); } function agenda_create ($couple_id, $couple_type, $title, $description, $author_user_id, $is_deleted = null, $is_ok = null, $date_debut = null, $date_fin = null) { try { // Create a tool tool_create($couple_id, $couple_type, $title, $description, $author_user_id, $is_deleted, $is_ok); // Create the action item $tool_id = tool_get_max_id(); $sql = "INSERT INTO " . TABLE_TOOL_AGENDA . " SET tool_id = '$tool_id'"; if (!empty($date_debut)) { $sql .= ", date_deb = '$date_debut'"; } if (!empty($date_fin)) { $sql .= ", date_fin = '$date_fin'"; } } catch (Exception $e) { return error_log($e->getMessage()); } $ret = Database::query($sql); // Create a log accordingly log_generate($couple_id, $couple_type, $author_user_id, $tool_id, 'crée', "(du $date_debut au $date_fin)", "confirmer votre présence", 'validate', "proposer un autre créneau", 'edit'); return $ret; } function agenda_read($couple_id, $couple_type) { // Note : to display month name, simply change %m to %M. And many other examples can be found in the doc. // Don't do these conversions in php unless you need to do so $select = ", DATE_FORMAT(date_deb, '%d-%m-%Y') AS date_deb, DATE_FORMAT(date_deb, '%H:%i') AS time_deb, " . "DATE_FORMAT(date_fin, '%d-%m-%Y') AS date_fin, DATE_FORMAT(date_fin, '%H:%i') AS time_fin"; return tool_get_tool_for_couple('agenda', $couple_id, $couple_type, $select); } function agenda_create_form() { // First, try to read all parameters $title = read_param('title'); $description = read_param('description'); $date_debut = read_param('date_debut'); $time_debut = read_param('time_debut'); $date_fin = read_param('date_fin', 'POST', null, false); $time_fin = read_param('time_fin', 'POST', null, false); // Check that dates and times are ok if (!agenda_are_dates_and_types_valid($date_debut, $time_debut, $date_fin, $time_fin)) return false; // Convert dates into timestamps $timestamp_debut = (!empty($date_debut) && !empty($time_debut) ? date('Y-m-d H:i:s', strtotime("$date_debut $time_debut")) : null); $timestamp_fin = (!empty($date_fin) && !empty($time_fin) ? date('Y-m-d H:i:s', strtotime("$date_fin $time_fin")) : null); // Test that these params are correct if ($title && $date_debut) { // React $my_user_id = api_get_user_id(); $couple = couple_get_coop_partner($my_user_id); return agenda_create( $couple['couple_id'], strtoupper($couple['type']), $title, $description, $my_user_id, false, false, $timestamp_debut, $timestamp_fin ); } error_throw("Echec de la création. Params : $title, $description, $date_debut, $time_debut, $date_fin, $time_fin"); return false; } /** * Deletes a date * @return boolean : true if the item was actually deleted */ function agenda_delete_form () { $tool_id = read_param('id', false); $tool_was_deleted = tool_delete($tool_id); if ($tool_was_deleted) { // The tool item was deleted, delete the date $sql = "DELETE FROM " . TABLE_TOOL_AGENDA . " WHERE tool_id = '$tool_id'"; Database::query($sql); return true; } return false; } function agenda_update_form($couple_id, $couple_type) { // First, try to read all parameters $now = date("Y-m-d H:i:s"); $title = read_param('title'); $description = read_param('description'); $date_debut = read_param('date_debut', 'POST', $now, false); $time_debut = read_param('time_debut', 'POST', '12:00', false); $date_fin = read_param('date_fin', 'POST', $now, false); $time_fin = read_param('time_fin', 'POST', '12:00', false); $id = read_param('id'); // Check that dates and times are ok if (!agenda_are_dates_and_types_valid($date_debut, $time_debut, $date_fin, $time_fin)) return false; // Convert dates into timestamps $timestamp_debut = ($date_debut && $time_debut ? date('Y-m-d H:i:s', strtotime("$date_debut $time_debut")) : null); $timestamp_fin = ($date_fin && $time_fin ? date('Y-m-d H:i:s', strtotime("$date_fin $time_fin")) : null); // Test that these params are correct if ($title && $description && $timestamp_debut) { // Update tool's columns $table = TABLE_TOOL; $sql = "UPDATE $table SET title = '" . Database::escape_string(trim($title)) . "', description = '" . Database::escape_string(trim($description)) . "' WHERE id = '$id'"; Database::query($sql); // Update tool_action's columns $deb = "date_deb = '$timestamp_debut'"; if ($timestamp_fin) $fin = "date_fin = '$timestamp_fin'"; $table_agenda = TABLE_TOOL_AGENDA; $sql = "UPDATE $table_agenda SET $deb" . ($timestamp_fin ? ", $fin" : "") . " WHERE tool_id = '$id'"; $ret = Database::query($sql); // Create a log accordingly log_generate($couple_id, $couple_type, api_get_user_id(), $id, 'modifié', "", "confirmer votre présence", 'validate', "proposer un autre créneau", 'edit'); // Updating causes the is_ok column to be set to false tool_unvalidate($id); return $ret; } error_throw("Echec de la création. Params : $title, $description, $id"); return false; }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0 |
proxy
|
phpinfo
|
Settings