PHP User::getLocalGroups Examples

PHP User::getLocalGroups - 2 examples found. These are the top rated real world PHP examples of User::getLocalGroups extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
 function getLocalGroupsArray()
 {
     $localGroupsArray = array();
     try {
         $localGroupsArray = unserialize(parent::getLocalGroups());
     } catch (Exception $exc) {
         $error = new Error($exc->getMessage());
         $error->writeLog();
     }
     return $localGroupsArray;
 }
Example #2
0
function group_funct()
{
    // get global user object
    global $user;
    // set connection var
    global $db;
    // protect from unauthorized access
    if (!isset($user) or !isset($_POST['formSurveyGroupFunction'])) {
        logout();
        die;
    }
    $group_id = $_POST['formSurveyGroupFunction'];
    $function = '';
    foreach ($_POST as $key => $post) {
        if ($post != $group_id) {
            $function = substr($key, 15);
        }
    }
    if ($function == 'Edit') {
        $_SESSION['group_id'] = $group_id;
        $cookie_key = 'msg';
        $cookie_value = 'Редакция на анкетна група!';
        setcookie($cookie_key, $cookie_value, time() + 1);
        header('location: ' . ROOT_DIR . '?page=survey_group');
        die;
    } elseif ($function == 'Reset') {
        if (isset($_SESSION['group'])) {
            unset($_SESSION['group']);
        }
        if (isset($_SESSION['group_id'])) {
            unset($_SESSION['group_id']);
        }
        $cookie_key = 'msg';
        $cookie_value = 'Създаване на нова група!';
        setcookie($cookie_key, $cookie_value, time() + 1);
        header('location: ' . ROOT_DIR . '?page=survey_group');
        die;
    } elseif ($function == 'Remove') {
        $group = new Group();
        $group->get_from_db($group_id);
        $group->setIsActive(0);
        $group->update_in_db();
        $cookie_key = 'msg';
        $cookie_value = 'Вие успешно изтрихте Ваша група!';
        setcookie($cookie_key, $cookie_value, time() + 1);
        header('location: ' . ROOT_DIR . '?page=admin_survey');
    } elseif ($function == 'Create') {
        if (!isset($_SESSION['group'])) {
            $error = "Unauthorized try for group creating";
            error($error);
            logout();
        }
        $groupName = filter_input(INPUT_POST, 'formSurveyGroupName');
        $groupDescription = filter_input(INPUT_POST, 'formSurveyGroupDescription');
        $groupAbbreviation = filter_input(INPUT_POST, 'formSurveyGroupAbbreviation');
        $time_now = date("Y-m-d H:i:s");
        $session_group = unserialize($_SESSION['group']);
        $group = new Group();
        $group = clone $session_group;
        $group->setCreatedBy(intval($user->getId()));
        $group->setIsActive(1);
        $group->setCreatedOn($time_now);
        $group->setLastEditedOn($time_now);
        $group->setLocal(1);
        $group->setStaff(0);
        $group->setStudent(0);
        $group->setName($groupName);
        $group->setDescription($groupDescription);
        $group->setAbbreviation($groupAbbreviation);
        $group_id = $group->store_in_db();
        if ($group_id != NULL) {
            $members = unserialize($group->getMembers());
            foreach ($members as $member_id) {
                $member = new User();
                $member->get_from_db($member_id);
                $local_groups = unserialize($member->getLocalGroups());
                if (is_array($local_groups)) {
                    array_push($local_groups, $group_id);
                } else {
                    $local_groups = array($group_id);
                }
                $member->setLocalGroups(serialize($local_groups));
                $member->update_in_db();
            }
        } else {
            $cookie_key = 'msg';
            $cookie_value = 'Извиняваме се за неудобството, Вашата група нв беше създадена! Опитайте пак по-късно.';
            setcookie($cookie_key, $cookie_value, time() + 1);
            header('location: ' . ROOT_DIR . '?page=admin_survey');
        }
        var_dump($_SESSION);
        unset($_SESSION['group']);
        $cookie_key = 'msg';
        $cookie_value = 'Вашата група беше успешно създадена!';
        setcookie($cookie_key, $cookie_value, time() + 1);
        header('location: ' . ROOT_DIR . '?page=admin_survey');
    } elseif ($function == 'Update') {
        if (!isset($_SESSION['group'])) {
            $error = "Unauthorized try for group update";
            error($error);
            logout();
        }
        $groupName = filter_input(INPUT_POST, 'formSurveyGroupName');
        $groupDescription = filter_input(INPUT_POST, 'formSurveyGroupDescription');
        $groupAbbreviation = filter_input(INPUT_POST, 'formSurveyGroupAbbreviation');
        $time_now = date("Y-m-d H:i:s");
        $session_group = unserialize($_SESSION['group']);
        $group = new Group();
        $group = clone $session_group;
        $group->setCreatedBy(intval($user->getId()));
        $group->setIsActive(1);
        $group->setCreatedOn($time_now);
        $group->setLastEditedOn($time_now);
        $group->setLocal(1);
        $group->setStaff(0);
        $group->setStudent(0);
        $group->setName($groupName);
        $group->setDescription($groupDescription);
        $group->setAbbreviation($groupAbbreviation);
        $group_id = $group->getId();
        if ($group_id != NULL) {
            $group->update_in_db();
            $members = unserialize($group->getMembers());
            foreach ($members as $member_id) {
                $member = new User();
                $member->get_from_db($member_id);
                $local_groups = unserialize($member->getLocalGroups());
                if (is_array($local_groups)) {
                    if (!in_array($group_id, $local_groups)) {
                        array_push($local_groups, $group_id);
                    }
                } else {
                    $local_groups = array($group_id);
                }
                $member->setLocalGroups(serialize($local_groups));
                $member->update_in_db();
            }
            //die();
        } else {
            $cookie_key = 'msg';
            $cookie_value = 'Извиняваме се за неудобството, Вашата група нв беше създадена! Опитайте пак по-късно.';
            setcookie($cookie_key, $cookie_value, time() + 1);
            header('location: ' . ROOT_DIR . '?page=admin_survey');
        }
        var_dump($_SESSION);
        unset($_SESSION['group']);
        $cookie_key = 'msg';
        $cookie_value = 'Вашата група беше успешно редактирана!';
        setcookie($cookie_key, $cookie_value, time() + 1);
        header('location: ' . ROOT_DIR . '?page=admin_survey');
    }
    die;
}