$id = 0; if (!empty($_POST['id'])) { $id = intval($_POST['id']); } if ($submitAnnouncement && empty($emailTitle)) { $error_message = get_lang('TitleIsRequired'); $content_to_modify = $newContent; } else { if ($submitAnnouncement) { $sendToUsersInSession = isset($_POST['send_to_users_in_session']) ? true : false; if (isset($id) && $id) { // there is an Id => the announcement already exists => update mode if ($ctok == $_POST['sec_token']) { $file_comment = $_POST['file_comment']; $file = $_FILES['user_upload']; AnnouncementManager::edit_announcement($id, $emailTitle, $newContent, $_POST['selectedform'], $file, $file_comment, $sendToUsersInSession); /* MAIL FUNCTION */ if ($_POST['email_ann'] && empty($_POST['onlyThoseMails'])) { AnnouncementManager::send_email($id, $sendToUsersInSession); } $message = get_lang('AnnouncementModified'); } } else { //insert mode if ($ctok == $_POST['sec_token']) { $file = $_FILES['user_upload']; $file_comment = $_POST['file_comment']; if (!empty($group_id)) { $insert_id = AnnouncementManager::add_group_announcement($safe_emailTitle, $safe_newContent, array('GROUP:' . $group_id), $_POST['selectedform'], $file, $file_comment, $sendToUsersInSession); } else { $insert_id = AnnouncementManager::add_announcement($safe_emailTitle, $safe_newContent, $_POST['selectedform'], $file, $file_comment, $sendToUsersInSession);
$form->addElement('hidden', 'sec_token', $stok); if (empty($sessionId)) { $form->addCheckBox('send_to_users_in_session', null, get_lang('SendToUsersInSessions')); } $form->addCheckBox('send_to_hrm_users', null, get_lang('SendAnnouncementCopyToDRH')); $form->addButtonSave(get_lang('ButtonPublishAnnouncement')); $form->setDefaults($defaults); if ($form->validate()) { $data = $form->getSubmitValues(); $sendToUsersInSession = isset($data['send_to_users_in_session']) ? true : false; if (isset($id) && $id) { // there is an Id => the announcement already exists => update mode if (true) { $file_comment = $_POST['file_comment']; $file = $_FILES['user_upload']; AnnouncementManager::edit_announcement($id, $data['title'], $data['content'], $data['users'], $file, $file_comment, $sendToUsersInSession); /* MAIL FUNCTION */ if (isset($_POST['email_ann']) && empty($_POST['onlyThoseMails'])) { AnnouncementManager::send_email($id, $sendToUsersInSession, isset($data['send_to_hrm_users'])); } Display::addFlash(Display::return_message(get_lang('AnnouncementModified'), 'success')); header('Location: ' . $homeUrl); exit; } } else { // Insert mode if (true) { $file = $_FILES['user_upload']; $file_comment = $data['file_comment']; if (empty($group_id)) { $insert_id = AnnouncementManager::add_announcement($data['title'], $data['content'], $data['users'], $file, $file_comment, null, $sendToUsersInSession);
} /* Submit announcement */ $submitAnnouncement = isset($_POST['submitAnnouncement']) ? $_POST['submitAnnouncement'] : 0; $id = 0; if (!empty($_POST['id'])) { $id = intval($_POST['id']); } if ($submitAnnouncement) { $selected_form = isset($_POST['users']) ? $_POST['users'] : null; $sendEmail = isset($_POST['email_ann']) ? $_POST['email_ann'] : null; if (isset($id) && $id) { // there is an Id => the announcement already exists => update mode if ($ctok == $_POST['sec_token']) { $file_comment = $_POST['file_comment']; $file = $_FILES['user_upload']; AnnouncementManager::edit_announcement($id, $_POST['emailTitle'], $_POST['newContent'], $selected_form, $file, $file_comment, $sendEmail); $message = get_lang('AnnouncementModified'); } } else { // Insert mode //if (1) { if ($ctok == $_REQUEST['sec_token']) { $file = $_FILES['user_upload']; $file_comment = $_POST['file_comment']; if (!empty($group_id)) { $insert_id = AnnouncementManager::add_group_announcement($_POST['emailTitle'], $_POST['newContent'], array('GROUP:' . $group_id), $selected_form, $file, $file_comment, $sendEmail); } else { $insert_id = AnnouncementManager::add_announcement($_POST['emailTitle'], $_POST['newContent'], $selected_form, $file, $file_comment, $sendEmail); } $message = get_lang('AnnouncementAdded'); }