示例#1
0
 /**
  * Prints or returns the HTML for this blog entry.
  *
  * @param bool $return
  * @return string
  */
 public function print_html($return = false)
 {
     global $USER, $CFG, $COURSE, $DB, $OUTPUT, $PAGE;
     $user = $DB->get_record('user', array('id' => $this->userid));
     $cmttext = '';
     if (!empty($CFG->usecomments) and $CFG->blogusecomments) {
         require_once $CFG->dirroot . '/comment/lib.php';
         // Comments
         $cmt = new stdClass();
         $cmt->context = get_context_instance(CONTEXT_USER, $user->id);
         $cmt->courseid = $PAGE->course->id;
         $cmt->area = 'format_blog';
         $cmt->itemid = $this->id;
         $cmt->showcount = $CFG->blogshowcommentscount;
         $cmt->component = 'blog';
         $comment = new comment($cmt);
         $cmttext = $comment->output(true);
     }
     $this->summary = file_rewrite_pluginfile_urls($this->summary, 'pluginfile.php', SYSCONTEXTID, 'blog', 'post', $this->id);
     $options = array('overflowdiv' => true);
     $template['body'] = format_text($this->summary, $this->summaryformat, $options) . $cmttext;
     $template['title'] = format_string($this->subject);
     $template['userid'] = $user->id;
     $template['author'] = fullname($user);
     $template['created'] = userdate($this->created);
     if ($this->created != $this->lastmodified) {
         $template['lastmod'] = userdate($this->lastmodified);
     }
     $template['publishstate'] = $this->publishstate;
     $stredit = get_string('edit');
     $strdelete = get_string('delete');
     // Check to see if the entry is unassociated with group/course level access
     $unassociatedentry = false;
     if (!empty($CFG->useblogassociations) && ($this->publishstate == 'group' || $this->publishstate == 'course')) {
         if (!$DB->record_exists('blog_association', array('blogid' => $this->id))) {
             $unassociatedentry = true;
         }
     }
     // Start printing of the blog
     $table = new html_table();
     $table->cellspacing = 0;
     $table->attributes['class'] = 'forumpost blog_entry blog' . ($unassociatedentry ? 'draft' : $template['publishstate']);
     $table->attributes['id'] = 'b' . $this->id;
     $table->width = '100%';
     $picturecell = new html_table_cell();
     $picturecell->attributes['class'] = 'picture left';
     $picturecell->text = $OUTPUT->user_picture($user);
     $table->head[] = $picturecell;
     $topiccell = new html_table_cell();
     $topiccell->attributes['class'] = 'topic starter';
     $titlelink = html_writer::link(new moodle_url('/blog/index.php', array('entryid' => $this->id)), $template['title']);
     $topiccell->text = $OUTPUT->container($titlelink, 'subject');
     $topiccell->text .= $OUTPUT->container_start('author');
     $fullname = fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $PAGE->course->id)));
     $by = new stdClass();
     $by->name = html_writer::link(new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $PAGE->course->id)), $fullname);
     $by->date = $template['created'];
     $topiccell->text .= get_string('bynameondate', 'forum', $by);
     $topiccell->text .= $OUTPUT->container_end();
     if ($this->uniquehash && $this->content) {
         if ($externalblog = $DB->get_record('blog_external', array('id' => $this->content))) {
             $urlparts = parse_url($externalblog->url);
             $topiccell->text .= $OUTPUT->container(get_string('retrievedfrom', 'blog') . get_string('labelsep', 'langconfig') . html_writer::link($urlparts['scheme'] . '://' . $urlparts['host'], $externalblog->name), 'externalblog');
         }
     }
     $topiccell->header = false;
     $table->head[] = $topiccell;
     // Actual content
     $mainrow = new html_table_row();
     $leftsidecell = new html_table_cell();
     $leftsidecell->attributes['class'] = 'left side';
     $mainrow->cells[] = $leftsidecell;
     $contentcell = new html_table_cell();
     $contentcell->attributes['class'] = 'content';
     $attachedimages = $OUTPUT->container($this->print_attachments(), 'attachments');
     // retrieve associations in case they're needed early
     $blogassociations = $DB->get_records('blog_association', array('blogid' => $this->id));
     // determine text for publish state
     switch ($template['publishstate']) {
         case 'draft':
             $blogtype = get_string('publishtonoone', 'blog');
             break;
         case 'site':
             $blogtype = get_string('publishtosite', 'blog');
             break;
         case 'public':
             $blogtype = get_string('publishtoworld', 'blog');
             break;
         default:
             $blogtype = '';
             break;
     }
     $contentcell->text .= $OUTPUT->container($blogtype, 'audience');
     $contentcell->text .= $template['body'];
     $contentcell->text .= $attachedimages;
     // Uniquehash is used as a link to an external blog
     if (!empty($this->uniquehash)) {
         $contentcell->text .= $OUTPUT->container_start('externalblog');
         $contentcell->text .= html_writer::link($this->uniquehash, get_string('linktooriginalentry', 'blog'));
         $contentcell->text .= $OUTPUT->container_end();
     }
     // Links to tags
     $officialtags = tag_get_tags_csv('post', $this->id, TAG_RETURN_HTML, 'official');
     $defaulttags = tag_get_tags_csv('post', $this->id, TAG_RETURN_HTML, 'default');
     if (!empty($CFG->usetags) && ($officialtags || $defaulttags)) {
         $contentcell->text .= $OUTPUT->container_start('tags');
         if ($officialtags) {
             $contentcell->text .= get_string('tags', 'tag') . ': ' . $OUTPUT->container($officialtags, 'officialblogtags');
             if ($defaulttags) {
                 $contentcell->text .= ', ';
             }
         }
         $contentcell->text .= $defaulttags;
         $contentcell->text .= $OUTPUT->container_end();
     }
     // Add associations
     if (!empty($CFG->useblogassociations) && $blogassociations) {
         $contentcell->text .= $OUTPUT->container_start('tags');
         $assocstr = '';
         $hascourseassocs = false;
         $assoctype = '';
         // First find and show the associated course
         foreach ($blogassociations as $assocrec) {
             $contextrec = $DB->get_record('context', array('id' => $assocrec->contextid));
             if ($contextrec->contextlevel == CONTEXT_COURSE) {
                 $assocurl = new moodle_url('/course/view.php', array('id' => $contextrec->instanceid));
                 $text = $DB->get_field('course', 'shortname', array('id' => $contextrec->instanceid));
                 //TODO: performance!!!!
                 $assocstr .= $OUTPUT->action_icon($assocurl, new pix_icon('i/course', $text), null, array(), true);
                 $hascourseassocs = true;
                 $assoctype = get_string('course');
             }
         }
         // Now show mod association
         foreach ($blogassociations as $assocrec) {
             $contextrec = $DB->get_record('context', array('id' => $assocrec->contextid));
             if ($contextrec->contextlevel == CONTEXT_MODULE) {
                 if ($hascourseassocs) {
                     $assocstr .= ', ';
                     $hascourseassocs = false;
                 }
                 $modinfo = $DB->get_record('course_modules', array('id' => $contextrec->instanceid));
                 $modname = $DB->get_field('modules', 'name', array('id' => $modinfo->module));
                 $assocurl = new moodle_url('/mod/' . $modname . '/view.php', array('id' => $modinfo->id));
                 $text = $DB->get_field($modname, 'name', array('id' => $modinfo->instance));
                 //TODO: performance!!!!
                 $assocstr .= $OUTPUT->action_icon($assocurl, new pix_icon('icon', $text, $modname), null, array(), true);
                 $assocstr .= ', ';
                 $assoctype = get_string('modulename', $modname);
             }
         }
         $assocstr = substr($assocstr, 0, -2);
         $contentcell->text .= get_string('associated', 'blog', $assoctype) . ': ' . $assocstr;
         $contentcell->text .= $OUTPUT->container_end();
     }
     if ($unassociatedentry) {
         $contentcell->text .= $OUTPUT->container(get_string('associationunviewable', 'blog'), 'noticebox');
     }
     /// Commands
     $contentcell->text .= $OUTPUT->container_start('commands');
     if (blog_user_can_edit_entry($this) && empty($this->uniquehash)) {
         $contentcell->text .= html_writer::link(new moodle_url('/blog/edit.php', array('action' => 'edit', 'entryid' => $this->id)), $stredit) . ' | ';
         $contentcell->text .= html_writer::link(new moodle_url('/blog/edit.php', array('action' => 'delete', 'entryid' => $this->id)), $strdelete) . ' | ';
     }
     $contentcell->text .= html_writer::link(new moodle_url('/blog/index.php', array('entryid' => $this->id)), get_string('permalink', 'blog'));
     $contentcell->text .= $OUTPUT->container_end();
     if (isset($template['lastmod'])) {
         $contentcell->text .= '<div style="font-size: 55%;">';
         $contentcell->text .= ' [ ' . get_string('modified') . ': ' . $template['lastmod'] . ' ]';
         $contentcell->text .= '</div>';
     }
     $mainrow->cells[] = $contentcell;
     $table->data = array($mainrow);
     if ($return) {
         return html_writer::table($table);
     } else {
         echo html_writer::table($table);
     }
 }
示例#2
0
    } else {
        $datestring = get_string("never");
    }
    print_row(get_string("firstaccess") . ":", $datestring);
}
if (!isset($hiddenfields['lastaccess'])) {
    if ($user->lastaccess) {
        $datestring = userdate($user->lastaccess) . "&nbsp; (" . format_time(time() - $user->lastaccess) . ")";
    } else {
        $datestring = get_string("never");
    }
    print_row(get_string("lastaccess") . ":", $datestring);
}
/// Printing tagged interests
if (!empty($CFG->usetags)) {
    if ($interests = tag_get_tags_csv('user', $user->id)) {
        print_row(get_string('interests') . ": ", $interests);
    }
}
if (!isset($hiddenfields['suspended'])) {
    if ($user->suspended) {
        print_row('', get_string('suspended', 'auth'));
    }
}
echo "</table></div></div>";
echo $OUTPUT->blocks_for_region('content');
// Print messaging link if allowed
if (isloggedin() && has_capability('moodle/site:sendmessage', $context) && !empty($CFG->messaging) && !isguestuser() && !isguestuser($user) && $USER->id != $user->id) {
    echo '<div class="messagebox">';
    echo '<a href="' . $CFG->wwwroot . '/message/index.php?id=' . $user->id . '">' . get_string('messageselectadd') . '</a>';
    echo '</div>';
示例#3
0
文件: pagelib.php 项目: Burick/moodle
    protected function print_edit($content = null) {
        global $CFG, $OUTPUT, $USER, $PAGE;

        if (!$this->check_locks()) {
            return;
        }

        //delete old locks (> 1 hour)
        wiki_delete_old_locks();

        $version = wiki_get_current_version($this->page->id);
        $format = $version->contentformat;

        if ($content == null) {
            if (empty($this->section)) {
                $content = $version->content;
            } else {
                $content = $this->sectioncontent;
            }
        }

        $versionnumber = $version->version;
        if ($this->versionnumber >= 0) {
            if ($version->version != $this->versionnumber) {
                print $OUTPUT->box(get_string('wrongversionlock', 'wiki'), 'errorbox');
                $versionnumber = $this->versionnumber;
            }
        }

        $url = $CFG->wwwroot . '/mod/wiki/edit.php?pageid=' . $this->page->id;
        if (!empty($this->section)) {
            $url .= "&section=" . urlencode($this->section);
        }

        $params = array(
            'attachmentoptions' => page_wiki_edit::$attachmentoptions,
            'format' => $version->contentformat,
            'version' => $versionnumber,
            'pagetitle' => $this->page->title,
            'contextid' => $this->modcontext->id
        );

        $data = new StdClass();
        $data->newcontent = $content;
        $data->version = $versionnumber;
        $data->format = $format;

        switch ($format) {
        case 'html':
            $data->newcontentformat = FORMAT_HTML;
            // Append editor context to editor options, giving preference to existing context.
            page_wiki_edit::$attachmentoptions = array_merge(array('context' => $this->modcontext), page_wiki_edit::$attachmentoptions);
            $data = file_prepare_standard_editor($data, 'newcontent', page_wiki_edit::$attachmentoptions, $this->modcontext, 'mod_wiki', 'attachments', $this->subwiki->id);
            break;
        default:
            break;
        }

        if ($version->contentformat != 'html') {
            $params['fileitemid'] = $this->subwiki->id;
            $params['component']  = 'mod_wiki';
            $params['filearea']   = 'attachments';
        }

        if (!empty($CFG->usetags)) {
            $params['tags'] = tag_get_tags_csv('wiki_pages', $this->page->id, TAG_RETURN_TEXT);
        }

        $form = new mod_wiki_edit_form($url, $params);

        if ($formdata = $form->get_data()) {
            if (!empty($CFG->usetags)) {
                $data->tags = $formdata->tags;
            }
        } else {
            if (!empty($CFG->usetags)) {
                $data->tags = tag_get_tags_array('wiki', $this->page->id);
            }
        }

        $form->set_data($data);
        $form->display();
    }
示例#4
0
/**
 * This function is in lib and not in BlogInfo because entries being searched
 * might be found in any number of blogs rather than just one.
 *
 * This function builds an array which can be used by the included
 * template file, making predefined and nicely formatted variables available
 * to the template. Template creators will not need to become intimate
 * with the internal objects and vars of moodle blog nor will they need to worry
 * about properly formatting their data
 *
 *   @param BlogEntry blogEntry - a hopefully fully populated BlogEntry object
 *   @param string viewtype Default is 'full'. If 'full' then display this blog entry
 *     in its complete form (eg. archive page). If anything other than 'full'
 *     display the entry in its abbreviated format (eg. index page)
 */
function blog_print_entry($blogEntry, $viewtype = 'full', $filtertype = '', $filterselect = '', $mode = 'loud')
{
    global $USER, $CFG, $COURSE, $ME;
    $template['body'] = format_text($blogEntry->summary, $blogEntry->format);
    $template['title'] = '<a id=b"' . s($blogEntry->id) . ' /">';
    //enclose the title in nolink tags so that moodle formatting doesn't autolink the text
    $template['title'] .= '<span class="nolink">' . format_string($blogEntry->subject) . '</span>';
    $template['userid'] = $blogEntry->userid;
    $template['author'] = fullname(get_record('user', 'id', $blogEntry->userid));
    $template['created'] = userdate($blogEntry->created);
    if ($blogEntry->created != $blogEntry->lastmodified) {
        $template['lastmod'] = userdate($blogEntry->lastmodified);
    }
    $template['publishstate'] = $blogEntry->publishstate;
    /// preventing user to browse blogs that they aren't supposed to see
    /// This might not be too good since there are multiple calls per page
    /*
            if (!blog_user_can_view_user_post($template['userid'])) {
                error ('you can not view this post');
            }*/
    $stredit = get_string('edit');
    $strdelete = get_string('delete');
    $user = get_record('user', 'id', $template['userid']);
    /// Start printing of the blog
    echo '<table cellspacing="0" class="forumpost blogpost blog' . $template['publishstate'] . '" width="100%">';
    echo '<tr class="header"><td class="picture left">';
    print_user_picture($user, SITEID, $user->picture);
    echo '</td>';
    echo '<td class="topic starter"><div class="subject">' . $template['title'] . '</div><div class="author">';
    $fullname = fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $COURSE->id)));
    $by = new object();
    $by->name = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $user->id . '&amp;course=' . $COURSE->id . '">' . $fullname . '</a>';
    $by->date = $template['created'];
    print_string('bynameondate', 'forum', $by);
    echo '</div></td></tr>';
    echo '<tr><td class="left side">';
    /// Actual content
    echo '</td><td class="content">' . "\n";
    if ($blogEntry->attachment) {
        echo '<div class="attachments">';
        $attachedimages = blog_print_attachments($blogEntry);
        echo '</div>';
    } else {
        $attachedimages = '';
    }
    switch ($template['publishstate']) {
        case 'draft':
            $blogtype = get_string('publishtonoone', 'blog');
            break;
        case 'site':
            $blogtype = get_string('publishtosite', 'blog');
            break;
        case 'public':
            $blogtype = get_string('publishtoworld', 'blog');
            break;
        default:
            $blogtype = '';
            break;
    }
    echo '<div class="audience">' . $blogtype . '</div>';
    // Print whole message
    echo $template['body'];
    /// Print attachments
    echo $attachedimages;
    /// Links to tags
    if (!empty($CFG->usetags) && ($blogtags = tag_get_tags_csv('post', $blogEntry->id))) {
        echo '<div class="tags">';
        if ($blogtags) {
            print get_string('tags', 'tag') . ': ' . $blogtags;
        }
        echo '</div>';
    }
    /// Commands
    echo '<div class="commands">';
    if (blog_user_can_edit_post($blogEntry)) {
        echo '<a href="' . $CFG->wwwroot . '/blog/edit.php?action=edit&amp;id=' . $blogEntry->id . '">' . $stredit . '</a>';
        echo '| <a href="' . $CFG->wwwroot . '/blog/edit.php?action=delete&amp;id=' . $blogEntry->id . '">' . $strdelete . '</a> | ';
    }
    echo '<a href="' . $CFG->wwwroot . '/blog/index.php?postid=' . $blogEntry->id . '">' . get_string('permalink', 'blog') . '</a>';
    echo '</div>';
    if (isset($template['lastmod'])) {
        echo '<div style="font-size: 55%;">';
        echo ' [ ' . get_string('modified') . ': ' . $template['lastmod'] . ' ]';
        echo '</div>';
    }
    echo '</td></tr></table>' . "\n\n";
}
示例#5
0
/**
 *
 * Give user record from mdl_user, build an array conntains
 * all user details
 *
 * Warning: description file urls are 'webservice/pluginfile.php' is use.
 *          it can be changed with $CFG->moodlewstextformatlinkstoimagesfile
 *
 * @param stdClass $user user record from mdl_user
 * @param stdClass $context context object
 * @param stdClass $course moodle course
 * @param array $userfields required fields
 * @return array|null
 */
function user_get_user_details($user, $course = null, array $userfields = array())
{
    global $USER, $DB, $CFG;
    require_once $CFG->dirroot . "/user/profile/lib.php";
    //custom field library
    require_once $CFG->dirroot . "/lib/filelib.php";
    // file handling on description and friends
    $defaultfields = user_get_default_fields();
    if (empty($userfields)) {
        $userfields = $defaultfields;
    }
    foreach ($userfields as $thefield) {
        if (!in_array($thefield, $defaultfields)) {
            throw new moodle_exception('invaliduserfield', 'error', '', $thefield);
        }
    }
    // Make sure id and fullname are included
    if (!in_array('id', $userfields)) {
        $userfields[] = 'id';
    }
    if (!in_array('fullname', $userfields)) {
        $userfields[] = 'fullname';
    }
    if (!empty($course)) {
        $context = context_course::instance($course->id);
        $usercontext = context_user::instance($user->id);
        $canviewdetailscap = has_capability('moodle/user:viewdetails', $context) || has_capability('moodle/user:viewdetails', $usercontext);
    } else {
        $context = context_user::instance($user->id);
        $usercontext = $context;
        $canviewdetailscap = has_capability('moodle/user:viewdetails', $usercontext);
    }
    $currentuser = $user->id == $USER->id;
    $isadmin = is_siteadmin($USER);
    $showuseridentityfields = get_extra_user_fields($context);
    if (!empty($course)) {
        $canviewhiddenuserfields = has_capability('moodle/course:viewhiddenuserfields', $context);
    } else {
        $canviewhiddenuserfields = has_capability('moodle/user:viewhiddendetails', $context);
    }
    $canviewfullnames = has_capability('moodle/site:viewfullnames', $context);
    if (!empty($course)) {
        $canviewuseremail = has_capability('moodle/course:useremail', $context);
    } else {
        $canviewuseremail = false;
    }
    $cannotviewdescription = !empty($CFG->profilesforenrolledusersonly) && !$currentuser && !$DB->record_exists('role_assignments', array('userid' => $user->id));
    if (!empty($course)) {
        $canaccessallgroups = has_capability('moodle/site:accessallgroups', $context);
    } else {
        $canaccessallgroups = false;
    }
    if (!$currentuser && !$canviewdetailscap && !has_coursecontact_role($user->id)) {
        // skip this user details
        return null;
    }
    $userdetails = array();
    $userdetails['id'] = $user->id;
    if (($isadmin or $currentuser) and in_array('username', $userfields)) {
        $userdetails['username'] = $user->username;
    }
    if ($isadmin or $canviewfullnames) {
        if (in_array('firstname', $userfields)) {
            $userdetails['firstname'] = $user->firstname;
        }
        if (in_array('lastname', $userfields)) {
            $userdetails['lastname'] = $user->lastname;
        }
    }
    $userdetails['fullname'] = fullname($user);
    if (in_array('customfields', $userfields)) {
        $fields = $DB->get_recordset_sql("SELECT f.*\n                                            FROM {user_info_field} f\n                                            JOIN {user_info_category} c\n                                                 ON f.categoryid=c.id\n                                        ORDER BY c.sortorder ASC, f.sortorder ASC");
        $userdetails['customfields'] = array();
        foreach ($fields as $field) {
            require_once $CFG->dirroot . '/user/profile/field/' . $field->datatype . '/field.class.php';
            $newfield = 'profile_field_' . $field->datatype;
            $formfield = new $newfield($field->id, $user->id);
            if ($formfield->is_visible() and !$formfield->is_empty()) {
                $userdetails['customfields'][] = array('name' => $formfield->field->name, 'value' => $formfield->data, 'type' => $field->datatype, 'shortname' => $formfield->field->shortname);
            }
        }
        $fields->close();
        // unset customfields if it's empty
        if (empty($userdetails['customfields'])) {
            unset($userdetails['customfields']);
        }
    }
    // profile image
    if (in_array('profileimageurl', $userfields)) {
        $profileimageurl = moodle_url::make_pluginfile_url($usercontext->id, 'user', 'icon', NULL, '/', 'f1');
        $userdetails['profileimageurl'] = $profileimageurl->out(false);
    }
    if (in_array('profileimageurlsmall', $userfields)) {
        $profileimageurlsmall = moodle_url::make_pluginfile_url($usercontext->id, 'user', 'icon', NULL, '/', 'f2');
        $userdetails['profileimageurlsmall'] = $profileimageurlsmall->out(false);
    }
    //hidden user field
    if ($canviewhiddenuserfields) {
        $hiddenfields = array();
        // address, phone1 and phone2 not appears in hidden fields list
        // but require viewhiddenfields capability
        // according to user/profile.php
        if ($user->address && in_array('address', $userfields)) {
            $userdetails['address'] = $user->address;
        }
    } else {
        $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields));
    }
    if ($user->phone1 && in_array('phone1', $userfields) && (in_array('phone1', $showuseridentityfields) or $canviewhiddenuserfields)) {
        $userdetails['phone1'] = $user->phone1;
    }
    if ($user->phone2 && in_array('phone2', $userfields) && (in_array('phone2', $showuseridentityfields) or $canviewhiddenuserfields)) {
        $userdetails['phone2'] = $user->phone2;
    }
    if (isset($user->description) && (!isset($hiddenfields['description']) && !$cannotviewdescription or $isadmin)) {
        if (in_array('description', $userfields)) {
            // Always return the descriptionformat if description is requested.
            list($userdetails['description'], $userdetails['descriptionformat']) = external_format_text($user->description, $user->descriptionformat, $usercontext->id, 'user', 'profile', null);
        }
    }
    if (in_array('country', $userfields) && (!isset($hiddenfields['country']) or $isadmin) && $user->country) {
        $userdetails['country'] = $user->country;
    }
    if (in_array('city', $userfields) && (!isset($hiddenfields['city']) or $isadmin) && $user->city) {
        $userdetails['city'] = $user->city;
    }
    if (in_array('url', $userfields) && $user->url && (!isset($hiddenfields['webpage']) or $isadmin)) {
        $url = $user->url;
        if (strpos($user->url, '://') === false) {
            $url = 'http://' . $url;
        }
        $user->url = clean_param($user->url, PARAM_URL);
        $userdetails['url'] = $user->url;
    }
    if (in_array('icq', $userfields) && $user->icq && (!isset($hiddenfields['icqnumber']) or $isadmin)) {
        $userdetails['icq'] = $user->icq;
    }
    if (in_array('skype', $userfields) && $user->skype && (!isset($hiddenfields['skypeid']) or $isadmin)) {
        $userdetails['skype'] = $user->skype;
    }
    if (in_array('yahoo', $userfields) && $user->yahoo && (!isset($hiddenfields['yahooid']) or $isadmin)) {
        $userdetails['yahoo'] = $user->yahoo;
    }
    if (in_array('aim', $userfields) && $user->aim && (!isset($hiddenfields['aimid']) or $isadmin)) {
        $userdetails['aim'] = $user->aim;
    }
    if (in_array('msn', $userfields) && $user->msn && (!isset($hiddenfields['msnid']) or $isadmin)) {
        $userdetails['msn'] = $user->msn;
    }
    if (in_array('firstaccess', $userfields) && (!isset($hiddenfields['firstaccess']) or $isadmin)) {
        if ($user->firstaccess) {
            $userdetails['firstaccess'] = $user->firstaccess;
        } else {
            $userdetails['firstaccess'] = 0;
        }
    }
    if (in_array('lastaccess', $userfields) && (!isset($hiddenfields['lastaccess']) or $isadmin)) {
        if ($user->lastaccess) {
            $userdetails['lastaccess'] = $user->lastaccess;
        } else {
            $userdetails['lastaccess'] = 0;
        }
    }
    if (in_array('email', $userfields) && ($isadmin or $currentuser or $canviewuseremail or in_array('email', $showuseridentityfields) or $user->maildisplay == 1 or $user->maildisplay == 2 and enrol_sharing_course($user, $USER))) {
        $userdetails['email'] = $user->email;
    }
    if (in_array('interests', $userfields) && !empty($CFG->usetags)) {
        require_once $CFG->dirroot . '/tag/lib.php';
        if ($interests = tag_get_tags_csv('user', $user->id, TAG_RETURN_TEXT)) {
            $userdetails['interests'] = $interests;
        }
    }
    //Departement/Institution/Idnumber are not displayed on any profile, however you can get them from editing profile.
    if ($isadmin or $currentuser or in_array('idnumber', $showuseridentityfields)) {
        if (in_array('idnumber', $userfields) && $user->idnumber) {
            $userdetails['idnumber'] = $user->idnumber;
        }
    }
    if ($isadmin or $currentuser or in_array('institution', $showuseridentityfields)) {
        if (in_array('institution', $userfields) && $user->institution) {
            $userdetails['institution'] = $user->institution;
        }
    }
    if ($isadmin or $currentuser or in_array('department', $showuseridentityfields)) {
        if (in_array('department', $userfields) && isset($user->department)) {
            //isset because it's ok to have department 0
            $userdetails['department'] = $user->department;
        }
    }
    if (in_array('roles', $userfields) && !empty($course)) {
        // not a big secret
        $roles = get_user_roles($context, $user->id, false);
        $userdetails['roles'] = array();
        foreach ($roles as $role) {
            $userdetails['roles'][] = array('roleid' => $role->roleid, 'name' => $role->name, 'shortname' => $role->shortname, 'sortorder' => $role->sortorder);
        }
    }
    // If groups are in use and enforced throughout the course, then make sure we can meet in at least one course level group
    if (in_array('groups', $userfields) && !empty($course) && $canaccessallgroups) {
        $usergroups = groups_get_all_groups($course->id, $user->id, $course->defaultgroupingid, 'g.id, g.name,g.description,g.descriptionformat');
        $userdetails['groups'] = array();
        foreach ($usergroups as $group) {
            list($group->description, $group->descriptionformat) = external_format_text($group->description, $group->descriptionformat, $context->id, 'group', 'description', $group->id);
            $userdetails['groups'][] = array('id' => $group->id, 'name' => $group->name, 'description' => $group->description, 'descriptionformat' => $group->descriptionformat);
        }
    }
    //list of courses where the user is enrolled
    if (in_array('enrolledcourses', $userfields) && !isset($hiddenfields['mycourses'])) {
        $enrolledcourses = array();
        if ($mycourses = enrol_get_users_courses($user->id, true)) {
            foreach ($mycourses as $mycourse) {
                if ($mycourse->category) {
                    $coursecontext = context_course::instance($mycourse->id);
                    $enrolledcourse = array();
                    $enrolledcourse['id'] = $mycourse->id;
                    $enrolledcourse['fullname'] = format_string($mycourse->fullname, true, array('context' => $coursecontext));
                    $enrolledcourse['shortname'] = format_string($mycourse->shortname, true, array('context' => $coursecontext));
                    $enrolledcourses[] = $enrolledcourse;
                }
            }
            $userdetails['enrolledcourses'] = $enrolledcourses;
        }
    }
    //user preferences
    if (in_array('preferences', $userfields) && $currentuser) {
        $preferences = array();
        $userpreferences = get_user_preferences();
        foreach ($userpreferences as $prefname => $prefvalue) {
            $preferences[] = array('name' => $prefname, 'value' => $prefvalue);
        }
        $userdetails['preferences'] = $preferences;
    }
    return $userdetails;
}
示例#6
0
    foreach ($values as $value) {
        if (!preg_match('/value(\\d+)/', $value, $matches)) {
            continue;
        }
        insert_record('course_classification', (object) array('course' => $course->id, 'value' => $matches[1]));
        $cleanvalues[] = $matches[1];
    }
    // update the manual tags
    tag_set('course', $course->id, explode(',', $formdata->tags));
    // update the classification tags
    $ctag_arr = array();
    $sql = "SELECT value FROM {$CFG->prefix}classification_value WHERE id IN ( " . implode(',', $cleanvalues) . ")";
    if (!empty($cleanvalues) && ($ctags = get_records_sql($sql))) {
        foreach ($ctags as $ctag) {
            $ctag_arr[] = strtolower($ctag->value);
        }
    }
    tag_set('courseclassification', $course->id, $ctag_arr);
    //set the tags (or clear them if none selected)
    commit_sql();
    events_trigger('lp_classification', $course->id);
    notify(get_string('changessaved'), 'notifysuccess');
    print_continue($CFG->wwwroot . '/course/view.php?id=' . $course->id);
} else {
    $post = new object();
    if ($itemptags = tag_get_tags_csv('course', $course->id, TAG_RETURN_TEXT, 'default')) {
        $post->tags = $itemptags;
    }
    $mform->set_data($post);
    $mform->display();
}
示例#7
0
// Guest can not edit
if (isguestuser()) {
    print_error('guestnoeditprofile');
}
// The user profile we are editing
if (!($user = get_record('user', 'id', $userid))) {
    error('User ID was incorrect');
}
// Guest can not be edited
if (isguestuser($user)) {
    print_error('guestnoeditprofile');
}
// User interests separated by commas
if (!empty($CFG->usetags)) {
    require_once $CFG->dirroot . '/tag/lib.php';
    $user->interests = tag_get_tags_csv('user', $user->id, TAG_RETURN_TEXT);
}
// remote users cannot be edited
if (is_mnet_remote_user($user)) {
    redirect($CFG->wwwroot . "/user/view.php?course={$course->id}");
}
if ($course->id == SITEID) {
    $coursecontext = get_context_instance(CONTEXT_SYSTEM);
    // SYSTEM context
} else {
    $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
    // Course context
}
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
$personalcontext = get_context_instance(CONTEXT_USER, $user->id);
// check access control
示例#8
0
        $post->publishstate = 'site';
        $strformheading = get_string('addnewentry', 'blog');
        $post->action = $action;
        break;
    case 'edit':
        if (!$existing) {
            error('Incorrect blog post id');
        }
        $post->id = $existing->id;
        $post->subject = $existing->subject;
        $post->summary = $existing->summary;
        $post->publishstate = $existing->publishstate;
        $post->format = $existing->format;
        $post->action = $action;
        $strformheading = get_string('updateentrywithid', 'blog');
        if ($itemptags = tag_get_tags_csv('post', $post->id, TAG_RETURN_TEXT, 'default')) {
            $post->ptags = $itemptags;
        }
        if ($itemotags = tag_get_tags_array('post', $post->id, 'official')) {
            $post->otags = array_keys($itemotags);
        }
        break;
    default:
        error('Unknown action!');
}
// done here in order to allow deleting of posts with wrong user id above
if (!($user = get_record('user', 'id', $userid))) {
    error('Incorrect user id');
}
$navlinks = array();
$navlinks[] = array('name' => fullname($user), 'link' => "{$CFG->wwwroot}/user/view.php?id={$userid}", 'type' => 'misc');
示例#9
0
/**
 * Defines core nodes for my profile navigation tree.
 *
 * @param \core_user\output\myprofile\tree $tree Tree object
 * @param stdClass $user user object
 * @param bool $iscurrentuser is the user viewing profile, current user ?
 * @param stdClass $course course object
 *
 * @return bool
 */
function core_myprofile_navigation(core_user\output\myprofile\tree $tree, $user, $iscurrentuser, $course)
{
    global $CFG, $USER, $DB;
    $usercontext = context_user::instance($user->id, MUST_EXIST);
    $systemcontext = context_system::instance();
    $context = !empty($course) ? context_course::instance($course->id) : $systemcontext;
    $courseid = !empty($course) ? $course->id : SITEID;
    $contactcategory = new core_user\output\myprofile\category('contact', get_string('userdetails'));
    $coursedetailscategory = new core_user\output\myprofile\category('coursedetails', get_string('coursedetails'), 'contact');
    $miscategory = new core_user\output\myprofile\category('miscellaneous', get_string('miscellaneous'), 'coursedetails');
    $reportcategory = new core_user\output\myprofile\category('reports', get_string('reports'), 'miscellaneous');
    $admincategory = new core_user\output\myprofile\category('administration', get_string('administration'), 'reports');
    $loginactivitycategory = new core_user\output\myprofile\category('loginactivity', get_string('loginactivity'), 'administration');
    // Add categories.
    $tree->add_category($contactcategory);
    $tree->add_category($coursedetailscategory);
    $tree->add_category($miscategory);
    $tree->add_category($reportcategory);
    $tree->add_category($admincategory);
    $tree->add_category($loginactivitycategory);
    // Add core nodes.
    // Full profile node.
    if (!empty($course)) {
        if (empty($CFG->forceloginforprofiles) || $iscurrentuser || has_capability('moodle/user:viewdetails', context_user::instance($user->id)) || has_coursecontact_role($user->id)) {
            $url = new moodle_url('/user/profile.php', array('id' => $user->id));
            $node = new core_user\output\myprofile\node('miscellaneous', 'fullprofile', get_string('fullprofile'), null, $url);
            $tree->add_node($node);
        }
    }
    // Edit profile.
    if (isloggedin() && !isguestuser($user) && !is_mnet_remote_user($user)) {
        if (($iscurrentuser || is_siteadmin($USER) || !is_siteadmin($user)) && has_capability('moodle/user:update', $systemcontext)) {
            $url = new moodle_url('/user/editadvanced.php', array('id' => $user->id, 'course' => $courseid));
            $node = new core_user\output\myprofile\node('contact', 'editprofile', get_string('editmyprofile'), null, $url);
            $tree->add_node($node);
        } else {
            if (has_capability('moodle/user:editprofile', $usercontext) && !is_siteadmin($user) || $iscurrentuser && has_capability('moodle/user:editownprofile', $systemcontext)) {
                $userauthplugin = false;
                if (!empty($user->auth)) {
                    $userauthplugin = get_auth_plugin($user->auth);
                }
                if ($userauthplugin && $userauthplugin->can_edit_profile()) {
                    $url = $userauthplugin->edit_profile_url();
                    if (empty($url)) {
                        if (empty($course)) {
                            $url = new moodle_url('/user/edit.php', array('userid' => $user->id));
                        } else {
                            $url = new moodle_url('/user/edit.php', array('userid' => $user->id, 'course' => $course->id));
                        }
                    }
                    $node = new core_user\output\myprofile\node('contact', 'editprofile', get_string('editmyprofile'), null, $url);
                    $tree->add_node($node);
                }
            }
        }
    }
    // Preference page. Only visible by administrators.
    if (is_siteadmin()) {
        $url = new moodle_url('/user/preferences.php', array('userid' => $user->id));
        $title = $iscurrentuser ? get_string('mypreferences') : get_string('userspreferences', 'moodle', fullname($user));
        $node = new core_user\output\myprofile\node('administration', 'preferences', $title, null, $url);
        $tree->add_node($node);
    }
    // Login as ...
    if (!$user->deleted && !$iscurrentuser && !\core\session\manager::is_loggedinas() && has_capability('moodle/user:loginas', $context) && !is_siteadmin($user->id)) {
        $url = new moodle_url('/course/loginas.php', array('id' => $courseid, 'user' => $user->id, 'sesskey' => sesskey()));
        $node = new core_user\output\myprofile\node('administration', 'loginas', get_string('loginas'), null, $url);
        $tree->add_node($node);
    }
    // Contact details.
    if (has_capability('moodle/user:viewhiddendetails', $usercontext)) {
        $hiddenfields = array();
    } else {
        $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields));
    }
    if (has_capability('moodle/site:viewuseridentity', $context)) {
        $identityfields = array_flip(explode(',', $CFG->showuseridentity));
    } else {
        $identityfields = array();
    }
    if (is_mnet_remote_user($user)) {
        $sql = "SELECT h.id, h.name, h.wwwroot,\n                       a.name as application, a.display_name\n                  FROM {mnet_host} h, {mnet_application} a\n                 WHERE h.id = ? AND h.applicationid = a.id";
        $remotehost = $DB->get_record_sql($sql, array($user->mnethostid));
        $remoteuser = new stdclass();
        $remoteuser->remotetype = $remotehost->display_name;
        $hostinfo = new stdclass();
        $hostinfo->remotename = $remotehost->name;
        $hostinfo->remoteurl = $remotehost->wwwroot;
        $node = new core_user\output\myprofile\node('contact', 'mnet', get_string('remoteuser', 'mnet', $remoteuser), null, null, get_string('remoteuserinfo', 'mnet', $hostinfo), null, 'remoteuserinfo');
        $tree->add_node($node);
    }
    if (isset($identityfields['email']) and ($iscurrentuser or $user->maildisplay == 1 or has_capability('moodle/course:useremail', $usercontext) or $user->maildisplay == 2 and enrol_sharing_course($user, $USER))) {
        $node = new core_user\output\myprofile\node('contact', 'email', get_string('email'), null, null, obfuscate_mailto($user->email, ''));
        $tree->add_node($node);
    }
    if (!isset($hiddenfields['country']) && $user->country) {
        $node = new core_user\output\myprofile\node('contact', 'country', get_string('country'), null, null, get_string($user->country, 'countries'));
        $tree->add_node($node);
    }
    if (!isset($hiddenfields['city']) && $user->city) {
        $node = new core_user\output\myprofile\node('contact', 'city', get_string('city'), null, null, $user->city);
        $tree->add_node($node);
    }
    if (isset($identityfields['address']) && $user->address) {
        $node = new core_user\output\myprofile\node('contact', 'address', get_string('address'), null, null, $user->address);
        $tree->add_node($node);
    }
    if (isset($identityfields['phone1']) && $user->phone1) {
        $node = new core_user\output\myprofile\node('contact', 'phone1', get_string('phone'), null, null, $user->phone1);
        $tree->add_node($node);
    }
    if (isset($identityfields['phone2']) && $user->phone2) {
        $node = new core_user\output\myprofile\node('contact', 'phone2', get_string('phone2'), null, null, $user->phone2);
        $tree->add_node($node);
    }
    if (isset($identityfields['institution']) && $user->institution) {
        $node = new core_user\output\myprofile\node('contact', 'institution', get_string('institution'), null, null, $user->institution);
        $tree->add_node($node);
    }
    if (isset($identityfields['department']) && $user->department) {
        $node = new core_user\output\myprofile\node('contact', 'department', get_string('department'), null, null, $user->institution);
        $tree->add_node($node);
    }
    if (isset($identityfields['idnumber']) && $user->idnumber) {
        $node = new core_user\output\myprofile\node('contact', 'idnumber', get_string('idnumber'), null, null, $user->institution);
        $tree->add_node($node);
    }
    if ($user->url && !isset($hiddenfields['webpage'])) {
        $url = $user->url;
        if (strpos($user->url, '://') === false) {
            $url = 'http://' . $url;
        }
        $webpageurl = new moodle_url($url);
        $node = new core_user\output\myprofile\node('contact', 'webpage', get_string('webpage'), null, null, html_writer::link($url, $webpageurl));
        $tree->add_node($node);
    }
    // Printing tagged interests. We want this only for full profile.
    if (!empty($CFG->usetags) && empty($course)) {
        if ($interests = tag_get_tags_csv('user', $user->id)) {
            $node = new core_user\output\myprofile\node('contact', 'interests', get_string('interests'), null, null, $interests);
            $tree->add_node($node);
        }
    }
    if (!isset($hiddenfields['mycourses'])) {
        $showallcourses = optional_param('showallcourses', 0, PARAM_INT);
        if ($mycourses = enrol_get_all_users_courses($user->id, true, null, 'visible DESC, sortorder ASC')) {
            $shown = 0;
            $courselisting = html_writer::start_tag('ul');
            foreach ($mycourses as $mycourse) {
                if ($mycourse->category) {
                    context_helper::preload_from_record($mycourse);
                    $ccontext = context_course::instance($mycourse->id);
                    if (!isset($course) || $mycourse->id != $course->id) {
                        $linkattributes = null;
                        if ($mycourse->visible == 0) {
                            if (!has_capability('moodle/course:viewhiddencourses', $ccontext)) {
                                continue;
                            }
                            $linkattributes['class'] = 'dimmed';
                        }
                        $params = array('id' => $user->id, 'course' => $mycourse->id);
                        if ($showallcourses) {
                            $params['showallcourses'] = 1;
                        }
                        $url = new moodle_url('/user/view.php', $params);
                        $courselisting .= html_writer::tag('li', html_writer::link($url, $ccontext->get_context_name(false), $linkattributes));
                    } else {
                        $courselisting .= html_writer::tag('li', $course->fullname);
                    }
                }
                $shown++;
                if (!$showallcourses && $shown == $CFG->navcourselimit) {
                    $url = null;
                    if (isset($course)) {
                        $url = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id, 'showallcourses' => 1));
                    } else {
                        $url = new moodle_url('/user/profile.php', array('id' => $user->id, 'showallcourses' => 1));
                    }
                    $courselisting .= html_writer::tag('li', html_writer::link($url, get_string('viewmore'), array('title' => get_string('viewmore'))));
                    break;
                }
            }
            $courselisting .= html_writer::end_tag('ul');
            if (!empty($mycourses)) {
                // Add this node only if there are courses to display.
                $node = new core_user\output\myprofile\node('coursedetails', 'courseprofiles', get_string('courseprofiles'), null, null, rtrim($courselisting, ', '));
                $tree->add_node($node);
            }
        }
    }
    if (!empty($course)) {
        // Show roles in this course.
        if ($rolestring = get_user_roles_in_course($user->id, $course->id)) {
            $node = new core_user\output\myprofile\node('coursedetails', 'roles', get_string('roles'), null, null, $rolestring);
            $tree->add_node($node);
        }
        // Show groups this user is in.
        if (!isset($hiddenfields['groups']) && !empty($course)) {
            $accessallgroups = has_capability('moodle/site:accessallgroups', $context);
            if ($usergroups = groups_get_all_groups($course->id, $user->id)) {
                $groupstr = '';
                foreach ($usergroups as $group) {
                    if ($course->groupmode == SEPARATEGROUPS and !$accessallgroups and $user->id != $USER->id) {
                        if (!groups_is_member($group->id, $user->id)) {
                            continue;
                        }
                    }
                    if ($course->groupmode != NOGROUPS) {
                        $groupstr .= ' <a href="' . $CFG->wwwroot . '/user/index.php?id=' . $course->id . '&amp;group=' . $group->id . '">' . format_string($group->name) . '</a>,';
                    } else {
                        // The user/index.php shows groups only when course in group mode.
                        $groupstr .= ' ' . format_string($group->name);
                    }
                }
                if ($groupstr !== '') {
                    $node = new core_user\output\myprofile\node('coursedetails', 'groups', get_string('group'), null, null, rtrim($groupstr, ', '));
                    $tree->add_node($node);
                }
            }
        }
        if (!isset($hiddenfields['suspended'])) {
            if ($user->suspended) {
                $node = new core_user\output\myprofile\node('coursedetails', 'suspended', null, null, null, get_string('suspended', 'auth'));
                $tree->add_node($node);
            }
        }
        echo html_writer::end_tag('dl');
    }
    if ($user->icq && !isset($hiddenfields['icqnumber'])) {
        $imurl = new moodle_url('http://web.icq.com/wwp', array('uin' => $user->icq));
        $iconurl = new moodle_url('http://web.icq.com/whitepages/online', array('icq' => $user->icq, 'img' => '5'));
        $statusicon = html_writer::tag('img', '', array('src' => $iconurl, 'class' => 'icon icon-post', 'alt' => get_string('status')));
        $node = new core_user\output\myprofile\node('contact', 'icqnumber', get_string('icqnumber'), null, null, html_writer::link($imurl, s($user->icq) . $statusicon));
        $tree->add_node($node);
    }
    if ($user->skype && !isset($hiddenfields['skypeid'])) {
        $imurl = 'skype:' . urlencode($user->skype) . '?call';
        $iconurl = new moodle_url('http://mystatus.skype.com/smallicon/' . urlencode($user->skype));
        if (is_https()) {
            // Bad luck, skype devs are lazy to set up SSL on their servers - see MDL-37233.
            $statusicon = '';
        } else {
            $statusicon = html_writer::empty_tag('img', array('src' => $iconurl, 'class' => 'icon icon-post', 'alt' => get_string('status')));
        }
        $node = new core_user\output\myprofile\node('contact', 'skypeid', get_string('skypeid'), null, null, html_writer::link($imurl, s($user->skype) . $statusicon));
        $tree->add_node($node);
    }
    if ($user->yahoo && !isset($hiddenfields['yahooid'])) {
        $imurl = new moodle_url('http://edit.yahoo.com/config/send_webmesg', array('.target' => $user->yahoo, '.src' => 'pg'));
        $iconurl = new moodle_url('http://opi.yahoo.com/online', array('u' => $user->yahoo, 'm' => 'g', 't' => '0'));
        $statusicon = html_writer::tag('img', '', array('src' => $iconurl, 'class' => 'iconsmall icon-post', 'alt' => get_string('status')));
        $node = new core_user\output\myprofile\node('contact', 'yahooid', get_string('yahooid'), null, null, html_writer::link($imurl, s($user->yahoo) . $statusicon));
        $tree->add_node($node);
    }
    if ($user->aim && !isset($hiddenfields['aimid'])) {
        $imurl = 'aim:goim?screenname=' . urlencode($user->aim);
        $node = new core_user\output\myprofile\node('contact', 'aimid', get_string('aimid'), null, null, html_writer::link($imurl, s($user->aim)));
        $tree->add_node($node);
    }
    if ($user->msn && !isset($hiddenfields['msnid'])) {
        $node = new core_user\output\myprofile\node('contact', 'msnid', get_string('msnid'), null, null, s($user->msn));
        $tree->add_node($node);
    }
    if ($categories = $DB->get_records('user_info_category', null, 'sortorder ASC')) {
        foreach ($categories as $category) {
            if ($fields = $DB->get_records('user_info_field', array('categoryid' => $category->id), 'sortorder ASC')) {
                foreach ($fields as $field) {
                    require_once $CFG->dirroot . '/user/profile/field/' . $field->datatype . '/field.class.php';
                    $newfield = 'profile_field_' . $field->datatype;
                    $formfield = new $newfield($field->id, $user->id);
                    if ($formfield->is_visible() and !$formfield->is_empty()) {
                        $node = new core_user\output\myprofile\node('contact', $formfield->field->shortname, format_string($formfield->field->name), null, null, $formfield->display_data());
                        $tree->add_node($node);
                    }
                }
            }
        }
    }
    // First access. (Why only for sites ?)
    if (!isset($hiddenfields['firstaccess']) && empty($course)) {
        if ($user->firstaccess) {
            $datestring = userdate($user->firstaccess) . "&nbsp; (" . format_time(time() - $user->firstaccess) . ")";
        } else {
            $datestring = get_string("never");
        }
        $node = new core_user\output\myprofile\node('loginactivity', 'firstaccess', get_string('firstsiteaccess'), null, null, $datestring);
        $tree->add_node($node);
    }
    // Last access.
    if (!isset($hiddenfields['lastaccess'])) {
        if (empty($course)) {
            $string = get_string('lastsiteaccess');
            if ($user->lastaccess) {
                $datestring = userdate($user->lastaccess) . "&nbsp; (" . format_time(time() - $user->lastaccess) . ")";
            } else {
                $datestring = get_string("never");
            }
        } else {
            $string = get_string('lastcourseaccess');
            if ($lastaccess = $DB->get_record('user_lastaccess', array('userid' => $user->id, 'courseid' => $course->id))) {
                $datestring = userdate($lastaccess->timeaccess) . "&nbsp; (" . format_time(time() - $lastaccess->timeaccess) . ")";
            } else {
                $datestring = get_string("never");
            }
        }
        $node = new core_user\output\myprofile\node('loginactivity', 'lastaccess', $string, null, null, $datestring);
        $tree->add_node($node);
    }
    // Last ip.
    if (has_capability('moodle/user:viewlastip', $usercontext) && !isset($hiddenfields['lastip'])) {
        if ($user->lastip) {
            $iplookupurl = new moodle_url('/iplookup/index.php', array('ip' => $user->lastip, 'user' => $USER->id));
            $ipstring = html_writer::link($iplookupurl, $user->lastip);
        } else {
            $ipstring = get_string("none");
        }
        $node = new core_user\output\myprofile\node('loginactivity', 'lastip', get_string('lastip'), null, null, $ipstring);
        $tree->add_node($node);
    }
}
示例#10
0
 public function test_create()
 {
     global $DB;
     $this->resetAfterTest(true);
     $generator = $this->getDataGenerator();
     $count = $DB->count_records('course_categories');
     $category = $generator->create_category();
     $this->assertEquals($count + 1, $DB->count_records('course_categories'));
     $this->assertRegExp('/^Course category \\d/', $category->name);
     $this->assertSame('', $category->idnumber);
     $this->assertRegExp('/^Test course category \\d/', $category->description);
     $this->assertSame(FORMAT_MOODLE, $category->descriptionformat);
     $count = $DB->count_records('cohort');
     $cohort = $generator->create_cohort();
     $this->assertEquals($count + 1, $DB->count_records('cohort'));
     $this->assertEquals(context_system::instance()->id, $cohort->contextid);
     $this->assertRegExp('/^Cohort \\d/', $cohort->name);
     $this->assertSame('', $cohort->idnumber);
     $this->assertRegExp('/^Test cohort \\d/', $cohort->description);
     $this->assertSame(FORMAT_MOODLE, $cohort->descriptionformat);
     $this->assertSame('', $cohort->component);
     $this->assertLessThanOrEqual(time(), $cohort->timecreated);
     $this->assertSame($cohort->timecreated, $cohort->timemodified);
     $count = $DB->count_records('course');
     $course = $generator->create_course();
     $this->assertEquals($count + 1, $DB->count_records('course'));
     $this->assertRegExp('/^Test course \\d/', $course->fullname);
     $this->assertRegExp('/^tc_\\d/', $course->shortname);
     $this->assertSame('', $course->idnumber);
     $this->assertSame('topics', $course->format);
     $this->assertEquals(0, $course->newsitems);
     $this->assertEquals(5, $course->numsections);
     $this->assertRegExp('/^Test course \\d/', $course->summary);
     $this->assertSame(FORMAT_MOODLE, $course->summaryformat);
     $section = $generator->create_course_section(array('course' => $course->id, 'section' => 3));
     $this->assertEquals($course->id, $section->course);
     $course = $generator->create_course(array('tags' => 'Cat, Dog'));
     $this->assertEquals('Cat, Dog', tag_get_tags_csv('course', $course->id, TAG_RETURN_TEXT));
     $scale = $generator->create_scale();
     $this->assertNotEmpty($scale);
 }
示例#11
0
 /**
  * Retrieve the current set of tags for this object.
  *
  * @access public
  * @return string CSV list of tags.
  */
 public function get_tags()
 {
     return tag_get_tags_csv(static::$table, $this->id, TAG_RETURN_TEXT);
 }
示例#12
0
 /**
  * Renders a blog entry
  *
  * @param blog_entry $entry
  * @return string The table HTML
  */
 public function render_blog_entry(blog_entry $entry)
 {
     global $CFG;
     $syscontext = context_system::instance();
     $stredit = get_string('edit');
     $strdelete = get_string('delete');
     // Header.
     $mainclass = 'forumpost blog_entry blog clearfix ';
     if ($entry->renderable->unassociatedentry) {
         $mainclass .= 'draft';
     } else {
         $mainclass .= $entry->publishstate;
     }
     $o = $this->output->container_start($mainclass, 'b' . $entry->id);
     $o .= $this->output->container_start('row header clearfix');
     // User picture.
     $o .= $this->output->container_start('left picture header');
     $o .= $this->output->user_picture($entry->renderable->user);
     $o .= $this->output->container_end();
     $o .= $this->output->container_start('topic starter header clearfix');
     // Title.
     $titlelink = html_writer::link(new moodle_url('/blog/index.php', array('entryid' => $entry->id)), format_string($entry->subject));
     $o .= $this->output->container($titlelink, 'subject');
     // Post by.
     $by = new stdClass();
     $fullname = fullname($entry->renderable->user, has_capability('moodle/site:viewfullnames', $syscontext));
     $userurlparams = array('id' => $entry->renderable->user->id, 'course' => $this->page->course->id);
     $by->name = html_writer::link(new moodle_url('/user/view.php', $userurlparams), $fullname);
     $by->date = userdate($entry->created);
     $o .= $this->output->container(get_string('bynameondate', 'forum', $by), 'author');
     // Adding external blog link.
     if (!empty($entry->renderable->externalblogtext)) {
         $o .= $this->output->container($entry->renderable->externalblogtext, 'externalblog');
     }
     // Closing subject tag and header tag.
     $o .= $this->output->container_end();
     $o .= $this->output->container_end();
     // Post content.
     $o .= $this->output->container_start('row maincontent clearfix');
     // Entry.
     $o .= $this->output->container_start('no-overflow content ');
     // Determine text for publish state.
     switch ($entry->publishstate) {
         case 'draft':
             $blogtype = get_string('publishtonoone', 'blog');
             break;
         case 'site':
             $blogtype = get_string('publishtosite', 'blog');
             break;
         case 'public':
             $blogtype = get_string('publishtoworld', 'blog');
             break;
         default:
             $blogtype = '';
             break;
     }
     $o .= $this->output->container($blogtype, 'audience');
     // Attachments.
     $attachmentsoutputs = array();
     if ($entry->renderable->attachments) {
         foreach ($entry->renderable->attachments as $attachment) {
             $o .= $this->render($attachment, false);
         }
     }
     // Body.
     $o .= format_text($entry->summary, $entry->summaryformat, array('overflowdiv' => true));
     if (!empty($entry->uniquehash)) {
         // Uniquehash is used as a link to an external blog.
         $url = clean_param($entry->uniquehash, PARAM_URL);
         if (!empty($url)) {
             $o .= $this->output->container_start('externalblog');
             $o .= html_writer::link($url, get_string('linktooriginalentry', 'blog'));
             $o .= $this->output->container_end();
         }
     }
     // Links to tags.
     $officialtags = tag_get_tags_csv('post', $entry->id, TAG_RETURN_HTML, 'official');
     $defaulttags = tag_get_tags_csv('post', $entry->id, TAG_RETURN_HTML, 'default');
     if (!empty($CFG->usetags) && ($officialtags || $defaulttags)) {
         $o .= $this->output->container_start('tags');
         if ($officialtags) {
             $o .= get_string('tags', 'tag') . ': ' . $this->output->container($officialtags, 'officialblogtags');
             if ($defaulttags) {
                 $o .= ', ';
             }
         }
         $o .= $defaulttags;
         $o .= $this->output->container_end();
     }
     // Add associations.
     if (!empty($CFG->useblogassociations) && !empty($entry->renderable->blogassociations)) {
         // First find and show the associated course.
         $assocstr = '';
         $coursesarray = array();
         foreach ($entry->renderable->blogassociations as $assocrec) {
             if ($assocrec->contextlevel == CONTEXT_COURSE) {
                 $coursesarray[] = $this->output->action_icon($assocrec->url, $assocrec->icon, null, array(), true);
             }
         }
         if (!empty($coursesarray)) {
             $assocstr .= get_string('associated', 'blog', get_string('course')) . ': ' . implode(', ', $coursesarray);
         }
         // Now show mod association.
         $modulesarray = array();
         foreach ($entry->renderable->blogassociations as $assocrec) {
             if ($assocrec->contextlevel == CONTEXT_MODULE) {
                 $str = get_string('associated', 'blog', $assocrec->type) . ': ';
                 $str .= $this->output->action_icon($assocrec->url, $assocrec->icon, null, array(), true);
                 $modulesarray[] = $str;
             }
         }
         if (!empty($modulesarray)) {
             if (!empty($coursesarray)) {
                 $assocstr .= '<br/>';
             }
             $assocstr .= implode('<br/>', $modulesarray);
         }
         // Adding the asociations to the output.
         $o .= $this->output->container($assocstr, 'tags');
     }
     if ($entry->renderable->unassociatedentry) {
         $o .= $this->output->container(get_string('associationunviewable', 'blog'), 'noticebox');
     }
     // Commands.
     $o .= $this->output->container_start('commands');
     if ($entry->renderable->usercanedit) {
         // External blog entries should not be edited.
         if (empty($entry->uniquehash)) {
             $o .= html_writer::link(new moodle_url('/blog/edit.php', array('action' => 'edit', 'entryid' => $entry->id)), $stredit) . ' | ';
         }
         $o .= html_writer::link(new moodle_url('/blog/edit.php', array('action' => 'delete', 'entryid' => $entry->id)), $strdelete) . ' | ';
     }
     $entryurl = new moodle_url('/blog/index.php', array('entryid' => $entry->id));
     $o .= html_writer::link($entryurl, get_string('permalink', 'blog'));
     $o .= $this->output->container_end();
     // Last modification.
     if ($entry->created != $entry->lastmodified) {
         $o .= $this->output->container(' [ ' . get_string('modified') . ': ' . userdate($entry->lastmodified) . ' ]');
     }
     // Comments.
     if (!empty($entry->renderable->comment)) {
         $o .= $entry->renderable->comment->output(true);
     }
     $o .= $this->output->container_end();
     // Closing maincontent div.
     $o .= $this->output->container('&nbsp;', 'side options');
     $o .= $this->output->container_end();
     $o .= $this->output->container_end();
     return $o;
 }
示例#13
0
    protected function print_edit($content = null) {
        global $CFG, $OUTPUT, $USER, $PAGE;

        if (!$this->check_locks()) {
            return;
        }

        //delete old locks (> 1 hour)
        wiki_delete_old_locks();

        $version = wiki_get_current_version($this->page->id);
        $format = $version->contentformat;

        if ($content == null) {
            if (empty($this->section)) {
                $content = $version->content;
            } else {
                $content = $this->sectioncontent;
            }
        }

        $versionnumber = $version->version;
        if ($this->versionnumber >= 0) {
            if ($version->version != $this->versionnumber) {
                print $OUTPUT->box(get_string('wrongversionlock', 'wiki'), 'errorbox');
                $versionnumber = $this->versionnumber;
            }
        }

        $url = $CFG->wwwroot . '/mod/wiki/edit.php?pageid=' . $this->page->id;
        if (!empty($this->section)) {
            $url .= "&section=" . $this->section;
        }

        $params = array('attachmentoptions' => page_wiki_edit::$attachmentoptions, 'format' => $version->contentformat, 'version' => $versionnumber, 'pagetitle'=>$this->page->title);

        $data = new StdClass();
        $data->newcontent = $content;
        $data->version = $versionnumber;
        $data->format = $format;

        switch ($format) {
        case 'html':
            $data->newcontentformat = FORMAT_HTML;
            $data = file_prepare_standard_editor($data, 'newcontent', page_wiki_edit::$attachmentoptions, $this->modcontext, 'mod_wiki', 'attachments', $this->subwiki->id);
            break;
        default:
            //$draftitemid = file_get_submitted_draft_itemid('attachments');
            //file_prepare_draft_area($draftitemid, $this->modcontext->id, 'mod_wiki', 'attachments', $this->subwiki->id);
            //$data->attachments = $draftitemid;
            }

        if ($version->contentformat != 'html') {
            $params['contextid'] = $this->modcontext->id;
            $params['component'] = 'mod_wiki';
            $params['filearea'] = 'attachments';
            $params['fileitemid'] = $this->subwiki->id;
        }

        if (!empty($CFG->usetags)) {
            $params['tags'] = tag_get_tags_csv('wiki_pages', $this->page->id, TAG_RETURN_TEXT);
        }

        $form = new mod_wiki_edit_form($url, $params);

        if ($formdata = $form->get_data()) {
            if ($format != 'html') {
                $errors = $this->process_uploads($this->modcontext);
                if (!empty($errors)) {
                    $contenterror = "";
                    foreach ($errors as $e) {
                        $contenterror .= "<p>" . get_string('filenotuploadederror', 'wiki', $e->get_filename()) . "</p>";
                    }
                    print $OUTPUT->box($contenterror, 'errorbox');
                }
            }
            if (!empty($CFG->usetags)) {
                $data->tags = $formdata->tags;
            }
        } else {
            if (!empty($CFG->usetags)) {
                $data->tags = tag_get_tags_array('wiki', $this->page->id);
            }
        }

        $form->set_data($data);
        $form->display();
    }
示例#14
0
    /**
     * Get course participant's details
     * @param array $userlist  array of user ids and according course ids
     * @return array An array of arrays describing course participants
     */
    public static function get_course_participants_by_id($userlist) {
        global $CFG, $USER, $DB;
        require_once($CFG->dirroot . "/user/lib.php");
        require_once($CFG->dirroot . "/user/profile/lib.php"); //custom field library
        require_once($CFG->dirroot . "/lib/filelib.php");      // file handling on description and friends

        $isadmin = is_siteadmin($USER);

        $params = self::validate_parameters(self::get_course_participants_by_id_parameters(), array('userlist'=>$userlist));

        $userids = array();
        $courseids = array();
        foreach ($params['userlist'] as $value) {
            $userids[] = $value['userid'];
            $courseids[$value['userid']] = $value['courseid'];
        }

        // cache all courses
        $courses = array();
        list($cselect, $cjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
        list($sqlcourseids, $params) = $DB->get_in_or_equal(array_unique($courseids));
        $coursesql = "SELECT c.* $uselect
                        FROM {course} c $cjoin
                       WHERE c.id $sqlcourseids";
        $rs = $DB->get_recordset_sql($coursesql, $params);
        foreach ($rs as $course) {
            // adding course contexts to cache
            context_instance_preload($course);
            // cache courses
            $courses[$course->id] = $course;
        }
        $rs->close();

        list($uselect, $ujoin) = context_instance_preload_sql('u.id', CONTEXT_USER, 'ctx');
        list($sqluserids, $params) = $DB->get_in_or_equal($userids);
        $usersql = "SELECT u.* $uselect
                      FROM {user} u $ujoin
                     WHERE u.id $sqluserids";
        $users = $DB->get_recordset_sql($usersql, $params);
        $result = array();
        foreach ($users as $user) {
            if (!empty($user->deleted)) {
                continue;
            }
            context_instance_preload($user);
            $usercontext = get_context_instance(CONTEXT_USER, $user->id);
            $course = $courses[$courseids[$user->id]];
            $context = get_context_instance(CONTEXT_COURSE, $courseids[$user->id]);
            $hasviewdetailscap = has_capability('moodle/user:viewdetails', $context) || has_capability('moodle/user:viewdetails', $usercontext);

            self::validate_context($context);

            $currentuser = ($user->id == $USER->id);

            if (!$currentuser && !$hasviewdetailscap && !has_coursecontact_role($user->id)) {
                throw new moodle_exception('usernotavailable', 'error');
            }
            $userarray = array();

            //basic fields
            $userarray['id'] = $user->id;
            if ($isadmin) {
                $userarray['username'] = $user->username;
            }
            if ($isadmin or has_capability('moodle/site:viewfullnames', $context)) {
                $userarray['firstname'] = $user->firstname;
                $userarray['lastname'] = $user->lastname;
            }
            $userarray['fullname'] = fullname($user);

            //Custom fields (matching /user/profile/lib.php - profile_display_fields code logic)
            $userarray['customfields'] = array();

            $fields = $DB->get_recordset_sql("SELECT f.*
                                                FROM {user_info_field} f
                                                JOIN {user_info_category} c
                                                     ON f.categoryid=c.id
                                            ORDER BY c.sortorder ASC, f.sortorder ASC");
            foreach ($fields as $field) {
                require_once($CFG->dirroot.'/user/profile/field/'.$field->datatype.'/field.class.php');
                $newfield = 'profile_field_'.$field->datatype;
                $formfield = new $newfield($field->id, $user->id);
                if ($formfield->is_visible() and !$formfield->is_empty()) {
                    $userarray['customfields'][] =
                        array('name' => $formfield->field->name, 'value' => $formfield->data,
                            'type' => $field->datatype, 'shortname' => $formfield->field->shortname);
                }
            }
            $fields->close();

            //image profiles urls (public, no permission required in fact)
            $profileimageurl = moodle_url::make_pluginfile_url($usercontext->id, 'user', 'icon', NULL, '/', 'f1');
            $userarray['profileimageurl'] = $profileimageurl->out(false);
            $profileimageurlsmall = moodle_url::make_pluginfile_url($usercontext->id, 'user', 'icon', NULL, '/', 'f2');
            $userarray['profileimageurlsmall'] = $profileimageurlsmall->out(false);

            //hidden user field
            if (has_capability('moodle/course:viewhiddenuserfields', $context)) {
                $hiddenfields = array();
            } else {
                $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields));
            }

            if (isset($user->description) && (!isset($hiddenfields['description']) or $isadmin)) {
                if (empty($CFG->profilesforenrolledusersonly) || $currentuser) {
                    $user->description = file_rewrite_pluginfile_urls($user->description, 'pluginfile.php', $context->id, 'user', 'profile', null);
                    $userarray['description'] = $user->description;
                    $userarray['descriptionformat'] = $user->descriptionformat;
                }
            }

            if ((! isset($hiddenfields['country']) or $isadmin) && $user->country) {
                $userarray['country'] = $user->country;
            }

            if ((! isset($hiddenfields['city']) or $isadmin) && $user->city) {
                $userarray['city'] = $user->city;
            }

            if (has_capability('moodle/course:viewhiddenuserfields', $context)) {
                if ($user->address) {
                    $userarray['address'] = $user->address;
                }
                if ($user->phone1) {
                    $userarray['phone1'] = $user->phone1;
                }
                if ($user->phone2) {
                    $userarray['phone2'] = $user->phone2;
                }
            }

            if ($currentuser
              or $user->maildisplay == 1
              or has_capability('moodle/course:useremail', $context)
              or ($user->maildisplay == 2 and enrol_sharing_course($user, $USER))) {
                $userarray['email'] = $user->email;;
            }

            if ($user->url && (!isset($hiddenfields['webpage']) or $isadmin)) {
                $url = $user->url;
                if (strpos($user->url, '://') === false) {
                    $url = 'http://'. $url;
                }
                $user->url = clean_param($user->url, PARAM_URL);
                $userarray['url'] = $user->url;
            }

            if ($user->icq && (!isset($hiddenfields['icqnumber']) or $isadmin)) {
                $userarray['icq'] = $user->icq;
            }

            if ($user->skype && (!isset($hiddenfields['skypeid']) or $isadmin)) {
                $userarray['skype'] = $user->skype;
            }
            if ($user->yahoo && (!isset($hiddenfields['yahooid']) or $isadmin)) {
                $userarray['yahoo'] = $user->yahoo;
            }
            if ($user->aim && (!isset($hiddenfields['aimid']) or $isadmin)) {
                $userarray['aim'] = $user->aim;
            }
            if ($user->msn && (!isset($hiddenfields['msnid']) or $isadmin)) {
                $userarray['msn'] = $user->msn;
            }

            if ((!isset($hiddenfields['firstaccess'])) or $isadmin) {
                if ($user->firstaccess) {
                    $userarray['firstaccess'] = $user->firstaccess;
                } else {
                    $userarray['firstaccess'] = 0;
                }
            }
            if ((!isset($hiddenfields['lastaccess'])) or $isadmin) {
                if ($user->lastaccess) {
                    $userarray['lastaccess'] = $user->lastaccess;
                } else {
                    $userarray['lastaccess'] = 0;
                }
            }
            /// Printing tagged interests
            if (!empty($CFG->usetags)) {
                require_once($CFG->dirroot . '/tag/lib.php');
                if ($interests = tag_get_tags_csv('user', $user->id, TAG_RETURN_TEXT) ) {
                    $userarray['interests'] = $interests;
                }
            }

            //Departement/Institution are not displayed on any profile, however you can get them from editing profile.
            if ($isadmin or $currentuser) {
                if ($user->institution) {
                    $userarray['institution'] = $user->institution;
                }
                if (isset($user->department)) { //isset because it's ok to have department 0
                    $userarray['department'] = $user->department;
                }
            }

            // not a big secret
            $userarray['roles'] = array();
            $roles = get_user_roles($context, $user->id, false);
            foreach ($roles as $role) {
                $userarray['roles'][] = array(
                    'roleid'       => $role->roleid,
                    'name'         => $role->name,
                    'shortname'    => $role->shortname,
                    'sortorder'    => $role->sortorder
                );
            }

            // If groups are in use and enforced throughout the course, then make sure we can meet in at least one course level group
            if (has_capability('moodle/site:accessallgroups', $context)) {
                $usergroups = groups_get_all_groups($course->id, $user->id, $course->defaultgroupingid, 'g.id, g.name,g.description');
                foreach ($usergroups as $group) {
                    $group->description = file_rewrite_pluginfile_urls($group->description, 'pluginfile.php', $context->id, 'group', 'description', $group->id);
                    $userarray['groups'][] = array('id'=>$group->id, 'name'=>$group->name, 'description'=>$group->description);
                }
            }
            $result[] = $userarray;
        }

        $users->close();

        return $result;
    }