noalyss  Version-6.9.1.8
 All Data Structures Namespaces Files Functions Variables Pages
class_dossier.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of NOALYSS.
5  *
6  * NOALYSS is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * NOALYSS is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with NOALYSS; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 
21 // Copyright Author Dany De Bontridder danydb@aevalys.eu
22 
23 /*!\file
24  * \brief the class for the dossier, everywhere we need to know to
25  * which folder we are connected, because we can't use $_SESSION, we
26  * need to pass the dossier_id via a _GET or a POST variable
27  */
28 
29 /*! \brief manage the current dossier, everywhere we need to know to
30  * which folder we are connected, because we can't use $_SESSION, we
31  * need to pass the dossier_id via a _GET or a POST variable
32  * private static $variable=array("id"=>"dos_id",
33  "name"=>"dos_name",
34  "desc"=>"dos_description");
35  *
36  */
37 require_once NOALYSS_INCLUDE.'/lib/class_database.php';
38 require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
39 require_once NOALYSS_INCLUDE.'/class/class_user.php';
40 
41 class Dossier
42 {
43 
44  private static $variable=array("id"=>"dos_id",
45  "name"=>"dos_name",
46  "desc"=>"dos_description",
47  "max_email"=>'dos_email');
48 
49  function __construct($p_id)
50  {
51  $this->cn=new Database(); // Connect to the repository
52  $this->dos_id=$p_id;
53  }
54 
55  /*!\brief return the $_REQUEST['gDossier'] after a check */
56 
57  static function id()
58  {
59  self::check();
60  return $_REQUEST['gDossier'];
61  }
62 
63  /**
64  * @brief Show the folder where user have access.
65  * @param p_type string
66  - A for all dossiers
67  - R for accessible folders
68  - X forbidden folders
69  * @param p_login is the user name
70  * @param p_text is a part of the name where are looking for
71  * @return nothing
72  *
73  */
74  static function show_dossier($p_type, $p_login="", $p_text="", $limit=0)
75  {
76  $cn=new Database();
77  $str_limit=($limit==0)?'':' limit '.$limit;
78  if ($p_type=="A")
79  {
80  $l_sql="select *, 'W' as priv_priv "
81  . "from ac_dossier "
82  . "where "
83  . "dos_name ~* $2 "
84  . "or dos_description ~* $2 "
85  . "ORDER BY dos_name $str_limit ";
86  $a_row=$cn->get_array($l_sql, $p_text);
87  return $a_row;
88  }
89  else if ($p_type=="R")
90  {
91  $l_sql="select * from jnt_use_dos
92  natural join ac_dossier
93  natural join ac_users
94  where
95  use_login=$1
96  and ( dos_name ~* $2 or dos_description ~* $2)
97 
98  order by dos_name
99  $str_limit
100  ";
101 
102  $a_row=$cn->get_array($l_sql, array($p_login, $p_text));
103  return $a_row;
104  }
105  else if ($p_type=='X')
106  {
107  $l_sql=' select * from ac_dossier where dos_id not in
108  (select dos_id from jnt_use_dos where use_id=$1)
109  and ( dos_name ~* $2 or dos_description ~* $2)
110  order by dos_name '.$str_limit;
111  $a_row=$cn->get_array($l_sql, array($p_login, $p_text));
112  return $a_row;
113  }
114  else
115  {
116  throw new Exception(_("Erreur paramètre"));
117  }
118  }
119 
120  /**
121  * Count the number of folder in the repository
122  * @return integer
123  */
124  function count()
125  {
126  $nb_folder=$this->cn->get_value('select count(*) from ac_dossier');
127  return $nb_folder;
128  }
129 
130  /*!
131  * \brief Return all the users
132  * as an array
133  */
134 
135  function get_user_folder($sql="")
136  {
137 
138  $sql="
139  select
140  use_id,
141  use_first_name,
142  use_name,
143  use_login,
144  use_active,
145  use_admin,
146  ag_dossier
147  from
148  ac_users as ac
149  left join
150  (select array_to_string(array_agg(dos_name),',') as ag_dossier,
151  jt.use_id as jt_use_id
152  from ac_dossier as ds
153  join jnt_use_dos as jt on (jt.dos_id=ds.dos_id)
154  group by jt.use_id) as dossier_name on (jt_use_id=ac.use_id)
155  where
156  use_login!=$1
157  $sql
158  ";
159 
160  $res=$this->cn->get_array($sql,array(NOALYSS_ADMINISTRATOR));
161  return $res;
162  }
163 
164  /*!\brief check if gDossier is set */
165 
166  static function check()
167  {
168  if (!isset($_REQUEST['gDossier']))
169  {
170  echo_error('Dossier inconnu ');
171  exit('Dossier invalide ');
172  }
173  $id=$_REQUEST['gDossier'];
174  if (is_numeric($id)==0||
175  strlen($id)>6||
176  $id>999999)
177  exit('gDossier Invalide : '.$id);
178  }
179 
180  /*!
181  * \brief return a string to put to gDossier into a GET
182  */
183 
184  static function get()
185  {
186  self::check();
187  return "gDossier=".$_REQUEST['gDossier'];
188  }
189 
190  /*!\brief return a string to set gDossier into a FORM */
191 
192  static function hidden()
193  {
194  self::check();
195  return '<input type="hidden" id="gDossier" name="gDossier" value="'.$_REQUEST['gDossier'].'">';
196  }
197 
198  /*!\brief retrieve the name of the current dossier */
199 
200  static function name($id=0)
201  {
202  self::check();
203 
204  $cn=new Database();
205  $id=($id==0)?$_REQUEST['gDossier']:$id;
206  $name=$cn->get_value("select dos_name from ac_dossier where dos_id=$1",
207  array($_REQUEST['gDossier']));
208  return $name;
209  }
210 
211  public function get_parameter($p_string)
212  {
213  if (array_key_exists($p_string, self::$variable))
214  {
215  $idx=self::$variable[$p_string];
216  return $this->$idx;
217  }
218  else
219  throw new Exception("Attribut inexistant $p_string");
220  }
221 
222  public function set_parameter($p_string, $p_value)
223  {
224  if (array_key_exists($p_string, self::$variable))
225  {
226  $idx=self::$variable[$p_string];
227  $this->$idx=$p_value;
228  }
229  else
230  throw new Exception("Attribut inexistant $p_string");
231  }
232 
233  public function get_info()
234  {
235  return var_export(self::$variable, true);
236  }
237 
238  public function save()
239  {
240  $this->update();
241  }
242 
243  public function update()
244  {
245  if (strlen(trim($this->dos_name))==0)
246  return;
247 
248  if ($this->cn->get_value("select count(*) from ac_dossier "
249  . " where dos_name=$1 and dos_id<>$2",
250  array($this->dos_name, $this->dos_id))!=0)
251  return;
252 
253  $sql="update ac_dossier set dos_name=$1,dos_description=$2 ,dos_email=$3".
254  " where dos_id = $4";
255  $res=$this->cn->exec_sql(
256  $sql,
257  array(trim($this->dos_name),
258  trim($this->dos_description),
259  $this->dos_email,
260  $this->dos_id)
261  );
262  }
263 
264  public function load()
265  {
266 
267  $sql="select dos_name,dos_description,dos_email from ac_dossier where dos_id=$1";
268 
269  $res=$this->cn->exec_sql(
270  $sql, array($this->dos_id)
271  );
272 
273  if (Database::num_row($res)==0)
274  return;
276  foreach ($row as $idx=> $value)
277  {
278  $this->$idx=$value;
279  }
280  }
281 
282  static function get_version($p_cn)
283  {
284  return $p_cn->get_value('select val from version');
285  }
286 
287  static function connect()
288  {
289  static $cn=null;
290  if ($cn!=null)
291  return $cn;
292  $id=Dossier::id();
293  $cn=new Database($id);
294  return $cn;
295  }
296 
297  /**
298  * connect to folder and give to admin. the profile Admin(builtin)
299  * @param int $p_id dossier::id()
300  */
301  static function synchro_admin($p_id)
302  {
303  // connect to target
304  $cn=new Database($p_id);
305 
306  if (!$cn->exist_table("profile_menu"))
307  {
308  echo_warning("Dossier invalide");
309  return;
310  }
311  // connect to repo
312  $repo=new Database();
313 
314  $a_admin=$repo->get_array("select use_login from ac_users where
315  use_admin=1 and use_active=1");
316  try
317  {
318  /**
319  * synchro global
320  */
321  $cn->start();
322  for ($i=0; $i<count($a_admin); $i++)
323  {
324  User::grant_admin_access($a_admin[$i]['use_login'], $p_id);
325  }
326  $cn->commit();
327  }
328  catch (Exception $e)
329  {
330  echo_warning($e->getMessage());
331  error_log($e->getTraceAsString());
332  $cn->rollback();
333  }
334  }
335 
336 }
static grant_admin_access($p_login, $p_dossier)
Grant access to folder, grant administrator profile , all the ledgers and all the action...
get_parameter($p_string)
static synchro_admin($p_id)
connect to folder and give to admin.
static num_row($ret)
wrapper for the function pg_NumRows
static get_version($p_cn)
count()
Count the number of folder in the repository.
$value
static show_dossier($p_type, $p_login="", $p_text="", $limit=0)
Show the folder where user have access.
$idx
set_parameter($p_string, $p_value)
static name($id=0)
retrieve the name of the current dossier
static $variable
static check()
check if gDossier is set
__construct($p_id)
static fetch_array($ret, $p_indice=0)
wrapper for the function pg_fetch_array
echo_error($p_log, $p_line="", $p_message="")
log error into the /tmp/noalyss_error.log it doesn't work on windows
Definition: ac_common.php:153
get_user_folder($sql="")
Return all the users as an array.
static hidden()
return a string to set gDossier into a FORM
$_REQUEST['ac']
function trim(s)
remove trailing and heading space
Definition: scripts.js:95
$input_from cn
Definition: balance.inc.php:71
static id()
return the $_REQUEST['gDossier'] after a check
This class allow you to connect to the postgresql database, execute sql, retrieve data...
static connect()
$limit
Definition: dashboard.php:157
manage the current dossier, everywhere we need to know to which folder we are connected, because we can't use $_SESSION, we need to pass the dossier_id via a _GET or a POST variable private static $variable=array("id"=>"dos_id", "name"=>"dos_name", "desc"=>"dos_description");
if(isset($_REQUEST['gDossier'])&&$_REQUEST['gDossier']<>0) $repo
for($e=0;$e< count($afiche);$e++) exit
echo_warning($p_string)
warns
Definition: ac_common.php:546