Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From d885a28b83e11507a02106f9de20132d41a41b4f Mon Sep 17 00:00:00 2001
- From: SMFPL_Koha <fred.pierre@smfpl.org>
- Date: Wed, 19 Jun 2013 12:34:52 -0400
- Subject: [PATCH] test/messaging.pl and koha-tmpl/intranet-tmpl/prog/en/modules/messaging.tt
- Content-Type: text/plain; charset="utf-8"
- ---
- .../prog/en/modules/test/messaging.tt | 122 +++++++++
- test/messaging.pl | 261 ++++++++++++++++++++
- 2 files changed, 383 insertions(+), 0 deletions(-)
- create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/test/messaging.tt
- create mode 100755 test/messaging.pl
- diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/test/messaging.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/test/messaging.tt
- new file mode 100644
- index 0000000..8c5ade0
- --- /dev/null
- +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/test/messaging.tt
- @@ -0,0 +1,122 @@
- +[% INCLUDE 'doc-head-open.inc' %]
- +<title>Koha Test Messaging</title>
- +[% INCLUDE 'doc-head-close.inc' %]
- +[% INCLUDE 'file-upload.inc' %]
- +<!--
- +<script type="text/javascript" src="[% themelang %]/js/background-job-progressbar.js"></script>
- +<style type="text/css">
- + #uploadpanel,#fileuploadstatus,#fileuploadfailed,#jobpanel,#jobstatus,#jobfailed { display : none; }
- + #fileuploadstatus,#jobstatus { margin:.4em; }
- + #fileuploadprogress,#jobprogress{ width:150px;height:10px;border:1px solid #666;background:url('/intranet-tmpl/prog/img/progress.png') -300px 0px no-repeat; }</style>
- +-->
- +<script type="text/javascript">
- +//<![CDATA[
- +$(document).ready(function(){
- +});
- +function CheckForm(f) {
- + alert("Hi There");
- + return false;
- +}
- +
- +//]]>
- +</script>
- +<style>
- +option.letter-not-selected{
- +background-color:red;
- +}
- +td{
- +background-color:transparent;
- +}
- +
- +#wrapper{
- +margin-top:40px;
- +margin-left:20px;
- +}
- +.maid-1{background-color:#F5F6CE;}
- +.maid-2{background-color:#CEF6CE;}
- +.maid-4{background-color:#CEE3F6;}
- +.maid-5{background-color:#D8CEF6;}
- +.maid-6{background-color:#F6CEEC;}
- +.is_not_digest{font-weight:bold;}
- +</style>
- +</head>
- +<body>
- +<div id="wrapper">
- +<h3>[% message %]</h3>
- +[% IF op %]
- +<div>
- +<p><strong>OP: </strong>[% op %]</p>
- +<p><strong>Id: </strong>[% id %]</p>
- +<p><strong>Message type: </strong>[% message_type %]</p>
- +<p><strong>Transport: </strong>[% transport %]</p>
- +<p><strong>Is Digest: </strong>[% is_digest %]</p>
- +<p><strong>Module: </strong>[% module %]</p>
- +<p><strong>Letter code: </strong>[% letter_code %]</p>
- +<form>
- +<p><strong>Select new code: </strong>
- +<select name="new_letter_code">
- +[% IF module == "circulation" %]
- + [% FOREACH selopt IN circulation_options %]
- + <option value="[% selopt.code %]" [% IF letter_code == selopt.code %]selected="selected"[% END %] >[% selopt.desc %] ([% selopt.code %])</option>
- + [% END %]
- +[% END %]
- +[% IF module == "reserves" %]
- + [% FOREACH selopt IN reserves_options %]
- + <option value="[% selopt.code %]" [% IF letter_code == selopt.code %]selected="selected"[% END %] >[% selopt.desc %] ([% selopt.code %])</option>
- + [% END %]
- +[% END %]
- +
- +
- +</select>
- +</p>
- +<input type="hidden" name="id" value="[% id %]" />
- +<input type="hidden" name="message_type" value="[% message_type %]" />
- +<input type="hidden" name="transport" value="[% transport %]" />
- +<input type="hidden" name="is_digest" value="[% is_digest %]" />
- +<input type="hidden" name="module" value="[% module %]" />
- +<input type="hidden" name="letter_code" value="[% letter_code %]" />
- +[% IF letter_code %]
- +<input type="hidden" name="update" value="1" />
- +[% END %]
- +<input type="submit" name="op" value="Save" />
- +<input type="button" name="cancel" value="Cancel" onclick="history.go(-1)"/>
- +</form>
- +</div>
- +[% END %]
- +
- +[% UNLESS op %]
- +
- +<table>
- +<tr>
- +<th>ID</th>
- +<th>Type</th>
- +<th>Module</th>
- +<th>Transport</th>
- +<th>Is Digest</th>
- +<th>Letter Code</th>
- +<th>Letter Description</th>
- +<th>Edit</th>
- +</tr>
- +[% FOREACH notice IN notices %]
- +<tr class="[% IF notice.is_digest %]is_digest[% ELSE %]is_not_digest[% END %] maid-[% notice.message_attribute_id %]" >
- +<td>[% notice.message_attribute_id %]</td>
- +<td>[% notice.message_name %]</td>
- +<td>[% notice.letter_module %]</td>
- +<td>[% notice.transport %]</td>
- +<td>[% notice.is_digest %]</td>
- +<td>[% notice.letter %]</td>
- +<td>[% notice.letter_description %]</td>
- +<td><a href='/cgi-bin/koha/test/messaging.pl?op=edit&id=[% notice.message_attribute_id %]&transport=[% notice.transport %]&is_digest=[% notice.is_digest %]&letter_code=[% notice.letter %][% IF !notice.letter %]&new_letter=yes[% END %]'>Edit</a></td>
- +</tr>
- +[% END %]
- +</table>
- +<div>
- +<p></p>
- +<input type="button" name="mainpage" value="Home" onClick="window.location.href='/'" />
- +</div>
- +<div><pre></pre></div>
- +<div><pre></pre></div>
- +<div><pre></pre></div>
- +[% END %]
- +</div>
- +</body>
- diff --git a/test/messaging.pl b/test/messaging.pl
- new file mode 100755
- index 0000000..68b9f3e
- --- /dev/null
- +++ b/test/messaging.pl
- @@ -0,0 +1,261 @@
- +#!/usr/bin/perl
- +
- +use strict;
- +use warnings;
- +
- +# standard or CPAN modules used
- +use CGI;
- +use CGI::Cookie;
- +
- +# Koha modules used
- +use C4::Context;
- +use C4::Auth;
- +use C4::Output;
- +use C4::Members;
- +use C4::Letters;
- +
- +
- +use Data::Dumper;
- +
- +my $input = new CGI;
- +my $dbh = C4::Context->dbh;
- +#$dbh->{AutoCommit} = 0;
- +$dbh->{RaiseError} = 0;
- +
- +my ($template, $loggedinuser, $cookie)
- + = get_template_and_user({template_name => "test/messaging.tmpl",
- + query => $input,
- + type => "intranet",
- + debug => 1,
- + });
- +
- +my $myhashref = {'me'=>25, "one"=>10, "two"=>22, "threee"=>333};
- +
- +my $userinfo = $template->{'VARS'}->{'USER_INFO'};
- +my $user = ${$userinfo}[0];
- +my $firstname = $user->{'firstname'};
- +
- +
- +my $driver = C4::Context->preference('SMSSendDriver');
- +my $transports = ['email','sms','print','phone'];
- +my $digests = ['0','1'];
- +
- +
- +
- +my $reserves = GetLetters('reserves');
- +my @res_keys = sort(keys %$reserves);
- +my @resv_loop;
- +push @resv_loop, {'code'=>'0', 'desc'=>'*** None Selected ***'};
- +foreach my $key (@res_keys){
- +
- + push @resv_loop, {'code'=>$key, 'desc'=>$reserves->{$key}};
- +
- +}
- +
- +my $circulations = GetLetters('circulation');
- +my @circ_keys = sort(keys %$circulations);
- +my @circ_loop;
- +push @circ_loop, {'code'=>'0', 'desc'=>'<span style="color:#ff0000;"> None Selected </span>'};
- +foreach my $key (@circ_keys){
- +
- + push @circ_loop, {'code'=>$key, 'desc'=>$circulations->{$key}};
- +}
- +
- +$template->param(
- + 'reserves_options'=> \@resv_loop,
- + 'circulation_options' => \@circ_loop ,
- +);
- +
- +my %descriptions =(%$reserves, %$circulations);
- +my $attributes = GetMessageAttributes();
- +
- +if($input->param('op') eq 'edit'){
- +
- +my $id = $input->param('id');
- +my $transport = $input->param('transport');
- +my $is_digest = $input->param('is_digest');
- +my $letter_code = $input->param('letter_code');
- +
- +$template->param(
- + 'op' => 'edit',
- + 'id' => $id,
- + 'message_type' => $attributes->{$id}->{'message_name'},
- + 'module' => $attributes->{$id}->{'letter_module'},
- + 'transport' => $transport,
- + 'is_digest' => $is_digest,
- + 'letter_code' => $letter_code,
- +);
- +
- +output_html_with_http_headers $input, $cookie, $template->output;
- +exit 0;
- +}
- +
- +my $message;
- +
- +if($input->param('op') eq 'Save'){
- +
- +my $id = $input->param('id');
- +my $transport = $input->param('transport');
- +my $is_digest = $input->param('is_digest');
- +my $letter_code = $input->param('new_letter_code');
- +
- +if($input->param('new_letter_code')){
- +# Save new entry
- +# need: message_attribute_id, message_transport_type and is_digest to save letter_code
- +
- + if($input->param('update')){
- + #update db
- + my $update = "UPDATE message_transports SET letter_code = ? WHERE message_attribute_id = ? AND message_transport_type = ? AND is_digest = ?";
- + my $sth = $dbh->prepare($update);
- + # set up so that we can easily construct the insert SQL
- + my $success = $sth->execute( $letter_code,
- + $id,
- + $transport,
- + $is_digest,
- + );
- +if($success){
- +$message = $letter_code." Updated: id= ". $id.", transport= ".$transport.", is_digest= ".$is_digest.".";
- +}else{
- +$message = "Update failed.";
- +}
- +
- + }else{
- + #insert into db
- + #also need letter_module
- + my $module = $attributes->{$id}->{'letter_module'};
- + my $insert = "INSERT INTO message_transports (message_attribute_id, message_transport_type, is_digest, letter_module, letter_code) VALUES ( ?, ?, ?, ?, ?)";
- +
- + my $sth = $dbh->prepare($insert);
- + # set up so that we can easily construct the insert SQL
- + my $success = $sth->execute( $id,
- + $transport,
- + $is_digest,
- + $module,
- + $letter_code );
- +if($success){
- +$message = $letter_code." Saved: id= ". $id.", transport= ".$transport.", is_digest= ".$is_digest.", module= ".$module;
- +}else{
- +$message = "Failed to save.";
- +}
- +
- +
- +}
- +}else{
- +# did not select new Letter Code
- +
- + if($input->param('update')){
- + #update db
- + my $update = "DELETE FROM message_transports WHERE message_attribute_id = ? AND message_transport_type = ? AND is_digest = ?";
- + my $sth = $dbh->prepare($update);
- + # set up so that we can easily construct the insert SQL
- + my $success = $sth->execute( $id,
- + $transport,
- + $is_digest,
- + );
- +if($success){
- +$message = $letter_code." Updated: id= ". $id.", transport= ".$transport.", is_digest= ".$is_digest.".";
- +}else{
- +$message = "Update failed.";
- +}
- +
- + }
- +
- +
- +}
- +}
- +
- +my $messaging_options = C4::Members::Messaging::GetMessagingOptions();
- +my %sort_options;
- +foreach my $mo (@$messaging_options){
- + my $id = $mo->{message_attribute_id};
- + $sort_options{($attributes->{$id}->{'letter_module'}).$id} = $mo;
- +}
- +
- +my @keys = sort keys %sort_options;
- +my @new_sort_options;
- +foreach my $key (@keys){
- +
- + push @new_sort_options, $sort_options{$key}
- +
- +}
- +
- +
- +my $letter_codes = GetLettersCodes();
- +
- +my @notices;
- +foreach my $messop (@new_sort_options){
- + my $id;
- + my $props;
- + foreach my $digest (@$digests){
- + $id = $messop->{message_attribute_id};
- + foreach my $trans (@$transports){
- + $props = {
- + 'message_attribute_id' => $id,
- + 'message_name'=> $messop->{message_name},
- + 'letter_module' => $attributes->{$id}->{'letter_module'},
- + 'takes_days' => $messop->{takes_days},
- + 'letter' => $letter_codes->{$id}->{$trans}->{$digest},
- + 'letter_description' => $descriptions{$letter_codes->{$id}->{$trans}->{$digest}},
- + 'is_digest' => $digest,
- + 'transport' => $trans,
- + };
- + push @notices, $props
- + };
- + };
- +
- +
- +};
- +
- +my $dump = Dumper($messaging_options);
- +$template->param(
- + dump => $dump,
- + message => $message,
- + firstname => $firstname,
- + notices => \@notices,
- + transports => $transports,
- +);
- +
- +output_html_with_http_headers $input, $cookie, $template->output;
- +
- +exit 0;
- +
- +# Returns hash ref to Letter_Codes used in [message_transports]
- +# for each id in [message_attributes] table
- +# {id}->{transport_type}->{is_digest} = letter_code
- +#
- +sub GetLettersCodes(){
- +
- + my $sql = <<'END_SQL';
- +select message_attributes.message_attribute_id, message_transport_type, is_digest , letter_code
- + FROM message_attributes
- + LEFT JOIN message_transports
- + ON message_attributes.message_attribute_id = message_transports.message_attribute_id
- +END_SQL
- +
- + my $sth = C4::Context->dbh->prepare($sql);
- + $sth->execute();
- + my $letters;
- + while ( my $row = $sth->fetchrow_hashref() ) {
- +
- + $letters->{ $row->{'message_attribute_id'} }->{$row->{'message_transport_type'}}->{$row->{'is_digest'}} = $row->{'letter_code'};
- + }
- +
- +return $letters;
- +
- +}
- +
- +# Return hash ref to Messages defined in modules: circulation & reserves
- +sub GetMessageAttributes(){
- +
- +my $attributes = {
- +'1' => {'message_attribute_id'=>1, 'message_name'=>'Item_Due', 'letter_module'=>'circulation'},
- +'2' => {'message_attribute_id'=>2, 'message_name'=>'Advance_Notice', 'letter_module'=>'circulation'},
- +'4' => {'message_attribute_id'=>4, 'message_name'=>'Hold_Filled', 'letter_module'=>'reserves'},
- +'5' => {'message_attribute_id'=>5, 'message_name'=>'Item_Check_in', 'letter_module'=>'circulation'},
- +'6' => {'message_attribute_id'=>6, 'message_name'=>'Item_Checkout', 'letter_module'=>'circulation'},
- + };
- +
- +return $attributes;
- +
- +}
- +
- --
- 1.7.2.5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement