Add redirection plugin #2176 BT#13461
- Add configuration "plugin_redirection_enabled" - Redirect a specific user id to a URL after login successful. - Requires composer updatepull/2487/head
parent
ea6a9db2ab
commit
acb161458f
@ -0,0 +1,8 @@ |
||||
# chamilo-plugin-redirection |
||||
Plugin chamilo para la redirección de usuarios. |
||||
|
||||
Requiere agregar: |
||||
|
||||
<code> |
||||
$_configuration['plugin_redirection_enabled'] = true; |
||||
</code> |
@ -0,0 +1,118 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* Config the plugin |
||||
* @author Enrique Alcaraz Lopez |
||||
* @package chamilo.plugin.redirection |
||||
*/ |
||||
class RedirectionPlugin extends Plugin |
||||
{ |
||||
/** |
||||
* Class constructor |
||||
*/ |
||||
protected function __construct() |
||||
{ |
||||
$version = '1.0'; |
||||
$author = 'Enrique Alcaraz, Julio Montoya'; |
||||
|
||||
parent::__construct($version, $author, ['enabled' => 'boolean']); |
||||
} |
||||
|
||||
|
||||
public static function create() |
||||
{ |
||||
static $result = null; |
||||
return $result ? $result : $result = new self(); |
||||
} |
||||
|
||||
/** |
||||
* @param int $userId |
||||
* @param string $url |
||||
* @return false|string |
||||
*/ |
||||
public static function insert($userId, $url) |
||||
{ |
||||
$userId = (int) $userId; |
||||
|
||||
if (empty($userId)) { |
||||
return false; |
||||
} |
||||
|
||||
$sql = "DELETE FROM plugin_redirection WHERE user_id = $userId"; |
||||
Database::query($sql); |
||||
|
||||
$userInfo = api_get_user_info($userId); |
||||
|
||||
if (empty($userInfo)) { |
||||
return false; |
||||
} |
||||
|
||||
return Database::insert( |
||||
'plugin_redirection', |
||||
[ |
||||
'user_id' => $userId, |
||||
'url' => $url, |
||||
] |
||||
); |
||||
} |
||||
|
||||
/** |
||||
* @param $userId |
||||
* @return array |
||||
* @throws \Doctrine\DBAL\DBALException |
||||
*/ |
||||
public static function getUrlFromUser($userId) |
||||
{ |
||||
$userId = (int) $userId; |
||||
$userInfo = api_get_user_info($userId); |
||||
if (empty($userInfo)) { |
||||
return false; |
||||
} |
||||
$sql = "SELECT * FROM plugin_redirection WHERE user_id = $userId LIMIT 1"; |
||||
$result = Database::query($sql); |
||||
return Database::fetch_array($result, 'ASSOC'); |
||||
} |
||||
|
||||
/** |
||||
* @param int $id |
||||
*/ |
||||
public static function delete($id) |
||||
{ |
||||
$table = Database::get_main_table('plugin_redirection'); |
||||
Database::delete( |
||||
$table, |
||||
array('id = ?' => array($id)) |
||||
); |
||||
} |
||||
|
||||
/** |
||||
* @return array |
||||
*/ |
||||
public static function getAll() |
||||
{ |
||||
$table = Database::get_main_table('plugin_redirection'); |
||||
|
||||
return Database::select('*', $table); |
||||
} |
||||
|
||||
public static function install() |
||||
{ |
||||
$table = Database::get_main_table('plugin_redirection'); |
||||
|
||||
$sql = "CREATE TABLE IF NOT EXISTS $table ( |
||||
id INT unsigned NOT NULL auto_increment PRIMARY KEY, |
||||
user_id INT unsigned NOT NULL DEFAULT 0, |
||||
url VARCHAR(255) NOT NULL DEFAULT '' |
||||
)"; |
||||
|
||||
Database::query($sql); |
||||
} |
||||
|
||||
public static function uninstall() |
||||
{ |
||||
$table = Database::get_main_table('plugin_redirection'); |
||||
$sql = "DROP TABLE $table"; |
||||
Database::query($sql); |
||||
} |
||||
} |
@ -1,56 +1,73 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* Config the plugin |
||||
* @author Enrique Alcaraz Lopez |
||||
* @package chamilo.plugin.redirection |
||||
*/ |
||||
* Config the plugin |
||||
* @author Enrique Alcaraz Lopez |
||||
* @package chamilo.plugin.redirection |
||||
*/ |
||||
|
||||
require_once __DIR__.'/config.php'; |
||||
$redirecciones = PluginRedirection::get(); |
||||
|
||||
if (isset($_REQUEST["id"])) { |
||||
PluginRedirection::delete($_REQUEST["id"]); |
||||
header("Location: index.php"); |
||||
exit(); |
||||
} elseif (isset($_POST["submit_button"])) { |
||||
PluginRedirection::insert($_POST["user_id"], $_POST["url"]); |
||||
header("Location: index.php"); |
||||
exit(); |
||||
|
||||
api_protect_admin_script(); |
||||
|
||||
$list = RedirectionPlugin::getAll(); |
||||
|
||||
if (isset($_REQUEST['id'])) { |
||||
RedirectionPlugin::delete($_REQUEST['id']); |
||||
Display::addFlash(Display::return_message(get_lang('Deleted'))); |
||||
header('Location: index.php'); |
||||
exit; |
||||
} elseif (isset($_POST['submit_button'])) { |
||||
$result = RedirectionPlugin::insert($_POST['user_id'], $_POST['url']); |
||||
if ($result) { |
||||
Display::addFlash(Display::return_message(get_lang('Added'))); |
||||
} else { |
||||
Display::addFlash(Display::return_message(get_lang('Error'), 'warning')); |
||||
} |
||||
header('Location: index.php'); |
||||
exit; |
||||
} |
||||
|
||||
Display::display_header(); |
||||
|
||||
?> |
||||
|
||||
<form action="./index.php" method="post"> |
||||
<div class="table-responsive well"> |
||||
<table class="table table-condensed"> |
||||
<thead> |
||||
<td><input type="text" class="form-control" placeholder="User_id" name="user_id" /></td> |
||||
<td><input type="text" class="form-control" placeholder="url" name="url" /></td> |
||||
<td><input type='submit' value='Agregar' name="submit_button" class='btn btn-primary' /></td> |
||||
</thead> |
||||
</table> |
||||
|
||||
</div> |
||||
<div class="table-responsive well"> |
||||
<table class="table table-condensed"> |
||||
<thead> |
||||
<td><input type="text" class="form-control" placeholder="User Id" name="user_id"/></td> |
||||
<td><input type="text" class="form-control" placeholder="URL" name="url"/></td> |
||||
<td><input type='submit' value='Add' name="submit_button" class='btn btn-primary'/></td> |
||||
</thead> |
||||
</table> |
||||
</div> |
||||
</form> |
||||
|
||||
|
||||
<div class="table-responsive"> |
||||
<table class="table table-bordered table-condensed"> |
||||
<div class="table-responsive"> |
||||
<table class="table table-bordered table-condensed"> |
||||
<tr> |
||||
<th>Usuario</th> |
||||
<th>Url</th> |
||||
<th>User</th> |
||||
<th>URL</th> |
||||
<th></th> |
||||
</tr> |
||||
</tr> |
||||
<?php |
||||
foreach ($redirecciones as $redi) { |
||||
foreach ($list as $item) { |
||||
$userInfo = api_get_user_info($item['user_id']); |
||||
$userName = get_lang('Unknown'); |
||||
if (!empty($userInfo)) { |
||||
$userName = $userInfo['complete_name_with_username'].' - '.$item['user_id']; |
||||
} |
||||
echo '<tr>'; |
||||
echo '<td>' . $redi["user_id"] . '</td>'; |
||||
echo '<td>' . $redi["url"] . '</td>'; |
||||
echo '<td><a href="index.php?id=' . $redi["id"] . '">Borrar</a></td>'; |
||||
echo '<td>'.$userName.'</td>'; |
||||
echo '<td>'.$item['url'].'</td>'; |
||||
echo '<td><a class="btn btn-danger" href="index.php?id='.$item['id'].'">Delete</a></td>'; |
||||
echo '</tr>'; |
||||
} |
||||
?> |
||||
</table> |
||||
</div> |
||||
<?php |
||||
|
||||
Display::display_footer(); |
@ -1,7 +1,5 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
/** |
||||
* @author Enrique Alcaraz Lopez |
||||
* @package chamilo.plugin.redirection |
||||
*/ |
||||
|
||||
$strings['plugin_title'] = "Redirección personalizada"; |
||||
$strings['plugin_comment'] = "Redirecciona a una url personalizada a un usuario en concreto"; |
||||
|
@ -1,7 +1,5 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
/** |
||||
* @author Enrique Alcaraz Lopez |
||||
* @package chamilo.plugin.redirection |
||||
*/ |
||||
|
||||
$strings['plugin_title'] = "Redirección personalizada"; |
||||
$strings['plugin_comment'] = "Redirecciona a una url personalizada a un usuario en concreto"; |
||||
|
@ -1,39 +0,0 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
/** |
||||
* Config the plugin |
||||
* @author Enrique Alcaraz Lopez |
||||
* @package chamilo.plugin.redirection |
||||
*/ |
||||
|
||||
class PluginRedirection |
||||
{ |
||||
# Insertamos la redirección |
||||
public static function insert($user_id, $url) |
||||
{ |
||||
return Database::insert( |
||||
'plugin_redirection', |
||||
[ |
||||
'user_id' => $user_id, |
||||
'url' => $url |
||||
] |
||||
); |
||||
} |
||||
|
||||
# Borramos al redirección |
||||
public static function delete($id) |
||||
{ |
||||
$table = Database::get_main_table('plugin_redirection'); |
||||
Database::delete( |
||||
$table, |
||||
array('id = ?' => array($id)) |
||||
); |
||||
} |
||||
|
||||
# Devolemos las redirecciones |
||||
public static function get() |
||||
{ |
||||
$table = Database::get_main_table('plugin_redirection'); |
||||
return Database::select('*', $table); |
||||
} |
||||
} |
@ -1,24 +1,11 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* Plugin |
||||
* @author Enrique Alcaraz Lopez |
||||
* @package chamilo.plugin.redirection |
||||
*/ |
||||
require_once __DIR__.'/lib/redireccion.class.php'; |
||||
|
||||
/* Plugin config */ |
||||
//the plugin title |
||||
$plugin_info['title'] = 'Redireccion personalizada'; |
||||
//the comments that go with the plugin |
||||
$plugin_info['comment'] = "Redirecciona a una url personalizada a un usuario en concreto"; |
||||
//the plugin version |
||||
$plugin_info['version'] = '1'; |
||||
//the plugin author |
||||
$plugin_info['author'] = 'Enrique Alcaraz'; |
||||
|
||||
$form = new FormValidator('redirection_form'); |
||||
$form->addElement('text', 'user_id', get_lang('user_id')); |
||||
$form->addElement('text', 'url', get_lang('url')); |
||||
$form->addButtonSave(get_lang('Save'), 'submit_button'); |
||||
$plugin_info['settings_form'] = $form; |
||||
$plugin_info = RedirectionPlugin::create()->get_info(); |
||||
|
@ -1,2 +0,0 @@ |
||||
# chamilo-plugin-redirection |
||||
Plugin chamilo para la redirección de usuarios. |
Loading…
Reference in new issue