admin.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Admin interface for the plugin configuration.
  5. *
  6. * @author Enrique Alcaraz Lopez
  7. *
  8. * @package chamilo.plugin.redirection
  9. */
  10. require_once __DIR__.'/config.php';
  11. api_protect_admin_script();
  12. $list = RedirectionPlugin::getAll();
  13. $url = api_get_path(WEB_PLUGIN_PATH).'redirection/admin.php';
  14. $form = new FormValidator('add', 'post', api_get_self());
  15. $form->addHeader('Redirection');
  16. $form->addSelectAjax(
  17. 'user_id',
  18. get_lang('User'),
  19. null,
  20. [
  21. 'url' => api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=get_user_like',
  22. 'id' => 'user_id',
  23. ]
  24. );
  25. $form->addUrl('url', 'URL');
  26. $form->addButtonSend(get_lang('Add'));
  27. if (isset($_REQUEST['id'])) {
  28. RedirectionPlugin::delete($_REQUEST['id']);
  29. Display::addFlash(Display::return_message(get_lang('Deleted')));
  30. header('Location: admin.php');
  31. exit;
  32. }
  33. if ($form->validate()) {
  34. $result = RedirectionPlugin::insert($_POST['user_id'], $_POST['url']);
  35. if ($result) {
  36. Display::addFlash(Display::return_message(get_lang('Added')));
  37. } else {
  38. Display::addFlash(Display::return_message(get_lang('Error'), 'warning'));
  39. }
  40. header('Location: '.$url);
  41. exit;
  42. }
  43. $content = $form->returnForm();
  44. $content .= '
  45. <div class="table-responsive">
  46. <table class="table table-bordered table-condensed">
  47. <tr>
  48. <th>User</th>
  49. <th>URL</th>
  50. <th></th>
  51. </tr>
  52. ';
  53. foreach ($list as $item) {
  54. $userInfo = api_get_user_info($item['user_id']);
  55. $userName = get_lang('Unknown');
  56. if (!empty($userInfo)) {
  57. $userName = $userInfo['complete_name_with_username'].' - '.$item['user_id'];
  58. }
  59. $content .= '<tr>';
  60. $content .= '<td>'.$userName.'</td>';
  61. $content .= '<td>'.$item['url'].'</td>';
  62. $content .= '<td><a class="btn btn-danger" href="'.$url.'?id='.$item['id'].'">Delete</a></td>';
  63. $content .= '</tr>';
  64. }
  65. $content .= '
  66. </table>
  67. </div>';
  68. $tpl = new Template(
  69. '',
  70. true,
  71. true,
  72. false,
  73. false,
  74. false
  75. );
  76. $tpl->assign('content', $content);
  77. $tpl->display_one_col_template();