Apache-SdnFw

 view release on metacpan or  search on metacpan

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

			$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 = @_;

	my %from;
	my $nodev;
	if ($info{from}) {
		$nodev = 1;
		$from{email} = $info{from};
	} else {
		%from = $s->db_q("
			SELECT *
			FROM employees_v
			WHERE employee_id=?
			",'hash',
			v => [ $s->{employee_id} ]);
	
		croak "Unknown email address for you...." unless($from{email});
	
		$info{from} = qq("$from{name}" <$from{email}>) unless($info{from});
		#$info{bcc} = qq("$from{name}" <$from{email}>);
	}

	# Check to make sure we are getting passed all the information we need;
	foreach my $key (qw(to from subject)) {
		croak "Missing '$key' parameter on sendmail call" unless($info{$key});
	}

	foreach my $key (qw(to cc bcc)) {
		# make sure and put spaces around any email addresses
		if ($info{$key}) {
			$info{$key} =~ s/,/, /g;
		}
	}

	my @attachments;
	# if we have an attachment, check all the files first
	if (defined($info{attachment})) {
		foreach my $a (@{$info{attachment}}) {
			croak "Could not find /tmp/$a" unless (-e "/tmp/$a");
			push(@attachments,$a);
		}
	}

	if ($s->{env}{DEV} && !$nodev) {
		$info{subject} .= " (normally for $info{to})";
		$info{to} = $info{from};
		delete $info{bcc};



( run in 0.958 second using v1.01-cache-2.11-cpan-d7f47b0818f )