/** * reject a task - this will invoke the task onreject action * saved against this message * * @param int $id message id * @return boolean success */ function tm_message_task_reject($id) { global $DB; $message = $DB->get_record('message', array('id' => $id)); if ($message) { // get the event data $eventdata =message_eventdata($id, 'onreject'); // grab the onaccept handler if (isset($eventdata->action)) { $plugin = tm_message_workflow_object($eventdata->action); if (!$plugin) { return false; } // run the onreject phase $result = $plugin->onreject($eventdata->data, $message); } // finally - dismiss this message as it has now been processed $result = tm_message_mark_message_read($message, time()); return $result; } else { return false; } }
/** * Construct the accept/reject actions * * @param int $id message Id * @return string HTML of accept/reject button */ function message_accept_reject_action($id) { global $CFG, $FULLME, $PAGE; // Button Lang Strings $cancel_string = get_string('cancel'); $clean_fullme = clean_param($FULLME, PARAM_LOCALURL); $msg = $DB->get_record('message', array('id' => $id), '*', MUST_EXIST); $msgmeta = $DB->get_record('message_metadata', array('messageid' => $id), '*', MUST_EXIST); $msgacceptdata = message_eventdata($id, 'onaccept'); $returnto = ($msgmeta->msgtype == MSG_TYPE_LINK && isset($msgacceptdata->data['redirect'])) ? $msgacceptdata->data['redirect'] : $clean_fullme; // Validate redirect $return_host = parse_url($returnto); $site_host = parse_url($CFG->wwwroot); if ($return_host['host'] != $site_host['host']) { print_error('error:redirecttoexternal', 'local_message'); } $subject = format_string($msg->subject); $onaccept_str = format_string(isset($msgacceptdata->acceptbutton) ? $msgacceptdata->acceptbutton : get_string('onaccept', 'block_tasks')); $onreject_str = get_string('onreject', 'block_tasks'); // only give the accept/reject actions if they actually exist $out = ''; if (!empty($msgmeta->onaccept)) { $PAGE->requires->string_for_js('cancel', 'moodle'); $args = array('id'=>$id, 'type' => 'accept', 'type_str' =>$onaccept_str, 'dialog_title' =>$subject, 'returnto'=>$returnto, 'sesskey'=>sesskey()); $PAGE->requires->js_init_call('M.message.create_accept_reject_dialog', $args); // Construct HTML for accept button $out .= html_writer::tag('form', html_writer::empty_tag('input', array('id' => "acceptmsg'.$id.'-dialog", 'type' => 'image', 'name' => 'tm_accept_msg', 'class' => 'iconsmall action', 'src' => $OUTPUT->pix_url('t/accept'), 'title' => $onaccept_str, 'alt' => $onaccept_str, 'style' => 'display:none;')) ); $out .= html_writer::tag('noscript', html_writer::tag('form', html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'id', 'value' => $id)) . html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'returnto', 'value' => $returnto)) . html_writer::empty_tag('input', array('type' => 'image', 'class' => 'iconsmall action', 'src' => $OUTPUT->pix_url('t/accept'), 'title' => $onaccept_str, 'alt' => $onaccept_str)), array('action' => $CFG->wwwroot . '/local/message/accept.php?id=' . $id, 'method' => 'post')) ); } if (!empty($msgmeta->onreject)) { $PAGE->requires->string_for_js('cancel', 'moodle'); $args = array('id'=>$id, 'type' => 'reject', 'type_str' =>$onaccept_str, 'dialog_title' =>$onreject_str, 'returnto'=>$clean_fullme, 'sesskey'=>sesskey()); $PAGE->requires->js_init_call('M.message.create_accept_reject_dialog', $args); // Construct HTML for accept button $out .= html_writer::tag('form', html_writer::empty_tag('input', array('id' => "rejectmsg'.$id.'-dialog", 'type' => 'image', 'name' => 'tm_reject_msg', 'class' => 'iconsmall action', 'src' => $OUTPUT->pix_url('t/delete'), 'title' => $onreject_str, 'alt' => $onreject_str, 'style' => 'display:none;')) ); $out .= html_writer::tag('noscript', html_writer::tag('form', html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'id', 'value' => $id)) . html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'returnto', 'value' => $clean_fullme)) . html_writer::empty_tag('input', array('type' => 'image', 'class' => 'iconsmall action', 'src' => $OUTPUT->pix_url('t/delete'), 'title' => $onreject_str, 'alt' => $onreject_str)), array('action' => $CFG->wwwroot . '/local/message/reject.php?id=' . $id, 'method' => 'post')) ); } return $out; }