Advertisement
SMFPL

messaging_patch

Jun 19th, 2013
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.57 KB | None | 0 0
  1. From d885a28b83e11507a02106f9de20132d41a41b4f Mon Sep 17 00:00:00 2001
  2. From: SMFPL_Koha <fred.pierre@smfpl.org>
  3. Date: Wed, 19 Jun 2013 12:34:52 -0400
  4. Subject: [PATCH] test/messaging.pl and koha-tmpl/intranet-tmpl/prog/en/modules/messaging.tt
  5. Content-Type: text/plain; charset="utf-8"
  6.  
  7. ---
  8. .../prog/en/modules/test/messaging.tt | 122 +++++++++
  9. test/messaging.pl | 261 ++++++++++++++++++++
  10. 2 files changed, 383 insertions(+), 0 deletions(-)
  11. create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/test/messaging.tt
  12. create mode 100755 test/messaging.pl
  13.  
  14. diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/test/messaging.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/test/messaging.tt
  15. new file mode 100644
  16. index 0000000..8c5ade0
  17. --- /dev/null
  18. +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/test/messaging.tt
  19. @@ -0,0 +1,122 @@
  20. +[% INCLUDE 'doc-head-open.inc' %]
  21. +<title>Koha Test Messaging</title>
  22. +[% INCLUDE 'doc-head-close.inc' %]
  23. +[% INCLUDE 'file-upload.inc' %]
  24. +<!--
  25. +<script type="text/javascript" src="[% themelang %]/js/background-job-progressbar.js"></script>
  26. +<style type="text/css">
  27. + #uploadpanel,#fileuploadstatus,#fileuploadfailed,#jobpanel,#jobstatus,#jobfailed { display : none; }
  28. + #fileuploadstatus,#jobstatus { margin:.4em; }
  29. + #fileuploadprogress,#jobprogress{ width:150px;height:10px;border:1px solid #666;background:url('/intranet-tmpl/prog/img/progress.png') -300px 0px no-repeat; }</style>
  30. +-->
  31. +<script type="text/javascript">
  32. +//<![CDATA[
  33. +$(document).ready(function(){
  34. +});
  35. +function CheckForm(f) {
  36. + alert("Hi There");
  37. + return false;
  38. +}
  39. +
  40. +//]]>
  41. +</script>
  42. +<style>
  43. +option.letter-not-selected{
  44. +background-color:red;
  45. +}
  46. +td{
  47. +background-color:transparent;
  48. +}
  49. +
  50. +#wrapper{
  51. +margin-top:40px;
  52. +margin-left:20px;
  53. +}
  54. +.maid-1{background-color:#F5F6CE;}
  55. +.maid-2{background-color:#CEF6CE;}
  56. +.maid-4{background-color:#CEE3F6;}
  57. +.maid-5{background-color:#D8CEF6;}
  58. +.maid-6{background-color:#F6CEEC;}
  59. +.is_not_digest{font-weight:bold;}
  60. +</style>
  61. +</head>
  62. +<body>
  63. +<div id="wrapper">
  64. +<h3>[% message %]</h3>
  65. +[% IF op %]
  66. +<div>
  67. +<p><strong>OP: </strong>[% op %]</p>
  68. +<p><strong>Id: </strong>[% id %]</p>
  69. +<p><strong>Message type: </strong>[% message_type %]</p>
  70. +<p><strong>Transport: </strong>[% transport %]</p>
  71. +<p><strong>Is Digest: </strong>[% is_digest %]</p>
  72. +<p><strong>Module: </strong>[% module %]</p>
  73. +<p><strong>Letter code: </strong>[% letter_code %]</p>
  74. +<form>
  75. +<p><strong>Select new code: </strong>
  76. +<select name="new_letter_code">
  77. +[% IF module == "circulation" %]
  78. + [% FOREACH selopt IN circulation_options %]
  79. + <option value="[% selopt.code %]" [% IF letter_code == selopt.code %]selected="selected"[% END %] >[% selopt.desc %] ([% selopt.code %])</option>
  80. + [% END %]
  81. +[% END %]
  82. +[% IF module == "reserves" %]
  83. + [% FOREACH selopt IN reserves_options %]
  84. + <option value="[% selopt.code %]" [% IF letter_code == selopt.code %]selected="selected"[% END %] >[% selopt.desc %] ([% selopt.code %])</option>
  85. + [% END %]
  86. +[% END %]
  87. +
  88. +
  89. +</select>
  90. +</p>
  91. +<input type="hidden" name="id" value="[% id %]" />
  92. +<input type="hidden" name="message_type" value="[% message_type %]" />
  93. +<input type="hidden" name="transport" value="[% transport %]" />
  94. +<input type="hidden" name="is_digest" value="[% is_digest %]" />
  95. +<input type="hidden" name="module" value="[% module %]" />
  96. +<input type="hidden" name="letter_code" value="[% letter_code %]" />
  97. +[% IF letter_code %]
  98. +<input type="hidden" name="update" value="1" />
  99. +[% END %]
  100. +<input type="submit" name="op" value="Save" />
  101. +<input type="button" name="cancel" value="Cancel" onclick="history.go(-1)"/>
  102. +</form>
  103. +</div>
  104. +[% END %]
  105. +
  106. +[% UNLESS op %]
  107. +
  108. +<table>
  109. +<tr>
  110. +<th>ID</th>
  111. +<th>Type</th>
  112. +<th>Module</th>
  113. +<th>Transport</th>
  114. +<th>Is Digest</th>
  115. +<th>Letter Code</th>
  116. +<th>Letter Description</th>
  117. +<th>Edit</th>
  118. +</tr>
  119. +[% FOREACH notice IN notices %]
  120. +<tr class="[% IF notice.is_digest %]is_digest[% ELSE %]is_not_digest[% END %] maid-[% notice.message_attribute_id %]" >
  121. +<td>[% notice.message_attribute_id %]</td>
  122. +<td>[% notice.message_name %]</td>
  123. +<td>[% notice.letter_module %]</td>
  124. +<td>[% notice.transport %]</td>
  125. +<td>[% notice.is_digest %]</td>
  126. +<td>[% notice.letter %]</td>
  127. +<td>[% notice.letter_description %]</td>
  128. +<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>
  129. +</tr>
  130. +[% END %]
  131. +</table>
  132. +<div>
  133. +<p></p>
  134. +<input type="button" name="mainpage" value="Home" onClick="window.location.href='/'" />
  135. +</div>
  136. +<div><pre></pre></div>
  137. +<div><pre></pre></div>
  138. +<div><pre></pre></div>
  139. +[% END %]
  140. +</div>
  141. +</body>
  142. diff --git a/test/messaging.pl b/test/messaging.pl
  143. new file mode 100755
  144. index 0000000..68b9f3e
  145. --- /dev/null
  146. +++ b/test/messaging.pl
  147. @@ -0,0 +1,261 @@
  148. +#!/usr/bin/perl
  149. +
  150. +use strict;
  151. +use warnings;
  152. +
  153. +# standard or CPAN modules used
  154. +use CGI;
  155. +use CGI::Cookie;
  156. +
  157. +# Koha modules used
  158. +use C4::Context;
  159. +use C4::Auth;
  160. +use C4::Output;
  161. +use C4::Members;
  162. +use C4::Letters;
  163. +
  164. +
  165. +use Data::Dumper;
  166. +
  167. +my $input = new CGI;
  168. +my $dbh = C4::Context->dbh;
  169. +#$dbh->{AutoCommit} = 0;
  170. +$dbh->{RaiseError} = 0;
  171. +
  172. +my ($template, $loggedinuser, $cookie)
  173. + = get_template_and_user({template_name => "test/messaging.tmpl",
  174. + query => $input,
  175. + type => "intranet",
  176. + debug => 1,
  177. + });
  178. +
  179. +my $myhashref = {'me'=>25, "one"=>10, "two"=>22, "threee"=>333};
  180. +
  181. +my $userinfo = $template->{'VARS'}->{'USER_INFO'};
  182. +my $user = ${$userinfo}[0];
  183. +my $firstname = $user->{'firstname'};
  184. +
  185. +
  186. +my $driver = C4::Context->preference('SMSSendDriver');
  187. +my $transports = ['email','sms','print','phone'];
  188. +my $digests = ['0','1'];
  189. +
  190. +
  191. +
  192. +my $reserves = GetLetters('reserves');
  193. +my @res_keys = sort(keys %$reserves);
  194. +my @resv_loop;
  195. +push @resv_loop, {'code'=>'0', 'desc'=>'*** None Selected ***'};
  196. +foreach my $key (@res_keys){
  197. +
  198. + push @resv_loop, {'code'=>$key, 'desc'=>$reserves->{$key}};
  199. +
  200. +}
  201. +
  202. +my $circulations = GetLetters('circulation');
  203. +my @circ_keys = sort(keys %$circulations);
  204. +my @circ_loop;
  205. +push @circ_loop, {'code'=>'0', 'desc'=>'<span style="color:#ff0000;"> None Selected </span>'};
  206. +foreach my $key (@circ_keys){
  207. +
  208. + push @circ_loop, {'code'=>$key, 'desc'=>$circulations->{$key}};
  209. +}
  210. +
  211. +$template->param(
  212. + 'reserves_options'=> \@resv_loop,
  213. + 'circulation_options' => \@circ_loop ,
  214. +);
  215. +
  216. +my %descriptions =(%$reserves, %$circulations);
  217. +my $attributes = GetMessageAttributes();
  218. +
  219. +if($input->param('op') eq 'edit'){
  220. +
  221. +my $id = $input->param('id');
  222. +my $transport = $input->param('transport');
  223. +my $is_digest = $input->param('is_digest');
  224. +my $letter_code = $input->param('letter_code');
  225. +
  226. +$template->param(
  227. + 'op' => 'edit',
  228. + 'id' => $id,
  229. + 'message_type' => $attributes->{$id}->{'message_name'},
  230. + 'module' => $attributes->{$id}->{'letter_module'},
  231. + 'transport' => $transport,
  232. + 'is_digest' => $is_digest,
  233. + 'letter_code' => $letter_code,
  234. +);
  235. +
  236. +output_html_with_http_headers $input, $cookie, $template->output;
  237. +exit 0;
  238. +}
  239. +
  240. +my $message;
  241. +
  242. +if($input->param('op') eq 'Save'){
  243. +
  244. +my $id = $input->param('id');
  245. +my $transport = $input->param('transport');
  246. +my $is_digest = $input->param('is_digest');
  247. +my $letter_code = $input->param('new_letter_code');
  248. +
  249. +if($input->param('new_letter_code')){
  250. +# Save new entry
  251. +# need: message_attribute_id, message_transport_type and is_digest to save letter_code
  252. +
  253. + if($input->param('update')){
  254. + #update db
  255. + my $update = "UPDATE message_transports SET letter_code = ? WHERE message_attribute_id = ? AND message_transport_type = ? AND is_digest = ?";
  256. + my $sth = $dbh->prepare($update);
  257. + # set up so that we can easily construct the insert SQL
  258. + my $success = $sth->execute( $letter_code,
  259. + $id,
  260. + $transport,
  261. + $is_digest,
  262. + );
  263. +if($success){
  264. +$message = $letter_code." Updated: id= ". $id.", transport= ".$transport.", is_digest= ".$is_digest.".";
  265. +}else{
  266. +$message = "Update failed.";
  267. +}
  268. +
  269. + }else{
  270. + #insert into db
  271. + #also need letter_module
  272. + my $module = $attributes->{$id}->{'letter_module'};
  273. + my $insert = "INSERT INTO message_transports (message_attribute_id, message_transport_type, is_digest, letter_module, letter_code) VALUES ( ?, ?, ?, ?, ?)";
  274. +
  275. + my $sth = $dbh->prepare($insert);
  276. + # set up so that we can easily construct the insert SQL
  277. + my $success = $sth->execute( $id,
  278. + $transport,
  279. + $is_digest,
  280. + $module,
  281. + $letter_code );
  282. +if($success){
  283. +$message = $letter_code." Saved: id= ". $id.", transport= ".$transport.", is_digest= ".$is_digest.", module= ".$module;
  284. +}else{
  285. +$message = "Failed to save.";
  286. +}
  287. +
  288. +
  289. +}
  290. +}else{
  291. +# did not select new Letter Code
  292. +
  293. + if($input->param('update')){
  294. + #update db
  295. + my $update = "DELETE FROM message_transports WHERE message_attribute_id = ? AND message_transport_type = ? AND is_digest = ?";
  296. + my $sth = $dbh->prepare($update);
  297. + # set up so that we can easily construct the insert SQL
  298. + my $success = $sth->execute( $id,
  299. + $transport,
  300. + $is_digest,
  301. + );
  302. +if($success){
  303. +$message = $letter_code." Updated: id= ". $id.", transport= ".$transport.", is_digest= ".$is_digest.".";
  304. +}else{
  305. +$message = "Update failed.";
  306. +}
  307. +
  308. + }
  309. +
  310. +
  311. +}
  312. +}
  313. +
  314. +my $messaging_options = C4::Members::Messaging::GetMessagingOptions();
  315. +my %sort_options;
  316. +foreach my $mo (@$messaging_options){
  317. + my $id = $mo->{message_attribute_id};
  318. + $sort_options{($attributes->{$id}->{'letter_module'}).$id} = $mo;
  319. +}
  320. +
  321. +my @keys = sort keys %sort_options;
  322. +my @new_sort_options;
  323. +foreach my $key (@keys){
  324. +
  325. + push @new_sort_options, $sort_options{$key}
  326. +
  327. +}
  328. +
  329. +
  330. +my $letter_codes = GetLettersCodes();
  331. +
  332. +my @notices;
  333. +foreach my $messop (@new_sort_options){
  334. + my $id;
  335. + my $props;
  336. + foreach my $digest (@$digests){
  337. + $id = $messop->{message_attribute_id};
  338. + foreach my $trans (@$transports){
  339. + $props = {
  340. + 'message_attribute_id' => $id,
  341. + 'message_name'=> $messop->{message_name},
  342. + 'letter_module' => $attributes->{$id}->{'letter_module'},
  343. + 'takes_days' => $messop->{takes_days},
  344. + 'letter' => $letter_codes->{$id}->{$trans}->{$digest},
  345. + 'letter_description' => $descriptions{$letter_codes->{$id}->{$trans}->{$digest}},
  346. + 'is_digest' => $digest,
  347. + 'transport' => $trans,
  348. + };
  349. + push @notices, $props
  350. + };
  351. + };
  352. +
  353. +
  354. +};
  355. +
  356. +my $dump = Dumper($messaging_options);
  357. +$template->param(
  358. + dump => $dump,
  359. + message => $message,
  360. + firstname => $firstname,
  361. + notices => \@notices,
  362. + transports => $transports,
  363. +);
  364. +
  365. +output_html_with_http_headers $input, $cookie, $template->output;
  366. +
  367. +exit 0;
  368. +
  369. +# Returns hash ref to Letter_Codes used in [message_transports]
  370. +# for each id in [message_attributes] table
  371. +# {id}->{transport_type}->{is_digest} = letter_code
  372. +#
  373. +sub GetLettersCodes(){
  374. +
  375. + my $sql = <<'END_SQL';
  376. +select message_attributes.message_attribute_id, message_transport_type, is_digest , letter_code
  377. + FROM message_attributes
  378. + LEFT JOIN message_transports
  379. + ON message_attributes.message_attribute_id = message_transports.message_attribute_id
  380. +END_SQL
  381. +
  382. + my $sth = C4::Context->dbh->prepare($sql);
  383. + $sth->execute();
  384. + my $letters;
  385. + while ( my $row = $sth->fetchrow_hashref() ) {
  386. +
  387. + $letters->{ $row->{'message_attribute_id'} }->{$row->{'message_transport_type'}}->{$row->{'is_digest'}} = $row->{'letter_code'};
  388. + }
  389. +
  390. +return $letters;
  391. +
  392. +}
  393. +
  394. +# Return hash ref to Messages defined in modules: circulation & reserves
  395. +sub GetMessageAttributes(){
  396. +
  397. +my $attributes = {
  398. +'1' => {'message_attribute_id'=>1, 'message_name'=>'Item_Due', 'letter_module'=>'circulation'},
  399. +'2' => {'message_attribute_id'=>2, 'message_name'=>'Advance_Notice', 'letter_module'=>'circulation'},
  400. +'4' => {'message_attribute_id'=>4, 'message_name'=>'Hold_Filled', 'letter_module'=>'reserves'},
  401. +'5' => {'message_attribute_id'=>5, 'message_name'=>'Item_Check_in', 'letter_module'=>'circulation'},
  402. +'6' => {'message_attribute_id'=>6, 'message_name'=>'Item_Checkout', 'letter_module'=>'circulation'},
  403. + };
  404. +
  405. +return $attributes;
  406. +
  407. +}
  408. +
  409. --
  410. 1.7.2.5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement