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 | 
					<?php | 
				
			||||||
/* For licensing terms, see /license.txt */ | 
					/* For licensing terms, see /license.txt */ | 
				
			||||||
 | 
					
 | 
				
			||||||
/** | 
					/** | 
				
			||||||
* Config the plugin | 
					 * Config the plugin | 
				
			||||||
* @author Enrique Alcaraz Lopez | 
					 * @author Enrique Alcaraz Lopez | 
				
			||||||
* @package chamilo.plugin.redirection | 
					 * @package chamilo.plugin.redirection | 
				
			||||||
*/ | 
					 */ | 
				
			||||||
 | 
					
 | 
				
			||||||
require_once __DIR__.'/config.php'; | 
					require_once __DIR__.'/config.php'; | 
				
			||||||
$redirecciones = PluginRedirection::get(); | 
					
 | 
				
			||||||
 | 
					api_protect_admin_script(); | 
				
			||||||
if (isset($_REQUEST["id"])) { | 
					
 | 
				
			||||||
    PluginRedirection::delete($_REQUEST["id"]); | 
					$list = RedirectionPlugin::getAll(); | 
				
			||||||
    header("Location: index.php"); | 
					
 | 
				
			||||||
    exit();     | 
					if (isset($_REQUEST['id'])) { | 
				
			||||||
} elseif (isset($_POST["submit_button"])) {     | 
					    RedirectionPlugin::delete($_REQUEST['id']); | 
				
			||||||
    PluginRedirection::insert($_POST["user_id"], $_POST["url"]); | 
					    Display::addFlash(Display::return_message(get_lang('Deleted'))); | 
				
			||||||
    header("Location: index.php"); | 
					    header('Location: index.php'); | 
				
			||||||
    exit(); | 
					    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"> | 
					<form action="./index.php" method="post"> | 
				
			||||||
<div class="table-responsive well">  | 
					    <div class="table-responsive well"> | 
				
			||||||
    <table class="table table-condensed">             | 
					        <table class="table table-condensed"> | 
				
			||||||
        <thead> | 
					            <thead> | 
				
			||||||
            <td><input type="text" class="form-control" placeholder="User_id" name="user_id" /></td> | 
					            <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="text" class="form-control" placeholder="URL" name="url"/></td> | 
				
			||||||
            <td><input type='submit' value='Agregar' name="submit_button" class='btn btn-primary' /></td> | 
					            <td><input type='submit' value='Add' name="submit_button" class='btn btn-primary'/></td> | 
				
			||||||
        </thead>         | 
					            </thead> | 
				
			||||||
    </table> | 
					        </table> | 
				
			||||||
     | 
					    </div> | 
				
			||||||
</div> | 
					 | 
				
			||||||
</form> | 
					</form> | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<div class="table-responsive">  | 
					<div class="table-responsive"> | 
				
			||||||
    <table class="table table-bordered table-condensed">             | 
					    <table class="table table-bordered table-condensed"> | 
				
			||||||
        <tr> | 
					        <tr> | 
				
			||||||
            <th>Usuario</th> | 
					            <th>User</th> | 
				
			||||||
            <th>Url</th> | 
					            <th>URL</th> | 
				
			||||||
            <th></th> | 
					            <th></th> | 
				
			||||||
        </tr>             | 
					        </tr> | 
				
			||||||
        <?php | 
					        <?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 '<tr>'; | 
				
			||||||
            echo '<td>' . $redi["user_id"] . '</td>'; | 
					            echo '<td>'.$userName.'</td>'; | 
				
			||||||
            echo '<td>' . $redi["url"] . '</td>'; | 
					            echo '<td>'.$item['url'].'</td>'; | 
				
			||||||
            echo '<td><a href="index.php?id=' . $redi["id"] . '">Borrar</a></td>'; | 
					            echo '<td><a class="btn btn-danger" href="index.php?id='.$item['id'].'">Delete</a></td>'; | 
				
			||||||
            echo '</tr>'; | 
					            echo '</tr>'; | 
				
			||||||
        } | 
					        } | 
				
			||||||
        ?> | 
					        ?> | 
				
			||||||
    </table> | 
					    </table> | 
				
			||||||
</div> | 
					</div> | 
				
			||||||
 | 
					<?php | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Display::display_footer(); | 
				
			||||||
@ -1,7 +1,5 @@ | 
				
			|||||||
<?php | 
					<?php | 
				
			||||||
/* For licensing terms, see /license.txt */ | 
					/* 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 | 
					<?php | 
				
			||||||
/* For licensing terms, see /license.txt */ | 
					/* 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 | 
					<?php | 
				
			||||||
/* For licensing terms, see /license.txt */ | 
					/* For licensing terms, see /license.txt */ | 
				
			||||||
 | 
					
 | 
				
			||||||
/** | 
					/** | 
				
			||||||
 * Plugin | 
					 * Plugin | 
				
			||||||
 * @author Enrique Alcaraz Lopez | 
					 * @author Enrique Alcaraz Lopez | 
				
			||||||
 * @package chamilo.plugin.redirection | 
					 * @package chamilo.plugin.redirection | 
				
			||||||
 */ | 
					 */ | 
				
			||||||
require_once __DIR__.'/lib/redireccion.class.php'; | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Plugin config */ | 
					/* Plugin config */ | 
				
			||||||
//the plugin title | 
					$plugin_info = RedirectionPlugin::create()->get_info(); | 
				
			||||||
$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; | 
					 | 
				
			||||||
 | 
				
			|||||||
@ -1,2 +0,0 @@ | 
				
			|||||||
# chamilo-plugin-redirection | 
					 | 
				
			||||||
Plugin chamilo para la redirección de usuarios. | 
					 | 
				
			||||||
					Loading…
					
					
				
		Reference in new issue