View | Details | Raw Unified | Return to bug 30435
Collapse All | Expand All

(-)a/cataloguing/value_builder/macles.pl (-170 lines)
Lines 1-170 Link Here
1
#!/usr/bin/perl 
2
3
# Converted to new plugin style (Bug 13437)
4
5
# Copyright 2000-2002 Katipo Communications
6
#
7
# This file is part of Koha.
8
#
9
# Koha is free software; you can redistribute it and/or modify it
10
# under the terms of the GNU General Public License as published by
11
# the Free Software Foundation; either version 3 of the License, or
12
# (at your option) any later version.
13
#
14
# Koha is distributed in the hope that it will be useful, but
15
# WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
# GNU General Public License for more details.
18
#
19
# You should have received a copy of the GNU General Public License
20
# along with Koha; if not, see <http://www.gnu.org/licenses>.
21
22
use Modern::Perl;
23
use CGI qw ( -utf8 );
24
25
use C4::Context;
26
use C4::Output qw( output_html_with_http_headers );
27
use C4::Auth qw( get_template_and_user );
28
29
my $builder = sub {
30
    my ( $params ) = @_;
31
    my $function_name = $params->{id};
32
    my $res="
33
<script>
34
function Click$function_name(i) {
35
    newin=window.open(\"../cataloguing/plugin_launcher.pl?plugin_name=macles.pl&index=\"+i,\"MACLES\",',toolbar=false,scrollbars=yes');
36
}
37
</script>
38
";
39
    return $res;
40
};
41
42
my $launcher = sub {
43
    my ( $params ) = @_;
44
    my $input = $params->{cgi};
45
	my $index= $input->param('index');
46
47
	my $dbh = C4::Context->dbh;
48
    my $rq=$dbh->prepare("SELECT authorised_value, lib from authorised_values where category=\"MACLES\" order by authorised_value DESC");
49
    #tabs
50
    $rq->execute;
51
    my @BIGLOOP;
52
    my (%numbers,@lists,$table);
53
    while (my $tab = $rq->fetchrow_hashref){
54
      my $number=substr($tab->{authorised_value},0,1);
55
      if ($tab->{authorised_value}=~/[0-9]XX/){
56
        $numbers{$number}->{'hdr_tab'}=$tab->{lib};
57
        $numbers{$number}->{'Table'}=($number=~/[1-7]/);
58
      } elsif ($tab->{authorised_value}=~/.X./){
59
        $tab->{authorised_value}=~s/X/\./;
60
        $table=1;
61
        unshift @{$numbers{$number}->{"col_hdr"}},{"colvalue"=>$tab->{authorised_value},"collib"=>$tab->{lib}};
62
      } elsif ($tab->{authorised_value}=~/..X/){
63
        $tab->{authorised_value}=~s/X/\./;
64
        unshift @{$numbers{$number}->{"row_hdr"}},{"rowvalue"=>$tab->{authorised_value},"rowlib"=>$tab->{lib}}
65
      } elsif ($tab->{'authorised_value'}=~/,/){
66
        my @listval=split /,/,$tab->{'authorised_value'};
67
#          $tab->{authorised_value}=~s/,/","/g;
68
#         $tab->{authorised_value}="(".$tab->{authorised_value}.")";
69
        my %mulrows;
70
        foreach my $val (@listval){
71
          unshift @{$numbers{$number}->{$val}},$tab->{'lib'};
72
          my $mulrow=substr($val,0,2);
73
          $mulrows{$mulrow}=1;
74
        }
75
        foreach my $mulrow (sort keys %mulrows){
76
          unshift @{$numbers{$number}->{$mulrow}},{'listlib' => $tab->{'lib'},'listvalue' => $tab->{'authorised_value'}};
77
        }
78
      } else {
79
        unshift @{$numbers{$number}->{$tab->{'authorised_value'}}},$tab->{'lib'};
80
      }
81
    }
82
    foreach my $num ( sort keys %numbers ) {
83
        my @tmpcolhdr;
84
        my @tmprowhdr;
85
        @tmpcolhdr = @{ $numbers{$num}->{'col_hdr'} }
86
          if ( $numbers{$num}->{'col_hdr'} );
87
        @tmprowhdr = @{ $numbers{$num}->{"row_hdr"} }
88
          if ( $numbers{$num}->{'row_hdr'} );
89
        my @lines;
90
        my @lists;
91
        my %BIGLOOPcell;
92
        foreach my $row (@tmprowhdr) {
93
            my $tmprowvalue = $row->{rowvalue};
94
            my $rowcode;
95
            $rowcode = $1 if $tmprowvalue =~ /[0-9]([0-9])\./;
96
            my @cells;
97
            if ( scalar(@tmpcolhdr) > 0 ) {
98
99
                #cas du tableau bidim
100
                foreach my $col (@tmpcolhdr) {
101
                    my $tmpcolvalue = $col->{colvalue};
102
                    my $colcode;
103
                    $colcode = $1 if $tmpcolvalue =~ /[0-9]\.([0-9])/;
104
                    my %cell;
105
                    $cell{celvalue} = $num . $rowcode . $colcode;
106
                    $cell{rowvalue} = $tmprowvalue;
107
                    $cell{colvalue} = $tmpcolvalue;
108
                    if ( $numbers{$num}->{ $num . $rowcode . $colcode } ) {
109
110
                        foreach (
111
                            @{ $numbers{$num}->{ $num . $rowcode . $colcode } }
112
                          )
113
                        {
114
                            push @{ $cell{libs} }, { 'lib' => $_ };
115
                        }
116
                    }
117
                    else {
118
                        push @{ $cell{libs} },
119
                          { 'lib' => $num . $rowcode . $colcode };
120
                    }
121
                    push @cells, \%cell;
122
                }
123
                if ( $numbers{$num}->{ $num . $rowcode } ) {
124
                    my @tmpliblist = @{ $numbers{$num}->{ $num . $rowcode } };
125
                    push @lists,
126
                      { 'lib' => $row->{rowlib}, 'liblist' => \@tmpliblist };
127
                }
128
            }
129
            else {
130
131
                #Cas de la liste simple
132
                foreach my $key ( sort keys %{ $numbers{$num} } ) {
133
                    my %cell;
134
                    if ( $key =~ /$num$rowcode[0-9]/ ) {
135
                        $cell{celvalue} = $key;
136
                        foreach my $lib ( @{ $numbers{$num}->{$key} } ) {
137
                            push @{ $cell{'libs'} }, { 'lib' => $lib };
138
                        }
139
                        push @cells, \%cell;
140
                    }
141
                }
142
            }
143
            push @lines,
144
              {
145
                'cells'    => \@cells,
146
                'rowvalue' => $row->{rowvalue},
147
                'rowlib'   => $row->{rowlib}
148
              };
149
        }
150
        $BIGLOOPcell{'Lists'}   = \@lists     if ( scalar(@lists) > 0 );
151
        $BIGLOOPcell{'lines'}   = \@lines     if ( scalar(@lines) > 0 );
152
        $BIGLOOPcell{'col_hdr'} = \@tmpcolhdr if ( scalar(@tmpcolhdr) > 0 );
153
        $BIGLOOPcell{'Table'}   = $numbers{$num}->{'Table'};
154
        $BIGLOOPcell{'hdr_tab'} = $numbers{$num}->{'hdr_tab'};
155
        $BIGLOOPcell{'number'}  = $num;
156
        push @BIGLOOP, \%BIGLOOPcell;
157
    }
158
159
    my ($template, $loggedinuser, $cookie)
160
        = get_template_and_user({template_name => "cataloguing/value_builder/macles.tt",
161
                    query => $input,
162
                    type => "intranet",
163
                    flagsrequired => {editcatalogue => '*'},
164
                    });
165
    $template->param(BIGLOOP=>\@BIGLOOP);
166
	$template->param("index"=>$index);
167
	output_html_with_http_headers $input, $cookie, $template->output;
168
};
169
170
return { builder => $builder, launcher => $launcher };
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/macles.tt (-251 lines)
Lines 1-250 Link Here
1
<!DOCTYPE html PUBLIC "-//W3C//DTD Xhtml 1.0 Transitional//EN"
2
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
<html xmlns="http://www.w3.org/1999/xhtml">
4
<head>
5
<title>Gestion des index MACLES</title>
6
[% INCLUDE 'doc-head-close.inc' %]
7
<script>
8
//<![CDATA[
9
10
    $(document).ready(function() {
11
        $('#macles').tabs();
12
    });
13
//]]>
14
</script>
15
</head>
16
17
<body id="cat_macles" class="cat" onload="Activate(0);load_macles();" >
18
19
<h1>Gestion des index MACLES</h1>
20
<form name="f_pop" action="">
21
22
<div id="macles" class="toptabs numbered">
23
    [% IF ( BIGLOOP ) %]<ul>
24
    [% FOREACH BIGLOO IN BIGLOOP %]
25
        <li><a href="#tab[% BIGLOO.number | uri %]XX">[% BIGLOO.number | html %]</a></li>
26
    [% END %]
27
    </ul>[% END %]
28
    <!-- RESET PAGINATION -->
29
    [% FOREACH BIGLOO IN BIGLOOP %]
30
    [% IF ( BIGLOO.number ) %]
31
        <div id="tab[% BIGLOO.number | html %]XX">
32
    [% ELSE %]
33
        <div id="tab[% BIGLOO.number | html %]XX">
34
    [% END %]
35
            <h2> [% BIGLOO.hdr_tab | html %]</h2>
36
            <a href="#" class="button" onclick="add_macles('630');">Envoyer</a>
37
            <!-- <input type="submit" class="button" value="Envoyer" /> -->
38
            <a class="button" href="" onclick="load_macles(630);">R&eacute;initialiser</a>
39
            <a class="button" href="javascript:uncheck_tab([% BIGLOO.number | html %])">d&eacute;selectionner onglet</a>
40
            <input type="reset" class="button" value="déselectionner tout" />
41
            [% IF ( BIGLOO.Table ) %]
42
            <table>
43
                <tr>
44
                <th>Espace\Temps</th>
45
                [% FOREACH col_hd IN BIGLOO.col_hdr %]
46
                    <th scope="col" id="[% col_hd.colvalue | html %]">  [% col_hd.collib | html %] <br /><input type="checkbox" name="[% col_hd.colvalue | html %]" onclick="check_col('[% col_hd.colvalue | html %]')" />
47
                    </th>
48
                [% END %]
49
                </tr>
50
                [% FOREACH line IN BIGLOO.lines %]
51
                <tr>
52
                    <th scope="row" id="[% line.rowvalue | html %]">  [% line.rowlib | html %] <br /><input type="checkbox" name="[% line.rowvalue | html %]" onclick="check_row('[% line.rowvalue | html %]')" />
53
                    </th>
54
                    [% FOREACH cell IN line.cells %]
55
                    <td headers="[% cell.rowvalue | html %] [% cell.colvalue | html %]">
56
                    [% BLOCK spantitle %][% FOREACH lib IN cell.libs %][% lib.lib | html %] - [% END %][% END %]
57
                    <span title="[% INCLUDE spantitle %]">
58
                    [% cell.celvalue | html %] <br /><input type="checkbox" name="[% cell.celvalue | html %]" value="[% cell.celvalue | html %]" />
59
                    </span>
60
                    </td>
61
                    [% END %]
62
                </tr>
63
                [% END %]
64
            </table>
65
            [% END %]
66
            [% IF ( BIGLOO.Lists ) %]
67
            <h2>s&eacute;lection au moyen d'une liste de descripteurs</h2>
68
            [% FOREACH List IN BIGLOO.Lists %]
69
                <h3>[% List.lib | html %]</h3>
70
                [% FOREACH liblis IN List.liblist %]
71
                <a href="#[% liblis.listvalue | uri %]" onclick="check_multiple([% liblis.listvalue | html %])"> [% liblis.listlib | html %]</a><br />
72
                [% END %]
73
            [% END %]
74
            [% END %]
75
            [% UNLESS ( BIGLOO.Table ) %]
76
            <!-- Listes simples :Onglets 0 et 9-->
77
            [% FOREACH line IN BIGLOO.lines %]
78
                <h3>[% line.rowvalue | html %]&nbsp;-&nbsp;[% line.rowlib | html %]&nbsp;<input type="checkbox" name="[% line.rowvalue | html %]" onclick="check_row('[% line.rowvalue | html %]')" /></h3>
79
                [% FOREACH cell IN line.cells %]
80
                <p>[% cell.celvalue | html %]&nbsp;-&nbsp;[% FOREACH lib IN cell.libs %]
81
                        [% lib.lib | html %] &nbsp;
82
                    [% END %]
83
                    <input type="checkbox" name="[% cell.celvalue | html %]" value="[% cell.celvalue | html %]" />
84
                </p>
85
                [% END %]
86
            [% END %]
87
            [% END %]
88
        </div>
89
    [% END %]
90
</div>
91
</form>
92
<script>
93
//<![CDATA[
94
function Activate(numlayer)
95
{
96
	for (var i=0; i <= 9 ; i++ ) {
97
		var ong = i+"XX";
98
		var link = "link"+i;
99
		if (numlayer==i) {
100
			with(document){
101
			if (document.getElementById(ong)){
102
				document.getElementById(ong).style.visibility="visible";
103
			}
104
			if(document.getElementById(link)){
105
				document.getElementById(link).style.color="#000066";
106
				document.getElementById(link).style.backgroundColor="#FFFFCC";
107
			}
108
			}
109
		} else {
110
			with(document){
111
			if (document.getElementById(ong)){
112
				document.getElementById(ong).style.visibility="hidden";
113
			}
114
			if (document.getElementById(link)) {
115
				document.getElementById(link).style.color="#669999";
116
				document.getElementById(link).style.backgroundColor="#D8DEB8";
117
			}
118
			}
119
		}
120
	}
121
}
122
123
function add_macles(myvalue)
124
{
125
  var myinputs=document.getElementsByTagName("input");
126
  var mycountMACLESgen=0;
127
  var tab = new Array();
128
  for (var i=0;i<myinputs.length;i++){
129
    if (myinputs[i].checked) {
130
      tab[mycountMACLESgen]=myinputs[i].value;
131
      mycountMACLESgen++;
132
    }
133
  }
134
  if (mycountMACLESgen==1){opener.document.f.[% index | html %].value = tab[0];
135
  } else {
136
    var mytags=opener.document.getElementsByTagName("input");
137
    var index_string="[% index | html %]";
138
    index_string=index_string.substr(0,index_string.lastIndexOf("_"));  
139
    index_string=index_string.substr(0,index_string.lastIndexOf("_"));
140
    index_string=index_string+".*";    
141
    var mycountMACLESinit=0;
142
    var indexmin=0;
143
    var tab_ids_fields=new Array();  
144
    //Compter le nombre de MACLES present
145
    for (i=0;i<mytags.length;i++){
146
      if (mytags[i].name.match(index_string)){
147
        if (mytags[i].value==myvalue) {
148
            if (indexmin==0){
149
                indexmin=i
150
            }
151
        }
152
        tab_ids_fields[mycountMACLESinit]=mytags[i].getAttribute("id");
153
        mycountMACLESinit++;
154
      }   
155
    }
156
    // Si Nombre de Macles <Nombre de cases cochees, ajouter le nombre de champ manquant
157
    if (mycountMACLESinit < mycountMACLESgen){
158
    //for (i=0;i< (mycountMACLESgen - mycountMACLESinit);i++){
159
    //  PluginAddField(myvalue);
160
    //}
161
      alert(_("veuillez d'abord creer le nombre de champs necessaires "));
162
    } else {
163
    // Pour chaque valeur cochee, ajouter la valeur dans un noeud MACLES.
164
      for (i=0;i<tab.length;i++){
165
          // Se positionner sur le prochain noeud MACLES
166
          opener.document.f.elements[tab_ids_fields[i]].value = tab[i];
167
      }
168
    }
169
  }
170
  window.close();
171
  return false;
172
}
173
174
function uncheck_tab(number)
175
{
176
  var myinputs=document.getElementsByTagName("input");
177
  var myRegEx=new RegExp(number+"..");
178
  for(i=0;i<myinputs.length;i++){
179
    if ((myinputs[i].name.search(myRegEx)>=0) && myinputs[i].checked == true) {
180
      myinputs[i].checked = false;
181
    }
182
  }
183
}
184
function check_col(col)
185
{
186
  var myref=document.getElementsByName(col);
187
  var myinputs=document.getElementsByTagName("input");
188
  var myRegEx=new RegExp(col);
189
  for(i=0;i<myinputs.length;i++){
190
    if (myinputs[i].name.search(myRegEx)>=0) {
191
      if (myref[0].checked){
192
        myinputs[i].checked = true;
193
      } else {
194
        myinputs[i].checked = false;
195
      }
196
    } 
197
  }
198
  return false;
199
}
200
201
function check_multiple()
202
{
203
  for(myi=0;myi<check_multiple.arguments.length;myi++){
204
    var myinput=document.getElementsByName(""+check_multiple.arguments[myi]);
205
    myinput[0].checked=true;
206
  }
207
  return false;
208
}
209
210
function check_row(row)
211
{
212
  var myref=document.getElementsByName(row);
213
  var myinputs=document.getElementsByTagName("input");
214
  var myRegEx=new RegExp(row);
215
//   alert myRegEx;
216
  for(i=0;i<myinputs.length;i++){
217
    if (myinputs[i].name.search(myRegEx)>=0){
218
      if (myref[0].checked){
219
        myinputs[i].checked = true;
220
      } else {
221
        myinputs[i].checked = false;
222
      }
223
    } 
224
  }
225
  return false;
226
}
227
228
function load_macles()
229
{
230
  document.forms.f_pop.reset;
231
  var mystart="[% index | html %]";
232
  mystart=mystart.substr(0,mystart.lastIndexOf("_"));  
233
  mystart=mystart.substr(0,mystart.lastIndexOf("_"));
234
  mystart=mystart+".*";    
235
  var mytags=opener.document.getElementsByTagName("input");
236
  for (i=0;i<mytags.length;i++){
237
    if (mytags[i].name.match(mystart)){
238
      var checkvalue=mytags[i].value;
239
      var myinput=document.getElementsByName(checkvalue);
240
      if (myinput.length>0){
241
        myinput[0].checked=true;
242
      }
243
    }  
244
  } 
245
  return false;
246
}
247
//]]>
248
</script>
249
</body>
250
</html>
251
- 

Return to bug 30435