Ejemplo n.º 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
            }
        }
    }
}
Ejemplo n.º 2
0
 /**
  * @return void
  * @version 2015062901
  * @since 2015062901
  */
 public function pollForBlacklistedRecipients()
 {
     $usAccounts = $this->accountDAO->getAccountByLocation(TxttoolsAccount::$US_LOCATION);
     foreach ($usAccounts as $account) {
         try {
             $phoneNumbers = $this->getAllPhoneNumbers();
             $blacklistedNumbers = $this->xmlController->getOptOutStatusUpdates($phoneNumbers, $account);
             $this->syncDbWithResponse($blacklistedNumbers, $account);
         } catch (Exception $ex) {
             // XML request might throw exceptions in case of some errors
             // Ignored
             file_put_contents('C:\\moodle.log', time() . ': cron blacklist poll failed for account (' . $account->getUsername() . '@' . $account->getUrl() . ') -> ' . $ex->getMessage(), FILE_APPEND);
         }
     }
 }
 /**
  * Globally toggle access to an account, either in or outbound
  * @param int $accountId ID of account to modify
  * @param string $direction Specify inbound/outbound access to update
  * @return string JSON response
  * @throws MoodletxtAJAXException
  * @version 2012101601
  * @since 2011061301
  */
 private function toggleAccountAccess($accountId, $direction = 'outbound')
 {
     $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);
     }
     // Update account settings within DB
     if ($direction == self::$DIRECTION_IDENTIFIER_OUTBOUND) {
         $txttoolsAccount->setOutboundEnabled(!$txttoolsAccount->isOutboundEnabled());
     } else {
         if ($direction == self::$DIRECTION_IDENTIFIER_INBOUND) {
             $txttoolsAccount->setInboundEnabled(!$txttoolsAccount->isInboundEnabled());
         }
     }
     $this->accountDAO->saveTxttoolsAccount($txttoolsAccount);
     return $this->buildResponse($txttoolsAccount);
 }
Ejemplo n.º 4
0
require_once $CFG->dirroot . '/blocks/moodletxt/forms/MoodletxtSendMessageForm.php';
require_once $CFG->dirroot . '/blocks/moodletxt/connect/MoodletxtOutboundControllerFactory.php';
$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');
Ejemplo n.º 5
0
 /**
  * Validation routine for account form
  * @param array $formdata Submitted data from form
  * @param object $files File uploads from form
  * @return array(string => string) Array of errors, if any found
  * @version 2012081401
  * @since 2011062901
  */
 public function validation($formData, $files = null)
 {
     $err = array();
     $accountDAO = new TxttoolsAccountDAO();
     $filterDAO = new MoodletxtInboundFilterDAO();
     $formData = $this->cleanupFormData($formData);
     // Check for valid account ID
     if ($formData['filterAccountList'] <= 0 || !$accountDAO->accountIdExists($formData['filterAccountList'])) {
         $err['filterAccountList'] = get_string('errorfilternoaccount', 'block_moodletxt');
     }
     // Clean up any potential data cockups on the user list
     if (!isset($formData['usersOnFilter']) || $formData['usersOnFilter'] == '') {
         $formData['usersOnFilter'] = array();
     } else {
         if (!is_array($formData['usersOnFilter'])) {
             $formData['usersOnFilter'] = array($formData['usersOnFilter']);
         }
     }
     // Check that, if a new phone number filter has been entered, it is valid
     if ($formData['newPhoneNumberFilter'] != '' && !MoodletxtPhoneNumber::validatePhoneNumber($formData['newPhoneNumberFilter'])) {
         $err['newPhoneNumberFilter'] = get_string('errorfilterbadphoneno', 'block_moodletxt');
     }
     if ($formData['newKeywordFilter'] != '' || $formData['newPhoneNumberFilter'] != '') {
         // When creating a new filter, the user must have selected recipient inboxes
         if (count($formData['usersOnFilter']) == 0) {
             $err['usersOnFilter'] = get_string('errorfilternousers', 'block_moodletxt');
         }
         $type = $formData['newKeywordFilter'] != '' ? MoodletxtInboundFilter::$FILTER_TYPE_KEYWORD : MoodletxtInboundFilter::$FILTER_TYPE_PHONE_NUMBER;
         $value = $formData['newKeywordFilter'] != '' ? $formData['newKeywordFilter'] : $formData['newPhoneNumberFilter'];
         if ($filterDAO->filterExists($formData['filterAccountList'], $type, $value)) {
             if ($type == MoodletxtInboundFilter::$FILTER_TYPE_KEYWORD) {
                 $err['newKeywordFilter'] = get_string('errorfilterexists', 'block_moodletxt');
             } else {
                 $err['newPhoneNumberFilter'] = get_string('errorfilterexists', 'block_moodletxt');
             }
         }
     } else {
         if ($formData['existingKeywordFilterList'] <= 0 && $formData['existingPhoneNumberFilterList'] <= 0) {
             $err['existingKeywordFilterList'] = get_string('errorfilternotselected', 'block_moodletxt');
         }
     }
     return $err;
 }
Ejemplo n.º 6
0
 * Anyone using, extending or modifying moodletxt indemnifies the original authors against any contractual
 * or legal liability arising from their use of this code.
 * 
 * @package uk.co.moodletxt
 * @author Greg J Preece <*****@*****.**>
 * @copyright Copyright &copy; 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 2015062901
 * @since 2011041701
 */
defined('MOODLE_INTERNAL') || die('File cannot be accessed directly.');
// Not really supposed to do this kind of thing here, but I need the account list
require_once $CFG->dirroot . '/blocks/moodletxt/dao/TxttoolsAccountDAO.php';
require_once $CFG->dirroot . '/blocks/moodletxt/settings/admin_setting_password_unmask_encrypted.php';
// Grab current ConnectTxt accounts from database, fo sho
$accountDAO = new TxttoolsAccountDAO();
$accountSet = array();
try {
    $accountSet = $accountDAO->getAllTxttoolsAccounts(false, false, true, false);
    // Check outbound is active
} catch (dml_read_exception $ex) {
    /* We're not really supposed to have database code in the settings file
       but we need it here to get a list of accounts. Valid use case, certainly.
       However, if the block is in place at Moodle install time, this file
       may be run before the database tables are in place, so we need this
       try-catch to stop the installation from failing! */
    // Do nothing - fail silently and allow installation to continue
}
$accountList = array(0 => get_string('adminselecteventsdisabled', 'block_moodletxt'));
foreach ($accountSet as $account) {
    $accountList[$account->getId()] = $account->getUsername() . ' (' . $account->getDescription() . ')';
Ejemplo n.º 7
0
 /**
  * Validation routine for account form
  * @param array $formdata Submitted data from form
  * @param object $files File uploads from form
  * @return Array of errors, if any found
  * @version 2015062901
  * @since 2011042601
  */
 public function validation($formdata, $files = null)
 {
     $accountDAO = new TxttoolsAccountDAO();
     $accountCount = $accountDAO->countTxttoolsRecords();
     $err = array();
     $formdata['accountCtxtInstance'] = trim($formdata['accountCtxtInstance']);
     $formdata['accountUrl'] = trim($formdata['accountUrl']);
     $formdata['accountName'] = trim($formdata['accountName']);
     $formdata['accountPassword1'] = trim($formdata['accountPassword1']);
     $formdata['accountPassword2'] = trim($formdata['accountPassword2']);
     $formdata['accountDescription'] = trim($formdata['accountDescription']);
     $formdata['accountDefaultInbox'] = trim($formdata['accountDefaultInbox']);
     if ($formdata['accountPassword1'] !== $formdata['accountPassword2']) {
         $err['accountPassword1'] = get_string('errornopasswordmatch', 'block_moodletxt');
     }
     if ($accountCount < 1 && $formdata['accountCtxtInstance'] === 'URL' && !$formdata['accountUrl']) {
         $err['accountUrl'] = get_string('errornourl', 'block_moodletxt');
     }
     return $err;
 }
 /**
  * Returns any Moodle users that match a given keyword
  * @param string $keyword Keyword to search for
  * @return string JSON response
  * @version 2011062701
  * @since 2011062301
  */
 private function searchByKeyword($keyword)
 {
     $foundUsers = $this->dao->searchUsersByNameAndUsername($keyword);
     return $this->buildResponse($foundUsers);
 }
Ejemplo n.º 9
0
 * @copyright Copyright &copy; 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 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');
Ejemplo n.º 10
0
 * @copyright Copyright &copy; 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 2015062901
 * @since 2011042601
 */
require_once '../../config.php';
require_once $CFG->libdir . '/adminlib.php';
require_once $CFG->libdir . '/tablelib.php';
require_once $CFG->dirroot . '/blocks/moodletxt/dao/TxttoolsAccountDAO.php';
require_once $CFG->dirroot . '/blocks/moodletxt/dao/TxttoolsSentMessageDAO.php';
require_once $CFG->dirroot . '/blocks/moodletxt/forms/TxttoolsAccountEditForm.php';
require_once $CFG->dirroot . '/blocks/moodletxt/forms/TxttoolsAccountRestrictionsForm.php';
require_login();
require_capability('block/moodletxt:adminsettings', context_system::instance());
// OK, so you're legit. Let's load DAOs
$accountDAO = new TxttoolsAccountDAO();
$sentMessageDAO = new TxttoolsSentMessageDAO();
// Grab account details - if there are no accounts to see,
// send the user to the new installation screen
$accountList = $accountDAO->getAllTxttoolsAccounts();
if (count($accountList) == 0) {
    redirect($CFG->wwwroot . '/blocks/moodletxt/settings_accounts_new.php', get_string('redirectnoaccountsfound', 'block_moodletxt'));
}
// Account IDs are passed to JS for AJAX transactions
// Shifted up to match onscreen table rows
$accountIds = array();
// To further complicate things, Moodle 2.4 and above
// actually render tables correctly, with <tbody> tags
// and everything, so the index is different
$accountTableIndex = $CFG->version >= 2012120300 ? 1 : 2;
foreach ($accountList as $accountId => $account) {
Ejemplo n.º 11
0
require_once $CFG->dirroot . '/blocks/moodletxt/inbound/MoodletxtInboundFilterManager.php';
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();