1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* @author Xavier Chopin <[email protected]> |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace App\Controller; |
11
|
|
|
|
12
|
|
|
use App\Model\API\User; |
13
|
|
|
use Exception; |
14
|
|
|
use Symfony\Component\HttpFoundation\Request; |
15
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @Route("/tools") |
20
|
|
|
*/ |
21
|
|
|
class AdminController extends AbstractController implements AdminAuthenticatedInterface |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* GET: Renders a form page to find a student |
25
|
|
|
* POST: Returns JSON data for a name given |
26
|
|
|
* |
27
|
|
|
* @Route("/view-as", name="view-as") |
28
|
|
|
* @param Request $request |
29
|
|
|
* @return \Symfony\Component\HttpFoundation\JsonResponse | \Symfony\Component\HttpFoundation\Response |
30
|
|
|
*/ |
31
|
|
|
public function findStudent(Request $request) |
32
|
|
|
{ |
33
|
|
|
if ($request->isMethod('POST')) { |
34
|
|
|
$keyword = $request->get('name'); |
35
|
|
|
$filter = '(&(businesscategory=E*)(displayname=*' . $keyword . '*))'; |
36
|
|
|
$students = $this->ldap($filter, ['displayname', 'uid']); |
37
|
|
|
$res = []; |
38
|
|
|
|
39
|
|
|
foreach($students as $student) { |
40
|
|
|
if ($student['uid'][0] != null) |
41
|
|
|
$res += [ $student['uid'][0] => $student['displayname'][0] ]; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
return $this->json($res); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return $this->render('Admin/find-student.twig'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* |
52
|
|
|
* @Route("/view/{id}", name="enable-view") |
53
|
|
|
* @param Request $request |
54
|
|
|
* @param String $id |
55
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
56
|
|
|
*/ |
57
|
|
|
public function viewAs(Request $request, String $id) |
|
|
|
|
58
|
|
|
{ |
59
|
|
|
$_SESSION['username'] = $_SESSION['phpCAS']['user']; |
60
|
|
|
$_SESSION['phpCAS']['user'] = $id; |
61
|
|
|
return $this->redirectToRoute('home'); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.