function execute($data, $user, $courseid)
 {
     $finalcourses = array();
     $mycourses = get_my_courses($user->id);
     if (!empty($mycourses)) {
         $finalcourses = array_keys($mycourses);
     }
     return $finalcourses;
 }
 function definition()
 {
     global $CFG, $USER;
     $mform =& $this->_form;
     // Get customdata
     $action = $this->_customdata['action'];
     $courseid = $this->_customdata['course'];
     $folderid = $this->_customdata['id'];
     /// Print the required moodle fields first
     $mform->addElement('header', 'moodle', get_string('folder', 'block_email_list'));
     $mform->addElement('text', 'name', get_string('namenewfolder', 'block_email_list'));
     $mform->setDefault('name', '');
     $mform->addRule('name', get_string('nofolder', 'block_email_list'), 'required', null, 'client');
     // Get root folders
     $folders = email_get_my_folders($USER->id, $courseid, true, true);
     // Get inbox, there default option on menu
     $inbox = email_get_root_folder($USER->id, EMAIL_INBOX);
     $menu = array();
     // Insert into menu, only name folder
     foreach ($folders as $key => $foldername) {
         $menu[$key] = $foldername;
     }
     if ($parent = email_get_parent_folder($folderid)) {
         $parentid = $parent->id;
     } else {
         $parentid = 0;
     }
     // Select parent folder
     $mform->addElement('select', 'parentfolder', get_string('linkto', 'block_email_list'), $menu);
     $mform->setDefault('parentfolder', $parentid);
     $mform->addElement('hidden', 'gost');
     if ($preference = get_record('email_preference', 'userid', $USER->id)) {
         if ($preference->marriedfolders2courses) {
             // Get my courses
             $mycourses = get_my_courses($USER->id);
             $courses = array();
             // Prepare array
             foreach ($mycourses as $mycourse) {
                 strlen($mycourse->fullname) > 60 ? $course = substr($mycourse->fullname, 0, 60) . ' ...' : ($course = $mycourse->fullname);
                 $courses[$mycourse->id] = $course;
             }
             $mform->addElement('select', 'foldercourse', get_string('course'), $courses);
             $mform->setDefault('foldercourse', $courseid);
         }
     }
     /// Add some extra hidden fields
     $mform->addElement('hidden', 'course', $courseid);
     $mform->addElement('hidden', 'oldname');
     $mform->addElement('hidden', 'id');
     $mform->addElement('hidden', 'action', $action);
     // buttons
     $this->add_action_buttons();
 }
예제 #3
0
파일: lib.php 프로젝트: henriquecrang/e-UNI
/**
 * This function gets all userid unread mails. It don't read trash, draft and send folders.
 * Only used in the cron.
 *
 * @param int $userid User Id.
 * @return Array All Inbox mails.
 */
function email_get_unread_mails($userid)
{
    global $CFG;
    // Get user courses (don't read hidden courses)
    if ($mycourses = get_my_courses($userid)) {
        $courses = '';
        foreach ($mycourses as $mycourse) {
            $courses .= !empty($courses) ? ', ' . $mycourse->id : $mycourse->id;
        }
        // Get inbox folder
        if ($folder = email_get_root_folder($userid, EMAIL_INBOX)) {
            $foldersid = $folder->id;
            // Get all subfolders
            if ($subfolders = email_get_all_subfolders($folder->id)) {
                foreach ($subfolders as $subfolder) {
                    $foldersid .= ', ' . $subfolder->id;
                }
            }
            $sql = "SELECT *\n\t\t                            FROM {$CFG->prefix}block_email_list_mail m\n\t\t                   LEFT JOIN {$CFG->prefix}block_email_list_send s ON m.id = s.mailid\n\t\t                   LEFT JOIN {$CFG->prefix}block_email_list_foldermail fm ON m.id = fm.mailid ";
            // WHERE principal clause for filter by user and course
            $wheresql = " WHERE s.userid = {$userid}\n\t\t\t\t\t\t  AND s.course IN ( {$courses} )\n\t\t\t\t\t\t  AND fm.folderid IN ( {$foldersid} )\n\t\t\t\t\t\t  AND s.readed = 0\n\t\t\t\t\t\t  AND s.sended = 1";
            return get_records_sql($sql . $wheresql);
        }
    }
    return array();
}
예제 #4
0
 public function fill_table()
 {
     global $CFG, $DB;
     // MDL-11679, only show 'mycourses' instead of all courses
     if ($courses = get_my_courses($this->user->id, 'c.sortorder ASC', 'id, shortname, showgrades')) {
         $numusers = $this->get_numusers(false);
         foreach ($courses as $course) {
             if (!$course->showgrades) {
                 continue;
             }
             $courselink = '<a href="' . $CFG->wwwroot . '/grade/report/user/index.php?id=' . $course->id . '">' . $course->shortname . '</a>';
             $canviewhidden = has_capability('moodle/grade:viewhidden', get_context_instance(CONTEXT_COURSE, $course->id));
             // Get course grade_item
             $course_item = grade_item::fetch_course_item($course->id);
             // Get the stored grade
             $course_grade = new grade_grade(array('itemid' => $course_item->id, 'userid' => $this->user->id));
             $course_grade->grade_item =& $course_item;
             $finalgrade = $course_grade->finalgrade;
             if (!$canviewhidden and !is_null($finalgrade)) {
                 if ($course_grade->is_hidden()) {
                     $finalgrade = null;
                 } else {
                     // This is a really ugly hack, it will be fixed in 2.0
                     $items = grade_item::fetch_all(array('courseid' => $course->id));
                     $grades = array();
                     $sql = "SELECT g.*\n                                  FROM {grade_grades} g\n                                  JOIN {grade_items} gi ON gi.id = g.itemid\n                                 WHERE g.userid = ? AND gi.courseid = ?";
                     if ($gradesrecords = $DB->get_records_sql($sql, array($this->user->id, $course->id))) {
                         foreach ($gradesrecords as $grade) {
                             $grades[$grade->itemid] = new grade_grade($grade, false);
                         }
                         unset($gradesrecords);
                     }
                     foreach ($items as $itemid => $unused) {
                         if (!isset($grades[$itemid])) {
                             $grade_grade = new grade_grade();
                             $grade_grade->userid = $this->user->id;
                             $grade_grade->itemid = $items[$itemid]->id;
                             $grades[$itemid] = $grade_grade;
                         }
                         $grades[$itemid]->grade_item =& $items[$itemid];
                     }
                     $hiding_affected = grade_grade::get_hiding_affected($grades, $items);
                     if (array_key_exists($course_item->id, $hiding_affected['altered'])) {
                         $finalgrade = $hiding_affected['altered'][$course_item->id];
                     } else {
                         if (!empty($hiding_affected['unknown'][$course_item->id])) {
                             $finalgrade = null;
                         }
                     }
                     unset($hiding_affected);
                     unset($grades);
                     unset($items);
                 }
             }
             $data = array($courselink, grade_format_gradevalue($finalgrade, $course_item, true));
             if (!$this->showrank) {
                 //nothing to do
             } else {
                 if (!is_null($finalgrade)) {
                     /// find the number of users with a higher grade
                     /// please note this can not work if hidden grades involved :-( to be fixed in 2.0
                     $params = array($finalgrade, $course_item->id);
                     $sql = "SELECT COUNT(DISTINCT(userid))\n                              FROM {grade_grades}\n                             WHERE finalgrade IS NOT NULL AND finalgrade > ?\n                                   AND itemid = ?";
                     $rank = $DB->count_records_sql($sql, $params) + 1;
                     $data[] = "{$rank}/{$numusers}";
                 } else {
                     // no grade, no rank
                     $data[] = '-';
                 }
             }
             $this->table->add_data($data);
         }
         return true;
     } else {
         notify(get_string('nocourses', 'grades'));
         return false;
     }
 }
예제 #5
0
         print_container_start();
         blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
         print_container_end();
         echo '</td>';
     }
     break;
 case 'middle':
     echo '<td valign="top" id="middle-column">';
     print_container_start(TRUE);
     /// The main overview in the middle of the page
     // limits the number of courses showing up
     $courses_limit = 21;
     if (!empty($CFG->mycoursesperpage)) {
         $courses_limit = $CFG->mycoursesperpage;
     }
     $courses = get_my_courses($USER->id, 'visible DESC,sortorder ASC', '*', false, $courses_limit);
     $site = get_site();
     $course = $site;
     //just in case we need the old global $course hack
     if (array_key_exists($site->id, $courses)) {
         unset($courses[$site->id]);
     }
     foreach ($courses as $c) {
         if (isset($USER->lastcourseaccess[$c->id])) {
             $courses[$c->id]->lastaccess = $USER->lastcourseaccess[$c->id];
         } else {
             $courses[$c->id]->lastaccess = 0;
         }
     }
     if (empty($courses)) {
         print_simple_box(get_string('nocourses', 'my'), 'center');
예제 #6
0
파일: view.php 프로젝트: nadavkav/MoodleTAO
function calendar_course_filter_selector($getvars = '')
{
    global $USER, $SESSION;
    if (empty($USER->id) or isguest()) {
        return '';
    }
    if (has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_SYSTEM)) && !empty($CFG->calendar_adminseesall)) {
        $courses = get_courses('all', 'c.shortname', 'c.id,c.shortname');
    } else {
        $courses = get_my_courses($USER->id, 'shortname');
    }
    unset($courses[SITEID]);
    $courseoptions[SITEID] = get_string('fulllistofcourses');
    foreach ($courses as $course) {
        $courseoptions[$course->id] = format_string($course->shortname);
    }
    if (is_numeric($SESSION->cal_courses_shown)) {
        $selected = $SESSION->cal_courses_shown;
    } else {
        $selected = '';
    }
    return popup_form(CALENDAR_URL . 'set.php?var=setcourse&amp;' . $getvars . '&amp;id=', $courseoptions, 'cal_course_flt', $selected, '', '', '', true);
}
예제 #7
0
 function get_content()
 {
     global $THEME, $CFG, $USER;
     if ($this->content !== NULL) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->items = array();
     $this->content->icons = array();
     $this->content->footer = '';
     $icon = "<img src=\"{$CFG->pixpath}/i/course.gif\"" . " class=\"icon\" alt=\"" . get_string("course") . "\" />";
     $adminseesall = true;
     if (isset($CFG->block_course_list_adminview)) {
         if ($CFG->block_course_list_adminview == 'own') {
             $adminseesall = false;
         }
     }
     if (empty($CFG->disablemycourses) and !empty($USER->id) and !(has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM)) and $adminseesall) and !isguest()) {
         // Just print My Courses
         if ($courses = get_my_courses($USER->id)) {
             foreach ($courses as $course) {
                 if ($course->id == SITEID) {
                     continue;
                 }
                 $linkcss = $course->visible ? "" : " class=\"dimmed\" ";
                 $this->content->items[] = "<a {$linkcss} title=\"" . format_string($course->shortname) . "\" " . "href=\"{$CFG->wwwroot}/course/view.php?id={$course->id}\">" . format_string($course->fullname) . "</a>";
                 $this->content->icons[] = $icon;
             }
             $this->title = get_string('mycourses');
             /// If we can update any course of the view all isn't hidden, show the view all courses link
             if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM)) || empty($CFG->block_course_list_hideallcourseslink)) {
                 $this->content->footer = "<a href=\"{$CFG->wwwroot}/course/index.php\">" . get_string("fulllistofcourses") . "</a> ...";
             }
             $this->get_remote_courses();
             if ($this->content->items) {
                 // make sure we don't return an empty list
                 return $this->content;
             }
         }
     }
     $categories = get_categories("0");
     // Parent = 0   ie top-level categories only
     if ($categories) {
         //Check we have categories
         if (count($categories) > 1 || count($categories) == 1 && count_records('course') > 200) {
             // Just print top level category links
             foreach ($categories as $category) {
                 $linkcss = $category->visible ? "" : " class=\"dimmed\" ";
                 $this->content->items[] = "<a {$linkcss} href=\"{$CFG->wwwroot}/course/category.php?id={$category->id}\">" . format_string($category->name) . "</a>";
                 $this->content->icons[] = $icon;
             }
             /// If we can update any course of the view all isn't hidden, show the view all courses link
             if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM)) || empty($CFG->block_course_list_hideallcourseslink)) {
                 $this->content->footer .= "<a href=\"{$CFG->wwwroot}/course/index.php\">" . get_string('fulllistofcourses') . '</a> ...';
             }
             $this->title = get_string('categories');
         } else {
             // Just print course names of single category
             $category = array_shift($categories);
             $courses = get_courses($category->id);
             if ($courses) {
                 foreach ($courses as $course) {
                     $linkcss = $course->visible ? "" : " class=\"dimmed\" ";
                     $this->content->items[] = "<a {$linkcss} title=\"" . format_string($course->shortname) . "\" " . "href=\"{$CFG->wwwroot}/course/view.php?id={$course->id}\">" . format_string($course->fullname) . "</a>";
                     $this->content->icons[] = $icon;
                 }
                 /// If we can update any course of the view all isn't hidden, show the view all courses link
                 if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM)) || empty($CFG->block_course_list_hideallcourseslink)) {
                     $this->content->footer .= "<a href=\"{$CFG->wwwroot}/course/index.php\">" . get_string('fulllistofcourses') . '</a> ...';
                 }
                 $this->get_remote_courses();
             } else {
                 $this->content->icons[] = '';
                 $this->content->items[] = get_string('nocoursesyet');
                 if (has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $category->id))) {
                     $this->content->footer = '<a href="' . $CFG->wwwroot . '/course/edit.php?category=' . $category->id . '">' . get_string("addnewcourse") . '</a> ...';
                 }
                 $this->get_remote_courses();
             }
             $this->title = get_string('courses');
         }
     }
     return $this->content;
 }
        }
        // if no courses pass the filter in that category, delete the current string
        if ($coursecnt == 0) {
            unset($courselist[$catcnt]);
        } else {
            $courselist[$catcnt] .= '</optgroup>';
            $catcnt++;
        }
    }
    // return the html code with categorized courses
    return implode(' ', $courselist);
}
// generate full and selected course lists
$availablecourses = array();
foreach ($SESSION->bulk_users as $user) {
    $usercourses = get_my_courses($user);
    foreach ($usercourses as $key => $junk) {
        if (!in_array($key, $availablecourses)) {
            $availablecourses[] = $key;
        }
    }
}
$unaccessible = array_diff($SESSION->bulk_courses, $availablecourses);
if (!empty($unaccessible)) {
    $SESSION->bulk_courses = array();
}
$coursenames = gen_course_list($searchtext, array_diff($availablecourses, $SESSION->bulk_courses));
$selcoursenames = gen_course_list('', array_intersect($availablecourses, $SESSION->bulk_courses));
// print the page
if ($accept) {
    if (empty($SESSION->bulk_courses)) {
예제 #9
0
                    $json_output["enrol"] = true;
                    unset($USER->mycourses);
                } else {
                    $json_output["errors"][] = "Error enrolling student into course.";
                }
            }
        }
    } else {
        $json_output["errors"][] = "Enrolment key is incorrect.";
    }
}
if (isset($_GET['my_courses']) || $update_all) {
    if (!empty($USER->id)) {
        // Return my classes.
        $course_ids = array();
        $courses = get_my_courses($USER->id);
        if ($courses) {
            foreach ($courses as $course) {
                if ($CFG->rolesactive) {
                    $context = get_context_instance(CONTEXT_COURSE, $course->id);
                    $course_ids[$course->id] = array("can_edit" => has_capability('moodle/course:manageactivities', $context));
                } else {
                    if ($course->id != 1) {
                        $course_ids[$course->id] = array("can_edit" => isteacher($course->id, $USER->id, true));
                    }
                }
            }
        }
        /*
        $courses = get_my_remotecourses();
        if($courses) {
예제 #10
0
파일: view.php 프로젝트: r007/PMoodle
}
if ($user->skype && !isset($hiddenfields['skypeid'])) {
    print_row(get_string('skypeid') . ':', '<a href="callto:' . urlencode($user->skype) . '">' . s($user->skype) . ' <img src="http://mystatus.skype.com/smallicon/' . urlencode($user->skype) . '" alt="' . get_string('status') . '" ' . ' /></a>');
}
if ($user->yahoo && !isset($hiddenfields['yahooid'])) {
    print_row(get_string('yahooid') . ':', '<a href="http://edit.yahoo.com/config/send_webmesg?.target=' . urlencode($user->yahoo) . '&amp;.src=pg">' . s($user->yahoo) . " <img src=\"http://opi.yahoo.com/online?u=" . urlencode($user->yahoo) . "&m=g&t=0\" alt=\"\"></a>");
}
if ($user->aim && !isset($hiddenfields['aimid'])) {
    print_row(get_string('aimid') . ':', '<a href="aim:goim?screenname=' . s($user->aim) . '">' . s($user->aim) . '</a>');
}
if ($user->msn && !isset($hiddenfields['msnid'])) {
    print_row(get_string('msnid') . ':', s($user->msn));
}
/// Print the Custom User Fields
profile_display_fields($user->id);
if ($mycourses = get_my_courses($user->id, null, null, false, 21)) {
    $shown = 0;
    $courselisting = '';
    foreach ($mycourses as $mycourse) {
        if ($mycourse->category) {
            if ($mycourse->id != $course->id) {
                $class = '';
                if ($mycourse->visible == 0) {
                    // get_my_courses will filter courses $USER cannot see
                    // if we get one with visible 0 it just means it's hidden
                    // ... but not from $USER
                    $class = 'class="dimmed"';
                }
                $courselisting .= "<a href=\"{$CFG->wwwroot}/user/view.php?id={$user->id}&amp;course={$mycourse->id}\" {$class} >" . format_string($mycourse->fullname) . "</a>, ";
            } else {
                $courselisting .= format_string($mycourse->fullname) . ", ";
예제 #11
0
$straddnewnote = get_string('addnewnote', 'notes');
print_box_start();
if ($courseid != SITEID) {
    //echo '<a href="#sitenotes">' . $strsitenotes . '</a> | <a href="#coursenotes">' . $strcoursenotes . '</a> | <a href="#personalnotes">' . $strpersonalnotes . '</a>';
    $context = get_context_instance(CONTEXT_COURSE, $courseid);
    $addid = has_capability('moodle/notes:manage', $context) ? $courseid : 0;
    $view = has_capability('moodle/notes:view', $context);
    note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, $addid, $view, 0, $userid, NOTES_STATE_SITE, 0);
    note_print_notes('<a name="coursenotes"></a>' . $strcoursenotes . ' (' . $course->fullname . ')', $addid, $view, $courseid, $userid, NOTES_STATE_PUBLIC, 0);
    note_print_notes('<a name="personalnotes"></a>' . $strpersonalnotes, $addid, $view, $courseid, $userid, NOTES_STATE_DRAFT, $USER->id);
} else {
    // Normal course
    //echo '<a href="#sitenotes">' . $strsitenotes . '</a> | <a href="#coursenotes">' . $strcoursenotes . '</a>';
    $view = has_capability('moodle/notes:view', get_context_instance(CONTEXT_SYSTEM));
    note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, 0, $view, 0, $userid, NOTES_STATE_SITE, 0);
    echo '<a name="coursenotes"></a>';
    if (!empty($userid)) {
        $courses = get_my_courses($userid);
        foreach ($courses as $c) {
            $header = '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $c->id . '">' . $c->fullname . '</a>';
            if (has_capability('moodle/notes:manage', get_context_instance(CONTEXT_COURSE, $c->id))) {
                $addid = $c->id;
            } else {
                $addid = 0;
            }
            note_print_notes($header, $addid, $view, $c->id, $userid, NOTES_STATE_PUBLIC, 0);
        }
    }
}
print_box_end();
print_footer($course);
  </li> 


<?php 
// Include HTML based menu from each course, if exists
//include($CFG->dataroot.'/'.$COURSE->id.'/menu.txt');
include $CFG->dataroot . '/1/menu.txt';
?>

  <li><div><a href="<?php 
echo $CFG->wwwroot . '/';
?>
">מרחביי הלימוד שלי</a>
        <ul>
<?php 
if ($courses = get_my_courses($USER->id, 'visible DESC, fullname ASC')) {
    foreach ($courses as $course) {
        if ($course->id == SITEID) {
            continue;
        }
        $linkcss = $course->visible ? "" : " class=\"dimmed\" ";
        echo "<li><a {$linkcss} title=\"" . format_string($course->shortname) . "\" " . "href=\"{$CFG->wwwroot}/course/view.php?id={$course->id}\">" . format_string($course->fullname) . "</a></li>";
    }
}
?>
     
	</ul>
</div></li>
</ul>
<div id="top_menu_date">
<a href="<?php 
예제 #13
0
파일: lib.php 프로젝트: r007/PMoodle
function message_print_search_results($frm)
{
    global $USER, $CFG;
    echo '<div align="center">';
    /// search for person
    if (!empty($frm->personsubmit) and !empty($frm->name)) {
        if (optional_param('mycourses', 0, PARAM_BOOL)) {
            $users = array();
            $mycourses = get_my_courses($USER->id);
            foreach ($mycourses as $mycourse) {
                if (is_array($susers = message_search_users($mycourse->id, $frm->name))) {
                    foreach ($susers as $suser) {
                        $users[$suser->id] = $suser;
                    }
                }
            }
        } else {
            $users = message_search_users(SITEID, $frm->name);
        }
        if (!empty($users)) {
            echo '<strong>' . get_string('userssearchresults', 'message', count($users)) . '</strong>';
            echo '<table class="message_users">';
            foreach ($users as $user) {
                if ($user->contactlistid) {
                    if ($user->blocked == 0) {
                        /// not blocked
                        $strcontact = message_contact_link($user->id, 'remove', true);
                        $strblock = message_contact_link($user->id, 'block', true);
                    } else {
                        // blocked
                        $strcontact = message_contact_link($user->id, 'add', true);
                        $strblock = message_contact_link($user->id, 'unblock', true);
                    }
                } else {
                    $strcontact = message_contact_link($user->id, 'add', true);
                    $strblock = message_contact_link($user->id, 'block', true);
                }
                $strhistory = message_history_link($user->id, 0, true, '', '', 'icon');
                echo '<tr><td class="pix">';
                print_user_picture($user, SITEID, $user->picture, 20, false, true, 'userwindow');
                echo '</td>';
                echo '<td class="contact">';
                link_to_popup_window("/message/discussion.php?id={$user->id}", "message_{$user->id}", fullname($user), 500, 500, get_string('sendmessageto', 'message', fullname($user)), 'menubar=0,location=0,status,scrollbars,resizable,width=500,height=500');
                echo '</td>';
                echo '<td class="link">' . $strcontact . '</td>';
                echo '<td class="link">' . $strblock . '</td>';
                echo '<td class="link">' . $strhistory . '</td>';
                echo '</tr>';
            }
            echo '</table>';
        } else {
            notify(get_string('nosearchresults', 'message'));
        }
        /// search messages for keywords
    } else {
        if (!empty($frm->keywordssubmit) and !empty($frm->keywords)) {
            $keywordstring = clean_text(trim($frm->keywords));
            $keywords = explode(' ', $keywordstring);
            $tome = false;
            $fromme = false;
            $courseid = 'none';
            switch ($frm->keywordsoption) {
                case 'tome':
                    $tome = true;
                    break;
                case 'fromme':
                    $fromme = true;
                    break;
                case 'allmine':
                    $tome = true;
                    $fromme = true;
                    break;
                case 'allusers':
                    $courseid = SITEID;
                    break;
                case 'courseusers':
                    $courseid = $frm->courseid;
                    break;
                default:
                    $tome = true;
                    $fromme = true;
            }
            if (($messages = message_search($keywords, $fromme, $tome, $courseid)) !== false) {
                /// get a list of contacts
                if (($contacts = get_records('message_contacts', 'userid', $USER->id, '', 'contactid, blocked')) === false) {
                    $contacts = array();
                }
                /// print heading with number of results
                echo '<p class="heading">' . get_string('keywordssearchresults', 'message', count($messages)) . ' ("' . s($keywordstring) . '")</p>';
                /// print table headings
                echo '<table class="searchresults" cellspacing="0">';
                echo '<tr>';
                echo '<td><strong>' . get_string('from') . '</strong></td>';
                echo '<td><strong>' . get_string('to') . '</strong></td>';
                echo '<td><strong>' . get_string('message', 'message') . '</strong></td>';
                echo '<td><strong>' . get_string('timesent', 'message') . '</strong></td>';
                echo "</tr>\n";
                $blockedcount = 0;
                $dateformat = get_string('strftimedatetimeshort');
                $strcontext = get_string('context', 'message');
                foreach ($messages as $message) {
                    /// ignore messages to and from blocked users unless $frm->includeblocked is set
                    if (!optional_param('includeblocked', 0, PARAM_BOOL) and (isset($contacts[$message->useridfrom]) and $contacts[$message->useridfrom]->blocked == 1 or isset($contacts[$message->useridto]) and $contacts[$message->useridto]->blocked == 1)) {
                        $blockedcount++;
                        continue;
                    }
                    /// load up user to record
                    if ($message->useridto !== $USER->id) {
                        $userto = get_record('user', 'id', $message->useridto);
                        $tocontact = (array_key_exists($message->useridto, $contacts) and $contacts[$message->useridto]->blocked == 0);
                        $toblocked = (array_key_exists($message->useridto, $contacts) and $contacts[$message->useridto]->blocked == 1);
                    } else {
                        $userto = false;
                        $tocontact = false;
                        $toblocked = false;
                    }
                    /// load up user from record
                    if ($message->useridfrom !== $USER->id) {
                        $userfrom = get_record('user', 'id', $message->useridfrom);
                        $fromcontact = (array_key_exists($message->useridfrom, $contacts) and $contacts[$message->useridfrom]->blocked == 0);
                        $fromblocked = (array_key_exists($message->useridfrom, $contacts) and $contacts[$message->useridfrom]->blocked == 1);
                    } else {
                        $userfrom = false;
                        $fromcontact = false;
                        $fromblocked = false;
                    }
                    /// find date string for this message
                    $date = usergetdate($message->timecreated);
                    $datestring = $date['year'] . $date['mon'] . $date['mday'];
                    /// print out message row
                    echo '<tr valign="top">';
                    echo '<td class="contact">';
                    message_print_user($userfrom, $fromcontact, $fromblocked);
                    echo '</td>';
                    echo '<td class="contact">';
                    message_print_user($userto, $tocontact, $toblocked);
                    echo '</td>';
                    echo '<td class="summary">' . message_get_fragment($message->message, $keywords);
                    echo '<br /><div class="link">';
                    message_history_link($message->useridto, $message->useridfrom, false, $keywordstring, 'm' . $message->id, $strcontext);
                    echo '</div>';
                    echo '</td>';
                    echo '<td class="date">' . userdate($message->timecreated, $dateformat) . '</td>';
                    echo "</tr>\n";
                }
                if ($blockedcount > 0) {
                    echo '<tr><td colspan="4" align="center">' . get_string('blockedmessages', 'message', $blockedcount) . '</td></tr>';
                }
                echo '</table>';
            } else {
                notify(get_string('nosearchresults', 'message'));
            }
            /// what the ????, probably an empty search string, duh!
        } else {
            notify(get_string('emptysearchstring', 'message'));
        }
    }
    echo '<br />';
    print_single_button('index.php', array('tab' => 'search'), get_string('newsearch', 'message'));
    echo '</div>';
}
예제 #14
0
/**
 * Returns the aggregated or calculated course grade for the given user(s).
 * @public
 * @param int $userid
 * @param int $courseid optional id of course or array of ids, empty means all uses courses (returns array if not present)
 * @return mixed grade info or grades array including item info, false if error
 */
function grade_get_course_grade($userid, $courseid_or_ids = null)
{
    if (!is_array($courseid_or_ids)) {
        if (empty($courseid_or_ids)) {
            if (!($courses = get_my_courses($userid, $sort = 'visible DESC,sortorder ASC', 'id'))) {
                return false;
            }
            $courseids = array_keys($courses);
            return grade_get_course_grade($userid, $courseids);
        }
        if (!is_numeric($courseid_or_ids)) {
            return false;
        }
        if (!($grades = grade_get_course_grade($userid, array($courseid_or_ids)))) {
            return false;
        } else {
            // only one grade - not array
            $grade = reset($grades);
            return $grade;
        }
    }
    foreach ($courseid_or_ids as $courseid) {
        $grade_item = grade_item::fetch_course_item($courseid);
        $course_items[$grade_item->courseid] = $grade_item;
    }
    $grades = array();
    foreach ($course_items as $grade_item) {
        if ($grade_item->needsupdate) {
            grade_regrade_final_grades($courseid);
        }
        $item = new object();
        $item->scaleid = $grade_item->scaleid;
        $item->name = $grade_item->get_name();
        $item->grademin = $grade_item->grademin;
        $item->grademax = $grade_item->grademax;
        $item->gradepass = $grade_item->gradepass;
        $item->locked = $grade_item->is_locked();
        $item->hidden = $grade_item->is_hidden();
        switch ($grade_item->gradetype) {
            case GRADE_TYPE_NONE:
                continue;
            case GRADE_TYPE_VALUE:
                $item->scaleid = 0;
                break;
            case GRADE_TYPE_TEXT:
                $item->scaleid = 0;
                $item->grademin = 0;
                $item->grademax = 0;
                $item->gradepass = 0;
                break;
        }
        $grade_grade = new grade_grade(array('userid' => $userid, 'itemid' => $grade_item->id));
        $grade_grade->grade_item =& $grade_item;
        $grade = new object();
        $grade->grade = $grade_grade->finalgrade;
        $grade->locked = $grade_grade->is_locked();
        $grade->hidden = $grade_grade->is_hidden();
        $grade->overridden = $grade_grade->overridden;
        $grade->feedback = $grade_grade->feedback;
        $grade->feedbackformat = $grade_grade->feedbackformat;
        $grade->usermodified = $grade_grade->usermodified;
        $grade->dategraded = $grade_grade->get_dategraded();
        $grade->item = $item;
        // create text representation of grade
        if ($grade_item->needsupdate) {
            $grade->grade = false;
            $grade->str_grade = get_string('error');
            $grade->str_long_grade = $grade->str_grade;
        } else {
            if (is_null($grade->grade)) {
                $grade->str_grade = '-';
                $grade->str_long_grade = $grade->str_grade;
            } else {
                $grade->str_grade = grade_format_gradevalue($grade->grade, $grade_item);
                if ($grade_item->gradetype == GRADE_TYPE_SCALE or $grade_item->get_displaytype() != GRADE_DISPLAY_TYPE_REAL) {
                    $grade->str_long_grade = $grade->str_grade;
                } else {
                    $a = new object();
                    $a->grade = $grade->str_grade;
                    $a->max = grade_format_gradevalue($grade_item->grademax, $grade_item);
                    $grade->str_long_grade = get_string('gradelong', 'grades', $a);
                }
            }
        }
        // create html representation of feedback
        if (is_null($grade->feedback)) {
            $grade->str_feedback = '';
        } else {
            $grade->str_feedback = format_text($grade->feedback, $grade->feedbackformat);
        }
        $grades[$grade_item->courseid] = $grade;
    }
    return $grades;
}
예제 #15
0
 /**
  * This function confirms the remote (ID provider) host's mnet session
  * by communicating the token and UA over the XMLRPC transport layer, and
  * returns the local user record on success.
  *
  *   @param string $token           The random session token.
  *   @param string $remotewwwroot   The ID provider wwwroot.
  *   @return array The local user record.
  */
 function confirm_mnet_session($token, $remotewwwroot)
 {
     global $CFG, $MNET, $SESSION, $DB;
     require_once $CFG->dirroot . '/mnet/xmlrpc/client.php';
     // verify the remote host is configured locally before attempting RPC call
     if (!($remotehost = $DB->get_record('mnet_host', array('wwwroot' => $remotewwwroot, 'deleted' => 0)))) {
         print_error('notpermittedtoland', 'mnet');
     }
     // get the originating (ID provider) host info
     $remotepeer = new mnet_peer();
     $remotepeer->set_wwwroot($remotewwwroot);
     // set up the RPC request
     $mnetrequest = new mnet_xmlrpc_client();
     $mnetrequest->set_method('auth/mnet/auth.php/user_authorise');
     // set $token and $useragent parameters
     $mnetrequest->add_param($token);
     $mnetrequest->add_param(sha1($_SERVER['HTTP_USER_AGENT']));
     // Thunderbirds are go! Do RPC call and store response
     if ($mnetrequest->send($remotepeer) === true) {
         $remoteuser = (object) $mnetrequest->response;
     } else {
         foreach ($mnetrequest->error as $errormessage) {
             list($code, $message) = array_map('trim', explode(':', $errormessage, 2));
             if ($code == 702) {
                 $site = get_site();
                 print_error('mnet_session_prohibited', 'mnet', $remotewwwroot, format_string($site->fullname));
                 exit;
             }
             $message .= "ERROR {$code}:<br/>{$errormessage}<br/>";
         }
         print_error("rpcerror", '', '', $message);
     }
     unset($mnetrequest);
     if (empty($remoteuser) or empty($remoteuser->username)) {
         print_error('unknownerror', 'mnet');
         exit;
     }
     $firsttime = false;
     // get the local record for the remote user
     $localuser = $DB->get_record('user', array('username' => $remoteuser->username, 'mnethostid' => $remotehost->id));
     // add the remote user to the database if necessary, and if allowed
     // TODO: refactor into a separate function
     if (empty($localuser) || !$localuser->id) {
         if (empty($this->config->auto_add_remote_users)) {
             print_error('nolocaluser', 'mnet');
         }
         $remoteuser->mnethostid = $remotehost->id;
         $DB->insert_record('user', $remoteuser);
         $firsttime = true;
         if (!($localuser = $DB->get_record('user', array('username' => $remoteuser->username, 'mnethostid' => $remotehost->id)))) {
             print_error('nolocaluser', 'mnet');
         }
     }
     // check sso access control list for permission first
     if (!$this->can_login_remotely($localuser->username, $remotehost->id)) {
         print_error('sso_mnet_login_refused', 'mnet', '', array($localuser->username, $remotehost->name));
     }
     $session_gc_maxlifetime = 1440;
     // update the local user record with remote user data
     foreach ((array) $remoteuser as $key => $val) {
         if ($key == 'session.gc_maxlifetime') {
             $session_gc_maxlifetime = $val;
             continue;
         }
         // TODO: fetch image if it has changed
         if ($key == 'imagehash') {
             $dirname = make_user_directory($localuser->id, true);
             $filename = "{$dirname}/f1.jpg";
             $localhash = '';
             if (file_exists($filename)) {
                 $localhash = sha1(file_get_contents($filename));
             } elseif (!file_exists($dirname)) {
                 mkdir($dirname);
             }
             if ($localhash != $val) {
                 // fetch image from remote host
                 $fetchrequest = new mnet_xmlrpc_client();
                 $fetchrequest->set_method('auth/mnet/auth.php/fetch_user_image');
                 $fetchrequest->add_param($localuser->username);
                 if ($fetchrequest->send($remotepeer) === true) {
                     if (strlen($fetchrequest->response['f1']) > 0) {
                         $imagecontents = base64_decode($fetchrequest->response['f1']);
                         file_put_contents($filename, $imagecontents);
                         $localuser->picture = 1;
                     }
                     if (strlen($fetchrequest->response['f2']) > 0) {
                         $imagecontents = base64_decode($fetchrequest->response['f2']);
                         file_put_contents($dirname . '/f2.jpg', $imagecontents);
                     }
                 }
             }
         }
         if ($key == 'myhosts') {
             $localuser->mnet_foreign_host_array = array();
             foreach ($val as $rhost) {
                 $name = clean_param($rhost['name'], PARAM_ALPHANUM);
                 $url = clean_param($rhost['url'], PARAM_URL);
                 $count = clean_param($rhost['count'], PARAM_INT);
                 $url_is_local = stristr($url, $CFG->wwwroot);
                 if (!empty($name) && !empty($count) && empty($url_is_local)) {
                     $localuser->mnet_foreign_host_array[] = array('name' => $name, 'url' => $url, 'count' => $count);
                 }
             }
         }
         $localuser->{$key} = $val;
     }
     $localuser->mnethostid = $remotepeer->id;
     $DB->update_record('user', $localuser);
     // set up the session
     $mnet_session = $DB->get_record('mnet_session', array('userid' => $localuser->id, 'mnethostid' => $remotepeer->id, 'useragent' => sha1($_SERVER['HTTP_USER_AGENT'])));
     if ($mnet_session == false) {
         $mnet_session = new object();
         $mnet_session->mnethostid = $remotepeer->id;
         $mnet_session->userid = $localuser->id;
         $mnet_session->username = $localuser->username;
         $mnet_session->useragent = sha1($_SERVER['HTTP_USER_AGENT']);
         $mnet_session->token = $token;
         // Needed to support simultaneous sessions
         // and preserving DB rec uniqueness
         $mnet_session->confirm_timeout = time();
         $mnet_session->expires = time() + (int) $session_gc_maxlifetime;
         $mnet_session->session_id = session_id();
         $mnet_session->id = $DB->insert_record('mnet_session', $mnet_session);
     } else {
         $mnet_session->expires = time() + (int) $session_gc_maxlifetime;
         $DB->update_record('mnet_session', $mnet_session);
     }
     if (!$firsttime) {
         // repeat customer! let the IDP know about enrolments
         // we have for this user.
         // set up the RPC request
         $mnetrequest = new mnet_xmlrpc_client();
         $mnetrequest->set_method('auth/mnet/auth.php/update_enrolments');
         // pass username and an assoc array of "my courses"
         // with info so that the IDP can maintain mnet_enrol_assignments
         $mnetrequest->add_param($remoteuser->username);
         $fields = 'id, category, sortorder, fullname, shortname, idnumber, summary,
                    startdate, cost, currency, defaultrole, visible';
         $courses = get_my_courses($localuser->id, 'visible DESC,sortorder ASC', $fields);
         if (is_array($courses) && !empty($courses)) {
             // Second request to do the JOINs that we'd have done
             // inside get_my_courses() if we had been allowed
             $sql = "SELECT c.id,\n                               cc.name AS cat_name, cc.description AS cat_description,\n                               r.shortname as defaultrolename\n                          FROM {course} c\n                          JOIN {course_categories} cc ON c.category = cc.id\n                          LEFT OUTER JOIN {role} r  ON c.defaultrole = r.id\n                         WHERE c.id IN (" . join(',', array_keys($courses)) . ')';
             $extra = $DB->get_records_sql($sql);
             $keys = array_keys($courses);
             $defaultrolename = $DB->get_field('role', 'shortname', array('id' => $CFG->defaultcourseroleid));
             foreach ($keys as $id) {
                 if ($courses[$id]->visible == 0) {
                     unset($courses[$id]);
                     continue;
                 }
                 $courses[$id]->cat_id = $courses[$id]->category;
                 $courses[$id]->defaultroleid = $courses[$id]->defaultrole;
                 unset($courses[$id]->category);
                 unset($courses[$id]->defaultrole);
                 unset($courses[$id]->visible);
                 $courses[$id]->cat_name = $extra[$id]->cat_name;
                 $courses[$id]->cat_description = $extra[$id]->cat_description;
                 if (!empty($extra[$id]->defaultrolename)) {
                     $courses[$id]->defaultrolename = $extra[$id]->defaultrolename;
                 } else {
                     $courses[$id]->defaultrolename = $defaultrolename;
                 }
                 // coerce to array
                 $courses[$id] = (array) $courses[$id];
             }
         } else {
             // if the array is empty, send it anyway
             // we may be clearing out stale entries
             $courses = array();
         }
         $mnetrequest->add_param($courses);
         // Call 0800-RPC Now! -- we don't care too much if it fails
         // as it's just informational.
         if ($mnetrequest->send($remotepeer) === false) {
             // error_log(print_r($mnetrequest->error,1));
         }
     }
     return $localuser;
 }
예제 #16
0
파일: lib.php 프로젝트: r007/PMoodle
/**
 * An array of forum objects that the user is allowed to read/search through.
 * @param $userid
 * @param $courseid - if 0, we look for forums throughout the whole site.
 * @return array of forum objects, or false if no matches
 *         Forum objects have the following attributes:
 *         id, type, course, cmid, cmvisible, cmgroupmode, accessallgroups,
 *         viewhiddentimedposts
 */
function forum_get_readable_forums($userid, $courseid = 0)
{
    global $CFG, $USER;
    require_once $CFG->dirroot . '/course/lib.php';
    if (!($forummod = get_record('modules', 'name', 'forum'))) {
        error('The forum module is not installed');
    }
    if ($courseid) {
        $courses = get_records('course', 'id', $courseid);
    } else {
        // If no course is specified, then the user can see SITE + his courses.
        // And admins can see all courses, so pass the $doanything flag enabled
        $courses1 = get_records('course', 'id', SITEID);
        $courses2 = get_my_courses($userid, null, null, true);
        $courses = array_merge($courses1, $courses2);
    }
    if (!$courses) {
        return array();
    }
    $readableforums = array();
    foreach ($courses as $course) {
        $modinfo =& get_fast_modinfo($course);
        if (is_null($modinfo->groups)) {
            $modinfo->groups = groups_get_user_groups($course->id, $userid);
        }
        if (empty($modinfo->instances['forum'])) {
            // hmm, no forums?
            continue;
        }
        $courseforums = get_records('forum', 'course', $course->id);
        foreach ($modinfo->instances['forum'] as $forumid => $cm) {
            if (!$cm->uservisible or !isset($courseforums[$forumid])) {
                continue;
            }
            $context = get_context_instance(CONTEXT_MODULE, $cm->id);
            $forum = $courseforums[$forumid];
            if (!has_capability('mod/forum:viewdiscussion', $context)) {
                continue;
            }
            /// group access
            if (groups_get_activity_groupmode($cm, $course) == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) {
                if (is_null($modinfo->groups)) {
                    $modinfo->groups = groups_get_user_groups($course->id, $USER->id);
                }
                if (empty($CFG->enablegroupings)) {
                    $forum->onlygroups = $modinfo->groups[0];
                    $forum->onlygroups[] = -1;
                } else {
                    if (isset($modinfo->groups[$cm->groupingid])) {
                        $forum->onlygroups = $modinfo->groups[$cm->groupingid];
                        $forum->onlygroups[] = -1;
                    } else {
                        $forum->onlygroups = array(-1);
                    }
                }
            }
            /// hidden timed discussions
            $forum->viewhiddentimedposts = true;
            if (!empty($CFG->forum_enabletimedposts)) {
                if (!has_capability('mod/forum:viewhiddentimedposts', $context)) {
                    $forum->viewhiddentimedposts = false;
                }
            }
            /// qanda access
            if ($forum->type == 'qanda' && !has_capability('mod/forum:viewqandawithoutposting', $context)) {
                // We need to check whether the user has posted in the qanda forum.
                $forum->onlydiscussions = array();
                // Holds discussion ids for the discussions
                // the user is allowed to see in this forum.
                if ($discussionspostedin = forum_discussions_user_has_posted_in($forum->id, $USER->id)) {
                    foreach ($discussionspostedin as $d) {
                        $forum->onlydiscussions[] = $d->id;
                    }
                }
            }
            $readableforums[$forum->id] = $forum;
        }
        unset($modinfo);
    }
    // End foreach $courses
    //print_object($courses);
    //print_object($readableforums);
    return $readableforums;
}
예제 #17
0
function print_my_moodle()
{
    /// Prints custom user information on the home page.
    /// Over time this can include all sorts of information
    global $USER, $CFG;
    if (empty($USER->id)) {
        error("It shouldn't be possible to see My Moodle without being logged in.");
    }
    $courses = get_my_courses($USER->id, 'visible DESC,sortorder ASC', array('summary'));
    $rhosts = array();
    $rcourses = array();
    if (!empty($CFG->mnet_dispatcher_mode) && $CFG->mnet_dispatcher_mode === 'strict') {
        $rcourses = get_my_remotecourses($USER->id);
        $rhosts = get_my_remotehosts();
    }
    if (!empty($courses) || !empty($rcourses) || !empty($rhosts)) {
        if (!empty($courses)) {
            echo '<ul class="unlist">';
            foreach ($courses as $course) {
                if ($course->id == SITEID) {
                    continue;
                }
                echo '<li>';
                print_course($course);
                echo "</li>\n";
            }
            echo "</ul>\n";
        }
        // MNET
        if (!empty($rcourses)) {
            // at the IDP, we know of all the remote courses
            foreach ($rcourses as $course) {
                print_remote_course($course, "100%");
            }
        } elseif (!empty($rhosts)) {
            // non-IDP, we know of all the remote servers, but not courses
            foreach ($rhosts as $host) {
                print_remote_host($host, "100%");
            }
        }
        unset($course);
        unset($host);
        if (count_records("course") > count($courses) + 1) {
            // Some courses not being displayed
            echo "<table width=\"100%\"><tr><td align=\"center\">";
            print_course_search("", false, "short");
            echo "</td><td align=\"center\">";
            print_single_button("{$CFG->wwwroot}/course/index.php", NULL, get_string("fulllistofcourses"), "get");
            echo "</td></tr></table>\n";
        }
    } else {
        if (count_records("course_categories") > 1) {
            print_simple_box_start("center", "100%", "#FFFFFF", 5, "categorybox");
            print_whole_category_list();
            print_simple_box_end();
        } else {
            print_courses(0);
        }
    }
}
/**
 * This function prints blocks.
 *
 * @uses $CGF, $USER
 * @param int $userid User ID
 * @param int $courseid Course ID
 * @param boolean $printsearchblock Print search block
 * @return NULL
 * @todo Finish documenting this function
 **/
function email_printblocks($userid, $courseid, $printsearchblock = true)
{
    global $CFG, $USER;
    $strcourse = get_string('course');
    $strcourses = get_string('mailboxs', 'block_email_list');
    $strsearch = get_string('search');
    $strmail = get_string('name', 'block_email_list');
    // For title blocks
    $startdivtitle = '<div class="title">';
    $enddivtitle = '</div>';
    $list = array();
    $icons = array();
    if ($printsearchblock) {
        // Print search block
        $form = email_get_search_form($courseid);
        print_side_block_start($startdivtitle . $strsearch . $enddivtitle);
        echo $form;
        print_side_block_end();
    }
    // Print my folders
    email_print_tree_myfolders($userid, $courseid);
    // Remove old fields
    unset($list);
    unset($icons);
    // Get my course
    $mycourses = get_my_courses($USER->id, NULL, 'id, fullname, visible');
    $list = array();
    $icons = array();
    // Get courses
    foreach ($mycourses as $mycourse) {
        $context = get_context_instance(CONTEXT_COURSE, $mycourse->id);
        //Get the number of unread mails
        $numberunreadmails = email_count_unreaded_mails($USER->id, $mycourse->id);
        $unreadmails = '';
        // Only show if has unreaded mails
        if ($numberunreadmails > 0) {
            $unreadmails = '<b>(' . $numberunreadmails . ')</b>';
            // Define default path of icon for course
            $icon = '<img src="' . $CFG->wwwroot . '/blocks/email_list/email/images/openicon.gif" height="16" width="16" alt="' . $strcourse . '" />';
        } else {
            // Define default path of icon for course
            $icon = '<img src="' . $CFG->wwwroot . '/blocks/email_list/email/icon.gif" height="16" width="16" alt="' . $strcourse . '" />';
        }
        $linkcss = $mycourse->visible ? '' : ' class="dimmed" ';
        if (!$mycourse->visible and !has_capability('moodle/legacy:student', $context, $USER->id, false) or !has_capability('moodle/legacy:student', $context, $USER->id, false) or has_capability('moodle/legacy:student', $context, $USER->id, false) and $mycourse->visible) {
            $list[] = '<a href="' . $CFG->wwwroot . '/blocks/email_list/email/index.php?id=' . $mycourse->id . '" ' . $linkcss . '>' . $mycourse->fullname . ' ' . $unreadmails . '</a>';
            $icons[] = $icon;
        }
    }
    // Print block of my courses
    print_side_block($startdivtitle . $strcourses . $enddivtitle, '', $list, $icons);
}
예제 #19
0
 /**
  *
  * Returns all courses that the user with the given id is enrolled
  * in
  *
  * @param int $user_id	the id of the user whose course we will retrieve
  *
  * @return  array of recordset objects or bool false
  */
 function get_user_courses($user_id)
 {
     global $CFG;
     if (stripos($CFG->release, "2.") !== false) {
         $courses = enrol_get_users_courses($user_id, false, NULL, 'fullname DESC');
     } else {
         $courses = get_my_courses($user_id);
     }
     return $courses;
 }
예제 #20
0
파일: lib.php 프로젝트: r007/PMoodle
 function fill_table()
 {
     global $CFG;
     // MDL-11679, only show 'mycourses' instead of all courses
     if ($courses = get_my_courses($this->user->id, 'c.sortorder ASC', 'id, shortname')) {
         $numusers = $this->get_numusers(false);
         foreach ($courses as $course) {
             $courselink = '<a href="' . $CFG->wwwroot . '/grade/report/user/index.php?id=' . $course->id . '">' . $course->shortname . '</a>';
             // Get course grade_item
             $grade_item = grade_item::fetch_course_item($course->id);
             // Get the grade
             $grade = new grade_grade(array('itemid' => $grade_item->id, 'userid' => $this->user->id));
             $grade->grade_item =& $grade_item;
             $finalgrade = $grade->finalgrade;
             // TODO: this DOES NOT work properly if there are any hidden grades,
             //       rank might be wrong & totals might be different from user report!!!
             if ($grade->is_hidden() and !has_capability('moodle/grade:viewhidden', get_context_instance(CONTEXT_COURSE, $course->id))) {
                 $finalgrade = null;
             }
             $data = array($courselink, grade_format_gradevalue($finalgrade, $grade_item, true));
             if (!$this->showrank) {
                 //nothing to do
             } else {
                 if (!is_null($finalgrade)) {
                     /// find the number of users with a higher grade
                     $sql = "SELECT COUNT(DISTINCT(userid))\n                              FROM {$CFG->prefix}grade_grades\n                             WHERE finalgrade IS NOT NULL AND finalgrade > {$finalgrade}\n                                   AND itemid = {$grade_item->id}";
                     $rank = count_records_sql($sql) + 1;
                     $data[] = "{$rank}/{$numusers}";
                 } else {
                     // no grade, no rank
                     $data[] = '-';
                 }
             }
             $this->table->add_data($data);
         }
         return true;
     } else {
         notify(get_string('nocourses', 'grades'));
         return false;
     }
 }
예제 #21
0
 case 'left':
     $blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), 210);
     if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $PAGE->user_is_editing()) {
         echo '<td style="vertical-align: top; width: ' . $blocks_preferred_width . 'px;" id="left-column">';
         print_container_start();
         blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
         print_container_end();
         echo '</td>';
     }
     break;
 case 'middle':
     echo '<td valign="top" id="middle-column">';
     print_container_start(TRUE);
     /// The main overview in the middle of the page
     // limits the number of courses showing up
     $courses = get_my_courses($USER->id, null, '*', false, 21);
     $site = get_site();
     $course = $site;
     //just in case we need the old global $course hack
     if (array_key_exists($site->id, $courses)) {
         unset($courses[$site->id]);
     }
     foreach ($courses as $c) {
         if (isset($USER->lastcourseaccess[$c->id])) {
             $courses[$c->id]->lastaccess = $USER->lastcourseaccess[$c->id];
         } else {
             $courses[$c->id]->lastaccess = 0;
         }
     }
     if (empty($courses)) {
         print_simple_box(get_string('nocourses', 'my'), 'center');
/* fast png fix */
* html .png{
    position:relative;
    behavior: expression((this.runtimeStyle.behavior="none")&&(this.pngSet?this.pngSet=true:(this.nodeName == "IMG" && this.src.toLowerCase().indexOf('.png')>-1?(this.runtimeStyle.backgroundImage = "none",
this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.src + "', sizingMethod='image')",
this.src = "transparent.gif"):(this.origBg = this.origBg? this.origBg :this.currentStyle.backgroundImage.toString().replace('url("','').replace('")',''),
this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.origBg + "', sizingMethod='crop')",
this.runtimeStyle.backgroundImage = "none")),this.pngSet=true));
}

</style>

<?php 
                            if (isloggedin() and !isguest() and isset($CFG->frontpageloggedin)) {
                                $courses = get_my_courses($USER->id, 'visible DESC,sortorder ASC', array('summary'));
                                if (!empty($courses)) {
                                    ?>

                <script type="text/javascript">
                //show5();
                </script>

                <?php 
                                    echo '<h3>Courses:<br/></h3>';
                                    // Setup of Tab Layout
                                    $selected = "class='selected'";
                                    $listitems = "";
                                    $divcourses = "";
                                    //echo "<ul style='list-style-image:none; list-style-position:outside; list-style-type:none; margin:0; padding:10'>";
                                    foreach ($courses as $course) {
예제 #23
0
    //No such user
    die('Invalid authentication');
}
//Check authentication token
if ($authtoken != sha1($username . $user->password)) {
    die('Invalid authentication');
}
$what = optional_param('preset_what', 'all', PARAM_ALPHA);
$time = optional_param('preset_time', 'weeknow', PARAM_ALPHA);
$now = usergetdate(time());
// Let's see if we have sufficient and correct data
$allowed_what = array('all', 'courses');
$allowed_time = array('weeknow', 'weeknext', 'monthnow', 'monthnext', 'recentupcoming');
if (!empty($what) && !empty($time)) {
    if (in_array($what, $allowed_what) && in_array($time, $allowed_time)) {
        $courses = get_my_courses($user->id, NULL, 'id, visible, shortname');
        if ($what == 'all') {
            $users = $user->id;
            $groups = array();
            foreach ($courses as $course) {
                $course_groups = groups_get_all_groups($course->id, $user->id);
                if ($course_groups) {
                    $groups = $groups + array_keys($course_groups);
                }
            }
            if (empty($groups)) {
                $groups = false;
            }
            $courses[SITEID] = new stdClass();
            $courses[SITEID]->shortname = get_string('globalevents', 'calendar');
        } else {
예제 #24
0
function get_all_courses($member_id)
{
    global $system_courses, $db;
    $list = array();
    $num_courses = count($system_courses);
    // add all the courses that are not hidden,then find the hidden courses that you're enrolled in and then add that to array
    foreach ($system_courses as $course_id => $course_info) {
        if (!$course_info['hide']) {
            $list[] = $course_id;
        }
    }
    // if there aren't any hidden courses:
    if (count($system_courses) == count($list)) {
        return $list;
    }
    if ($_SESSION['valid_user']) {
        $my_courses = implode(',', get_my_courses($member_id));
        $sql = "SELECT course_id FROM " . TABLE_PREFIX . "courses WHERE hide=1 AND course_id IN (0, {$my_courses})";
        $result = mysql_query($sql, $db);
        while ($row = mysql_fetch_assoc($result)) {
            $list[] = $row['course_id'];
        }
    }
    return $list;
}
예제 #25
0
파일: lib.php 프로젝트: nadavkav/MoodleTAO
/**
 * Checks to see if a user can view the blogs of another user.
 * Only blog level is checked here, the capabilities are enforced
 * in blog/index.php
 */
function blog_user_can_view_user_post($targetuserid, $blogEntry = null)
{
    global $CFG, $USER;
    if (empty($CFG->bloglevel)) {
        return false;
        // blog system disabled
    }
    // a hack to publish some blogs openly.  Uses $CFG->openblogs = array(44, 322); in config.php
    if (isset($CFG->openblogs) && in_array($targetuserid, $CFG->openblogs)) {
        return true;
    }
    if (!empty($USER->id) and $USER->id == $targetuserid) {
        return true;
        // can view own posts in any case
    }
    $sitecontext = get_context_instance(CONTEXT_SYSTEM);
    if (has_capability('moodle/blog:manageentries', $sitecontext)) {
        return true;
        // can manage all posts
    }
    // coming for 1 post, make sure it's not a draft
    if ($blogEntry and $blogEntry->publishstate == 'draft') {
        return false;
        // can not view draft of others
    }
    // coming for 1 post, make sure user is logged in, if not a public blog
    if ($blogEntry && $blogEntry->publishstate != 'public' && !isloggedin()) {
        return false;
    }
    switch ($CFG->bloglevel) {
        case BLOG_GLOBAL_LEVEL:
            return true;
            break;
        case BLOG_SITE_LEVEL:
            if (!empty($USER->id)) {
                // not logged in viewers forbidden
                return true;
            }
            return false;
            break;
        case BLOG_COURSE_LEVEL:
            $mycourses = array_keys(get_my_courses($USER->id));
            $usercourses = array_keys(get_my_courses($targetuserid));
            $shared = array_intersect($mycourses, $usercourses);
            if (!empty($shared)) {
                return true;
            }
            return false;
            break;
        case BLOG_GROUP_LEVEL:
            $mycourses = array_keys(get_my_courses($USER->id));
            $usercourses = array_keys(get_my_courses($targetuserid));
            $shared = array_intersect($mycourses, $usercourses);
            foreach ($shared as $courseid) {
                $course = get_record('course', 'id', $courseid);
                $coursecontext = get_context_instance(CONTEXT_COURSE, $courseid);
                if (has_capability('moodle/site:accessallgroups', $coursecontext) or groups_get_course_groupmode($course) != SEPARATEGROUPS) {
                    return true;
                } else {
                    if ($usergroups = groups_get_all_groups($courseid, $targetuserid)) {
                        foreach ($usergroups as $usergroup) {
                            if (groups_is_member($usergroup->id)) {
                                return true;
                            }
                        }
                    }
                }
            }
            return false;
            break;
        case BLOG_USER_LEVEL:
        default:
            $personalcontext = get_context_instance(CONTEXT_USER, $targetuserid);
            return has_capability('moodle/user:readuserblogs', $personalcontext);
            break;
    }
}
예제 #26
0
 function get_content()
 {
     global $USER, $CFG, $COURSE;
     // It need update?
     if (email_must_update($this->version)) {
         $this->content = get_string('mustupdate', 'block_email_list');
     }
     // Get course id
     if (!empty($COURSE)) {
         $this->courseid = $COURSE->id;
     }
     // If block have content, skip.
     if ($this->content !== NULL) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->items = array();
     $this->content->icons = array();
     if ($CFG->email_enable_ssl) {
         $wwwroot = str_replace('http:', 'https:', $CFG->wwwroot);
     } else {
         $wwwroot = $CFG->wwwroot;
     }
     // Get context
     $context = get_context_instance(CONTEXT_BLOCK, $this->instance->id);
     $emailicon = '<img src="' . $CFG->wwwroot . '/blocks/email_list/email/images/sobre.png" height="11" width="15" alt="' . get_string("course") . '" />';
     $composeicon = '<img src="' . $CFG->pixpath . '/i/edit.gif" alt="" />';
     // Only show all course in principal course, others, show it
     if ($this->instance->pageid == 1) {
         //Get the courses of the user
         $mycourses = get_my_courses($USER->id);
         $this->content->footer = '<br />' . $emailicon . print_spacer(1, 4, false, true) . '<a href="' . $CFG->wwwroot . '/blocks/email_list/email/">' . get_string('view_all', 'block_email_list') . '</a>';
     } else {
         if (!empty($CFG->mymoodleredirect) and $COURSE->id == 1) {
             //Get the courses of the user
             $mycourses = get_my_courses($USER->id);
             $this->content->footer = '<br />' . $emailicon . print_spacer(1, 4, false, true) . '<a href="' . $CFG->wwwroot . '/blocks/email_list/email/">' . get_string('view_all', 'block_email_list') . '</a>';
         } else {
             // Get this course
             $course = get_record('course', 'id', $this->instance->pageid);
             $mycourses[] = $course;
             $this->content->footer = '<br />' . $emailicon . print_spacer(1, 4, false, true) . '<a href="' . $CFG->wwwroot . '/blocks/email_list/email/index.php?id=' . $course->id . '">' . get_string('view_inbox', 'block_email_list') . '</a>';
             $this->content->footer .= '<br />' . $composeicon . print_spacer(1, 4, false, true) . '<a href="' . $wwwroot . '/blocks/email_list/email/sendmail.php?course=' . $course->id . '&amp;folderid=0&amp;filterid=0&amp;folderoldid=0&amp;action=newmail">' . get_string('compose', 'block_email_list') . '</a>';
         }
     }
     // Count my courses
     $countmycourses = count($mycourses);
     //Configure item and icon for this account
     $icon = '<img src="' . $CFG->wwwroot . '/blocks/email_list/email/images/openicon.gif" height="16" width="16" alt="' . get_string("course") . '" />';
     $number = 0;
     foreach ($mycourses as $mycourse) {
         ++$number;
         // increment for first course
         if ($number > $CFG->email_max_number_courses && !empty($CFG->email_max_number_courses)) {
             continue;
         }
         //Get the number of unread mails
         $numberunreadmails = email_count_unreaded_mails($USER->id, $mycourse->id);
         // Only show if has unreaded mails
         if ($numberunreadmails > 0) {
             $unreadmails = '<b>(' . $numberunreadmails . ')</b>';
             $this->content->items[] = '<a href="' . $CFG->wwwroot . '/blocks/email_list/email/index.php?id=' . $mycourse->id . '">' . $mycourse->fullname . ' ' . $unreadmails . '</a>';
             $this->content->icons[] = $icon;
         }
     }
     if (count($this->content->items) == 0) {
         $this->content->items[] = '<div align="center">' . get_string('emptymailbox', 'block_email_list') . '</div>';
     }
     return $this->content;
 }
예제 #27
0
require_once $CFG->dirroot . '/user/tabs.php';
/// Get the hidden field list
if (has_capability('moodle/course:viewhiddenuserfields', $context)) {
    $hiddenfields = array();
    // teachers and admins are allowed to see everything
} else {
    $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields));
}
if (isset($hiddenfields['lastaccess'])) {
    // do not allow access since filtering
    $accesssince = 0;
}
/// Print settings and things in a table across the top
echo '<table class="controls" cellspacing="0"><tr>';
/// Print my course menus
if ($mycourses = get_my_courses($USER->id)) {
    echo '<td class="left">';
    $courselist = array();
    foreach ($mycourses as $mycourse) {
        $courselist[$mycourse->id] = format_string($mycourse->shortname);
    }
    if (has_capability('moodle/site:viewparticipants', $systemcontext)) {
        unset($courselist[SITEID]);
        $courselist = array(SITEID => format_string($SITE->shortname)) + $courselist;
    }
    popup_form($CFG->wwwroot . '/user/index.php?roleid=' . $roleid . '&amp;sifirst=&amp;silast=&amp;id=', $courselist, 'courseform', $course->id, '', '', '', false, 'self', get_string('mycourses'));
    echo '</td>';
}
echo '<td class="left">';
groups_print_course_menu($course, $baseurl);
echo '</td>';
예제 #28
0
	if ($_GET['include'] == 'all') {
		$predicate = 'AND';
	} else {
		$predicate = 'OR';
	}

	if (($_GET['find_in'] == 'this') && ($_SESSION['course_id'] > 0)) {
		if ($_GET['display_as'] == 'pages') {
			$search_results = get_search_result($_GET['words'], $predicate, $_SESSION['course_id'], $num_found, $total_score);
		} else { // 'courses' or 'summaries' :
			$search_results[$_SESSION['course_id']] = get_search_result($_GET['words'], $predicate, $_SESSION['course_id'], $num_found, $total_score);
			$search_totals[$_SESSION['course_id']]  = $total_score;
		}
	} else {
		if ($_GET['find_in'] == 'my') {
			$my_courses = get_my_courses($_SESSION['member_id']);
		} else { // $_GET['find_in'] == 'all' (or other). always safe to perform.
			$my_courses = get_all_courses($_SESSION['member_id']);
		}

		foreach ($my_courses as $tmp_course_id) {
			if ($_GET['display_as'] == 'pages') {
				// merge all the content results together
				$search_results = array_merge($search_results, get_search_result($_GET['words'], $predicate, $tmp_course_id, $num_found, $total_score));
			} else {
				// group by Course
				$total_score = 0;
				$search_results[$tmp_course_id] = get_search_result($_GET['words'], $predicate, $tmp_course_id, $num_found, $total_score);
				if ($total_score) {
					$search_totals[$tmp_course_id]  = $total_score;
				} // else: no content found in this course.
예제 #29
0
파일: lib.php 프로젝트: kai707/ITSA-backup
function calendar_get_default_courses($ignoreref = false)
{
    global $USER, $CFG, $SESSION;
    if (!empty($SESSION->cal_course_referer) && !$ignoreref) {
        return array($SESSION->cal_course_referer => 1);
    }
    if (empty($USER->id)) {
        return array();
    }
    $courses = array();
    if (has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_SYSTEM))) {
        if (!empty($CFG->calendar_adminseesall)) {
            $courses = get_records_sql('SELECT id, 1 FROM ' . $CFG->prefix . 'course');
            return $courses;
        }
    }
    if (isset($CFG->adminseesall)) {
        $courses = get_my_courses($USER->id, null, null, $CFG->adminseesall);
    } else {
        $courses = get_my_courses($USER->id, null, null, false);
    }
    return $courses;
}
function dcmetadata_search_metadata($searchterms, $courseid, $searchcourseid, $page = 0, $recordsperpage = 50, &$totalcountdc, $extrasql = '')
{
    /// Returns a list of los metadatadc found using an array of search terms
    /// eg   word  +word -word
    ///
    global $CFG, $USER;
    //	require_once('meta_searchlib.php');
    /*
        if (!isteacher($courseid)) {
            $notteacherforum = "AND f.type <> 'teacher'";
            $forummodule = get_record("modules", "name", "forum");
            $onlyvisible = "AND d.forum = f.id AND f.id = cm.instance AND cm.visible = 1 AND cm.module = $forummodule->id";
            $onlyvisibletable = ", {$CFG->prefix}course_modules cm, {$CFG->prefix}forum f";
            if (!empty($sepgroups)) {
                $separategroups = SEPARATEGROUPS;
                $selectgroup = " AND ( NOT (cm.groupmode='$separategroups'".
                                          " OR (c.groupmode='$separategroups' AND c.groupmodeforce='1') )";//.
                $selectgroup .= " OR d.groupid = '-1'"; //search inside discussions for all groups too
                foreach ($sepgroups as $sepgroup){
                    $selectgroup .= " OR d.groupid = '$sepgroup->id'";
                }
                $selectgroup .= ")";
    
                                   //  " OR d.groupid = '$groupid')";
                $selectcourse = " AND d.course = '$courseid' AND c.id='$courseid'";
                $coursetable = ", {$CFG->prefix}course c";
            } else {
                $selectgroup = '';
                $selectcourse = " AND d.course = '$courseid'";
                $coursetable = '';
            }
        } else { */
    //$notteacherforum = "";
    //$selectgroup = '';
    //$onlyvisible = "";
    //$onlyvisibletable = "";
    //$coursetable = '';
    //if ($courseid == SITEID && isadmin()) {
    if ($searchcourseid == '9999') {
        $mycourses = get_my_courses($USER->id);
        foreach ($mycourses as $mycourse) {
            $mcstring = $mcstring . " d.course = '{$mycourse->id}' OR";
        }
        $mcstringfinal = meta_cut_final($mcstring);
        $selectcourse = " AND" . $mcstringfinal;
    } elseif ($searchcourseid == '0') {
        $selectcourse = '';
    } elseif (!$searchcourseid == '9999' | !$searchcourseid == '0' | !empty($searchcourseid)) {
        $selectcourse = " AND d.course = '{$searchcourseid}'";
    } else {
        if ($courseid == SITEID) {
            $selectcourse = '';
        } else {
            $selectcourse = " AND d.course = '{$courseid}'";
        }
    }
    $timelimit = '';
    //    if (!empty($CFG->forum_enabletimedposts) && (!((isadmin() and !empty($CFG->admineditalways)) || isteacher($courseid)))) {
    //if ((!((isadmin() and !empty($CFG->admineditalways)) || isteacher($courseid)))) {
    $now = time();
    //        $timelimit = " AND (d.userid = $USER->id OR ((d.timestart = 0 OR d.timestart <= $now) AND (d.timeend = 0 OR d.timeend > $now)))";
    $timelimit = " AND (d.userid = {$USER->id} OR ((d.timemodified = 0 OR d.timemodified <= {$now}) AND (d.timemodified = 0 OR d.timemodified > {$now})))";
    //     $timelimit = " AND ((d.timemodified <= $now) OR (d.timemodified > $now)))";
    //    }
    $limit = sql_paging_limit($page, $recordsperpage);
    /// Some differences in syntax for PostgreSQL
    if ($CFG->dbtype == "postgres7") {
        $LIKE = "ILIKE";
        // case-insensitive
        $NOTLIKE = "NOT ILIKE";
        // case-insensitive
        $REGEXP = "~*";
        $NOTREGEXP = "!~*";
    } else {
        $LIKE = "LIKE";
        $NOTLIKE = "NOT LIKE";
        $REGEXP = "REGEXP";
        $NOTREGEXP = "NOT REGEXP";
    }
    $metasearch = "";
    $searchstring = "";
    // Need to concat these back together for parser to work.
    foreach ($searchterms as $searchterm) {
        if ($searchstring != "") {
            $searchstring .= " ";
        }
        $searchstring .= $searchterm;
    }
    // We need to allow quoted strings for the search. The quotes *should* be stripped
    // by the parser, but this should be examined carefully for security implications.
    $searchstring = str_replace("\\\"", "\"", $searchstring);
    $parser = new search_parser();
    $lexer = new search_lexer($parser);
    if ($lexer->parse($searchstring)) {
        $parsearray = $parser->get_parsed_array();
        //search_generate_sql($parsetree, $datafield, $metafield, $mainidfield, $useridfield,$userfirstnamefield, $userlastnamefield, $timefield, $instancefield)
        //$messagesearch = search_generate_SQL($parsearray,'p.message','p.subject','p.userid','u.id','u.firstname','u.lastname','p.modified', 'd.forum');
        $metasearch = metasearch_generate_SQL($parsearray, 'd.title', 'd.alternative', 'd.type', 'd.format', 'd.audience', 'd.instructionalMethod', 'd.subject', 'd.description', 'd.abstract', 'd.tableOfContents', 'd.bibliographicCitation', 'd.coverage', 'd.creator', 'd.publisher', 'd.contributor', 'd.userid', 'd.timemodified', '');
    }
    //'cm.modnameid','d.timemodified','d.course');
    /*
        $selectsql = "{$CFG->prefix}forum_posts p,
                      {$CFG->prefix}forum_discussions d,
                      {$CFG->prefix}user u $onlyvisibletable $coursetable
                 WHERE ($messagesearch)
                   AND p.userid = u.id
                   AND p.discussion = d.id $selectcourse $notteacherforum $onlyvisible $selectgroup $timelimit $extrasql";
    
        $totalcount = count_records_sql("SELECT COUNT(*) FROM $selectsql");
    
        return get_records_sql("SELECT p.*,d.forum, u.firstname,u.lastname,u.email,u.picture FROM
                                $selectsql ORDER BY p.modified DESC $limit");
    */
    $selectsql = "{$CFG->prefix}metadatadc d\r\n             WHERE ({$metasearch})\r\n               \t\t{$selectcourse} {$extrasql}";
    //AND cm.course = d.course AND d.resource = cm.modnameid $selectcourse $extrasql";				  {$CFG->prefix}course_module cm
    $totalcountdc = count_records_sql("SELECT COUNT(*) FROM {$selectsql}");
    return get_records_sql("SELECT d.* FROM\r\n                            {$selectsql} ORDER BY d.course, d.timemodified DESC {$limit}");
}