Exemplo n.º 1
0
     $user = get_user_by_userid($_REQUEST['userid']);
     DBstart();
     $result = delete_user($_REQUEST['userid']);
     $result = DBend($result);
     show_messages($result, S_USER_DELETED, S_CANNOT_DELETE_USER);
     if ($result) {
         add_audit(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_USER, 'User alias [' . $user['alias'] . '] name [' . $user['name'] . '] surname [' . $user['surname'] . ']');
         unset($_REQUEST['userid']);
         unset($_REQUEST['form']);
     }
 } else {
     if (isset($_REQUEST['grpaction']) && isset($_REQUEST['usrgrpid']) && isset($_REQUEST['userid']) && $_REQUEST['grpaction'] == 1) {
         $user = get_user_by_userid($_REQUEST['userid']);
         $group = get_group_by_usrgrpid($_REQUEST['usrgrpid']);
         DBstart();
         $result = add_user_to_group($_REQUEST['userid'], $_REQUEST['usrgrpid']);
         $result = DBend($result);
         show_messages($result, S_USER_UPDATED, S_CANNOT_UPDATE_USER);
         if ($result) {
             add_audit(AUDIT_ACTION_ADD, AUDIT_RESOURCE_USER_GROUP, 'User alias [' . $user['alias'] . '] name [' . $user['name'] . '] surname [' . $user['surname'] . ']');
             unset($_REQUEST['usrgrpid']);
             unset($_REQUEST['userid']);
         }
         unset($_REQUEST['grpaction']);
         unset($_REQUEST['form']);
     } else {
         if (isset($_REQUEST['grpaction']) && isset($_REQUEST['usrgrpid']) && isset($_REQUEST['userid']) && $_REQUEST['grpaction'] == 0) {
             $user = get_user_by_userid($_REQUEST['userid']);
             $group = get_group_by_usrgrpid($_REQUEST['usrgrpid']);
             DBstart();
             $result = remove_user_from_group($_REQUEST['userid'], $_REQUEST['usrgrpid']);
Exemplo n.º 2
0
function update_user_group($usrgrpid, $name, $users_status, $gui_access, $api_access, $debug_mode, $users = array(), $rights = array())
{
    global $USER_DETAILS;
    $sql = 'SELECT * ' . ' FROM usrgrp ' . ' WHERE name=' . zbx_dbstr($name) . ' AND usrgrpid<>' . $usrgrpid . ' AND ' . DBin_node('usrgrpid', get_current_nodeid(false));
    if (DBfetch(DBselect($sql))) {
        error("Group '{$name}' already exists");
        return 0;
    }
    $result = DBexecute('UPDATE usrgrp SET name=' . zbx_dbstr($name) . ' WHERE usrgrpid=' . $usrgrpid);
    if (!$result) {
        return $result;
    }
    // must come before adding user to group
    $result &= change_group_status($usrgrpid, $users_status);
    $result &= change_group_gui_access($usrgrpid, $gui_access);
    $result &= change_group_api_access($usrgrpid, $api_access);
    $result &= change_group_debug_mode($usrgrpid, $debug_mode);
    if (!$result) {
        return $result;
    }
    //-------
    $grant = true;
    if ($gui_access == GROUP_GUI_ACCESS_DISABLED || $users_status == GROUP_STATUS_DISABLED) {
        $grant = !uint_in_array($USER_DETAILS['userid'], $users);
    }
    if ($grant) {
        $result = DBexecute('DELETE FROM users_groups WHERE usrgrpid=' . $usrgrpid);
        foreach ($users as $userid => $name) {
            $result = add_user_to_group($userid, $usrgrpid);
            if (!$result) {
                return $result;
            }
        }
    } else {
        error(S_USER_CANNOT_DISABLE_ITSELF);
        return false;
    }
    $result = DBexecute('DELETE FROM rights WHERE groupid=' . $usrgrpid);
    foreach ($rights as $right) {
        $id = get_dbid('rights', 'rightid');
        $result = DBexecute('INSERT INTO rights (rightid,groupid,permission,id)' . ' VALUES (' . $id . ',' . $usrgrpid . ',' . $right['permission'] . ',' . $right['id'] . ')');
        if (!$result) {
            return $result;
        }
    }
    return $result;
}
Exemplo n.º 3
0
\t\t\t\tset
\t\t\t\t\tstatus = ?
\t\t\t\twhere
\t\t\t\t\tgroup_id rlike ?
\t\t\t\t\tand
\t\t\t\t\tdmn_id = ?
SQL_QUERY;
        check_for_lock_file();
        $rs_update_htaccess = exec_query($sql, $query, array($change_status, $group_id, $dmn_id));
        send_request();
        set_page_message(tr('User was deleted from group ') . "- " . $rs->fields['ugroup']);
    } else {
        return;
    }
}
// ** end of funcfions
gen_client_menu($tpl);
gen_logged_from($tpl);
check_permissions($tpl);
$dmn_id = get_user_domain_id($sql, $_SESSION['user_id']);
add_user_to_group($tpl, $sql, $dmn_id);
delete_user_from_group($tpl, $sql, $dmn_id);
gen_user_assign($tpl, $sql, $dmn_id);
$tpl->assign(array('TR_HTACCESS' => tr('Protected areas'), 'TR_DELETE' => tr('Delete'), 'TR_USER_ASSIGN' => tr('User assign'), 'TR_ALLREADY' => tr('Already in:'), 'TR_MEMBER_OF_GROUP' => tr('Member of group:'), 'TR_BACK' => tr('Back'), 'TR_REMOVE' => tr('Remove'), 'TR_ADD' => tr('Add'), 'TR_SELECT_GROUP' => tr('Select group:')));
gen_page_message($tpl);
$tpl->parse('PAGE', 'page');
$tpl->prnt();
if (isset($cfg['DUMP_GUI_DEBUG'])) {
    dump_gui_debug();
}
unset_messages();
Exemplo n.º 4
0
 public function add_user_group()
 {
     add_user_to_group(1, 2);
 }
Exemplo n.º 5
0
 /**
 * Process the membership tag. This defines whether the specified Moodle users
 * should be added/removed as teachers/students.
 * @param string $tagconents The raw contents of the XML element
 */
 function process_membership_tag($tagcontents)
 {
     global $CFG;
     $memberstally = 0;
     $membersuntally = 0;
     // In order to reduce the number of db queries required, group name/id associations are cached in this array:
     $groupids = array();
     if (preg_match('{<sourcedid>.*?<id>(.+?)</id>.*?</sourcedid>}is', $tagcontents, $matches)) {
         $ship->coursecode = $CFG->enrol_truncatecoursecodes > 0 ? substr(trim($matches[1]), 0, intval($CFG->enrol_truncatecoursecodes)) : trim($matches[1]);
         $ship->courseid = get_field('course', 'id', 'idnumber', $ship->coursecode);
     }
     if ($ship->courseid && preg_match_all('{<member>(.*?)</member>}is', $tagcontents, $membermatches, PREG_SET_ORDER)) {
         foreach ($membermatches as $mmatch) {
             unset($member);
             unset($memberstoreobj);
             if (preg_match('{<sourcedid>.*?<id>(.+?)</id>.*?</sourcedid>}is', $mmatch[1], $matches)) {
                 $member->idnumber = trim($matches[1]);
             }
             if (preg_match('{<role\\s+roletype=["\'](.+?)["\'].*?>}is', $mmatch[1], $matches)) {
                 $member->roletype = trim($matches[1]);
                 // 01 means Student, 02 means Instructor, 3 means ContentDeveloper, and there are more besides
             } elseif ($CFG->enrol_imscapitafix && preg_match('{<roletype>(.+?)</roletype>}is', $mmatch[1], $matches)) {
                 // The XML that comes out of Capita Student Records seems to contain a misinterpretation of the IMS specification!
                 $member->roletype = trim($matches[1]);
                 // 01 means Student, 02 means Instructor, 3 means ContentDeveloper, and there are more besides
             }
             if (preg_match('{<role\\b.*?<status>(.+?)</status>.*?</role>}is', $mmatch[1], $matches)) {
                 $member->status = trim($matches[1]);
                 // 1 means active, 0 means inactive - treat this as enrol vs unenrol
             }
             $recstatus = $this->get_recstatus($mmatch[1], 'role');
             if ($recstatus == 3) {
                 $member->status = 0;
                 // See above - recstatus of 3 (==delete) is treated the same as status of 0
                 //echo "<p>process_membership_tag: unenrolling member due to recstatus of 3</p>";
             }
             $timeframe->begin = 0;
             $timeframe->end = 0;
             if (preg_match('{<role\\b.*?<timeframe>(.+?)</timeframe>.*?</role>}is', $mmatch[1], $matches)) {
                 $timeframe = $this->decode_timeframe($matches[1]);
             }
             if (preg_match('{<role\\b.*?<extension>.*?<cohort>(.+?)</cohort>.*?</extension>.*?</role>}is', $mmatch[1], $matches)) {
                 $member->groupname = trim($matches[1]);
                 // The actual processing (ensuring a group record exists, etc) occurs below, in the enrol-a-student clause
             }
             $rolecontext = get_context_instance(CONTEXT_COURSE, $ship->courseid);
             $rolecontext = $rolecontext->id;
             // All we really want is the ID
             //$this->log_line("Context instance for course $ship->courseid is...");
             //print_r($rolecontext);
             // Add or remove this student or teacher to the course...
             $memberstoreobj->userid = get_field('user', 'id', 'idnumber', $member->idnumber);
             $memberstoreobj->enrol = 'imsenterprise';
             $memberstoreobj->course = $ship->courseid;
             $memberstoreobj->time = time();
             $memberstoreobj->timemodified = time();
             if ($memberstoreobj->userid) {
                 // Decide the "real" role (i.e. the Moodle role) that this user should be assigned to.
                 // Zero means this roletype is supposed to be skipped.
                 $moodleroleid = $this->rolemappings[$member->roletype];
                 if (!$moodleroleid) {
                     $this->log_line("SKIPPING role {$member->roletype} for {$memberstoreobj->userid} ({$member->idnumber}) in course {$memberstoreobj->course}");
                     continue;
                 }
                 if (intval($member->status) == 1) {
                     // Enrol unsing the generic role_assign() function
                     if (!role_assign($moodleroleid, $memberstoreobj->userid, 0, $rolecontext, $timeframe->begin, $timeframe->end, 0, 'imsenterprise') && trim($memberstoreobj->userid) != '') {
                         $this->log_line("Error enrolling user #{$memberstoreobj->userid} ({$member->idnumber}) to role {$member->roletype} in course {$memberstoreobj->course}");
                     } else {
                         $this->log_line("Enrolled user #{$memberstoreobj->userid} ({$member->idnumber}) to role {$member->roletype} in course {$memberstoreobj->course}");
                         $memberstally++;
                         // At this point we can also ensure the group membership is recorded if present
                         if (isset($member->groupname)) {
                             // Create the group if it doesn't exist - either way, make sure we know the group ID
                             if (isset($groupids[$member->groupname])) {
                                 $member->groupid = $groupids[$member->groupname];
                                 // Recall the group ID from cache if available
                             } else {
                                 if ($groupid = get_field('groups', 'id', 'name', addslashes($member->groupname), 'courseid', $ship->courseid)) {
                                     $member->groupid = $groupid;
                                     $groupids[$member->groupname] = $groupid;
                                     // Store ID in cache
                                 } else {
                                     // Attempt to create the group
                                     $group->name = addslashes($member->groupname);
                                     $group->courseid = $ship->courseid;
                                     $group->timecreated = time();
                                     $group->timemodified = time();
                                     $groupid = insert_record('groups', $group);
                                     $this->log_line('Added a new group for this course: ' . $group->name);
                                     $groupids[$member->groupname] = $groupid;
                                     // Store ID in cache
                                     $member->groupid = $groupid;
                                 }
                             }
                             // Add the user-to-group association if it doesn't already exist
                             if ($member->groupid) {
                                 add_user_to_group($member->groupid, $memberstoreobj->userid);
                             }
                         }
                         // End of group-enrolment (from member.role.extension.cohort tag)
                     }
                 } elseif ($CFG->enrol_imsunenrol) {
                     // Unenrol
                     if (!role_unassign($moodleroleid, $memberstoreobj->userid, 0, $rolecontext, 'imsenterprise')) {
                         $this->log_line("Error unenrolling {$memberstoreobj->userid} from role {$moodleroleid} in course");
                     } else {
                         $membersuntally++;
                         $this->log_line("Unenrolled {$member->idnumber} from role {$moodleroleid} in course");
                     }
                 }
             }
         }
         $this->log_line("Added {$memberstally} users to course {$ship->coursecode}");
         if ($membersuntally > 0) {
             $this->log_line("Removed {$membersuntally} users from course {$ship->coursecode}");
         }
     }
 }
Exemplo n.º 6
0
 /**
 * The other half to print_entry, this checks the form data
 *
 * This function checks that the user has completed the task on the 
 * enrolment entry page and then enrolls them.
 *
 * @param    form    the form data submitted, as an object
 * @param    course  the current course, as an object
 */
 function check_entry($form, $course)
 {
     global $CFG, $USER, $SESSION, $THEME;
     if (empty($form->password)) {
         $form->password = '';
     }
     if (empty($course->password)) {
         // do not allow entry when no course password set
         // automatic login when manual primary, no login when secondary at all!!
         error('illegal enrolment attempted');
     }
     $groupid = $this->check_group_entry($course->id, $form->password);
     if ($form->password == $course->password or $groupid !== false) {
         if (isguestuser()) {
             // only real user guest, do not use this for users with guest role
             $USER->enrolkey[$course->id] = true;
             add_to_log($course->id, 'course', 'guest', 'view.php?id=' . $course->id, getremoteaddr());
         } else {
             /// Update or add new enrolment
             if (enrol_into_course($course, $USER, 'manual')) {
                 if ($groupid !== false) {
                     if (!add_user_to_group($groupid, $USER->id)) {
                         print_error('couldnotassigngroup');
                     }
                 }
             } else {
                 print_error('couldnotassignrole');
             }
         }
         if ($SESSION->wantsurl) {
             $destination = $SESSION->wantsurl;
             unset($SESSION->wantsurl);
         } else {
             $destination = "{$CFG->wwwroot}/course/view.php?id={$course->id}";
         }
         redirect($destination);
     } else {
         $this->errormsg = get_string('enrolmentkeyhint', '', substr($course->password, 0, 1));
     }
 }
Exemplo n.º 7
0
                     }
                 }
                 if ($ret) {
                     // OK
                     notify('-->' . get_string('enrolledincourse', '', $addcourse[$i]));
                 } else {
                     notify('-->' . get_string('enrolledincoursenot', '', $addcourse[$i]));
                 }
             }
         }
         for ($i = 0; $i < 5; $i++) {
             // Add user to groups if necessary
             if ($course[$i] && $groupid[$i]) {
                 $coursecontext = get_context_instance(CONTEXT_COURSE, $course[$i]->id);
                 if (count(get_user_roles($coursecontext, $user->id))) {
                     if (add_user_to_group($groupid[$i], $user->id)) {
                         notify('-->' . get_string('addedtogroup', '', $addgroup[$i]));
                     } else {
                         notify('-->' . get_string('addedtogroupnot', '', $addgroup[$i]));
                     }
                 } else {
                     notify('-->' . get_string('addedtogroupnotenrolled', '', $addgroup[$i]));
                 }
             }
         }
         unset($user);
     }
 }
 fclose($fp);
 notify("{$strusersnew}: {$usersnew}");
 notify(get_string('usersupdated', 'admin') . ": {$usersupdated}");