[interchange-cvs] interchange - heins modified 10 files

interchange-cvs at icdevgroup.org interchange-cvs at icdevgroup.org
Fri May 20 10:11:04 EDT 2005


User:      heins
Date:      2005-05-20 14:11:04 GMT
Added:     dist/features/quickpoll quickpoll.catalog.cfg
Added:              quickpoll.global quickpoll.init
Added:     dist/features/quickpoll/doc/quickpoll README
Added:     dist/features/quickpoll/templates/components quickpoll
Removed:   features/quickpoll quickpoll.catalog.cfg quickpoll.global
Removed:            quickpoll.init
Removed:   features/quickpoll/doc/quickpoll README
Removed:   features/quickpoll/templates/components quickpoll
Log:
* Put "features" directory in dist/ instead of at top level. 8-)

Revision  Changes    Path
1.1                  interchange/dist/features/quickpoll/quickpoll.catalog.cfg


rev 1.1, prev_rev 1.0
Index: quickpoll.catalog.cfg
===================================================================

Database	quickpoll	quickpoll.txt	__SQLDSN__
Database	quickpoll	NAME	code poll_id owner title question choices colors num_answers
Database	quickpoll	CREATE_EMPTY_TXT	1
Database	quickpoll	AUTO_SEQUENCE	quickpoll_seq
Database	quickpoll	COLUMN_DEF	"poll_id=int"
Database	quickpoll	COLUMN_DEF	"owner=varchar(128)"
Database	quickpoll	COLUMN_DEF	"question=varchar(255)"
Database	quickpoll	COLUMN_DEF	"choices=text"
Database	quickpoll	COLUMN_DEF	"colors=text"

Database	quickpoll_answer	quickpoll_answer.txt	__SQLDSN__
Database	quickpoll_answer	NAME	code poll_id question_id answer comment answer_date ipaddr username login_table
Database	quickpoll_answer	CREATE_EMPTY_TXT	1
Database	quickpoll_answer	AUTO_SEQUENCE	quickpoll_answer_seq
Database	quickpoll_answer	COLUMN_DEF	"poll_id=int"
Database	quickpoll_answer	COLUMN_DEF	"question_id=int"
Database	quickpoll_answer	COLUMN_DEF	"answer=varchar(255)"
Database	quickpoll_answer	COLUMN_DEF	"comment=text"
Database	quickpoll_answer	INDEX  question_id



1.1                  interchange/dist/features/quickpoll/quickpoll.global


rev 1.1, prev_rev 1.0
Index: quickpoll.global
===================================================================
ActionMap quickpoll <<EOR
sub {
	my $path = shift;
	$path =~ s{^quickpoll/}{};

	use vars qw/$Tag/;
	$CGI::values{mv_nextpage} ||= $path;
	my $code = $CGI::values{poll};
	$code =~ s/\D+//g;
	return 1 if $Vend::Session->{quickpoll}{$code}++;
	my $answer = $CGI::values{answer};
	my $adb = dbref($::Variable->{POLL_ANSWER_TABLE} || 'quickpoll_answer');
	my $pdb = dbref($::Variable->{POLL_TABLE} || 'quickpoll');
	my $poll = $pdb->row_hash($code) 
		or do {
			::logError("Bad poll %s, no database record", $code);
			return 1;
		};
	my $date = POSIX::strftime('%Y%m%d%H%M%S', localtime());
	my $poll_id = $poll->{poll_id} || $code;
	my $record = {
		answer => $CGI::values{answer},
		poll_id => $poll_id,
		question_id => $code,
		ipaddr => $CGI::remote_addr,
		username => $Vend::username,
		answer_date => $date,
		login_table => $Vend::login_table,
	};
	$Vend::Session->{quickpoll}{$code} = $adb->set_slice(undef, $record);
	return 1;
}
EOR

UserTag poll-answer Order code
UserTag poll-answer addAttr
UserTag poll-answer Routine <<EOR
sub {
	my ($code, $opt) = @_;

	use vars qw/$Tag/;

	my $adb = dbref($::Variable->{POLL_ANSWER_TABLE} || 'quickpoll_answer');
	my $pdb = dbref($::Variable->{POLL_TABLE} || 'quickpoll');
	my $poll = $pdb->row_hash($code)
		or do {
			::logError("Bad poll %s, no database record", $code);
			return undef;
		};
	my $answer_ary = Vend::Form::options_to_array($poll->{choices});
	my %key;
	for(@$answer_ary) {
		$key{$_->[0]} = $_->[1];
	}
	
	my $tname = $adb->name();
	my $q = qq{SELECT answer, COUNT(answer) FROM $tname
				WHERE question_id = $code
				GROUP BY answer
			};

	my $ary = $adb->query($q)
		or do {
			::logError("Bad answers to poll %s, no database return", $code);
			return undef;
		};
	my @out;
	push @out, qq{<table>};

	my $total = 0;
	my @results;

	for(@$ary) {
		my ($ans, $number) = @$_;
		$total += $number;
		push @results, [$ans, $number];
	}

	@results = sort { $b->[1] <=> $a->[1] } @results;

	return "No answers yet!" unless $total > 0;

	my $tops = $opt->{shown} || 4;
	if(@results > $tops) {
		my $other = 0;
		for(my $i = $tops; $i < @results; $i++) {
			$other += $results[$i][1];
		}
		splice @results, $tops;
		push @results, [ $opt->{other_title} || 'Other', $other];
	}

	for(@results) {
		push @$_, int($_->[1] / $total * 100);
	}

	my @colors = qw(
		red
		green
		blue
		orange
		yellow
		brown
		purple
		cyan
		chartruese
	);

	if($poll->{colors}) {
		my @custom = grep /\w/, split /[\s,\0]+/, $poll->{colors};
		for(my $i = 0; $i < @custom; $i++) {
			$colors[$i] = $custom[$i];
		}
	}

	for( my $i = 0; $i < @results; $i++) {
		my ($answer, $number, $percent) = @{$results[$i]};
		$answer = $key{$answer} if $key{$answer};
		my $short = $Tag->filter('16.', $answer);
		if(length($answer) > length($short)) {
			my $encode_answer = HTML::Entities::encode($answer);
			my $encode_short = HTML::Entities::encode($short);
			$answer = qq{<span title="$encode_answer">$encode_short</span>};
		}
		else {
			HTML::Entities::encode($answer);
		}
		my $opt = {
			hr => 1,
			hr_color => $colors[$i],
			value => $percent,
		};
		my $graph = $Tag->ascii_graph($opt);
		push @out, <<EOF;
<tr>
	<td>$answer</td>
	<td>$number</td>
	<td>$graph</td>
</tr>
EOF
	}
	push @out, '</table>';
	return join "\n", @out;
	
}
EOR

UserTag ascii-graph Order value scale
UserTag ascii-graph addAttr
UserTag ascii-graph Routine <<EOR
sub {
	my ($value, $scale, $opt) = @_;

	unless($opt->{div_per_scale}) {
		$opt->{div_per_scale} = ($opt->{image} || $opt->{hr}) ? 100 : 25;
	}
	$scale ||= 100;
	my $factor = $opt->{div_per_scale} / $scale;
	
	my $amount = int($value * $factor);

	my $out = '';

	return $out unless $amount;

	if($opt->{image}) {
		$opt->{line_width} ||= 5;
		if($opt->{vertical}) {
			$out = qq{<img src="$opt->{image}" height=$amount width=$opt->{line_width}>};
		}
		else {
			$out = qq{<img src="$opt->{image}" width=$amount height=$opt->{line_width}>};
		}
	}
	elsif ($opt->{hr}) {
		$opt->{hr_color} ||= '#666666';
		$opt->{hr_height} ||= 5;
		my $shade = $opt->{hr_noshade} ? ' noshade' : '';
		$out = qq{<hr align=left size=$opt->{hr_height} width=$amount$shade color="$opt->{hr_color}">};
	}
	else {
		my $char = $opt->{character} || $opt->{char} || '*';
		$out = $char x $amount;
	}

	if($opt->{prepend_value}) {
		$out = qq{<table cellspacing=0 cellpadding=0><tr><td width=20 align=right>$value</td><td>&nbsp;</td><td>$out</td></tr></table>};
	}
	elsif($opt->{append_value}) {
		$out = "$out&nbsp;$value";
	}
	return $out;
}
EOR



1.1                  interchange/dist/features/quickpoll/quickpoll.init


rev 1.1, prev_rev 1.0
Index: quickpoll.init
===================================================================
[flag type=write table=mv_metadata]
[write-relative-file file="tmp/poll_metadata.asc"]code	type	width	height	field	db	name	outboard	options	attribute	label	help	lookup	filter	help_url	pre_filter	lookup_exclude	prepend	append	display_filter	extended
quickpoll::choices	textarea	30	5							Choices	Standard IC option format, i.e.:
<blockquote>
value1=Label which may be long<br>
value2=Another label<br>
value3=Yet another label<br>
value4<br>
value5=The above is just shown as value4
</blockquote>
		line2options		options2line					{}
quickpoll::code	hidden_text									Question ID										{}
quickpoll::colors	movecombo							green,red,blue,brown,yellow,cyan,chartreuse,gray		Colors	Colors for results, in order (highest value first color, next second, etc.)									{}
quickpoll::num_answers	select							=--default is 4--,1,2,3,4,5,6,7,8,9,10		Answers to show	Answers after this number are added together and shown as "Other"									{}
quickpoll::question	text_40									Question										{}
quickpoll	table																			{'no_code_link' => "1",'restrict_allow' => "poll_answer cgi",'panel_shade' => "f",'include_form' => "<td class=clabel> Answers </td>
<td class=cdata>

   [poll-answer code=\"[cgi item_id]\"]
</td>
",'include_form_interpolate' => "1",'display_type' => "image_meta",'ui_more_decade' => "10",'include_before' => "code",'explicit_edit' => "1",'ui_data_fields' => "code
title
question
choices
colors
num_answers",}
quickpoll::title	text_30									Title	Default is "Quick poll"									{}
[/write-relative-file]
[import-fields table=mv_metadata file="tmp/poll_metadata.asc" add=1]

[flag type=write table=quickpoll]
[write-relative-file file="tmp/quickpoll.asc"]code	poll_id	owner	title	question	choices	colors	num_answers
1	0		A New Poll	Will this poll work?	Yes,No,Maybe,Sometimes,Always,Never,x=When it wants to it will&#44; you bet	cyan green red blue yellow chartreuse	4
2			Another Poll	Do you like polls?	Yes,No,Sometimes,Always,Never,Anytime!	green red blue chartreuse	0
[/write-relative-file]
[import-fields table=quickpoll file="tmp/quickpoll.asc" add=1]



1.1                  interchange/dist/features/quickpoll/doc/quickpoll/README


rev 1.1, prev_rev 1.0
Index: README
===================================================================
=head1 NAME

quickpoll- Quick poll for Interchange

=head1 VERSION

$Revision: 1.1 $

=head1 SYNOPSIS

	[control-set]
		[component]quickpoll[/component]
	    [code]1[/code]
	[/control-set]

=head1 DESCRIPTION

This feature adds a "Quick Poll" feature to an interchange catalog. To implement,
place the "quickpoll" component in a page (or take the page code from
templates/components/quickpoll and incorporate it).

It creates two tables, "quickpoll" and "quickpoll_answer". It is tested on
MySQL, but should run on Postgres as well.

+-------------+--------------+------+-----+---------+----------------+
| Field       | Type         | Null | Key | Default | Extra          |
+-------------+--------------+------+-----+---------+----------------+
| code        | int(11)      |      | PRI | NULL    | auto_increment |
| poll_id     | varchar(128) | YES  |     | NULL    |                |
| owner       | varchar(128) | YES  |     | NULL    |                |
| title       | varchar(128) | YES  |     | NULL    |                |
| question    | varchar(255) | YES  |     | NULL    |                |
| choices     | text         | YES  |     | NULL    |                |
| colors      | text         | YES  |     | NULL    |                |
| num_answers | varchar(128) | YES  |     | NULL    |                |
+-------------+--------------+------+-----+---------+----------------+

+-------------+--------------+------+-----+---------+----------------+
| Field       | Type         | Null | Key | Default | Extra          |
+-------------+--------------+------+-----+---------+----------------+
| code        | int(11)      |      | PRI | NULL    | auto_increment |
| poll_id     | int(11)      | YES  |     | NULL    |                |
| question_id | int(11)      | YES  | MUL | NULL    |                |
| answer      | varchar(255) | YES  |     | NULL    |                |
| comment     | text         | YES  |     | NULL    |                |
| answer_date | varchar(128) | YES  |     | NULL    |                |
| ipaddr      | varchar(128) | YES  |     | NULL    |                |
| username    | varchar(128) | YES  |     | NULL    |                |
| login_table | varchar(128) | YES  |     | NULL    |                |
+-------------+--------------+------+-----+---------+----------------+

To create a poll, go to Tables->quickpoll->New Entry in the admin UI.

=head1 AUTHOR

Mike Heins, Perusion, <mikeh at perusion.com>.





1.1                  interchange/dist/features/quickpoll/templates/components/quickpoll


rev 1.1, prev_rev 1.0
Index: quickpoll
===================================================================
[comment]
ui_name: poll
ui_type: component
ui_class: vertical
ui_group: info
ui_label: Quick one-question poll

code:
	label: Poll ID
	lookup_query: select distinct code, question from poll
	type: select

answer_type:
	label: Answer type
	default: select
	options: radio_left_1=Radio box, select=Dropdown, checkbox_left_1=Checkbox (multiple choice)
	type: select

submit_label:
	label: Button text
	type: text_10
	default: Go

[/comment]
<!-- BEGIN COMPONENT poll -->

[tmp tmp_answered][calc]
		my $code = $Tag->control('code');
		return $Session->{quickpoll}{$code};
		[/calc][/tmp]

[if !scratch tmp_answered] 

	[loop list="[control code]"]
	<form action="[area quickpoll]">
	[form-session-id]
	<input type=hidden name="poll" value="[loop-code]">
	<input type=hidden name="mv_nextpage" value="@@MV_PAGE@@">
	<input type=hidden name="mv_arg" value="[data session arg]">
	  <div class=titlebox>
		[either][loop-data quickpoll title][or]Quick poll[/either]
	  </div>
	  <div class=shadowbox>
			[loop-data quickpoll question]<br>
			[display
				name="answer"
				type="[control answer_type radio_left_1]"
				passed="[loop-data quickpoll choices]"
			]
			<br>
			<input type=submit value="[control submit_label Go]">
	  </div>
	</form>
	[/loop]

[else]
	[loop list="[control code]"]
	  <div class=titlebox>
		[either][loop-data quickpoll title][or]Quick poll[/either]
	  </div>
	  <div class=shadowbox>
			<h5>[loop-data quickpoll question]</h5>
			[poll-answer code="[control code]"]
	  </div>
	[/loop]
[/else]
[/if]

<!-- END COMPONENT poll -->








More information about the interchange-cvs mailing list