type_obj = $type+0; $this->object_id = $obj+0; $this->all_audit=array() ; } // --------------------------------------------------------------- // get_all () : récupération toutes informations // --------------------------------------------------------------- public function get_all() { global $pmb_type_audit, $msg ; if (!$pmb_type_audit) return 0; $query = "select user_id, user_name, type_modif, quand, date_format(quand, '".$msg["format_date_heure"]."') as aff_quand, concat(prenom, ' ', nom) as prenom_nom from audit left join users on user_id=userid where "; $query .= "type_obj='$this->type_obj' AND "; $query .= "object_id='$this->object_id' "; $query .= "order by quand "; $result = @pmb_mysql_query($query); if(!$result) die("can't select from table audit left join users :
$query "); if(pmb_mysql_num_rows($result)){ while ($audit=pmb_mysql_fetch_object($result)) { $this->all_audit[] = $audit ; } } } // --------------------------------------------------------------- // get_creation () : récupération création // --------------------------------------------------------------- public function get_creation () { global $dbh, $pmb_type_audit ; if (!$pmb_type_audit || !isset($this->all_audit[0])) return 0; return $this->all_audit[0]; } // --------------------------------------------------------------- // get_last () : récupération dernière modification // --------------------------------------------------------------- public function get_last () { global $pmb_type_audit ; if (!$pmb_type_audit || !isset($this->all_audit[(count($this->all_audit)-1)])) return 0; return $this->all_audit[(count($this->all_audit)-1)]; } // --------------------------------------------------------------- // insert_creation ($type=0, $obj=0) : // --------------------------------------------------------------- public static function insert_creation ($type=0, $obj=0) { global $pmb_type_audit , $msg; if (!$pmb_type_audit) return 0; $type += 0; $obj += 0; $query = "INSERT INTO audit SET "; $query .= "type_obj='$type', "; $query .= "object_id='$obj', "; $query .= "user_id=0, "; $query .= "user_name='".$msg['audit_lecteur']."', "; $query .= "type_modif=1, "; $query .= "type_user=1 "; $result = @pmb_mysql_query($query); if(!$result) return 0; return 1; } // --------------------------------------------------------------- // insert_modif ($type=0, $obj=0) : // --------------------------------------------------------------- public static function insert_modif ($type=0, $obj=0) { global $pmb_type_audit, $msg ; if (!$pmb_type_audit) return 0; $type += 0; $obj += 0; if ($pmb_type_audit=='1') { $query = "DELETE FROM audit WHERE "; $query .= "type_obj='$type' AND "; $query .= "object_id='$obj' AND "; $query .= "type_modif=2 "; $result = @pmb_mysql_query($query); if(!$result) return 0; } $query = "INSERT INTO audit SET "; $query .= "type_obj='$type', "; $query .= "object_id='$obj', "; $query .= "user_id=0, "; $query .= "user_name='".$msg['audit_lecteur']."', "; $query .= "type_modif=2, "; $query .= "type_user=1 "; $result = @pmb_mysql_query($query); return 1; } // --------------------------------------------------------------- // delete_audit ($type=0, $obj=0) : // --------------------------------------------------------------- public static function delete_audit ($type=0, $obj=0) { $type += 0; $obj += 0; $query = "DELETE FROM audit WHERE "; $query .= "type_obj='$type' AND "; $query .= "object_id in ($obj) "; $result = @pmb_mysql_query($query); return 1; } // --------------------------------------------------------------- // get_all_from_user_id () : récupération toutes informations d'un utilisateur // --------------------------------------------------------------- static public function get_all_from_user_id(int $user_id, int $type_user = 1) { global $pmb_type_audit, $msg; $all_audit = array(); if (!$pmb_type_audit || empty($user_id)) return $all_audit; $query = "SELECT object_id, type_obj, user_id, quand, date_format(quand, '".$msg["format_date_heure"]."') as aff_quand, concat(prenom, ' ', nom) as prenom_nom, info "; $query .= "FROM audit LEFT JOIN users ON user_id = userid "; $query .= "WHERE user_id='$user_id' AND type_user=$type_user "; $query .= "ORDER BY quand DESC"; $result = pmb_mysql_query($query); if (!empty($result)) { if(pmb_mysql_num_rows($result)){ while ($audit = pmb_mysql_fetch_object($result)) { $all_audit[$audit->object_id] = $audit ; } } } return $all_audit; } // --------------------------------------------------------------- // get_last_edit_from_object_id () : retourne la dernière modification d'un object // --------------------------------------------------------------- static public function get_last_edit_from_object_id(int $object_id) { global $pmb_type_audit; if (!$pmb_type_audit || empty($object_id)) return ""; $result = pmb_mysql_query("SELECT quand FROM audit WHERE object_id='$object_id' ORDER BY quand DESC LIMIT 1"); if (!empty($result)) { if(pmb_mysql_num_rows($result)){ $audit = pmb_mysql_fetch_object($result); return $audit->quand; } } return ""; } } // fin if !define } // class audit