コード例 #1
0
ファイル: requestfriendship.php プロジェクト: rboyatt/mahara
function requestfriendship_submit(Pieform $form, $values)
{
    global $USER, $SESSION, $id, $goto;
    $loggedinid = $USER->get('id');
    $user = get_record('usr', 'id', $id);
    // friend db record
    $f = new StdClass();
    $f->ctime = db_format_timestamp(time());
    // notification info
    $n = new StdClass();
    $n->url = profile_url($USER, false);
    $n->users = array($user->id);
    $n->fromuser = $loggedinid;
    $lang = get_user_language($user->id);
    $displayname = display_name($USER, $user);
    $n->strings = new stdClass();
    $n->strings->urltext = (object) array('key' => 'Requests');
    $f->owner = $id;
    $f->requester = $loggedinid;
    $f->message = $values['message'];
    insert_record('usr_friend_request', $f);
    $n->subject = get_string_from_language($lang, 'requestedfriendlistsubject', 'group');
    if (isset($values['message']) && !empty($values['message'])) {
        $n->message = get_string_from_language($lang, 'requestedfriendlistmessageexplanation', 'group', $displayname) . $values['message'];
    } else {
        $n->message = get_string_from_language($lang, 'requestedfriendlistinboxmessage', 'group', $displayname);
    }
    require_once 'activity.php';
    activity_occurred('maharamessage', $n);
    handle_event('addfriendrequest', array('requester' => $loggedinid, 'owner' => $id));
    $SESSION->add_ok_msg(get_string('friendformrequestsuccess', 'group', display_name($id)));
    redirect($goto);
}
コード例 #2
0
ファイル: lib.php プロジェクト: Br3nda/mahara
 public function assign_smarty_vars()
 {
     $this->smarty->assign('artefacttype', 'internal');
     $this->smarty->assign('artefactplugin', 'internal');
     $this->smarty->assign('title', display_name($this->get('exporter')->get('user'), $this->get('exporter')->get('user')));
     // If this ID is changed, you'll have to change it in author.tpl too
     $this->smarty->assign('id', 'portfolio:artefactinternal');
     $this->smarty->assign('leaptype', $this->get_leap_type());
     $persondata = array();
     $spacialdata = array();
     foreach ($this->artefacts as $a) {
         if (!($data = $this->data_mapping($a))) {
             if ($a->get('artefacttype') == 'introduction') {
                 $this->smarty->assign('contenttype', 'html');
                 $this->smarty->assign('content', clean_html($a->get('title')));
             }
             continue;
         }
         $value = $a->render_self(array());
         $value = $value['html'];
         // TODO fix this when we non-js stuff
         $data = array_merge(array('value' => $value, 'artefacttype' => $a->get('artefacttype'), 'artefactplugin' => 'internal'), $data);
         if (array_key_exists('spacial', $data)) {
             $spacialdata[] = (object) $data;
         } else {
             $data = array_merge($data, array('label' => get_string($a->get('artefacttype'), 'artefact.internal')));
             $persondata[] = (object) $data;
         }
     }
     if ($extras = $this->exporter->get('extrapersondata')) {
         $persondata = array_merge($persondata, $extras);
     }
     $this->smarty->assign('persondata', $persondata);
     $this->smarty->assign('spacialdata', $spacialdata);
 }
コード例 #3
0
ファイル: lib.php プロジェクト: Br3nda/mahara
 public static function notify_user($user, $data)
 {
     $lang = empty($user->lang) || $user->lang == 'default' ? get_config('lang') : $user->lang;
     $separator = str_repeat('-', 72);
     $sitename = get_config('sitename');
     $subject = get_string_from_language($lang, 'emailsubject', 'notification.email', $sitename);
     if (!empty($data->subject)) {
         $subject .= ': ' . $data->subject;
     }
     $messagebody = get_string_from_language($lang, 'emailheader', 'notification.email', $sitename) . "\n";
     $messagebody .= $separator . "\n\n";
     $messagebody .= get_string_from_language($lang, 'subject') . ': ' . $data->subject . "\n\n";
     if ($data->activityname == 'usermessage') {
         // Do not include the message body in user messages when they are sent by email
         // because it encourages people to reply to the email.
         $messagebody .= get_string_from_language($lang, 'newusermessageemailbody', 'group', display_name($data->userfrom), $data->url);
     } else {
         $messagebody .= $data->message;
         if (!empty($data->url)) {
             $messagebody .= "\n\n" . get_string_from_language($lang, 'referurl', 'notification.email', $data->url);
         }
     }
     if (isset($data->unsubscribeurl) && isset($data->unsubscribename)) {
         $messagebody .= "\n\n" . get_string_from_language($lang, 'unsubscribemessage', 'notification.email', $data->unsubscribename, $data->unsubscribeurl);
     }
     $messagebody .= "\n\n{$separator}";
     $prefurl = get_config('wwwroot') . 'account/activity/preferences/';
     $messagebody .= "\n\n" . get_string_from_language($lang, 'emailfooter', 'notification.email', $sitename, $prefurl);
     email_user($user, null, $subject, $messagebody, null, !empty($data->customheaders) ? $data->customheaders : null);
 }
コード例 #4
0
/**
 * Dwoo {display_name} function plugin
 *
 * Type:     function<br>
 * Date:     June 22, 2006<br>
 * Purpose:  Display a user's name according to mahara rules
 * @author   Catalyst IT Ltd
 * @version  1.0
 */
function Dwoo_Plugin_display_name(Dwoo $dwoo, $user, $userto = null, $nameonly = false, $realname = false)
{
    if (!$user) {
        return '';
    }
    return hsc(display_name($user, $userto, $nameonly, $realname));
}
コード例 #5
0
 public static function notify_user($user, $data)
 {
     $messagehtml = null;
     if (!empty($data->overridemessagecontents)) {
         $subject = $data->subject;
         if (!empty($data->emailmessage)) {
             $messagebody = $data->emailmessage;
         } else {
             if (!empty($user->emailmessage)) {
                 $messagebody = $user->emailmessage;
             } else {
                 $messagebody = $data->message;
             }
         }
         if (!empty($data->htmlmessage)) {
             $messagehtml = $data->htmlmessage;
         } else {
             if (!empty($user->htmlmessage)) {
                 $messagehtml = $user->htmlmessage;
             }
         }
     } else {
         $lang = empty($user->lang) || $user->lang == 'default' ? get_config('lang') : $user->lang;
         $separator = str_repeat('-', 72);
         $sitename = get_config('sitename');
         $subject = get_string_from_language($lang, 'emailsubject', 'notification.email', $sitename);
         if (!empty($data->subject)) {
             $subject .= ': ' . $data->subject;
         }
         $messagebody = get_string_from_language($lang, 'emailheader', 'notification.email', $sitename) . "\n";
         $messagebody .= $separator . "\n\n";
         $messagebody .= get_string_from_language($lang, 'subject') . ': ' . $data->subject . "\n\n";
         if ($data->url && stripos($data->url, 'http://') !== 0 && stripos($data->url, 'https://') !== 0) {
             $data->url = get_config('wwwroot') . $data->url;
         }
         if ($data->activityname == 'usermessage') {
             // Do not include the message body in user messages when they are sent by email
             // because it encourages people to reply to the email.
             $messagebody .= get_string_from_language($lang, 'newusermessageemailbody', 'group', display_name($data->userfrom), $data->url);
         } else {
             $messagebody .= $data->message;
             if (!empty($data->url)) {
                 $messagebody .= "\n\n" . get_string_from_language($lang, 'referurl', 'notification.email', $data->url);
             }
         }
         $messagebody .= "\n\n{$separator}";
         $prefurl = get_config('wwwroot') . 'account/activity/preferences/index.php';
         $messagebody .= "\n\n" . get_string_from_language($lang, 'emailfooter', 'notification.email', $sitename, $prefurl);
     }
     // Bug 738263: Put the user's email address in the Reply-to field; email_user() will put the site address in 'From:'
     $userfrom = null;
     if (!empty($data->fromuser) && !$data->hideemail) {
         $user_data = get_record('usr', 'id', $data->fromuser);
         if (empty($data->customheaders)) {
             $data->customheaders = array();
         }
         $data->customheaders[] = "Reply-to: {$user_data->email}";
     }
     email_user($user, $userfrom, $subject, $messagebody, $messagehtml, !empty($data->customheaders) ? $data->customheaders : null);
 }
コード例 #6
0
 public static function getRecordDataById($type, $id)
 {
     $sql = 'SELECT c.id, c.name, c.ctime, c.description, cv.view AS viewid, c.owner
     FROM {collectio}n c
     LEFT OUTER JOIN {collection_view} cv ON cv.collection = c.id
     WHERE id = ? ORDER BY cv.displayorder asc LIMIT 1;';
     $record = get_record_sql($sql, array($id));
     if (!$record) {
         return false;
     }
     $record->name = str_replace(array("\r\n", "\n", "\r"), ' ', strip_tags($record->name));
     $record->description = str_replace(array("\r\n", "\n", "\r"), ' ', strip_tags($record->description));
     //  Created by
     if (intval($record->owner) > 0) {
         $record->createdby = get_record('usr', 'id', $record->owner);
         $record->createdbyname = display_name($record->createdby);
     }
     // Get all views included in that collection
     $sql = 'SELECT v.id, v.title
     FROM {view} v
     LEFT OUTER JOIN {collection_view} cv ON cv.view = v.id
     WHERE cv.collection = ?';
     $views = recordset_to_array(get_recordset_sql($sql, array($id)));
     if ($views) {
         $record_views = array();
         foreach ($views as $view) {
             if (isset($view->id)) {
                 $record_views[$view->id] = $view->title;
             }
         }
         $record->views = $record_views;
     }
     return $record;
 }
コード例 #7
0
/**
 * Smarty {display_name} function plugin
 *
 * Type:     function<br>
 * Name:     str<br>
 * Date:     June 22, 2006<br>
 * Purpose:  Display a user's name according to mahara rules
 * @author   Catalyst IT Ltd
 * @version  1.0
 * @param array
 * @param Smarty
 * @return Internationalized string
 */
function smarty_function_display_name($params, &$smarty)
{
    static $dictionary;
    if (!isset($params['user']) || !is_object($params['user'])) {
        return '';
    }
    return display_name($params['user']);
}
コード例 #8
0
ファイル: lib.php プロジェクト: vohung96/mahara
 public static function override_instance_title(BlockInstance $instance)
 {
     global $USER;
     $ownerid = $instance->get_view()->get('owner');
     if ($ownerid === null || $ownerid == $USER->get('id')) {
         return get_string('title', 'blocktype.myviews');
     }
     return get_string('otherusertitle', 'blocktype.myviews', display_name($ownerid, null, true));
 }
コード例 #9
0
 public function assign_smarty_vars()
 {
     $user = $this->get('exporter')->get('user');
     $userid = $user->get('id');
     $updated = get_record_sql('select ' . db_format_tsfield('max(mtime)', 'mtime') . ' from {artefact} a join {artefact_installed_type} t on a.artefacttype = t.name where t.plugin = \'internal\'');
     $this->smarty->assign('artefacttype', 'internal');
     $this->smarty->assign('artefactplugin', 'internal');
     $this->smarty->assign('title', display_name($user, $user));
     $this->smarty->assign('updated', PluginExportLeap::format_rfc3339_date($updated->mtime));
     // If this ID is changed, you'll have to change it in author.tpl too
     $this->smarty->assign('id', 'portfolio:artefactinternal');
     $this->smarty->assign('leaptype', $this->get_leap_type());
     $persondata = array();
     $spacialdata = array();
     usort($this->artefacts, array($this, 'artefact_sort'));
     foreach ($this->artefacts as $a) {
         if (!($data = $this->data_mapping($a))) {
             if ($a->get('artefacttype') == 'introduction') {
                 $this->smarty->assign('contenttype', 'html');
                 $this->smarty->assign('content', clean_html($a->get('title')));
             }
             continue;
         }
         $value = $a->render_self(array());
         $value = $value['html'];
         // TODO fix this when we non-js stuff
         $data = array_merge(array('value' => $value, 'artefacttype' => $a->get('artefacttype'), 'artefactplugin' => 'internal'), $data);
         if (array_key_exists('spacial', $data)) {
             $spacialdata[] = (object) $data;
         } else {
             $label = get_string($a->get('artefacttype'), 'artefact.internal');
             if ($a->get('artefacttype') == 'socialprofile') {
                 $label = $a->get('description');
             }
             $data = array_merge($data, array('label' => $label));
             $persondata[] = (object) $data;
         }
     }
     if ($extras = $this->exporter->get('extrapersondata')) {
         $persondata = array_merge($persondata, $extras);
     }
     $this->smarty->assign('persondata', $persondata);
     $this->smarty->assign('spacialdata', $spacialdata);
     // Grab profile icons and link to them, making sure the default is first
     if ($icons = get_column_sql("SELECT id\n            FROM {artefact}\n            WHERE artefacttype = 'profileicon'\n            AND \"owner\" = ?\n            ORDER BY id = (\n                SELECT profileicon FROM {usr} WHERE id = ?\n            ) DESC, id", array($userid, $userid))) {
         foreach ($icons as $icon) {
             $icon = artefact_instance_from_id($icon);
             $this->add_artefact_link($icon, 'related');
         }
         $this->smarty->assign('links', $this->links);
     }
     if (!($categories = $this->get_categories())) {
         $categories = array();
     }
     $this->smarty->assign('categories', $categories);
 }
コード例 #10
0
 public static function getRecordDataById($type, $id)
 {
     $record = get_record('usr', 'id', $id);
     if (!$record || $record->deleted) {
         return false;
     }
     $record->display_name = display_name($record);
     $record->introduction = get_field('artefact', 'title', 'owner', $id, 'artefacttype', 'introduction');
     return $record;
 }
コード例 #11
0
function addmembers_submit(Pieform $form, $values)
{
    global $SESSION, $group, $USER;
    if (empty($values['users'])) {
        redirect(get_config('wwwroot') . 'group/suggest.php?id=' . GROUP);
    }
    require_once 'activity.php';
    $groupurl = group_homepage_url($group, false);
    activity_occurred('maharamessage', array('users' => $values['users'], 'subject' => '', 'message' => '', 'strings' => (object) array('subject' => (object) array('key' => 'suggestgroupnotificationsubject', 'section' => 'group', 'args' => array(display_name($USER))), 'message' => (object) array('key' => 'suggestgroupnotificationmessage', 'section' => 'group', 'args' => array(display_name($USER), hsc($group->name), get_config('sitename')))), 'url' => $groupurl, 'urltext' => hsc($group->name)));
    $SESSION->add_ok_msg(get_string('recommendationssent', 'group', count($values['users'])));
    redirect(get_config('wwwroot') . $groupurl);
}
コード例 #12
0
ファイル: viewacl.php プロジェクト: Br3nda/mahara
function pieform_render_viewacl_getvaluebytype($type, $id)
{
    switch ($type) {
        case 'user':
            $user = get_record('usr', 'id', $id);
            return display_name($user);
            break;
        case 'group':
            return get_field('group', 'name', 'id', $id);
            break;
    }
    return "{$type}: {$id}";
}
コード例 #13
0
ファイル: invite.php プロジェクト: Br3nda/mahara
function invitetogroup_submit(Pieform $form, $values)
{
    global $SESSION, $USER, $group, $user;
    $data = new StdClass();
    $data->group = $group->id;
    $data->member = $user->id;
    $data->ctime = db_format_timestamp(time());
    $data->role = $values['role'];
    insert_record('group_member_invite', $data);
    $lang = get_user_language($user->id);
    require_once 'activity.php';
    activity_occurred('maharamessage', array('users' => array($user->id), 'subject' => get_string_from_language($lang, 'invitetogroupsubject', 'group'), 'message' => get_string_from_language($lang, 'invitetogroupmessage', 'group', display_name($USER, $user), $group->name), 'url' => get_config('wwwroot') . 'group/view.php?id=' . $group->id));
    $SESSION->add_ok_msg(get_string('userinvited', 'group'));
    redirect('/user/view.php?id=' . $user->id);
}
コード例 #14
0
ファイル: changeuser.php プロジェクト: patkira/mahara
/**
 * Notify user (if configured), do the masquerading and emit event. Called when
 * no (further) interaction with the admin is needed before the loginas.
 *
 * @param string $why The masquerading reason (if given) or null.
 */
function do_masquerade($why = null)
{
    global $USER, $SESSION;
    $id = param_integer('id');
    $who = display_name($USER, $id);
    $when = format_date(time());
    if (get_config('masqueradingnotified')) {
        $msg = (object) array('subject' => get_string('masqueradenotificationsubject', 'admin'), 'message' => $why === null ? get_string('masqueradenotificationnoreason', 'admin', $who, $when) : get_string('masqueradenotificationreason', 'admin', $who, $when, $why), 'users' => array($id), 'url' => profile_url($USER, false), 'urltext' => $who);
        activity_occurred('maharamessage', $msg);
        $SESSION->add_info_msg(get_string('masqueradenotificationdone', 'admin'));
    }
    $USER->change_identity_to($id);
    // Permissions checking is done in here
    handle_event('loginas', array('who' => $who, 'when' => $when, 'reason' => $why));
    redirect(get_config('wwwroot'));
}
コード例 #15
0
ファイル: userlist.php プロジェクト: sarahjcotton/mahara
/**
 * Provides a basic text field input.
 *
 * @todo this is just lies ...
 * @param array    $element The element to render
 * @param Pieform  $form    The form to render the element for
 * @return string           The HTML for the element
 */
function pieform_element_userlist(Pieform $form, $element)
{
    $smarty = smarty_core();
    $smarty->left_delimiter = '{{';
    $smarty->right_delimiter = '}}';
    $value = $form->get_value($element);
    if (!is_array($value) && isset($element['defaultvalue']) && is_array($element['defaultvalue'])) {
        $value = $element['defaultvalue'];
    }
    if (is_array($value) && count($value)) {
        $orderby = isset($element['searchparams']['orderby']) && $element['searchparams']['orderby'] == 'lastname' ? 'lastname,firstname,id' : 'firstname,lastname,id';
        $members = get_records_select_assoc('usr', 'id IN (' . join(',', array_map('intval', $value)) . ')', null, $orderby, 'id,username,firstname,lastname,preferredname,staff');
        foreach ($members as &$member) {
            $member = display_name($member);
        }
        $smarty->assign('options', $members);
        $smarty->assign('value', join(',', $value));
    }
    $smarty->assign('name', $element['name']);
    if (!empty($element['lefttitle'])) {
        $smarty->assign('lefttitle', $element['lefttitle']);
    }
    if (!empty($element['righttitle'])) {
        $smarty->assign('righttitle', $element['righttitle']);
    }
    if (!empty($element['leftarrowlabel'])) {
        $smarty->assign('leftarrowlabel', $element['leftarrowlabel']);
    }
    if (!empty($element['rightarrowlabel'])) {
        $smarty->assign('rightarrowlabel', $element['rightarrowlabel']);
    }
    if (!empty($element['group'])) {
        $smarty->assign('group', $element['group']);
        $smarty->assign('includeadmins', !isset($element['includeadmins']) || $element['includeadmins'] ? 1 : 0);
    }
    if (empty($element['searchscript'])) {
        $element['searchscript'] = 'json/usersearch.php';
    }
    $smarty->assign('searchscript', $element['searchscript']);
    if (empty($element['searchparams'])) {
        $element['searchparams'] = array('query' => '', 'limit' => 100);
    }
    $smarty->assign('searchparams', json_encode($element['searchparams']));
    $smarty->assign('onlyshowingfirst', json_encode(get_string('onlyshowingfirst', 'admin')));
    $smarty->assign('resultsof', json_encode(get_string('resultsof', 'admin')));
    return $smarty->fetch('form/userlist.tpl');
}
コード例 #16
0
ファイル: requestjoin.php プロジェクト: patkira/mahara
function requestjoingroup_submit(Pieform $form, $values)
{
    global $SESSION, $USER, $group, $goto;
    insert_record('group_member_request', (object) array('group' => $group->id, 'member' => $USER->get('id'), 'ctime' => db_format_timestamp(time()), 'reason' => isset($values['reason']) ? $values['reason'] : null));
    // Send request to all group admins
    require_once 'activity.php';
    $groupadmins = get_column('group_member', 'member', 'group', $group->id, 'role', 'admin');
    foreach ($groupadmins as $groupadmin) {
        $adminlang = get_user_language($groupadmin);
        if (isset($values['reason']) && $values['reason'] != '') {
            $message = get_string_from_language($adminlang, 'grouprequestmessagereason', 'group', display_name($USER, get_record('usr', 'id', $groupadmin)), $group->name, $values['reason']);
        } else {
            $message = get_string_from_language($adminlang, 'grouprequestmessage', 'group', display_name($USER, get_record('usr', 'id', $groupadmin)), $group->name);
        }
        activity_occurred('maharamessage', array('users' => array($groupadmin), 'subject' => get_string_from_language($adminlang, 'grouprequestsubject', 'group'), 'message' => $message, 'url' => 'group/members.php?id=' . $group->id . '&membershiptype=request', 'strings' => (object) array('urltext' => (object) array('key' => 'pendingmembers', 'section' => 'group'))));
    }
    $SESSION->add_ok_msg(get_string('grouprequestsent', 'group'));
    redirect($goto);
}
コード例 #17
0
ファイル: denyrequest.php プロジェクト: vohung96/mahara
function denyrequest_submit(Pieform $form, $values)
{
    global $USER, $SESSION, $id;
    $loggedinid = $USER->get('id');
    $user = get_record('usr', 'id', $id);
    // friend db record
    $f = new StdClass();
    $f->ctime = db_format_timestamp(time());
    // notification info
    $n = new StdClass();
    $n->url = profile_url($USER, false);
    $n->users = array($user->id);
    $n->fromuser = $USER->get('id');
    $lang = get_user_language($user->id);
    $displayname = display_name($USER, $user);
    $n->urltext = $displayname;
    delete_records('usr_friend_request', 'owner', $loggedinid, 'requester', $id);
    $n->subject = get_string_from_language($lang, 'friendrequestrejectedsubject', 'group');
    if (isset($values['reason']) && !empty($values['reason'])) {
        $n->message = get_string_from_language($lang, 'friendrequestrejectedmessagereason', 'group', $displayname) . $values['reason'];
    } else {
        $n->message = get_string_from_language($lang, 'friendrequestrejectedmessage', 'group', $displayname);
    }
    require_once 'activity.php';
    activity_occurred('maharamessage', $n);
    handle_event('removefriendrequest', array('owner' => $loggedinid, 'requester' => $id));
    $SESSION->add_ok_msg(get_string('friendformrejectsuccess', 'group'));
    $offset = param_integer('offset', 0);
    switch (param_alpha('returnto', 'myfriends')) {
        case 'find':
            $goto = 'user/find.php';
            break;
        case 'view':
            $goto = profile_url($user, false);
            break;
        default:
            $goto = 'user/myfriends.php';
            break;
    }
    $goto .= strpos($goto, '?') ? '&offset=' . $offset : '?offset=' . $offset;
    $goto = get_config('wwwroot') . $goto;
    redirect($goto);
}
コード例 #18
0
ファイル: requestfriendship.php プロジェクト: Br3nda/mahara
function requestfriendship_submit(Pieform $form, $values)
{
    global $USER, $SESSION, $id;
    $loggedinid = $USER->get('id');
    $user = get_record('usr', 'id', $id);
    // friend db record
    $f = new StdClass();
    $f->ctime = db_format_timestamp(time());
    // notification info
    $n = new StdClass();
    $n->url = get_config('wwwroot') . 'user/view.php?id=' . $loggedinid;
    $n->users = array($user->id);
    $lang = get_user_language($user->id);
    $displayname = display_name($USER, $user);
    $f->owner = $id;
    $f->requester = $loggedinid;
    $f->message = $values['message'];
    insert_record('usr_friend_request', $f);
    $n->subject = get_string_from_language($lang, 'requestedfriendlistsubject', 'group');
    if (isset($values['message']) && !empty($values['message'])) {
        $n->message = get_string_from_language($lang, 'requestedfriendlistmessagereason', 'group', $displayname) . $values['message'];
    } else {
        $n->message = get_string_from_language($lang, 'requestedfriendlistmessage', 'group', $displayname);
    }
    require_once 'activity.php';
    activity_occurred('maharamessage', $n);
    $SESSION->add_ok_msg(get_string('friendformrequestsuccess', 'group', display_name($id)));
    switch (param_alpha('returnto', 'myfriends')) {
        case 'find':
            redirect('/user/find.php');
            break;
        case 'view':
            redirect('/user/view.php?id=' . $id);
            break;
        default:
            redirect('/user/myfriends.php');
            break;
    }
}
コード例 #19
0
 public static function getRecordDataById($type, $id)
 {
     $record = parent::getRecordDataById($type, $id);
     if (!$record) {
         return false;
     }
     //  Created by
     if (intval($record->owner) > 0) {
         $record->createdby = get_record('usr', 'id', $record->owner);
         $record->createdbyname = display_name($record->createdby);
     }
     //  Tags
     $tags = get_records_array('view_tag', 'view', $id);
     if ($tags != false) {
         foreach ($tags as $tag) {
             $record->tags[] = $tag->tag;
         }
     } else {
         $record->tags = null;
     }
     return $record;
 }
 public static function getRecordDataById($type, $id)
 {
     $sql = 'SELECT p1.id, p1.topic, p1.parent, p1.poster, COALESCE(p1.subject, p2.subject) AS subject, p2.subject,
     p1.body, p1.ctime, p1.deleted, p1.sent, p1.path,
     u.username, u.preferredname, u.firstname, u.lastname, u.profileicon,
     f.title as forumname, f.id as forumid,
     g.name as groupname, g.id as groupid
     FROM {interaction_forum_post} p1
     LEFT JOIN {interaction_forum_post} p2 ON p2.parent IS NULL AND p2.topic = p1.topic
     LEFT JOIN {usr} u ON u.id = p1.poster
     LEFT JOIN {interaction_forum_topic} ift on p1.topic = ift.id
     LEFT JOIN {interaction_instance} f ON ift.forum = f.id AND f.plugin=\'forum\'
     LEFT JOIN {group} g ON f.group = g.id
     WHERE p1.id = ?';
     $record = get_record_sql($sql, array($id));
     if (!$record || $record->deleted) {
         return false;
     }
     $record->body = str_replace(array("\r\n", "\n", "\r"), ' ', strip_tags($record->body));
     $record->ctime = format_date(strtotime($record->ctime));
     $record->authorlink = '<a href="' . profile_url($record->poster) . '" class="forumuser">' . display_name($record->poster, null, true) . '</a>';
     return $record;
 }
コード例 #21
0
ファイル: lib.php プロジェクト: vohung96/mahara
 public static function render_instance(BlockInstance $instance, $editing = false)
 {
     require_once get_config('docroot') . 'artefact/lib.php';
     global $USER;
     $smarty = smarty_core();
     $groupdata = group_get_associated_groups($USER->get('id'), 'all', null, null);
     $data = new stdclass();
     $data->data = array();
     $data->count = $groupdata['count'];
     $data->displayname = display_name($user);
     if ($data->count) {
         foreach ($groupdata['groups'] as $g) {
             $record = array();
             $record['id'] = $g->id;
             $record['name'] = $g->name;
             $record['description'] = $g->description;
             $owner = group_get_admin_ids($g->id);
             $record['group_admin'] = display_name($owner[0]);
             $data->data[] = $record;
         }
     }
     $smarty->assign('eselma_groups', $data);
     return $smarty->fetch('blocktype:eselmagroup:content.tpl');
 }
コード例 #22
0
ファイル: actionregistration.php プロジェクト: kienv/mahara
function denyregistration_submit(Pieform $form, $values)
{
    global $USER, $SESSION;
    if (isset($values['message']) && !empty($values['message'])) {
        $message = get_string('registrationdeniedmessagereason', 'auth.internal', $values['firstname'], get_config('sitename'), $values['message'], display_name($USER));
    } else {
        $message = get_string('registrationdeniedmessage', 'auth.internal', $values['firstname'], get_config('sitename'), display_name($USER));
    }
    try {
        delete_records('usr_registration', 'email', $values['email']);
        $user = (object) $values;
        $user->admin = 0;
        $user->staff = 0;
        email_user($user, $USER, get_string('registrationdeniedemailsubject', 'auth.internal', get_config('sitename')), $message);
    } catch (EmailException $e) {
        log_warn($e);
        die_info(get_string('registrationdeniedunsuccessful', 'admin'));
    } catch (SQLException $e) {
        log_warn($e);
        die_info(get_string('registrationdeniedunsuccessful', 'admin'));
    }
    $SESSION->add_ok_msg(get_string('registrationdeniedsuccessful', 'admin'));
    redirect('/admin/users/pendingregistrations.php?institution=' . $values['institution']);
}
コード例 #23
0
 /**
  * The name of the entry's author
  *
  * @return string
  */
 public function get_entry_author()
 {
     if ($author = $this->artefact->get('author')) {
         if ($author != $this->artefact->get('owner')) {
             return display_name($author);
         }
         return;
     }
     return $this->artefact->get('authorname');
 }
コード例 #24
0
define('GROUP', $groupid);
$group = group_current_group();
$user = get_record('usr', 'id', $userid, 'deleted', 0);
if (!$user) {
    throw new UserNotFoundException(get_string('usernotfound', 'group', $userid));
}
$role = group_user_access($groupid);
if ($role != 'admin' && !group_user_can_assess_submitted_views($group->id, $USER->get('id'))) {
    if (!$group->invitefriends || !is_friend($user->id, $USER->get('id'))) {
        throw new AccessDeniedException(get_string('cannotinvitetogroup', 'group'));
    }
}
if (record_exists('group_member', 'group', $groupid, 'member', $userid) || record_exists('group_member_invite', 'group', $groupid, 'member', $userid)) {
    throw new UserException(get_string('useralreadyinvitedtogroup', 'group'));
}
define('TITLE', get_string('invitemembertogroup', 'group', display_name($userid), $group->name));
$roles = group_get_role_info($groupid);
foreach ($roles as $k => &$v) {
    $v = $v->display;
}
safe_require('grouptype', $group->grouptype);
$form = pieform(array('name' => 'invitetogroup', 'autofocus' => false, 'method' => 'post', 'elements' => array('reason' => array('type' => 'textarea', 'cols' => 50, 'rows' => 4, 'title' => get_string('reason')), 'role' => array('type' => 'select', 'options' => $roles, 'title' => get_string('Role', 'group'), 'defaultvalue' => call_static_method('GroupType' . $group->grouptype, 'default_role'), 'ignore' => $role != 'admin'), 'submit' => array('type' => 'submitcancel', 'value' => array(get_string('invite', 'group'), get_string('cancel')), 'goto' => profile_url($user)))));
$smarty = smarty();
$smarty->assign('subheading', TITLE);
$smarty->assign('form', $form);
$smarty->display('group/invite.tpl');
function invitetogroup_submit(Pieform $form, $values)
{
    global $SESSION, $USER, $group, $user;
    group_invite_user($group, $user->id, $USER, isset($values['role']) ? $values['role'] : null);
    $SESSION->add_ok_msg(get_string('userinvited', 'group'));
コード例 #25
0
/**
 * Sends notification e-mails to site and institutional admins when:
 *
 *  - An institution is expiring within the institution expiry warning
 *    period, set in site options.
 *
 * The actual prevention of users logging in is handled by the authentication
 * code. This cron job sends e-mails to notify users that these events will
 * happen soon.
 */
function auth_handle_institution_expiries()
{
    // The 'expiry' flag on the usr table
    $sitename = get_config('sitename');
    $wwwroot = get_config('wwwroot');
    $expire = get_config('institutionautosuspend');
    $warn = get_config('institutionexpirynotification');
    $daystoexpire = ceil($warn / 86400) . ' ';
    $daystoexpire .= $daystoexpire == 1 ? get_string('day') : get_string('days');
    // Get site administrators
    $siteadmins = get_records_sql_array('SELECT u.id, u.username, u.firstname, u.lastname, u.preferredname, u.email, u.admin, u.staff FROM {usr} u WHERE u.admin = 1', array());
    // Expiry warning messages
    if ($institutions = get_records_sql_array('SELECT i.name, i.displayname FROM {institution} i ' . 'WHERE ' . db_format_tsfield('i.expiry', false) . ' < ? AND suspended != 1 AND expirymailsent != 1', array(time() + $warn))) {
        foreach ($institutions as $institution) {
            $institution_displayname = $institution->displayname;
            // Email site administrators
            foreach ($siteadmins as $user) {
                $user_displayname = display_name($user);
                _email_or_notify($user, get_string('institutionexpirywarning'), get_string('institutionexpirywarningtext_site', 'mahara', $user_displayname, $institution_displayname, $daystoexpire, $sitename, $sitename), get_string('institutionexpirywarninghtml_site', 'mahara', $user_displayname, $institution_displayname, $daystoexpire, $sitename, $sitename));
            }
            // Email institutional administrators
            $institutionaladmins = get_records_sql_array('SELECT u.id, u.username, u.expiry, u.staff, u.admin AS siteadmin, ui.admin AS institutionadmin, u.firstname, u.lastname, u.email ' . 'FROM {usr_institution} ui JOIN {usr} u ON (ui.usr = u.id) WHERE ui.admin = 1', array());
            foreach ($institutionaladmins as $user) {
                $user_displayname = display_name($user);
                _email_or_notify($user, get_string('institutionexpirywarning'), get_string('institutionexpirywarningtext_institution', 'mahara', $user_displayname, $institution_displayname, $sitename, $daystoexpire, $wwwroot . 'contact.php', $sitename), get_string('institutionexpirywarninghtml_institution', 'mahara', $user_displayname, $institution_displayname, $sitename, $daystoexpire, $wwwroot . 'contact.php', $sitename));
            }
            set_field('institution', 'expirymailsent', 1, 'name', $institution->name);
        }
    }
    // If we can automatically suspend expired institutions
    $autosuspend = get_config('institutionautosuspend');
    if ($autosuspend) {
        // Actual expired institutions
        if ($institutions = get_records_sql_array('SELECT name FROM {institution} ' . 'WHERE ' . db_format_tsfield('expiry', false) . ' < ?', array(time()))) {
            // Institutions have expired!
            foreach ($institutions as $institution) {
                set_field('institution', 'suspended', 1, 'name', $institution->name);
            }
        }
    }
}
コード例 #26
0
ファイル: user.php プロジェクト: sarahjcotton/mahara
 public function change_identity_to($userid)
 {
     $user = new User();
     $user->find_by_id($userid);
     if (!$this->is_admin_for_user($user)) {
         throw new AccessDeniedException(get_string('loginasdenied', 'admin'));
     }
     $olduser = $this->get('parentuser');
     if (!is_null($olduser)) {
         throw new UserException(get_string('loginastwice', 'admin'));
     }
     $olduser = new StdClass();
     $olduser->id = $this->get('id');
     $olduser->name = display_name($this, null, true);
     $this->reloadLiveUser($userid);
     $this->set('parentuser', $olduser);
 }
コード例 #27
0
require dirname(dirname(dirname(__FILE__))) . '/init.php';
require_once dirname(__FILE__) . '/lib/multirecipientnotification.php';
require_once get_config('docroot') . '/lib/searchlib.php';
global $USER;
$request = param_variable('q');
$page = param_integer('page');
if ($page < 1) {
    $page = 1;
}
$usersperpage = 10;
$more = true;
$tmpuser = array();
while ($more && count($tmpuser) < $usersperpage) {
    $users = search_user($request, $usersperpage, $usersperpage * ($page - 1));
    $more = $users['count'] > $usersperpage * $page;
    if (!$users['data']) {
        $users['data'] = array();
    }
    foreach ($users['data'] as $user) {
        if (count($tmpuser) >= $usersperpage) {
            $more = true;
            continue;
        }
        if (!can_send_message($USER->id, $user['id']) || $USER->id == $user['id']) {
            continue;
        }
        $tmpuser[] = (object) array('id' => $user['id'], 'text' => '<img class="select2-user-icon" src="' . get_config('wwwroot') . 'thumb.php?type=profileicon&maxwidth=40&maxheight=40&id=' . $user['id'] . '" />' . '<span>' . display_name($user['id']) . '</span>', 'name' => display_name($user['id']));
    }
    $page++;
}
echo json_encode(array('more' => $more, 'results' => $tmpuser));
コード例 #28
0
                    $message .= "Name: " . $creid[0]['Task_Name'] . "\r\n<br />";
                    $message .= $r['Task_Description'] . "\r\n<br />";
                    $tsk = $slave->select("SELECT * FROM Task_Logs WHERE Task_ID=" . $data['Task_ID']);
                    if ($tsk) {
                        foreach ($tsk as $t) {
                            $message .= $t['Public_Note'] . "\r\n<br />";
                        }
                    }
                    if (valid_email($requester[0]['Email'])) {
                        $ftemail = $requester[0]['Email'];
                    } else {
                        $ftemail = $noreply_email;
                    }
                    //print_r($r);
                    //print_r($requester);
                    smtp_mail("", "", $r['Email'], $ftemail, display_name($requester[0]['First_Name'], $requester[0]['Last_Name']), $ftemail, $subject, $message);
                }
            }
        }
    }
} elseif ($_POST['acknowledge']) {
    foreach ($_POST['acknowledge'] as $tid => $ack) {
        $data['User_ID'] = $_SESSION['user_id'];
        $data['Acknowledged'] = date("Y-m-d H:i:s");
        $data['Accepted'] = '1';
        $data['Task_ID'] = $tid;
        $data['Progress'] = $_POST['progress'][$tid];
        $insert = $db->insert("Task_Acknowledgement", $data);
    }
} elseif ($_POST['task_id']) {
    $data['User_ID'] = $_SESSION['user_id'];
コード例 #29
0
ファイル: tasks.php プロジェクト: sketchings/task-refactor
             $img = $f['Image'];
             if ($f['Image'] == 1) {
                 $icon = "111.png";
                 echo "<a href=\"" . CDN . "img.php?id=" . $log['Task_ID'] . "&log=" . $log['Log_ID'] . "\" alt=\"\" target=\"_blank\"><img src=\"" . CDN . "img/icons/{$icon}\" border=0 /></a>";
             } else {
                 $icon = "3.png";
                 echo "<a href=\"{$target_path}" . $f['File_ID'] . "." . $f['Extention'] . "\" alt=\"\" target=\"_blank\"><img src=\"" . CDN . "img/icons/{$icon}\" border=0 /></a>";
             }
         } elseif ($img == 1) {
             $mult = "+";
         }
     }
     echo $mult;
 }
 echo "</td>\n";
 echo "<td>" . display_name($log['First_Name'], $log['Last_Name']) . "</td>\n";
 echo "<td>\$" . number_format($log['Log_Cost'], 2) . "</td>\n";
 if ($log['Log_Time'] > 60 and $log['Log_Time'] % 60 < 1) {
     $log_time = $log['Log_Time'] / 60 . "/hour";
 } else {
     $log_time = $log['Log_Time'] . "/min";
 }
 echo "<td>" . $log_time . "</td>\n";
 echo "<td>" . str_replace("\n", "<br />", htmlentities(str_replace("&#39;", "'", $log['Public_Note']), ENT_NOQUOTES));
 if ($log['Log_Note']) {
     echo "<hr />" . str_replace("\n", "<br />", htmlentities(str_replace("&#39;", "'", $log['Log_Note']), ENT_NOQUOTES));
 }
 if ($files) {
     foreach ($files as $f) {
         echo "<br /><em>";
         if ($f['Original_File']) {
コード例 #30
0
function edituser_site_submit(Pieform $form, $values)
{
    global $USER, $authobj, $SESSION;
    if (!($user = get_record('usr', 'id', $values['id']))) {
        return false;
    }
    if (is_using_probation()) {
        // Value should be between 0 and 10 inclusive
        $user->probation = ensure_valid_probation_points($values['probationpoints']);
    }
    if ($USER->get('admin') || get_config_plugin('artefact', 'file', 'institutionaloverride')) {
        $user->quota = $values['quota'];
        // check if the user has gone over the quota notify limit
        $quotanotifylimit = get_config_plugin('artefact', 'file', 'quotanotifylimit');
        if ($quotanotifylimit <= 0 || $quotanotifylimit >= 100) {
            $quotanotifylimit = 100;
        }
        $user->quotausedpercent = $user->quotaused / $user->quota * 100;
        $overlimit = false;
        if ($quotanotifylimit <= $user->quotausedpercent) {
            $overlimit = true;
        }
        $notified = get_field('usr_account_preference', 'value', 'field', 'quota_exceeded_notified', 'usr', $user->id);
        if ($overlimit && '1' !== $notified) {
            require_once get_config('docroot') . 'artefact/file/lib.php';
            ArtefactTypeFile::notify_users_threshold_exceeded(array($user), false);
            // no need to email admin as we can alert them right now
            $SESSION->add_error_msg(get_string('useroverquotathreshold', 'artefact.file', display_name($user)));
        } else {
            if ($notified && !$overlimit) {
                set_account_preference($user->id, 'quota_exceeded_notified', false);
            }
        }
    }
    $unexpire = $user->expiry && strtotime($user->expiry) < time() && (empty($values['expiry']) || $values['expiry'] > time());
    $newexpiry = db_format_timestamp($values['expiry']);
    if ($user->expiry != $newexpiry) {
        $user->expiry = $newexpiry;
        if ($unexpire) {
            $user->expirymailsent = 0;
            $user->lastaccess = db_format_timestamp(time());
        }
    }
    // Try to kick the user from any active login sessions, before saving data.
    require_once get_config('docroot') . 'auth/session.php';
    remove_user_sessions($user->id);
    if ($USER->get('admin')) {
        // Not editable by institutional admins
        $user->staff = (int) ($values['staff'] == 'on');
        $user->admin = (int) ($values['admin'] == 'on');
        if ($user->admin) {
            activity_add_admin_defaults(array($user->id));
        }
    }
    if ($values['maildisabled'] == 0 && get_account_preference($user->id, 'maildisabled') == 1) {
        // Reset the sent and bounce counts otherwise mail will be disabled
        // on the next send attempt
        $u = new StdClass();
        $u->email = $user->email;
        $u->id = $user->id;
        update_bounce_count($u, true);
        update_send_count($u, true);
    }
    set_account_preference($user->id, 'maildisabled', $values['maildisabled']);
    // process the change of the authinstance and or the remoteuser
    if (isset($values['authinstance']) && isset($values['remoteusername'])) {
        // Authinstance can be changed by institutional admins if both the
        // old and new authinstances belong to the admin's institutions
        $authinst = get_records_select_assoc('auth_instance', 'id = ? OR id = ?', array($values['authinstance'], $user->authinstance));
        // But don't bother if the auth instance doesn't take a remote username
        $authobj = AuthFactory::create($values['authinstance']);
        if ($USER->get('admin') || $USER->is_institutional_admin($authinst[$values['authinstance']]->institution) && ($USER->is_institutional_admin($authinst[$user->authinstance]->institution) || $user->authinstance == 1)) {
            if ($authobj->needs_remote_username()) {
                // determine the current remoteuser
                $current_remotename = get_field('auth_remote_user', 'remoteusername', 'authinstance', $user->authinstance, 'localusr', $user->id);
                if (!$current_remotename) {
                    $current_remotename = $user->username;
                }
                // if the remoteuser is empty
                if (strlen(trim($values['remoteusername'])) == 0) {
                    delete_records('auth_remote_user', 'authinstance', $user->authinstance, 'localusr', $user->id);
                }
                // what should the new remoteuser be
                $new_remoteuser = get_field('auth_remote_user', 'remoteusername', 'authinstance', $values['authinstance'], 'localusr', $user->id);
                // save the remotename for the target existence check
                $target_remotename = $new_remoteuser;
                if (!$new_remoteuser) {
                    $new_remoteuser = $user->username;
                }
                if (strlen(trim($values['remoteusername'])) > 0) {
                    // value changed on page - use it
                    if ($values['remoteusername'] != $current_remotename) {
                        $new_remoteuser = $values['remoteusername'];
                    }
                }
                // only update remote name if the input actually changed on the page  or it doesn't yet exist
                if ($current_remotename != $new_remoteuser || !$target_remotename) {
                    // only remove the ones related to this traget authinstance as we now allow multiple
                    // for dual login mechanisms
                    delete_records('auth_remote_user', 'authinstance', $values['authinstance'], 'localusr', $user->id);
                    insert_record('auth_remote_user', (object) array('authinstance' => $values['authinstance'], 'remoteusername' => $new_remoteuser, 'localusr' => $user->id));
                }
            }
            // update the ai on the user master
            $user->authinstance = $values['authinstance'];
            // update the global $authobj to match the new authinstance
            // this is used by the password/username change methods
            // if either/both has been requested at the same time
            $authobj = AuthFactory::create($user->authinstance);
        }
    }
    // Only change the pw if the new auth instance allows for it
    if (method_exists($authobj, 'change_password')) {
        $user->passwordchange = (int) (isset($values['passwordchange']) && $values['passwordchange'] == 'on' ? 1 : 0);
        if (isset($values['password']) && $values['password'] !== '') {
            $userobj = new User();
            $userobj = $userobj->find_by_id($user->id);
            $user->password = $authobj->change_password($userobj, $values['password']);
            $user->salt = $userobj->salt;
            unset($userobj);
        }
    } else {
        // inform the user that the chosen auth instance doesn't allow password changes
        // but only if they tried changing it
        if (isset($values['password']) && $values['password'] !== '') {
            $SESSION->add_error_msg(get_string('passwordchangenotallowed', 'admin'));
            // Set empty pw with salt
            $user->password = '';
            $user->salt = auth_get_random_salt();
        }
    }
    if (isset($values['username']) && $values['username'] !== '') {
        $userobj = new User();
        $userobj = $userobj->find_by_id($user->id);
        if ($userobj->username != $values['username']) {
            // Only change the username if the auth instance allows for it
            if (method_exists($authobj, 'change_username')) {
                // check the existence of the chosen username
                try {
                    if ($authobj->user_exists($values['username'])) {
                        // set an error message if it is already in use
                        $SESSION->add_error_msg(get_string('usernameexists', 'account'));
                    }
                } catch (AuthUnknownUserException $e) {
                    // update the username otherwise
                    $user->username = $authobj->change_username($userobj, $values['username']);
                }
            } else {
                // inform the user that the chosen auth instance doesn't allow username changes
                $SESSION->add_error_msg(get_string('usernamechangenotallowed', 'admin'));
            }
        }
        unset($userobj);
    }
    // OVERWRITE 4: insert
    if (isset($values['email']) && !empty($values['email']) && $values['email'] != $user->email) {
        global $CFG;
        $user->email = $values['email'];
        $mhr_user = $CFG->current_app->getUserById($user->id);
        $mhr_user->setEmailAddress($values['email']);
    }
    // END OVERWRITE 4
    db_begin();
    update_record('usr', $user);
    delete_records('usr_tag', 'usr', $user->id);
    if (is_array($values['tags'])) {
        $values['tags'] = check_case_sensitive($values['tags'], 'usr_tag');
        foreach (array_unique($values['tags']) as $tag) {
            if (empty($tag)) {
                continue;
            }
            insert_record('usr_tag', (object) array('usr' => $user->id, 'tag' => strtolower($tag)));
        }
    }
    db_commit();
    $SESSION->add_ok_msg(get_string('usersitesettingschanged', 'admin'));
    redirect('/admin/users/edit.php?id=' . $user->id);
}