Bug 2365 : Inner counter not properly set for serials subscriptions not starting...
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / serials / subscription-add.tmpl
1 <!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
2 <title>Koha &rsaquo; Serials &rsaquo; <!-- TMPL_IF name="mod" --> Modify subscription to <!-- TMPL_VAR name="bibliotitle" --><!-- TMPL_ELSE -->New subscription<!-- /TMPL_IF --></title>
3 <!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
4 <!-- TMPL_INCLUDE NAME="calendar.inc" -->
5
6 <script type="text/javascript">
7 <!--
8
9 // the english words used in display purposes
10 var text = new Array(_("Number"),_("Volume"),_("Issue"),_("Month"),_("Week"),_("Starting with:"),_("Rollover at:"),_("Choose Hemisphere:"),_("Northern"),_("Southern"),
11 _("Autumn"),_("Winter"),_("Spring"),_("Summer"),_("Fall"),_("Season"),_("Year"));
12 var weekno_label = _("Week # ");
13 var is_season = 0;
14 var is_hemisphere = 1;
15 var irregular_issues;   // will hold irregularity object.
16
17 function formatDate(myDate) {
18     var d = new Array( myDate.getFullYear(), myDate.getMonth() + 1 ,myDate.getDate());
19     if(d[1].toString().length == 1) { d[1] = '0'+d[1] };
20     if(d[2].toString().length == 1) { d[2] = '0'+d[2] };
21     <!-- TMPL_IF NAME="dateformat_us" -->
22         return(d[1] + '/' + d[2] + '/' + d[0]) ;
23     <!-- TMPL_ELSIF NAME="dateformat_metric" -->
24         return(d[2] + '/' + d[1] + '/' + d[0]) ;
25     <!-- TMPL_ELSE -->
26         return(''+d[0] + '-' + d[1] + '-' + d[2]) ;
27     <!-- /TMPL_IF -->    
28 }
29
30 Date.prototype.addDays = function(days) {
31     this.setDate(this.getDate()+days);
32 }
33
34 function getWeeksArray(startDate,periodicity) {
35 // returns an array of syspref-formatted dates starting at the first day of startDate's year.
36 // This prediction method will not accurately predict irregularites beyond the first year.
37 // FIXME : Should replace with ajax query to get the first Monday of the year so that week numbers have correct dates.
38     var incr=1;
39     if(periodicity==3) {  // 1/2 wks
40         incr=2;
41     } else if(periodicity == 4) { // 1/3 wks
42         incr=3;
43     }
44     var weeksArray = new Array;
45     var jan01 = new Date();
46     jan01.setDate(1);
47     jan01.setMonth(0);
48     jan01.setFullYear(startDate.getFullYear());
49     for(var i=0;i<52;i++) {
50         weeksArray[i] = formatDate(jan01) + ' ' + weekno_label + (i + 1);
51         jan01.addDays( 7 ); 
52     }
53     return weeksArray;
54 }
55
56 function YMDaToYWDa(S) {
57     with (new Date(Date.UTC(S[0], S[1] - 1, S[2]))) {
58         var DoW = getUTCDay();
59         setUTCDate(getUTCDate() - (DoW + 6) % 7 + 3);
60         var ms = valueOf();
61         setUTCMonth(0, 4);
62         var WN = Math.round((ms - valueOf()) / 604800000) + 1;
63         return [getUTCFullYear(), WN, DoW == 0 ? 7 : DoW];
64     }
65 }
66 function dayofyear(d) { // d is a Date object
67 var yn = d.getFullYear();
68 var mn = d.getMonth();
69 var dn = d.getDate();
70 var d1 = new Date(yn,0,1,12,0,0); // noon on Jan. 1
71 var d2 = new Date(yn,mn,dn,12,0,0); // noon on input date
72 var ddiff = Math.round((d2-d1)/864e5);
73 return ddiff+1;
74 }
75
76
77 // create irregularity object.
78 function IrregularPattern() {
79         this.months = new Array(_("January"),_("February"),_("March"),_("April"),_("May"),_("June"),_("July"),_("August"),_("September"),_("October"),_("November"),_("December"));
80         this.seasons = new Array(_("Autumn"),_("Winter"),_("Spring"),_("Summer"),_("Fall"));
81     this.daynames = new Array(_("Monday"),_("Tuesday"),_("Wednesday"),_("Thursday"),_("Friday"),_("Saturday"),_("Sunday"));
82     // create weeks irregularity selection array:
83     this.firstissue = new Date();
84     this.firstissue.setDate(1);
85     this.firstissue.setMonth(0);
86     <!-- TMPL_IF NAME='firstacquiyear' --> // it's a mod, we already have a start date.
87         this.firstissue.setFullYear( <!-- TMPL_VAR NAME="firstacquiyear" --> );
88     <!-- /TMPL_IF -->
89         this.weeks = getWeeksArray(this.firstissue); 
90
91     this.numskipped = 0;
92     // init:
93         var irregular = '<!-- TMPL_VAR NAME="irregularity" -->';
94     this.skipped = irregular.split(',');
95 }
96
97 IrregularPattern.prototype.update = function() {
98                 this.skipped= new Array;
99                 var cnt = 0;
100                 // daily periodicity, we interpret irregular array as which days of week to skip.
101                 // else if weekly periodicity, week numbers (starting from 01 Jan) to skip.
102         // else  irregular array is list of issues to skip
103                 var summary_str = '';
104                 this.numskipped = 0;
105         if(document.f.irregularity_select) {
106             for( var i in document.f.irregularity_select.options ) {
107                 if( document.f.irregularity_select.options[i].selected ) {
108                     this.skipped[cnt] = document.f.irregularity_select.options[i].value ;
109                     summary_str += document.f.irregularity_select.options[i].text + "\n" ;
110                                     cnt++;
111                                     this.numskipped++;
112                             }
113                     }
114                     var summary = document.getElementById("irregularity_summary");
115                     if(summary) {
116                             summary.value = summary_str;
117                             summary.rows= ( cnt > 6 ) ? cnt : 6 ; // textarea will bre resized, but not more than 6 lines will show.
118                     }
119         }
120 }
121
122 IrregularPattern.prototype.irregular = function(index) { 
123         for( var i in this.skipped) {
124                         if( this.skipped[i] == index) {
125                                 return true;
126                         }
127         }
128         return false;
129 }
130
131 function init_pattern() {
132         irregular_issues = new IrregularPattern();
133 }
134 function reset_pattern() {
135         document.getElementById("numberpattern").value = '';
136     document.getElementById("irregularity").innerHTML = '';
137         init_pattern();
138         reset_num_pattern();
139
140 }
141 // common pre defined number patterns
142 function reset_num_pattern() {
143 var patternchoice = document.getElementById("numberpattern").value;
144     switch(patternchoice){
145     case "2":
146         document.f.add1.value=1;
147         document.f.add2.value=1;
148         document.f.add3.value=1;
149         document.f.every1.value=12;
150         document.f.every2.value=1;
151         document.f.every3.value=1;
152         document.f.whenmorethan1.value=9999999;
153         document.f.whenmorethan2.value=12;
154         document.f.whenmorethan3.value=4;
155         document.f.setto1.value=0;
156         document.f.setto2.value=1;
157         document.f.setto3.value=1;
158         document.f.lastvalue1.value=1;
159         document.f.lastvalue2.value=1;
160         document.f.lastvalue3.value=1;
161         document.f.numberingmethod.value=_("Vol {X}, No {Y}, Issue {Z}");
162         moreoptions(text[1],text[0],text[2]);
163         display_table(0); // toggle info box on (1) or off (0)
164         break;
165     case "3":
166         document.f.add1.value=1;
167         document.f.add2.value=1;
168         document.f.add3.value='';
169         document.f.every1.value=12;
170         document.f.every2.value=1;
171         document.f.every3.value='';
172         document.f.whenmorethan1.value=9999999;
173         document.f.whenmorethan2.value=12;
174         document.f.whenmorethan3.value='';
175         document.f.setto1.value=0;
176         document.f.setto2.value=1;
177         document.f.setto3.value='';
178         document.f.lastvalue1.value=1;
179         document.f.lastvalue2.value=1;
180         document.f.lastvalue3.value='';
181         document.f.numberingmethod.value=_("Vol {X}, No {Y}");
182         moreoptions(text[1],text[0]);
183         display_table(0);
184         break;
185     case "4":
186         document.f.add1.value=1;
187         document.f.add2.value=1;
188         document.f.add3.value='';
189         document.f.every1.value=12;
190         document.f.every2.value=1;
191         document.f.every3.value='';
192         document.f.whenmorethan1.value=9999999;
193         document.f.whenmorethan2.value=12;
194         document.f.whenmorethan3.value='';
195         document.f.setto1.value=0;
196         document.f.setto2.value=1;
197         document.f.setto3.value='';
198         document.f.lastvalue1.value=1;
199         document.f.lastvalue2.value=1;
200         document.f.lastvalue3.value='';
201         document.f.numberingmethod.value=_("Vol {X}, Issue {Y}");
202         moreoptions(text[1],text[2]);
203         display_table(0);
204         break;
205     case "5":
206 //        var d = new Date(document.f.firstacquidate.value);
207 //        var smonth = d.getMonth();
208         document.f.add1.value=1;
209         document.f.add2.value=1;
210         document.f.add3.value='';
211         document.f.every1.value=12;
212         document.f.every2.value=1;
213         document.f.every3.value='';
214         document.f.whenmorethan1.value=9999999;
215         document.f.whenmorethan2.value=12;
216         document.f.whenmorethan3.value='';
217         document.f.setto1.value=0;
218         document.f.setto2.value=1;
219         document.f.setto3.value='';
220         document.f.numberingmethod.value=_("No {X}, Issue {Y}");
221         moreoptions(text[0],text[2]);
222         display_table(0);
223         break;
224     case "6":
225         var d = new Date(document.f.firstacquidate.value);
226         var sYear = d.getFullYear();
227         moreoptions_seasons(text[15],sYear);
228         var d = new Date(document.f.firstacquidate.value);
229         var sYear = d.getFullYear();
230         document.f.add1.value=1;
231         document.f.add2.value='1';
232         document.f.add3.value='';
233         document.f.every1.value=4;
234         document.f.every2.value='1';
235         document.f.every3.value='';
236         document.f.whenmorethan1.value=9999999;
237         document.f.whenmorethan2.value='4';
238         document.f.whenmorethan3.value='';
239         document.f.setto1.value=0;
240         document.f.setto2.value='1';
241         document.f.setto3.value='';
242         document.f.periodicity.value='8';
243         document.f.numberingmethod.value=_("{Y} {X}");
244         moreoptions_seasons(text[15],sYear);
245         document.f.lastvalue1temp.value=document.f.lastvalue1.value=sYear;
246         display_table(0);
247         is_season = 1;
248         break;
249     case "7":
250         display_table(1);
251         document.getElementById("more_options").innerHTML = '';
252         document.f.irreg_check.value=1; 
253         break;
254     case "8":  // Year/Number
255         var d = (document.f.firstacquidate.value) ? new Date( document.f.firstacquidate.value) : new Date() ;
256         var sYear = d.getFullYear();
257         document.f.add1.value=1;
258         document.f.add2.value=1;
259         document.f.add3.value='';
260         document.f.every1.value=12;
261         document.f.every2.value=1;
262         document.f.every3.value='';
263         document.f.whenmorethan1.value=9999999;
264         document.f.whenmorethan2.value=12;
265         document.f.whenmorethan3.value='';
266         document.f.setto1.value=0;
267         document.f.setto2.value=1;
268         document.f.setto3.value='';
269         document.f.lastvalue1.value=sYear;
270           switch (document.f.periodicity.value){
271             case 1:              
272               var doy = dayofyear(d);
273               document.f.lastvalue2.value=doy; 
274               document.f.whenmorethan2.value=365; 
275               break;      
276             case 12:     
277               var doy = dayofyear(d);
278               document.f.lastvalue2.value=doy*2; 
279               document.f.whenmorethan2.value=730; 
280               break;      
281             case 2:
282             case 3:
283             case 4:
284               var YWDa = YMDaToYWDa(d);
285               document.f.lastvalue2.value=YWDA[1]/(document.f.periodicity.value-1); 
286               break;      
287             case 5:
288               var smonth = d.getMonth();
289               document.f.lastvalue2.value=smonth;
290               break;      
291             case 6:
292               var smonth = d.getMonth();
293               document.f.lastvalue2.value=smonth/2;
294               document.f.whenmorethan2.value=6;
295               break;      
296             case 7:
297             case 8:      
298               var smonth = d.getMonth();
299               document.f.lastvalue2.value=smonth/3;
300               document.f.whenmorethan2.value=4;
301               break;      
302             case 9:                        
303               var smonth = d.getMonth();
304               document.f.lastvalue2.value=smonth/6;
305               document.f.whenmorethan2.value=2;
306               break;      
307             default:
308           } 
309         document.f.lastvalue3.value='';
310         document.f.numberingmethod.value=_("{X} / {Y}");
311         moreoptions(text[16],text[0]);
312      //   document.f.lastvalue1temp.value=sYear;
313      //   document.f.lastvalue2temp.value=document.f.lastvalue2.value;
314         display_table(0);
315         break;
316     default:
317         document.f.add1.value=1;
318         document.f.add2.value='';
319         document.f.add3.value='';
320         document.f.every1.value=1;
321         document.f.every2.value='';
322         document.f.every3.value='';
323         document.f.whenmorethan1.value=9999999;
324         document.f.whenmorethan2.value='';
325         document.f.whenmorethan3.value='';
326         document.f.setto1.value=0;
327         document.f.setto2.value='';
328         document.f.setto3.value='';
329         document.f.lastvalue1.value=1;
330         document.f.lastvalue2.value='';
331         document.f.lastvalue3.value='';
332         document.f.numberingmethod.value='{X}';
333 //        moreoptions_daily_check(text[0]);
334         moreoptions(text[0]);
335         document.f.irreg_check.value=1;
336         display_table(0);
337         break;
338     }
339 }
340
341 function display_table(n) {
342     if(n==1){
343         document.getElementById("basetable").style.display = 'block';
344     } else if(n==0){
345         document.getElementById("basetable").style.display = 'none';
346     } else {
347                 var disp_val = ( document.getElementById("basetable").style.display == 'none' ) ? 'block' : 'none' ;
348                         document.getElementById("basetable").style.display = disp_val;
349         }
350 }
351
352 function set_num_pattern_from_template_vars() {
353         if(!document.getElementById("numberpattern")){ return false; }
354     document.getElementById("numberpattern").value = '<!-- TMPL_VAR NAME="numberpattern" -->';
355     reset_num_pattern();
356     
357     document.f.add1.value='<!-- TMPL_VAR NAME="add1" -->';
358     document.f.add2.value='<!-- TMPL_VAR NAME="add2" -->';
359     document.f.add3.value='<!-- TMPL_VAR NAME="add3" -->';
360     document.f.every1.value='<!-- TMPL_VAR NAME="every1" -->';
361     document.f.every2.value='<!-- TMPL_VAR NAME="every2" -->';
362     document.f.every3.value='<!-- TMPL_VAR NAME="every3" -->';
363     document.f.whenmorethan1.value='<!-- TMPL_VAR NAME="whenmorethan1" -->';
364     document.f.whenmorethan2.value='<!-- TMPL_VAR NAME="whenmorethan2" -->';
365     document.f.whenmorethan3.value='<!-- TMPL_VAR NAME="whenmorethan3" -->';
366     document.f.setto1.value='<!-- TMPL_VAR NAME="setto1" -->';
367     document.f.setto2.value='<!-- TMPL_VAR NAME="setto2" -->';
368     document.f.setto3.value='<!-- TMPL_VAR NAME="setto3" -->';
369     document.f.lastvalue1.value='<!-- TMPL_VAR NAME="lastvalue1" -->';
370     document.f.lastvalue2.value='<!-- TMPL_VAR NAME="lastvalue2" -->';
371     document.f.lastvalue3.value='<!-- TMPL_VAR NAME="lastvalue3" -->';
372     document.f.numberingmethod.value='<!-- TMPL_VAR NAME="numberingmethod" -->';
373
374     var more_strY;
375     var more_strZ;
376     <!-- TMPL_IF NAME="add2" -->
377     if(<!-- TMPL_VAR NAME="add2" --> > 0){
378         more_strY="Y";
379     }
380     <!-- /TMPL_IF -->
381     <!-- TMPL_IF NAME="add3" -->
382     if(<!-- TMPL_VAR NAME="add3" --> > 0){
383         more_strZ="Z";
384     }
385     <!-- /TMPL_IF -->
386     document.f.lastvalue1temp.value='<!-- TMPL_VAR NAME="lastvalue1" -->';
387     if(more_strY){
388         document.f.lastvalue2temp.value='<!-- TMPL_VAR NAME="lastvalue2" -->';
389     document.f.whenmorethan2temp.value='<!-- TMPL_VAR NAME="whenmorethan2" -->';
390     }
391     if(more_strZ){
392         document.f.lastvalue3temp.value='<!-- TMPL_VAR NAME="lastvalue3" -->';
393     document.f.whenmorethan3temp.value='<!-- TMPL_VAR NAME="whenmorethan3" -->';
394     }
395 }
396
397 // a pre check with more options to see if 'number' and '1/day' are chosen
398 <!-- 
399 function moreoptions_daily_check(x) {
400     var periodicity = document.f.periodicity.value;
401     var errortext='';
402     if(periodicity == 1){ // i.e. daily
403         document.getElementById("irregularity").innerHTML = '';
404         errortext =_("Please indicate which days of the week you <b>DO NOT<\/b> expect to receive issues.<br \/>");
405         for(var j=0;j<irregular_issues.daynames.length;j++){
406             errortext +="<input type='checkbox' name='irregular' id='irregular"+(j+1)+"' value='"+(j+1)+"' />"+irregular_issues.daynames[j]+" &nbsp; ";
407         }
408         var error = errortext;
409         moreoptions(x);
410         document.getElementById("irregularity").innerHTML = error;
411     } else {
412         document.getElementById("irregularity").innerHTML = '';
413         document.getElementById("more_options").innerHTML = '';
414         moreoptions(x);
415     }
416 }
417 -->
418
419
420 // to dispaly the more options section
421 function moreoptions(x,y,z){
422 document.getElementById("irregularity").innerHTML = '';
423 document.getElementById("more_options").innerHTML = '';
424 var textbox = '';
425     // alert("X: "+x+"Y: "+y+"Z: "+z);
426     if(x){
427         textbox +="<table id='irregularity_table'>\n<tr><th>&nbsp;<\/th><th>"+x+"<\/th>";
428         if(y){
429             textbox +="<th>"+y+"<\/th>";
430             if(z){
431                 textbox +="<th>"+z+"<\/th>";
432             }
433         }
434         textbox +="<\/tr>\n";
435         textbox +="<tr><th scope=\"row\">"+text[5]+"<\/td><td><input type='text' name='lastvalue1temp' id='lastvalue1temp' size='4' onkeyup='moreoptionsupdate(this)' value=\"" + document.f.lastvalue1.value +  "\" /><\/td>\n";
436         if(y){
437             textbox +="<td><input type='text' name='lastvalue2temp' id='lastvalue2temp' size='4' onkeyup='moreoptionsupdate(this)' value=\"" + document.f.lastvalue2.value + "\" /><\/td>\n";
438             if(z){
439                 textbox +="<td><input type='text' name='lastvalue3temp' id='lastvalue3temp' size='4' onkeyup='moreoptionsupdate(this)' value=\"" + document.f.lastvalue3.value + "\" /><\/td>\n";
440             }
441         }
442         textbox +="<\/tr>\n";
443         if(y){
444             textbox +="<tr><th scope=\"row\">"+text[6]+"<\/th>";
445             textbox +="<td>&nbsp;<\/td>\n";
446             textbox +="<td><input type='text' name='whenmorethan2temp' id='whenmorethan2temp' size='4' onkeyup='moreoptionsupdate(this,1)'><\/td>\n";
447             if(z){
448                 textbox +="<td><input type='text' name='whenmorethan3temp' id='whenmorethan3temp' size='4' onkeyup='moreoptionsupdate(this,1)'><\/td>\n";
449             }
450             textbox +="<\/tr>";
451         } else {
452           textbox +="<tr> <td>"+_("issues expected")+"</td><td><input type='text' name='issuesexpected1temp' id='issuesexpected1temp' size='4' onkeyup='moreoptionsupdate(this,0)' value=\"" + document.f.issuesexpected1.value + "\" ></td></tr>";
453         }
454         textbox +="<\/table>\n";
455     }
456     document.getElementById("more_options").innerHTML = textbox;
457 }
458
459 function hemispheres(chosen){
460 var selbox = document.getElementById("season1");
461     if(selbox){
462     var selboxselected = selbox.options[selbox.selectedIndex].value;
463     selbox.options.length = 0;
464
465     if ( (chosen == "1") || ( ! (chosen) && is_hemisphere == 1 )) {
466         selbox.options[selbox.options.length] = new Option(text[11],'1');
467         selbox.options[selbox.options.length] = new Option(text[12],'2');
468         selbox.options[selbox.options.length] = new Option(text[13],'3');
469         selbox.options[selbox.options.length] = new Option(text[14],'4');
470         is_hemisphere = 1;
471         selbox.options[selboxselected-1].selected = true;
472     }
473
474     if ( (chosen == "2") || ( ! (chosen) && is_hemisphere == 2 )) {
475         selbox.options[selbox.options.length] = new Option(text[13],'1');
476         selbox.options[selbox.options.length] = new Option(text[10],'2');
477         selbox.options[selbox.options.length] = new Option(text[11],'3');
478         selbox.options[selbox.options.length] = new Option(text[12],'4');
479         is_hemisphere = 2;
480         selbox.options[selboxselected-1].selected = true;
481     }
482     }
483 }
484
485 // to display the more options section for seasons
486 function moreoptions_seasons(x,y){
487 // x = 'Season'.  y = 'Year'.
488 document.getElementById("irregularity").innerHTML = '';
489 document.getElementById("more_options").innerHTML = '';
490 var textbox = '';
491     //alert("X: "+x+"Year: "+y);
492     if(x){
493         var hemi_select = parseInt('<!-- TMPL_VAR NAME="hemisphere" -->');
494         textbox +="<li><label for=\"hemisphere\">"+ text[7]  +"<\/label><select name='hemisphere' id=\"hemisphere\" onchange='hemispheres(this.options[this.selectedIndex].value)'>";
495         for(var i = 1; i <= 2; i++){
496             textbox +="<option value='"+i+"'";
497             if(i == hemi_select){
498                 textbox += " selected "
499             }
500             textbox +=">"+text[i+7]+"<\/option>";
501         }
502         textbox +="<\/li>\n";
503         textbox +="<table id='seasonal_irregularity'><tr><th>&nbsp;<\/th><th>"+x+"<\/th>";
504         textbox +="<th>"+text[16]+"<\/th>";
505         textbox +="<\/tr>\n";
506         textbox +="<tr><th scope=\"row\">"+text[5]+"<\/th><td><select name='lastvalue2temp' id='lastvalue2temp' id='season1' onchange='moreoptionsupdate(this)'>";
507         for(var j = 1; j <= 4; j++){
508             textbox +="<option value='"+j+"'>"+text[j+9]+"<\/option>";
509         }
510         textbox +="<\/select><\/td>";
511         var isyr = irregular_issues.firstissue;
512         textbox += "<td>" + irregular_issues.firstissue.getFullYear() + "<\/td><\/tr>\n";
513         textbox +="<tr><th scope=\"row\">"+text[6]+"<\/th>";
514         textbox +="<td><input type='text' name='whenmorethan2temp' id='whenmorethan2temp' size='4' onkeyup='moreoptionsupdate(this,1)'><\/td>\n";
515                 textbox +="<\/tr><\/table>\n";
516
517     }
518     document.getElementById("more_options").innerHTML = textbox;
519 }
520
521 function irregularity_check(){
522     document.f.irreg_check.value = 1; // Irregularity button now pushed
523     var periodicity = document.f.periodicity.value;
524         var rollover = document.f.issuesexpected1.value;
525     if( (document.f.whenmorethan2) && ( document.f.whenmorethan2.value > 0) ){
526       rollover = document.f.whenmorethan2.value;
527     }
528     if((document.f.whenmorethan3) && document.f.whenmorethan3.value > 0 ){
529         // FIXME: Irregularity check assumes that the full prediction pattern repeats each year.
530                 //  In cases where the outermost periodicity is > 1 year,  
531                 //  e.g. where a volume spans two years, the irregularity check will be incorrect, 
532         // but you can safely ignore the check, submit the form, and the prediction pattern should be correct.
533                 //  a way to distinguish between these two cases is needed.
534                 rollover = document.f.whenmorethan3.value * document.f.whenmorethan2.value;
535     }
536     var error='';
537     var toobig;
538     var expected; 
539     var errortext = _("<b>Warning irregularity detected<\/b><br \/>");
540     switch(periodicity){
541     case "12":
542         if(rollover < 730) expected =730;
543         if(rollover > 730) {
544             expectedover=730;
545             toobig=1;
546         }
547         break;
548     case "1":
549         if(rollover < 365) expected =365;
550         if(rollover > 365) {
551             expectedover=365;
552             toobig=1;
553         }
554         break;
555     case "2":
556         if(rollover < 52) expected =52;
557         if(rollover > 52){
558             expectedover=52;
559             toobig=1;
560         }
561         break;
562     case "3":
563         if(rollover < 26) expected =26;
564         if(rollover > 26){
565             expectedover=26;
566             toobig=1;
567         }
568         break;
569     case "4":
570         if(rollover < 17) expected =17;
571         if(rollover > 17){
572             expectedover=17;
573             toobig=1;
574         }
575         break;
576     case "5":
577         if(rollover < 12) expected =12;
578         if(rollover > 12){
579             expectedover=12;
580             toobig=1;
581         }
582         break;
583     case "6":
584         if(rollover < 6) expected =6;
585         if(rollover > 6){
586             expectedover=6;
587             toobig=1;
588         }
589         break;
590     case "7":
591         if(rollover < 4) expected =4;
592         if(rollover > 4){
593             expectedover=4;
594             toobig=1;
595         }
596         break;
597     case "8":
598         if(rollover < 4) expected =4;
599         if(rollover > 4){
600             expectedover=4;
601             toobig=1;
602         }
603         break;
604     case "9":
605         if(rollover < 2) expected =2;
606         if(rollover > 2){
607             expectedover=2;
608             toobig=1;
609         }
610         break;
611     case "10":
612         if(rollover < 1) expected =1;
613         if(rollover > 1){
614             expectedover=1;
615             toobig=1;
616         }
617         break;
618     default:
619         break;
620     }
621     if(expected){
622         if(expected == 365 || expected==730){  // what about leap years ?
623                         // FIXME:  We interpret irregularity as which days per week for periodicity==1.
624                         //  We need two cases: one in which we're published n days/week, in which case irregularity should be per week,
625                         //  and a regular daily pub, where irregularity should be per year.
626             errortext += _("Please indicate which days of the week you <b>DO NOT<\/b> expect to receive issues.<br \/>");
627         } else {
628             errortext +=expected+_(" issues expected, ")+rollover+_(" were entered. <br \/>Please indicate which date(s) an issue is not expected<br \/>");
629             irregular_issues.numskipped = expected - rollover;
630                 }
631         errortext +="<select multiple id='irregularity_select' name='irregularity_select' onchange='irregular_issues.update();'>\n"; 
632                 errortext +=irregular_options(periodicity);
633                 errortext += "</select>\n <textarea rows='6' width='18' id='irregularity_summary' name='irregularity_summary' value='foo' />";
634         error=errortext;
635     }
636     if(toobig){
637         errortext +=expectedover+_(" issues expected, ")+rollover+_(" were entered.<p class='warning'> You seem to have indicated more issues per year than expected.</p>");
638         error=errortext;
639     }
640     if(error.length ==0){
641         error=_("No irregularities noticed");
642     }
643         display_example(expected);
644     document.getElementById("irregularity").innerHTML = error;
645         irregular_issues.update();
646 }
647
648 function irregular_options(periodicity){
649     var titles;
650     var count;
651     var errortext='';
652     if(periodicity == 1) {
653         expected = 7;
654         titles = irregular_issues.daynames;
655         count = 1;
656     }
657     if(periodicity == 2 || periodicity == 3 || periodicity == 4) { 
658         titles = irregular_issues.weeks;
659                 count = 1;
660         if(periodicity==3) {  // 1/2 wks
661             expected = 26;
662         } else if(periodicity == 4) { // 1/3 wks
663             expected = 17;
664         } else {
665             expected = 52;
666         }
667     }
668     if(periodicity == 5 || periodicity == 6 || periodicity == 7 || periodicity == 8 || periodicity == 9) {
669         if(periodicity == 8 && numberpattern==8) {
670             is_season = 1; // setting up from edit page
671         } 
672         if(is_season){
673             titles = irregular_issues.seasons;
674             expected = 4;
675             if(is_hemisphere == 2){
676                 count = 2;
677             } else {
678                 count = 1;
679             }
680         } else {
681             titles = irregular_issues.months;
682             expected = 12;
683             count = 1;
684         }
685     }
686         if( !expected) {
687                 return '';   // don't know how to deal with irregularity.
688         }       
689     for(var j=0;j<expected;j++){   // rch - changed frrom (1..expected).
690         if(isArray(titles)){
691             if(count>expected){
692                 count = count-expected;
693             }
694             if(is_season && is_hemisphere == 1){
695                 errortext +="<option value='"+((count*3)-2)+"'>"+titles[j]+"<\/option>\n";
696 // alert("value: "+((count*3)-2)+" title: "+titles[j]);
697             } else if(is_season && is_hemisphere == 2){
698                 errortext +="<option value='"+((count*3)-2)+"'>"+titles[j-1]+"<\/option>\n";
699 // alert("value: "+((count*3)-2)+" title: "+titles[j-1]);
700             } else {  // all non-seasonal periodicities:
701                 var incr=1; // multiplier for ( 1/n weeks)  patterns; in this case the irreg calc relies on the week# , not the issue#.
702                 if(periodicity==3) {  // 1/2 wks
703                     incr=2;
704                 } else if(periodicity == 4) { // 1/3 wks
705                     incr=3;
706                 }
707                 errortext += "<option value='" + (1+j*incr) ;  
708                                 if(irregular_issues.irregular(1+incr*j)) {
709                                         errortext += "' selected='selected" ;
710                                 }
711                                 errortext += "'>"+titles[incr*j]+"<\/option>\n";
712             }
713             count++;
714         } else { 
715             errortext +="<option value='"+j+"'>"+titles+" "+j+"<\/option>\n";
716         }
717     }
718     return errortext;
719 }
720
721
722 function display_example(expected){
723     var startfrom1 = parseInt(document.f.lastvalue1.value);
724     var startfrom2 = parseInt(document.f.lastvalue2.value);
725     var startfrom3 = parseInt(document.f.lastvalue3.value);
726     var every1 = parseInt(document.f.every1.value);
727     var every2 = parseInt(document.f.every2.value);
728     var every3 = parseInt(document.f.every3.value);
729     var numberpattern = document.f.numberingmethod.value;
730     var whenmorethan2 = parseInt(document.f.whenmorethan2.value);
731     var whenmorethan3 = parseInt(document.f.whenmorethan3.value);
732     var setto2 = parseInt(document.f.setto2.value);
733     var setto3 = parseInt(document.f.setto3.value);
734     var displaytext = _("Based on the information entered, the Numbering Pattern will look like this: <br \/><ul class=\"numpattern_preview\">");
735     if(startfrom3>0){
736         var count=startfrom3-1;
737         var count2=startfrom2;
738         for(var i = 0 ; i < 12; i++){
739             if(count>=whenmorethan3){
740                 count=setto3;
741                 if(count2>=whenmorethan2){
742                     startfrom1++;
743                     count2=setto2;
744                 } else {
745                     count2++;
746                 }
747             } else {
748                 count++;
749             }
750             displaytext += '<li>' + numberpattern.replace(/{Z}/,count) + '</li>\n';
751             displaytext = displaytext.replace(/{Y}/,count2);
752             displaytext = displaytext.replace(/{X}/,startfrom1);
753
754         }
755     }
756     if(startfrom2>0 && !startfrom3){
757         var count=startfrom2-1;
758         for(var i=0;i<12;i++){
759             if(count>=whenmorethan2){
760                 startfrom1++;
761                 count=setto2;
762             } else {
763                 count++;
764             }
765
766             if(is_season){
767                 if(is_hemisphere == 2){
768                     if(count == 1) {
769                         displaytext += numberpattern.replace(/{Y}/,text[count+12])+'\n';
770                     } else {
771                         displaytext += numberpattern.replace(/{Y}/,text[count+8])+'\n';
772                     }
773                 } else {
774                 displaytext += numberpattern.replace(/{Y}/,text[count+10])+'\n';
775                 }
776             } else {
777                 displaytext += numberpattern.replace(/{Y}/,count)+'\n';
778             }
779             displaytext = displaytext.replace(/{X}/,startfrom1)+'<br \/>\n';
780         }
781     }
782     if(startfrom1>0 && !startfrom2 && !startfrom3){
783         var offset=eval(document.f.issuesexpected1.value);
784         if (!offset){
785             offset = 12 
786         }
787         for(var i=startfrom1;i<(startfrom1+offset);i+=every1){
788             displaytext += numberpattern.replace(/{X}/,i)+'<br \/>\n';
789         }
790     }
791    //  displaytext = "<div style='padding: 5px; background-color: #CCCCCC'>"+displaytext+"<\/div>";
792     document.getElementById("displayexample").innerHTML = displaytext;
793 }
794
795 function isArray(obj) {
796 if (obj.constructor.toString().indexOf("Array") == -1)
797     return false;
798 else
799     return true;
800 }
801
802 function moreoptionsupdate(inputfield,rollover){
803     fieldname = inputfield.name;
804     // find parent element in base table by stripping 'temp' from element name.
805     basefield = document.getElementById(fieldname.slice(0,-4));
806     var fieldnumber = fieldname.slice(-5,-4);
807
808     basefield.value = inputfield.value;
809     if(basefield.name.slice(0,-1) == 'lastvalue') {
810         // lastvalue seems to mean 'begins with', tracking the first received issue so
811         // we can recreate the whole historeven after receiving.  innerloop is the var that
812         // actually tracks which issue we're on, though.
813         document.getElementById('innerloop'+fieldnumber).value = inputfield.value;
814     }
815     var patternchoice = document.getElementById("numberpattern").value;
816     switch(patternchoice){
817     case "2":
818     case "4":
819     case "5":
820     case "8": // Year, Number.  -- Why not just use Vol, Number withvol==year??
821        if (document.f.lastvalue2temp.value>0){document.f.innerloop1.value = document.f.lastvalue2temp.value - 1;}
822       break;   
823     }  
824     if(rollover){
825        // calculate rollover  for higher level of periodicity.
826        // if there are two levels of periodicity, (e.g. vol{X},num{Y},issue{Z}, then every1=every2*whenmorethan2 
827        // otherwise, every2 == 1.
828        var addN = (document.getElementById('add'+fieldnumber)) ? document.getElementById('add'+fieldnumber).value : 1 ;
829        var everyN = (document.getElementById('every'+fieldnumber)) ? document.getElementById('every'+fieldnumber).value : 1 ;
830        document.getElementById('every'+(fieldnumber-1)).value = basefield.value * everyN / addN ;
831      }
832      //FIXME : add checks for innerloop || lastvalue  > rollover  
833 }
834
835
836 function check_input(e){
837     var unicode=e.charCode? e.charCode : e.keyCode
838     if (unicode!=8 && unicode !=46 && unicode!=9 && unicode !=13){ // if key isn't backspace or delete
839         if (unicode<48||unicode>57) { // if not a number
840             alert(_("Needs to be entered in digit form -eg 10"));
841             return false // disable key press
842         }
843     }
844 }
845
846 function addbiblioPopup(biblionumber) {
847         var destination = "/cgi-bin/koha/cataloguing/addbiblio.pl?mode=popup";
848         if(biblionumber){ destination += "&biblionumber="+biblionumber; }
849  window.open(destination,'AddBiblioPopup','width=1024,height=768,toolbar=no,scrollbars=yes');
850 }
851
852 function Plugin(f)
853 {
854          window.open('subscription-bib-search.pl','FindABibIndex','width=800,height=400,toolbar=no,scrollbars=yes');
855 }
856
857 function FindAcqui(f)
858 {
859          window.open('acqui-search.pl','FindASupplier','width=800,height=400,toolbar=no,scrollbars=yes');
860 }
861
862 function Find_ISSN(f)
863 {
864          window.open('issn-search.pl','FindABibIndex','width=800,height=400,toolbar=no,scrollbars=yes');
865 }
866
867
868 function Check(f) {
869     if (f.aqbooksellerid.value.length==0) {
870         input_box = confirm(_("If you wish to claim late or missing issues you must link this subscription to a vendor. Click OK to ignore or Cancel to return and enter a vendor"));
871                 if (input_box==true) {
872                 }
873                 else {
874                         return false;
875                 }
876     }
877         if (f.biblionumber.value.length==0) {
878         alert(_("You must choose or create a biblio"));
879     } else if(f.startdate.value.length != 0 && f.sublength.value > 0) {
880         if (f.irreg_check.value == 1) {
881             document.f.submit();
882         } else {
883             if(f.numbering_pattern.value == ''){
884                 alert(_("Please choose a numbering pattern"));
885             } else {
886                 alert(_("Please check for irregularity by clicking 'Test Prediction Pattern'"));
887             }
888         }
889     } else {
890         alert(_("You must choose a start date and a subscription length"));
891     }
892         if(irregular_issues.numskipped < irregular_issues.skipped.length ) {
893                 alert(_("You have not accounted for all missing issues."));
894         }
895     return false;
896 }
897
898 $(document).ready(function() {
899 init_pattern();
900 <!-- TMPL_IF name="mod" -->
901     set_num_pattern_from_template_vars();
902     <!-- TMPL_IF name="hemisphere" -->
903         is_hemisphere = <!-- TMPL_VAR NAME="hemisphere" --> ;
904     hemispheres();
905     <!-- /TMPL_IF -->
906 <!-- /TMPL_IF -->
907 <!-- TMPL_IF name="irregularity" -->
908     irregularity_check();
909 <!-- /TMPL_IF -->
910 $('#numberpattern').change( function() { 
911     reset_num_pattern(); 
912     });
913 });
914 -->
915 </script>
916 </head>
917 <body>
918 <!-- TMPL_INCLUDE NAME="header.inc" -->
919 <!-- TMPL_INCLUDE NAME="serials-search.inc" -->
920
921 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/serials/serials-home.pl">Serials</a> &rsaquo; <!-- TMPL_IF name="mod" --> Modify subscription for <span class="title"><!-- TMPL_VAR name="bibliotitle" --></span><!-- TMPL_ELSE -->New subscription<!-- /TMPL_IF --></div>
922
923 <div id="doc3" class="yui-t7">
924    
925    <div id="bd">
926    <div class="yui-g">
927 <h1><!-- TMPL_IF name="mod" --> Modify subscription for <i><!-- TMPL_VAR name="bibliotitle" --></i><!-- TMPL_ELSE -->Add a new subscription<!-- /TMPL_IF --></h1>
928     <form method="post" name="f" action="/cgi-bin/koha/serials/subscription-add.pl">
929 <!-- TMPL_IF name="mod" -->
930         <input type="hidden" name="op" value="modsubscription" />
931         <input type="hidden" name="subscriptionid" value="<!-- TMPL_VAR name="subscriptionid" -->" />
932 <!-- TMPL_ELSE -->
933         <input type="hidden" name="op" value="addsubscription" />
934 <!-- /TMPL_IF -->
935 <input type="hidden" name="user" value="<!-- TMPL_VAR name="loggedinusername" -->" />
936 <input type="hidden" name="irreg_check" value="0" />
937 <input type="hidden" name="issuesexpected1" id="issuesexpected1" value="0" />
938
939         <div class="yui-u first">
940     <fieldset id="subscription_add_information" class="rows">
941         <legend>Subscription details</legend>
942         <ol>
943         <li><span class="label">Subscription #</span> <!--TMPL_VAR name="subscriptionid"--></li>
944         <li>
945             <span class="label">Librarian: </span>            <!-- TMPL_VAR name="loggedinusername" -->
946         </li>
947         <li>
948             <label for="aqbooksellerid">Vendor: </label>
949             <input type="text" name="aqbooksellerid" id="aqbooksellerid" value="<!-- TMPL_VAR name="aqbooksellerid" -->" size="8" /> (<input type="text" name="aqbooksellername" value="<!-- TMPL_VAR name="aqbooksellername" -->" disabled="disabled" readonly="readonly" />) <div class="inputnote"><a href="#" onclick="FindAcqui(f)">Search for a vendor</a></div>
950         </li>
951         <li>
952             <label for="biblionumber" class="required" title="Subscriptions must be associated with a bibliographic record">Biblio:</label>
953             
954                 <input type="text" name="biblionumber" id="biblionumber" value="<!-- TMPL_VAR name="bibnum" -->" size="8" /> 
955                 (<input type="text" name="title" value="<!-- TMPL_VAR name="bibliotitle" -->" disabled="disabled" readonly="readonly" />) <span class="required" title="Subscriptions must be associated with a bibliographic record">Required</span>
956                <div class="inputnote"> <a href="#" onclick="Plugin(f)">Search for Biblio</a> | <!--TMPL_IF Name="mod"--><a href="#" onclick="addbiblioPopup(<!-- TMPL_VAR NAME="bibnum" -->); return false;">Edit biblio</a><!-- TMPL_ELSE -->
957                 <a href="#" onclick="addbiblioPopup(); return false;">Create Biblio</a><!--/TMPL_IF--></div>
958             
959         </li>
960         <li class="radio">
961             <!-- TMPL_IF name="serialsadditems" -->
962                 <p><input type="radio" id="serialsadditems-yes" name="serialsadditems" value="1" checked="checked" /><label for="serialsadditems-yes">create an item record when receiving this serial</label></p>
963                 <p><input type="radio" id="serialsadditems-no" name="serialsadditems" value="0" /><label for="serialsadditems-no">do not create an item record when receiving this serial </label></p>
964             <!-- TMPL_ELSE -->
965                 <p><input type="radio" id="serialsadditems-yes" name="serialsadditems" value="1"/><label for="serialsadditems-yes">create an item record when receiving this serial</label></p>
966                 <p><input type="radio" id="serialsadditems-no" name="serialsadditems" value="0" checked="checked" /><label for="serialsadditems-no">do not create an item record when receiving this serial</label></p>
967             <!-- /TMPL_IF -->
968         </li>
969         <li>
970             <label for="callnumber">Call Number:</label>
971             <input type="text" name="callnumber" id="callnumber" value="<!-- TMPL_VAR name="callnumber" -->" size="20" />
972         </li>
973         <li>
974             <label for="branchcode">Library:</label>
975             
976                 <select name="branchcode" id="branchcode" style="width: 20em;">
977                     <!-- TMPL_UNLESS NAME="Independantbranches" --><option value="">None</option><!-- /TMPL_UNLESS -->
978                     <!-- TMPL_LOOP name="branchloop" --><!-- TMPL_IF NAME="selected" --><option value="<!-- TMPL_VAR NAME="value" -->" selected="selected"><!-- TMPL_VAR NAME="branchname" --></option>
979                                 <!-- TMPL_ELSE -->
980                                 <option value="<!-- TMPL_VAR NAME="value" -->"><!-- TMPL_VAR NAME="branchname" --></option>
981                                 <!-- /TMPL_IF -->
982                     <!-- /TMPL_LOOP -->
983                 </select> (select a library)
984             
985         </li>
986         <li>
987             <label for="notes">Public note:</label>
988             <textarea name="notes" id="notes" cols="30" rows="2"><!-- TMPL_VAR name="notes" --></textarea>
989         </li>
990         <li>
991             <label for="internalnotes">Nonpublic note:</label>
992             <textarea name="internalnotes" id="internalnotes" cols="30" rows="2"><!-- TMPL_VAR name="internalnotes" --></textarea>
993         </li>
994         <li>
995             <label for="letter">Patron notification: </label>
996             
997                <!-- TMPL_IF NAME="letterloop" -->
998                            <select name="letter" id="letter">
999                     <option value="">None</option>
1000                 <!-- TMPL_LOOP name="letterloop" -->
1001                                 <!-- TMPL_IF name="selected" -->
1002                     <option value="<!-- TMPL_VAR name="value" -->" selected="selected"><!-- TMPL_VAR name="lettername" --></option>
1003 <!-- TMPL_ELSE -->
1004                     <option value="<!-- TMPL_VAR name="value" -->"><!-- TMPL_VAR name="lettername" --></option>
1005 <!-- /TMPL_IF -->
1006                 <!-- /TMPL_LOOP -->
1007                 </select> 
1008                                 <div class="hint">Select a notice and patrons on the routing list will be notified when new issues are received.</div>
1009                 <!-- TMPL_ELSE -->
1010                                 <div class="hint">To notify patrons of new serial issues, you must <a href="/cgi-bin/koha/tools/letter.pl">define a notice</a>.</div>
1011                                 <!-- /TMPL_IF -->
1012         </li>
1013         </ol>
1014
1015             <div style="float:left;clear:left;margin:1em;"><strong>Note:</strong>
1016             
1017                 <ul>
1018                     <li>The subscription <strong>must</strong> be associated with a bibliographic record.</li>
1019                     <li>You <strong>must</strong> select a vendor if you wish to generate claims.</li>
1020                 </ul></div>
1021             
1022             
1023         </fieldset>
1024         </div>
1025         
1026 <div class="yui-u">
1027 <div id="subscription_form_planning">
1028         <fieldset class="rows">
1029         <legend>Serials planning</legend>
1030     <ol>
1031         <li>
1032            <label for="firstacquidate"> First issue publication date:</label>
1033                 <!-- TMPL_UNLESS NAME="mod" --><img src="<!-- TMPL_VAR Name="themelang" -->/lib/calendar/cal.gif" id="acqui_button" style="cursor: pointer;" alt="Show Calendar" title="Show Calendar" /><!-- /TMPL_UNLESS -->
1034                 <input type="text" name="firstacquidate" value="<!-- TMPL_VAR name="firstacquidate" -->"  size="13" maxlength="10" id="acqui_date" <!-- TMPL_IF NAME="mod" -->disabled="true"<!-- /TMPL_IF --> style="border-width: 0px;"  />
1035         </li>
1036            <!-- TMPL_IF NAME="mod" --><li><label for="nextacquidate"> Next issue publication date:</label>
1037                 <img src="<!-- TMPL_VAR Name="themelang" -->/lib/calendar/cal.gif" id="next_acqui_button" style="cursor: pointer;" alt="Show Calendar" title="Show Calendar" />
1038                 <input type="text" name="nextacquidate" value="<!-- TMPL_VAR name="nextacquidate" -->" size="13" maxlength="10" id="next_acqui_date" style="border-width: 0px;"  />
1039                 </li><!-- /TMPL_IF -->
1040                 <!-- both scripts for calendar must follow the input field --> 
1041                 <script type="text/javascript">
1042                     Calendar.setup({
1043                         inputField      :   "<!-- TMPL_IF NAME="mod" -->next_<!-- /TMPL_IF -->acqui_date",
1044                         ifFormat       :   "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
1045                         button         :   "<!-- TMPL_IF NAME="mod" -->next_<!-- /TMPL_IF -->acqui_button",
1046                         align          :   "Tl",
1047                         onUpdate        :    function(cal) { 
1048                                                              irregular_issues.weeks = getWeeksArray(cal.date);
1049                                                             irregular_issues.firstissue = cal.date;
1050                                                             if(document.irregularity_summary) {
1051                                                                 irregular_issues.update();
1052                                                             }
1053                                                             if(document.getElementById("seasonal_irregularity")) {
1054                                                                 moreoptions_seasons(text[15]);
1055                                                             }
1056                                                         } 
1057                         });
1058                     Calendar.setup({
1059                         inputField      :   "<!-- TMPL_IF NAME="mod" -->next_<!-- /TMPL_IF -->acqui_date",
1060                         ifFormat       :   "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
1061                         button         :   "<!-- TMPL_IF NAME="mod" -->next_<!-- /TMPL_IF -->acqui_date",
1062                         align          :   "Tl",
1063                         onUpdate        :    function(cal) { irregular_issues.weeks = getWeeksArray(cal.date);
1064                                                             irregular_issues.firstissue = cal.date;
1065                                                             if(document.irregularity_summary) {
1066                                                                 irregular_issues.update();
1067                                                             }
1068                                                             if(document.getElementById("seasonal_irregularity")) {
1069                                                                 moreoptions_seasons(text[15]);
1070                                                             }
1071                                                         } 
1072                         });
1073                 </script>
1074         <li>
1075             <label for="periodicity" class="required">Frequency:</label>
1076             
1077                 <select name="periodicity" size="1" id="periodicity" onchange="javascript:document.getElementsByName('manualhist')[0].checked=(this.value==1); reset_num_pattern();">
1078                 <option value="" selected="selected">-- please choose --</option>
1079                 <!-- TMPL_IF name="periodicity16" -->
1080                 <option value="16" selected="selected">Without periodicity</option>
1081                 <!-- TMPL_ELSE -->
1082                     <option value="16">Without periodicity</option>
1083                 <!-- /TMPL_IF -->
1084                 <!-- TMPL_IF name="periodicity48" -->
1085                 <option value="48" selected="selected">Unknown</option>
1086                 <!-- TMPL_ELSE -->
1087                 <option value="48">Unknown</option>
1088                 <!-- /TMPL_IF -->
1089                 <!-- TMPL_IF name="periodicity32" -->
1090                 <option value="32" selected="selected">Irregular</option>
1091                 <!-- TMPL_ELSE -->
1092                     <option value="32">Irregular</option>
1093                 <!-- /TMPL_IF -->
1094
1095                 <!-- TMPL_IF name="periodicity12" -->
1096                     <option value="12" selected="selected">2/day</option>
1097                 <!-- TMPL_ELSE -->
1098                     <option value="12">2/day</option>
1099                 <!-- /TMPL_IF -->
1100                 <!-- TMPL_IF name="periodicity1" -->
1101                     <option value="1" selected="selected">daily (n/week)</option>
1102                 <!-- TMPL_ELSE -->
1103                     <option value="1">daily (n/week)</option>
1104                 <!-- /TMPL_IF -->
1105                 <!-- TMPL_IF name="periodicity2" -->
1106                     <option value="2" selected="selected">1/week</option>
1107                 <!-- TMPL_ELSE -->
1108                     <option value="2">1/week</option>
1109                 <!-- /TMPL_IF -->
1110                 <!-- TMPL_IF name="periodicity3" -->
1111                     <option value="3" selected="selected">1/2 weeks </option>
1112                 <!-- TMPL_ELSE -->
1113                     <option value="3">1/2 weeks </option>
1114                 <!-- /TMPL_IF -->
1115                 <!-- TMPL_IF name="periodicity4" -->
1116                     <option value="4" selected="selected">1/3 weeks</option>
1117                 <!-- TMPL_ELSE -->
1118                     <option value="4">1/3 weeks</option>
1119                 <!-- /TMPL_IF -->
1120                 <!-- TMPL_IF name="periodicity5" -->
1121                     <option value="5" selected="selected">1/month</option>
1122                 <!-- TMPL_ELSE -->
1123                     <option value="5">1/month</option>
1124                 <!-- /TMPL_IF -->
1125                 <!-- TMPL_IF name="periodicity6" -->
1126                     <option value="6" selected="selected">1/2 months (6/year)</option>
1127                 <!-- TMPL_ELSE -->
1128                     <option value="6">1/2 months (6/year)</option>
1129                 <!-- /TMPL_IF -->
1130                 <!-- TMPL_IF name="periodicity7" -->
1131                     <option value="7" selected="selected">1/3 months (1/quarter)</option>
1132                 <!-- TMPL_ELSE -->
1133                     <option value="7">1/3 months (1/quarter)</option>
1134                 <!-- /TMPL_IF -->
1135                 <!-- periodicity8 is 1/quarter, exactly like periodicity7 but will use it for seasonal option -->
1136                 <!-- TMPL_IF name="periodicity8" -->
1137                     <option value="8" selected="selected">1/quarter (seasonal)</option>
1138                 <!-- TMPL_ELSE -->
1139                     <option value="8">1/quarter (seasonal)</option>
1140                 <!-- /TMPL_IF -->
1141
1142                 <!-- TMPL_IF name="periodicity9" -->
1143                     <option value="9" selected="selected">2/years</option>
1144                 <!-- TMPL_ELSE -->
1145                     <option value="9">2/year</option>
1146                 <!-- /TMPL_IF -->
1147                 <!-- TMPL_IF name="periodicity10" -->
1148                     <option value="10" selected="selected">1/year</option>
1149                 <!-- TMPL_ELSE -->
1150                     <option value="10">1/year</option>
1151                 <!-- /TMPL_IF -->
1152                 <!-- TMPL_IF name="periodicity11" -->
1153                     <option value="11" selected="selected">1/2 years</option>
1154                 <!-- TMPL_ELSE -->
1155                     <option value="11">1/2 years</option>
1156                 <!-- /TMPL_IF -->
1157                 </select> <span class="required">Required</span></li>
1158                                 <li><label for="manuallist"> Manual history:</label> <input type="checkbox" name="manualhist" id="manuallist" value="1" /></li>
1159         <li>
1160            <label for="numberpattern"> Numbering pattern:</label>
1161             
1162                 <select name="numbering_pattern" size="1" id="numberpattern" >
1163                     <option value="" selected="selected">-- please choose --</option>
1164                     <!-- TMPL_IF name="numberpattern1" -->
1165                         <option value="1" selected="selected">Number</option>
1166                     <!-- TMPL_ELSE -->
1167                         <option value="1">Number</option>
1168                     <!-- /TMPL_IF -->
1169                     <!-- TMPL_IF name="numberpattern2" -->
1170                         <option value="2" selected="selected">Volume, Number, Issue</option>
1171                     <!-- TMPL_ELSE -->
1172                         <option value="2">Volume, Number, Issue</option>
1173                     <!-- /TMPL_IF -->
1174                     <!-- TMPL_IF name="numberpattern3" -->
1175                         <option value="3" selected="selected">Volume, Number</option>
1176                     <!-- TMPL_ELSE -->
1177                         <option value="3">Volume, Number</option>
1178                     <!-- /TMPL_IF -->
1179                     <!-- TMPL_IF name="numberpattern4" -->
1180                         <option value="4" selected="selected">Volume, Issue</option>
1181                     <!-- TMPL_ELSE -->
1182                         <option value="4">Volume, Issue</option>
1183                     <!-- /TMPL_IF -->
1184                     <!-- TMPL_IF name="numberpattern5" -->
1185                         <option value="5" selected="selected">Number, Issue</option>
1186                     <!-- TMPL_ELSE -->
1187                         <option value="5">Number, Issue</option>
1188                     <!-- /TMPL_IF -->
1189                     <!-- TMPL_IF name="numberpattern6" -->
1190                         <option value="6" selected="selected">Seasonal only</option>
1191                     <!-- TMPL_ELSE -->
1192                         <option value="6">Seasonal only</option>
1193                     <!-- /TMPL_IF -->
1194                     <!-- TMPL_IF name="numberpattern8" -->
1195                         <option value="8" selected="selected">Year/Number</option>
1196                     <!-- TMPL_ELSE -->
1197                         <option value="8">Year/Number</option>
1198                     <!-- /TMPL_IF -->          
1199                     <!-- TMPL_IF name="numberpattern7" -->
1200                         <option value="7" selected="selected">None of the above</option>
1201                     <!-- TMPL_ELSE -->
1202                         <option value="7">None of the above</option>
1203                     <!-- /TMPL_IF -->
1204                 </select>
1205         </li>
1206                 <li id="more_options"></li>
1207                 <li id="irregularity"></li>
1208                    <li id="displayexample"></li>
1209         <li>
1210            <label for="startdate" class="required"> Subscription start date:</label>
1211             
1212                 <img src="<!-- TMPL_VAR Name="themelang" -->/lib/calendar/cal.gif" id="button1" style="cursor: pointer;" alt="Show Calendar" title="Show Calendar" />
1213                 <input type="text" name="startdate" value="<!-- TMPL_VAR name="startdate" -->" size="13" maxlength="10" id="beginning_date" style="border-width: 0px;" />
1214                 <!-- both scripts for calendar must follow the input field --> 
1215                 <script type="text/javascript">
1216                     Calendar.setup({
1217                         inputField   : "beginning_date",
1218                         ifFormat     : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
1219                         button       : "button1",
1220                         align        : "Tl"
1221                     });
1222                 </script>
1223                 <script type="text/javascript">
1224                     Calendar.setup({
1225                         inputField   : "beginning_date",
1226                         ifFormat     : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
1227                         button       : "beginning_date",
1228                         align        : "Tl"
1229                     });
1230                 </script>
1231             <span class="required">Required</span>
1232         </li>
1233         <li>
1234             <label for="subtype" class="required">Subscription length:</label>
1235             
1236                 <select name="subtype" id="subtype">
1237                     <!-- TMPL_LOOP NAME="subtype" -->
1238                         <!-- TMPL_IF NAME="selected" -->
1239                         <option value="<!-- TMPL_VAR NAME="name" -->" selected="selected">
1240                         <!-- TMPL_ELSE -->
1241                         <option value="<!-- TMPL_VAR NAME="name" -->">
1242                         <!-- /TMPL_IF -->
1243                         <!-- TMPL_VAR NAME="name" -->
1244                         </option>
1245                     <!-- /TMPL_LOOP -->
1246                 </select>
1247                 <input type="text" name="sublength" value="<!-- TMPL_VAR name="sublength" -->" size="3" onkeypress="return check_input(event)" /> (enter amount in numerals)
1248             <span class="required">Required</span>
1249         </li>
1250     <li><label for="numberingmethod">Numbering formula:</label> <input type="text" name="numberingmethod" id="numberingmethod" value="<!-- TMPL_VAR name="numberingmethod" -->" />
1251     </li>
1252     </ol>
1253         </fieldset>
1254 </div>
1255         <fieldset class="action">
1256         <input type="button" class="action_test" value="Test Prediction Pattern" onclick="javascript:irregularity_check()" />
1257         <input type="button" class="action_reset" value="Reset Pattern" onclick="javascript:reset_pattern()" />
1258     <input type="button" class="action_save"  value="Save subscription" onclick="Check(this.form)" accesskey="w" />
1259         </fieldset>
1260     <fieldset class="action">
1261     <input type="button" class="action_advanced" value="Show/Hide Advanced Pattern" onclick="javascript:display_table()" />
1262     </fieldset>
1263            <div id="basetable"  style="display: none;">
1264             <table class="small">
1265                 <tr><th colspan="4">Advanced Prediction Pattern</th></tr>
1266                                 <tr>
1267                     <th>&nbsp;</th>
1268                     <th>X</th>
1269                     <th>Y</th>
1270                     <th>Z</th>
1271                 </tr>
1272                 <tr>
1273                     <td>Add</td>
1274                     <td>
1275                         <input type="text" name="add1" id="add1" value="<!-- TMPL_VAR name="add1" -->" />
1276                     </td>
1277                     <td>
1278                         <input type="text" name="add2" id="add2" value="<!-- TMPL_VAR name="add2" -->" />
1279                     </td>
1280                     <td>
1281                         <input type="text" name="add3" id="add3" value="<!-- TMPL_VAR name="add3" -->" />
1282                     </td>
1283                 </tr>
1284                 <tr>
1285                     <td>once every</td>
1286                     <td><input type="text" name="every1" id="every1" value="<!-- TMPL_VAR name="every1" -->" /></td>
1287                     <td><input type="text" name="every2" id="every2" value="<!-- TMPL_VAR name="every2" -->" /></td>
1288                     <td><input type="text" name="every3" id="every3" value="<!-- TMPL_VAR name="every3" -->" /></td>
1289                 </tr>
1290                 <tr>
1291                     <td>When more than</td>
1292                     <td><input type="text" name="whenmorethan1" id="whenmorethan1" value="<!-- TMPL_VAR name="whenmorethan1" -->" /></td>
1293                     <td><input type="text" name="whenmorethan2" id="whenmorethan2" value="<!-- TMPL_VAR name="whenmorethan2" -->" /></td>
1294                     <td><input type="text" name="whenmorethan3" id="whenmorethan3" value="<!-- TMPL_VAR name="whenmorethan3" -->" /></td>
1295                 </tr>
1296                 <tr>
1297                     <td>inner counter</td>
1298                     <td><input type="text" name="innerloop1" id="innerloop1" value="<!-- TMPL_VAR name="innerloop1" -->" /></td>
1299                     <td><input type="text" name="innerloop2" id="innerloop2" value="<!-- TMPL_VAR name="innerloop2" -->" /></td>
1300                     <td><input type="text" name="innerloop3" id="innerloop3" value="<!-- TMPL_VAR name="innerloop3" -->" /></td>
1301                 </tr>
1302                 <tr>
1303                     <td>Set back to</td>
1304                     <td><input type="text" name="setto1" id="setto1" value="<!-- TMPL_VAR name="setto1" -->" /></td>
1305                     <td><input type="text" name="setto2" id="setto2" value="<!-- TMPL_VAR name="setto2" -->" /></td>
1306                     <td><input type="text" name="setto3" id="setto3" value="<!-- TMPL_VAR name="setto3" -->" /></td>
1307                 </tr>
1308                 <tr>
1309                     <td>
1310                         <!-- TMPL_IF name="mod" -->
1311                             Last value
1312                         <!-- TMPL_ELSE -->
1313                             Begins with
1314                         <!-- /TMPL_IF -->
1315                     </td>
1316                     <td><input type="text" name="lastvalue1" id="lastvalue1" value="<!-- TMPL_VAR name="lastvalue1" -->" /></td>
1317                     <td><input type="text" name="lastvalue2" id="lastvalue2" value="<!-- TMPL_VAR name="lastvalue2" -->" /></td>
1318                     <td><input type="text" name="lastvalue3" id="lastvalue3" value="<!-- TMPL_VAR name="lastvalue3" -->" /></td>
1319                 </tr>
1320             </table>
1321         </div>
1322
1323 </div>
1324
1325 </form>
1326 </div>
1327
1328 <!--TMPL_IF Name="history"-->
1329 <div id="subscription_form_history">
1330     <h2>Subscription history</h2>
1331     <form method="post" action="/cgi-bin/koha/serials/subscription-add.pl">
1332         <input type="hidden" name="op" value="modsubscription" />
1333         <input type="hidden" name="subscriptionid" value="<!-- TMPL_VAR name="subscriptionid" -->" />
1334         <input type="hidden" name="history_only" value="1" />
1335         <p>Hint : you can update the serial history manually. This can be useful for an old subscription or to clean the existing history. Modify these fields with care, as future serial receive will continue to update them automatically.</p>
1336         <table>
1337             <tr>
1338             <td>Subscription start date</td>
1339             <td><input type="text" name="histstartdate" value="<!-- TMPL_VAR name="histstartdate" -->" /> (start date of the 1st subscription)</td>
1340             </tr>
1341             <tr>
1342             <td>Subscription end date</td>
1343             <td><input type="text" name="histenddate" value="<!-- TMPL_VAR name="histenddate" -->" />(if empty, subscription is still active)</td>
1344             </tr>
1345             <tr>
1346                 <td>Received issues</td>
1347                 <td><textarea name="recievedlist" cols="60" rows="5"><!-- TMPL_VAR name="recievedlist" --></textarea></td>
1348             </tr>
1349             <tr>
1350                 <td>Missing issues</td>
1351                 <td><textarea name="missinglist" cols="60" rows="5"><!-- TMPL_VAR name="missinglist" --></textarea></td>
1352             </tr>
1353             <tr>
1354                 <td>Note for OPAC</td>
1355                 <td><textarea name="opacnote" cols="60" rows="5"><!-- TMPL_VAR name="opacnote" --></textarea></td>
1356             </tr>
1357             <tr>
1358                 <td>Note for staff</td>
1359                 <td><textarea name="librariannote" cols="60" rows="5"><!-- TMPL_VAR name="librariannote" --></textarea></td>
1360             </tr>
1361         </table>
1362     <input type="submit" value="Save subscription history"  />
1363     </form>
1364 </div>
1365 <!--/TMPL_IF-->
1366
1367 </div>
1368
1369 <!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->