Esempio n. 1
0
 function HandleObjectCategories($objectCategoryIds)
 {
     global $prefs;
     $perspectivelib = TikiLib::lib('perspective');
     $current_object = current_object();
     if (!$current_object) {
         // only used on tiki objects
         return;
     }
     $descendants = $this->get_category_descendants($prefs['areas_root']);
     $objectPerspective = 0;
     if (!empty($objectCategoryIds)) {
         if (!isset($_SESSION['current_perspective'])) {
             unset($_SESSION['current_perspective']);
         }
         foreach ($objectCategoryIds as $categId) {
             // If category is inside $prefs['areas_root']
             if (in_array($categId, $descendants)) {
                 $area = $this->getAreaByCategId($categId);
                 if ($area) {
                     $objectPerspective = $area['perspectives'][0];
                     // use 1st persp
                     break;
                 }
             }
         }
         if ($objectPerspective && $objectPerspective != $_SESSION['current_perspective']) {
             $area = $this->getAreaByPerspId($_SESSION['current_perspective']);
             $objectArea = $this->getAreaByPerspId($objectPerspective);
             if ($area && !$area['share_common'] || $objectArea && $objectArea['exclusive']) {
                 $perspectivelib->set_perspective($objectPerspective, true);
                 ZendOpenId\OpenId::redirect(ZendOpenId\OpenId::selfUrl());
             }
         }
     }
     if ($objectPerspective < 1 && !empty($_SESSION['current_perspective'])) {
         // uncategorised objects
         $area = $this->getAreaByPerspId($_SESSION['current_perspective']);
         if ($area) {
             if (!$area['share_common']) {
                 $perspectivelib->set_perspective($objectPerspective, true);
                 ZendOpenId\OpenId::redirect(ZendOpenId\OpenId::selfUrl());
             }
         }
     }
 }
Esempio n. 2
0
function wikiplugin_subscribegroup($data, $params)
{
    global $tiki_p_subscribe_groups, $user;
    $userlib = TikiLib::lib('user');
    $smarty = TikiLib::lib('smarty');
    static $iSubscribeGroup = 0;
    ++$iSubscribeGroup;
    if (empty($user)) {
        return '';
    }
    if ($tiki_p_subscribe_groups != 'y') {
        return tra('Permission denied');
    }
    extract($params, EXTR_SKIP);
    if (empty($group)) {
        if (!empty($_REQUEST['group'])) {
            $group = $_REQUEST['group'];
        } else {
            return tra('Missing parameter');
        }
    }
    if ($group == 'Anonymous' || $group == 'Registered') {
        return tra('Incorrect param');
    }
    if (!($info = $userlib->get_group_info($group)) || $info['groupName'] != $group) {
        // must have the right case
        return tra('Incorrect param');
    }
    if (!isset($params['allowLeaveNonUserChoice']) || $params['allowLeaveNonUserChoice'] != 'y') {
        if ($info['userChoice'] != 'y') {
            return tra('Permission denied');
        }
    }
    $groups = $userlib->get_user_groups_inclusion($user);
    $current_defgroup = $userlib->get_user_default_group($user);
    if (!$groups[$group] && $params['allowLeaveNonUserChoice'] == 'y') {
        // Deny anyway if user is not in group even if allowLeaveNonUserChoice is y
        return tra('Permission denied');
    }
    if (!empty($_REQUEST['subscribeGroup']) && !empty($_REQUEST['iSubscribeGroup']) && $_REQUEST['iSubscribeGroup'] == $iSubscribeGroup && $_REQUEST['group'] == $group) {
        if (isset($defgroup) || isset($defgroup_action) || isset($undefgroup) || isset($undefgroup_action)) {
            if ($current_defgroup == $group) {
                $new_group = !empty($undefgroup_group) ? $undefgroup_group : 'Registered';
                $userlib->set_default_group($user, $new_group);
            } else {
                if (!isset($groups[$group])) {
                    $userlib->assign_user_to_group($user, $group);
                }
                $userlib->set_default_group($user, $group);
            }
            if (!empty($params['defgroup_url']) && $params['defgroup_url'] === 'n') {
                ZendOpenId\OpenId::redirect(ZendOpenId\OpenId::selfUrl());
            } else {
                global $tikiroot;
                ZendOpenId\OpenId::redirect($tikiroot);
            }
            die;
        } else {
            if (isset($groups[$group])) {
                $userlib->remove_user_from_group($user, $group);
                unset($groups[$group]);
                if (!empty($postunsubscribe_url)) {
                    header("Location: {$postunsubscribe_url}");
                    die;
                }
            } else {
                $userlib->assign_user_to_group($user, $group);
                $groups[$group] = 'real';
                if (!empty($postsubscribe_url)) {
                    header("Location: {$postsubscribe_url}");
                    die;
                }
            }
        }
    }
    if (isset($undefgroup) || isset($undefgroup_action)) {
        if ($current_defgroup == $group) {
            $text = isset($undefgroup) ? $undefgroup : '';
            if (!isset($undefgroup_action)) {
                $undefgroup_action = tra('OK');
            }
            $smarty->assign('action', $undefgroup_action);
        } else {
            $text = isset($defgroup) ? $defgroup : '';
            if (!isset($defgroup_action)) {
                $defgroup_action = tra('OK');
            }
            $smarty->assign('action', $defgroup_action);
        }
    } else {
        if (isset($groups[$group])) {
            //user already in the group->
            if ($groups[$group] == 'included') {
                return tra('Incorrect param');
            }
            $text = isset($unsubscribe) ? $unsubscribe : tra('Unsubscribe') . '%s';
            if (!isset($unsubscribe_action)) {
                $unsubscribe_action = tra('OK');
            }
            $smarty->assign('action', $unsubscribe_action);
        } else {
            $text = isset($subscribe) ? $subscribe : tra('Subscribe') . '%s';
            if (!isset($subscribe_action)) {
                $subscribe_action = tra('OK');
            }
            $smarty->assign('action', $subscribe_action);
        }
    }
    $smarty->assign('text', sprintf(tra($text), $group));
    $smarty->assign('subscribeGroup', $group);
    $smarty->assign('iSubscribeGroup', $iSubscribeGroup);
    $data = $data . $smarty->fetch('wiki-plugins/wikiplugin_subscribegroup.tpl');
    return $data;
}