/**
  * Gets all txttools accounts stored within moodletxt
  * @global type $DB Moodle database manager
  * @param boolean $includeRestrictions Turn this off if restrictions aren't needed to speed up fetch
  * @param boolean $includeFilters Turn this off if filters aren't needed to speed up fetch
  * @return TxttoolsAccount[] All accounts found
  * @version 2012073101
  * @since 2011060801
  */
 public function getAllTxttoolsAccounts($includeRestrictions = true, $includeFilters = true, $checkActiveOutbound = false, $checkActiveInbound = false)
 {
     global $DB;
     $params = array();
     $sql = 'SELECT accounts.*, usertable.firstname, usertable.lastname, 
             usertable.username AS defaultusername
             FROM {block_moodletxt_accounts} accounts
             INNER JOIN {user} usertable
                 ON accounts.defaultuser = usertable.id';
     if ($checkActiveOutbound) {
         $sql .= strpos($sql, 'WHERE') > 0 ? ' AND' : ' WHERE';
         $sql .= ' accounts.outboundenabled = 1';
     }
     if ($checkActiveInbound) {
         $sql .= strpos($sql, 'WHERE') > 0 ? ' AND' : ' WHERE';
         $sql .= ' accounts.inboundenabled = 1';
     }
     $sql .= ' ORDER BY accounts.username ASC';
     $returnArray = array();
     $rawRecords = $DB->get_records_sql($sql, $params);
     foreach ($rawRecords as $rawRecord) {
         $txttoolsAccount = $this->convertStandardClassToBean($rawRecord);
         if ($includeRestrictions) {
             $txttoolsAccount = $this->getAllowedUsersForAccount($txttoolsAccount);
         }
         if ($includeFilters) {
             $txttoolsAccount = $this->filterDAO->getFiltersForAccount($txttoolsAccount);
         }
         $returnArray[$txttoolsAccount->getId()] = $txttoolsAccount;
     }
     return $returnArray;
 }
 /**
  * Gets full details of an inbound filter
  * @param int $filterId ID of filter to fetch
  * @return string JSON response
  * @version 2011071101
  * @since 2011071101
  */
 private function getFilterDetails($filterId)
 {
     $inboundFilter = $this->filterDAO->getFilterById($filterId);
     // Account must exist within system
     if (!is_object($inboundFilter)) {
         throw new MoodletxtAJAXException(get_string('errorinvalidaccountid', 'block_moodletxt'), MoodletxtAJAXException::$ERROR_CODE_BAD_ACCOUNT_ID, null, false);
     }
     return $this->buildResponse($inboundFilter);
 }
 /**
  * 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;
 }
Example #4
0
 * @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');
$PAGE->requires->jquery();