/** * Removes a tag's association with a given inbox message * @param int $userId ID of user that owns inbox/message * @param int $messageId ID of message to remove tag from * @param string $tagName Name of tag to remove * @version 2012052801 * @since 2012052701 */ private function removeTagFromMessage($userId, $messageId, $tagName) { $tag = $this->messageDAO->getTagByName($userId, $tagName); $this->messageDAO->removeTagFromMessage($messageId, $tag->getId()); $response = $this->responseTemplate; $response['userId'] = $userId; return json_encode($response); }
/** * Fetches content for the block when displayed * @global Object $CFG Moodle config object * @global Object $USER Moodle user object * @return string Block content * @version 2012071701 * @since 2010081801 */ public function get_content() { global $CFG, $USER; // If content has already been created, return that if ($this->content !== NULL) { return $this->content; } // Get renderer $output = $this->page->get_renderer('block_moodletxt'); // Get some user details $user = $this->userDAO->getUserById($USER->id); // Initialise content class $this->content = new stdClass(); // Check that specialization has been done $this->specialization(); $userIsAdmin = false; $userCanReceive = false; // Check for admin $userIsAdmin = has_capability('block/moodletxt:adminsettings', $this->context, $USER->id) || has_capability('block/moodletxt:adminusers', $this->context, $USER->id); // Check that user has send access $checkSend = has_capability('block/moodletxt:sendmessages', $this->context, $USER->id); // Check user is allowed to set their signature/templates up $checkPrefs = has_capability('block/moodletxt:personalsettings', $this->context, $USER->id); $unreadFrag = ''; if (has_capability('block/moodletxt:receivemessages', $this->context, $USER->id)) { $userCanReceive = true; $unreadMessages = $this->receivedMessagesDAO->countMessagesInUsersInbox($USER->id, true); if ($unreadMessages > 0) { $unreadFrag = html_writer::tag('b', '(' . $unreadMessages . ')'); } } // Initialise content object $this->content->items = array(); $this->content->icons = array(); $this->content->footer = ''; // Add links to block dependent on user permissions/access level if ($checkSend) { $icon = new moodletxt_icon(moodletxt_icon::$ICON_MESSAGE_COMPOSE, get_string('altcompose', 'block_moodletxt'), array('title' => get_string('imgtitlecompose', 'block_moodletxt'))); array_push($this->content->items, html_writer::tag('a', get_string('blocklinksend', 'block_moodletxt'), array('href' => $CFG->wwwroot . '/blocks/moodletxt/send.php?course=' . $this->page->course->id . '&instance=' . $this->instance->id))); array_push($this->content->icons, $output->render($icon)); $icon = new moodletxt_icon(moodletxt_icon::$ICON_MESSAGES_SENT, get_string('altsentmessages', 'block_moodletxt'), array('title' => get_string('imgtitlesentmessages', 'block_moodletxt'))); array_push($this->content->items, html_writer::tag('a', get_string('blocklinksent', 'block_moodletxt'), array('href' => $CFG->wwwroot . '/blocks/moodletxt/sent.php?course=' . $this->page->course->id . '&instance=' . $this->instance->id))); array_push($this->content->icons, $output->render($icon)); $icon = new moodletxt_icon(moodletxt_icon::$ICON_ADDRESSBOOK, get_string('altaddressbook', 'block_moodletxt'), array('title' => get_string('imgtitleaddressbook', 'block_moodletxt'))); array_push($this->content->items, html_writer::tag('a', get_string('blocklinkaddressbook', 'block_moodletxt'), array('href' => $CFG->wwwroot . '/blocks/moodletxt/addressbooks.php?course=' . $this->page->course->id . '&instance=' . $this->instance->id))); array_push($this->content->icons, $output->render($icon)); } if ($userCanReceive) { $icon = new moodletxt_icon(moodletxt_icon::$ICON_MESSAGES_INBOX, get_string('altinbox', 'block_moodletxt'), array('title' => get_string('imgtitleinbox', 'block_moodletxt'))); array_push($this->content->items, html_writer::tag('a', get_string('blocklinkinbox', 'block_moodletxt') . $unreadFrag, array('href' => $CFG->wwwroot . '/blocks/moodletxt/received.php?course=' . $this->page->course->id . '&instance=' . $this->instance->id))); array_push($this->content->icons, $output->render($icon)); } if ($checkPrefs) { $icon = new moodletxt_icon(moodletxt_icon::$ICON_PREFERENCES, get_string('altpreferences', 'block_moodletxt'), array('title' => get_string('imgtitlepreferences', 'block_moodletxt'))); array_push($this->content->items, html_writer::tag('a', get_string('blocklinkpreferences', 'block_moodletxt'), array('href' => $CFG->wwwroot . '/blocks/moodletxt/preferences.php?course=' . $this->page->course->id . '&instance=' . $this->instance->id))); array_push($this->content->icons, $output->render($icon)); } if ($userIsAdmin) { // $icon = new moodletxt_icon(moodletxt_icon::$ICON_STATS, get_string('altstats', 'block_moodletxt'), array('title' => get_string('imgtitlestats', 'block_moodletxt'))); // array_push($this->content->items, html_writer::tag('a', get_string('blocklinkstats', 'block_moodletxt'), array('href' => $CFG->wwwroot . '/blocks/moodletxt/userstats.php?course=' . $this->page->course->id . '&instance=' . $this->instance->id))); // array_push($this->content->icons, $output->render($icon)); $icon = new moodletxt_icon(moodletxt_icon::$ICON_SETTINGS, get_string('altsettings', 'block_moodletxt'), array('title' => get_string('imgtitlesettings', 'block_moodletxt'))); array_push($this->content->items, html_writer::tag('a', get_string('blocklinksettings', 'block_moodletxt'), array('href' => $CFG->wwwroot . '/admin/settings.php?section=blocksettingmoodletxt'))); array_push($this->content->icons, $output->render($icon)); } // If some form of content has been added, set up block if (count($this->content->items) > 0) { $this->content->footer = get_string('blockfooter', 'block_moodletxt'); // Check whether config info has been previously defined if (!isset($this->config->title) || empty($this->config->title)) { // Set up default configuration $this->title = get_string('blocktitle', 'block_moodletxt'); } else { // Use user configuration $this->title = $this->config->title; } } return $this->content; }
require_once $CFG->dirroot . '/blocks/moodletxt/dao/TxttoolsAccountDAO.php'; require_once $CFG->dirroot . '/blocks/moodletxt/dao/TxttoolsReceivedMessageDAO.php'; require_once $CFG->dirroot . '/blocks/moodletxt/dao/MoodletxtMoodleUserDAO.php'; require_once $CFG->dirroot . '/blocks/moodletxt/forms/renderers/InlineFormRenderer.php'; require_once $CFG->dirroot . '/blocks/moodletxt/forms/MoodletxtInboxControlForm.php'; require_once $CFG->dirroot . '/blocks/moodletxt/util/MoodletxtStringHelper.php'; $courseId = required_param('course', PARAM_INT); $instanceId = required_param('instance', PARAM_INT); $update = optional_param('update', 0, PARAM_INT); $download = optional_param('download', '', PARAM_ALPHA); require_login($courseId, false); $blockcontext = context_block::instance($instanceId); require_capability('block/moodletxt:receivemessages', $blockcontext, $USER->id); // OK, so you're legit. Let's load DAOs $txttoolsAccountDAO = new TxttoolsAccountDAO(); $receivedMessagesDAO = new TxttoolsReceivedMessageDAO(); $inboundFilterManager = new MoodletxtInboundFilterManager(); $userDAO = new MoodletxtMoodleUserDAO(); // Get user's inbox preferences $globalSourceConfig = get_config('moodletxt', 'Show_Inbound_Numbers'); $userConfig = $userDAO->getUserConfig($USER->id); $showInboundNumbers = $userConfig->getUserConfig('hideSources') == '0' && $globalSourceConfig == '1'; // Get tags and counts for user $tagList = $receivedMessagesDAO->getAllTagsForUser($USER->id); /* * Check to see if inbound messages should be fetched at this point. * This should only be used on-demand, or if the user cannot * set up XML Push */ $fetchErrors = array(); if ($update == 1 || get_config('moodletxt', 'Get_Inbound_On_View') == '1') {
*/ require_once '../../config.php'; require_once $CFG->dirroot . '/blocks/moodletxt/lib/MoodletxtEncryption.php'; require_once $CFG->dirroot . '/blocks/moodletxt/connect/xml/MoodletxtXMLParser.php'; require_once $CFG->dirroot . '/blocks/moodletxt/dao/TxttoolsSentMessageDAO.php'; require_once $CFG->dirroot . '/blocks/moodletxt/dao/TxttoolsReceivedMessageDAO.php'; require_once $CFG->dirroot . '/blocks/moodletxt/inbound/MoodletxtInboundFilterManager.php'; // Read in POST variables $inPushUser = required_param('u', PARAM_ALPHANUM); $inPushPass = required_param('p', PARAM_ALPHANUM); $inPayload = required_param('x', PARAM_RAW); // Assuming we have the right params, set up for parsing $parser = new MoodletxtXMLParser(); $decrypter = new MoodletxtEncryption(); $sentMessagesDAO = new TxttoolsSentMessageDAO(); $receivedMessagesDAO = new TxttoolsReceivedMessageDAO(); $inboundFilterManager = new MoodletxtInboundFilterManager(); $key = get_config('moodletxt', 'EK'); $pushUsername = get_config('moodletxt', 'Push_Username'); $pushPassword = $decrypter->decrypt($key, get_config('moodletxt', 'Push_Password')); // Check credentials against those stored in Moodle if ($inPushUser === $pushUsername && $inPushPass === $pushPassword) { $parsedInboundMessages = array(); $parsedStatusUpdates = array(); try { $parsedObjects = $parser->parse($inPayload); } catch (Exception $ex) { // Invalid XML from remote system die; } if (is_array($parsedObjects)) {