// Check first if we need to handle the servers at all, or if we should just delete all servers from the SG (depending on the checkbox in the "MISP instances" tab).
// If we have not found the server previously, create a new sharing group server object.
// Otherwise, if we have found it check whether the extended field has been altered, if not just continue without saving
if(!$found){
$this->create();
$isChange=false;
}else{
if($found['all_orgs']==$SgS['all_orgs']){
continue;
}
$isChange=true;
$SgS['id']=$found['id'];
}
$this->save($SgS);
if($this->save($SgS)){
$log->create();
if($isChange){
$log->createLogEntry($user,'edit','SharingGroupServer',$this->id,'Sharing group ('.$id.'): Modified access rights for users on '.$server_name.'.',($server['all_orgs']?'All organisations on server '.$server['id'].' are now part of the sharing group.':'Organisations on '.$server_name.' are now not part of the sharing group unless they are present in the list of organisations.'));
}else{
$log->createLogEntry($user,'add','SharingGroupServer',$this->id,'Sharing group ('.$id.'): Added server ('.$server['id'].').',ucfirst($server_name).' added to Sharing group.'.($server['all_orgs']?' Sharing group visible to all organisations on the server.':''));
}
}
}
// We are left with some "old orgs" that are not in the new list. This means that they can be safely deleted.
$log->createLogEntry($user,'delete','SharingGroupServer',$old_server['id'],'Sharing group ('.$id.'): Removed server('.$old_server['server_id'].').','Server ('.$old_server['server_id'].') removed from Sharing group.');