Exemple #1
0
/**
 * Receives a message event object from moodletxt+
 * and sens an SMS to the destination user as per their
 * preferences
 * @param object $messageObject Message event object
 * @version 2012062401
 * @since 2012062401
 */
function send_moodletxt_plus_message($messageObject)
{
    $accountDAO = new TxttoolsAccountDAO();
    $userDAO = new MoodletxtMoodleUserDAO();
    $messageDAO = new TxttoolsSentMessageDAO();
    // moodletxt requires a ConnectTxt account to be specified
    // for this message to transition via
    $defaultAccountId = (int) get_config('moodletxt', 'Event_Messaging_Account');
    if ($defaultAccountId > 0) {
        $connectTxtAccount = $accountDAO->getTxttoolsAccountById($defaultAccountId);
        // Check that the specified account has outbound enabled
        if ($connectTxtAccount->isOutboundEnabled()) {
            $sender = $userDAO->getUserById($messageObject->from_id);
            $recipient = $userDAO->getUserById($messageObject->to_id);
            $message = new MoodletxtOutboundMessage($connectTxtAccount, $sender, $messageObject->smallmessage, time(), MoodletxtOutboundMessage::$MESSAGE_CHARGE_TYPE_BULK);
            $message->addMessageRecipient($recipient);
            $message->setEventCreated(true);
            // Send message to ConnectTxt
            try {
                $connector = MoodletxtOutboundControllerFactory::getOutboundController(MoodletxtOutboundControllerFactory::$CONTROLLER_TYPE_XML);
                $message->setSentSMSMessages($connector->sendMessage($message));
                $messageDAO->saveSentMessage($message);
            } catch (MoodletxtRemoteProcessingException $ex) {
                // Die silently, for now
            }
        }
    }
}
 /**
  * @return array
  * @version 2015062901
  * @since 2015062901
  */
 private function getAllPhoneNumbers()
 {
     $numbers = array();
     $contactNumbers = $this->addressbookDAO->getPhonenumbersOfAllContacts();
     $users = $this->userDAO->getAllUsers();
     foreach ($contactNumbers as $number) {
         $numbers[] = $number;
     }
     foreach ($users as $user) {
         if ($user->getRecipientNumber() != NULL && $user->getRecipientNumber()->getPhoneNumber() != NULL) {
             $numbers[] = $user->getRecipientNumber()->getPhoneNumber();
         }
     }
     return array_unique($numbers);
 }
 /**
  * Updates an acount's list of allowed users
  * @param int $accountId ConnectTxt account ID
  * @param array $allowedUsers User IDs the account should be restricted to
  * @return string JSON response
  * @version 2013061701
  * @since 2011062301
  */
 private function updateAccountRestrictions($accountId, array $allowedUsers)
 {
     $txttoolsAccount = $this->accountDAO->getTxttoolsAccountById($accountId);
     // Account must exist within system
     if (!is_object($txttoolsAccount)) {
         throw new MoodletxtAJAXException(get_string('errorinvalidaccountid', 'block_moodletxt'), MoodletxtAJAXException::$ERROR_CODE_BAD_ACCOUNT_ID, null, false, $accountId);
     }
     // Easiest way of doing this, rather than checking
     // which links already exist and modifying, is to clear
     // all existing links and save the given set
     $txttoolsAccount->clearAllowedUsers();
     foreach ($allowedUsers as $allowedUser) {
         try {
             $userObj = $this->userDAO->getUserById($allowedUser);
             $txttoolsAccount->addAllowedUser($userObj);
         } catch (InvalidArgumentException $ex) {
             // Bad user ID - ignore and continue
             continue;
         }
     }
     $this->accountDAO->saveTxttoolsAccount($txttoolsAccount, true);
     return $this->buildResponse($txttoolsAccount);
 }
 /**
  * Move messages from one user's inbox to another
  * @param int $sourceUserId ID of source user for the message(s)
  * @param array(int) $messageIds The ID(s) of message(s) to move across
  * @param int $destinationUserId ID of user to send messages to
  * @return string Encoded JSON response
  * @throws MoodletxtAJAXException 
  * @version 2012051601
  * @since 2012050301
  */
 private function moveMessagesToUser($sourceUserId, array $messageIds, $destinationUserId)
 {
     try {
         $sourceUser = $this->userDAO->getUserById($sourceUserId);
         $destinationUser = $this->userDAO->getUserById($destinationUserId);
         // User is trying to pull a fast one - stop them
         if ($sourceUser === null || $destinationUser === null) {
             throw new MoodletxtAJAXException(get_string('errorinvaliduserid', 'block_moodletxt'), MoodletxtAJAXException::$ERROR_CODE_BAD_USER_ID);
         }
         foreach ($messageIds as $messageId) {
             $message = $this->messageDAO->getMessageById($messageId, true, $sourceUser->getId());
             $this->messageDAO->deleteMessage($message);
             $message->addDestinationUserId($destinationUser->getId());
             $this->messageDAO->saveInboundMessage($message);
         }
     } catch (InvalidArgumentException $ex) {
         // Either the message no longer exists,
         // or the user is attempting to access a message they don't own
         throw new MoodletxtAJAXException(get_string('errorbadmessageid', 'block_moodletxt'), MoodletxtAJAXException::$ERROR_CODE_BAD_MESSAGE_ID);
     }
     $response = $this->responseTemplate;
     $response['userId'] = $sourceUser->getId();
     return json_encode($response);
 }
Exemple #5
0
$courseId = required_param('course', PARAM_INT);
$instanceId = required_param('instance', PARAM_INT);
$replyType = optional_param('replyType', '', PARAM_ALPHA);
$replyValue = optional_param('replyValue', '', PARAM_RAW_TRIMMED);
if ($replyType == 'additional' && !MoodletxtPhoneNumber::validatePhoneNumber($replyValue)) {
    $replyType = '';
    $replyValue = '';
}
require_login($courseId, false);
$blockcontext = context_block::instance($instanceId);
require_capability('block/moodletxt:sendmessages', $blockcontext, $USER->id);
// OK, so you're legit. Let's load DAOs and required DB data
$templateDAO = new MoodletxtTemplatesDAO();
$accountDAO = new TxttoolsAccountDAO();
$addressbookDAO = new MoodletxtAddressbookDAO();
$userDAO = new MoodletxtMoodleUserDAO();
$messageDAO = new TxttoolsSentMessageDAO();
$statsDAO = new MoodletxtUserStatsDAO();
$course = $DB->get_record('course', array('id' => $courseId));
$notifications = '';
// Set up the page for rendering
$PAGE->set_url('/blocks/moodletxt/send.php');
$PAGE->set_title(get_string('titlesend', 'block_moodletxt') . ' ' . $course->fullname);
$PAGE->set_heading(get_string('headersend', 'block_moodletxt'));
$PAGE->set_pagelayout('incourse');
$PAGE->set_button('');
// Clear editing button
$PAGE->navbar->add(get_string('navmoodletxt', 'block_moodletxt'), null, navigation_node::TYPE_CUSTOM, 'moodletxt');
$PAGE->navbar->add(get_string('navsent', 'block_moodletxt'), null, navigation_node::TYPE_CUSTOM, 'moodletxt');
$PAGE->requires->strings_for_js(array('errorlabel', 'errornonumber', 'errornofirstname', 'errornolastname', 'errornorecipientsselected', 'errornomessage'), 'block_moodletxt');
$PAGE->requires->jquery();
 /**
  * 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;
 }
 * @copyright Copyright © 2014 Blackboard Connect. All rights reserved.
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public Licence v3 (See code header for additional terms)
 * @version 2014071501
 * @since 2011062901
 */
require_once '../../config.php';
require_once $CFG->libdir . '/adminlib.php';
require_once $CFG->dirroot . '/blocks/moodletxt/dao/TxttoolsAccountDAO.php';
require_once $CFG->dirroot . '/blocks/moodletxt/dao/MoodletxtMoodleUserDAO.php';
require_once $CFG->dirroot . '/blocks/moodletxt/dao/MoodletxtInboundFilterDAO.php';
require_once $CFG->dirroot . '/blocks/moodletxt/forms/MoodletxtFiltersForm.php';
require_login();
require_capability('block/moodletxt:adminsettings', context_system::instance());
// Set up DAOs
$accountDAO = new TxttoolsAccountDAO();
$userDAO = new MoodletxtMoodleUserDAO();
$filterDAO = new MoodletxtInboundFilterDAO();
admin_externalpage_setup('manageblocks');
// Shortcut function sets up page for block admin
// Set up the page
$PAGE->set_url('/blocks/moodletxt/settings_filters.php');
$PAGE->set_heading(get_string('adminheaderfilters', 'block_moodletxt'));
$PAGE->set_title(get_string('admintitlefilters', 'block_moodletxt'));
$PAGE->set_docs_path('admin/setting/moodletxtfilters');
// External admin pages get their MoodleDocs links messed up
$PAGE->set_button('');
// Clear editing button
$PAGE->navbar->add(get_string('navmoodletxt', 'block_moodletxt'), $CFG->wwwroot . '/admin/settings.php?section=blocksettingmoodletxt', navigation_node::TYPE_CUSTOM, 'moodletxt');
$PAGE->navbar->add(get_string('navfilters', 'block_moodletxt'), null, navigation_node::TYPE_CUSTOM, 'moodletxt');
// JS/CSS includes and language requirements
$PAGE->requires->strings_for_js(array('adminaccountfragloading', 'adminlabelfilterusersearch'), 'block_moodletxt');
Exemple #8
0
$includeEvents = optional_param('events', TxttoolsSentMessageDAO::$EVENT_QUERY_DISCARD, PARAM_INT);
$userToView = optional_param('user', $USER->id, PARAM_INT);
$MESSAGES_PER_PAGE = 25;
require_login($courseId, false);
$blockcontext = context_block::instance($instanceId);
require_capability('block/moodletxt:sendmessages', $blockcontext, $USER->id);
// Make sure that the user has the ability to change the
// ID of the user whose messages are being shown
$canAdminUsers = has_capability('block/moodletxt:adminusers', $blockcontext, $USER->id);
if (!$canAdminUsers && $userToView != $USER->id) {
    $userToView = $USER->id;
}
// Naughty user, don't try that again.
// OK, so you're legit. Let's load DAOs
$sentMessagesDAO = new TxttoolsSentMessageDAO();
$userDAO = new MoodletxtMoodleUserDAO();
// Set up the page for rendering
$pageParams = '?course=' . $courseId . '&instance=' . $instanceId . '&events=' . $includeEvents;
$pageParams .= $canAdminUsers ? '&user='******'';
$PAGE->set_url('/blocks/moodletxt/sent.php' . $pageParams);
$PAGE->set_title(get_string('titlesent', 'block_moodletxt') . ' ' . $USER->lastname . ', ' . $USER->firstname);
$PAGE->set_heading(get_string('headersent', 'block_moodletxt'));
$PAGE->set_pagelayout('incourse');
$PAGE->set_button('');
// Clear editing button
$PAGE->navbar->add(get_string('navmoodletxt', 'block_moodletxt'), null, navigation_node::TYPE_CUSTOM, 'moodletxt');
$PAGE->navbar->add(get_string('navsent', 'block_moodletxt'), null, navigation_node::TYPE_CUSTOM, 'moodletxt');
$output = $PAGE->get_renderer('block_moodletxt');
/*
 * Create results table
 */
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public Licence v3 (See code header for additional terms)
 * @version 2015062901
 * @since 2011042601
 */
require_once '../../config.php';
require_once $CFG->libdir . '/adminlib.php';
require_once $CFG->dirroot . '/blocks/moodletxt/dao/TxttoolsAccountDAO.php';
require_once $CFG->dirroot . '/blocks/moodletxt/dao/MoodletxtMoodleUserDAO.php';
require_once $CFG->dirroot . '/blocks/moodletxt/forms/NewTxttoolsAccountForm.php';
require_once $CFG->dirroot . '/blocks/moodletxt/lib/MoodletxtEncryption.php';
require_once $CFG->dirroot . '/blocks/moodletxt/connect/MoodletxtOutboundControllerFactory.php';
require_login();
require_capability('block/moodletxt:adminsettings', context_system::instance());
// OK, so you're legit. Let's load DAOs
$accountDAO = new TxttoolsAccountDAO();
$userDAO = new MoodletxtMoodleUserDAO();
// Check for txttools accounts - if there are no accounts in the system, we'll
// display the "new installation" page introduction, rather than the standard one
$numberOfAccounts = $accountDAO->countTxttoolsRecords();
admin_externalpage_setup('manageblocks');
// Shortcut function sets up page for block admin
$PAGE->set_url('/blocks/moodletxt/settings_accounts_new.php');
$PAGE->set_button('');
// Clear editing button
$PAGE->set_focuscontrol('id_accountName');
// Focus username field on load
$PAGE->set_docs_path('admin/setting/moodletxtaccountsnew');
// External admin pages get their MoodleDocs links messed up
$PAGE->navbar->add(get_string('navmoodletxt', 'block_moodletxt'), $CFG->wwwroot . '/admin/settings.php?section=blocksettingmoodletxt', navigation_node::TYPE_CUSTOM, 'moodletxt');
$PAGE->navbar->add(get_string('navaccounts', 'block_moodletxt'), $CFG->wwwroot . '/blocks/moodletxt/settings_accounts.php', navigation_node::TYPE_CUSTOM, 'moodletxt');
if ($numberOfAccounts == 0) {
Exemple #10
0
 * @copyright Copyright © 2014 Blackboard Connect. All rights reserved.
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public Licence v3 (See code header for additional terms)
 * @version 2014071401
 * @since 2011072601
 */
require_once '../../config.php';
require_once $CFG->dirroot . '/blocks/moodletxt/dao/MoodletxtMoodleUserDAO.php';
require_once $CFG->dirroot . '/blocks/moodletxt/dao/MoodletxtTemplatesDAO.php';
require_once $CFG->dirroot . '/blocks/moodletxt/forms/UserPreferencesForm.php';
$courseId = required_param('course', PARAM_INT);
$instanceId = required_param('instance', PARAM_INT);
require_login($courseId, false);
$blockcontext = context_block::instance($instanceId);
require_capability('block/moodletxt:personalsettings', $blockcontext, $USER->id);
// Load DAOs
$userDAO = new MoodletxtMoodleUserDAO();
$templateDAO = new MoodletxtTemplatesDAO();
// Set up page object and JavaScript requirements
$PAGE->set_url('/blocks/moodletxt/preferences.php');
$PAGE->set_heading(get_string('headerpreferences', 'block_moodletxt'));
$PAGE->set_title(get_string('titlepreferences', 'block_moodletxt'));
$PAGE->set_pagelayout('incourse');
$PAGE->set_button('');
// Clear editing button
$PAGE->navbar->add(get_string('navmoodletxt', 'block_moodletxt'), null, navigation_node::TYPE_CUSTOM, 'moodletxt');
$PAGE->navbar->add(get_string('navpreferences', 'block_moodletxt'), null, navigation_node::TYPE_CUSTOM, 'moodletxt');
$PAGE->requires->strings_for_js(array('headertemplatesedit', 'alertnotemplateselected', 'alertconfirmdeletetemplate', 'settingsedittemplate', 'warnunicode'), 'block_moodletxt');
$PAGE->requires->jquery();
$PAGE->requires->jquery_plugin('moodletxt-json', 'block_moodletxt');
$PAGE->requires->jquery_plugin('moodletxt-timers', 'block_moodletxt');
$PAGE->requires->jquery_plugin('moodletxt-selectboxes', 'block_moodletxt');
Exemple #11
0
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') {
    try {
        $connector = MoodletxtOutboundControllerFactory::getOutboundController(MoodletxtOutboundControllerFactory::$CONTROLLER_TYPE_XML);