File manager - Edit - /home/missmand/public_html/learning/old/main/couple/action.php
Back
<?php /* For licensing terms, see /license.txt */ /** * Model CRUD for couple_tool_action * @author Batiste Roger <batiste.roger@live.fr> * @package chamilo.couple */ require_once(api_get_path(SYS_PATH) . 'main/couple/tool.php'); define('TABLE_TOOL_ACTION', 'couple_tool_action'); /** * Create an action item * @param type $couple_id * @param type $couple_type * @param type $title * @param type $description * @param type $author_user_id * @param type $is_deleted * @param type $is_ok * @param type $assigned_to_hp * @param type $assigned_to_su * @return Databse::query if params are ok, else array with params errors */ function action_create ($couple_id, $couple_type, $title, $description, $author_user_id, $is_deleted = null, $is_ok = null, $assigned_to_hp = null, $assigned_to_su = null) { // Check that booleans are booleans try { error_test_param (is_bool($assigned_to_hp)|| empty($assigned_to_hp), "Boolean $assigned_to_hp is not a boolean."); error_test_param (is_bool($assigned_to_su)|| empty($assigned_to_su), "Boolean $assigned_to_su is not a boolean."); } catch (Exception $e) { return error_log($e->getMessage()); } // Create a tool try { tool_create($couple_id, $couple_type, $title, $description, $author_user_id, $is_deleted, $is_ok); } catch (Exception $e) { return error_log($e->getMessage()); } // Create the action item $tool_id = tool_get_max_id(); $sql = "INSERT INTO " . TABLE_TOOL_ACTION . " SET tool_id = '$tool_id'"; if (!empty($assigned_to_hp)) { $sql .= ", assigned_to_hp = '$assigned_to_hp'"; } if (!empty($assigned_to_su)) { $sql .= ", assigned_to_su = '$assigned_to_su'"; } $ret = Database::query($sql); // Create a log accordingly $names = couple_get_firstnames($couple_id, $couple_type); if ($assigned_to_hp && $assigned_to_su) { $end = "affectée à " . Database::escape_string(trim($names['hp'])) . " et " . Database::escape_string(trim($names['pa'])); } else if ($assigned_to_hp) { $end = "affectée à " . Database::escape_string(trim($names['hp'])); } else if ($assigned_to_su) { $end = "affectée à " . Database::escape_string(trim($names['pa'])); } else { $end = "qui n'est pas encore affectée"; } log_generate($couple_id, $couple_type, $author_user_id, $tool_id, 'crée', $end, "confirmer l'affectation", 'validate', "proposer une alternative", 'edit'); return $ret; } function action_read ($couple_id, $couple_type) { // Get couple info for user_id $couple = couple_get_from_id($couple_id, $couple_type); if (empty($couple)) return null; $couple_type = strtoupper($couple['type']); $couple_id = $couple['couple_id']; // Get the tool $tool = tool_get_tool_for_couple('action', $couple_id, $couple_type); return $tool; } function action_read_and_format ($couple_id, $couple_type) { $read = action_read($couple_id, $couple_type); if (empty($read)) return $read; foreach ($read as $key => $action) { $to_hp = $action['assigned_to_hp']; $to_su = $action['assigned_to_su']; // Get names $couple = couple_get_from_id($couple_id, $couple_type); $hp_name = ucfirst(subrole_id_to_user_fullname($couple['hp_id'], HP)); $su_name = ucfirst(subrole_id_to_user_fullname($couple['su_id'], STARTUP)); // acteurs if ($to_hp && $to_su) { $read[$key]['acteurs'] = "$hp_name et $su_name"; } else if ($to_hp) { $read[$key]['acteurs'] = $hp_name; } else if ($to_su) { $read[$key]['acteurs'] = $su_name; } else { $read[$key]['acteurs'] = null; } // format me_checked and pa_checked [TODO REGLER CA] $read[$key]['hp_checked'] = $to_hp ; $read[$key]['su_checked'] = $to_su ; } return $read; } /** Create an action based on the info sent by POST or return errors * */ function action_create_form() { // First, try to read all parameters $title = read_param('title'); $description = read_param('description'); $assigned_to_hp = read_param('assigned_to_hp', 'POST', false, false); $assigned_to_su = read_param('assigned_to_su', 'POST', false, false); // Test that these params are correct if ($title && $description) { // React $my_user_id = api_get_user_id(); $couple = couple_get_coop_partner($my_user_id); return action_create($couple['couple_id'], strtoupper($couple['type']), $title, $description, $my_user_id, null, null, (bool)$assigned_to_hp, (bool)$assigned_to_su); } error_throw("Echec de la création. Params : $title, $description, $assigned_to_hp, $assigned_to_su", "action.php/action_create_form"); return false; } /** * Deletes an action * @return boolean : true if the item was actually deleted */ function action_delete_form () { $id = read_param('id', false); $tool_was_deleted = tool_delete($id); if ($tool_was_deleted) { // The tool item was deleted, delete the action $sql = "DELETE FROM " . TABLE_TOOL_ACTION . " WHERE tool_id = '$id'"; Database::query($sql); return true; } return false; } function action_update_form($couple_id, $couple_type) { // First, try to read all parameters $title = read_param('title'); $description = read_param('description'); $assigned_to_me = read_param('assigned_to_me', 'POST', false, false); $assigned_to_pa = read_param('assigned_to_pa', 'POST', false, false); $id = read_param('id'); // Test that these params are correct if ($title && $description && $id) { // Update tool's columns $my_user_id = api_get_user_id(); $i_am_hp = user_has_subrole($my_user_id, HP); $assigned_to_hp = intval((bool)($i_am_hp ? $assigned_to_me : $assigned_to_pa)); $assigned_to_su = intval((bool)($i_am_hp ? $assigned_to_pa : $assigned_to_me)); $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 $hp = "assigned_to_hp = '$assigned_to_hp'"; $su = "assigned_to_su = '$assigned_to_su'"; $table = TABLE_TOOL_ACTION; $sql = "UPDATE $table SET $hp, $su WHERE tool_id = '$id'"; // Create a log accordingly log_generate($couple_id, $couple_type, api_get_user_id(), $id, 'modifié', "", "confirmer l'affectation", 'validate', "proposer une alternative", 'edit'); // Updating causes the is_ok column to be set to false tool_unvalidate($id); return Database::query($sql); } error_throw("Echec de la création. Params : $title, $description, $id", "action.php/action_update_form"); return false; }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0 |
proxy
|
phpinfo
|
Settings