コード例 #1
0
ファイル: user.php プロジェクト: patkira/mahara
/**
 * Get user records for online users page
 *
 * @param integer $limit
 * @param integer $offset
 *
 * @returns array Total number of users, along with $limit or fewer user records.
 */
function get_onlineusers($limit = 10, $offset = 0, $orderby = 'firstname,lastname')
{
    global $USER;
    // Determine what level of users to show
    // 0 = none, 1 = institution/s only, 2 = all users
    $showusers = 2;
    $institutions = $USER->institutions;
    if (!empty($institutions)) {
        $showusers = 0;
        foreach ($institutions as $i) {
            if ($i->showonlineusers == 2) {
                $showusers = 2;
                break;
            }
            if ($i->showonlineusers == 1) {
                $showusers = 1;
            }
        }
    }
    $result = array('count' => 0, 'limit' => $limit, 'offset' => $offset, 'data' => false);
    switch ($showusers) {
        case 0:
            // show none
            return $result;
        case 1:
            // show institution only
            $sql = "SELECT DISTINCT u.* FROM {usr} u JOIN {usr_institution} i ON id = i.usr\n                WHERE deleted = 0 AND lastaccess > ? AND i.institution IN (" . join(',', array_map('db_quote', array_keys($institutions))) . ")\n                ORDER BY {$orderby}";
            $countsql = 'SELECT count(DISTINCT id) FROM {usr} JOIN {usr_institution} i ON id = i.usr
                WHERE deleted = 0 AND lastaccess > ? AND i.institution IN (' . join(',', array_map('db_quote', array_keys($institutions))) . ')';
            break;
        case 2:
            // show all
            $sql = "SELECT * FROM {usr} WHERE deleted = 0 AND lastaccess > ? ORDER BY {$orderby}";
            $countsql = 'SELECT count(id) FROM {usr} WHERE deleted = 0 AND lastaccess > ?';
            break;
    }
    $lastaccess = db_format_timestamp(time() - get_config('accessidletimeout'));
    if (!($result['count'] = count_records_sql($countsql, array($lastaccess)))) {
        return $result;
    }
    $onlineusers = get_records_sql_array($sql, array($lastaccess), $offset, $limit);
    if ($onlineusers) {
        foreach ($onlineusers as &$user) {
            $user->profileiconurl = profile_icon_url($user, 20, 20);
            // If the user is an MNET user, show where they've come from
            $authobj = AuthFactory::create($user->authinstance);
            if ($authobj->authname == 'xmlrpc') {
                $peer = get_peer($authobj->wwwroot);
                $user->loggedinfrom = $peer->name;
            }
        }
    } else {
        $onlineusers = array();
    }
    $result['data'] = array_map(create_function('$a', 'return $a->id;'), $onlineusers);
    return $result;
}
コード例 #2
0
ファイル: mahara.php プロジェクト: kienv/mahara
/**
 * Gets data about users who have been online in the last while.
 *
 * The time is configured by setting the 'accessidletimeout' configuration
 * option.
 *
 * Limits the number of users to display based on the 'onlineuserssideblockmaxusers'
 * site configuration option and the Institution specific 'showonlineusers' setting.
 * If the user belongs to no institution (other than the standard 'mahara' one) then
 * the decision will be to show ALL users by default.
 *
 */
function onlineusers_sideblock()
{
    global $USER;
    // Determine what level of users to show
    // 0 = none, 1 = institution/s only, 2 = all users
    $showusers = 2;
    $institutions = $USER->institutions;
    if (!empty($institutions)) {
        $showusers = 0;
        foreach ($institutions as $i) {
            if ($i->showonlineusers == 2) {
                $showusers = 2;
                break;
            }
            if ($i->showonlineusers == 1) {
                $showusers = 1;
            }
        }
    }
    $maxonlineusers = get_config('onlineuserssideblockmaxusers');
    switch ($showusers) {
        case 0:
            // show none
            return array('users' => array(), 'count' => 0, 'lastminutes' => floor(get_config('accessidletimeout') / 60));
        case 1:
            // show institution only
            $sql = 'SELECT DISTINCT u.* FROM {usr} u JOIN {usr_institution} i ON u.id = i.usr
                WHERE i.institution IN (' . join(',', array_map('db_quote', array_keys($institutions))) . ')
                AND lastaccess > ? AND deleted = 0 ORDER BY lastaccess DESC';
            break;
        case 2:
            // show all
            $sql = 'SELECT * FROM {usr} WHERE lastaccess > ? AND deleted = 0 ORDER BY lastaccess DESC';
            break;
    }
    $onlineusers = get_records_sql_array($sql, array(db_format_timestamp(time() - get_config('accessidletimeout'))), 0, $maxonlineusers);
    if ($onlineusers) {
        foreach ($onlineusers as &$user) {
            $user->profileiconurl = profile_icon_url($user, 20, 20);
            // If the user is an MNET user, show where they've come from
            $authobj = AuthFactory::create($user->authinstance);
            if ($authobj->authname == 'xmlrpc') {
                $peer = get_peer($authobj->wwwroot);
                $user->loggedinfrom = $peer->name;
            }
        }
    } else {
        $onlineusers = array();
    }
    return array('users' => $onlineusers, 'count' => count($onlineusers), 'lastminutes' => floor(get_config('accessidletimeout') / 60));
}
コード例 #3
0
ファイル: index.php プロジェクト: patkira/mahara
function get_desired_fields(&$allfields, $desiredfields, $section)
{
    global $USER;
    if ($section == 'about') {
        $r = get_record_select('view', 'type = ? AND owner = ?', array('profile', $USER->id), 'id');
        $label = '<div id="profileicon" class="profile-icon pseudolabel pull-left"><a href="' . get_config('wwwroot') . 'artefact/file/profileicons.php" class="user-icon"><img src="' . profile_icon_url($USER, 100, 100) . '" alt="' . get_string("editprofileicon", "artefact.file") . '"></a></div>';
        $descr = '' . get_string('aboutprofilelinkdescription', 'artefact.internal', get_config('wwwroot') . 'view/blocks.php?id=' . $r->id);
        $descr .= '<p>' . get_string('aboutdescription', 'artefact.internal') . '</p>';
    } else {
        $label = '';
        $descr = get_string('infoisprivate', 'artefact.internal');
    }
    $return = array("{$section}description" => array('type' => 'html', 'labelhtml' => $label, 'value' => $descr));
    foreach ($desiredfields as $field) {
        if (isset($allfields[$field])) {
            $return[$field] = $allfields[$field];
            unset($allfields[$field]);
        }
    }
    return $return;
}
コード例 #4
0
/**
 * Dwoo {profile_icon_url} function plugin
 *
 * Type:     function<br>
 * Date:     June 22, 2006<br>
 * Purpose:  Display a user's profile icon according to mahara rules
 * @author   Catalyst IT Ltd
 * @version  1.0
 */
function Dwoo_Plugin_profile_icon_url(Dwoo $dwoo, $user, $maxwidth, $maxheight)
{
    return profile_icon_url($user, $maxwidth, $maxheight);
}
コード例 #5
0
    /**
     * This function returns a list of browsable items.
     *
     * @param limit how many items to display per page
     * @param offset current page to display
     * @return array (count: integer, data: array)
     */

    public static function get_browsable_items($filters, $offset=0, $limit=20) {
        global $USER;

        $contents = array();
        $texttitletrim = 20;
        $onetimeclause = false;
        $count = 0;

        if (is_postgres()) {
            $selectclause =  'SELECT *
                              FROM (
                                    SELECT DISTINCT ON (va.view) va.view, a.id, v.mtime, v.owner';
            $grouporderclause = ') p
                                  ORDER BY mtime DESC';
        }
        else if (is_mysql()) {
            $selectclause =  'SELECT va.view, a.id, v.mtime, v.owner';
            $grouporderclause = 'GROUP BY va.view
                                 ORDER BY a.mtime DESC';
        }
        $fromclause =       ' FROM {view_access} va';
        $joinclause =       " INNER JOIN {view} v ON (va.view = v.id AND v.type = 'profile')";
        $join2clause =      " JOIN {view_artefact} var ON v.id = var.view";
        $join3clause =      " JOIN {artefact} a ON (a.artefacttype = 'image' AND a.id = var.artefact)";
        $join4clause =      '';
        $whereclause =      ' WHERE (v.owner > 0)';
        $andclause =        " AND (v.startdate IS NULL OR v.startdate < current_timestamp)
        AND (v.stopdate IS NULL OR v.stopdate > current_timestamp)
        AND (va.startdate IS NULL OR va.startdate < current_timestamp)
        AND (va.stopdate IS NULL OR va.stopdate > current_timestamp)";

        foreach ($filters as $filterkey => $filterval) {

            switch ($filterkey) {

                case 'keyword':
                    $join4clause = ' LEFT JOIN {usr} u ON u.id = v.owner';
                    // replace spaces with commas so that we can search on each term separately
                    $filterval = str_replace(' ', ',', $filterval);
                    $keywords = explode(",", $filterval);
                    if (count($keywords) == 1 ) {
                        $andclause .= " AND (
                        LOWER(u.firstname) LIKE LOWER('%$filterval%')
                        OR LOWER(u.lastname) LIKE LOWER('%$filterval%')
                        OR LOWER(u.preferredname) LIKE LOWER('%$filterval%')
                        )";
                    } else {
                        foreach($keywords as $key => $word) {
                            if ($key == 0) {
                                $andclause .= " AND ((
                                LOWER(u.firstname) LIKE LOWER('%$word%')
                                OR LOWER(u.lastname) LIKE LOWER('%$word%')
                                OR LOWER(u.preferredname) LIKE LOWER('%$word%')
                                )";
                            } else {
                                $andclause .= " AND (
                                LOWER(u.firstname) LIKE LOWER('%$word%')
                                OR LOWER(u.lastname) LIKE LOWER('%$word%')
                                OR LOWER(u.preferredname) LIKE LOWER('%$word%')
                                )";
                            }
                            if ($key == count($keywords)-1) {
                                $andclause .= ')';
                            }
                        }
                    }
                    break;
                case 'college' :
                    if (!empty($filterval) && !$onetimeclause) {
                        $join4clause .= ' JOIN {usr_enrolment} e ON e.usr = v.owner';
                        $selectclause .= ', e.college, e.course';
                        $ontimeclause = true;
                    }
                    $andclause .= " AND e.college IN ($filterval)";
                    break;
                case 'course' :
                     if (!empty($filterval) && !$onetimeclause) {
                        $join4clause .= ' JOIN {usr_enrolment} e ON e.usr = v.owner';
                        $selectclause .= ', e.college, e.course';
                        $ontimeclause = true;
                    }
                    $courseidgroups = explode(";", $filterval);
                    if (count($courseidgroups) == 1) {
                        // one course submitted, could have multiple csv ids if selected by name
                        $courseids = explode(",", $courseidgroups[0]);
                        if (count($courseids) == 1 ) {
                            $andclause .= " AND (e.course LIKE '%$courseids[0]%' AND e.usr = v.owner)";
                        } else if (count($courseids) > 1 ) {
                            foreach($courseids as $key => $id) {
                                if ($key == 0) {
                                    $andclause .= " AND (e.course LIKE '%$id%'";
                                } else {
                                    $andclause .= " OR e.course LIKE '%$id%'";
                                }
                                if ($key == count($courseids)-1) {
                                    $andclause .= ')';
                                }
                            }
                        }
                    } else if (count($courseidgroups) > 1) {
                        // more than one course submitted
                        foreach($courseidgroups as $key => $coursegroup) {

                            if ($key == 0) {
                                $courseids = explode(",", $coursegroup);
                                if (count($courseids) == 1 ) {
                                    $andclause .= " AND ((e.course LIKE '%$courseids[0]%')";
                                } else if (count($courseids) > 1 ) {
                                    foreach($courseids as $key => $id) {
                                        if ($key == 0) {
                                            $andclause .= " AND ((e.course LIKE '%$id%'";
                                        } else {
                                            $andclause .= " OR e.course LIKE '%$id%'";
                                        }
                                        if ($key == count($courseids)-1) {
                                            $andclause .= ')';
                                        }
                                    }
                                }

                            } else {
                                // key != 0
                                $courseids = explode(",", $coursegroup);
                                if (count($courseids) == 1 ) {
                                    $andclause .= " AND (e.course LIKE '%$courseids[0]%')";
                                } else if (count($courseids) > 1 ) {
                                    foreach($courseids as $key => $id) {
                                        if ($key == 0) {
                                            $andclause .= " AND (e.course LIKE '%$id%'";
                                        } else {
                                            $andclause .= " OR e.course LIKE '%$id%'";
                                        }
                                        if ($key == count($courseids)-1) {
                                            $andclause .= ')';
                                        }
                                    }
                                }
                            }
                        }
                    }
                    break;
            }
        }

        /**
        * The query checks for profile page images.
        */
        $profileimagesids = get_records_sql_array("
                $selectclause
                $fromclause
                $joinclause
                $join2clause
                $join3clause
                $join4clause
                $whereclause
                $andclause
                $grouporderclause
                ", array(), $offset, $limit);

        if ($profileimagesids) {
            foreach ($profileimagesids as $key => $profileimageid) {
                $view = new View($profileimageid->view);
                $view->set('dirty', false);
                $fullurl = $view->get_url();
                $avatarurl = profile_icon_url($profileimageid->owner,50,50);
                $pagetitle = str_shorten_text(display_name($profileimageid->owner), $texttitletrim, true);
                $contents['profiles'][] = array("id" => "p" . $profileimageid->id,
                                    "type" => "profile",
                                    "image" => array(
                                                "id" => $profileimageid->id,
                                                "view" => $profileimageid->view
                                            ),
                                    "page" => array(
                                                "url" => $fullurl,
                                                "title" => $pagetitle
                                    ),
                                    "owner" => array(
                                            "avatarurl" => $avatarurl
                                    )
                                );
            } // foreach
        }

        if ($profileimagesids) {
            $allprofileswithimages = get_records_sql_array("
                    SELECT va.view
                    $fromclause
                    $joinclause
                    $join2clause
                    $join3clause
                    $join4clause
                    $whereclause
                    $andclause
                    GROUP BY va.view
                    ", array());
            $count = count($allprofileswithimages);
        }

        $items = array(
                'count'  => $count,
                'data'   => $contents,
                'offset' => $offset,
                'limit'  => $limit,
        );
        return $items;
    }
コード例 #6
0
 /** Code copied from blocktype::groupviews **/
 public static function get_data($groupid, $offset = 0, $limit = 20)
 {
     global $USER;
     $texttitletrim = 20;
     $items2 = null;
     if (!defined('GROUP')) {
         define('GROUP', $groupid);
     }
     // get the currently requested group
     $group = group_current_group();
     $role = group_user_access($group->id);
     if ($role) {
         // For group members, display a list of views that others have shared to the group
         // Params for get_sharedviews_data is $limit=0,$offset=0, $groupid
         $data['sharedviews'] = View::get_sharedviews_data($limit, $offset, $group->id);
         /*
         foreach ($data['sharedviews']->data as &$view) {
         	if (isset($view['template']) && $view['template']) {
         		$view['form'] = pieform(create_view_form($group, null, $view->id));
         	}				
                     }
         */
         //the array that is returned from View::get_sharedviews_data($limit, $offset, $group->id)
         //contains a few other things but we just wanted to focus on sharedviews
         //the foreach below will loop through all views shared with the group
         foreach ($data['sharedviews'] as $aView) {
             if (is_array($aView)) {
                 //20140909 JW sort the array returned by View::get_sharedviews_data($limit, $offset, $group->id)
                 //by ctime, this requires the query within get_sharedviews_data to have ctime in its select string
                 $aView = self::array_msort($aView, array('ctime' => SORT_DESC));
                 //the foreach below will loop through all the properties for a view (returned by get_data method) and assigns them to the required variables
                 foreach ($aView as $aViewProperty) {
                     //get the view
                     $viewID = $aViewProperty['id'];
                     //the page shared
                     $fullurl = $aViewProperty['fullurl'];
                     //full url of the page shared
                     $viewTitle = str_shorten_text($aViewProperty['displaytitle'], $texttitletrim, true);
                     //view's title
                     //get the owner of the view
                     $viewOwnerName = $aViewProperty['user']->firstname . " " . $aViewProperty['user']->lastname;
                     //owner of the view's name
                     $userobj = new User();
                     $userobj->find_by_id($aViewProperty['user']->id);
                     $profileurl = profile_url($userobj);
                     //owner of the view's proflie page
                     $avatarurl = profile_icon_url($aViewProperty['user']->id, 50, 50);
                     //owner of the view's profile picture
                     //get the artefact id of an image in the view
                     $theView = new View($aViewProperty['id']);
                     //create the view
                     $artefactInView = $theView->get_artefact_metadata();
                     //get all artefacts in the view
                     foreach ($artefactInView as $anArtefact) {
                         //for each artefact
                         if ($anArtefact->artefacttype == 'image') {
                             $artefactID = $anArtefact->id;
                             //if it is an image artefact assign the id and break the loop
                             break;
                         }
                         //20150331 JW added that if page contains a folder with images (galleries count as folders)
                         //it will pull an image from that folder and use it as the cover
                         if ($anArtefact->artefacttype == 'folder') {
                             $query = "SELECT id FROM {artefact} where parent = ? AND artefacttype = 'image'";
                             $imagesInAFolder = get_records_sql_array($query, array($anArtefact->id));
                             //only assign the id of an image if the folder contains at least 1 image
                             if (!empty($imagesInAFolder)) {
                                 $artefactID = $imagesInAFolder[0]->id;
                                 break;
                             }
                         }
                         //20140903 JW if there are no images on the page then set to artefactID to 0
                         //this way, when display each page, instead of a blank box it will show a place holder image
                         $artefactID = 0;
                     }
                     //the items variable below requires the contents array to be in this format
                     $contents['photos'][] = array("image" => array("id" => $artefactID, "view" => $viewID), "type" => "photo", "page" => array("url" => $fullurl, "title" => $viewTitle), "owner" => array("name" => $viewOwnerName, "profileurl" => $profileurl, "avatarurl" => $avatarurl));
                 }
             }
         }
         //20150723 JW added the if statement to check if $content is set, if not then skip
         if (isset($contents)) {
             $items2 = array('count' => $data['sharedviews']->count, 'data' => $contents, 'offset' => $offset, 'limit' => $limit);
         }
     }
     //$data['group'] = $group;
     return $items2;
 }
コード例 #7
0
/**
 * Gets data about users who have been online in the last while.
 *
 * The time is configured by setting the 'accessidletimeout' configuration 
 * option.
 *
 * NOTE: currently returns all online users, this might not be desirable on a 
 * really busy site.
 */
function onlineusers_sideblock()
{
    global $USER;
    $onlineusers = get_records_select_array('usr', 'deleted = 0 AND lastaccess > ?', array(db_format_timestamp(time() - get_config('accessidletimeout'))), 'lastaccess DESC');
    if ($onlineusers) {
        foreach ($onlineusers as &$user) {
            if ($user->id == $USER->get('id')) {
                // Use a shorter caching time for the current user, just in case they change their profile icon
                $user->profileiconurl = get_config('wwwroot') . 'thumb.php?type=profileicon&id=' . $user->id . '&maxheight=20&maxwidth=20&earlyexpiry=1';
            } else {
                $user->profileiconurl = profile_icon_url($user, 20, 20);
            }
            // If the user is an MNET user, show where they've come from
            $authobj = AuthFactory::create($user->authinstance);
            if ($authobj->authname == 'xmlrpc') {
                $peer = get_peer($authobj->wwwroot);
                $user->loggedinfrom = $peer->name;
            }
        }
    } else {
        $onlineusers = array();
    }
    return array('users' => $onlineusers, 'count' => count($onlineusers), 'lastminutes' => floor(get_config('accessidletimeout') / 60));
}