Exemple #1
0
 /**
  * Constructor
  *
  * Sets up and retrieves the API objects
  *
  **/
 public function __construct($company, $user, $course, $invoice, $classroom, $license, $sender, $approveuser)
 {
     $this->company =& $company;
     $this->user =& $user;
     $this->invoice =& $invoice;
     $this->classroom =& $classroom;
     $this->license =& $license;
     $this->sender =& $sender;
     $this->approveuser =& $approveuser;
     if (!isset($this->company)) {
         if (isset($user->id) && !isset($user->profile)) {
             profile_load_custom_fields($this->user);
         }
         if (isset($user->profile["company"])) {
             $this->company = company::by_shortname($this->user->profile["company"])->get('*');
         }
     }
     $this->course =& $course;
     if (!empty($course->id)) {
         $this->course->url = new moodle_url('/course/view.php', array('id' => $this->course->id));
     }
     if (!empty($user->id)) {
         $this->url = new moodle_url('/user/profile.php', array('id' => $this->user->id));
     }
     $this->site = get_site();
 }
function html_header($course, $wdir, $formfield = "")
{
    global $CFG, $ME, $choose;
    if (!($site = get_site())) {
        error("Invalid site!");
    }
    $strfiles = get_string("coursefiles", 'wiki');
    if ($wdir == "/") {
        $fullnav = "{$strfiles}";
    } else {
        $dirs = explode("/", $wdir);
        $numdirs = count($dirs);
        $link = "";
        $navigation = "";
        for ($i = 1; $i < $numdirs - 1; $i++) {
            $navigation .= " -> ";
            $link .= "/" . urlencode($dirs[$i]);
            $navigation .= "<a href=\"" . $ME . "?id={$course->id}&amp;wdir={$link}&amp;choose={$choose}\">" . $dirs[$i] . "</a>";
        }
        $fullnav = "<a href=\"" . $ME . "?id={$course->id}&amp;wdir=/&amp;choose={$choose}\">{$strfiles}</a> {$navigation} -> " . $dirs[$numdirs - 1];
    }
    if ($choose) {
        print_header();
        $chooseparts = explode('.', $choose);
        ?>
        <script language="javascript" type="text/javascript">
        <!--
        function set_value(txt) {
            opener.document.forms['<?php 
        echo $chooseparts[0] . "']." . $chooseparts[1];
        ?>
.value = txt;
            window.close();
        }
        -->
        </script>

        <?php 
        $fullnav = str_replace('->', '&raquo;', "{$course->shortname} -> {$fullnav}");
        echo '<div id="nav-bar">' . $fullnav . '</div>';
        if ($course->id == $site->id) {
            print_heading(get_string("publicsitefileswarning"), "center", 2);
        }
    } else {
        if ($course->id == $site->id) {
            print_header("{$course->shortname}: {$strfiles}", "{$course->fullname}", "<a href=\"../index.php?id={$course->id}\">" . get_string("modulenameplural", 'wiki') . "</a> -> {$fullnav}", $formfield);
            print_heading(get_string("publicsitefileswarning"), "center", 2);
        } else {
            print_header("{$course->shortname}: {$strfiles}", "{$course->fullname}", "<a href=\"../../../course/view.php?id={$course->id}\">{$course->shortname}" . "</a> -> <a href=\"../index.php?id={$course->id}\">" . get_string("modulenameplural", 'wiki') . "</a> -> {$fullnav}", $formfield);
        }
    }
    $prop = null;
    $prop->border = "0";
    $prop->spacing = "3";
    $prop->padding = "3";
    $prop->width = "640";
    $prop->class = "boxaligncenter";
    $prop->colspantd = "2";
    wiki_table_start($prop);
}
Exemple #3
0
function xmldb_tool_bloglevelupgrade_install()
{
    global $CFG, $OUTPUT;
    // this is a hack - admins were long ago instructed to upgrade blog levels,
    // the problem is that blog is not supposed to be course level activity!!
    if (!empty($CFG->bloglevel_upgrade_complete)) {
        // somebody already upgrades, we do not need this any more
        unset_config('bloglevel_upgrade_complete');
        return;
    }
    if (!isset($CFG->bloglevel)) {
        // fresh install?
        return;
    }
    if ($CFG->bloglevel == BLOG_COURSE_LEVEL || $CFG->bloglevel == BLOG_GROUP_LEVEL) {
        // inform admins that some settings require attention after upgrade
        $site = get_site();
        $a = new StdClass();
        $a->sitename = $site->fullname;
        $a->fixurl = "{$CFG->wwwroot}/{$CFG->admin}/tool/bloglevelupgrade/index.php";
        $subject = get_string('bloglevelupgrade', 'tool_bloglevelupgrade');
        $description = get_string('bloglevelupgradedescription', 'tool_bloglevelupgrade', $a);
        // can not use messaging here because it is not configured yet!
        upgrade_log(UPGRADE_LOG_NOTICE, null, $subject, $description);
        set_config('tool_bloglevelupgrade_pending', 1);
        echo $OUTPUT->notification($description);
    }
}
 public function test_get_site_in_switched_state_returns_switched_site()
 {
     switch_to_blog(self::$site_ids['wordpress.org/foo/']);
     $site = get_site();
     restore_current_blog();
     $this->assertEquals(self::$site_ids['wordpress.org/foo/'], $site->id);
 }
Exemple #5
0
 /**
  * Tests that the filter applies the required changes.
  *
  * @return void
  */
 public function test_filter()
 {
     $this->resetAfterTest(true);
     $this->setAdminUser();
     filter_manager::reset_caches();
     filter_set_global_state('data', TEXTFILTER_ON);
     $course1 = $this->getDataGenerator()->create_course();
     $coursecontext1 = context_course::instance($course1->id);
     $course2 = $this->getDataGenerator()->create_course();
     $coursecontext2 = context_course::instance($course2->id);
     $sitecontext = context_course::instance(SITEID);
     $site = get_site();
     $this->add_simple_database_instance($site, array('SiteEntry'));
     $this->add_simple_database_instance($course1, array('CourseEntry'));
     $html = '<p>I like CourseEntry and SiteEntry</p>';
     // Testing at course level (both site and course).
     $filtered = format_text($html, FORMAT_HTML, array('context' => $coursecontext1));
     $this->assertRegExp('/title=(\'|")CourseEntry(\'|")/', $filtered);
     $this->assertRegExp('/title=(\'|")SiteEntry(\'|")/', $filtered);
     // Testing at site level (only site).
     $filtered = format_text($html, FORMAT_HTML, array('context' => $sitecontext));
     $this->assertNotRegExp('/title=(\'|")CourseEntry(\'|")/', $filtered);
     $this->assertRegExp('/title=(\'|")SiteEntry(\'|")/', $filtered);
     // Changing to another course to test the caches invalidation (only site).
     $filtered = format_text($html, FORMAT_HTML, array('context' => $coursecontext2));
     $this->assertNotRegExp('/title=(\'|")CourseEntry(\'|")/', $filtered);
     $this->assertRegExp('/title=(\'|")SiteEntry(\'|")/', $filtered);
 }
function html_header($course, $wdir, $formfield = "")
{
    global $CFG, $ME, $choose;
    if (!($site = get_site())) {
        error("Invalid site!");
    }
    if ($course->id == $site->id) {
        $strfiles = get_string("sitefiles");
    } else {
        $strfiles = get_string("files");
    }
    if ($wdir == "/") {
        $fullnav = "{$strfiles}";
    } else {
        $dirs = explode("/", $wdir);
        $numdirs = count($dirs);
        $link = "";
        $navigation = "";
        for ($i = 1; $i < $numdirs - 1; $i++) {
            $navigation .= " -> ";
            $link .= "/" . urlencode($dirs[$i]);
            $navigation .= "<a href=\"" . $ME . "?id={$course->id}&amp;wdir={$link}&amp;choose={$choose}\">" . $dirs[$i] . "</a>";
        }
        $fullnav = "<a href=\"" . $ME . "?id={$course->id}&amp;wdir=/&amp;choose={$choose}\">{$strfiles}</a> {$navigation} -> " . $dirs[$numdirs - 1];
    }
    if ($choose) {
        print_header();
        $chooseparts = explode('.', $choose);
        ?>
            <script language="javascript" type="text/javascript">
            <!--
            function set_value(txt) {
                opener.document.forms['<?php 
        echo $chooseparts[0] . "']." . $chooseparts[1];
        ?>
.value = txt;
                window.close();
            }
            -->
            </script>

            <?php 
        $fullnav = str_replace('->', '&raquo;', "{$course->shortname} -> {$fullnav}");
        echo '<div id="nav-bar">' . $fullnav . '</div>';
        if ($course->id == $site->id) {
            print_heading(get_string("publicsitefileswarning"), "center", 2);
        }
    } else {
        if ($course->id == $site->id) {
            print_header("{$course->shortname}: {$strfiles}", "{$course->fullname}", "<a href=\"../{$CFG->admin}/index.php\">" . get_string("administration") . "</a> -> {$fullnav}", $formfield);
            print_heading(get_string("publicsitefileswarning"), "center", 2);
        } else {
            print_header("{$course->shortname}: {$strfiles}", "{$course->fullname}", "<a href=\"../course/view.php?id={$course->id}\">{$course->shortname}" . "</a> -> {$fullnav}", $formfield);
        }
    }
    echo "<table border=\"0\" align=\"center\" cellspacing=\"3\" cellpadding=\"3\" width=\"640\">";
    echo "<tr>";
    echo "<td colspan=\"2\">";
}
 function config_read($name)
 {
     $site = get_site();
     if ($site->format == 'page') {
         return 1;
     } else {
         return 0;
     }
 }
Exemple #8
0
 /**
  * Authentication choice (CAS or other)
  * Redirection to the CAS form or to login/index.php
  * for other authentication
  */
 function loginpage_hook()
 {
     global $frm;
     global $CFG;
     global $SESSION, $OUTPUT, $PAGE;
     $site = get_site();
     $CASform = get_string('CASform', 'auth_cas');
     $username = optional_param('username', '', PARAM_RAW);
     if (!empty($username)) {
         if (isset($SESSION->wantsurl) && (strstr($SESSION->wantsurl, 'ticket') || strstr($SESSION->wantsurl, 'NOCAS'))) {
             unset($SESSION->wantsurl);
         }
         return;
     }
     // Return if CAS enabled and settings not specified yet
     if (empty($this->config->hostname)) {
         return;
     }
     // Connection to CAS server
     $this->connectCAS();
     if (phpCAS::checkAuthentication()) {
         $frm = new stdClass();
         $frm->username = phpCAS::getUser();
         $frm->password = '******';
         return;
     }
     if (isset($_GET['loginguest']) && $_GET['loginguest'] == true) {
         $frm = new stdClass();
         $frm->username = '******';
         $frm->password = '******';
         return;
     }
     if ($this->config->multiauth) {
         $authCAS = optional_param('authCAS', '', PARAM_RAW);
         if ($authCAS == 'NOCAS') {
             return;
         }
         // Show authentication form for multi-authentication
         // test pgtIou parameter for proxy mode (https connection
         // in background from CAS server to the php server)
         if ($authCAS != 'CAS' && !isset($_GET['pgtIou'])) {
             $PAGE->set_url('/auth/cas/auth.php');
             $PAGE->navbar->add($CASform);
             $PAGE->set_title("{$site->fullname}: {$CASform}");
             $PAGE->set_heading($site->fullname);
             echo $OUTPUT->header();
             include $CFG->dirroot . '/auth/cas/cas_form.html';
             echo $OUTPUT->footer();
             exit;
         }
     }
     // Force CAS authentication (if needed).
     if (!phpCAS::isAuthenticated()) {
         phpCAS::setLang($this->config->language);
         phpCAS::forceAuthentication();
     }
 }
 /**
  * Sets the parameters property of the extended class
  *
  * Sets the parameters property of the extended file resource class
  *
  * @param    USER  global object
  * @param    CFG   global object
  */
 function set_parameters()
 {
     global $USER, $CFG;
     $site = get_site();
     $this->parameters = array('label2' => array('langstr' => "", 'value' => '/optgroup'), 'label3' => array('langstr' => get_string('course'), 'value' => 'optgroup'), 'courseid' => array('langstr' => 'id', 'value' => $this->course->id), 'coursefullname' => array('langstr' => get_string('fullname'), 'value' => $this->course->fullname), 'courseshortname' => array('langstr' => get_string('shortname'), 'value' => $this->course->shortname), 'courseidnumber' => array('langstr' => get_string('idnumbercourse'), 'value' => $this->course->idnumber), 'coursesummary' => array('langstr' => get_string('summary'), 'value' => $this->course->summary), 'courseformat' => array('langstr' => get_string('format'), 'value' => $this->course->format), 'courseteacher' => array('langstr' => get_string('wordforteacher'), 'value' => $this->course->teacher), 'courseteachers' => array('langstr' => get_string('wordforteachers'), 'value' => $this->course->teachers), 'coursestudent' => array('langstr' => get_string('wordforstudent'), 'value' => $this->course->student), 'coursestudents' => array('langstr' => get_string('wordforstudents'), 'value' => $this->course->students), 'label4' => array('langstr' => "", 'value' => '/optgroup'), 'label5' => array('langstr' => get_string('miscellaneous'), 'value' => 'optgroup'), 'lang' => array('langstr' => get_string('preferredlanguage'), 'value' => current_language()), 'sitename' => array('langstr' => get_string('fullsitename'), 'value' => format_string($site->fullname)), 'serverurl' => array('langstr' => get_string('serverurl', 'resource', $CFG), 'value' => $CFG->wwwroot), 'currenttime' => array('langstr' => get_string('time'), 'value' => time()), 'encryptedcode' => array('langstr' => get_string('encryptedcode'), 'value' => $this->set_encrypted_parameter()), 'label6' => array('langstr' => "", 'value' => '/optgroup'));
     if (!empty($USER->id)) {
         $userparameters = array('label1' => array('langstr' => get_string('user'), 'value' => 'optgroup'), 'userid' => array('langstr' => 'id', 'value' => $USER->id), 'userusername' => array('langstr' => get_string('username'), 'value' => $USER->username), 'useridnumber' => array('langstr' => get_string('idnumber'), 'value' => $USER->idnumber), 'userfirstname' => array('langstr' => get_string('firstname'), 'value' => $USER->firstname), 'userlastname' => array('langstr' => get_string('lastname'), 'value' => $USER->lastname), 'userfullname' => array('langstr' => get_string('fullname'), 'value' => fullname($USER)), 'useremail' => array('langstr' => get_string('email'), 'value' => $USER->email), 'usericq' => array('langstr' => get_string('icqnumber'), 'value' => $USER->icq), 'userphone1' => array('langstr' => get_string('phone') . ' 1', 'value' => $USER->phone1), 'userphone2' => array('langstr' => get_string('phone') . ' 2', 'value' => $USER->phone2), 'userinstitution' => array('langstr' => get_string('institution'), 'value' => $USER->institution), 'userdepartment' => array('langstr' => get_string('department'), 'value' => $USER->department), 'useraddress' => array('langstr' => get_string('address'), 'value' => $USER->address), 'usercity' => array('langstr' => get_string('city'), 'value' => $USER->city), 'usertimezone' => array('langstr' => get_string('timezone'), 'value' => get_user_timezone_offset()), 'userurl' => array('langstr' => get_string('webpage'), 'value' => $USER->url));
         $this->parameters = $userparameters + $this->parameters;
     }
 }
Exemple #10
0
function saml_error($err, $urltogo = false, $logfile = '')
{
    global $CFG, $PAGE, $OUTPUT;
    if (!isset($CFG->debugdisplay) || !$CFG->debugdisplay) {
        $debug = false;
    } else {
        $debug = true;
    }
    if ($urltogo != false) {
        $site = get_site();
        if ($site === false || !isset($site->fullname)) {
            $site_name = '';
        } else {
            $site_name = $site->fullname;
        }
        $PAGE->set_title($site_name . ':Error SAML Login');
        echo $OUTPUT->header();
        echo '<div style="margin:20px;font-weight: bold; color: red;">';
    }
    if (is_array($err)) {
        foreach ($err as $key => $messages) {
            if (!is_array($messages)) {
                if ($urltogo != false && ($debug || $key == 'course_enrollment')) {
                    echo $messages;
                }
                $msg = 'Moodle SAML module: ' . $key . ': ' . $messages;
                log_saml_error($msg, $logfile);
            } else {
                foreach ($messages as $message) {
                    if ($urltogo != false && ($debug || $key == 'course_enrollment')) {
                        echo $message . '<br>';
                    }
                    $msg = 'Moodle SAML module: ' . $key . ': ' . $message;
                    log_saml_error($msg, $logfile);
                }
            }
            echo '<br>';
        }
    } else {
        if ($urltogo != false) {
            echo $err;
        }
        $msg = 'Moodle SAML module: login: '******'</div>';
        $OUTPUT->continue_button($urltogo);
        if ($debug) {
            print_string("auth_saml_disable_debugdisplay", "auth_saml");
        }
        $OUTPUT->footer();
        exit;
    }
}
 /**
  * Processes the message and sends a notification via airnotifier
  *
  * @param stdClass $eventdata the event data submitted by the message sender plus $eventdata->savedmessageid
  * @return true if ok, false if error
  */
 public function send_message($eventdata)
 {
     global $CFG;
     require_once $CFG->libdir . '/filelib.php';
     if (!empty($CFG->noemailever)) {
         // Hidden setting for development sites, set in config.php if needed.
         debugging('$CFG->noemailever active, no airnotifier message sent.', DEBUG_MINIMAL);
         return true;
     }
     // Skip any messaging suspended and deleted users.
     if ($eventdata->userto->auth === 'nologin' or $eventdata->userto->suspended or $eventdata->userto->deleted) {
         return true;
     }
     // Site id, to map with Moodle Mobile stored sites.
     $siteid = md5($CFG->wwwroot . $eventdata->userto->username);
     // Airnotifier can handle custom requests using processors (that are Airnotifier plugins).
     // In the extra parameter we indicate which processor to use and also additional data to be handled by the processor.
     // Here we clone the eventdata object because will be deleting/adding attributes.
     $extra = clone $eventdata;
     // Delete attributes that may content private information.
     if (!empty($eventdata->userfrom)) {
         $extra->userfromid = $eventdata->userfrom->id;
         $extra->userfromfullname = fullname($eventdata->userfrom);
         unset($extra->userfrom);
     }
     $extra->usertoid = $eventdata->userto->id;
     unset($extra->userto);
     $extra->processor = 'moodle';
     $extra->site = $siteid;
     $extra->date = !empty($eventdata->timecreated) ? $eventdata->timecreated : time();
     $extra->notification = !empty($eventdata->notification) ? 1 : 0;
     // Site name.
     $site = get_site();
     $extra->sitefullname = format_string($site->fullname);
     $extra->siteshortname = format_string($site->shortname);
     // We are sending to message to all devices.
     $airnotifiermanager = new message_airnotifier_manager();
     $devicetokens = $airnotifiermanager->get_user_devices($CFG->airnotifiermobileappname, $eventdata->userto->id);
     foreach ($devicetokens as $devicetoken) {
         if (!$devicetoken->enable) {
             continue;
         }
         // Sending the message to the device.
         $serverurl = $CFG->airnotifierurl . ':' . $CFG->airnotifierport . '/api/v2/push/';
         $header = array('Accept: application/json', 'X-AN-APP-NAME: ' . $CFG->airnotifierappname, 'X-AN-APP-KEY: ' . $CFG->airnotifieraccesskey);
         $curl = new curl();
         $curl->setHeader($header);
         $params = array('device' => $devicetoken->platform, 'token' => $devicetoken->pushid, 'extra' => $extra);
         // JSON POST raw body request.
         $resp = $curl->post($serverurl, json_encode($params));
     }
     return true;
 }
 function print_header($title)
 {
     global $USER, $CFG;
     $replacements = array('%fullname%' => get_string('mycollaboration', 'local'));
     foreach ($replacements as $search => $replace) {
         $title = str_replace($search, $replace, $title);
     }
     $site = get_site();
     $nav = get_string('mycollaboration', 'local');
     $header = $site->shortname . ': ' . $nav;
     $navlinks = array(array('name' => $nav, 'link' => '', 'type' => 'misc'));
     $navigation = build_navigation($navlinks);
     print_header($title, $header, $navigation, '', '', true);
 }
Exemple #13
0
 function print_header($title)
 {
     global $USER;
     $replacements = array('%fullname%' => get_string('mymoodle', 'my'));
     foreach ($replacements as $search => $replace) {
         $title = str_replace($search, $replace, $title);
     }
     $site = get_site();
     $button = update_mymoodle_icon($USER->id);
     $nav = get_string('mymoodle', 'my');
     $header = $site->shortname . ': ' . $nav;
     $loggedinas = user_login_string($site);
     print_header($title, $header, $nav, '', '', true, $button, $loggedinas);
 }
 public function begin()
 {
     global $CFG, $USER;
     $txnId = time() . $this->_transaction->get_id();
     $site = get_site();
     // create the "Generate Request" XML message
     $xmlrequest = sprintf("<GenerateRequest>\n            \t<PxPayUserId>%s</PxPayUserId>\n            \t<PxPayKey>%s</PxPayKey>\n            \t<AmountInput>%.2f</AmountInput>\n            \t<CurrencyInput>%s</CurrencyInput>\n            \t<MerchantReference>%s</MerchantReference>\n            \t<EmailAddress>%s</EmailAddress>\n            \t<TxnData1>%d</TxnData1>\n            \t<TxnData2>%s</TxnData2>\n            \t<TxnData3>%s</TxnData3>\n            \t<TxnType>Purchase</TxnType>\n            \t<TxnId>%d</TxnId>\n            \t<BillingId></BillingId>\n            \t<EnableAddBillCard>0</EnableAddBillCard>\n            \t<UrlSuccess>%s</UrlSuccess>\n            \t<UrlFail>%s</UrlFail>\n            \t<Opt></Opt>\n            </GenerateRequest>", clean_param(get_config('local_moodec', 'payment_dps_userid'), PARAM_CLEAN), clean_param(get_config('local_moodec', 'payment_dps_key'), PARAM_CLEAN), clean_param($this->_transaction->get_cost(), PARAM_CLEAN), clean_param(get_config('local_moodec', 'currency'), PARAM_CLEAN), clean_param('Transaction #' . $this->_transaction->get_id(), PARAM_CLEAN), clean_param($USER->email, PARAM_CLEAN), clean_param($txnId, PARAM_CLEAN), clean_param(substr($site->shortname, 0, 50), PARAM_CLEAN), clean_param(substr("{$USER->lastname}, {$USER->firstname}", 0, 50), PARAM_CLEAN), clean_param(time() . $this->_transaction->get_id(), PARAM_CLEAN), new moodle_url($CFG->wwwroot . '/local/moodec/payment/dps/success.php'), new moodle_url($CFG->wwwroot . '/local/moodec/payment/dps/fail.php'));
     // Query DPS with the xml request
     $result = $this->query($xmlrequest);
     // Set the transaction gateway and status
     $this->_transaction->set_gateway(MOODEC_GATEWAY_DPS);
     $this->_transaction->set_txn_id($txnId);
     $this->_transaction->pending();
     // Return the DOM formatted result of the request
     return $this->get_dom($result);
 }
 /**
  * Find site by domain.
  *
  * @param  string $domain The domain to look for.
  *
  * @return \WP_Site|null
  */
 protected function find_site($domain)
 {
     if (empty($domain) || !is_string($domain)) {
         return;
     }
     // Get site by domain.
     if ($site = get_site_by_path($domain, '')) {
         return $site instanceof WP_Site ? $site : new WP_Site($site);
     }
     // Redirect to main site if no site is found.
     if ($site = get_site(1)) {
         $scheme = is_ssl() ? 'https' : 'http';
         $uri = sprintf('%s://%s', $scheme, $site->domain);
         header('Location: ' . $uri);
         die;
     }
 }
 public function execute()
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/mod/ratingallocate/locallib.php';
     $site = get_site();
     // parse customdata passed
     $customdata = $this->get_custom_data();
     $userid = $customdata->userid;
     $ratingallocateid = $customdata->ratingallocateid;
     //get instance of ratingallocate
     $ratingallocate = $DB->get_record(this_db\ratingallocate::TABLE, array(this_db\ratingallocate::ID => $ratingallocateid), '*', MUST_EXIST);
     $courseid = $ratingallocate->course;
     $course = get_course($courseid);
     $cm = get_coursemodule_from_instance('ratingallocate', $ratingallocate->id, $courseid);
     $context = \context_module::instance($cm->id);
     $ratingallocateobj = new \ratingallocate($ratingallocate, $course, $cm, $context);
     $ratingallocateobj->notify_users_distribution($userid);
 }
Exemple #17
0
/**
 * Emails admins about a clam outcome
 *
 * @param string $notice The body of the email to be sent.
 */
function clam_message_admins($notice)
{
    $site = get_site();
    $subject = get_string('clamemailsubject', 'moodle', format_string($site->fullname));
    $admins = get_admins();
    foreach ($admins as $admin) {
        $eventdata = new stdClass();
        $eventdata->component = 'moodle';
        $eventdata->name = 'errors';
        $eventdata->userfrom = get_admin();
        $eventdata->userto = $admin;
        $eventdata->subject = $subject;
        $eventdata->fullmessage = $notice;
        $eventdata->fullmessageformat = FORMAT_PLAIN;
        $eventdata->fullmessagehtml = '';
        $eventdata->smallmessage = '';
        message_send($eventdata);
    }
}
 /**
  * Form definition.
  */
 protected function definition()
 {
     global $DB;
     $mform = $this->_form;
     // Add student select box.
     $mform->addElement('select', 'users', 'Users', $DB->get_records_menu('user', array(), '', 'id,username'), array('class' => 'chosen', 'multiple' => 'multiple'));
     $mform->addRule('users', null, 'required', null, 'client');
     // Add student select box.
     $courses = $DB->get_records_menu('course', array(), '', 'id,CONCAT(shortname, \': \', fullname)');
     $mform->addElement('select', 'courses', 'Courses', $courses, array('class' => 'chosen', 'multiple' => 'multiple'));
     $mform->addRule('courses', null, 'required', null, 'client');
     unset($courses);
     // Add role select box.
     $course = get_site();
     $roles = get_assignable_roles(\context_course::instance($course->id));
     $mform->addElement('select', 'roleid', 'Role', $roles);
     $mform->addRule('roleid', null, 'required', null, 'client');
     $this->add_action_buttons(true, 'Enrol');
 }
function atom_standard_header($uniqueid, $link, $updated, $title = NULL, $description = NULL)
{
    global $CFG, $USER;
    static $pixpath = '';
    $status = true;
    $result = "";
    if (!($site = get_site())) {
        $status = false;
    }
    if ($status) {
        //Calculate title, link and description
        if (empty($title)) {
            $title = format_string($site->fullname);
        }
        //xml headers
        $result .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
        $result .= "<feed xmlns=\"http://www.w3.org/2005/Atom\">\n";
        //open the channel
        //write channel info
        $result .= atom_full_tag('id', 1, false, htmlspecialchars($uniqueid));
        $result .= atom_full_tag('updated', 1, false, date_format_rfc3339($updated));
        $result .= atom_full_tag('title', 1, false, htmlspecialchars(html_to_text($title)));
        $result .= atom_full_tag('link', 1, false, null, array('href' => $link, 'rel' => 'self'));
        if (!empty($description)) {
            $result .= atom_full_tag('subtitle', 1, false, $description);
        }
        $result .= atom_full_tag('generator', 1, false, 'Moodle');
        if (!empty($USER->lang)) {
            $result .= atom_full_tag('language', 1, false, substr($USER->lang, 0, 2));
        }
        $today = getdate();
        $result .= atom_full_tag('rights', 1, false, '&#169; ' . $today['year'] . ' ' . format_string($site->fullname));
        //write image info
        $atompix = $CFG->pixpath . "/i/rsssitelogo.gif";
        //write the info
        $result .= atom_full_tag('logo', 1, false, $atompix);
    }
    if (!$status) {
        return false;
    } else {
        return $result;
    }
}
/**
 * Checks status of current blog.
 *
 * Checks if the blog is deleted, inactive, archived, or spammed.
 *
 * Dies with a default message if the blog does not pass the check.
 *
 * To change the default message when a blog does not pass the check,
 * use the wp-content/blog-deleted.php, blog-inactive.php and
 * blog-suspended.php drop-ins.
 *
 * @since 3.0.0
 *
 * @return true|string Returns true on success, or drop-in file to include.
 */
function ms_site_check()
{
    /**
     * Filters checking the status of the current blog.
     *
     * @since 3.0.0
     *
     * @param bool null Whether to skip the blog status check. Default null.
     */
    $check = apply_filters('ms_site_check', null);
    if (null !== $check) {
        return true;
    }
    // Allow super admins to see blocked sites
    if (is_super_admin()) {
        return true;
    }
    $blog = get_site();
    if ('1' == $blog->deleted) {
        if (file_exists(WP_CONTENT_DIR . '/blog-deleted.php')) {
            return WP_CONTENT_DIR . '/blog-deleted.php';
        } else {
            wp_die(__('This site is no longer available.'), '', array('response' => 410));
        }
    }
    if ('2' == $blog->deleted) {
        if (file_exists(WP_CONTENT_DIR . '/blog-inactive.php')) {
            return WP_CONTENT_DIR . '/blog-inactive.php';
        } else {
            $admin_email = str_replace('@', ' AT ', get_site_option('admin_email', 'support@' . get_network()->domain));
            wp_die(sprintf(__('This site has not been activated yet. If you are having problems activating your site, please contact %s.'), sprintf('<a href="mailto:%s">%s</a>', $admin_email)));
        }
    }
    if ($blog->archived == '1' || $blog->spam == '1') {
        if (file_exists(WP_CONTENT_DIR . '/blog-suspended.php')) {
            return WP_CONTENT_DIR . '/blog-suspended.php';
        } else {
            wp_die(__('This site has been archived or suspended.'), '', array('response' => 410));
        }
    }
    return true;
}
function organizer_add_calendar()
{
    global $PAGE, $DB;
    $courseid = optional_param('course', SITEID, PARAM_INT);
    if ($courseid != SITEID && !empty($courseid)) {
        $course = $DB->get_record('course', array('id' => $courseid));
        $courses = array($course->id => $course);
        $issite = false;
    } else {
        $course = get_site();
        $courses = calendar_get_default_courses();
        $issite = true;
    }
    $now = usergetdate(time());
    $calendar = new calendar_information($now['mday'], $now['mon'], $now['year']);
    $calendar->prepare_for_view($course, $courses);
    $renderer = $PAGE->get_renderer('core_calendar');
    $calendar->add_sidecalendar_blocks($renderer, true, 'month');
    $PAGE->requires->js_init_call('M.mod_organizer.fix_calendar_styles');
}
    private function __app_reset_password_and_mail($user)
    {
        global $CFG;
        $site = get_site();
        $supportuser = generate_email_supportuser();
        $userauth = get_auth_plugin($user->auth);
        if (!$userauth->can_reset_password() or !is_enabled_auth($user->auth)) {
            trigger_error("Attempt to reset user password for user {$user->username} with Auth {$user->auth}.");
            return false;
        }
        $newpassword = generate_password();
        if (!$userauth->user_update_password($user, $newpassword)) {
            $error->error = true;
            $error->msg = 'fp_passwordgen_failure';
            echo json_encode($error);
            die;
        }
        $a = new stdClass();
        $a->firstname = $user->firstname;
        $a->lastname = $user->lastname;
        $a->sitename = format_string($site->fullname);
        $a->username = $user->username;
        $a->newpassword = $newpassword;
        //$a->signoff = generate_email_signoff();
        $message = 'Hi ' . $a->firstname . ',

Your account password at \'' . $a->sitename . '\' has been reset
and you have been issued with a new temporary password.

Your current login information is now:
   username: '******'
   password: '******'

Cheers from the \'' . $a->sitename . '\' administrator.';
        //$message = get_string('newpasswordtext', '', $a);
        $subject = format_string($site->fullname) . ': ' . get_string('changedpassword');
        unset_user_preference('create_password', $user);
        // prevent cron from generating the password
        //directly email rather than using the messaging system to ensure its not routed to a popup or jabber
        return email_to_user($user, $supportuser, $subject, $message);
    }
Exemple #23
0
 /**
  * Alerts site admin of potential problems.
  *
  * @param string   $subject email subject
  * @param stdClass $data    PayPal IPN data
  */
 public static function message_paypal_error_to_admin($subject, $data)
 {
     $admin = get_admin();
     $site = get_site();
     $message = "{$site->fullname}:  Transaction failed.\n\n{$subject}\n\n";
     foreach ($data as $key => $value) {
         $message .= "{$key} => {$value}\n";
     }
     $eventdata = new \stdClass();
     $eventdata->modulename = 'moodle';
     $eventdata->component = 'enrol_paypal';
     $eventdata->name = 'paypal_enrolment';
     $eventdata->userfrom = $admin;
     $eventdata->userto = $admin;
     $eventdata->subject = "PAYPAL ERROR: " . $subject;
     $eventdata->fullmessage = $message;
     $eventdata->fullmessageformat = FORMAT_PLAIN;
     $eventdata->fullmessagehtml = '';
     $eventdata->smallmessage = '';
     message_send($eventdata);
 }
/**
 * Library for Atom feeds, sort of like the system RSS library. (Originally
 * by Matt Clarkson from Catalyst.)
 * @package mod
 * @subpackage forumng
 * @copyright 2011 The Open University
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
function atom_standard_header($uniqueid, $link, $updated, $title = null, $description = null)
{
    global $CFG, $USER;
    $status = true;
    $result = "";
    if (!($site = get_site())) {
        $status = false;
    }
    if ($status) {
        // Calculate title, link and description.
        if (empty($title)) {
            $title = format_string($site->fullname);
        }
        // XML headers.
        $result .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
        $result .= "<feed xmlns=\"http://www.w3.org/2005/Atom\">\n";
        // Open the channel
        // write channel info.
        $result .= atom_full_tag('id', 1, false, htmlspecialchars($uniqueid));
        $result .= atom_full_tag('updated', 1, false, date_format_rfc3339($updated));
        $result .= atom_full_tag('title', 1, false, htmlspecialchars(html_to_text($title)));
        $result .= atom_full_tag('link', 1, false, null, array('href' => $link, 'rel' => 'self'));
        if (!empty($description)) {
            $result .= atom_full_tag('subtitle', 1, false, $description);
        }
        $result .= atom_full_tag('generator', 1, false, 'Moodle');
        $today = getdate();
        $result .= atom_full_tag('rights', 1, false, '&#169; ' . $today['year'] . ' ' . format_string($site->fullname));
        // Write image info.
        $out = mod_forumng_utils::get_renderer();
        $atompix = $out->pix_url('/i/rsssitelogo');
        // Write the info.
        $result .= atom_full_tag('logo', 1, false, $atompix);
    }
    if (!$status) {
        return false;
    } else {
        return $result;
    }
}
 /**
  * Sets the parameters property of the extended class
  *
  * @param    USER  global object
  * @param    CFG   global object
  */
 function set_parameters()
 {
     global $USER, $CFG;
     $site = get_site();
     $littlecfg = new object();
     // to avoid some notices later
     $littlecfg->wwwroot = $CFG->wwwroot;
     $courseparameters = array('label3' => array('langstr' => get_string('course'), 'value' => 'optgroup'), 'courseid' => array('langstr' => 'id', 'value' => $this->course->id), 'coursefullname' => array('langstr' => get_string('fullnamecourse'), 'value' => $this->course->fullname), 'courseshortname' => array('langstr' => get_string('shortnamecourse'), 'value' => $this->course->shortname), 'courseidnumber' => array('langstr' => get_string('idnumbercourse'), 'value' => $this->course->idnumber), 'coursesummary' => array('langstr' => get_string('summary'), 'value' => $this->course->summary), 'courseformat' => array('langstr' => get_string('format'), 'value' => $this->course->format));
     $roles = get_all_roles();
     $coursecontext = get_context_instance(CONTEXT_COURSE, $this->course->id);
     $roles = role_fix_names($roles, $coursecontext, ROLENAME_ALIAS);
     foreach ($roles as $role) {
         $courseparameters['course' . $role->shortname] = array('langstr' => get_string('yourwordforx', '', $role->name), 'value' => $role->localname);
     }
     $courseparameters['label4'] = array('langstr' => '', 'value' => '/optgroup');
     $miscparameters = array('label5' => array('langstr' => get_string('miscellaneous'), 'value' => 'optgroup'), 'lang' => array('langstr' => get_string('preferredlanguage'), 'value' => current_language()), 'sitename' => array('langstr' => get_string('fullsitename'), 'value' => format_string($site->fullname)), 'serverurl' => array('langstr' => get_string('serverurl', 'resource', $littlecfg), 'value' => $littlecfg->wwwroot), 'currenttime' => array('langstr' => get_string('time'), 'value' => time()), 'encryptedcode' => array('langstr' => get_string('encryptedcode'), 'value' => $this->set_encrypted_parameter()), 'label6' => array('langstr' => "", 'value' => '/optgroup'));
     $userparameters = array();
     if (!empty($USER->id)) {
         $userparameters = array('label1' => array('langstr' => get_string('user'), 'value' => 'optgroup'), 'userid' => array('langstr' => 'id', 'value' => $USER->id), 'userusername' => array('langstr' => get_string('username'), 'value' => $USER->username), 'useridnumber' => array('langstr' => get_string('idnumber'), 'value' => $USER->idnumber), 'userfirstname' => array('langstr' => get_string('firstname'), 'value' => $USER->firstname), 'userlastname' => array('langstr' => get_string('lastname'), 'value' => $USER->lastname), 'userfullname' => array('langstr' => get_string('fullnameuser'), 'value' => fullname($USER)), 'useremail' => array('langstr' => get_string('email'), 'value' => $USER->email), 'usericq' => array('langstr' => get_string('icqnumber'), 'value' => $USER->icq), 'userphone1' => array('langstr' => get_string('phone') . ' 1', 'value' => $USER->phone1), 'userphone2' => array('langstr' => get_string('phone2') . ' 2', 'value' => $USER->phone2), 'userinstitution' => array('langstr' => get_string('institution'), 'value' => $USER->institution), 'userdepartment' => array('langstr' => get_string('department'), 'value' => $USER->department), 'useraddress' => array('langstr' => get_string('address'), 'value' => $USER->address), 'usercity' => array('langstr' => get_string('city'), 'value' => $USER->city), 'usertimezone' => array('langstr' => get_string('timezone'), 'value' => get_user_timezone_offset()), 'userurl' => array('langstr' => get_string('webpage'), 'value' => $USER->url), 'label2' => array('langstr' => "", 'value' => '/optgroup'));
     }
     $this->parameters = array_merge($userparameters, $courseparameters, $miscparameters);
 }
Exemple #26
0
 function print_header($title)
 {
     global $USER, $CFG;
     $replacements = array('%fullname%' => get_string('mymoodle', 'my'));
     foreach ($replacements as $search => $replace) {
         $title = str_replace($search, $replace, $title);
     }
     $site = get_site();
     $button = update_mymoodle_icon($USER->id);
     $nav = get_string('mymoodle', 'my');
     $header = $site->shortname . ': ' . $nav;
     $navlinks = array(array('name' => $nav, 'link' => '', 'type' => 'misc'));
     $navigation = build_navigation($navlinks);
     $loggedinas = user_login_string($site);
     if (empty($CFG->langmenu)) {
         $langmenu = '';
     } else {
         $currlang = current_language();
         $langs = get_list_of_languages();
         $langlabel = get_accesshide(get_string('language'));
         $langmenu = popup_form($CFG->wwwroot . '/my/index.php?lang=', $langs, 'chooselang', $currlang, '', '', '', true, 'self', $langlabel);
     }
     print_header($title, $header, $navigation, '', '', true, $button, $loggedinas . $langmenu);
 }
Exemple #27
0
// Course id
$name = optional_param('name', false, PARAM_RAW);
// Course short name
if (!$id and !$name) {
    error("Must specify course id or short name");
}
if ($name) {
    if (!($course = get_record("course", "shortname", $name))) {
        error("That's an invalid short course name");
    }
} else {
    if (!($course = get_record("course", "id", $id))) {
        error("That's an invalid course id");
    }
}
$site = get_site();
if ($CFG->forcelogin) {
    require_login();
}
$context = get_context_instance(CONTEXT_COURSE, $course->id);
if ((!(course_parent_visible($course) && $CFG->allowvisiblecoursesinhiddencategories) || !$course->visible) && !has_capability('moodle/course:viewhiddencourses', $context)) {
    error(get_string('coursehidden'), $CFG->wwwroot . '/');
}
print_header(get_string("summaryof", "", $course->fullname));
print_heading(format_string($course->fullname) . '<br />(' . format_string($course->shortname) . ')');
if ($course->guest || $course->password) {
    print_box_start('generalbox icons');
    if ($course->guest) {
        $strallowguests = get_string('allowguests');
        echo "<div><img alt=\"\" class=\"icon guest\" src=\"{$CFG->pixpath}/i/guest.gif\" />&nbsp;{$strallowguests}</div>";
    }
 /**
  * Loads user specific information into the navigation in the appropriate place.
  *
  * If no user is provided the current user is assumed.
  *
  * @param stdClass $user
  * @param bool $forceforcontext probably force something to be loaded somewhere (ask SamH if not sure what this means)
  * @return bool
  */
 protected function load_for_user($user = null, $forceforcontext = false)
 {
     global $DB, $CFG, $USER, $SITE;
     if ($user === null) {
         // We can't require login here but if the user isn't logged in we don't
         // want to show anything
         if (!isloggedin() || isguestuser()) {
             return false;
         }
         $user = $USER;
     } else {
         if (!is_object($user)) {
             // If the user is not an object then get them from the database
             $select = context_helper::get_preload_record_columns_sql('ctx');
             $sql = "SELECT u.*, {$select}\n                      FROM {user} u\n                      JOIN {context} ctx ON u.id = ctx.instanceid\n                     WHERE u.id = :userid AND\n                           ctx.contextlevel = :contextlevel";
             $user = $DB->get_record_sql($sql, array('userid' => (int) $user, 'contextlevel' => CONTEXT_USER), MUST_EXIST);
             context_helper::preload_from_record($user);
         }
     }
     $iscurrentuser = $user->id == $USER->id;
     $usercontext = get_context_instance(CONTEXT_USER, $user->id);
     // Get the course set against the page, by default this will be the site
     $course = $this->page->course;
     $baseargs = array('id' => $user->id);
     if ($course->id != $SITE->id && (!$iscurrentuser || $forceforcontext)) {
         $coursenode = $this->load_course($course);
         $baseargs['course'] = $course->id;
         $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
         $issitecourse = false;
     } else {
         // Load all categories and get the context for the system
         $coursecontext = get_context_instance(CONTEXT_SYSTEM);
         $issitecourse = true;
     }
     // Create a node to add user information under.
     if ($iscurrentuser && !$forceforcontext) {
         // If it's the current user the information will go under the profile root node
         $usernode = $this->rootnodes['myprofile'];
         $course = get_site();
         $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
         $issitecourse = true;
     } else {
         if (!$issitecourse) {
             // Not the current user so add it to the participants node for the current course
             $usersnode = $coursenode->get('participants', navigation_node::TYPE_CONTAINER);
             $userviewurl = new moodle_url('/user/view.php', $baseargs);
         } else {
             // This is the site so add a users node to the root branch
             $usersnode = $this->rootnodes['users'];
             if (has_capability('moodle/course:viewparticipants', $coursecontext)) {
                 $usersnode->action = new moodle_url('/user/index.php', array('id' => $course->id));
             }
             $userviewurl = new moodle_url('/user/profile.php', $baseargs);
         }
         if (!$usersnode) {
             // We should NEVER get here, if the course hasn't been populated
             // with a participants node then the navigaiton either wasn't generated
             // for it (you are missing a require_login or set_context call) or
             // you don't have access.... in the interests of no leaking informatin
             // we simply quit...
             return false;
         }
         // Add a branch for the current user
         $canseefullname = has_capability('moodle/site:viewfullnames', $coursecontext);
         $usernode = $usersnode->add(fullname($user, $canseefullname), $userviewurl, self::TYPE_USER, null, $user->id);
         if ($this->page->context->contextlevel == CONTEXT_USER && $user->id == $this->page->context->instanceid) {
             $usernode->make_active();
         }
     }
     // If the user is the current user or has permission to view the details of the requested
     // user than add a view profile link.
     if ($iscurrentuser || has_capability('moodle/user:viewdetails', $coursecontext) || has_capability('moodle/user:viewdetails', $usercontext)) {
         if ($issitecourse || $iscurrentuser && !$forceforcontext) {
             $usernode->add(get_string('viewprofile'), new moodle_url('/user/profile.php', $baseargs));
         } else {
             $usernode->add(get_string('viewprofile'), new moodle_url('/user/view.php', $baseargs));
         }
     }
     if (!empty($CFG->navadduserpostslinks)) {
         // Add nodes for forum posts and discussions if the user can view either or both
         // There are no capability checks here as the content of the page is based
         // purely on the forums the current user has access too.
         $forumtab = $usernode->add(get_string('forumposts', 'forum'));
         $forumtab->add(get_string('posts', 'forum'), new moodle_url('/mod/forum/user.php', $baseargs));
         $forumtab->add(get_string('discussions', 'forum'), new moodle_url('/mod/forum/user.php', array_merge($baseargs, array('mode' => 'discussions'))));
     }
     // Add blog nodes
     if (!empty($CFG->bloglevel)) {
         if (!$this->cache->cached('userblogoptions' . $user->id)) {
             require_once $CFG->dirroot . '/blog/lib.php';
             // Get all options for the user
             $options = blog_get_options_for_user($user);
             $this->cache->set('userblogoptions' . $user->id, $options);
         } else {
             $options = $this->cache->{'userblogoptions' . $user->id};
         }
         if (count($options) > 0) {
             $blogs = $usernode->add(get_string('blogs', 'blog'), null, navigation_node::TYPE_CONTAINER);
             foreach ($options as $type => $option) {
                 if ($type == "rss") {
                     $blogs->add($option['string'], $option['link'], settings_navigation::TYPE_SETTING, null, null, new pix_icon('i/rss', ''));
                 } else {
                     $blogs->add($option['string'], $option['link']);
                 }
             }
         }
     }
     if (!empty($CFG->messaging)) {
         $messageargs = null;
         if ($USER->id != $user->id) {
             $messageargs = array('id' => $user->id);
         }
         $url = new moodle_url('/message/index.php', $messageargs);
         $usernode->add(get_string('messages', 'message'), $url, self::TYPE_SETTING, null, 'messages');
     }
     $context = get_context_instance(CONTEXT_USER, $USER->id);
     if ($iscurrentuser && has_capability('moodle/user:manageownfiles', $context)) {
         $url = new moodle_url('/user/files.php');
         $usernode->add(get_string('myfiles'), $url, self::TYPE_SETTING);
     }
     // Add a node to view the users notes if permitted
     if (!empty($CFG->enablenotes) && has_any_capability(array('moodle/notes:manage', 'moodle/notes:view'), $coursecontext)) {
         $url = new moodle_url('/notes/index.php', array('user' => $user->id));
         if ($coursecontext->instanceid) {
             $url->param('course', $coursecontext->instanceid);
         }
         $usernode->add(get_string('notes', 'notes'), $url);
     }
     // Add reports node
     $reporttab = $usernode->add(get_string('activityreports'));
     $reports = get_plugin_list_with_function('report', 'extend_navigation_user', 'lib.php');
     foreach ($reports as $reportfunction) {
         $reportfunction($reporttab, $user, $course);
     }
     $anyreport = has_capability('moodle/user:viewuseractivitiesreport', $usercontext);
     if ($anyreport || $course->showreports && $iscurrentuser && $forceforcontext) {
         // Add grade hardcoded grade report if necessary
         $gradeaccess = false;
         if (has_capability('moodle/grade:viewall', $coursecontext)) {
             //ok - can view all course grades
             $gradeaccess = true;
         } else {
             if ($course->showgrades) {
                 if ($iscurrentuser && has_capability('moodle/grade:view', $coursecontext)) {
                     //ok - can view own grades
                     $gradeaccess = true;
                 } else {
                     if (has_capability('moodle/grade:viewall', $usercontext)) {
                         // ok - can view grades of this user - parent most probably
                         $gradeaccess = true;
                     } else {
                         if ($anyreport) {
                             // ok - can view grades of this user - parent most probably
                             $gradeaccess = true;
                         }
                     }
                 }
             }
         }
         if ($gradeaccess) {
             $reporttab->add(get_string('grade'), new moodle_url('/course/user.php', array('mode' => 'grade', 'id' => $course->id, 'user' => $usercontext->instanceid)));
         }
     }
     // Check the number of nodes in the report node... if there are none remove the node
     $reporttab->trim_if_empty();
     // If the user is the current user add the repositories for the current user
     $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields));
     if ($iscurrentuser) {
         if (!$this->cache->cached('contexthasrepos' . $usercontext->id)) {
             require_once $CFG->dirroot . '/repository/lib.php';
             $editabletypes = repository::get_editable_types($usercontext);
             $haseditabletypes = !empty($editabletypes);
             unset($editabletypes);
             $this->cache->set('contexthasrepos' . $usercontext->id, $haseditabletypes);
         } else {
             $haseditabletypes = $this->cache->{'contexthasrepos' . $usercontext->id};
         }
         if ($haseditabletypes) {
             $usernode->add(get_string('repositories', 'repository'), new moodle_url('/repository/manage_instances.php', array('contextid' => $usercontext->id)));
         }
     } else {
         if ($course->id == $SITE->id && has_capability('moodle/user:viewdetails', $usercontext) && (!in_array('mycourses', $hiddenfields) || has_capability('moodle/user:viewhiddendetails', $coursecontext))) {
             // Add view grade report is permitted
             $reports = get_plugin_list('gradereport');
             arsort($reports);
             // user is last, we want to test it first
             $userscourses = enrol_get_users_courses($user->id);
             $userscoursesnode = $usernode->add(get_string('courses'));
             foreach ($userscourses as $usercourse) {
                 $usercoursecontext = get_context_instance(CONTEXT_COURSE, $usercourse->id);
                 $usercourseshortname = format_string($usercourse->shortname, true, array('context' => $usercoursecontext));
                 $usercoursenode = $userscoursesnode->add($usercourseshortname, new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $usercourse->id)), self::TYPE_CONTAINER);
                 $gradeavailable = has_capability('moodle/grade:viewall', $usercoursecontext);
                 if (!$gradeavailable && !empty($usercourse->showgrades) && is_array($reports) && !empty($reports)) {
                     foreach ($reports as $plugin => $plugindir) {
                         if (has_capability('gradereport/' . $plugin . ':view', $usercoursecontext)) {
                             //stop when the first visible plugin is found
                             $gradeavailable = true;
                             break;
                         }
                     }
                 }
                 if ($gradeavailable) {
                     $url = new moodle_url('/grade/report/index.php', array('id' => $usercourse->id));
                     $usercoursenode->add(get_string('grades'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/grades', ''));
                 }
                 // Add a node to view the users notes if permitted
                 if (!empty($CFG->enablenotes) && has_any_capability(array('moodle/notes:manage', 'moodle/notes:view'), $usercoursecontext)) {
                     $url = new moodle_url('/notes/index.php', array('user' => $user->id, 'course' => $usercourse->id));
                     $usercoursenode->add(get_string('notes', 'notes'), $url, self::TYPE_SETTING);
                 }
                 if (can_access_course($usercourse, $user->id)) {
                     $usercoursenode->add(get_string('entercourse'), new moodle_url('/course/view.php', array('id' => $usercourse->id)), self::TYPE_SETTING, null, null, new pix_icon('i/course', ''));
                 }
                 $reporttab = $usercoursenode->add(get_string('activityreports'));
                 $reports = get_plugin_list_with_function('report', 'extend_navigation_user', 'lib.php');
                 foreach ($reports as $reportfunction) {
                     $reportfunction($reporttab, $user, $usercourse);
                 }
                 $reporttab->trim_if_empty();
             }
         }
     }
     return true;
 }
$subscriptionid = optional_param('id', 0, PARAM_INT);
$pollinterval = optional_param('pollinterval', 0, PARAM_INT);
$action = optional_param('action', '', PARAM_ALPHA);
$url = new moodle_url('/calendar/managesubscriptions.php');
if ($courseid != SITEID) {
    $url->param('course', $courseid);
}
navigation_node::override_active_url(new moodle_url('/calendar/view.php', array('view' => 'month')));
$PAGE->set_url($url);
$PAGE->set_pagelayout('standard');
$PAGE->navbar->add(get_string('managesubscriptions', 'calendar'));
if ($courseid != SITEID && !empty($courseid)) {
    $course = $DB->get_record('course', array('id' => $courseid));
    $courses = array($course->id => $course);
} else {
    $course = get_site();
    $courses = calendar_get_default_courses();
}
require_course_login($course);
if (!calendar_user_can_add_event($course)) {
    print_error('errorcannotimport', 'calendar');
}
$form = new calendar_addsubscription_form(null);
$form->set_data(array('course' => $course->id));
$importresults = '';
$formdata = $form->get_data();
if (!empty($formdata)) {
    require_sesskey();
    // Must have sesskey for all actions.
    $subscriptionid = calendar_add_subscription($formdata);
    if ($formdata->importfrom == CALENDAR_IMPORT_FROM_FILE) {
Exemple #30
0
/**
 * Lockout user and send notification email.
 *
 * @param stdClass $user
 */
function login_lock_account($user)
{
    global $CFG;
    if ($user->mnethostid != $CFG->mnet_localhost_id) {
        return;
    }
    if (isguestuser($user)) {
        return;
    }
    if (get_user_preferences('login_lockout_ignored', 0, $user)) {
        // This user can not be locked out.
        return;
    }
    $alreadylockedout = get_user_preferences('login_lockout', 0, $user);
    set_user_preference('login_lockout', time(), $user);
    if ($alreadylockedout == 0) {
        $secret = random_string(15);
        set_user_preference('login_lockout_secret', $secret, $user);
        $oldforcelang = force_current_language($user->lang);
        $site = get_site();
        $supportuser = core_user::get_support_user();
        $data = new stdClass();
        $data->firstname = $user->firstname;
        $data->lastname = $user->lastname;
        $data->username = $user->username;
        $data->sitename = format_string($site->fullname);
        $data->link = $CFG->wwwroot . '/login/unlock_account.php?u=' . $user->id . '&s=' . $secret;
        $data->admin = generate_email_signoff();
        $message = get_string('lockoutemailbody', 'admin', $data);
        $subject = get_string('lockoutemailsubject', 'admin', format_string($site->fullname));
        if ($message) {
            // Directly email rather than using the messaging system to ensure its not routed to a popup or jabber.
            email_to_user($user, $supportuser, $subject, $message);
        }
        force_current_language($oldforcelang);
    }
}