} $TopicID = $_POST['thread']; $ThreadInfo = Forums::get_thread_info($TopicID); if ($ThreadInfo === null) { error(404); } $ForumID = $ThreadInfo['ForumID']; $SQLTime = sqltime(); if (!Forums::check_forumperm($ForumID)) { error(403); } if (!Forums::check_forumperm($ForumID, 'Write') || $LoggedUser['DisablePosting'] || $ThreadInfo['IsLocked'] == '1' && !check_perms('site_moderate_forums')) { error(403); } if (isset($_POST['subscribe']) && Subscriptions::has_subscribed($TopicID) === false) { Subscriptions::subscribe($TopicID); } //Now lets handle the special case of merging posts, we can skip bumping the thread and all that fun if ($ThreadInfo['LastPostAuthorID'] == $LoggedUser['ID'] && (!check_perms('site_forums_double_post') && !in_array($ForumID, $ForumsDoublePost) || isset($_POST['merge']))) { //Get the id for this post in the database to append $DB->query("\n\t\tSELECT ID, Body\n\t\tFROM forums_posts\n\t\tWHERE TopicID = '{$TopicID}'\n\t\t\tAND AuthorID = '" . $LoggedUser['ID'] . "'\n\t\tORDER BY ID DESC\n\t\tLIMIT 1"); list($PostID, $OldBody) = $DB->next_record(MYSQLI_NUM, false); //Edit the post $DB->query("\n\t\tUPDATE forums_posts\n\t\tSET\n\t\t\tBody = CONCAT(Body,'\n\n" . db_string($Body) . "'),\n\t\t\tEditedUserID = '" . $LoggedUser['ID'] . "',\n\t\t\tEditedTime = '{$SQLTime}'\n\t\tWHERE ID = '{$PostID}'"); //Store edit history $DB->query("\n\t\tINSERT INTO comments_edits\n\t\t\t(Page, PostID, EditUser, EditTime, Body)\n\t\tVALUES\n\t\t\t('forums', {$PostID}, " . $LoggedUser['ID'] . ", '{$SQLTime}', '" . db_string($OldBody) . "')"); $Cache->delete_value("forums_edits_{$PostID}"); //Get the catalogue it is in $CatalogueID = floor((POSTS_PER_PAGE * ceil($ThreadInfo['Posts'] / POSTS_PER_PAGE) - POSTS_PER_PAGE) / THREAD_CATALOGUE); //Get the catalogue value for the post we're appending to if ($ThreadInfo['Posts'] % THREAD_CATALOGUE == 0) {
/** * Upload new file version * * @param void * @return null */ function new_version() { if ($this->active_file->isNew()) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if if (!$this->active_file->canEdit($this->logged_user)) { $this->httpError(HTTP_ERR_FORBIDDEN); } // if if ($this->request->isSubmitted()) { $attached = attach_from_files($this->active_file, $this->logged_user); if ($attached && !is_error($attached)) { $this->active_file->setRevision($this->active_file->getRevision() + 1); $save = $this->active_file->save(); if ($save && !is_error($save)) { $last_revision = $this->active_file->getLastRevision(); if (instance_of($last_revision, 'Attachment')) { $last_revision->setCreatedBy($this->logged_user); $last_revision->setAttachmentType(ATTACHMENT_TYPE_FILE_REVISION); $last_revision->save(); event_trigger('on_new_revision', array(&$this->active_file, &$last_revision, &$this->logged_user)); $activity_log = new NewFileVersionActivityLog(); $activity_log->log($this->active_file, $this->logged_user, $last_revision->getId()); } // if Subscriptions::subscribe($this->logged_user, $this->active_file); db_commit(); flash_success('File ":name" has been updated', array('name' => $this->active_file->getName())); $this->redirectToUrl($this->active_file->getViewUrl()); } else { db_rollback(); $this->smarty->assign('errors', $save); } // if } else { if (is_error($attached)) { $errors = new ValidationErrors(array('file' => $attached->getMessage())); } else { $errors = new ValidationErrors(array('file' => lang('File not uploaded'))); } // if $this->smarty->assign('errors', $errors); } // if } // if }
/** * Clone subscriptions from $from to $to object * * @param ProjectObject $from * @param ProjectObject $to * @return boolean */ function cloneSubscriptions($from, $to) { $project = $to->getProject(); // we need it to check if user has access to a given project $rows = db_execute_all('SELECT * FROM ' . TABLE_PREFIX . 'subscriptions WHERE parent_id = ?', $from->getId()); if (is_foreachable($rows)) { foreach ($rows as $row) { $user = Users::findById($row['user_id']); if (instance_of($user, 'User') && $user->isProjectMember($project)) { Subscriptions::subscribe($user, $to); } // if } // if } // if return true; }
/** * Subscribe $user to this object * * @param User $user * @return boolean */ function subscribe($user) { return Subscriptions::subscribe($user, $this); }
/** * Hnalde on_project_object_copied event * * @param ProjectObject $original * @param ProjectObject $copy * @param Project $destination * @param mixed $cascade * @return null */ function resources_handle_on_project_object_copied(&$original, &$copy, &$destination, $cascade) { if ($original->can_have_subscribers) { $subscribers = $original->getSubscribers(); if (is_foreachable($subscribers)) { foreach ($subscribers as $subscriber) { if ($subscriber->isProjectMember($destination)) { Subscriptions::subscribe($subscriber, $copy); } // if } // foreach } // if } // if if ($original->can_have_assignees) { Assignments::cloneAssignments($original, $copy); } // if if ($original->can_have_attachments) { Attachments::cloneAttachments($original, $copy); } // if // Copy child objects if ($cascade === true || is_foreachable($cascade)) { if ($cascade === true) { $rows = db_execute_all('SELECT * FROM ' . TABLE_PREFIX . 'project_objects WHERE parent_id = ?', $original->getId()); } else { $rows = db_execute_all('SELECT * FROM ' . TABLE_PREFIX . 'project_objects WHERE parent_id = ? AND type IN (?)', $original->getId(), $cascade); } // if if (is_foreachable($rows)) { // We'll remember original and copy tasks ID-s here so we can move // assignments later on, when we have both instances $tasks = array(); foreach ($rows as $row) { $subobject_original_id = $row['id']; $subobject_original_type = strtolower($row['type']); unset($row['id']); $row['project_id'] = $destination->getId(); $row['parent_id'] = $copy->getId(); $row['milestone_id'] = 0; // Copy file if ($subobject_original_type == 'attachment') { $path = UPLOAD_PATH . '/' . $row['varchar_field_1']; if (is_file($path)) { $destination_file = get_available_uploads_filename(); if (copy($path, $destination_file)) { $row['varchar_field_1'] = basename($destination_file); } // if } // if } // if // Escape values foreach ($row as $k => $v) { $row[$k] = db_escape($v); } // foreach db_execute('INSERT INTO ' . TABLE_PREFIX . 'project_objects (' . implode(', ', array_keys($row)) . ') VALUES (' . implode(', ', $row) . ')'); if ($subobject_original_type == 'task') { $tasks[$subobject_original_id] = db_last_insert_id(); } // if } // foraech if (instance_of($copy, 'Discussion')) { $last_comment = $copy->getLastComment(); $last_comment_datetime = instance_of($last_comment, 'Comment') ? $last_comment->getCreatedOn() : null; $copy->setLastCommentOn($last_comment_datetime); $copy->save(); } // if // Lets move task assinments if we have any tasks if (is_foreachable($tasks)) { foreach ($tasks as $task_original_id => $task_copy_id) { $task_original = Tasks::findById($task_original_id); $task_copy = Tasks::findById($task_copy_id); if (instance_of($task_original, 'Task') && instance_of($task_copy, 'Task')) { Assignments::cloneAssignments($task_original, $task_copy); Subscriptions::cloneSubscriptions($task_original, $task_copy); } // if } // foreach } // if } // if } // if }
<?php // perform the back end of subscribing to topics authorize(); if (!empty($LoggedUser['DisableForums'])) { error(403); } if (!is_number($_GET['topicid'])) { error(0); } $TopicID = (int) $_GET['topicid']; $DB->query("\n\tSELECT f.ID\n\tFROM forums_topics AS t\n\t\tJOIN forums AS f ON f.ID = t.ForumID\n\tWHERE t.ID = {$TopicID}"); list($ForumID) = $DB->next_record(); if (!Forums::check_forumperm($ForumID)) { die; } Subscriptions::subscribe($_GET['topicid']);