Example #1
0
 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);
 }
Example #2
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);
 }
Example #3
0
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);
}
Example #4
0
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);
}
Example #5
0
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);
}
Example #6
0
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);
}
Example #7
0
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;
    }
}
Example #8
0
 public static function send_digest()
 {
     $users = array();
     $sitename = get_config('sitename');
     $types = get_records_assoc('activity_type', 'admin', 0, 'plugintype,pluginname,name', 'id,name,plugintype,pluginname');
     foreach ($types as &$type) {
         if (!empty($type->plugintype)) {
             $type->section = "{$type->plugintype}.{$type->pluginname}";
         } else {
             $type->section = "activity";
         }
     }
     $sql = 'SELECT q.id, u.username, u.firstname, u.lastname, u.preferredname, u.email, u.admin, u.staff,
                 p.value AS lang, q.*,' . db_format_tsfield('ctime') . '
             FROM {usr} u 
                 JOIN {notification_emaildigest_queue} q
                     ON q.usr = u.id
                 LEFT OUTER JOIN {usr_account_preference} p ON (p.usr = u.id AND p.field = \'lang\')
             ORDER BY usr,type,q.ctime';
     if ($tosend = get_records_sql_array($sql, array())) {
         foreach ($tosend as $queue) {
             if (!isset($users[$queue->usr])) {
                 $users[$queue->usr] = new StdClass();
                 $users[$queue->usr]->user = new StdClass();
                 $users[$queue->usr]->user->username = $queue->username;
                 $users[$queue->usr]->user->firstname = $queue->firstname;
                 $users[$queue->usr]->user->lastname = $queue->lastname;
                 $users[$queue->usr]->user->preferredname = $queue->preferredname;
                 $users[$queue->usr]->user->email = $queue->email;
                 $users[$queue->usr]->user->admin = $queue->admin;
                 $users[$queue->usr]->user->staff = $queue->staff;
                 $users[$queue->usr]->user->id = $queue->usr;
                 $users[$queue->usr]->user->lang = empty($queue->lang) || $queue->lang == 'default' ? get_config('lang') : $queue->lang;
                 $users[$queue->usr]->entries = array();
             }
             $queue->nicetype = get_string_from_language($users[$queue->usr]->user->lang, 'type' . $types[$queue->type]->name, $types[$queue->type]->section);
             $users[$queue->usr]->entries[$queue->id] = $queue;
         }
     }
     foreach ($users as $user) {
         $lang = $user->user->lang;
         $subject = get_string_from_language($lang, 'emailsubject', 'notification.emaildigest', $sitename);
         $body = get_string_from_language($lang, 'emailbodynoreply', 'notification.emaildigest', $sitename);
         foreach ($user->entries as $entry) {
             $body .= get_string_from_language($lang, 'type', 'activity') . ': ' . $entry->nicetype . ' ' . get_string_from_language($lang, 'attime', 'activity') . ' ' . format_date($entry->ctime) . "\n";
             if (!empty($entry->subject)) {
                 $body .= get_string_from_language($lang, 'subject') . $entry->subject . "\n";
             }
             if (!empty($entry->message)) {
                 $body .= "\n" . $entry->message;
             }
             if (!empty($entry->url)) {
                 $body .= "\n" . $entry->url;
             }
             $body .= "\n\n";
         }
         $prefurl = get_config('wwwroot') . 'account/activity/preferences/';
         $body .= "\n\n" . get_string_from_language($lang, 'emailbodyending', 'notification.emaildigest', $prefurl);
         try {
             email_user($user->user, null, $subject, $body);
             //only delete them if the email succeeded!
             $in = db_array_to_ph($user->entries);
             delete_records_select('notification_emaildigest_queue', 'id IN (' . implode(', ', $in) . ')', array_keys($user->entries));
         } catch (Exception $e) {
             // @todo
         }
     }
 }
Example #9
0
/**
 * Returns a language select form
 *
 * @return string      HTML of language select form
 */
function language_select_form()
{
    global $SESSION;
    $languageform = '';
    $languages = get_languages();
    if (count($languages) > 1) {
        $languages = array_merge(array('default' => get_string('sitedefault', 'admin') . ' (' . get_string_from_language(get_config('lang'), 'thislanguage') . ')'), $languages);
        require_once 'pieforms/pieform.php';
        $languageform = pieform(array('name' => 'languageselect', 'renderer' => 'div', 'class' => 'form-inline with-label-widthauto', 'validate' => false, 'presubmitcallback' => '', 'elements' => array('inputgroup' => array('type' => 'fieldset', 'class' => 'input-group', 'elements' => array('lang' => array('type' => 'select', 'title' => get_string('language') . ':', 'hiddenlabel' => true, 'options' => $languages, 'defaultvalue' => $SESSION->get('lang') ? $SESSION->get('lang') : 'default'), 'changelang' => array('type' => 'button', 'usebuttontag' => true, 'class' => 'btn-default input-group-btn', 'value' => get_string('change')))))));
    }
    return $languageform;
}
Example #10
0
 public function __construct($data)
 {
     parent::__construct($data);
     $this->overridemessagecontents = true;
     $post = get_record_sql('
         SELECT
             p.subject, p.body, p.poster, p.parent, ' . db_format_tsfield('p.ctime', 'ctime') . ',
             t.id AS topicid, fp.subject AS topicsubject, f.title AS forumtitle, g.name AS groupname, f.id AS forumid
         FROM {interaction_forum_post} p
         INNER JOIN {interaction_forum_topic} t ON (t.id = p.topic AND t.deleted = 0)
         INNER JOIN {interaction_forum_post} fp ON (fp.parent IS NULL AND fp.topic = t.id)
         INNER JOIN {interaction_instance} f ON (t.forum = f.id AND f.deleted = 0)
         INNER JOIN {group} g ON (f.group = g.id AND g.deleted = 0)
         WHERE p.id = ? AND p.deleted = 0', array($this->postid));
     // The post may have been deleted during the activity delay
     if (!$post) {
         $this->users = array();
         return;
     }
     $subscribers = get_records_sql_assoc('
         SELECT "user" AS subscriber, \'topic\' AS type, "key" FROM {interaction_forum_subscription_topic} WHERE topic = ?
         UNION
         SELECT "user" AS subscriber, \'forum\' AS type, "key" FROM {interaction_forum_subscription_forum} WHERE forum = ?
         ORDER BY type', array($post->topicid, $post->forumid));
     $this->users = $subscribers ? activity_get_users($this->get_id(), array_keys($subscribers)) : array();
     $this->fromuser = $post->poster;
     // When emailing forum posts, create Message-Id headers for threaded display by email clients
     $urlinfo = parse_url(get_config('wwwroot'));
     $hostname = $urlinfo['host'];
     $cleanforumname = str_replace('"', "'", strip_tags($post->forumtitle));
     $this->customheaders = array('List-Id: "' . $cleanforumname . '" <forum' . $post->forumid . '@' . $hostname . '>', 'List-Help: ' . get_config('wwwroot') . 'interaction/forum/view.php?id=' . $post->forumid, 'Message-ID: <forumpost' . $this->postid . '@' . $hostname . '>');
     if ($post->parent) {
         $this->customheaders[] = 'In-Reply-To: <forumpost' . $post->parent . '@' . $hostname . '>';
         $this->customheaders[] = 'References: <forumpost' . $post->parent . '@' . $hostname . '>';
     }
     $posttime = strftime(get_string('strftimedaydatetime'), $post->ctime);
     $htmlbody = $post->body;
     $this->message = strip_tags(str_shorten_html($htmlbody, 200, true));
     // For internal notifications.
     $textbody = trim(html2text($post->body));
     $postlink = get_config('wwwroot') . 'interaction/forum/topic.php?id=' . $post->topicid . '#post' . $this->postid;
     $this->url = $postlink;
     $this->add_urltext(array('key' => 'Topic', 'section' => 'interaction.forum'));
     foreach ($this->users as &$user) {
         $lang = empty($user->lang) || $user->lang == 'default' ? get_config('lang') : $user->lang;
         if ($post->parent) {
             $user->subject = get_string_from_language($lang, 'replyforumpostnotificationsubject', 'interaction.forum', $post->groupname, $post->forumtitle, $post->topicsubject);
         } else {
             $user->subject = get_string_from_language($lang, 'newforumpostnotificationsubject', 'interaction.forum', $post->groupname, $post->forumtitle, $post->subject);
         }
         $type = $subscribers[$user->id]->type;
         $unsubscribeid = $post->{$type . 'id'};
         $unsubscribelink = get_config('wwwroot') . 'interaction/forum/unsubscribe.php?' . $type . '=' . $unsubscribeid . '&key=' . $subscribers[$user->id]->key;
         $user->emailmessage = get_string_from_language($lang, 'forumposttemplate', 'interaction.forum', $post->subject ? $post->subject : get_string_from_language($lang, 're', 'interaction.forum', $post->topicsubject), display_name($post->poster, $user), $posttime, $textbody, $postlink, $type, $unsubscribelink);
         $user->htmlmessage = get_string_from_language($lang, 'forumposthtmltemplate', 'interaction.forum', $post->subject ? $post->subject : get_string_from_language($lang, 're', 'interaction.forum', $post->topicsubject), display_name($post->poster, $user), $posttime, $htmlbody, $postlink, $unsubscribelink, $type);
     }
 }
Example #11
0
/**
 * Invite a user to a group.
 *
 * @param object $group group
 * @param object $userid  User to invite
 * @param object $userfrom  User sending the invitation
 */
function group_invite_user($group, $userid, $userfrom, $role = 'member', $delay = null)
{
    $user = optional_userobj($userid);
    $data = new StdClass();
    $data->group = $group->id;
    $data->member = $user->id;
    $data->ctime = db_format_timestamp(time());
    $data->role = $role;
    ensure_record_exists('group_member_invite', $data, $data);
    $lang = get_user_language($user->id);
    require_once 'activity.php';
    $activitydata = array('users' => array($user->id), 'subject' => get_string_from_language($lang, 'invitetogroupsubject', 'group'), 'message' => get_string_from_language($lang, 'invitetogroupmessage', 'group', display_name($userfrom, $user), $group->name), 'url' => group_homepage_url($group, false), 'urltext' => $group->name);
    activity_occurred('maharamessage', $activitydata, null, null, $delay);
}
            $groupstoaddmail .= $groupdata[$groupid]->name . "\n";
        }
    }
    db_commit();
    // Users notification
    $userrecord = get_record('usr', 'id', $userid);
    $lang = get_user_language($userid);
    $n = new StdClass();
    $n->users = array($userid);
    $n->subject = get_string_from_language($lang, 'changedgroupmembershipsubject', 'group');
    $n->message = '';
    if (isset($groupstoaddmail)) {
        $n->message .= get_string_from_language($lang, 'addedtongroupsmessage', 'group', count($groupstoadd), display_name($USER, $userrecord), $groupstoaddmail);
    }
    if (isset($groupstoremovemail)) {
        $n->message .= get_string_from_language($lang, 'removedfromngroupsmessage', 'group', count($groupstoremove), display_name($USER, $userrecord), $groupstoremovemail);
    }
    require_once get_config('libroot') . 'activity.php';
    activity_occurred('maharamessage', $n);
    $data['message'] = get_string('changedgroupmembership', 'group');
} else {
    if ($addtype == 'invite') {
        if ($groupstoadd = array_diff($resultgroups, $initialgroups)) {
            foreach ($groupstoadd as $groupid) {
                group_invite_user($groupdata[$groupid], $userid, $USER->get('id'));
            }
        }
        $data['message'] = get_string('userinvited', 'group');
    }
}
json_reply(false, $data);
Example #13
0
 public function release($releaseuser = null)
 {
     $submitinfo = $this->submitted_to();
     if (is_null($submitinfo)) {
         throw new ParameterException("View with id " . $this->get('id') . " has not been submitted");
     }
     $releaseuser = optional_userobj($releaseuser);
     if ($submitinfo['type'] == 'group') {
         $this->set('submittedgroup', null);
     } else {
         if ($submitinfo['type'] == 'host') {
             $this->set('submittedhost', null);
         }
     }
     $this->commit();
     $ownerlang = get_user_language($this->get('owner'));
     require_once 'activity.php';
     activity_occurred('maharamessage', array('users' => array($this->get('owner')), 'subject' => get_string_from_language($ownerlang, 'viewreleasedsubject', 'group'), 'message' => get_string_from_language($ownerlang, 'viewreleasedmessage', 'group', $submitinfo['name'], display_name($releaseuser, $this->get_owner_object()))));
 }
Example #14
0
function accountprefs_submit(Pieform $form, $values)
{
    global $USER, $SESSION;
    $authobj = AuthFactory::create($USER->authinstance);
    db_begin();
    $ispasswordchanged = false;
    if (isset($values['password1']) && $values['password1'] !== '') {
        global $authclass;
        $password = $authobj->change_password($USER, $values['password1']);
        $USER->password = $password;
        $USER->passwordchange = 0;
        $USER->commit();
        $ispasswordchanged = true;
    }
    // use this as looping through values is not safe.
    $expectedprefs = expected_account_preferences();
    if ($values['maildisabled'] == 0 && get_account_preference($USER->get('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->get('email');
        $u->id = $USER->get('id');
        update_bounce_count($u, true);
        update_send_count($u, true);
    }
    // Remember the user's language & theme prefs, so we can reload the page if they change them
    $oldlang = $USER->get_account_preference('lang');
    $oldtheme = $USER->get_account_preference('theme');
    $oldgroupsideblockmaxgroups = $USER->get_account_preference('groupsideblockmaxgroups');
    $oldgroupsideblocksortby = $USER->get_account_preference('groupsideblocksortby');
    if (get_config('allowmobileuploads')) {
        // Make sure the mobile token is formatted / saved correctly
        $values['mobileuploadtoken'] = array_filter($values['mobileuploadtoken']);
        $new_token_pref = empty($values['mobileuploadtoken']) ? null : '|' . join('|', $values['mobileuploadtoken']) . '|';
        $USER->set_account_preference('mobileuploadtoken', $new_token_pref);
        unset($values['mobileuploadtoken']);
    }
    // Set user account preferences
    foreach ($expectedprefs as $eprefkey => $epref) {
        if (isset($values[$eprefkey]) && $values[$eprefkey] !== get_account_preference($USER->get('id'), $eprefkey)) {
            $USER->set_account_preference($eprefkey, $values[$eprefkey]);
        }
    }
    $returndata = array();
    if (isset($values['username']) && $values['username'] != $USER->get('username')) {
        $USER->username = $values['username'];
        $USER->commit();
        $returndata['username'] = $values['username'];
    }
    $reload = false;
    if (get_config('cleanurls') && isset($values['urlid']) && $values['urlid'] != $USER->get('urlid')) {
        $USER->urlid = $values['urlid'];
        $USER->commit();
        $reload = true;
    }
    if ($ispasswordchanged) {
        // Destroy other sessions of the user
        require_once get_config('docroot') . 'auth/session.php';
        remove_user_sessions($USER->get('id'));
    }
    db_commit();
    $returndata['message'] = get_string('prefssaved', 'account');
    if (isset($values['theme']) && $values['theme'] != $oldtheme) {
        $USER->update_theme();
        $reload = true;
    }
    if (isset($values['lang']) && $values['lang'] != $oldlang) {
        // The session language pref is used when the user has no user pref,
        // and when logged out.
        $SESSION->set('lang', $values['lang']);
        $returndata['message'] = get_string_from_language($values['lang'], 'prefssaved', 'account');
        $reload = true;
    }
    if (isset($values['groupsideblockmaxgroups']) && $values['groupsideblockmaxgroups'] != $oldgroupsideblockmaxgroups) {
        $reload = true;
    }
    if ($values['groupsideblocksortby'] != $oldgroupsideblocksortby) {
        $reload = true;
    }
    $reload = plugin_account_prefs_submit($form, $values) || $reload;
    if (!empty($reload)) {
        // Use PIEFORM_CANCEL here to force a page reload and show the new language.
        $returndata['location'] = get_config('wwwroot') . 'account/index.php';
        $SESSION->add_ok_msg($returndata['message']);
        $form->json_reply(PIEFORM_CANCEL, $returndata);
    }
    $form->json_reply(PIEFORM_OK, $returndata);
}
 public function get_message($user)
 {
     $newaccessmessagestr = $this->incollection ? 'newcollectionaccessmessage' : 'newviewaccessmessage';
     $newaccessmessagenoownerstr = $this->incollection ? 'newcollectionaccessmessagenoowner' : 'newviewaccessmessagenoowner';
     if ($this->ownername) {
         return get_string_from_language($user->lang, $newaccessmessagestr, 'activity', $this->title, $this->ownername);
     }
     return get_string_from_language($user->lang, $newaccessmessagenoownerstr, 'activity', $this->title);
 }
Example #16
0
 public function get_message($user)
 {
     $title = $this->title;
     $plural = '';
     if ($titles = $this->get_view_titles()) {
         $title = implode('", "', $titles);
         $plural = 'views';
     }
     $newaccessmessagestr = $this->incollection ? 'newcollectionaccessmessage' . $plural : 'newviewaccessmessage' . $plural;
     if ($this->ownername) {
         return get_string_from_language($user->lang, $newaccessmessagestr, 'activity', $title, $this->ownername, $this->title);
     }
     $newaccessmessagenoownerstr = $this->incollection ? 'newcollectionaccessmessagenoowner' : 'newviewaccessmessagenoowner' . $plural;
     return get_string_from_language($user->lang, $newaccessmessagenoownerstr, 'activity', $title, $this->title);
 }
Example #17
0
 public static function change_language($userid, $oldlang, $newlang)
 {
     $oldname = get_string_from_language($oldlang, 'feedbackattachdirname', 'view');
     $artefact = ArtefactTypeFolder::get_folder_by_name($oldname, null, $userid);
     if (empty($artefact)) {
         return;
     }
     $name = get_string_from_language($newlang, 'feedbackattachdirname', 'view');
     $description = get_string_from_language($newlang, 'feedbackattachdirdesc', 'view');
     if (!empty($name)) {
         $artefact = artefact_instance_from_id($artefact->id);
         $artefact->set('title', $name);
         $artefact->set('description', $description);
         $artefact->commit();
     }
 }
Example #18
0
 public function get_htmlmessage($user)
 {
     $post = $this->temp->post;
     $reportername = hsc(display_default_name($this->reporter));
     $reporterurl = profile_url($this->reporter);
     $ctime = strftime(get_string_from_language($user->lang, 'strftimedaydatetime'), $this->ctime);
     return get_string_from_language($user->lang, 'objectionablecontentposthtml', 'interaction.forum', hsc($post->topicsubject), $reportername, $ctime, $this->message, $post->posttime, $post->htmlbody, get_config('wwwroot') . $this->url, hsc($post->topicsubject), $reporterurl, $reportername);
 }
 public function release($releaseuser = null)
 {
     require_once get_config('docroot') . 'artefact/lib.php';
     $submitinfo = $this->submitted_to();
     if (is_null($submitinfo)) {
         throw new ParameterException("View with id " . $this->get('id') . " has not been submitted");
     }
     $releaseuser = optional_userobj($releaseuser);
     db_begin();
     if ($submitinfo['type'] == 'group') {
         $group = $this->get('submittedgroup');
         $this->set('submittedgroup', null);
         if ($group) {
             // Remove hidden tutor view access records
             delete_records('view_access', 'view', $this->id, 'group', $group, 'visible', 0);
         }
     } else {
         if ($submitinfo['type'] == 'host') {
             $this->set('submittedhost', null);
         }
     }
     $this->set('submittedtime', null);
     $this->commit();
     ArtefactType::update_locked($this->owner);
     db_commit();
     $ownerlang = get_user_language($this->get('owner'));
     $url = get_config('wwwroot') . 'view/view.php?id=' . $this->get('id');
     require_once 'activity.php';
     activity_occurred('maharamessage', array('users' => array($this->get('owner')), 'subject' => get_string_from_language($ownerlang, 'viewreleasedsubject', 'group', $this->get('title'), $submitinfo['name'], display_name($releaseuser, $this->get_owner_object())), 'message' => get_string_from_language($ownerlang, 'viewreleasedmessage', 'group', $this->get('title'), $submitinfo['name'], display_name($releaseuser, $this->get_owner_object())), 'url' => $url, 'urltext' => $this->get('title')));
 }
Example #20
0
 /**
  * @param array $data Parameters:
  *                    - viewid (int)
  *                    - commentid (int)
  */
 public function __construct($data, $cron = false)
 {
     parent::__construct($data, $cron);
     $comment = new ArtefactTypeComment($this->commentid);
     $this->overridemessagecontents = true;
     if ($onartefact = $comment->get('onartefact')) {
         // feedback on artefact
         $userid = null;
         require_once get_config('docroot') . 'artefact/lib.php';
         $artefactinstance = artefact_instance_from_id($onartefact);
         if ($artefactinstance->feedback_notify_owner()) {
             $userid = $artefactinstance->get('owner');
         }
         if (empty($this->url)) {
             $this->url = get_config('wwwroot') . 'view/artefact.php?artefact=' . $onartefact . '&view=' . $this->viewid;
         }
     } else {
         // feedback on view.
         $onview = $comment->get('onview');
         if (!($viewrecord = get_record('view', 'id', $onview))) {
             throw new ViewNotFoundException(get_string('viewnotfound', 'error', $onview));
         }
         $userid = $viewrecord->owner;
         if (empty($this->url)) {
             $this->url = get_config('wwwroot') . 'view/view.php?id=' . $onview;
         }
     }
     if (empty($userid)) {
         return;
     }
     $this->users = activity_get_users($this->get_id(), array($userid));
     $title = $onartefact ? $artefactinstance->get('title') : $viewrecord->title;
     $this->urltext = $title;
     $body = $comment->get('description');
     $posttime = strftime(get_string('strftimedaydatetime'), $comment->get('ctime'));
     $user = $this->users[0];
     $lang = empty($user->lang) || $user->lang == 'default' ? get_config('lang') : $user->lang;
     // Internal
     $this->message = strip_tags(str_shorten_html($body, 200, true));
     // Comment deleted notification
     if ($deletedby = $comment->get('deletedby')) {
         $this->strings = (object) array('subject' => (object) array('key' => 'commentdeletednotificationsubject', 'section' => 'artefact.comment', 'args' => array($title)));
         $deletedmessage = ArtefactTypeComment::deleted_messages();
         $removedbyline = get_string_from_language($lang, $deletedmessage[$deletedby], 'artefact.comment');
         $this->message = $removedbyline . ":\n" . $this->message;
         // Email
         $this->users[0]->htmlmessage = get_string_from_language($lang, 'feedbackdeletedhtml', 'artefact.comment', $title, $removedbyline, $body, $this->url, $title);
         $this->users[0]->emailmessage = get_string_from_language($lang, 'feedbackdeletedtext', 'artefact.comment', $title, $removedbyline, trim(html2text($body)), $title, $this->url);
         return;
     }
     $this->strings = (object) array('subject' => (object) array('key' => 'newfeedbacknotificationsubject', 'section' => 'artefact.comment', 'args' => array($title)));
     $this->url .= '&showcomment=' . $comment->get('id');
     // Email
     $author = $comment->get('author');
     $authorname = empty($author) ? $comment->get('authorname') : display_name($author, $user);
     $this->users[0]->htmlmessage = get_string_from_language($lang, 'feedbacknotificationhtml', 'artefact.comment', $authorname, $title, $posttime, $body, $this->url);
     $this->users[0]->emailmessage = get_string_from_language($lang, 'feedbacknotificationtext', 'artefact.comment', $authorname, $title, $posttime, trim(html2text($body)), $this->url);
 }
Example #21
0
/**
 * This function creates a Smarty object and sets it up for use within our
 * podclass app, setting up some variables.
 *
 * The variables that it sets up are:
 *
 * - WWWROOT: The base url for the Mahara system
 * - USER: The user object
 * - JAVASCRIPT: A list of javascript files to include in the header.  This
 *   list is passed into this function (see below).
 * - HEADERS: An array of any further headers to set.  Each header is just
 *   straight HTML (see below).
 * - PUBLIC: Set true if this page is a public page
 * - MAINNAV: Array defining the main navigation
 *
 * @param $javascript A list of javascript includes.  Each include should be just
 *                    the name of a file, and reside in js/{filename}
 * @param $headers    A list of additional headers.  These are to be specified as
 *                    actual HTML.
 * @param $strings    A list of language strings required by the javascript code.
 * @return Smarty
 */
function smarty($javascript = array(), $headers = array(), $pagestrings = array(), $extraconfig = array())
{
    global $USER, $SESSION, $THEME;
    if (!is_array($headers)) {
        $headers = array();
    }
    if (!is_array($pagestrings)) {
        $pagestrings = array();
    }
    if (!is_array($extraconfig)) {
        $extraconfig = array();
    }
    $SIDEBLOCKS = array();
    $smarty = smarty_core();
    $wwwroot = get_config('wwwroot');
    // NOTE: not using jswwwroot - it seems to wreck image paths if you
    // drag them around the wysiwyg editor
    $jswwwroot = json_encode($wwwroot);
    $theme_list = array();
    if (function_exists('pieform_get_headdata')) {
        $headers = array_merge($headers, pieform_get_headdata());
    }
    // Insert the appropriate javascript tags
    $javascript_array = array();
    $jsroot = $wwwroot . 'js/';
    $langdirection = get_string('thisdirection', 'langconfig');
    // TinyMCE must be included first for some reason we're not sure about
    $checkarray = array(&$javascript, &$headers);
    $found_tinymce = false;
    foreach ($checkarray as &$check) {
        if (($key = array_search('tinymce', $check)) !== false || ($key = array_search('tinytinymce', $check)) !== false) {
            if (!$found_tinymce) {
                $found_tinymce = $check[$key];
                $javascript_array[] = $jsroot . 'tinymce/tiny_mce.js';
                $content_css = json_encode($THEME->get_url('style/tinymce.css'));
                $language = substr(current_language(), 0, 2);
                $extrasetup = isset($extraconfig['tinymcesetup']) ? $extraconfig['tinymcesetup'] : '';
                $adv_buttons = array("bold,italic,underline,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,bullist,numlist,separator,link,unlink,separator,code,fullscreen", "bold,italic,underline,strikethrough,separator,forecolor,backcolor,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,hr,emotions,image,iespell,cleanup,separator,link,unlink,separator,code", "bullist,numlist,separator,tablecontrols,separator,cut,copy,paste,pasteword", "fontselect,separator,fontsizeselect,separator,formatselect");
                // For right-to-left langs, reverse button order & align controls right.
                $tinymce_langdir = $langdirection == 'rtl' ? 'rtl' : 'ltr';
                $toolbar_align = 'left';
                if ($check[$key] == 'tinymce') {
                    $tinymce_config = <<<EOF
    mode: "none",
    theme: "advanced",
    plugins: "table,emotions,iespell,inlinepopups,paste",
    theme_advanced_buttons1 : "{$adv_buttons[1]}",
    theme_advanced_buttons2 : "{$adv_buttons[2]}",
    theme_advanced_buttons3 : "{$adv_buttons[3]}",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "{$toolbar_align}",
    //width: '512',
EOF;
                } else {
                    $tinymce_config = <<<EOF
    mode: "textareas",
    editor_selector: 'tinywysiwyg',
    theme: "advanced",
    plugins: "fullscreen,inlinepopups",
    theme_advanced_buttons1 : "{$adv_buttons[0]}",
    theme_advanced_buttons2 : "",
    theme_advanced_buttons3 : "",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "{$toolbar_align}",
    fullscreen_new_window: true,
    fullscreen_settings: {
        theme: "advanced",
        plugins: "table,emotions,iespell,inlinepopups,paste",
        theme_advanced_buttons1 : "{$adv_buttons[1]}",
        theme_advanced_buttons2 : "{$adv_buttons[2]}",
        theme_advanced_buttons3 : "{$adv_buttons[3]}"
    },
EOF;
                }
                $headers[] = <<<EOF
<script type="text/javascript">
tinyMCE.init({
    button_tile_map: true,
    {$tinymce_config}
    extended_valid_elements : "object[width|height|classid|codebase],param[name|value],embed[src|type|width|height|flashvars|wmode],script[src,type,language],+ul[id|type|compact]",
    urlconverter_callback : "custom_urlconvert",
    language: '{$language}',
    directionality: "{$tinymce_langdir}",
    content_css : {$content_css},
    //document_base_url: {$jswwwroot},
    remove_script_host: false,
    relative_urls: false,
    setup: function(ed) {
        ed.onInit.add(function(ed) {
            if (typeof(editor_to_focus) == 'string' && ed.editorId == editor_to_focus) {
                ed.focus();
            }
        });
        {$extrasetup}
    }
});
function custom_urlconvert (u, n, e) {
  // Don't convert the url on the skype status buttons.
  if (u.indexOf('skype:') == 0) {
      return u;
  }
  var t = tinyMCE.activeEditor, s = t.settings;

  // Don't convert link href since thats the CSS files that gets loaded into the editor also skip local file URLs
  if (!s.convert_urls || (e && e.nodeName == 'LINK') || u.indexOf('file:') === 0)
      return u;

  // Convert to relative
  if (s.relative_urls)
      return t.documentBaseURI.toRelative(u);

  // Convert to absolute
  u = t.documentBaseURI.toAbsolute(u, s.remove_script_host);

  return u;
}
</script>

EOF;
                unset($check[$key]);
            } else {
                if ($check[$key] != $found_tinymce) {
                    log_warn('Two differently configured tinyMCE instances have been asked for on this page! This is not possible');
                }
                unset($check[$key]);
            }
        }
    }
    if (get_config('developermode') & DEVMODE_UNPACKEDJS) {
        $javascript_array[] = $jsroot . 'MochiKit/MochiKit.js';
        $javascript_array[] = $jsroot . 'MochiKit/Position.js';
        $javascript_array[] = $jsroot . 'MochiKit/Color.js';
        $javascript_array[] = $jsroot . 'MochiKit/Visual.js';
        $javascript_array[] = $jsroot . 'MochiKit/DragAndDrop.js';
        $javascript_array[] = $jsroot . 'MochiKit/Format.js';
    } else {
        $javascript_array[] = $jsroot . 'MochiKit/Packed.js';
    }
    $javascript_array[] = $jsroot . 'keyboardNavigation.js';
    $strings = array();
    foreach ($pagestrings as $k => $v) {
        if (is_array($v)) {
            foreach ($v as $tag) {
                $strings[$tag] = get_raw_string($tag, $k);
            }
        } else {
            $strings[$k] = get_raw_string($k, $v);
        }
    }
    $jsstrings = jsstrings();
    $themepaths = themepaths();
    foreach ($javascript as $jsfile) {
        // For now, if there's no path in the js file, assume it's in
        // $jsroot and append '.js' to the name.  Later we may want to
        // ensure all smarty() calls include the full path to the js
        // file, with the proper extension.
        if (strpos($jsfile, '/') === false) {
            $javascript_array[] = $jsroot . $jsfile . '.js';
            if (isset($jsstrings[$jsfile])) {
                foreach ($jsstrings[$jsfile] as $section => $tags) {
                    foreach ($tags as $tag) {
                        $strings[$tag] = get_raw_string($tag, $section);
                    }
                }
            }
            if (isset($themepaths[$jsfile])) {
                foreach ($themepaths[$jsfile] as $themepath) {
                    $theme_list[$themepath] = $THEME->get_url($themepath);
                }
            }
        } else {
            // A .js file with a fully specified path
            $javascript_array[] = $wwwroot . $jsfile;
            // If $jsfile is from a plugin (i.e. plugintype/pluginname/js/foo.js)
            // Then get js strings from static function jsstrings in plugintype/pluginname/lib.php
            $bits = explode('/', $jsfile);
            if (count($bits) == 4) {
                safe_require($bits[0], $bits[1]);
                $pluginclass = generate_class_name($bits[0], $bits[1]);
                $name = substr($bits[3], 0, strpos($bits[3], '.js'));
                if (is_callable(array($pluginclass, 'jsstrings'))) {
                    $tempstrings = call_static_method($pluginclass, 'jsstrings', $name);
                    foreach ($tempstrings as $section => $tags) {
                        foreach ($tags as $tag) {
                            $strings[$tag] = get_raw_string($tag, $section);
                        }
                    }
                }
                if (is_callable(array($pluginclass, 'jshelp'))) {
                    $tempstrings = call_static_method($pluginclass, 'jshelp', $name);
                    foreach ($tempstrings as $section => $tags) {
                        foreach ($tags as $tag) {
                            $strings[$tag . '.help'] = get_help_icon($bits[0], $bits[1], null, null, null, $tag);
                        }
                    }
                }
                if (is_callable(array($pluginclass, 'themepaths'))) {
                    $tmpthemepaths = call_static_method($pluginclass, 'themepaths', $name);
                    foreach ($tmpthemepaths as $themepath) {
                        $theme_list[$themepath] = $THEME->get_url($themepath);
                    }
                }
            }
        }
    }
    $javascript_array[] = $jsroot . 'mahara.js';
    if (get_config('developermode') & DEVMODE_DEBUGJS) {
        $javascript_array[] = $jsroot . 'debug.js';
    }
    foreach ($jsstrings['mahara'] as $section => $tags) {
        foreach ($tags as $tag) {
            $strings[$tag] = get_raw_string($tag, $section);
        }
    }
    if (isset($extraconfig['themepaths']) && is_array($extraconfig['themepaths'])) {
        foreach ($extraconfig['themepaths'] as $themepath) {
            $theme_list[$themepath] = $THEME->get_url($themepath);
        }
    }
    $stringjs = '<script type="text/javascript">';
    $stringjs .= 'var strings = ' . json_encode($strings) . ';';
    $stringjs .= '</script>';
    // stylesheet set up - if we're in a plugin also get its stylesheet
    $stylesheets = array_reverse(array_values($THEME->get_url('style/style.css', true)));
    if (defined('SECTION_PLUGINTYPE') && defined('SECTION_PLUGINNAME') && SECTION_PLUGINTYPE != 'core') {
        if ($pluginsheets = $THEME->get_url('style/style.css', true, SECTION_PLUGINTYPE . '/' . SECTION_PLUGINNAME)) {
            $stylesheets = array_merge($stylesheets, array_reverse($pluginsheets));
        }
    }
    if (defined('ADMIN') || defined('INSTITUTIONALADMIN')) {
        if ($adminsheets = $THEME->get_url('style/admin.css', true)) {
            $stylesheets = array_merge($stylesheets, array_reverse($adminsheets));
        }
    }
    if (get_config('developermode') & DEVMODE_DEBUGCSS) {
        $stylesheets[] = get_config('wwwroot') . 'theme/debug.css';
    }
    // look for extra stylesheets
    if (isset($extraconfig['stylesheets']) && is_array($extraconfig['stylesheets'])) {
        foreach ($extraconfig['stylesheets'] as $extrasheet) {
            if ($sheets = $THEME->get_url($extrasheet, true)) {
                $stylesheets = array_merge($stylesheets, array_reverse(array_values($sheets)));
            }
        }
    }
    // Include rtl.css for right-to-left langs
    if ($langdirection == 'rtl') {
        $smarty->assign('LANGDIRECTION', 'rtl');
        if ($rtlsheets = $THEME->get_url('style/rtl.css', true)) {
            $stylesheets = array_merge($stylesheets, array_reverse($rtlsheets));
        }
    }
    $smarty->assign('STRINGJS', $stringjs);
    $smarty->assign('STYLESHEETLIST', $stylesheets);
    if (!empty($theme_list)) {
        // this gets assigned in smarty_core, but do it again here if it's changed locally
        $smarty->assign('THEMELIST', json_encode(array_merge((array) json_decode($smarty->get_template_vars('THEMELIST')), $theme_list)));
    }
    $sitename = get_config('sitename');
    if (!$sitename) {
        $sitename = 'Mahara';
    }
    $smarty->assign('sitename', $sitename);
    if (defined('TITLE')) {
        $smarty->assign('PAGETITLE', TITLE . ' - ' . $sitename);
        $smarty->assign('heading', TITLE);
    } else {
        $smarty->assign('PAGETITLE', $sitename);
    }
    if (defined('PUBLIC')) {
        $smarty->assign('PUBLIC', true);
    }
    if (defined('ADMIN')) {
        $smarty->assign('ADMIN', true);
    }
    if (defined('INSTITUTIONALADMIN')) {
        $smarty->assign('INSTITUTIONALADMIN', true);
    }
    $smarty->assign('LOGGEDIN', $USER->is_logged_in());
    if ($USER->is_logged_in()) {
        global $SELECTEDSUBNAV;
        // It's evil, but rightnav & mainnav stuff are now in different templates.
        $smarty->assign('MAINNAV', main_nav());
        $smarty->assign('RIGHTNAV', right_nav());
        $smarty->assign('SELECTEDSUBNAV', $SELECTEDSUBNAV);
    } else {
        $smarty->assign('sitedefaultlang', get_string('sitedefault', 'admin') . ' (' . get_string_from_language(get_config('lang'), 'thislanguage') . ')');
        $smarty->assign('LANGUAGES', get_languages());
    }
    $smarty->assign('FOOTERMENU', footer_menu());
    $smarty->assign_by_ref('USER', $USER);
    $smarty->assign('SESSKEY', $USER->get('sesskey'));
    $smarty->assign_by_ref('JAVASCRIPT', $javascript_array);
    $smarty->assign_by_ref('HEADERS', $headers);
    $siteclosedforupgrade = get_config('siteclosed');
    if ($siteclosedforupgrade && get_config('disablelogin')) {
        $smarty->assign('SITECLOSED', 'logindisabled');
    } else {
        if ($siteclosedforupgrade || get_config('siteclosedbyadmin')) {
            $smarty->assign('SITECLOSED', 'loginallowed');
        }
    }
    if (!isset($extraconfig['pagehelp']) || $extraconfig['pagehelp'] !== false and $help = has_page_help()) {
        $smarty->assign('PAGEHELPNAME', $help[0]);
        $smarty->assign('PAGEHELPICON', $help[1]);
    }
    if (defined('GROUP')) {
        require_once 'group.php';
        $group = group_current_group();
        $smarty->assign('GROUP', $group);
        $smarty->assign('SUBPAGENAV', group_get_menu_tabs());
        $smarty->assign('PAGEHEADING', $group->name);
    }
    // ---------- sideblock stuff ----------
    $sidebars = !isset($extraconfig['sidebars']) || $extraconfig['sidebars'] !== false;
    if ($sidebars && !defined('INSTALLER') && (!defined('MENUITEM') || substr(MENUITEM, 0, 5) != 'admin')) {
        if (get_config('installed') && !defined('ADMIN') && !defined('INSTITUTIONALADMIN')) {
            $data = site_menu();
            if (!empty($data)) {
                $smarty->assign('SITEMENU', site_menu());
                $SIDEBLOCKS[] = array('name' => 'linksandresources', 'weight' => 10, 'data' => $data);
            }
        }
        if ($USER->is_logged_in() && defined('MENUITEM') && substr(MENUITEM, 0, 11) == 'myportfolio') {
            if (get_config('showselfsearchsideblock')) {
                $SIDEBLOCKS[] = array('name' => 'selfsearch', 'weight' => 0, 'data' => array());
            }
            if (get_config('showtagssideblock')) {
                $SIDEBLOCKS[] = array('name' => 'tags', 'id' => 'sb-tags', 'weight' => 0, 'data' => tags_sideblock());
            }
        }
        if ($USER->is_logged_in() && !defined('ADMIN') && !defined('INSTITUTIONALADMIN')) {
            $SIDEBLOCKS[] = array('name' => 'profile', 'id' => 'sb-profile', 'weight' => -20, 'data' => profile_sideblock());
            if (get_config('showonlineuserssideblock')) {
                $SIDEBLOCKS[] = array('name' => 'onlineusers', 'id' => 'sb-onlineusers', 'weight' => -10, 'data' => onlineusers_sideblock());
            }
        }
        if (defined('GROUP')) {
            $SIDEBLOCKS[] = array('name' => 'group', 'id' => 'sb-groupnav', 'weight' => -10, 'data' => group_sideblock());
        }
        if (!$USER->is_logged_in() && !(get_config('siteclosed') && get_config('disablelogin'))) {
            $SIDEBLOCKS[] = array('name' => 'login', 'weight' => -10, 'id' => 'sb-loginbox', 'data' => array('loginform' => auth_generate_login_form()));
        }
        if (get_config('enablenetworking')) {
            require_once get_config('docroot') . 'api/xmlrpc/lib.php';
            if ($USER->is_logged_in() && ($ssopeers = get_service_providers($USER->authinstance))) {
                $SIDEBLOCKS[] = array('name' => 'ssopeers', 'weight' => 1, 'data' => $ssopeers);
            }
        }
        if (isset($extraconfig['sideblocks']) && is_array($extraconfig['sideblocks'])) {
            foreach ($extraconfig['sideblocks'] as $sideblock) {
                $SIDEBLOCKS[] = $sideblock;
            }
        }
        usort($SIDEBLOCKS, create_function('$a,$b', 'if ($a["weight"] == $b["weight"]) return 0; return ($a["weight"] < $b["weight"]) ? -1 : 1;'));
        // Place all sideblocks on the right. If this structure is munged
        // appropriately, you can put blocks on the left. In future versions of
        // Mahara, we'll make it easy to do this.
        $SIDEBLOCKS = array('left' => array(), 'right' => $SIDEBLOCKS);
        $smarty->assign('userauthinstance', $SESSION->get('authinstance'));
        $smarty->assign('MNETUSER', $SESSION->get('mnetuser'));
        $smarty->assign('SIDEBLOCKS', $SIDEBLOCKS);
        $smarty->assign('SIDEBARS', $sidebars);
    }
    if ($USER->get('parentuser')) {
        $smarty->assign('USERMASQUERADING', true);
        $smarty->assign('masqueradedetails', get_string('youaremasqueradingas', 'mahara', display_name($USER)));
        $smarty->assign('becomeyouagain', ' <a href="' . hsc($wwwroot) . 'admin/users/changeuser.php?restore=1">' . get_string('becomeadminagain', 'admin', hsc($USER->get('parentuser')->name)) . '</a>');
    }
    return $smarty;
}
Example #22
0
function addmember_submit(Pieform $form, $values)
{
    global $USER, $SESSION, $userid;
    $data = new StdClass();
    $data->group = $values['group'];
    $data->member = $userid;
    $data->ctime = db_format_timestamp(time());
    $data->role = 'member';
    // TODO: modify the dropdown to allow the role to be chosen
    $ctitle = get_field('group', 'name', 'id', $data->group);
    $adduser = get_record('usr', 'id', $data->member);
    try {
        insert_record('group_member', $data);
        delete_records('group_member_request', 'member', $userid, 'group', $data->group);
        $lang = get_user_language($userid);
        require_once get_config('libroot') . 'activity.php';
        activity_occurred('maharamessage', array('users' => array($userid), 'subject' => get_string_from_language($lang, 'addedtogroupsubject', 'group'), 'message' => get_string_from_language($lang, 'addedtogroupmessage', 'group', display_name($USER, $adduser), $ctitle), 'url' => get_config('wwwroot') . 'group/view.php?id=' . $values['group']));
        $SESSION->add_ok_msg(get_string('useradded', 'group'));
    } catch (SQLException $e) {
        $SESSION->add_error_msg(get_string('adduserfailed', 'group'));
    }
    redirect('/user/view.php?id=' . $userid);
}
Example #23
0
 public function release($releaseuser = null)
 {
     $submitinfo = $this->submitted_to();
     if (is_null($submitinfo)) {
         throw new ParameterException("View with id " . $this->get('id') . " has not been submitted");
     }
     $releaseuser = optional_userobj($releaseuser);
     self::_db_release(array($this->id), $this->get('owner'), $this->get('submittedgroup'));
     $ownerlang = get_user_language($this->get('owner'));
     $url = $this->get_url(false);
     require_once 'activity.php';
     activity_occurred('maharamessage', array('users' => array($this->get('owner')), 'subject' => get_string_from_language($ownerlang, 'viewreleasedsubject', 'group', $this->get('title'), $submitinfo['name'], display_name($releaseuser, $this->get_owner_object())), 'message' => get_string_from_language($ownerlang, 'viewreleasedmessage', 'group', $this->get('title'), $submitinfo['name'], display_name($releaseuser, $this->get_owner_object())), 'url' => $url, 'urltext' => $this->get('title')));
 }
Example #24
0
function addmember_submit(Pieform $form, $values)
{
    global $USER, $SESSION, $userid;
    $group = get_record('group', 'id', $values['group']);
    $ctitle = $group->name;
    $adduser = get_record('usr', 'id', $userid);
    try {
        group_add_user($values['group'], $userid, 'member');
        $lang = get_user_language($userid);
        require_once get_config('libroot') . 'activity.php';
        activity_occurred('maharamessage', array('users' => array($userid), 'subject' => get_string_from_language($lang, 'addedtogroupsubject', 'group'), 'message' => get_string_from_language($lang, 'addedtogroupmessage', 'group', display_name($USER, $adduser), $ctitle), 'url' => group_homepage_url($group, false), 'urltext' => $ctitle));
        $SESSION->add_ok_msg(get_string('useradded', 'group'));
    } catch (SQLException $e) {
        $SESSION->add_error_msg(get_string('adduserfailed', 'group'));
    }
    redirect(profile_url($adduser));
}
Example #25
0
 /**
  * @param array $data Parameters:
  *                    - viewid (int)
  *                    - annotationid (int)
  */
 public function __construct($data, $cron = false)
 {
     parent::__construct($data, $cron);
     $annotation = new ArtefactTypeAnnotation($this->annotationid);
     $annotationfeedback = new ArtefactTypeAnnotationfeedback($this->annotationfeedbackid);
     $this->overridemessagecontents = true;
     if ($onartefact = $annotation->get('artefact')) {
         // Feedback on artefact.
         $userid = null;
         require_once get_config('docroot') . 'artefact/lib.php';
         $artefactinstance = artefact_instance_from_id($onartefact);
         if ($artefactinstance->feedback_notify_owner()) {
             $userid = $artefactinstance->get('owner');
             $groupid = $artefactinstance->get('group');
             $institutionid = $artefactinstance->get('institution');
         }
         if (empty($this->url)) {
             $this->url = 'artefact/artefact.php?artefact=' . $onartefact . '&view=' . $this->viewid;
         }
     } else {
         if ($onview = $annotation->get('view')) {
             // Feedback on view.
             if (!($viewrecord = get_record('view', 'id', $onview))) {
                 throw new ViewNotFoundException(get_string('viewnotfound', 'error', $onview));
             }
             $userid = $viewrecord->owner;
             $groupid = $viewrecord->group;
             $institutionid = $viewrecord->institution;
             if (empty($this->url)) {
                 $this->url = 'view/view.php?id=' . $onview;
             }
         } else {
             // Something is wrong.
             throw new ViewNotFoundException(get_string('invalidannotationfeedbacklinkerror', 'artefact.annotation'));
         }
     }
     // Now fetch the users that will need to get notified about this event
     // depending on whether the page has an owner, group, or institution id set.
     if (!empty($userid)) {
         $this->users = activity_get_users($this->get_id(), array($userid));
     } else {
         if (!empty($groupid)) {
             require_once get_config('docroot') . 'lib/group.php';
             $sql = "SELECT u.*\n                    FROM {usr} u, {group_member} m, {group} g\n                    WHERE g.id = m.group\n                    AND m.member = u.id\n                    AND m.group = ?\n                    AND (g.feedbacknotify = " . GROUP_ROLES_ALL . "\n                         OR (g.feedbacknotify = " . GROUP_ROLES_NONMEMBER . " AND (m.role = 'tutor' OR m.role = 'admin'))\n                         OR (g.feedbacknotify = " . GROUP_ROLES_ADMIN . " AND m.role = 'admin')\n                        )";
             $this->users = get_records_sql_array($sql, array($groupid));
         } else {
             if (!empty($institutionid)) {
                 require_once get_config('libroot') . 'institution.php';
                 $institution = new Institution($institutionid);
                 $admins = $institution->institution_and_site_admins();
                 $this->users = get_records_sql_array("SELECT * FROM {usr} WHERE id IN (" . implode(',', $admins) . ")", array());
             }
         }
     }
     if (empty($this->users)) {
         // no one to notify - possibe if group 'feedbacknotify' is set to 0
         return;
     }
     $title = $onartefact ? $artefactinstance->get('title') : $viewrecord->title;
     $this->urltext = $title;
     $body = $annotationfeedback->get('description');
     $posttime = strftime(get_string('strftimedaydatetime'), $annotationfeedback->get('ctime'));
     // Internal
     $this->message = strip_tags(str_shorten_html($body, 200, true));
     // Seen as things like emaildigest base the message on $this->message
     // we need to set the language for the $removedbyline here based on first user.
     $user = $this->users[0];
     $lang = empty($user->lang) || $user->lang == 'default' ? get_config('lang') : $user->lang;
     // Comment deleted notification
     if ($deletedby = $annotationfeedback->get('deletedby')) {
         $this->strings = (object) array('subject' => (object) array('key' => 'annotationfeedbackdeletednotificationsubject', 'section' => 'artefact.annotation', 'args' => array($title)));
         $deletedmessage = ArtefactTypeAnnotationfeedback::deleted_by_types_description();
         $removedbyline = get_string_from_language($lang, $deletedmessage[$deletedby], 'artefact.annotation');
         $this->message = $removedbyline . ":\n" . $this->message;
         foreach ($this->users as $key => $user) {
             if (empty($user->lang) || $user->lang == 'default') {
                 // check to see if we need to show institution language
                 $instlang = get_user_institution_language($user->id);
                 $lang = empty($instlang) || $instlang == 'default' ? get_config('lang') : $instlang;
             } else {
                 $lang = $user->lang;
             }
             // For email we can send the message in the user's preferred language
             $removedbyline = get_string_from_language($lang, $deletedmessage[$deletedby], 'artefact.annotation');
             $this->users[$key]->htmlmessage = get_string_from_language($lang, 'annotationfeedbackdeletedhtml', 'artefact.annotation', hsc($title), $removedbyline, clean_html($body), get_config('wwwroot') . $this->url, hsc($title));
             $this->users[$key]->emailmessage = get_string_from_language($lang, 'annotationfeedbackdeletedtext', 'artefact.annotation', $title, $removedbyline, trim(html2text(htmlspecialchars($body))), $title, get_config('wwwroot') . $this->url);
         }
         return;
     }
     $this->strings = (object) array('subject' => (object) array('key' => 'newannotationfeedbacknotificationsubject', 'section' => 'artefact.annotation', 'args' => array($title)));
     $this->url .= '&showcomment=' . $annotationfeedback->get('id');
     // Email
     $author = $annotationfeedback->get('author');
     foreach ($this->users as $key => $user) {
         $authorname = empty($author) ? $annotationfeedback->get('authorname') : display_name($author, $user);
         if (empty($user->lang) || $user->lang == 'default') {
             // check to see if we need to show institution language
             $instlang = get_user_institution_language($user->id);
             $lang = empty($instlang) || $instlang == 'default' ? get_config('lang') : $instlang;
         } else {
             $lang = $user->lang;
         }
         $this->users[$key]->htmlmessage = get_string_from_language($lang, 'annotationfeedbacknotificationhtml', 'artefact.annotation', hsc($authorname), hsc($title), $posttime, clean_html($body), get_config('wwwroot') . $this->url);
         $this->users[$key]->emailmessage = get_string_from_language($lang, 'annotationfeedbacknotificationtext', 'artefact.annotation', $authorname, $title, $posttime, trim(html2text(htmlspecialchars($body))), get_config('wwwroot') . $this->url);
     }
 }
 public function declineRequestFromUser($userid)
 {
     $lang = get_user_language($userid);
     $message = (object) array('users' => array($userid), 'subject' => get_string_from_language($lang, 'institutionmemberrejectsubject'), 'message' => get_string_from_language($lang, 'institutionmemberrejectmessage', 'mahara', $this->displayname));
     db_begin();
     delete_records('usr_institution_request', 'usr', $userid, 'institution', $this->name, 'confirmedusr', 1);
     require_once 'activity.php';
     activity_occurred('maharamessage', $message);
     handle_event('updateuser', $userid);
     db_commit();
 }
function addfriend_submit(Pieform $form, $values)
{
    global $USER, $SESSION;
    $user = get_record('usr', 'id', $values['id']);
    $loggedinid = $USER->get('id');
    $userid = $user->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);
    $n->urltext = $displayname;
    $f->usr1 = $values['id'];
    $f->usr2 = $loggedinid;
    insert_record('usr_friend', $f);
    $n->subject = get_string_from_language($lang, 'addedtofriendslistsubject', 'group', $displayname);
    $n->message = get_string_from_language($lang, 'addedtofriendslistmessage', 'group', $displayname, $displayname);
    require_once 'activity.php';
    activity_occurred('maharamessage', $n);
    handle_event('addfriend', array('user' => $f->usr2, 'friend' => $f->usr1));
    $SESSION->add_ok_msg(get_string('friendformaddsuccess', 'group', display_name($user)));
    redirect('/user/view.php?id=' . $values['id']);
}
Example #28
0
function addfriend_submit(Pieform $form, $values)
{
    global $USER, $SESSION;
    $user = get_record('usr', 'id', $values['id']);
    $loggedinid = $USER->get('id');
    if (is_friend($loggedinid, $user->id)) {
        $SESSION->add_info_msg(get_string('alreadyfriends', 'group', display_name($user)));
        delete_records('usr_friend_request', 'owner', $loggedinid, 'requester', $user->id);
        redirect(profile_url($user));
    }
    // 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);
    $lang = get_user_language($user->id);
    $displayname = display_name($USER, $user);
    $n->urltext = $displayname;
    $f->usr1 = $values['id'];
    $f->usr2 = $loggedinid;
    db_begin();
    delete_records('usr_friend_request', 'owner', $loggedinid, 'requester', $user->id);
    insert_record('usr_friend', $f);
    db_commit();
    $n->subject = get_string_from_language($lang, 'addedtofriendslistsubject', 'group', $displayname);
    $n->message = get_string_from_language($lang, 'addedtofriendslistmessage', 'group', $displayname, $displayname);
    require_once 'activity.php';
    activity_occurred('maharamessage', $n);
    handle_event('addfriend', array('user' => $f->usr2, 'friend' => $f->usr1));
    $SESSION->add_ok_msg(get_string('friendformaddsuccess', 'group', display_name($user)));
    redirect(profile_url($user));
}
Example #29
0
 /**
  * Converts a Leap2A date point to a plain text version for resume date 
  * purposes.
  *
  * @param array $date The date - expected to come from {PluginImportLeap::....()}
  * @return string     The date in string form for resume composites
  */
 private static function convert_leap_date_to_resume_date($date)
 {
     if (isset($date['value'])) {
         return strftime(get_string_from_language('en.utf8', 'strftimedaydatetime'), strtotime($date['value']));
     }
     if (isset($date['label'])) {
         return $date['label'];
     }
     return '';
 }
Example #30
0
/**
 * Returns a language select form
 *
 * @return string      HTML of language select form
 */
function language_select_form()
{
    global $SESSION;
    $languageform = '';
    $languages = get_languages();
    if (count($languages) > 1) {
        $languages = array_merge(array('default' => get_string('sitedefault', 'admin') . ' (' . get_string_from_language(get_config('lang'), 'thislanguage') . ')'), $languages);
        require_once 'pieforms/pieform.php';
        $languageform = pieform(array('name' => 'languageselect', 'renderer' => 'oneline', 'validate' => false, 'presubmitcallback' => '', 'elements' => array('lang' => array('type' => 'select', 'title' => get_string('language') . ':', 'options' => $languages, 'defaultvalue' => $SESSION->get('lang') ? $SESSION->get('lang') : 'default'), 'changelang' => array('type' => 'submit', 'value' => get_string('change')))));
    }
    return $languageform;
}