FAQ-OMatic

 view release on metacpan or  search on metacpan

lib/FAQ/OMatic/Item.pm  view on Meta::CPAN

	if ((FAQ::OMatic::getParam($params, 'render') ne 'text')
		and not ($FAQ::OMatic::Config::hideSiblings || '')) {
		my $useTable = FAQ::OMatic::getParam($params, 'render') eq 'tables';
		$rt.="\n";
		$rt.="<table>" if $useTable;
		$rt.="<!-- Sibling links -->\n";
		$rt.= $self->displaySiblings($params);
		$rt.="</table>\n" if $useTable;
		$rt.="<p>\n" if not $useTable;
	}

	$rt.=FAQ::OMatic::HelpMod::helpFor($params,
		'How can I contribute to this FAQ?', "<br>");

	return $rt;
}

sub basicURL {
	my $params = shift;

	return '' if ($params->{'file'} =~ m/^help/);
	
	my %killParams = %{$params};
	delete $killParams{'file'};
	delete $killParams{'recurse'} if ($params->{'recurse'});
	my $i; foreach $i (keys %killParams) { $killParams{$i} = ''; }

	# TODO: We have always had the "This document is:"
	# TODO: refer to the CGI. I liked that because it let me fiddle
	# TODO: with the cache layout (after all, it changed in 2.604.)
	# TODO: But others have asked to totally hide the presence of the CGI,
	# TODO: in which case we should *only* display cache URLs here.
	# TODO: Or leave this line out altogether.

	my $url = FAQ::OMatic::makeAref('-command'=>'faq',
				'-params' => $params,
				'-changedParams'=>\%killParams,
				'-thisDocIs'=>1,
				'-refType'=>'url');

	if (FAQ::OMatic::getParam($params, 'render') ne 'text') {
		return gettext("This document is:") . " <a href=\"$url\">$url</a><br>\n";
	} else {
		return gettext("This document is at:") . " $url\n";
	}
}

sub permissionBox {
	my $self = shift;
	my $perm = shift;

	my @permNum = (7);
	push @permNum, FAQ::OMatic::Groups::getGroupCodeList();
	push @permNum, (5, 3);

	my @permDesc = map { nameForPerm($_); } @permNum;

	push @permNum, ('');
	push @permDesc, gettext('Inherit');

	return popup($perm, \@permNum, \@permDesc, $self->{$perm}||'');
}

sub popup {
	my $name = shift;
	my $values = shift;			# ary ref
	my $descary = shift;		# ary ref; 1:1 with $values
	my $curvalue = shift;		# one of @{$values}

	$curvalue = '' if (not defined $curvalue);

	my $rt = '';
	$rt.="<select name=\"_$name\">\n";
	for (my $i=0; $i<@{$values}; $i++) {
		$rt .= "<option value=\"".$values->[$i]."\"";
		$rt .= " SELECTED" if ($values->[$i] eq $curvalue);
		$rt .= ">".$descary->[$i]."\n";
	}
	$rt.="</select>\n";
	return $rt;
}

sub nameForPerm {
	# this is a lot like Auth::authError, but with more concise descriptions
	my $perm = shift;

	if ($perm =~ m/^6 (.*)$/) {
		return gettexta("Group %0", "$1");
	}

	my %map = (
		'3' => gettext("Users giving their names"),
		'5' => gettext("Authenticated users"),
		'7' => gettext("Moderator"),
	);

	return $map{$perm};
}

sub displayItemEditor {
	my $self = shift;
	my $params = shift;
	my $cgi = shift;
	my $rt = ""; 	# return text

	my $insertHint = $params->{'_insert'} || '';
	if ($insertHint eq 'category') {
		$rt .= gettext("New Category")."\n";
	} elsif ($insertHint eq "answer") {
		$rt .= gettext("New Answer")."\n";
	} else {
		if ($self->isCategory())
		{
			$rt .= gettexta("Editing Category <b>%0</b>", $self->getTitle());
		}
		elsif ($self->isAnswer())
		{
			$rt = gettexta("Editing Answer <b>%0</b>", $self->getTitle());
		}
		else
		{
			# fixup for unexpected cases.
			$rt .= gettexta("Editing %0 <b>%1</b>",
							gettext($self->whatAmI()),

lib/FAQ/OMatic/Item.pm  view on Meta::CPAN

}

sub displayModOptionsEditor {
	my $self = shift;
	my $params = shift;
	my $cgi = shift;
	my $rt = ""; 	# return text

	if ($self->isCategory())
	{
		$rt .= gettext("Moderator options for category");
	}
	elsif ($self->isAnswer())
	{
		$rt .= gettext("Moderator options for answer");
	}
	else
	{
		# fixup for unexpected cases.
		$rt .= gettext("Moderator options for")." "
				.gettext($self->whatAmI());
	}
	$rt .= " <b>".$self->getTitle()."</b>:\n"
			."<p>\n";

	$rt .= FAQ::OMatic::makeAref('-command'=>'submitModOptions',
			'-params'=>$params,
			'-changedParams'=>{'_insert'=>$params->{'_insert'}},
			'-refType'=>'POST');

	$rt .= "<input type=hidden name=\"checkSequenceNumber\" value=\""
			.$self->{'SequenceNumber'}."\">\n";

	# Moderator
	# THANKS to John Nolan for suggesting a better permissions layout.
	$rt .= "<table border=1>\n";
	$rt .=	"<tr>\n"
			."  <th>".gettext("Name & Description")."</th>\n"
			."  <th>".gettext("Setting")."</th>\n"
			."  <th>".gettext("Setting if Inherited")."</th>\n"
			."</tr>\n";

	# Moderator
#	$rt .= "<tr><td colspan=3 align=center><b>".gettext("Moderator")."</b>"
#			."</td></tr>\n";
	my $inherited = $self->getInheritance($params, 'Moderator', '<br>',
		sub {shift;});
	$rt .= "<tr><td colspan=2 align=left><b>".gettext("Moderator")."</b>\n"
			."<br>".gettext("(will inherit if empty)")."\n";
	$rt .= "<br>"
			."<input type=text name=\"_Moderator\" value=\""
			.($self->{'Moderator'}||'')."\" size=60></td>\n";
	$rt .= "<td>$inherited"
			."</td></tr>\n";

	# ModeratorMail
	$rt .= "<tr>"
			."<td><b>MailModerator</b>"
			."<br>".gettext("Send mail to the moderator when someone other than the moderator edits this item:")."</td>\n";
	$rt .= "<td>\n";
	$rt .= popup('MailModerator', [1, 0, ''], [gettext('Yes'), gettext('No'), gettext('Inherit')],
			$self->{'MailModerator'});
	$inherited =
		$self->getInheritance($params, 'MailModerator', '<br>',
			sub {(gettext("No"), gettext("Yes"))[shift()] || gettext("undefined")});
	$rt .= "<td>$inherited</td>\n";
	$rt .= "</tr>\n";


	# Notifier
	# THANKS to John Nolan for suggesting a better permissions layout.
#	$rt .= "<table border=1>\n";
#	$rt .=	"<tr>\n"
#			."  <th>".gettext("Name & Description")."</th>\n"
#			."  <th>".gettext("Setting")."</th>\n"
#			."  <th>".gettext("Setting if Inherited")."</th>\n"
#			."</tr>\n";

	# Notifer
#	$rt .= "<tr><td colspan=3 align=center><b>".gettext("Moderator")."</b>"
#			."</td></tr>\n";
	$inherited = $self->getInheritance($params, 'Notifier', '<br>',
		sub {shift;});
	$rt .= "<tr><td colspan=2 align=left><b>".gettext("Notifier")."</b>\n"
			."<br>".gettext("Send mail to the Notifier when item is created or modified")."\n"
			."<br>".gettext("(will inherit if empty)")."\n";
	$rt .= "<br>"
			."<input type=text name=\"_Notifier\" value=\""
			.($self->{'Notifier'}||'')."\" size=60></td>\n";
	$rt .= "<td>$inherited"
			."</td></tr>\n";

	# NotifierMail
	$rt .= "<tr>"
			."<td><b>MailNotifier</b>"
			."<br>".gettext("Send mail to the Notifier when someone other than the moderator edits this item:")."</td>\n";
	$rt .= "<td>\n";
	$rt .= popup('MailNotifier', [1, 0, ''], [gettext('Yes'), gettext('No'), gettext('Inherit')],
			$self->{'MailNotifier'});
	$inherited =
		$self->getInheritance($params, 'MailNotifier', '<br>',
			sub {(gettext("No"), gettext("Yes"))[shift()] || gettext("undefined")});
	$rt .= "<td>$inherited</td>\n";
	$rt .= "</tr>\n";

	# Permission info
	$rt .= "<tr><th colspan=3>".gettext("Permissions")."</th></tr>\n";

	my $permissionsInfo = permissionsInfo();
	foreach my $key (sort keys %{$permissionsInfo}) {
		my $ph = $permissionsInfo->{$key};	# permission descriptor hash
		next if ($ph->{'global'} and $self->{'filename'} ne '1');
			# only display global permissions for item 1, where they are set
		my $pname = $ph->{'name'};
		my $inherited =
			$self->getInheritance($params, $pname, '<br>', \&nameForPerm);
		$rt.="<tr><!-- $pname -->\n";
		$rt.="  <td><b>$pname</b>"
			."<br>".$ph->{'desc'}."</td>\n";	# Perm description column
		$rt.="  <td>".$self->permissionBox($ph->{'name'})."</td>\n";
												# popup choice column
		$rt.="  <td>$inherited</td>\n";			# inherited value column
		$rt.="</tr>\n";
	}

	# RelaxChildPerms
	$rt .= "<tr>"
			."<td><b>"."RelaxChildPerms"."</b>"
			."<br>".gettext("Relax: New answers and subcategories will be moderated ")
				.gettext("by the creator of the item, allowing that person full ")
				.gettext("freedom to edit that new item.")
			."<br>".gettext("Don't Relax: new items will be moderated by ")
			.gettext("the moderator of this item.")
			."</td>\n";
	$rt .= "<td>\n";
	$rt .= popup('RelaxChildPerms',
			['relax', 'norelax', ''],
			[gettext("Relax"), gettext("Don\'t Relax"), gettext("Inherit")],
			$self->{'RelaxChildPerms'});
	$inherited =
		$self->getInheritance($params, 'RelaxChildPerms', '<br>',
			sub {{'relax'=>gettext("Relax"), 'norelax'=>gettext("Don\'t Relax")}->{shift()}
				|| gettext("undefined")});
	$rt .= "<td>$inherited</td>\n";
	$rt .= "</tr>\n";

	$rt .= "</table>\n";

	$rt .="<p><input type=submit name=\"_submit\" value=\"".gettext("Submit Changes")."\">\n";
	$rt .= "<input type=reset name=\"_reset\" value=\"".gettext("Revert")."\">\n";
	$rt .= "<input type=hidden name=\"_zzverify\" value=\"zz\">\n";
		# this lets the submit script check that the whole POST was
		# received.
	$rt .= "</form>\n";

	$rt .= FAQ::OMatic::HelpMod::helpFor($params, 'editModOptions', "<br>\n");

	return $rt;
}

sub getInheritance {
	my $self = shift;
	my $params = shift;
	my $pname = shift;
	my $separator = shift;
	my $namecode = shift;

	my $val;
	my $whered;
	if ($self->getParent() eq $self) {
		$val = FAQ::OMatic::Auth::getDefaultProperty($pname);
		$whered = gettext("(system default)");
	} else {
		my ($pset,$where) = FAQ::OMatic::Auth::getInheritedProperty(
			$self->getParent(), $pname);
		if (defined $where) {
			$val = $pset;
			$whered = "(".gettext("defined in")." \""
				.FAQ::OMatic::makeAref('-command'=>'editModOptions',
					'-params'=>$params,
					'-changedParams'=>{'file'=>$where->{'filename'}})
				.$where->getTitle()
				."</a>\")";
		} else {
			$val = $pset;
			$whered = gettext("(system default)");
		}
	}
	return ("<i>".&{$namecode}($val)."</i>".$separator.$whered);
}

sub setProperty {
	my $self = shift;
	my $property = shift;
	my $value = shift;



( run in 0.882 second using v1.01-cache-2.11-cpan-364913b4093 )