/** * List all attachments, and manage attachments * * @param void * @return null */ function attachments() { if (!$this->active_object->canEdit($this->logged_user)) { $this->httpError(HTTP_ERR_FORBIDDEN, null, true, $this->request->isApiCall()); } // if $attachemts = $this->active_object->getAttachments(); $this->smarty->assign(array('attachments' => $attachemts)); if ($this->request->isSubmitted()) { $async = (bool) $this->request->get('async'); db_begin_work(); $file = array_shift($_FILES); $this->active_object->attachUploadedFile($file, $this->logged_user); $save = $this->active_object->save(); if ($save && !is_error($save)) { $attachment = Attachments::findLastByObject($this->active_object); if (instance_of($attachment, 'Attachment')) { db_commit(); if ($async) { $this->smarty->assign(array('_attachment' => $attachment, '_object_attachments_cycle_name' => 'object_attachments_cycle_' . $attachment->getId())); // jQuery acts a bit weird here. Insted of providing response as // a string it tries to append it to the BODY so some markup // (tr, td) gets discarded. That is why we need to use temp table // in order to get properly marked-up row die('<table style="display: none">' . $this->smarty->fetch(get_template_path('_object_attachments_row', 'attachments', RESOURCES_MODULE))) . '</table>'; } elseif ($this->request->isApiCall()) { $this->serveData($attachment, 'attachment'); } else { flash_success('File ":file" has been added', array('file' => $file['name'])); $this->redirectToUrl($this->active_object->getAttachmentsUrl()); } // if } // if } // if db_rollback(); if ($async) { $this->httpError(HTTP_ERR_OPERATION_FAILED); } elseif ($this->request->isApiCall()) { $this->httpError(HTTP_ERR_OPERATION_FAILED, null, true, true); } else { flash_error('File ":file" has not been added', array('file' => $file['name'])); $this->redirectToUrl($this->active_object->getAttachmentsUrl()); } // if } else { if ($this->request->isApiCall()) { $this->serveData($attachemts, 'attachments'); } // if } // if }
/** * Save comment into database * * @param void * @return boolean */ function save($is_email_comment = '') { $is_new = $this->isNew(); $save = parent::save(); if ($save && !is_error($save)) { $parent = $this->getParent(); if ($is_new) { //BOF: mod if ($is_email_comment) { //EOF: mod event_trigger('on_comment_added', array(&$this, &$parent)); //BOF: mod } //EOF: mod } else { event_trigger('on_comment_updated', array(&$this, &$parent)); } // if } // if return $save; }
/** * Save into database * * @return boolean */ function save() { if ($this->isNew()) { $this->setTicketId(Tickets::findNextTicketIdByProject($this->getProjectId())); } // if $changes = null; if ($this->isLoaded()) { $log_fields = array('project_id', 'milestone_id', 'parent_id', 'name', 'body', 'priority', 'due_on', 'completed_on'); $changes = new TicketChange(); $changes->setTicketId($this->getId()); $changes->setVersion($this->getVersion()); $changes->setCreatedOn(DateTimeValue::now()); $changes->setCreatedBy(get_logged_user()); if ($this->new_assignees !== false) { list($old_assignees, $old_owner_id) = $this->getAssignmentData(); if (is_array($this->new_assignees) && isset($this->new_assignees[0]) && isset($this->new_assignees[1])) { $new_assignees = $this->new_assignees[0]; $new_owner_id = $this->new_assignees[1]; } else { $new_assignees = array(); $new_owner_id = 0; } // if if ($new_owner_id != $old_owner_id) { $changes->addChange('owner', $old_owner_id, $new_owner_id); } // if sort($new_assignees); sort($old_assignees); if ($new_assignees != $old_assignees) { $changes->addChange('assignees', $old_assignees, $new_assignees); } // if } // if foreach ($this->modified_fields as $field) { if (!in_array($field, $log_fields)) { continue; } // if $old_value = array_var($this->old_values, $field); $new_value = array_var($this->values, $field); if ($old_value != $new_value) { $changes->addChange($field, $old_value, $new_value); } // if } // foreach } // if $save = parent::save(); if ($save && !is_error($save)) { if (instance_of($changes, 'TicketChange') && count($changes->changes)) { $this->changes = false; $changes->save(); } // if } // if return $save; }
/** * Save changed to DB * * @param void * @return boolean */ function save() { $is_new = $this->isNew(); if ($is_new) { $this->setRevisionNum(1); // initial revision number } // if if ($this->isModifiedField('parent_id')) { $parent = $this->getParent(); if (instance_of($parent, 'Page') && $parent->getVisibility() == VISIBILITY_PRIVATE) { $this->setVisibility($parent->getVisibility()); } // if } // if $modified_fields = $this->modified_fields; $old_values = $this->old_values; $save = parent::save(); if ($save && !is_error($save)) { if (!$is_new && in_array('visibility', $modified_fields)) { $subpages = Pages::findSubpages($this, $this->getState(), $old_values['visibility']); if (is_foreachable($subpages)) { foreach ($subpages as $subpage) { $subpage->setVisibility($this->getVisibility()); $subpage->save(); } // foreach } // if } // if } // if return $save; }
/** * Override save method * * @param void * @return boolean */ function save() { $save = parent::save(); if ($save && !is_error($save)) { $this->refreshParentHasTime(); } // if return $save; }