File manager - Edit - /home/missmand/public_html/learning/old/main/couple/logs.php
Back
<?php /* For licensing terms, see /license.txt */ /** * Fonctions d'affichage des evènements passés sour forme de logs * @author Batiste Roger <batiste.roger@live.fr> * @package chamilo.couple */ require_once '../inc/global.inc.php'; require_once(api_get_path(SYS_PATH) . 'main/subrole/subrole.php'); require_once(api_get_path(SYS_PATH) . 'main/couple/model.php'); require_once(api_get_path(SYS_PATH) . 'main/couple/action.php'); require_once(api_get_path(SYS_PATH) . 'main/couple/agenda.php'); require_once(api_get_path(SYS_PATH) . 'main/couple/tchat.php'); require_once(api_get_path(SYS_PATH) . 'main/couple/doc.php'); require_once(api_get_path(SYS_PATH) . 'main/couple/doc_system.php'); define ('TABLE_LOGS', 'couple_log'); /** * Read function for logs. The recipient can want the logs for coop or for tutor couple, that is why a boolean is required. * @param type $recipient_user_id * @param type $couple_type_is_tutor * @return null */ function log_read ($recipient_user_id, $student = null) { try { $table_logs = TABLE_LOGS; if (!empty($student)) { $sql = "SELECT *, " . "MINUTE (date_creation) AS minute, " . "HOUR (date_creation) AS hour, " . "DAY (date_creation) AS day, " . "MONTH(date_creation) AS month, " . "YEAR (date_creation) AS year " . "FROM $table_logs WHERE recipient_user_id = '$recipient_user_id' AND couple_type_is_tutor = '1' " . "AND author_user_id = $student"; } else { $sql = "SELECT *, " . "MINUTE (date_creation) AS minute, " . "HOUR (date_creation) AS hour, " . "DAY (date_creation) AS day, " . "MONTH(date_creation) AS month, " . "YEAR (date_creation) AS year " . "FROM $table_logs WHERE recipient_user_id = '$recipient_user_id' AND couple_type_is_tutor = '0'"; } // error_display("logs.php:log_read, sql = $sql"); $res = Database::query($sql); $logs = array(); if (Database::num_rows($res) <= 0) return null; } catch (Exception $e) { return null; } while ($row = Database::fetch_assoc($res)) { $user_info = UserManager::get_user_info_by_id($row['author_user_id']); $row['subject'] = ucfirst($user_info['firstname']); $logs[] = $row; } return $logs; } /** * Generates a log for given couple. Optionally, you can specify options. If so, all of them are required. * @param type $couple_id * @param type $couple_type * @param type $author_user_id * @param type $tool_id * @param type $verb * @param type $end * @param type $o1 option 1 : exemple, delete this item * @param type $a1 action 1 * @param type $o2 option 2 : exemple, restore this item * @param type $a2 action 2 * @return type */ function log_generate ($couple_id, $couple_type, $author_user_id, $tool_id, $verb, $end, $o1 = null, $a1 = null, $o2 = null, $a2 = null) { $couple_type = strtoupper($couple_type); // Guarantees the uppur case. $recipients = array(); $author_subrole = get_subrole($author_user_id); error_display("logs.php:log_generate ($couple_id, $couple_type, $author_user_id, $tool_id, $verb, '$end')"); error_display("logs.php:log_generate, couple_type = $couple_type"); // Determine recipients if ($couple_type == TU) { $pa = couple_get_partner($author_user_id, $couple_type); $pa_user_id = $author_subrole == TUTOR ? $pa['student_user_id'] : $pa['tu_user_id']; $recipients[] = array('id' => $pa_user_id, 'options' => true); // true -> take options into account } else { $couple = couple_get($couple_id, $couple_type); $hp_user_id = subrole_id_to_user_id($couple['hp_id'], HP); $su_user_id = subrole_id_to_user_id($couple['su_id'], STARTUP); if ($author_subrole != TUTOR) { // Send to partner and tutor $recipients[] = array('id' => ($author_user_id == $hp_user_id ? $su_user_id : $hp_user_id), 'options' => true); // true -> take options into account $tutor = couple_get_tutor($author_user_id); $tutor_user_id = $tutor['tu_id']; $recipients[] = array('id' => $tutor_user_id, 'options' => false); // true -> take options into account } else { // Send to both hp and su $recipients[] = array('id' => $hp_user_id, 'options' => true); // true -> take options into account $recipients[] = array('id' => $su_user_id, 'options' => true); // true -> take options into account } } error_display("logs.php:log_generate, recipients = " . print_r($recipients, true)); // Create logs foreach ($recipients as $recipient) { $tool_description = log_get_object_as_string($tool_id); if ($recipient['id'] == 0) { error_log("Id nul and log_generate. Params : $couple_id, $couple_type, $author_user_id, $tool_id, $verb, $end <br/> This user : " . api_get_user_id()); } if ($recipient['options']) { log_create_db($author_user_id, $tool_id, $tool_description, $verb, $end, $recipient['id'], $couple_type, $o1, $a1, $o2, $a2); } else { log_create_db($author_user_id, $tool_id, $tool_description, $verb, $end, $recipient['id'], $couple_type); } } } /** * NEVER USE THAT FUNCTION - SHOULD BE PRIVATE * @param type $author_user_id * @param type $tool_id * @param type $tool_desctiption * @param type $verb * @param type $end * @param type $recipient_user_id * @param type $o1 option 1 : exemple, delete this item * @param type $a1 action 1 * @param type $o2 option 2 : exemple, restore this item * @param type $a2 action 2 */ function log_create_db ($author_user_id, $tool_id, $tool_description, $verb, $end, $recipient_user_id, $couple_type, $o1 = null, $a1 = null, $o2 = null, $a2 = null) { if ($tool_id == 0) error_log("Found tool_id = $tool_id in log_create_db (logs.php)"); $o1 = Database::escape_string(trim($o1)); $o2 = Database::escape_string(trim($o2)); $a1 = Database::escape_string(trim($a1)); $a2 = Database::escape_string(trim($a2)); $sql = "INSERT INTO " . TABLE_LOGS . " SET " . "author_user_id = '$author_user_id', " . "tool_id = '$tool_id', " . "tool_description = '" . Database::escape_string(trim($tool_description)) . "', " . "verb = '$verb', " . "end = '" . Database::escape_string(trim($end)) . "', " . "recipient_user_id = '$recipient_user_id', " . "couple_type_is_tutor = " . ($couple_type == TU ? 1 : 0) . ""; if ($o1 && $a1 && $o2 && $a2) { $sql .= ", option1 = '$o1', action1 = '$a1', option2 = '$o2', action2 = '$a2'"; } error_display("logs.php:log_create_db, sql = $sql"); return Database::query($sql); } /** * Warning : this is 100% unsafe * @param int $id id of the log * @return query */ function log_delete ($log_id) { error_display("Suppression du log $log_id"); $sql = "UPDATE " . TABLE_LOGS . " SET is_deleted = true WHERE id = '$log_id'"; Database::query($sql); return $sql; } function log_get_object_as_string($tool_id) { $tool = tool_get_by_id($tool_id); $name = $tool['title']; switch (log_get_type($tool_id)) { case DOCUMENT : return "le document $name"; break; case AGENDA : return "la date $name"; break; case ACTION : return "l'action $name"; break; default : return error_throw('Wrong log type for tool ' . $name); } } function log_get_type($tool_id) { $types = tool_get_all_tool_types(); foreach($types as $type) { $table = tool_get_table_for_type($type); $sql = "SELECT * FROM $table WHERE tool_id = '$tool_id'"; $res = Database::query($sql); if (Database::num_rows($res) > 0) return $type; } return error_throw('Tool with no type, id = ' . $tool_id); }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0 |
proxy
|
phpinfo
|
Settings