function add_annotation_feedback_form_submit(Pieform $form, $values) { global $USER; $data = (object) array('title' => get_string('Annotation', 'artefact.annotation'), 'description' => $values['message'], 'onannotation' => $values['annotationid']); // hidden fields. $artefactid = $values['artefactid']; $viewid = $values['viewid']; $blockid = $values['blockid']; if ($artefactid) { $artefact = artefact_instance_from_id($artefactid); $data->artefact = $artefactid; $data->owner = $artefact->get('owner'); $data->group = $artefact->get('group'); $data->institution = $artefact->get('institution'); } else { if ($viewid) { $view = new View($viewid); $data->view = $viewid; $data->owner = $view->get('owner'); $data->group = $view->get('group'); $data->institution = $view->get('institution'); } } if ($author = $USER->get('id')) { $anonymous = false; $data->author = $author; } else { $anonymous = true; $data->authorname = $values['authorname']; } if (isset($values['moderate']) && $values['ispublic'] && !$USER->can_edit_view($view)) { $data->private = 1; $data->requestpublic = 'author'; $moderated = true; } else { $data->private = (int) (!$values['ispublic']); $moderated = false; } $private = $data->private; $annotationfeedback = new ArtefactTypeAnnotationfeedback(0, $data); $annotation = new ArtefactTypeAnnotation($values['annotationid']); db_begin(); $annotationfeedback->commit(); $url = $annotation->get_view_url($view->get('id'), true, false); $goto = get_config('wwwroot') . $url; if (isset($data->requestpublic) && $data->requestpublic === 'author' && $data->owner) { $arg = $author ? display_name($USER, null, true) : $data->authorname; $moderatemsg = (object) array('subject' => false, 'message' => false, 'strings' => (object) array('subject' => (object) array('key' => 'makepublicrequestsubject', 'section' => 'artefact.annotation', 'args' => array()), 'message' => (object) array('key' => 'makepublicrequestbyauthormessage', 'section' => 'artefact.annotation', 'args' => array(hsc($arg))), 'urltext' => (object) array('key' => 'Annotation', 'section' => 'artefact.annotation')), 'users' => array($data->owner), 'url' => $url); } require_once 'activity.php'; $data = (object) array('annotationfeedbackid' => $annotationfeedback->get('id'), 'annotationid' => $values['annotationid'], 'viewid' => $viewid, 'artefactid' => $artefactid); activity_occurred('annotationfeedback', $data, 'artefact', 'annotation'); if (isset($moderatemsg)) { activity_occurred('maharamessage', $moderatemsg); } db_commit(); if (param_exists('offset')) { $options = ArtefactTypeAnnotationfeedback::get_annotation_feedback_options(); $options->showcomment = 'last'; $options->artefact = $artefactid; $options->view = $viewid; $options->annotation = $values['annotationid']; $options->block = $blockid; $newlist = ArtefactTypeAnnotationfeedback::get_annotation_feedback($options); } else { $newlist = null; } // If you're anonymous and your message is moderated or private, then you won't // be able to tell what happened to it. So we'll provide some more explanation in // the feedback message. if ($anonymous && $moderated) { $message = get_string('annotationfeedbacksubmittedmoderatedanon', 'artefact.annotation'); } else { if ($anonymous && $private) { $message = get_string('annotationfeedbacksubmittedprivateanon', 'artefact.annotation'); } else { $message = get_string('annotationfeedbacksubmitted', 'artefact.annotation'); } } $form->reply(PIEFORM_OK, array('message' => $message, 'goto' => $goto, 'data' => $newlist)); }
safe_require('artefact', 'annotation'); $annotationfeedbackid = param_integer('id'); $viewid = param_integer('viewid'); $annotationfeedback = new ArtefactTypeAnnotationFeedback((int) $annotationfeedbackid); if ($USER->get('id') != $annotationfeedback->get('author')) { throw new AccessDeniedException(get_string('canteditnotauthor', 'artefact.annotation')); } $annotationid = $annotationfeedback->get('onannotation'); $annotation = new ArtefactTypeAnnotation($annotationid); $onview = $annotation->get('view'); if ($onview && $onview != $viewid) { throw new NotFoundException(get_string('annotationfeedbacknotinview', 'artefact.annotation', $annotationfeedbackid, $viewid)); } $maxage = (int) get_config_plugin('artefact', 'annotation', 'commenteditabletime'); $editableafter = time() - 60 * $maxage; $goto = $annotation->get_view_url($viewid, false); if ($annotationfeedback->get('ctime') < $editableafter) { $SESSION->add_error_msg(get_string('cantedittooold', 'artefact.annotation', $maxage)); redirect($goto); } $lastcomment = ArtefactTypeAnnotationfeedback::last_public_annotation_feedback($annotationid, $viewid, $annotation->get('artefact')); if (!$annotationfeedback->get('private') && $annotationfeedbackid != $lastcomment->id) { $SESSION->add_error_msg(get_string('cantedithasreplies', 'artefact.annotation')); redirect($goto); } $elements = array(); $elements['message'] = array('type' => 'wysiwyg', 'title' => get_string('Annotationfeedback', 'artefact.annotation'), 'rows' => 5, 'cols' => 80, 'defaultvalue' => $annotationfeedback->get('description'), 'rules' => array('maxlength' => 8192)); $elements['ispublic'] = array('type' => 'checkbox', 'title' => get_string('makepublic', 'artefact.annotation'), 'defaultvalue' => !$annotationfeedback->get('private')); // What is this annotation feedback linked to? Store it in hidden fields. $elements['viewid'] = array('type' => 'hidden', 'value' => $viewid); $elements['artefactid'] = array('type' => 'hidden', 'value' => $annotation->get('artefact'));