/**
  * Sets up form for display to user
  * @global object $CFG Moodle global config
  * @version 2015062901
  * @since 2011042601
  */
 public function definition()
 {
     global $CFG;
     global $PAGE;
     $accountDAO = new TxttoolsAccountDAO();
     $accountCount = $accountDAO->countTxttoolsRecords();
     $PAGE->requires->jquery();
     $PAGE->requires->yui_module('moodle-block_moodletxt-admin', 'M.block_moodletxt.admin.init');
     $installForm =& $this->_form;
     // We need a list of users that can be default inboxes,
     // for the user to choose from for this initial account
     $defaultInboxUsers = get_users_by_capability(context_system::instance(), 'block/moodletxt:defaultinbox');
     $admins = get_admins();
     foreach ($admins as $admin) {
         $defaultInboxUsers[$admin->id] = $admin;
     }
     $defaultInboxList = array();
     foreach ($defaultInboxUsers as $defaultInboxUser) {
         $defaultInboxList[$defaultInboxUser->id] = MoodletxtStringHelper::formatNameForDisplay($defaultInboxUser->firstname, $defaultInboxUser->lastname, $defaultInboxUser->username);
     }
     $ctxtInstances = array();
     $ctxtInstances[TxttoolsAccount::$UK_LOCATION] = TxttoolsAccount::$UK_LOCATION . ' - ' . TxttoolsAccount::$UK_URL;
     $ctxtInstances[TxttoolsAccount::$US_LOCATION] = TxttoolsAccount::$US_LOCATION . ' - ' . TxttoolsAccount::$US_URL;
     $ctxtInstances['URL'] = 'Custom';
     // Txttools account
     $installForm->addElement('header', 'addAccount', get_string('adminlabeladdaccount', 'block_moodletxt'));
     if ($accountCount < 1) {
         $installForm->addElement('select', 'accountCtxtInstance', get_string('adminaccountctxtinstance', 'block_moodletxt'), $ctxtInstances);
         $installForm->setType('accountCtxtInstance', PARAM_STRINGID);
         $installForm->addElement('text', 'accountUrl', get_string('adminaccounturl', 'block_moodletxt'));
         $installForm->setType('accountUrl', PARAM_URL);
     }
     $installForm->addElement('text', 'accountName', get_string('adminlabelaccusername', 'block_moodletxt'), array('maxlength' => 20));
     $installForm->setType('accountName', PARAM_ALPHANUMEXT);
     $installForm->addRule('accountName', get_string('errornousername', 'block_moodletxt'), 'required');
     $installForm->addElement('password', 'accountPassword1', get_string('adminlabelaccpassword', 'block_moodletxt'));
     $installForm->setType('accountPassword1', PARAM_ALPHANUMEXT);
     $installForm->addRule('accountPassword1', get_string('errornopassword', 'block_moodletxt'), 'required');
     $installForm->addRule('accountPassword1', get_string('errorpasswordtooshort', 'block_moodletxt'), 'minlength', 8);
     $installForm->addElement('password', 'accountPassword2', get_string('adminlabelaccpassword2', 'block_moodletxt'));
     $installForm->setType('accountPassword2', PARAM_ALPHANUMEXT);
     $installForm->addRule('accountPassword2', get_string('errornopassword', 'block_moodletxt'), 'required');
     $installForm->addRule('accountPassword2', get_string('errorpasswordtooshort', 'block_moodletxt'), 'minlength', 8);
     $installForm->addElement('text', 'accountDescription', get_string('adminlabelaccdesc', 'block_moodletxt'));
     $installForm->setType('accountDescription', PARAM_TEXT);
     $installForm->addElement('select', 'accountDefaultInbox', get_string('adminlabelaccinbox', 'block_moodletxt'), $defaultInboxList);
     $installForm->setType('accountDefaultInbox', PARAM_INT);
     // Buttons
     $buttonarray = array();
     $buttonarray[] =& $installForm->createElement('submit', 'submitButton', get_string('adminbutaddaccount', 'block_moodletxt'));
     $installForm->addGroup($buttonarray, 'buttonar', '', array(' '), false);
     $installForm->closeHeaderBefore('buttonar');
 }
 /**
  * Override of standard Moodle function - allows for this
  * element to have additional recipients selected that were not 
  * in the form when it first loaded.
  * @param array $submitValues Data submitted to form
  * @param boolean $assoc Whether to return the value(s) as associative array
  * @return mixed The selected and valid value(s) of the element
  * @version 2012100301
  * @since 2012100301
  */
 public function exportValue(&$submitValues, $assoc = false)
 {
     $value = $this->_findValue($submitValues);
     // Get values of element to iterate over
     if (is_null($value)) {
         $value = $this->getValue();
     } else {
         if (!is_array($value)) {
             $value = array($value);
         }
     }
     $cleanValues = null;
     // Values should only be allowed into the form data
     // if they are part of the initial value set,
     // or if they begin with the fragment "add#", which
     // denotes an additional recipient being dynamically added
     // to the composition form
     if (is_array($value) && !empty($this->_options)) {
         foreach ($value as $v) {
             for ($i = 0, $optCount = count($this->_options); $i < $optCount; $i++) {
                 // Passed values are compound - look for recipient type
                 $explodedValue = explode("#", $v);
                 if ($v == $this->_options[$i]['attr']['value'] || $explodedValue[0] === 'add') {
                     $cleanValues[] = $v;
                     // Dynamically added contacts must be persisted
                     // to the internal options array. After this point,
                     // the form will consider them to be valid and treat them
                     // as any other option in the form. Hurrah!
                     if ($explodedValue[0] === 'add') {
                         $this->_options[] = array('text' => MoodletxtStringHelper::formatNameForDisplay($explodedValue[3], $explodedValue[2], null, null, null, $explodedValue[1]), 'attr' => array('value' => $v));
                     }
                     break;
                 }
             }
         }
     } else {
         $cleanValues = $value;
     }
     if (is_array($cleanValues) && !$this->getMultiple()) {
         return $this->_prepareValue($cleanValues[0], $assoc);
     } else {
         return $this->_prepareValue($cleanValues, $assoc);
     }
 }
Esempio n. 3
0
             if (MoodletxtStringHelper::isIntegerValue($valuefrags[1])) {
                 array_push($moodleUsers, $valuefrags[1]);
             }
             break;
         case 'ug':
             if (MoodletxtStringHelper::isIntegerValue($valuefrags[1])) {
                 array_push($moodleUserGroups, $valuefrags[1]);
             }
             break;
         case 'ab':
             if (MoodletxtStringHelper::isIntegerValue($valuefrags[1])) {
                 array_push($addressBookContacts, $valuefrags[1]);
             }
             break;
         case 'abg':
             if (MoodletxtStringHelper::isIntegerValue($valuefrags[1])) {
                 array_push($addressBookGroups, $valuefrags[1]);
             }
             break;
         case 'add':
             $additionalContacts[$valuefrags[1]] = new MoodletxtAdditionalRecipient(new MoodletxtPhoneNumber($valuefrags[1]), $valuefrags[3], $valuefrags[2]);
             break;
         default:
             continue;
     }
 }
 // Build destination list, indexed by phone number to prevent duplicates
 // Fetch additional contacts first (lowest priority for linking)
 $destinations += $additionalContacts;
 // Addressbook contacts and groups next
 if (count($addressBookGroups) > 0) {
Esempio n. 4
0
    // Put tags into single string
    $tagString = '';
    if ($table->is_downloading()) {
        foreach ($message->getTags() as $tag) {
            if ($tagString != '') {
                $tagString .= ', ';
            }
            $tagString .= $tag->getName();
        }
    } else {
        foreach ($message->getTags() as $tag) {
            $tagString .= html_writer::tag('span', $tag->getName(), array('class' => 'mtxtAppliedTag'));
        }
    }
    array_push($tableRow, $tagString);
    if (!$table->is_downloading()) {
        array_push($tableRow, $output->render($tagButton) . $output->render($deleteButton) . $replyLink);
    }
    // Turn tag names into CSS classes
    $classString = '';
    foreach ($message->getTags() as $tag) {
        $classString .= ' ' . MoodletxtStringHelper::convertToValidCSSIdentifier($tag->getName());
    }
    $table->add_data($tableRow, $classString);
}
// Output everything and run away
$table->finish_output();
if (!$table->is_downloading()) {
    $inboxForm->display();
    echo $output->footer();
}
 /**
  * Returns the recipients full name, formatted for screen display
  * @return string Recipient's full name, display formatted
  * @version 2013052301
  * @since 2012031401
  */
 public function getFullNameForDisplay($linkifyUsername = false)
 {
     $userId = $linkifyUsername ? $this->getId() : 0;
     return MoodletxtStringHelper::formatNameForDisplay($this->getFirstName(), $this->getLastName(), $this->getUsername(), null, $userId);
 }
Esempio n. 6
0
 /**
  * Returns a full-name string to be used
  * in page table displays
  * @return string Recipient's full name, display formatted
  * @version 2013052301
  * @since 2010082001
  */
 public function getFullNameForDisplay()
 {
     return MoodletxtStringHelper::formatNameForDisplay($this->getFirstName(), $this->getLastName());
 }
Esempio n. 7
0
 /**
  * Build text message blocks.
  * Method builds the individual <Message> blocks to be included in the message being built.
  * These blocks are cached into an array, then compiled into <Request> blocks later on.
  * @param MoodletxtOutboundMessage $message The message object to base the block on
  * @version 2013080801
  * @since 2010090101
  */
 private function buildTextMessageBlocks(MoodletxtOutboundMessage $message)
 {
     $messageRecipients = $message->getMessageRecipients();
     // Loop over recipients and create message blocks
     foreach ($messageRecipients as $recipientKey => $recipient) {
         if (!$recipient->getRecipientNumber() instanceof MoodletxtPhoneNumber) {
             continue;
         }
         $messageText = trim(stripslashes($message->getMessageText()));
         $messageText = MoodletxtStringHelper::mergeTagsIntoMessageText($messageText, $recipient);
         // Chunk message text into blocks of 160 chars
         $messagechunks = str_split($messageText, 160);
         // Build message blocks
         foreach ($messagechunks as $chunk) {
             // Code written this way so the output is all nice and formatted
             $messageBlock = '
 ' . MoodletxtXMLConstants::$REQUEST_MESSAGE_BLOCK . '
     ' . MoodletxtXMLConstants::$REQUEST_MESSAGE_TEXT . $chunk . MoodletxtXMLConstants::$_REQUEST_MESSAGE_TEXT . '
     ' . MoodletxtXMLConstants::$REQUEST_MESSAGE_PHONE . $recipient->getRecipientNumber()->getPhoneNumber() . MoodletxtXMLConstants::$_REQUEST_MESSAGE_PHONE . '
     ' . MoodletxtXMLConstants::$REQUEST_MESSAGE_TYPE . $message->getType() . MoodletxtXMLConstants::$_REQUEST_MESSAGE_TYPE . '
     ' . MoodletxtXMLConstants::$REQUEST_MESSAGE_UNIQUE_ID . $recipientKey . MoodletxtXMLConstants::$_REQUEST_MESSAGE_UNIQUE_ID;
             // Add scheduled send time if specified
             $messageBlock .= $message->getScheduledTime() > $message->getTimeSent() ? '
     ' . MoodletxtXMLConstants::$REQUEST_MESSAGE_SCHEDULE_DATE . $message->getScheduledTime() . MoodletxtXMLConstants::$_REQUEST_MESSAGE_SCHEDULE_DATE : '';
             // Add UTF-8 suppression if specified
             $messageBlock .= $message->isSuppressUnicode() ? '
     ' . MoodletxtXMLConstants::$REQUEST_MESSAGE_SUPPRESS_UNICODE : '';
             $messageBlock .= '
 ' . MoodletxtXMLConstants::$_REQUEST_MESSAGE_BLOCK;
             $this->addRequestBlock($messageBlock);
         }
     }
 }
 /**
  * Gets the message source's name, formatted for display
  * @return string Formatted source name
  * @version 2013052301
  * @since 2012042401
  */
 public function getSourceNameForDisplay()
 {
     if ($this->associatedSource instanceof MoodletxtRecipient) {
         return $this->associatedSource->getFullNameForDisplay();
     } else {
         return MoodletxtStringHelper::formatNameForDisplay($this->getSourceFirstName(), $this->getSourceLastName());
     }
 }
Esempio n. 9
0
        }
        $errorText .= html_writer::tag('ul', $errorSet);
    } else {
        $errorText = get_string('errorconndefault', 'block_moodletxt');
    }
    echo $errorText;
}
// Populate table
foreach ($messageObject->getSentSMSMessages() as $message) {
    $recipient = $message->getRecipientObject();
    // Save on making this call
    // Create contact name string for display
    if ($recipient instanceof MoodletxtBiteSizedUser && !$table->is_downloading()) {
        $displayName = $recipient->getFullNameForDisplay(true);
    } else {
        $displayName = $recipient->getFullNameForDisplay();
    }
    $latestStatus = array_pop($message->getStatusUpdates());
    if ($table->is_downloading()) {
        $statusCell = $latestStatus->getStatus() . ' - ' . MoodletxtStringHelper::getLanguageStringForStatusCode($latestStatus->getStatus());
    } else {
        $statusCell = $output->render(MoodletxtStatusIconFactory::generateStatusIconForCode($latestStatus->getStatus()));
    }
    // Add data set to the table
    $table->add_data(array($displayName, $recipient->getRecipientNumber()->getPhoneNumber(), userdate($latestStatus->getUpdateTime(), "%H:%M:%S,  %d %B %Y"), $statusCell));
}
// Finally, output everything!
$table->finish_output();
if (!$table->is_downloading()) {
    echo $output->footer();
}