Example #1
0
function deleteview_submit(Pieform $form, $values)
{
    global $SESSION, $viewid, $groupid, $institution;
    $view = new View($viewid, null);
    $view->delete();
    $SESSION->add_ok_msg(get_string('viewdeleted', 'view'));
    if ($groupid) {
        redirect('/view/groupviews.php?group=' . $groupid);
    }
    if ($institution) {
        redirect('/view/institutionviews.php?institution=' . $institution);
    }
    redirect('/view/');
}
function deleteview_submit(Pieform $form, $values)
{
    global $SESSION, $USER, $viewid, $groupid, $institution, $goto;
    $view = new View($viewid, null);
    if (View::can_remove_viewtype($view->get('type')) || $USER->get('admin')) {
        $view->delete();
        $SESSION->add_ok_msg(get_string('viewdeleted', 'view'));
    } else {
        $SESSION->add_error_msg(get_string('cantdeleteview', 'view'));
    }
    if ($groupid) {
        redirect('/view/groupviews.php?group=' . $groupid);
    }
    if ($institution) {
        redirect('/view/institutionviews.php?institution=' . $institution);
    }
    redirect('/view/' . $goto);
}
 function delete_submit(Pieform $form, $values)
 {
     global $SESSION;
     $authinstanceids = get_column('auth_instance', 'id', 'institution', $values['i']);
     $viewids = get_column('view', 'id', 'institution', $values['i']);
     $artefactids = get_column('artefact', 'id', 'institution', $values['i']);
     db_begin();
     if ($viewids) {
         require_once get_config('libroot') . 'view.php';
         foreach ($viewids as $viewid) {
             $view = new View($viewid);
             $view->delete();
         }
     }
     if ($artefactids) {
         foreach ($artefactids as $artefactid) {
             try {
                 $a = artefact_instance_from_id($artefactid);
                 $a->delete();
             } catch (ArtefactNotFoundException $e) {
                 // Awesome, it's already gone.
             }
         }
     }
     foreach ($authinstanceids as $id) {
         delete_records('auth_instance_config', 'instance', $id);
     }
     delete_records('auth_instance', 'institution', $values['i']);
     delete_records('host', 'institution', $values['i']);
     delete_records('institution_locked_profile_field', 'name', $values['i']);
     delete_records('usr_institution_request', 'institution', $values['i']);
     delete_records('institution', 'name', $values['i']);
     db_commit();
     $SESSION->add_ok_msg(get_string('institutiondeletedsuccessfully', 'admin'));
     redirect('/admin/users/institutions.php');
 }
/**
 * Deletes a user
 *
 * This function ensures that a user is deleted according to how Mahara wants a 
 * deleted user to be. You can call it multiple times on the same user without 
 * harm.
 *
 * @param int $userid The ID of the user to delete
 */
function delete_user($userid)
{
    db_begin();
    // We want to append 'deleted.timestamp' to some unique fields in the usr
    // table, so they can be reused by new accounts
    $fieldstomunge = array('username', 'email');
    $datasuffix = '.deleted.' . time();
    $user = get_record('usr', 'id', $userid, null, null, null, null, implode(', ', $fieldstomunge));
    $deleterec = new StdClass();
    $deleterec->id = $userid;
    $deleterec->deleted = 1;
    foreach ($fieldstomunge as $field) {
        if (!preg_match('/\\.deleted\\.\\d+$/', $user->{$field})) {
            $deleterec->{$field} = $user->{$field} . $datasuffix;
        }
    }
    // Set authinstance to default internal, otherwise the old authinstance can be blocked from deletion
    // by deleted users.
    $authinst = get_field('auth_instance', 'id', 'institution', 'mahara', 'authname', 'internal');
    if ($authinst) {
        $deleterec->authinstance = $authinst;
    }
    update_record('usr', $deleterec);
    // Remove user from any groups they're in, invited to or want to be in
    $groupids = get_column('group_member', '"group"', 'member', $userid);
    if ($groupids) {
        require_once get_config('libroot') . 'group.php';
        foreach ($groupids as $groupid) {
            group_remove_user($groupid, $userid, true);
        }
    }
    delete_records('group_member_request', 'member', $userid);
    delete_records('group_member_invite', 'member', $userid);
    // Remove any friend relationships the user is in
    execute_sql('DELETE FROM {usr_friend}
        WHERE usr1 = ?
        OR usr2 = ?', array($userid, $userid));
    execute_sql('DELETE FROM {usr_friend_request}
        WHERE owner = ?
        OR requester = ?', array($userid, $userid));
    delete_records('artefact_access_usr', 'usr', $userid);
    delete_records('auth_remote_user', 'localusr', $userid);
    delete_records('import_queue', 'usr', $userid);
    delete_records('usr_account_preference', 'usr', $userid);
    delete_records('usr_activity_preference', 'usr', $userid);
    delete_records('usr_infectedupload', 'usr', $userid);
    delete_records('usr_institution', 'usr', $userid);
    delete_records('usr_institution_request', 'usr', $userid);
    delete_records('usr_password_request', 'usr', $userid);
    delete_records('usr_watchlist_view', 'usr', $userid);
    delete_records('view_access', 'usr', $userid);
    // Remove the user's views & artefacts
    $viewids = get_column('view', 'id', 'owner', $userid);
    if ($viewids) {
        require_once get_config('libroot') . 'view.php';
        foreach ($viewids as $viewid) {
            $view = new View($viewid);
            $view->delete();
        }
    }
    $artefactids = get_column('artefact', 'id', 'owner', $userid);
    // @todo: test all artefact bulk_delete stuff, then replace the one-by-one
    // artefact deletion below with ArtefactType::delete_by_artefacttype($artefactids);
    if ($artefactids) {
        foreach ($artefactids as $artefactid) {
            try {
                $a = artefact_instance_from_id($artefactid);
                $a->delete();
            } catch (ArtefactNotFoundException $e) {
                // Awesome, it's already gone.
            }
        }
    }
    db_commit();
    handle_event('deleteuser', $userid);
}
Example #5
0
/**
 * Deletes a group.
 *
 * All group deleting should be done through this function, even though it is
 * simple. What is required to perform group deletion may change over time.
 *
 * @param int $groupid The group to delete
 * @param string $shortname   shortname of the group
 * @param string $institution institution of the group
 *
 * {{@internal Maybe later we can have a group_can_be_deleted function if
 * necessary}}
 */
function group_delete($groupid, $shortname = null, $institution = null, $notifymembers = true)
{
    if (empty($groupid) && !empty($institution) && !is_null($shortname) && strlen($shortname)) {
        // External call to delete a group, check permission of $USER.
        global $USER;
        if (!$USER->can_edit_institution($institution)) {
            throw new AccessDeniedException("group_delete: cannot delete a group in this institution");
        }
        $group = get_record('group', 'shortname', $shortname, 'institution', $institution);
    } else {
        $groupid = group_param_groupid($groupid);
        $group = get_record('group', 'id', $groupid);
    }
    db_begin();
    // Leave the group_member table alone, it's needed for the deleted
    // group notification that's about to happen on cron.
    delete_records('group_member_invite', 'group', $group->id);
    delete_records('group_member_request', 'group', $group->id);
    delete_records('view_access', 'group', $group->id);
    // Delete views owned by the group
    require_once get_config('libroot') . 'view.php';
    foreach (get_column('view', 'id', 'group', $group->id) as $viewid) {
        $view = new View($viewid);
        $view->delete();
    }
    // Release views submitted to the group
    foreach (get_column('view', 'id', 'submittedgroup', $group->id) as $viewid) {
        $view = new View($viewid);
        $view->release();
    }
    // Delete artefacts
    require_once get_config('docroot') . 'artefact/lib.php';
    ArtefactType::delete_by_artefacttype(get_column('artefact', 'id', 'group', $group->id));
    // Delete forums
    require_once get_config('docroot') . 'interaction/lib.php';
    foreach (get_column('interaction_instance', 'id', 'group', $group->id) as $forumid) {
        $forum = interaction_instance_from_id($forumid);
        $forum->delete();
    }
    if ($notifymembers) {
        require_once 'activity.php';
        activity_occurred('groupmessage', array('group' => $group->id, 'deletedgroup' => true, 'strings' => (object) array('subject' => (object) array('key' => 'deletegroupnotificationsubject', 'section' => 'group', 'args' => array(hsc($group->name))), 'message' => (object) array('key' => 'deletegroupnotificationmessage', 'section' => 'group', 'args' => array(hsc($group->name), get_config('sitename'))))));
    }
    // make sure the group name + deleted suffix will fit within 128 chars
    $delete_name = $group->name;
    if (strlen($delete_name) > 100) {
        $delete_name = substr($delete_name, 0, 100) . '(...)';
    }
    update_record('group', array('deleted' => 1, 'name' => $delete_name . '.deleted.' . time(), 'shortname' => null, 'institution' => null, 'category' => null, 'urlid' => null), array('id' => $group->id));
    db_commit();
}
Example #6
0
 function delete_submit(Pieform $form, $values)
 {
     global $SESSION;
     $authinstanceids = get_column('auth_instance', 'id', 'institution', $values['i']);
     $collectionids = get_column('collection', 'id', 'institution', $values['i']);
     $viewids = get_column('view', 'id', 'institution', $values['i']);
     $artefactids = get_column('artefact', 'id', 'institution', $values['i']);
     $regdataids = get_column('institution_registration', 'id', 'institution', $values['i']);
     db_begin();
     if ($collectionids) {
         require_once get_config('libroot') . 'collection.php';
         foreach ($collectionids as $collectionid) {
             $collection = new Collection($collectionid);
             $collection->delete();
         }
     }
     if ($viewids) {
         require_once get_config('libroot') . 'view.php';
         foreach ($viewids as $viewid) {
             $view = new View($viewid);
             $view->delete();
         }
     }
     if ($artefactids) {
         foreach ($artefactids as $artefactid) {
             try {
                 $a = artefact_instance_from_id($artefactid);
                 $a->delete();
             } catch (ArtefactNotFoundException $e) {
                 // Awesome, it's already gone.
             }
         }
     }
     // If any users are still using this institution's authinstances, change them now.
     if ($authinstanceids) {
         execute_sql("\n                    UPDATE {usr}\n                    SET authinstance = (\n                        SELECT MIN(id) FROM {auth_instance} WHERE institution = 'mahara' AND authname = 'internal'\n                    )\n                    WHERE authinstance IN (" . join(',', array_fill(0, count($authinstanceids), '?')) . ')', $authinstanceids);
     }
     foreach ($authinstanceids as $id) {
         delete_records('auth_instance_config', 'instance', $id);
     }
     foreach ($regdataids as $id) {
         delete_records('institution_registration_data', 'registration_id', $id);
     }
     // The institution should have been removed from favourites lists when the members were removed,
     // but make sure it's gone.
     execute_sql('DELETE FROM {favorite_usr} WHERE favorite IN (SELECT id FROM {favorite} WHERE institution = ?)', array($values['i']));
     delete_records('favorite', 'institution', $values['i']);
     execute_sql("UPDATE {group} SET institution = NULL, shortname = NULL WHERE institution = ?", array($values['i']));
     delete_records('auth_instance', 'institution', $values['i']);
     delete_records('host', 'institution', $values['i']);
     delete_records('institution_locked_profile_field', 'name', $values['i']);
     delete_records('usr_institution_request', 'institution', $values['i']);
     delete_records('view_access', 'institution', $values['i']);
     delete_records('institution_data', 'institution', $values['i']);
     delete_records('institution_registration', 'institution', $values['i']);
     delete_records('site_content', 'institution', $values['i']);
     delete_records('institution_config', 'institution', $values['i']);
     delete_records('usr_custom_layout', 'institution', $values['i']);
     delete_records('usr_registration', 'institution', $values['i']);
     delete_records('institution', 'name', $values['i']);
     db_commit();
     $SESSION->add_ok_msg(get_string('institutiondeletedsuccessfully', 'admin'));
     redirect('/admin/users/institutions.php');
 }
 protected function __actionDelete(array $views, $redirect)
 {
     rsort($views);
     $success = true;
     foreach ($views as $path) {
         try {
             View::delete($path);
         } catch (Exception $e) {
             $success = false;
         }
     }
     if ($success == true) {
         redirect($redirect);
     }
     $this->alerts()->append(__('An error occurred while attempting to delete selected views. <a class="more">Show trace information.</a>'), AlertStack::ERROR, $e);
 }