if (!$CGDb->insert('tags', array('name' => $TagName, 'type' => 'ep'))) { Response::dbError('Episode tag creation failed'); } } } } else { if ($SeasonChanged || $EpisodeChanged) { $TagName = CGUtils::checkEpisodeTagName("s{$insert['season']}e{$insert['episode']}"); $EpTag = $CGDb->where('name', $editing ? "s{$Episode->season}e{$Episode->episode}" : $TagName)->getOne('tags', 'tid'); if (!empty($EpTag)) { if ($editing) { $CGDb->where('tid', $EpTag['tid'])->update('tags', array('name' => $TagName)); } } else { if (!$CGDb->insert('tags', array('name' => $TagName, 'type' => 'ep'))) { Response::dbError('Episode tag creation failed'); } } } } } if ($editing) { $logentry = array('target' => $Episode->formatTitle(AS_ARRAY, 'id')); $changes = 0; if (!empty($Episode->airs)) { $Episode->airs = date('c', strtotime($Episode->airs)); } foreach (array('season', 'episode', 'twoparter', 'title', 'airs') as $k) { if (isset($insert[$k]) && $insert[$k] != $Episode->{$k}) { $logentry["old{$k}"] = $Episode->{$k}; $logentry["new{$k}"] = $insert[$k];
} $insert = array('preview' => $Image->preview, 'fullsize' => $Image->fullsize); $season = Episodes::validateSeason(Episodes::ALLOW_MOVIES); $episode = Episodes::validateEpisode(); $epdata = Episodes::getActual($season, $episode, Episodes::ALLOW_MOVIES); if (empty($epdata)) { Response::fail("The specified episode (S{$season}E{$episode}) does not exist"); } $insert['season'] = $epdata->season; $insert['episode'] = $epdata->episode; $ByID = $currentUser->id; if (Permission::sufficient('developer')) { $username = Posts::validatePostAs(); if (isset($username)) { $PostAs = Users::get($username, 'name', 'id,role'); if (empty($PostAs)) { Response::fail('The user you wanted to post as does not exist'); } if ($type === 'reservation' && !Permission::sufficient('member', $PostAs->role) && !isset($_POST['allow_nonmember'])) { Response::fail('The user you wanted to post as is not a club member, do you want to post as them anyway?', array('canforce' => true)); } $ByID = $PostAs->id; } } $insert[$type === 'reservation' ? 'reserved_by' : 'requested_by'] = $ByID; Posts::checkPostDetails($type, $insert); $PostID = $Database->insert("{$type}s", $insert, 'id'); if (!$PostID) { Response::dbError(); } Response::done(array('id' => $PostID));
/** * Approves a specific post and optionally notifies it's author * * @param string $type request/reservation * @param int $id post id * @param string $notifyUserID id of user to notify * * @return array */ static function approve($type, $id, $notifyUserID = null) { global $Database; if (!$Database->where('id', $id)->update("{$type}s", array('lock' => true))) { Response::dbError(); } $postdata = array('type' => $type, 'id' => $id); Logs::action('post_lock', $postdata); if (!empty($notifyUserID)) { Notifications::send($notifyUserID, 'post-approved', $postdata); } return $postdata; }