$database->execute("UPDATE images SET parent_id = NULL WHERE parent_id = :iid",array("iid"=>$event->image->id));
}
if($event->image->parent_id!==NULL){
$database->execute("UPDATE images SET has_children = (SELECT * FROM (SELECT CASE WHEN (COUNT(*) - 1) > 0 THEN 1 ELSE 0 END FROM images WHERE parent_id = :pid) AS sub)
if($database->get_row("SELECT 1 FROM images WHERE id = :cid",array("cid"=>$childID))){
$database->execute("UPDATE images SET parent_id = :pid WHERE id = :cid",array("cid"=>$childID,"pid"=>$parentID));
$database->execute("UPDATE images SET has_children = TRUE WHERE id = :pid",array("pid"=>$parentID));
}
}
privatefunctionremove_parent(/*int*/$imageID){
global$database;
$parentID=$database->get_one("SELECT parent_id FROM images WHERE id = :iid",array("iid"=>$imageID));
if($parentID){
$database->execute("UPDATE images SET parent_id = NULL WHERE id = :iid",array("iid"=>$imageID));
$database->execute("UPDATE images SET has_children = (SELECT * FROM (SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END FROM images WHERE parent_id = :pid) AS sub)