1 |
mlimic |
515 |
<?php |
2 |
|
|
|
3 |
mlimic |
522 |
/* |
4 |
|
|
* The base class for all of the xxxManagers used for processing the |
5 |
|
|
* received requests. |
6 |
|
|
* |
7 |
|
|
* @author: Mirna Limic <[email protected]> |
8 |
|
|
* |
9 |
|
|
* Date: 15/10/2012 |
10 |
|
|
* Follow-up: |
11 |
|
|
* Bugs: Unknown |
12 |
|
|
* |
13 |
|
|
*/ |
14 |
mlimic |
515 |
|
15 |
mlimic |
522 |
|
16 |
|
|
|
17 |
|
|
require_once ("../obj/utils.class.php"); |
18 |
|
|
require_once ("../obj/om_utilisateur.class.php"); |
19 |
|
|
|
20 |
mlimic |
515 |
class MetierManager { |
21 |
|
|
|
22 |
mlimic |
522 |
|
23 |
|
|
/**#@+ |
24 |
|
|
* @access protected |
25 |
|
|
* @var string |
26 |
|
|
*/ |
27 |
mlimic |
515 |
var $KO = 'KO'; |
28 |
|
|
var $OK = 'OK'; |
29 |
|
|
var $DEBUG = 0; |
30 |
|
|
var $GENERIC_ERROR = "Error during request processing"; |
31 |
|
|
|
32 |
mlimic |
522 |
/* |
33 |
|
|
* Constructeur. |
34 |
|
|
* |
35 |
|
|
* Sets 'collectivite', and 'login' in the $_SESSION. |
36 |
|
|
* @todo The value stored in the $_SESSION['collectivite'] needs to |
37 |
|
|
* be obtained rather than hardcoded. |
38 |
|
|
* @todo The value stored in the $_SESSION['login'] could be obtained |
39 |
|
|
* rather than being hardcoded to "somelogin". |
40 |
|
|
* @uses utils Uses the obj/utils.class.php to establish a DB connection. |
41 |
|
|
* @uses application::connectDatabase() In this function the execution |
42 |
|
|
* could terminate if the connection to DB cannot be established. The |
43 |
|
|
* important thing to prevent this is to set the $_SESSION['login'] to |
44 |
|
|
* value that is not empty and that is bogus. |
45 |
|
|
*/ |
46 |
|
|
public function __construct() { |
47 |
mlimic |
515 |
session_start(); |
48 |
|
|
// Setter les variables de $_SESSION pour la connexion avec BD |
49 |
|
|
$_SESSION['collectivite'] = 1; // Arles |
50 |
mlimic |
522 |
// login has to be set to some value, i.e. it must not be empty, |
51 |
|
|
// and $_SESSION['justlogin'] MUST NOT be set, otherwise |
52 |
|
|
// isAuthenticated() inside of om_application will fail, and the |
53 |
|
|
// the script will stop executing |
54 |
mlimic |
515 |
$_SESSION['login'] = "somelogin"; |
55 |
|
|
// Genere une connexion a la base de donnees |
56 |
|
|
$this->f = new utils("nohtml"); |
57 |
mlimic |
522 |
// set the type of the DB to use |
58 |
mlimic |
515 |
$this->f->db->phptype = 'pgsql'; |
59 |
mlimic |
522 |
// save the reference to DB |
60 |
mlimic |
515 |
$this->db = $this->f->db; |
61 |
|
|
}// fin constructeur |
62 |
|
|
|
63 |
mlimic |
522 |
|
64 |
|
|
/* |
65 |
|
|
* Destructor |
66 |
|
|
* |
67 |
|
|
* Unsets the instance of the utils class. |
68 |
|
|
* Unsets in the $_SESSION the key=>value pairs that were set in |
69 |
|
|
* the constructor. |
70 |
|
|
*/ |
71 |
|
|
public function __destruct() { |
72 |
mlimic |
515 |
unset($this->f); |
73 |
|
|
unset($_SESSION['login']); |
74 |
|
|
unset($_SESSION['collectivite']); |
75 |
|
|
} |
76 |
|
|
|
77 |
mlimic |
522 |
|
78 |
|
|
/* |
79 |
|
|
* Checks that the data received in the request is valid. |
80 |
|
|
* |
81 |
|
|
* To be overridden in the derived classes. |
82 |
|
|
* @return bool Always return true. |
83 |
|
|
*/ |
84 |
|
|
protected function requestValid() { |
85 |
mlimic |
515 |
// A etre implemente dans les classes derivees |
86 |
|
|
return true; |
87 |
|
|
} |
88 |
|
|
|
89 |
mlimic |
522 |
|
90 |
|
|
/* |
91 |
|
|
* Filters out the HTML tags from a string. |
92 |
|
|
* |
93 |
|
|
* @param string $var The string from which to filter out the HTML tags. |
94 |
|
|
* @return string Returns $var without the HTML tags. |
95 |
|
|
*/ |
96 |
|
|
private function filterOutHtmlTags($var) { |
97 |
mlimic |
515 |
$pattern = '/<[\/]*[\sa-zA-Z0-9="]*[\/]*>/'; |
98 |
|
|
$replacement = ''; |
99 |
|
|
return preg_replace($pattern, $replacement, $var); |
100 |
|
|
} |
101 |
|
|
|
102 |
mlimic |
522 |
|
103 |
|
|
/* |
104 |
|
|
* Executes the insertion of a record into DB by calling the |
105 |
|
|
* dbform::ajouter() method. |
106 |
|
|
* |
107 |
|
|
* Precondition: $this->metier_instance is not null. |
108 |
|
|
* |
109 |
|
|
* @uses dbform::ajouter() The method that does insertion of data |
110 |
|
|
* into a DB |
111 |
|
|
* @return string Returns 'OK' on success, error message set by the |
112 |
|
|
* application (if it was set), a generic error message otherwise. |
113 |
|
|
*/ |
114 |
|
|
protected function ajouter(&$data) { |
115 |
mlimic |
515 |
// essai d'ajout des donnees dans la base de donnees |
116 |
|
|
$this->metier_instance->ajouter($data, $this->db, $this->DEBUG); |
117 |
|
|
if ($this->metier_instance->correct == false) { |
118 |
|
|
if (isset($this->metier_instance->msg) |
119 |
|
|
&& !empty($this->metier_instance->msg)) { |
120 |
|
|
return $this->filterOutHtmlTags($this->metier_instance->msg); |
121 |
|
|
} |
122 |
|
|
return $this->GENERIC_ERROR; |
123 |
|
|
} |
124 |
|
|
return $this->OK; |
125 |
|
|
} |
126 |
|
|
|
127 |
mlimic |
522 |
|
128 |
|
|
/* |
129 |
|
|
* Executes the update of a record in DB by calling the |
130 |
|
|
* dbform::modifier() method. |
131 |
|
|
* |
132 |
|
|
* Precondition: $this->metier_instance is not null. |
133 |
|
|
* |
134 |
|
|
* @uses dbform::modifier() The method that does insertion of data |
135 |
|
|
* into a DB |
136 |
|
|
* @return string Returns 'OK' on success, error message set by the |
137 |
|
|
* application (if it was set), a generic error message otherwise. |
138 |
|
|
*/ |
139 |
|
|
protected function modifier(&$data) { |
140 |
mlimic |
515 |
// essai de la modification des donnees dans la base de donnees |
141 |
|
|
$ret = $this->metier_instance->modifier($data, $this->db, $this->DEBUG); |
142 |
|
|
if ($this->metier_instance->correct == false) { |
143 |
|
|
if (isset($this->metier_instance->msg) |
144 |
|
|
&& !empty($this->metier_instance->msg)) { |
145 |
|
|
return $this->filterOutHtmlTags($this->metier_instance->msg); |
146 |
|
|
} |
147 |
|
|
return $this->GENERIC_ERROR; |
148 |
|
|
} |
149 |
|
|
return $this->OK; |
150 |
|
|
} |
151 |
|
|
|
152 |
|
|
|
153 |
mlimic |
522 |
/* |
154 |
|
|
* Executes the insertion of a record into DB by calling the |
155 |
|
|
* dbform::supprimer() method. |
156 |
|
|
* |
157 |
|
|
* Precondition: $this->metier_instance is not null. |
158 |
|
|
* |
159 |
|
|
* @uses dbform::supprimer() The method that does insertion of data |
160 |
|
|
* into a DB |
161 |
|
|
* @return string Returns 'OK' on success, error message set by the |
162 |
|
|
* application (if it was set), a generic error message otherwise. |
163 |
|
|
*/ |
164 |
|
|
protected function supprimer(&$data) { |
165 |
mlimic |
515 |
// essai de la suppression des donnes dans la base de donnees |
166 |
|
|
$ret = $this->metier_instance->supprimer($data, $this->db, $this->DEBUG); |
167 |
|
|
if ($this->metier_instance->correct == false) { |
168 |
|
|
if (isset($this->metier_instance->msg) |
169 |
|
|
&& !empty($this->metier_instance->msg)) { |
170 |
|
|
return $this->filterOutHtmlTags($this->metier_instance->msg); |
171 |
|
|
} |
172 |
|
|
return $this->GENERIC_ERROR; |
173 |
|
|
} |
174 |
|
|
return $this->OK; |
175 |
|
|
} |
176 |
|
|
|
177 |
|
|
/* |
178 |
mlimic |
522 |
* This function is to be overwritten by the derived classes when a GET |
179 |
|
|
* request is received. |
180 |
|
|
* |
181 |
|
|
* @return bool Always returns 'KO' to indicate that by default, |
182 |
|
|
* extraction of data from the DB is not supported. |
183 |
mlimic |
515 |
*/ |
184 |
mlimic |
522 |
protected function extraire(&$data) { |
185 |
|
|
// |
186 |
mlimic |
515 |
return $this->KO; |
187 |
|
|
} |
188 |
|
|
|
189 |
|
|
|
190 |
|
|
}// fin classe |
191 |
|
|
?> |