getSubtype() == "news" && $news->canEdit()) { // Cache to the session $_SESSION['newstitle'] = $title; $_SESSION['newsbody'] = $body; $_SESSION['newsshortdescription'] = $short_description; $_SESSION['newstags'] = $tags; $_SESSION['newssubjects'] = $subjects; $_SESSION['newstargetgroup'] = $targetgroup; $_SESSION['newscategories'] = $categories; $_SESSION['newsdeadline'] = $deadline; $_SESSION['newspublishingend'] = $publishing_end; $_SESSION['newsbegin'] = $begin; $_SESSION['newsend'] = $end; // Convert string of tags into a preformatted array $tagarray = string_to_tag_array($tags); // Make sure the title / description aren't blank if (empty($title) || empty($body) || empty($short_description)) { /*translation:Please fill all required fields.*/ register_error(elgg_echo("koolielu:error_blank")); forward("mod/info/edit_news.php?news=" . $guid); // Otherwise, save the news } else { // Get owning user $owner = get_entity($news->getOwner()); // For now, set its access to public (we'll add an access dropdown shortly) //$news->access_id = $access; // Set its title and description appropriately $news->title = $title; $news->description = $body; // Before we can set metadata, we need to save the news if (!$news->save()) { /*translation:Error occured, object could not be saved.*/ register_error(elgg_echo("koolielu:error_not_saved")); forward("mod/info/edit_news.php?news=" . $guid); } // Now let's add tags. We can pass an array directly to the object property! Easy. $news->clearMetadata('tags'); if (is_array($tagarray)) { $news->tags = $tagarray; } unassociate_prioval($prioval); $news->prioval = $prioval; // Custom metadata $news->clearMetadata('categories'); $news->categories = $categories; $news->clearMetadata('subjects'); $news->subjects = $subjects; $news->clearMetadata('targetgroup'); $news->targetgroup = $targetgroup; $news->clearMetadata('deadline'); if (!empty($deadline)) $deadline = dateIntoTimestamp($deadline); $news->deadline = $deadline; $news->clearMetadata('publishing_end'); if (!empty($publishing_end)) { $publishing_end = dateIntoTimestamp($publishing_end); // if publishing ending date is bigger than current time, then it should not be archived anymore if ($publishing_end > time()) $news->archived = 0; } $news->publishing_end = $publishing_end; $news->clearMetadata('begin'); if (!empty($begin)) $begin = dateIntoTimestamp($begin); $news->begin = $begin; $news->clearMetadata('end'); if (!empty($end)) $end = dateIntoTimestamp($end); $news->end = $end; $news->clearMetadata('shortdescription'); $news->shortdescription = $short_description; // Send data to base delete_data("DELETE from {$CONFIG->dbprefix}koolielu_calendar_objects where guid=".$news->getGUID()); $sql = "INSERT INTO {$CONFIG->dbprefix}koolielu_calendar_objects (guid, type, title, description, approved, time2_begin, time2_end, time1_begin, time1_end) VALUES (".$news->getGUID().",'news','".mysql_real_escape_string($news->title)."','".mysql_real_escape_string($news->shortdescription)."',".(int)$news->approved.",'".$news->deadline."','".$news->publishing_end."','".$news->begin."','".$news->end."')"; insert_data($sql); foreach ($subjects as $s) { $sql = "INSERT INTO {$CONFIG->dbprefix}koolielu_calendar_subject_refs (cal_object_id, subject_id) VALUES (".$news->getGUID().", ".$s.")"; insert_data($sql); } // Deal with image if ((isset($_FILES['newsimage'])) && (substr_count($_FILES['newsimage']['type'],'image/'))) { $supported_formats = getSupportedImageFormats(); $image = get_uploaded_file('newsimage'); // See if we even support the format first if (in_array(exif_imagetype($_FILES['newsimage']['tmp_name']),$supported_formats)) { // Delete old files and then save new ones deleteKeObjectImages($news->getGUID(), $news->getOwner()); $original = saveImageFile($news->guid . ".original", $image, $news->getOwner()); // Write original file name into objects metadata $news->clearMetadata('original_file_name'); $news->original_file_name = $_FILES['newsimage']['name']; if (!$original) { /*translation:Original image could not be saved.*/ register_error(elgg_echo('koolielu:error_original_image_not_saved')); } $resized_image = get_resized_image_from_uploaded_file('newsimage', 150, 150, false); $resized = saveImageFile("small_" . $news->guid . ".jpg", $resized_image, $news->getOwner()); if (!$resized) { /*translation:Resized image could not be saved.*/ register_error(elgg_echo('koolielu:error_resized_image_not_saved')); } $resized_listing_image = get_resized_image_from_uploaded_file('newsimage', 40, 40, false); $resized_listing = saveImageFile("listing_" . $news->getGUID() . ".jpg", $resized_listing_image, $news->getOwner()); if (!$resized_listing) { /*translation:Resized image could not be saved.*/ register_error(elgg_echo('koolielu:error_resized_image_not_saved')); } } else { /*translation:Image format not supported. Supported formats are: .jpg, .png, .jpeg and .gif.*/ register_error(elgg_echo('koolielu:error_supported_image_formats')); } } // Success message /*translation:News modified.*/ system_message(elgg_echo("koolielu:message_news_modified")); // Remove the news cache unset($_SESSION['newstitle']); unset($_SESSION['newsbody']); unset($_SESSION['newsshortdescription']); unset($_SESSION['newstags']); unset($_SESSION['newscategories']); unset($_SESSION['newssubjects']); unset($_SESSION['newstargetgroup']); unset($_SESSION['newsdeadline']); unset($_SESSION['newspublishingend']); unset($_SESSION['newsbegin']); unset($_SESSION['newsend']); // Forward to the main page forward($news->getURL()); } } ?>