Esempio n. 1
0
 /** 
  * Gets file information out of $_FILES and stores it locally in $files.
  * Checks file against max upload file size.
  * Scans file for viruses.
  * @return false for no errors, or a string describing the error
  */
 function preprocess_file()
 {
     $name = $this->inputname;
     if (!isset($_FILES[$name])) {
         return get_string('noinputnamesupplied');
     }
     $file = $_FILES[$name];
     $maxsize = get_config('maxuploadsize');
     if ($maxsize && $file['size'] > $maxsize) {
         return get_string('uploadedfiletoobig');
     }
     if ($file['error'] != UPLOAD_ERR_OK) {
         $errormsg = get_string('phpuploaderror', 'mahara', get_string('phpuploaderror_' . $file['error']), $file['error']);
         log_debug($errormsg);
         if ($file['error'] == UPLOAD_ERR_NO_TMP_DIR || $file['error'] == UPLOAD_ERR_CANT_WRITE) {
             // The admin probably needs to fix this; notify them
             // @TODO: Create a new activity type for general admin messages.
             $message = (object) array('users' => get_column('usr', 'id', 'admin', 1), 'subject' => get_string('adminphpuploaderror'), 'message' => $errormsg);
             require_once 'activity.php';
             activity_occurred('maharamessage', $message);
         } else {
             if ($file['error'] == UPLOAD_ERR_INI_SIZE || $file['error'] == UPLOAD_ERR_FORM_SIZE) {
                 return get_string('uploadedfiletoobig');
             }
         }
     }
     if (!is_uploaded_file($file['tmp_name'])) {
         return get_string('notphpuploadedfile');
     }
     if (get_config('viruschecking') && ($errormsg = mahara_clam_scan_file($file))) {
         return $errormsg;
     }
     $this->file = $file;
     return false;
 }
Esempio n. 2
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);
}
Esempio n. 3
0
function deletepost_submit(Pieform $form, $values)
{
    global $SESSION, $USER;
    $objectionable = get_record_sql("SELECT fp.id\n            FROM {interaction_forum_post} fp\n            JOIN {objectionable} o\n            ON (o.objecttype = 'forum' AND o.objectid = fp.id)\n            WHERE fp.id = ?\n            AND o.resolvedby IS NULL\n            AND o.resolvedtime IS NULL", array($values['post']));
    if ($objectionable !== false) {
        // Trigger activity.
        $data = new StdClass();
        $data->postid = $values['post'];
        $data->message = '';
        $data->reporter = $USER->get('id');
        $data->ctime = time();
        $data->event = DELETE_OBJECTIONABLE_POST;
        activity_occurred('reportpost', $data, 'interaction', 'forum');
    }
    update_record('interaction_forum_post', array('deleted' => 1), array('id' => $values['post']));
    $SESSION->add_ok_msg(get_string('deletepostsuccess', 'interaction.forum'));
    // Figure out which parent record to redirect us to. If the parent record is deleted,
    // keep moving up the chain until you find one that's not deleted.
    $postrec = new stdClass();
    $postrec->parent = $values['parent'];
    do {
        $postrec = get_record('interaction_forum_post', 'id', $postrec->parent, null, null, null, null, 'id, deleted, parent');
    } while ($postrec && $postrec->deleted && $postrec->parent);
    $redirecturl = get_config('wwwroot') . 'interaction/forum/topic.php?id=' . $values['topic'];
    if ($postrec && $postrec->parent) {
        $redirecturl .= '&post=' . $postrec->id;
    }
    redirect($redirecturl);
}
Esempio n. 4
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);
}
Esempio n. 5
0
function edit_comment_submit(Pieform $form, $values)
{
    global $viewid, $comment, $SESSION, $goto;
    db_begin();
    $comment->set('description', $values['message']);
    $comment->set('private', 1 - (int) $values['ispublic']);
    $comment->commit();
    require_once 'activity.php';
    $data = (object) array('commentid' => $comment->get('id'), 'viewid' => $viewid);
    activity_occurred('feedback', $data, 'artefact', 'comment');
    db_commit();
    $SESSION->add_ok_msg(get_string('commentupdated', 'artefact.comment'));
    redirect($goto);
}
Esempio n. 6
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);
}
Esempio n. 7
0
function contactus_submit(Pieform $form, $values)
{
    global $SESSION;
    $data = new StdClass();
    $data->fromname = $values['name'];
    $data->fromemail = $values['email'];
    $data->subject = $values['subject'];
    $data->message = $values['message'];
    if ($values['userid']) {
        $data->fromuser = $values['userid'];
    }
    require_once 'activity.php';
    activity_occurred('contactus', $data);
    $SESSION->add_ok_msg(get_string('messagesent'));
    redirect();
}
Esempio n. 8
0
/**
 * 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'));
}
function submitview_submit(Pieform $form, $values)
{
    global $SESSION, $USER, $viewid, $groupid, $group;
    db_begin();
    update_record('view', array('submittedgroup' => $groupid, 'submittedtime' => db_format_timestamp(time())), array('id' => $viewid));
    $roles = get_column('grouptype_roles', 'role', 'grouptype', $group->grouptype, 'see_submitted_views', 1);
    foreach ($roles as $role) {
        $accessrecord = (object) array('view' => $viewid, 'group' => $groupid, 'role' => $role, 'visible' => 0, 'allowcomments' => 1, 'approvecomments' => 0);
        ensure_record_exists('view_access', $accessrecord, $accessrecord);
    }
    ArtefactType::update_locked($USER->get('id'));
    activity_occurred('groupmessage', array('subject' => get_string('viewsubmitted', 'view'), 'message' => get_string('viewsubmitted', 'view'), 'submittedview' => $viewid, 'viewowner' => $USER->get('id'), 'group' => $groupid, 'roles' => $roles, 'strings' => (object) array('urltext' => (object) array('key' => 'view'))));
    db_commit();
    $SESSION->add_ok_msg(get_string('viewsubmitted', 'view'));
    redirect('/' . returnto());
}
Esempio n. 10
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);
}
Esempio n. 11
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);
}
function deletetopic_submit(Pieform $form, $values)
{
    global $SESSION, $USER, $topicid;
    $objectionable = get_record_sql("SELECT fp.id\n            FROM {interaction_forum_post} fp\n            JOIN {objectionable} o\n            ON (o.objecttype = 'forum' AND o.objectid = fp.id)\n            WHERE fp.topic = ?\n            AND fp.parent IS NULL\n            AND o.resolvedby IS NULL\n            AND o.resolvedtime IS NULL", $topicid);
    if ($objectionable !== false) {
        // Trigger activity.
        $data = new StdClass();
        $data->postid = $objectionable->id;
        $data->message = '';
        $data->reporter = $USER->get('id');
        $data->ctime = time();
        $data->event = DELETE_OBJECTIONABLE_TOPIC;
        activity_occurred('reportpost', $data, 'interaction', 'forum');
    }
    // mark topic as deleted
    update_record('interaction_forum_topic', array('deleted' => 1), array('id' => $topicid));
    // mark relevant posts as deleted
    update_record('interaction_forum_post', array('deleted' => 1), array('topic' => $topicid));
    $SESSION->add_ok_msg(get_string('deletetopicsuccess', 'interaction.forum'));
    redirect('/interaction/forum/view.php?id=' . $values['forum']);
}
Esempio n. 13
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;
    }
}
function reportpost_submit(Pieform $form, $values)
{
    global $SESSION, $USER, $postid;
    $ctime = time();
    $objection = new stdClass();
    $objection->objecttype = 'forum';
    $objection->objectid = $postid;
    $objection->reportedby = $USER->get('id');
    $objection->report = $values['message'];
    $objection->reportedtime = db_format_timestamp($ctime);
    insert_record('objectionable', $objection);
    // Trigger activity.
    $data = new StdClass();
    $data->postid = $postid;
    $data->message = $values['message'];
    $data->reporter = $USER->get('id');
    $data->ctime = $ctime;
    $data->event = REPORT_OBJECTIONABLE;
    activity_occurred('reportpost', $data, 'interaction', 'forum');
    $SESSION->add_ok_msg(get_string('reportpostsuccess', 'interaction.forum'));
    $redirecturl = get_config('wwwroot') . 'interaction/forum/topic.php?id=' . $values['topic'] . '&post=' . $postid;
    redirect($redirecturl);
}
Esempio n. 15
0
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']);
}
Esempio n. 16
0
function add_annotation_feedback_form_submit(Pieform $form, $values)
{
    global $USER;
    $data = (object) array('title' => get_string('Annotation', 'artefact.annotation'), 'description' => $values['message'], 'onannotation' => $values['annotationid']);
    // hidden fields.
    $artefactid = $values['artefactid'];
    $viewid = $values['viewid'];
    $blockid = $values['blockid'];
    if ($artefactid) {
        $artefact = artefact_instance_from_id($artefactid);
        $data->artefact = $artefactid;
        $data->owner = $artefact->get('owner');
        $data->group = $artefact->get('group');
        $data->institution = $artefact->get('institution');
    } else {
        if ($viewid) {
            $view = new View($viewid);
            $data->view = $viewid;
            $data->owner = $view->get('owner');
            $data->group = $view->get('group');
            $data->institution = $view->get('institution');
        }
    }
    if ($author = $USER->get('id')) {
        $anonymous = false;
        $data->author = $author;
    } else {
        $anonymous = true;
        $data->authorname = $values['authorname'];
    }
    if (isset($values['moderate']) && $values['ispublic'] && !$USER->can_edit_view($view)) {
        $data->private = 1;
        $data->requestpublic = 'author';
        $moderated = true;
    } else {
        $data->private = (int) (!$values['ispublic']);
        $moderated = false;
    }
    $private = $data->private;
    $annotationfeedback = new ArtefactTypeAnnotationfeedback(0, $data);
    $annotation = new ArtefactTypeAnnotation($values['annotationid']);
    db_begin();
    $annotationfeedback->commit();
    $url = $annotation->get_view_url($view->get('id'), true, false);
    $goto = get_config('wwwroot') . $url;
    if (isset($data->requestpublic) && $data->requestpublic === 'author' && $data->owner) {
        $arg = $author ? display_name($USER, null, true) : $data->authorname;
        $moderatemsg = (object) array('subject' => false, 'message' => false, 'strings' => (object) array('subject' => (object) array('key' => 'makepublicrequestsubject', 'section' => 'artefact.annotation', 'args' => array()), 'message' => (object) array('key' => 'makepublicrequestbyauthormessage', 'section' => 'artefact.annotation', 'args' => array(hsc($arg))), 'urltext' => (object) array('key' => 'Annotation', 'section' => 'artefact.annotation')), 'users' => array($data->owner), 'url' => $url);
    }
    require_once 'activity.php';
    $data = (object) array('annotationfeedbackid' => $annotationfeedback->get('id'), 'annotationid' => $values['annotationid'], 'viewid' => $viewid, 'artefactid' => $artefactid);
    activity_occurred('annotationfeedback', $data, 'artefact', 'annotation');
    if (isset($moderatemsg)) {
        activity_occurred('maharamessage', $moderatemsg);
    }
    db_commit();
    if (param_exists('offset')) {
        $options = ArtefactTypeAnnotationfeedback::get_annotation_feedback_options();
        $options->showcomment = 'last';
        $options->artefact = $artefactid;
        $options->view = $viewid;
        $options->annotation = $values['annotationid'];
        $options->block = $blockid;
        $newlist = ArtefactTypeAnnotationfeedback::get_annotation_feedback($options);
    } else {
        $newlist = null;
    }
    // If you're anonymous and your message is moderated or private, then you won't
    // be able to tell what happened to it. So we'll provide some more explanation in
    // the feedback message.
    if ($anonymous && $moderated) {
        $message = get_string('annotationfeedbacksubmittedmoderatedanon', 'artefact.annotation');
    } else {
        if ($anonymous && $private) {
            $message = get_string('annotationfeedbacksubmittedprivateanon', 'artefact.annotation');
        } else {
            $message = get_string('annotationfeedbacksubmitted', 'artefact.annotation');
        }
    }
    $form->reply(PIEFORM_OK, array('message' => $message, 'goto' => $goto, 'data' => $newlist));
}
Esempio n. 17
0
 /**
  * cronjob for new forum posts
  */
 public static function interaction_forum_new_post()
 {
     $currenttime = time();
     $minpostdelay = $currenttime - 30 * 60;
     $posts = get_records_sql_array('SELECT s.subscriber, s.type, p.id
         FROM (
             SELECT st."user" AS subscriber, st.topic AS topic, \'topic\' AS type
             FROM {interaction_forum_subscription_topic} st
             UNION SELECT sf."user" AS subscriber, t.id AS topic, \'forum\' AS type
             FROM {interaction_forum_subscription_forum} sf
             INNER JOIN {interaction_forum_topic} t ON t.forum = sf.forum
         ) s
         INNER JOIN {interaction_forum_topic} t ON (t.deleted != 1 AND t.id = s.topic)
         INNER JOIN {interaction_forum_post} p ON (p.sent != 1 AND p.ctime < ? AND p.deleted != 1 AND p.topic = t.id)
         INNER JOIN {interaction_instance} f ON (f.id = t.forum AND f.deleted != 1)
         INNER JOIN {group} g ON (g.id = f.group AND g.deleted = ?)
         INNER JOIN {group_member} gm ON (gm.member = s.subscriber AND gm.group = f.group)
         ORDER BY type, p.id', array(db_format_timestamp($minpostdelay), 0));
     // query gets a new object for every subscription
     // this combines all the objects for the same post together with an array for the subscribers
     if ($posts) {
         $count = count($posts);
         for ($i = 0; $i < $count; $i++) {
             $posts[$i]->users = array($posts[$i]->subscriber);
             $temp = $i;
             while (isset($posts[$i + 1]) && $posts[$i + 1]->id == $posts[$temp]->id && $posts[$i + 1]->type == $posts[$temp]->type) {
                 $i++;
                 $posts[$temp]->users[] = $posts[$i]->subscriber;
                 unset($posts[$i]);
             }
         }
         foreach ($posts as $post) {
             activity_occurred('newpost', array('type' => $post->type, 'postid' => $post->id, 'users' => $post->users), 'interaction', 'forum');
         }
         set_field_select('interaction_forum_post', 'sent', 1, 'ctime < ? AND deleted = 0 AND sent = 0', array(db_format_timestamp($minpostdelay)));
     }
 }
Esempio n. 18
0
 public function submit($group)
 {
     global $USER;
     if ($this->is_submitted()) {
         throw new SystemException('Attempting to submit a submitted view');
     }
     $group->roles = get_column('grouptype_roles', 'role', 'grouptype', $group->grouptype, 'see_submitted_views', 1);
     self::_db_submit(array($this->id), $group);
     activity_occurred('groupmessage', array('group' => $group->id, 'roles' => $group->roles, 'url' => $this->get_url(false), 'strings' => (object) array('urltext' => (object) array('key' => 'view'), 'subject' => (object) array('key' => 'viewsubmittedsubject1', 'section' => 'activity', 'args' => array($group->name)), 'message' => (object) array('key' => 'viewsubmittedmessage1', 'section' => 'activity', 'args' => array(display_name($USER, null, false, true), $this->title, $group->name)))));
 }
Esempio n. 19
0
 public function notify_user($user)
 {
     $changes = new stdClass();
     $userdata = $this->to_stdclass();
     // some stuff gets overridden by user specific stuff
     if (!empty($user->url)) {
         $userdata->url = $user->url;
     }
     if (empty($user->lang) || $user->lang == 'default') {
         $user->lang = get_config('lang');
     }
     if (empty($user->method)) {
         // If method is not set then either the user has selected 'none' or their setting has not been set (so use default).
         if ($record = get_record('usr_activity_preference', 'usr', $user->id, 'activity', $this->get_id())) {
             $user->method = $record->method;
             if (empty($user->method)) {
                 // The user specified 'none' as their notification type.
                 return;
             }
         } else {
             $user->method = $this->get_default_method();
             if (empty($user->method)) {
                 // The default notification type is 'none' for this activity type.
                 return;
             }
         }
     }
     // always do internal
     foreach (PluginNotificationInternal::$userdata as &$p) {
         $function = 'get_' . $p;
         $userdata->{$p} = $this->{$function}($user);
     }
     $userdata->internalid = PluginNotificationInternal::notify_user($user, $userdata);
     if ($this->update_url($userdata->internalid)) {
         $changes->url = $userdata->url = $this->url;
     }
     if ($user->method != 'internal' || isset($changes->url)) {
         // OVERWRITE 1: replacement, changed from:
         //$changes->read = (int) ($user->method != 'internal');
         $changes->read = 0;
         // END OVERWRITE 1
         $changes->id = $userdata->internalid;
         update_record('notification_internal_activity', $changes);
     }
     if ($user->method != 'internal') {
         $method = $user->method;
         safe_require('notification', $method);
         $notificationclass = generate_class_name('notification', $method);
         $classvars = get_class_vars($notificationclass);
         if (!empty($classvars['userdata'])) {
             foreach ($classvars['userdata'] as &$p) {
                 $function = 'get_' . $p;
                 if (!isset($userdata->{$p}) && method_exists($this, $function)) {
                     $userdata->{$p} = $this->{$function}($user);
                 }
             }
         }
         try {
             call_static_method($notificationclass, 'notify_user', $user, $userdata);
         } catch (MaharaException $e) {
             static $badnotification = false;
             static $adminnotified = array();
             // We don't mind other notification methods failing, as it'll
             // go into the activity log as 'unread'
             $changes->read = 0;
             update_record('notification_internal_activity', $changes);
             if (!$badnotification && !($e instanceof EmailDisabledException || $e instanceof InvalidEmailException)) {
                 // Admins should probably know about the error, but to avoid sending too many similar notifications,
                 // save an initial prefix of the message being sent and throw away subsequent exceptions with the
                 // same prefix.  To cut down on spam, it's worth missing out on a few similar messages.
                 $k = substr($e, 0, 60);
                 if (!isset($adminnotified[$k])) {
                     $message = (object) array('users' => get_column('usr', 'id', 'admin', 1), 'subject' => get_string('adminnotificationerror', 'activity'), 'message' => $e);
                     $adminnotified[$k] = 1;
                     $badnotification = true;
                     activity_occurred('maharamessage', $message);
                     $badnotification = false;
                 }
             }
         }
     }
     // The user's unread message count does not need to be updated from $changes->read
     // because of the db trigger on notification_internal_activity.
 }
Esempio n. 20
0
function artefact_watchlist_notification($artefactids)
{
    // gets all the views containing this artefact or a parent of this artefact and creates a watchlist activity for each view
    if ($views = get_column_sql('SELECT DISTINCT "view" FROM {view_artefact} WHERE artefact IN (' . implode(',', array_merge(array_keys(artefact_get_parents_for_cache($artefactids)), array_map('intval', $artefactids))) . ')')) {
        require_once 'activity.php';
        foreach ($views as $view) {
            activity_occurred('watchlist', (object) array('view' => $view));
        }
    }
}
Esempio n. 21
0
function add_feedback_form_submit(Pieform $form, $values)
{
    global $view, $artefact, $USER;
    $data = (object) array('title' => get_string('Comment', 'artefact.comment'), 'description' => $values['message']);
    if ($artefact) {
        $data->onartefact = $artefact->get('id');
        $data->owner = $artefact->get('owner');
        $data->group = $artefact->get('group');
        $data->institution = $artefact->get('institution');
    } else {
        $data->onview = $view->get('id');
        $data->owner = $view->get('owner');
        $data->group = $view->get('group');
        $data->institution = $view->get('institution');
    }
    if ($author = $USER->get('id')) {
        $anonymous = false;
        $data->author = $author;
    } else {
        $anonymous = true;
        $data->authorname = $values['authorname'];
    }
    if (isset($values['moderate']) && $values['ispublic'] && !$USER->can_edit_view($view)) {
        $data->private = 1;
        $data->requestpublic = 'author';
        $moderated = true;
    } else {
        $data->private = (int) (!$values['ispublic']);
        $moderated = false;
    }
    $private = $data->private;
    if (get_config('licensemetadata')) {
        $data->license = $values['license'];
        $data->licensor = $values['licensor'];
        $data->licensorurl = $values['licensorurl'];
    }
    if (isset($values['rating'])) {
        $data->rating = valid_rating($values['rating']);
    }
    $comment = new ArtefactTypeComment(0, $data);
    db_begin();
    $comment->commit();
    $url = $comment->get_view_url($view->get('id'), true, false);
    $goto = get_config('wwwroot') . $url;
    if (isset($data->requestpublic) && $data->requestpublic === 'author' && $data->owner) {
        $arg = $author ? display_name($USER, null, true) : $data->authorname;
        $moderatemsg = (object) array('subject' => false, 'message' => false, 'strings' => (object) array('subject' => (object) array('key' => 'makepublicrequestsubject', 'section' => 'artefact.comment', 'args' => array()), 'message' => (object) array('key' => 'makepublicrequestbyauthormessage', 'section' => 'artefact.comment', 'args' => array(hsc($arg))), 'urltext' => (object) array('key' => 'Comment', 'section' => 'artefact.comment')), 'users' => array($data->owner), 'url' => $url);
    }
    if (!empty($values['attachments']) && is_array($values['attachments']) && !empty($data->author)) {
        require_once get_config('libroot') . 'uploadmanager.php';
        safe_require('artefact', 'file');
        $ownerlang = empty($data->owner) ? get_config('lang') : get_user_language($data->owner);
        $folderid = ArtefactTypeFolder::get_folder_id(get_string_from_language($ownerlang, 'feedbackattachdirname', 'artefact.comment'), get_string_from_language($ownerlang, 'feedbackattachdirdesc', 'artefact.comment'), null, true, $data->owner, $data->group, $data->institution);
        $attachment = (object) array('owner' => $data->owner, 'group' => $data->group, 'institution' => $data->institution, 'author' => $data->author, 'allowcomments' => 0, 'parent' => $folderid, 'description' => get_string_from_language($ownerlang, 'feedbackonviewbyuser', 'artefact.comment', $view->get('title'), display_name($USER)));
        foreach ($values['attachments'] as $filesindex) {
            $originalname = $_FILES[$filesindex]['name'];
            $attachment->title = ArtefactTypeFileBase::get_new_file_title($originalname, $folderid, $data->owner, $data->group, $data->institution);
            try {
                $fileid = ArtefactTypeFile::save_uploaded_file($filesindex, $attachment);
            } catch (QuotaExceededException $e) {
                if ($data->owner == $USER->get('id')) {
                    $form->reply(PIEFORM_ERR, array('message' => $e->getMessage()));
                }
                redirect($goto);
            } catch (UploadException $e) {
                $form->reply(PIEFORM_ERR, array('message' => $e->getMessage()));
                redirect($goto);
            }
            $comment->attach($fileid);
        }
    }
    require_once 'activity.php';
    $data = (object) array('commentid' => $comment->get('id'), 'viewid' => $view->get('id'));
    activity_occurred('feedback', $data, 'artefact', 'comment');
    if (isset($moderatemsg)) {
        activity_occurred('maharamessage', $moderatemsg);
    }
    db_commit();
    $newlist = ArtefactTypeComment::get_comments(10, 0, 'last', $view, $artefact);
    // If you're anonymous and your message is moderated or private, then you won't
    // be able to tell what happened to it. So we'll provide some more explanation in
    // the feedback message.
    if ($anonymous && $moderated) {
        $message = get_string('feedbacksubmittedmoderatedanon', 'artefact.comment');
    } else {
        if ($anonymous && $private) {
            $message = get_string('feedbacksubmittedprivateanon', 'artefact.comment');
        } else {
            $message = get_string('feedbacksubmitted', 'artefact.comment');
        }
    }
    $form->reply(PIEFORM_OK, array('message' => $message, 'goto' => $goto, 'data' => $newlist));
}
Esempio n. 22
0
/**
 * This function is a wrapper around safe_require which will attempt to
 * handle missing plugins more gracefully.
 *
 * If a missing plugin is detected, then that plugin will be disabled, and
 * an e-mail will be sent to site administrators to inform them of the
 * issue.
 *
 * See @safe_require for further information on that function.
 *
 * @param string $plugintype the type of plugin (eg artefact)
 * @param string $pluginname the name of the plugin (eg blog)
 * @param string $filename the name of the file to include within the plugin structure
 * @param string $function (optional, defaults to require) the require/include function to use
 * @param string $nonfatal (optional, defaults to false) just returns false if the file doesn't exist
 */
function safe_require_plugin($plugintype, $pluginname, $filename = 'lib.php', $function = 'require_once', $nonfatal = false)
{
    try {
        safe_require($plugintype, $pluginname, $filename, $function, $nonfatal);
        return true;
    } catch (SystemException $e) {
        if (get_field($plugintype . '_installed', 'active', 'name', $pluginname) == 1) {
            global $SESSION;
            set_field($plugintype . '_installed', 'active', 0, 'name', $pluginname);
            $SESSION->add_error_msg(get_string('missingplugindisabled', 'admin', hsc("{$plugintype}:{$pluginname}")));
            // Reset the plugin cache.
            plugins_installed('', TRUE, TRUE);
            // Alert site admins that the plugin is broken so was disabled
            $message = new stdClass();
            $message->users = get_column('usr', 'id', 'admin', 1);
            $message->subject = get_string('pluginbrokenanddisabledtitle', 'mahara', $pluginname);
            $message->message = get_string('pluginbrokenanddisabled', 'mahara', $pluginname, $e->getMessage());
            require_once 'activity.php';
            activity_occurred('maharamessage', $message);
        }
        return false;
    }
}
Esempio n. 23
0
function edit_annotation_feedback_notify($view, $author, $owner)
{
    global $annotation, $SESSION;
    $data = (object) array('subject' => false, 'message' => false, 'strings' => (object) array('subject' => (object) array('key' => 'makepublicrequestsubject', 'section' => 'artefact.annotation', 'args' => array()), 'message' => (object) array('key' => 'makepublicrequestbyauthormessage', 'section' => 'artefact.annotation', 'args' => array(hsc(display_name($author, $owner)))), 'urltext' => (object) array('key' => 'annotation', 'section' => 'artefact.annotation')), 'users' => array($owner), 'url' => $annotation->get_view_url($view->get('id'), true, false));
    if (!empty($owner)) {
        $SESSION->add_ok_msg(get_string('makepublicrequestsent', 'artefact.annotation', display_name($owner)));
    }
    activity_occurred('maharamessage', $data);
}
 public function inviteUser($user)
 {
     $userid = is_object($user) ? $user->id : $user;
     db_begin();
     insert_record('usr_institution_request', (object) array('usr' => $userid, 'institution' => $this->name, 'confirmedinstitution' => 1, 'ctime' => db_format_timestamp(time())));
     require_once 'activity.php';
     activity_occurred('institutionmessage', (object) array('messagetype' => 'invite', 'users' => array($userid), 'institution' => (object) array('name' => $this->name, 'displayname' => $this->displayname)));
     handle_event('updateuser', $userid);
     db_commit();
 }
Esempio n. 25
0
function postnotobjectionable_submit(Pieform $form, $values)
{
    global $SESSION, $USER, $topicid;
    db_begin();
    $objections = explode(',', $values['objection']);
    // Mark records as resolved.
    foreach ($objections as $objection) {
        $todb = new stdClass();
        $todb->resolvedby = $USER->get('id');
        $todb->resolvedtime = db_format_timestamp(time());
        update_record('objectionable', $todb, array('id' => $objection));
    }
    // Trigger activity.
    $data = new StdClass();
    $data->postid = $values['postid'];
    $data->message = '';
    $data->reporter = $USER->get('id');
    $data->ctime = time();
    $data->event = MAKE_NOT_OBJECTIONABLE;
    activity_occurred('reportpost', $data, 'interaction', 'forum');
    db_commit();
    $SESSION->add_ok_msg(get_string('postnotobjectionablesuccess', 'interaction.forum'));
    $redirecturl = get_config('wwwroot') . 'interaction/forum/topic.php?id=' . $topicid . '&post=' . $values['postid'];
    redirect($redirecturl);
}
Esempio n. 26
0
function _email_or_notify($user, $subject, $bodytext, $bodyhtml)
{
    try {
        email_user($user, null, $subject, $bodytext, $bodyhtml);
    } catch (EmailException $e) {
        // Send a notification instead - email is invalid or disabled for this user
        $message = new StdClass();
        $message->users = array($user->id);
        $message->subject = $subject;
        $message->message = $bodytext;
        require_once 'activity.php';
        activity_occurred('maharamessage', $message);
    }
}
Esempio n. 27
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));
}
Esempio n. 28
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);
}
Esempio n. 29
0
 *
 * @package    mahara
 * @subpackage core
 * @author     Catalyst IT Ltd
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
 *
 */
define('INTERNAL', 1);
define('JSON', 1);
require dirname(dirname(__FILE__)) . '/init.php';
json_headers();
$data = new StdClass();
$data->view = param_integer('view');
$data->artefact = param_integer('artefact', null);
$data->message = param_variable('message');
$data->public = param_boolean('public') ? 1 : 0;
$data->attachment = param_integer('attachment', null);
$data->author = $USER->get('id');
$data->ctime = db_format_timestamp(time());
if ($data->artefact) {
    $table = 'artefact_feedback';
} else {
    $table = 'view_feedback';
}
if (!insert_record($table, $data, 'id', true)) {
    json_reply('local', get_string('addfeedbackfailed', 'view'));
}
require_once 'activity.php';
activity_occurred('feedback', $data);
json_reply(false, get_string('feedbacksubmitted', 'view'));
Esempio n. 30
0
function notrude_form_submit(Pieform $form, $values)
{
    global $view, $artefact, $USER;
    require_once 'activity.php';
    db_begin();
    $objection = new stdClass();
    if ($artefact) {
        $objection->objecttype = 'artefact';
        $objection->objectid = $artefact->get('id');
    } else {
        $objection->objecttype = 'view';
        $objection->objectid = $view->get('id');
    }
    $objection->resolvedby = $USER->get('id');
    $objection->resolvedtime = db_format_timestamp(time());
    update_record('objectionable', $objection, array('id' => $values['objection']));
    // Send notification to other admins.
    $reportername = display_default_name($USER);
    if ($artefact) {
        $goto = get_config('wwwroot') . 'artefact/artefact.php?artefact=' . $artefact->get('id') . '&view=' . $view->get('id');
    } else {
        $goto = $view->get_url();
    }
    $data = (object) array('view' => $view->get('id'), 'reporter' => $USER->get('id'), 'subject' => false, 'message' => false, 'strings' => (object) array('subject' => (object) array('key' => 'viewunobjectionablesubject', 'section' => 'view', 'args' => array($view->get('title'), $reportername)), 'message' => (object) array('key' => 'viewunobjectionablebody', 'section' => 'view', 'args' => array($reportername, $view->get('title'), $view->formatted_owner()))));
    activity_occurred('objectionable', $data);
    db_commit();
    $form->reply(PIEFORM_OK, array('message' => get_string('messagesent'), 'goto' => $goto));
}