diff --git a/main/announcements/announcements.inc.php b/main/announcements/announcements.inc.php index 3a07713626..685a6f2e58 100755 --- a/main/announcements/announcements.inc.php +++ b/main/announcements/announcements.inc.php @@ -941,31 +941,20 @@ function sent_to($tool, $id) { * @param int ID of the element of the corresponding type * @return bool False on failure, True on success */ -function change_visibility_announcement($tool, $id) { - global $_course; - $tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY); - $tool = Database::escape_string($tool); - $id = Database::escape_string($id); - - $sql = "SELECT visibility FROM $tbl_item_property WHERE tool='$tool' AND ref='$id'"; - - $result = Database::query($sql); - $row = Database::fetch_array($result, 'ASSOC'); - //Adding the AnnouncementUpdated when modifying the visibility - api_item_property_update($_course, TOOL_ANNOUNCEMENT, $id, "AnnouncementUpdated", api_get_user_id()); - - if ($row['visibility']=='1') { - $sql_visibility="UPDATE $tbl_item_property SET visibility='0' WHERE tool='$tool' AND ref='$id'"; +function change_visibility_announcement($id) { + global $_course; + $item_visibility = api_get_item_visibility($_course, TOOL_ANNOUNCEMENT, $id); + if ($item_visibility == '1') { + api_item_property_update($_course, TOOL_ANNOUNCEMENT, $id, 'invisible', api_get_user_id()); } else { - $sql_visibility="UPDATE $tbl_item_property SET visibility='1' WHERE tool='$tool' AND ref='$id'"; - } - $result = Database::query($sql_visibility); - if ($result === false) { - return false; - } + api_item_property_update($_course, TOOL_ANNOUNCEMENT, $id, 'visible', api_get_user_id()); + } return true; } +function delete_announcement($_course, $id) { + api_item_property_update($_course, TOOL_ANNOUNCEMENT, $id, 'delete', api_get_user_id()); +} /* ATTACHMENT FUNCTIONS diff --git a/main/announcements/announcements.php b/main/announcements/announcements.php index dcacce57c7..f4338c16d1 100755 --- a/main/announcements/announcements.php +++ b/main/announcements/announcements.php @@ -64,8 +64,9 @@ $tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY); /* Resource linker */ + $_SESSION['source_type']="Ad_Valvas"; -include '../resourcelinker/resourcelinker.inc.php'; +require_once '../resourcelinker/resourcelinker.inc.php'; if (!empty($_POST['addresources'])) { // When the "Add Resource" button is clicked we store all the form data into a session @@ -73,19 +74,17 @@ if (!empty($_POST['addresources'])) { $form_elements= array ('emailTitle'=>Security::remove_XSS($emailTitle), 'newContent'=>Security::remove_XSS($newContent), 'id'=>$id, 'to'=>$selectedform, 'emailoption'=>$email_ann); $_SESSION['formelements']=$form_elements; - if($id) // this is to correctly handle edits - { - $action="edit"; - }else - { - $action="add"; + if($id) { + // this is to correctly handle edits + $action="edit"; + } else { + $action="add"; } // ============== // // 7 = Ad_Valvas // // ============== // - if($surveyid) - { + if($surveyid) { header("Location: ../resourcelinker/resourcelinker.php?source_id=7&action=$action&id=$id&originalresource=no&publish_survey=$surveyid&db_name=$db_name&cidReq=$cidReq"); exit; } else { @@ -95,15 +94,12 @@ if (!empty($_POST['addresources'])) { exit; } -/* - Tracking -*/ +/* Tracking */ event_access_tool(TOOL_ANNOUNCEMENT); -/* - Libraries -*/ +/* Libraries */ + $lib = api_get_path(LIBRARY_PATH); //avoid useless function calls require_once $lib.'groupmanager.lib.php'; require_once $lib.'mail.lib.inc.php'; @@ -112,21 +108,18 @@ require_once $lib.'tracking.lib.php'; require_once $lib.'fckeditor/fckeditor.php'; require_once $lib.'fileUpload.lib.php'; require_once 'announcements.inc.php'; -/* - POST TO -*/ +/* POST TO */ $safe_emailTitle = $_POST['emailTitle']; $safe_newContent = $_POST['newContent']; -if (!empty($_POST['To'])) -{ +if (!empty($_POST['To'])) { if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) { api_not_allowed(); } $display_form = true; - $form_elements = array ('emailTitle'=>$safe_emailTitle, 'newContent'=>$safe_newContent, 'id'=>Security::remove_XSS($_POST['id']), 'emailoption'=>Security::remove_XSS($_POST['email_ann'])); + $form_elements = array ('emailTitle'=>$safe_emailTitle, 'newContent'=>$safe_newContent, 'id'=>$_POST['id'], 'emailoption'=>$_POST['email_ann']); $_SESSION['formelements'] = $form_elements; $form_elements = $_SESSION['formelements']; @@ -140,17 +133,14 @@ if (!empty($_POST['To'])) */ $setting_select_groupusers = true; -if (empty($_POST['To']) and !$_SESSION['select_groupusers']) -{ +if (empty($_POST['To']) and !$_SESSION['select_groupusers']) { $_SESSION['select_groupusers'] = "hide"; } $select_groupusers_status=$_SESSION['select_groupusers']; -if (!empty($_POST['To']) and ($select_groupusers_status=="hide")) -{ +if (!empty($_POST['To']) and ($select_groupusers_status=="hide")) { $_SESSION['select_groupusers'] = "show"; } -if (!empty($_POST['To']) and ($select_groupusers_status=="show")) -{ +if (!empty($_POST['To']) and ($select_groupusers_status=="show")) { $_SESSION['select_groupusers'] = "hide"; } @@ -198,7 +188,7 @@ if(!empty($_GET['toolgroup'])){ if($_GET['toolgroup'] == strval(intval($_GET['toolgroup']))){ //check is integer $toolgroup = $_GET['toolgroup']; $_SESSION['select_groupusers'] = 'hide'; - }else{ + } else { $toolgroup = 0; } api_session_register("toolgroup"); @@ -212,15 +202,13 @@ if(!empty($_GET['toolgroup'])){ $ctok = $_SESSION['sec_token']; $stok = Security::get_token(); -if (!empty($_SESSION['formelements']) and !empty($_GET['originalresource']) and $_GET['originalresource'] == 'no') -{ +if (!empty($_SESSION['formelements']) and !empty($_GET['originalresource']) and $_GET['originalresource'] == 'no') { $form_elements = $_SESSION['formelements']; $title_to_modify = $form_elements['emailTitle']; $content_to_modify = $form_elements['newContent']; $announcement_to_modify = $form_elements['id']; $to = $form_elements['to']; //load_edit_users('announcement',$announcement_to_modify); - $email_ann = $form_elements['emailoption']; } if(!empty($_GET['remind_inactive'])) { @@ -235,7 +223,7 @@ if(!empty($_REQUEST['publish_survey'])) { } //@todo fix those request values -$cidReq=Database::escape_string($_REQUEST['cidReq']); +$cidReq = Database::escape_string($_REQUEST['cidReq']); if($surveyid) { $db_name=Database::escape_string($_REQUEST['db_name']); $sql_temp = "SELECT * FROM $db_name.survey WHERE survey_id='$surveyid'"; @@ -267,10 +255,9 @@ if (!empty($_SESSION['toolgroup'])){ // showing the header if we are not in the learning path, if we are in // the learning path, we do not include the banner so we have to explicitly // include the stylesheet, which is normally done in the header -if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath') -{ +if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath') { //we are not in the learning path - Display::Display_header($nameTools,"Announcements"); + Display::display_header($nameTools,get_lang('Announcements')); } else { //we are in the learning path, only display central data and change css $display_title_list = false; @@ -278,8 +265,6 @@ if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath') $display_specific_announcement = true; $announcement_id = $_REQUEST['ann_id']; ?> - - 0) { if ((api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) { @@ -1452,7 +1431,9 @@ if ($display_announcement_list && !$surveyid) { } // end: if ($displayAnnoucementList) echo ""; -if (!empty($display_specific_announcement)) display_announcement($announcement_id); +if (!empty($display_specific_announcement)) { + display_announcement($announcement_id); +} /* FOOTER */ if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath') {