Apache-SdnFw

 view release on metacpan or  search on metacpan

lib/Apache/SdnFw/lib/Core.pm  view on Meta::CPAN

		my $help;
		$s->tt("template/help/$s->{function}.tt", { s => $s }, \$help);
		$help =~ s/\n\n/<br><br>/g;
		$s->{help_text} = $help;
		$s->tt('help.tt', { s => $s });
	} else {
		if ($s->{employee}{admin}) {
			$s->add_action(function => $s->{function},
				title => 'add',
				params => "f=add");
			
			if ($s->{in}{f} eq 'add') {
				$s->tt('help_add.tt', { s => $s, });		
				return;
			}
		} else {
			$s->add_action(
				title => 'add',
				class => 'greyout',
				nourl => 1);
		}
		$s->{content} = "Sorry no help file found for $s->{function}";
	}

	if ($s->{employee}{admin}) {
		$s->add_action(function => 'system',
			title => 'emergency information');
	}

	#$s->{content} = "<pre>".Data::Dumper->Dump([$s])."</pre>";
}

sub permission {
	my $s = shift;

	# manage permissions on an object.  This should only be accessable
	# with thos who are part of an admin group
	unless($s->{employee}{admin}) {
		$s->alert("You are not an admin.   You can not do this!");
		return 0;
	}

	$s->add_action(function => 'list') if (defined($s->{o}{functions}{list}));

	# before we get down to looking at the current permissions, lets make sure
	# we have defined them all in the database first
	my %check = $s->db_q("
		SELECT a_function, action_id
		FROM actions_v
		WHERE a_object=?
		",'keyval',
		v => [ $s->{object} ]);

	foreach my $f (keys %{$s->{o}{functions}}) {
		unless(defined($check{$f})) {
			$s->_set_default_access($s->{object},$f);
		}
	}

	my %existing = $s->db_q("
		SELECT a.a_function, a.action_id, concat(ga.group_id) as gids 
		FROM actions_v a
			LEFT JOIN group_actions_v ga ON a.action_id=ga.action_id
		WHERE a.a_object=?
		GROUP BY 1,2
		",'hashhash',
		k => 'a_function',
		v => [ $s->{object} ]);

	foreach my $f (keys %existing) {
		foreach my $id (split ',', $existing{$f}{gids}) {
			$existing{$f}{groupids}{$id} = $id;
		}
	}

	my @groups = $s->db_q("
		SELECT *
		FROM groups
		ORDER BY name
		",'arrayhash');

	if ($s->{in}{update}) {
		foreach my $f (keys %{$s->{o}{functions}}) {
			if ($s->{in}{"f:all:$f"}) {
				# by clearing all actions, we give everyone permission
				$s->db_q("
					DELETE FROM group_actions
					WHERE action_id=?
					",undef,
					v => [ $check{$f} ]);
			} else {
				foreach my $g (@groups) {
					if ($s->{in}{"f:$g->{group_id}:$f"} 
						&& !defined($existing{$f}{groupids}{$g->{group_id}})) {

						# we need to create a new entry
						$s->db_insert('group_actions',{
							action_id => $check{$f},
							group_id => $g->{group_id},
							});

					} elsif (!defined($s->{in}{"f:$g->{group_id}:$f"})
						&& defined($existing{$f}{groupids}{$g->{group_id}})) {
						# we need to delete an entry
						$s->db_q("
							DELETE FROM group_actions
							WHERE action_id=?
							AND group_id=?
							",undef,
							v => [ $check{$f}, $g->{group_id} ]);
					}
				}
			}
		}

		$s->notify("Permissions updated");
		if ($s->{in}{return}) {
			$s->redirect(function => $s->{in}{return},
				params => $s->{in}{return_args});
		}
		return;
	}

	#croak "<pre>".Data::Dumper->Dump([\%existing])."</pre>";

	$s->tt('permission.tt', { s => $s, groups => \@groups, existing => \%existing });
}

sub sendmail {
	my $s = shift;
	my %info = @_;



( run in 1.419 second using v1.01-cache-2.11-cpan-ceb78f64989 )