/**
	 * Check if specific user can add new templates to specific project
	 *
	 * @access public
	 * @param Contact $user
	 * @param Member $member
	 * @return boolean
	 */
	function canAddToMember(Contact $contact, Member $member, $context_members) {
		return can_manage_templates($contact) && can_add_to_member($contact,$member,$context_members,$this->getObjectTypeId());
	} // canAdd
Exemple #2
0
	/**
	 * @param Contact $user
	 * @param Member $member
	 * @return boolean
	 */
	function canAddToMember(Contact $user, Member $member, $context_members) {
		$rel_object = $this->getRelObject();
		if (!$rel_object instanceof ContentDataObject) {
			return false;
		}
		return can_add_to_member($user, $member, $context_members, $rel_object->getObjectTypeId());
	} // canAdd
Exemple #3
0
 /**
  * @param Contact $user
  * @param Member $member
  * @return boolean
  */
 function canAddToMember(Contact $user, Member $member, $context_members)
 {
     return can_add_to_member($user, $member, $context_members, $this->getRelObject()->getObjectTypeId());
 }
		$dimension_name = $dimension['dimension_name'];
		if ($is_required) $dimension_name .= " *";
		
		if (is_array($simulate_required) && in_array($dimension_id, $simulate_required)) $is_required = true;

		$dimension_selected_members = array();
		foreach ($selected_members as $selected_member) {
			if ($selected_member->getDimensionId() == $dimension_id) $dimension_selected_members[] = $selected_member;
		}
		
		$autocomplete_options = array();
		if (!isset($dim_controller)) $dim_controller = new DimensionController();
		$members = $dim_controller->initial_list_dimension_members($dimension_id, $content_object_type_id, $allowed_member_type_ids, false, "", null, false, null, true, $initial_selected_members, ACCESS_LEVEL_WRITE);
		
		foreach ($members as $m) {
			if (can_add_to_member(logged_user(), $m, active_context(), $content_object_type_id)) {
				$autocomplete_options[] = array($m['id'], $m['name'], $m['path'], $m['to_show'], $m['ico'], $m['dim']);
				$members_dimension[$m['id']] = $m['dim'];
			}
		}
		
		$expgenid = gen_id();
?>
	
	<div id="<?php echo $genid; ?>member-seleector-dim<?php echo $dimension_id?>" class="single-dimension-selector">
		<div class="header x-accordion-hd" onclick="og.dashExpand('<?php echo $expgenid?>', 'selector-body-dim<?php echo $dimension_id ?>');">
			<?php echo $dimension_name?>
			<div id="<?php echo $expgenid; ?>expander" class="dash-expander ico-dash-expanded"></div>
		</div>
		<div class="selector-body" id="<?php echo $expgenid?>selector-body-dim<?php echo $dimension_id ?>">
			<div id="<?php echo $genid; ?>selected-members-dim<?php echo $dimension_id?>" class="selected-members">
Exemple #5
0
/**
 * Return true if $user can add an object of type $object_type_id in $member. False otherwise.
 *
 * @param Contact $user
 * @param array $context
 * @param $object_type_id
 * @return boolean
 */
function can_add(Contact $user, $context, $object_type_id, &$notAllowedMember = '')
{
    if ($user->isGuest()) {
        return false;
    }
    $membersInContext = 0;
    $can_add = false;
    $required_dimensions_ids = DimensionObjectTypeContents::getRequiredDimensions($object_type_id);
    $dimensions_in_context = array();
    $no_required_dimensions = count($required_dimensions_ids) == 0;
    foreach ($required_dimensions_ids as $id) {
        $dimensions_in_context[$id] = false;
    }
    $contact_pg_ids = ContactPermissionGroups::getPermissionGroupIdsByContactCSV($user->getId(), false);
    if (is_array($context)) {
        foreach ($context as $selection) {
            $sel_dimension = $selection instanceof Dimension ? $selection : ($selection instanceof Member ? $selection->getDimension() : null);
            if ($sel_dimension instanceof Dimension && $sel_dimension->getOptions(1) && isset($sel_dimension->getOptions(1)->hidden) && $sel_dimension->getOptions(1)->hidden) {
                continue;
            }
            //$can_add = false;
            if ($selection instanceof Member) {
                $membersInContext++;
                if (can_add_to_member($user, $selection, $context, $object_type_id)) {
                    //if ($no_required_dimensions) return true;
                    $dimension_id = $selection->getDimensionId();
                    $can_add = true;
                    $dimensions_in_context[$dimension_id] = true;
                } else {
                    $notAllowedMember = $selection->getName();
                    return false;
                }
            }
            // Revoke explicty permission
            if ($can_add && !$no_required_dimensions) {
                foreach ($dimensions_in_context as $key => $value) {
                    $dim = Dimensions::getDimensionById($key);
                    if (!$value && $dim->getDefinesPermissions() && $dim->deniesAllForContact($contact_pg_ids)) {
                        $can_add = false;
                    }
                }
            }
        }
    }
    // All dimensions in 'all'.
    // If The object has no required dimensions, and no dimensions are selected: CAN ADD = True
    if ($no_required_dimensions && !$membersInContext) {
        $can_add = true;
    }
    // All dimensions in 'all'.
    // if there are required dimensions and no members selected then show correct error message.
    if (!$no_required_dimensions && !$membersInContext && !$can_add) {
        $dim_names = array();
        $required_dimensions = Dimensions::findAll(array('conditions' => 'id IN (' . implode(',', $required_dimensions_ids) . ')'));
        foreach ($required_dimensions as $dim) {
            $dim_names[] = $dim->getName();
        }
        $notAllowedMember = "-- req dim --" . implode(",", $dim_names);
    }
    return $can_add;
}
Exemple #6
0
/**
 * Return true if $user can add an object of type $object_type_id in $member. False otherwise.
 *
 * @param Contact $user
 * @param array $context
 * @param $object_type_id
 * @return boolean
 */
function can_add(Contact $user, $context, $object_type_id, &$notAllowedMember = '')
{
    if ($user->isGuest()) {
        return false;
    }
    $membersInContext = 0;
    $can_add = false;
    $required_dimensions_ids = DimensionObjectTypeContents::getRequiredDimensions($object_type_id);
    $dimensions_in_context = array();
    $no_required_dimensions = count($required_dimensions_ids) == 0;
    foreach ($required_dimensions_ids as $id) {
        $dimensions_in_context[$id] = false;
    }
    $enabled_dimensions = config_option('enabled_dimensions');
    $contact_pg_ids = ContactPermissionGroups::getPermissionGroupIdsByContactCSV($user->getId(), false);
    if (is_array($context)) {
        foreach ($context as $selection) {
            $sel_dimension = $selection instanceof Dimension ? $selection : ($selection instanceof Member ? $selection->getDimension() : null);
            //$can_add = false;
            if ($selection instanceof Member) {
                $dimension = $selection->getDimension();
                if (!$dimension->getDefinesPermissions() || !in_array($dimension->getId(), $enabled_dimensions)) {
                    continue;
                }
                $membersInContext++;
                if (can_add_to_member($user, $selection, $context, $object_type_id)) {
                    //if ($no_required_dimensions) return true;
                    $dimension_id = $selection->getDimensionId();
                    $can_add = true;
                    $dimensions_in_context[$dimension_id] = true;
                } else {
                    $notAllowedMember = $selection->getName();
                    return false;
                }
            }
            // Revoke explicty permission
            if ($can_add && !$no_required_dimensions) {
                foreach ($dimensions_in_context as $key => $value) {
                    $dim = Dimensions::getDimensionById($key);
                    if (!$value && $dim->getDefinesPermissions() && $dim->deniesAllForContact($contact_pg_ids)) {
                        $can_add = false;
                    }
                }
            }
        }
    }
    // All dimensions in 'all'.
    // If The object has no required dimensions, and no dimensions are selected: check for contact_member_permissions with member_id=0
    if ($no_required_dimensions && $membersInContext == 0) {
        $mailot = ObjectTypes::findByName('mail');
        if ($mailot instanceof ObjectType && $mailot->getId() == $object_type_id) {
            $can_add = true;
        } else {
            $can_add = false;
            if (config_option('let_users_create_objects_in_root') && $contact_pg_ids != '' && ($user->isAdminGroup() || $user->isExecutive() || $user->isManager())) {
                $cmp = ContactMemberPermissions::findOne(array('conditions' => 'member_id=0 AND object_type_id=' . $object_type_id . ' AND permission_group_id IN (' . $contact_pg_ids . ')'));
                $can_add = $cmp instanceof ContactMemberPermission && $cmp->getCanWrite();
            }
        }
    }
    // All dimensions in 'all'.
    // if there are required dimensions and no members selected then show correct error message.
    if (!$no_required_dimensions && $membersInContext == 0 && !$can_add) {
        $dim_names = array();
        $required_dimensions = Dimensions::findAll(array('conditions' => 'id IN (' . implode(',', $required_dimensions_ids) . ')'));
        foreach ($required_dimensions as $dim) {
            $dim_names[] = $dim->getName();
        }
        $notAllowedMember = "-- req dim --" . implode(",", $dim_names);
    }
    return $can_add;
}