2 package C4::InterfaceCDK; #asummes C4/InterfaceCDK
10 use C4::Circulation::Borrissues;
11 use C4::Circulation::Renewals;
16 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
18 # set the version for version checking
22 @EXPORT = qw(&dialog &startint &endint &output &clearscreen &pause &helptext
23 &textbox &menu &issuewindow &msg_yn &msg_ny &borrower_dialog &debug_msg &error_msg
24 &info_msg &selborrower &returnwindow &logondialog &borrowerwindow &titlepanel
25 &borrbind &borrfill &preeborr &borrowerbox &brmenu &prmenu);
26 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
28 # your exported package globals go here,
29 # as well as any optionally exported functions
31 @EXPORT_OK = qw($Var1 %Hashit);
32 # non-exported package globals go here
33 use vars qw(@more $stuff);
35 # initalize package globals, first exported ones
40 # then the others (which are still accessible as $Some::Module::stuff)
44 # all file-scoped lexicals must be created before
45 # the functions below that se them.
47 # file-private lexicals go here
51 #defining keystrokes used for screens
53 my $key_ctlr = chr(18);
54 my $lastval = $key_ctlr;
56 # here's a file-private function as a closure,
57 # callable as &$priv_func; it cannot be prototyped.
62 # make all your functions, whether exported or not;
73 my ($env,$type,$title,@items)=@_;
74 $env->{'sysarea'}="Menu";
75 my $titlebar=titlepanel($env,"Koha","Main Menu");
80 while ($items[$x] ne "") {
81 $mitems[$x]="<C>".$items[$x];
84 if ($type eq 'console'){
86 my $menu = new Cdk::Scroll ('Title'=>" ",
88 'Height'=> $menucnt+4,
90 # Activate the object.
91 my ($menuItem) = $menu->activate();
94 if (!defined $menuItem) {
98 $data = $items[$menuItem];
101 return($reason,$data);
114 my($left,$top,$msg)=@_;
117 my $output = new Cdk::Label ('Message' =>\@outm,
118 'Ypos'=>$top, 'Xpos'=>$left, 'Box'=>0);
125 my $helptext = output(1,24,$text);
131 my ($env,$title,$title2)=@_;
133 @header[0] = fmtstr($env,$title,"L24");
134 @header[0] = @header[0].fmtstr($env,
135 $env->{'branchname'}."-".$env->{'queue'},"C28");
136 @header[0] = @header[0].fmtstr($env,$title2,"R24");
137 my $label = new Cdk::Label ('Message' =>\@header,'Ypos'=>0,'Xpos'=>0);
143 my ($env,$text1,$text2)=@_;
144 # Create the dialog buttons.
145 my @buttons = ("Yes", "No");
146 my @mesg = ("<C>$text1", "<C>$text2");
147 # Create the dialog object.
148 my $dialog = new Cdk::Dialog ('Message' => \@mesg, 'Buttons' => \@buttons);
149 my $resp = $dialog->activate();
158 my ($env,$text1,$text2)=@_;
160 # Create the dialog buttons.
161 my @buttons = ("No", "Yes");
162 my @mesg = ("<C>$text1", "<C>$text2");
163 # Create the dialog object.
164 my $dialog = new Cdk::Dialog ('Message' => \@mesg, 'Buttons' => \@buttons);
165 my $resp = $dialog->activate();
176 if ($env->{'telnet'} eq "Y") {
177 popupLabel (["Debug </R>$text"]);
179 # print "****DEBUG $text****";
186 popupLabel (["<C>Error </R>$text"]);
192 popupLabel ([$text]);
202 my ($env,$brrecs)=@_;
203 $env->{'sysarea'}="Menu";
204 my $titlebar=titlepanel($env,"Koha","Select branch");
207 while (@$brrecs[$x] ne "") {
208 my $brrec =@$brrecs[$x];
209 $mitems[$x]=fmtstr($env,$brrec->{'branchcode'},"L6");
210 $mitems[$x]=$mitems[$x].fmtstr($env,$brrec->{'branchname'},"L20");
213 my $menu = new Cdk::Scroll ('Title'=>" ",
217 # Activate the object.
218 my ($menuItem) = $menu->activate();
220 if (defined $menuItem) {
221 my $brrec = @$brrecs[$menuItem];
222 $env->{'branchcode'} = $brrec->{'branchcode'};
223 $env->{'branchname'} = $brrec->{'branchname'};
232 my ($env,$prrecs)=@_;
233 $env->{'sysarea'}="Menu";
234 my $titlebar=titlepanel($env,"Koha","Select printer");
237 while (@$prrecs[$x] ne "") {
238 my $prrec =@$prrecs[$x];
239 $mitems[$x]=fmtstr($env,$prrec->{'printername'},"L20");
242 my $menu = new Cdk::Scroll ('Title'=>" ",
246 # Activate the object.
247 my ($menuItem) = $menu->activate();
251 if (defined $menuItem) {
252 my $prrec = @$prrecs[$menuItem];
253 $env->{'queue'} = $prrec->{'printqueue'};
254 $env->{'printtype'} = $prrec->{'printtype'};
261 sub borrower_dialog {
266 my @coltitles = ("Borrower","Item");
267 my @rowtitles = (" ");
268 my @coltypes = ("UMIXED","UMIXED");
269 my @colwidths = (12,12);
270 my $matrix = new Cdk::Matrix (
271 'ColTitles'=> \@coltitles,
272 'RowTitles'=> \@rowtitles,
273 'ColWidths'=> \@colwidths,
274 'ColTypes'=> \@coltypes,
277 borrbind($env,$matrix);
279 my ($rows,$cols,$info) = $matrix->activate();
280 if ((!defined $rows) && ($info->[0][0] eq "")) {
283 $borrower = $info->[0][0];
284 $book = $info->[0][1];
287 $matrix->unregister();
289 Cdk::refreshCdkScreen();
290 return ($borrower,$result,$book);
294 my ($env,$dbh,$borrows,$bornums)=@_;
296 my $label = "Select a borrower";
297 my $scroll = new Cdk::Scroll ('Title'=>$label,
298 'List'=>\@$borrows,'Height'=>15,'Width'=>60);
299 my $returnValue = $scroll->activate ();
300 if (!defined $returnValue) {
303 $result = substr(@$borrows[$returnValue],0,9);
306 #$scroll->unregister();
308 Cdk::refreshCdkScreen();
313 my ($env,$title,$dbh,$items1,$items2,$borrower,$amountowing,$odues)=@_;
314 my @functs=("Due Date","Renewals","Payments","Print","Current","Previous");
315 my $titlepanel = titlepanel($env,"Issues","Issue an Item");
316 my $scroll2 = new Cdk::Scroll ('Title'=>"Previous Issues",
317 'List'=>\@$items1,'Height'=> 8,'Width'=>78,'Ypos'=>18);
318 my $scroll1 = new Cdk::Scroll ('Title'=>"Current Issues",
319 'List'=>\@$items2,'Height'=> 8,'Width'=>78,'Ypos'=>9);
320 my $funcmenu = new Cdk::Scroll ('Title'=>"",
321 'List'=>\@functs,'Height'=>5,'Width'=>12,'Ypos'=>3,'Xpos'=>28);
322 my $loanlength = new Cdk::Entry('Label'=>"Due Date: ",
323 'Max'=>"30",'Width'=>"11",
324 'Xpos'=>0,'Ypos'=>5,'Type'=>"UMIXED");
326 while ($x < length($env->{'loanlength'})) {
327 $loanlength->inject('Input'=>substr($env->{'loanlength'},$x,1));
330 my $borrbox = borrowerbox($env,$borrower,$amountowing);
331 my $entryBox = new Cdk::Entry('Label'=>"Item Barcode: ",
332 'Max'=>"11",'Width'=>"11",
333 'Xpos'=>"0",'Ypos'=>3,'Type'=>"UMIXED");
339 #$env->{'loanlength'} = "";
340 #debug_msg($env,"clear len");
343 $entryBox->preProcess ('Function' =>
344 sub{prebook(@_,$env,$dbh,$funcmenu,$entryBox,$loanlength,
345 $scroll1,$scroll2,$borrower,$amountowing,$odues);});
346 $barcode = $entryBox->activate();
348 if (!defined $barcode) {
349 $reason="Finished user"
356 $loanlength->erase();
364 Cdk::refreshCdkScreen();
365 #debug_msg($env,"exiting");
366 return $barcode,$reason;
369 my ($env,$dbh,$funcmenu,$entryBox,$loanlength,$scroll1,
370 $scroll2,$borrower,$amountowing,$odues) = @_;
371 my $funct = $funcmenu->activate();
372 if (!defined $funct) {
373 } elsif ($funct == 0 ) {
374 actloanlength ($env,$entryBox,$loanlength,$scroll1,$scroll2);
375 } elsif ($funct == 1 ) {
379 $loanlength->erase();
382 C4::Circulation::Renewals::bulkrenew($env,$dbh,
383 $borrower->{'borrowernumber'},$amountowing,$borrower,$odues);
384 } elsif ($funct == 2 ) {
388 $loanlength->erase();
390 C4::Accounts::reconcileaccount($env,$dbh,$borrower->{'borrowernumber'},
391 $amountowing,$borrower,$odues);
392 } elsif ($funct == 3 ) {
393 C4::Circulation::Borrissues::printallissues ($env,$borrower);
394 } elsif ($funct == 4 ) {
395 actscroll1 ($env,$entryBox,$loanlength,$scroll1,$scroll2);
396 } elsif ($funct == 5 ) {
397 actscroll2 ($env,$entryBox,$loanlength,$scroll1,$scroll2);
399 Cdk::refreshCdkScreen();
400 $entryBox->unregister();
401 $entryBox->register();
405 my ($env,$entryBox,$loanlength,$scroll1,$scroll2) = @_;
406 $scroll1->activate();
410 my ($env,$entryBox,$loanlength,$scroll1,$scroll2) = @_;
411 $scroll2->activate();
415 my ($env,$entryBox,$loanlength,$scroll1,$scroll2) = @_;
417 while ($validdate eq "N") {
418 my $loanlength = $loanlength->activate();
419 if (!defined $loanlength) {
420 $env->{'loanlength'} = "";
422 } elsif ($loanlength eq "") {
423 $env->{'loanlength'} = "";
426 my $date = ParseDate($loanlength);
427 if ( $date > ParseDate('today')){
429 my $fdate = substr($date,0,4).'-'.substr($date,4,2).'-'.substr($date,6,2);
430 #debug_msg($env,"$date $fdate");
431 $env->{'loanlength'} = $fdate;
433 error_msg($env,"Invalid date");
441 my ($input,$env,$dbh,$funcmenu,$entryBox,$loanlength,
442 $scroll1,$scroll2,$borrower,$amountowing,$odues)= @_;
443 if ($input eq $key_tab) {
444 actfmenu ($env,$dbh,$funcmenu,$entryBox,$loanlength,$scroll1,
445 $scroll2,$borrower,$amountowing,$odues);
452 my ($env,$borrower,$amountowing,$odues) = @_;
454 my $amountowing = fmtdec($env,$amountowing,"42");
455 my $line = "$borrower->{'cardnumber'} ";
456 $line = $line."$borrower->{'surname'}, ";
457 $line = $line."$borrower->{'title'} $borrower->{'firstname'}";
459 $line = "$borrower->{'streetaddress'}, $borrower->{'city'}";
461 $line = "$borrower->{'categorycode'}";
462 if ($borrower->{'gonenoaddress'} == 1) {
463 $line = $line." </R>GNA<!R>";
465 if ($borrower->{'lost'} == 1) {
466 $line = $line." </R>LOST<!R>";
469 $line = $line." </R>ODUE<!R>";
471 if ($borrower->{'borrowernotes'} ne "" ) {
472 $line = $line." </R>NOTES<!R>";
474 if ($amountowing > 0) {
475 $line = $line." </B>\$$amountowing";
478 if ($borrower->{'borrowernotes'} ne "" ) {
479 $borrinfo[3]=substr($borrower->{'borrowernotes'},0,40);
481 my $borrbox = new Cdk::Label ('Message' =>\@borrinfo,
482 'Ypos'=>3, 'Xpos'=>"RIGHT");
487 my ($env,$title,$item,$items,$borrower,$amountowing,$odues,$dbh,$resp)=@_;
488 #debug_msg($env,$borrower);
489 my $titlepanel = titlepanel($env,"Returns","Scan Item");
490 my @functs=("Payments","Renewal");
491 my $funcmenu = new Cdk::Scroll ('Title'=>"",
492 'List'=>\@functs,'Height'=>5,'Width'=>12,'Ypos'=>3,'Xpos'=>16);
493 my $returnlist = new Cdk::Scroll ('Title'=>"Items Returned",
494 'List'=>\@$items,'Height'=> 12,'Width'=>74,'Ypos'=>10,'Xpos'=>1);
498 if ($borrower->{'cardnumber'} ne "") {
499 $borrbox = borrowerbox($env,$borrower,$amountowing);
505 $borrbox = new Cdk::Label ('Message' =>\@text, 'Ypos'=>3, 'Xpos'=>"RIGHT");
509 my $bookentry = new Cdk::Entry('Label'=>" ",
510 'Max'=>"11",'Width'=>"11",
511 'Xpos'=>"2",'Ypos'=>"3",'Title'=>"Item Barcode",
513 $bookentry->preProcess ('Function' =>sub{preretbook(@_,$env,$dbh,
514 $funcmenu,$bookentry,$borrower,$amountowing,
515 $odues,$titlepanel,$borrbox,$returnlist);});
516 my $barcode = $bookentry->activate();
518 if (!defined $barcode) {
523 if ($borrbox ne "") {$borrbox->erase();}
524 $returnlist->erase();
533 return($reason,$barcode);
537 my ($input,$env,$dbh,$funcmenu,$bookentry,$borrower,
538 $amountowing,$odues,$titlepanel,$borrbox,$returnlist)=@_;
539 if ($input eq $key_tab) {
540 actrfmenu($env,$dbh,$funcmenu,$bookentry,$borrower,
541 $amountowing,$odues,$titlepanel,$borrbox,$returnlist);
548 my ($env,$dbh,$funcmenu,$bookentry,$borrower,
549 $amountowing,$odues,$titlepanel,$borrbox,$returnlist)= @_;
550 my $funct = $funcmenu->activate();
551 #debug_msg($env,"funtion $funct");
552 if (!defined $funct) {
553 } elsif ($funct == 1 ) {
554 if ($borrower->{'borrowernumber'} ne "") {
557 $titlepanel->erase();
559 $returnlist->erase();
560 C4::Circulation::Renewals::bulkrenew($env,$dbh,
561 $borrower->{'borrowernumber'},$amountowing,$borrower,$odues);
562 Cdk::refreshCdkScreen();
569 } elsif ($funct == 0 ) {
570 if ($borrower->{'borrowernumber'} ne "") {
573 $titlepanel->erase();
575 $returnlist->erase();
576 C4::Accounts::reconcileaccount($env,$dbh,$borrower->{'borrowernumber'},
577 $amountowing,$borrower,$odues);
583 #Cdk::refreshCdkScreen();
590 my $ans = $obj->activate();
595 my ($env,$entry) = @_;
596 my $lastborr = $env->{"bcard"};
597 $entry->preProcess ('Function' => sub {preborr (@_, $env,$entry);});
601 my ($input,$env, $entry) = @_;
602 if ($env->{"bcard"} ne "") {
603 # error_msg($env,"hi there");
604 if ($input eq $lastval) {
605 # error_msg($env,"its a ctrl-r");
606 borfill($env,$entry);
615 my ($env,$entry) = @_;
616 error_msg($env,"in borfill: $env->{'bcard'}");
617 my $lastborr = $env->{"bcard"};
619 $entry->inject('Input'=>$lastborr);
621 # my $temp=substr($lastborr,$i,1);
622 # $entry->inject('Input'=>$temp);
628 END { } # module clean-up code here (global destructor)