type_obj = $type ;
$this->object_id = $obj ;
$this->all_audit=array() ;
}
// ---------------------------------------------------------------
// get_all () : récupération toutes informations
// ---------------------------------------------------------------
function get_all() {
global $dbh, $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 = @mysql_query($query, $dbh);
if(!$result) die("can't select from table audit left join users :
$query ");
while ($audit=mysql_fetch_object($result)) {
$this->all_audit[] = $audit ;
}
}
// ---------------------------------------------------------------
// get_creation () : récupération création
// ---------------------------------------------------------------
function get_creation () {
global $dbh, $pmb_type_audit ;
if (!$pmb_type_audit) return 0;
return $this->all_audit[0];
}
// ---------------------------------------------------------------
// get_last () : récupération dernière modification
// ---------------------------------------------------------------
function get_last () {
global $dbh, $pmb_type_audit ;
if (!$pmb_type_audit) return 0;
return $this->all_audit[(count($this->all_audit)-1)];
}
// ---------------------------------------------------------------
// insert_creation ($type=0, $obj=0) :
// ---------------------------------------------------------------
function insert_creation ($type=0, $obj=0) {
global $dbh, $PMBuserid, $PMBusername, $pmb_type_audit ;
if (!$pmb_type_audit) return 0;
$query = "INSERT INTO audit SET ";
$query .= "type_obj='$type', ";
$query .= "object_id='$obj', ";
$query .= "user_id='$PMBuserid', ";
$query .= "user_name='$PMBusername', ";
$query .= "type_modif=1 ";
$result = @mysql_query($query, $dbh);
if(!$result) die("can't INSERT into table audit :
$query ");
return 1;
}
// ---------------------------------------------------------------
// insert_modif ($type=0, $obj=0) :
// ---------------------------------------------------------------
function insert_modif ($type=0, $obj=0) {
global $dbh, $PMBuserid, $PMBusername, $pmb_type_audit ;
if (!$pmb_type_audit) return 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 = @mysql_query($query, $dbh);
if(!$result) die("can't DELETE FROM table audit :
$query ");
}
$query = "INSERT INTO audit SET ";
$query .= "type_obj='$type', ";
$query .= "object_id='$obj', ";
$query .= "user_id='$PMBuserid', ";
$query .= "user_name='$PMBusername', ";
$query .= "type_modif=2 ";
$result = @mysql_query($query, $dbh);
return 1;
}
// ---------------------------------------------------------------
// delete_audit ($type=0, $obj=0) :
// ---------------------------------------------------------------
function delete_audit ($type=0, $obj=0) {
global $dbh ;
$query = "DELETE FROM audit WHERE ";
$query .= "type_obj='$type' AND ";
$query .= "object_id in ($obj) ";
$result = @mysql_query($query, $dbh);
return 1;
}
} // fin if !define
} // class audit