$ending) { /*translation:Beginning date should be smaller than ending date.*/ register_error(elgg_echo('koolielu:error_beginning_larger_than_end')); $errors = true; } } if ($errors) { forward("mod/poster/add_course.php"); // Otherwise, create course announcement } else { $poster = new ElggObject(); $poster->subtype = "course"; $poster->owner_guid = $_SESSION['user']->getGUID(); // If admin, editor or moderator set its access to public and status to approved if (isModerator()) { $poster->access_id = 2; $poster->approved = 1; } else { $poster->access_id = 1; $poster->approved = 0; } // Set its title and description appropriately $poster->title = $title; $poster->brief_description = $brief_desc; $poster->subjects = $subjects; $poster->targetgroup = $targetgroup; $poster->description = $description; $poster->additional_info = $additional_info; $poster->place = $place; $poster->capacity = $capacity; $poster->cost = $cost; // Make date to timestamp conversions if (!empty($beginning_date)) $beginning_date = dateIntoTimestamp($beginning_date); $poster->beginning_date = $beginning_date; if (!empty($ending_date)) $ending_date = dateIntoTimestamp($ending_date); $poster->ending_date = $ending_date; $poster->contact_person = $contact_person; $poster->telephone = $telephone; $poster->email = $email; $poster->gmaplocation = $gmaplocation; // Before we can set metadata, we need to save the object if (!$poster->save()) { /*translation:Wasn't able to create course. Please try again.*/ register_error(elgg_echo("koolielu:course_creation_failure")); forward("mod/poster/add_course.php"); } // Send data to base $sql = "INSERT INTO {$CONFIG->dbprefix}koolielu_calendar_objects (guid, type, title, description, approved, time1_begin, time1_end) VALUES (".$poster->getGUID().",'".$poster->subtype."','".mysql_real_escape_string($poster->title)."','".mysql_real_escape_string($poster->brief_description)."',".(int)$poster->approved.",'".$poster->beginning_date."','".$poster->ending_date."')"; insert_data($sql); foreach ($subjects as $s) { $sql = "INSERT INTO {$CONFIG->dbprefix}koolielu_calendar_subject_refs (cal_object_id, subject_id) VALUES (".$poster->getGUID().", ".$s.")"; insert_data($sql); } $poster->frontpage = "0"; $poster->archived = 0; // Deal with image if ((isset($_FILES['image'])) && (substr_count($_FILES['image']['type'],'image/'))) { $supported_formats = getSupportedImageFormats(); // See if we even support the format first if (in_array(exif_imagetype($_FILES['image']['tmp_name']), $supported_formats)) { // Write original file name into objects metadata $poster->original_file_name = $_FILES['image']['name']; saveKeObjectImages('image', $poster->getGUID(), $poster->getOwner()); } else { /*translation:Image format not supported. Supported formats are: .jpg, .png, .jpeg and .gif.*/ register_error(elgg_echo('koolielu:error_supported_image_formats')); } } // send internal notification mails to editors (0-not approved, 1-approved) if (!(isModerator())) { $editors = getAllEditors(); if (is_array($editors) && sizeof($editors) > 0) { foreach($editors as $editor) { // Prepare message content /*translation:Course notification*/ $msg_title= elgg_echo('koolielu:Course_notification'); /*translation:New course %s has been added and requires your approval.*/ $msg_desc = sprintf(elgg_echo('koolielu:course_notif_req_app'), $poster->getURL(), $poster->title); $messages = array('title' => $msg_title, 'description' => $msg_desc); // Send message send_system_message($editor->getGUID(), $messages); } } // Success message /*translation:Course added and waiting editor approval before publishing.*/ system_message(elgg_echo('koolielu:course_added_waiting_approval')); } else { /*translation:Course added.*/ system_message(elgg_echo('koolielu:course_added')); // River add_to_river('river/object/course/create','create',$_SESSION['user']->guid,$poster->guid); } // Remove course announcement from cache unset($_SESSION['title']); unset($_SESSION['subjects']); unset($_SESSION['targetgroup']); unset($_SESSION['brief_description']); unset($_SESSION['description']); unset($_SESSION['additional_info']); unset($_SESSION['place']); unset($_SESSION['capacity']); unset($_SESSION['cost']); unset($_SESSION['beginning_date']); unset($_SESSION['ending_date']); unset($_SESSION['contact_person']); unset($_SESSION['telephone']); unset($_SESSION['email']); unset($_SESSION['gmaplocation']); // Forward to course forward("pg/poster/read/" . $poster->getGUID()); } ?>