File manager - Edit - /home/missmand/public_html/learning/old/main/subrole/admin.php
Back
<?php /* For licensing terms, see /license.txt */ /** * CR(U)D for subroles. This is admin only feature. * It was not placed in admin folder in order to loosely couple /subrole to Chamilo. * @author Batiste Roger <batiste.roger@live.fr> * @package chamilo.cooperation */ // ** Strange stuff require_once '../inc/global.inc.php'; global $_configuration; $current_access_url_id = api_get_current_access_url_id(); $this_section = SECTION_PLATFORM_ADMIN; api_protect_admin_script(true); // ******************************** // *** Test that I am an admin **** // ******************************** if (!api_is_platform_admin()) { // You should not be there echo "You are not allowed to view this page."; exit; } // ******************************** // *** Test and perform action **** // ******************************** // Test $valid_actions = array('create', 'delete'); if (isset($_GET["action"]) && in_array($_GET["action"], $valid_actions)) { $action = $_GET["action"]; } else { $action = null; } // Perform $hp = Security::remove_XSS($_GET['hp']); $su = Security::remove_XSS($_GET['su']); $type = Security::remove_XSS($_GET['type']); require_once(api_get_path(SYS_PATH) . 'main/cooperation/couple_model.php'); switch ($action) { case 'create' : couple_create($hp, $su, $type, USER); break; case 'delete' : couple_delete($hp, $su, $type); break; } // ******************************** // *** List @ couples (DB) ******** // ******************************** function get_number_of_couples() { return Database::num_rows(couple_read()); } function get_couple_data_as_array() { $result = couple_read(); $couples = array(); for ($i = 0; $i < get_number_of_couples(); $i++) { $row = Database::fetch_array($result, 'ASSOC'); $couples[$i] = $row; require_once(api_get_path(SYS_PATH) . 'main/subrole/subrole.php'); $couples[$i]['hp_name'] = subrole_id_to_user_fullname($row['hp_id'], HP); $couples[$i]['su_name'] = subrole_id_to_user_fullname($row['startup_id'], STARTUP); } return $couples; } // ******************************** // *** Create table to display **** // ******************************** $couples = get_couple_data_as_array(); $table = '<table class="data_table"><tbody>'; $table .= '<tr><th>HP</th><th>SU</th><th>Type</th><th>Action</th><tr>'; foreach ($couples as $couple) { $hp = $couple['hp_id']; $hp_name = $couple['hp_name'] . " ($hp)"; $su = $couple['startup_id']; $su_name = $couple['su_name'] . " ($su)"; $type = $couple['couple_type']; $type_name = coop_type($couple['couple_type']); $delete_link = "<a href='admin.php?action=delete&hp=$hp&su=$su&type=$type'>delete</a>"; $table .= "<tr><th>$hp_name</th><th>$su_name</th><th>$type_name</th><th>$delete_link</th><tr>"; } $table .= '</tbody></table>'; // ******************************** // *** Create creation form ******* // ******************************** function list_subrole_X_by_name ($subrole) { // Tests for debug assert(in_array($subrole, allowed_subroles())); // Call $table = subrole_to_table($subrole); assert(!empty($table)); $sql = "SELECT id, user_id FROM $table"; $result = Database::query($sql); $users = array(); for ($i = 0; $i < Database::num_rows($result); $i++) { $row = Database::fetch_array($result, 'ASSOC'); $info = api_get_user_info($row['user_id']); $users[$i]['user_id'] = $row['user_id']; $users[$i]['name'] = api_get_person_name($info['firstname'], $info['lastname']); } return $users; } function create_select ($type = HP) { $subrole = ($type == HP ? 'hp' : 'su'); $form = '<select name="' . $subrole . '" id="' . $subrole . '">'; $list_hp = list_subrole_X_by_name($type); $first = true; foreach ($list_hp as $row) { $id = $row['user_id']; $name = $row['name']; if (!empty($name)) { if ($first) { $form .= '<option selected value="' . $id . '">' . $name . '</option>'; $first = false; } else { $form .= '<option value="' . $id . '">' . $name . '</option>'; } } } $form .= '</select>'; return $form; } function create_radio ($type = DS) { assert($type == DS || $type == CE); $selected = ($type == CE ? 'checked' : null); return '<input ' . $selected . ' type="radio" name="type" value="' . $type . '" id="' . coop_type($type) . '" />' . coop_type($type, false) . " ($type) <br />"; } // For subroles to be understood require_once(api_get_path(SYS_PATH) . 'main/subrole/subrole.php'); $form = "<form action='admin.php' method='get'>"; $form .= "<p>"; $form .= create_select(HP); $form .= "</p>"; $form .= "<p>"; $form .= create_select(STARTUP); $form .= "</p>"; $form .= "<p>"; $form .= create_radio(DS); $form .= create_radio(CE); $form .= "</p>"; $form .= "<input type='submit' name='action' value='create'/>"; $form .= "</form>"; // ******************************** // *** Display @ ****************** // ******************************** $tpl = new Template('Couples'); // $tpl->assign('actions', $actions); // $tpl->assign('message', $message); $table_title = '<h3>List</h3>'; $form_title = '<h3>Create</h3>'; $content = $table_title . $table . $form_title . $form; $tpl->assign('content', $content); $tpl->display_one_col_template();
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0 |
proxy
|
phpinfo
|
Settings