glpi-plugin-auf : ajout des champs AUF
[auf-serveur.git] / glpi-plugin-auf / plugin / inc / profile.class.php
1 <?php
2 /*
3 AUF plugin for GLPI
4 Copyright (C) 2014 AUF -- www.auf.org
5 */
6 if (!defined('GLPI_ROOT')) {
7 die("Sorry. You can't access directly to this file");
8 }
9
10 class PluginAufProfile extends CommonDBTM {
11
12 static function canCreate() {
13 if (isset($_SESSION["glpi_plugin_auf_profile"])) {
14 return ($_SESSION["glpi_plugin_auf_profile"]['auf'] == 'w');
15 }
16 return false;
17 }
18
19 static function canView() {
20 if (isset($_SESSION["glpi_plugin_auf_profile"])) {
21 return ($_SESSION["glpi_plugin_auf_profile"]['auf'] == 'w'
22 || $_SESSION["glpi_plugin_auf_profile"]['auf'] == 'r');
23 }
24 return false;
25 }
26
27 static function createAdminAccess($ID) {
28 $myProf = new self();
29 // si le profile n'existent pas déjà dans la table profile de mon plugin
30 if (!$myProf->getFromDB($ID)) {
31 // ajouter un champ dans la table comprenant l'ID du profil de la
32 // personne connectée et le droit d'écriture
33 $myProf->add(array('id' => $ID, 'right' => 'w'));
34 }
35 }
36
37 function createAccess($ID) {
38 $this->add(array('id' => $ID));
39 }
40
41 static function changeProfile() {
42 $prof = new self();
43 if ($prof->getFromDB($_SESSION['glpiactiveprofile']['id'])) {
44 $_SESSION["glpi_plugin_auf_profile"] = $prof->fields;
45 } else {
46 unset($_SESSION["glpi_plugin_auf_profile"]);
47 }
48 }
49
50 function showForm($id, $options=array()) {
51 $target = $this->getFormURL();
52 if (isset($options['target'])) {
53 $target = $options['target'];
54 }
55
56 if (!Session::haveRight("profile", "r")) {
57 return false;
58 }
59
60 $canedit = Session::haveRight("profile", "w");
61 $prof = new Profile();
62 if ($id){
63 $this->getFromDB($id);
64 $prof->getFromDB($id);
65 }
66
67 echo "<form action='".$target."' method='post'>";
68 echo "<table class='tab_cadre_fixe'>";
69 echo "<tr><th colspan='2' class='center b'>".sprintf(__('%1$s %2$s'),
70 ('Gestion des droits -'), Dropdown::getDropdownName("glpi_profiles",
71 $this->fields["id"]));
72 echo "</th></tr>";
73
74 echo "<tr class='tab_bg_2'>";
75 echo "<td>Infos AUF</td><td>";
76 Profile::dropdownNoneReadWrite("right", $this->fields["right"], 1, 1, 1);
77 echo "</td></tr>";
78
79 if ($canedit) {
80 echo "<tr class='tab_bg_1'>";
81 echo "<td class='center' colspan='2'>";
82 echo "<input type='hidden' name='id' value=$id>";
83 echo "<input type='submit' name='update_user_profile' value='Mettre à jour' class='submit'>";
84 echo "</td></tr>";
85 }
86 echo "</table>";
87 Html::closeForm();
88 }
89
90 function getTabNameForItem(CommonGLPI $item, $withtemplate=0) {
91 if ($item->getType() == 'Profile') {
92 return "Infos AUF";
93 }
94 return '';
95 }
96
97 static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) {
98 if ($item->getType() == 'Profile') {
99 $ID = $item->getID();
100 $prof = new self();
101 // si le profil n'existe pas dans la base, je l'ajoute
102 if (!$prof->GetfromDB($ID)) {
103 $prof->createAccess($ID);
104 }
105 $prof->showForm($ID);
106 }
107 return true;
108 }
109
110 }
111
112 ?>