idproc = $idproc+0; if ($this->idproc) { $this->load(); } } // charge une procedure a partir de la base. public function load(){ global $dbh; $q = "select name, requete, comment, autorisations, parameters, num_classement, p_mode, p_form from procs where idproc = '".$this->idproc."' "; $r = pmb_mysql_query($q, $dbh) ; $obj = pmb_mysql_fetch_object($r); $this->name = $obj->name; $this->requete = $obj->requete; $this->comment = $obj->comment; $this->autorisations = explode(' ', $obj->autorisations); $this->parameters = $obj->parameters; $this->p_type = $obj->p_type; $this->num_classement = $obj->num_classement; $this->p_mode = $obj->p_mode; $this->p_form = $obj->p_form; } // enregistre une procedure en base. public function save(){ global $dbh; if ($this->idproc) { $q = "update procs set "; $q.= "requete = '".addslashes($this->requete)."', "; $q.= "comment = '".addslashes($this->comment)."', "; $q.= "autorisation = '".implode(' ', $this->autorisations)."', "; $q.= "parameters ='".addslashes($this->parameters)."', "; $q.= "num_classement = '".$this->num_classement."', "; $q.= "p_mode = '".$this->p_mode."', "; $q.= "p_form = '".addslashes($this->p_form)."' "; $q.= "where idproc = '".$this->idproc."' "; pmb_mysql_query($q, $dbh); } else { $q = "insert into procs set "; $q.= "requete = '".addslashes($this->requete)."', "; $q.= "comment = '".addslashes($this->comment)."', "; $q.= "autorisation = '".implode(' ', $this->autorisations)."', "; $q.= "parameters ='".addslashes($this->parameters)."', "; $q.= "num_classement = '".$this->num_classement."', "; $q.= "p_mode = '".$this->p_mode."', "; $q.= "p_form = '".addslashes($this->p_form)."' "; pmb_mysql_query($q, $dbh); $this->idproc = pmb_mysql_insert_id($dbh); } } //supprime une procedure de la base public function delete($idproc = 0) { if(!$idproc) $idproc = $this->idproc; $q = "delete from procs where idproc = '".$idproc."' "; pmb_mysql_query($q); } //retourne un form pour les autorisations d'une requete ou les autorisations par defaut si requete non creee static public function getAutorisationsForm() { global $dbh, $charset; global $req_auth; $aut = array('1'); //recuperation des utilisateurs $q = "SELECT userid, username FROM users "; $r = pmb_mysql_query($q, $dbh); $p_user = array(); while (($row=pmb_mysql_fetch_row($r))) { $p_user[$row[0]]=$row[1]; } $form = ""; $id_check_list=''; foreach($p_user as $userid=>$username) { $form.= $req_auth; $form = str_replace('!!user_name!!', htmlentities($username,ENT_QUOTES, $charset), $form); $form = str_replace('!!user_id!!', $userid, $form); if (in_array($userid, $aut)) { $chk = 'checked=\'checked\''; } else { $chk = ''; } $form = str_replace('!!checked!!', $chk, $form); $id_check="user_aut[".$userid."]"; if($id_check_list)$id_check_list.='|'; $id_check_list.=$id_check; } $form.=""; return $form; } } ?>