Adding macle_plugin for FRANTIQ

This commit is contained in:
hdl 2007-07-10 08:48:54 +00:00
parent eef937a824
commit 7494188760
2 changed files with 433 additions and 0 deletions

View file

@ -0,0 +1,186 @@
#!/usr/bin/perl
# $Id$
# Copyright 2000-2002 Katipo Communications
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307 USA
use strict;
use CGI;
use C4::Context;
use C4::Output;
use C4::Auth;
# use Data::Dumper;
use vars qw( $tagslib);
use vars qw( $authorised_values_sth);
use vars qw( $is_a_modif );
use utf8;
=head1
plugin_parameters : other parameters added when the plugin is called by the dopop function
=cut
sub plugin_parameters {
my ($dbh,$record,$tagslib,$i,$tabloop) = @_;
return "";
}
sub plugin_javascript {
my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
my $function_name= "macles".(int(rand(100000))+1);
my $res="
<script>
function Focus$function_name(subfield_managed) {
return 1;
}
function Blur$function_name(subfield_managed) {
return 1;
}
function Clic$function_name(i) {
newin=window.open(\"plugin_launcher.pl?plugin_name=macles.pl&index=\"+i,\"MACLES\",',toolbar=false,scrollbars=yes');
}
</script>
";
return ($function_name,$res);
}
sub plugin {
my ($input) = @_;
my %env;
# my $input = new CGI;
my $index= $input->param('index');
my $dbh = C4::Context->dbh;
my $rq=$dbh->prepare("SELECT authorised_value, lib from authorised_values where category=\"MACLES\" order by authorised_value DESC");
#tabs
$rq->execute;
my @BIGLOOP;
my @innerloop;
my (%numbers,%cells,@colhdr,@rowhdr,@multiplelines,@lists,$table);
while (my $tab = $rq->fetchrow_hashref){
# if (! utf8::is_utf8($tab->{lib})) {
# utf8::decode($tab->{lib});
# }
# warn $tab->{lib};
my $number=substr($tab->{authorised_value},0,1);
if ($tab->{authorised_value}=~/[0-9]XX/){
$numbers{$number}->{'hdr_tab'}=$tab->{lib};
$numbers{$number}->{'Table'}=($number=~/[1-7]/);
} elsif ($tab->{authorised_value}=~/.X./){
$tab->{authorised_value}=~s/X/\./;
$table=1;
unshift @{$numbers{$number}->{"col_hdr"}},{"colvalue"=>$tab->{authorised_value},"collib"=>$tab->{lib}};
} elsif ($tab->{authorised_value}=~/..X/){
$tab->{authorised_value}=~s/X/\./;
unshift @{$numbers{$number}->{"row_hdr"}},{"rowvalue"=>$tab->{authorised_value},"rowlib"=>$tab->{lib}}
} elsif ($tab->{'authorised_value'}=~/,/){
my @listval=split /,/,$tab->{'authorised_value'};
# $tab->{authorised_value}=~s/,/","/g;
# $tab->{authorised_value}="(".$tab->{authorised_value}.")";
my %mulrows;
foreach my $val (@listval){
unshift @{$numbers{$number}->{$val}},$tab->{'lib'};
my $mulrow=substr($val,0,2);
$mulrows{$mulrow}=1;
}
foreach my $mulrow (sort keys %mulrows){
unshift @{$numbers{$number}->{$mulrow}},{'listlib' => $tab->{'lib'},'listvalue' => $tab->{'authorised_value'}};
}
} else {
unshift @{$numbers{$number}->{$tab->{'authorised_value'}}},$tab->{'lib'};
}
# use Data::Dumper;warn "BIGLOOP IN".Dumper(@BIGLOOP);
}
foreach my $num (sort keys %numbers){
my @tmpcolhdr = @{$numbers{$num}->{'col_hdr'}} if ($numbers{$num}->{'col_hdr'});
my @tmprowhdr = @{$numbers{$num}->{"row_hdr"}} if ($numbers{$num}->{'row_hdr'});
my @lines;
my @lists;
my %BIGLOOPcell;
foreach my $row (@tmprowhdr){
my $tmprowvalue=$row->{rowvalue};
my $rowcode=$1 if $tmprowvalue=~/[0-9]([0-9])\./;
my @cells;
if (scalar(@tmpcolhdr)>0){
#cas du tableau bidim
foreach my $col (@tmpcolhdr){
my $tmpcolvalue=$col->{colvalue};
my $colcode=$1 if $tmpcolvalue=~/[0-9]\.([0-9])/;
my %cell;
$cell{celvalue}=$num.$rowcode.$colcode;
$cell{rowvalue}=$tmprowvalue;
$cell{colvalue}=$tmpcolvalue;
if ($numbers{$num}->{$num.$rowcode.$colcode}){
foreach (@{$numbers{$num}->{$num.$rowcode.$colcode}}){
push @{$cell{libs}},{'lib'=>$_};
}
}else {
push @{$cell{libs}},{'lib'=>$num.$rowcode.$colcode};
}
push @cells,\%cell;
}
if ($numbers{$num}->{$num.$rowcode}){
my @tmpliblist=@{$numbers{$num}->{$num.$rowcode}};
push @lists,{'lib'=>$row->{rowlib},'liblist'=>\@tmpliblist};
}
} else {
#Cas de la liste simple
foreach my $key (sort keys %{$numbers{$num}}){
my %cell;
if ($key=~/$num$rowcode[0-9]/){
$cell{celvalue}=$key;
foreach my $lib (@{$numbers{$num}->{$key}}){
push @{$cell{'libs'}},{'lib'=>$lib};
}
push @cells,\%cell;
}
}
}
push @lines,{'cells'=>\@cells,'rowvalue'=>$row->{rowvalue},'rowlib'=>$row->{rowlib}};
}
$BIGLOOPcell{'Lists'}=\@lists if (scalar(@lists)>0);
$BIGLOOPcell{'lines'}=\@lines if (scalar(@lines)>0);
$BIGLOOPcell{'col_hdr'}=\@tmpcolhdr if (scalar(@tmpcolhdr)>0);
$BIGLOOPcell{'Table'}=$numbers{$num}->{'Table'};
$BIGLOOPcell{'hdr_tab'}=$numbers{$num}->{'hdr_tab'};
$BIGLOOPcell{'number'}=$num;
push @BIGLOOP,\%BIGLOOPcell;
}
# warn "BIGLOOP OUT".Dumper(@BIGLOOP);
my ($template, $loggedinuser, $cookie)
= get_template_and_user({template_name => "cataloguing/value_builder/macles.tmpl",
query => $input,
type => "intranet",
authnotrequired => 0,
flagsrequired => {editcatalogue => 1},
debug => 1,
});
$template->param(BIGLOOP=>\@BIGLOOP);
$template->param("index"=>$index);
output_html_with_http_headers $input, $cookie, $template->output;
}
1;

View file

@ -0,0 +1,247 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html>
<head>
<title>Gestion_des_index_MACLES</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="<!-- TMPL_VAR name="themelang" -->/includes/common-style.css">
<link rel="stylesheet" type="text/css" href="<!-- TMPL_VAR name="themelang" -->/includes/marc-editor.css">
</head>
<body onload="javascript:Activate(0);load_macles(630);">
<h1 class="catalogue">Gestion des index MACLES</h1>
<form name="f_pop"> <!-- onSubmit="javascript:add_macles('630');"> -->
<div class="tabbed">
<div class="tabs">
<!--TMPL_LOOP name="BIGLOOP" -->
<a href="#" onclick="javascript:Activate('<!-- TMPL_VAR name="number"-->'); return false;" id="link<!-- TMPL_VAR name="number"-->"><!-- TMPL_VAR name="number"--></a>
<!--/TMPL_LOOP -->
</div>
<!-- RESET PAGINATION -->
<!-- TMPL_LOOP name="BIGLOOP" -->
<!-- hide every tab except the 1st -->
<!-- TMPL_IF name="number" -->
<div name="<!-- TMPL_VAR name="number" -->XX" id="<!-- TMPL_VAR name="number" -->XX" class="tab" style="visibility:hidden">
<!-- TMPL_ELSE -->
<div name="<!-- TMPL_VAR name="number" -->XX" id="<!-- TMPL_VAR name="number" -->XX" class="tab" style="visibility:visible">
<!-- /TMPL_IF -->
<h2 class="catalogue"> <!--TMPL_VAR Name="hdr_tab"--></h2>
<a href="#" class="button catalogue" onclick="JavaScript:add_macles('630');">Envoyer</a>
<!-- <input type="submit" class="button catalogue" value="Envoyer" /> -->
<a class="button catalogue" href="" onclick="javascript:load_macles(630);">R&eacute;initialiser</a>
<a class="button catalogue" href="javascript:uncheck_tab(<!-- TMPL_VAR name="number" -->)">d&eacute;selectionner onglet</a>
<input type="reset" class="button catalogue" value="d&eacute;selectionner tout" />
<!--TMPL_IF Name="Table"-->
<table>
<tr>
<th class="catalogue">Espace\Temps</th>
<!--TMPL_LOOP Name="col_hdr"-->
<th class="catalogue" scope="col" id="<!--TMPL_VAR Name="colvalue"-->"> <!--TMPL_VAR Name="collib" ESCAPE=HTML--> <br /><input type="checkbox" name="<!--TMPL_VAR Name="colvalue"-->" OnClick="check_col('<!--TMPL_VAR Name="colvalue"-->')" />
</th>
<!--/TMPL_LOOP-->
</tr>
<!--TMPL_LOOP Name="lines"-->
<tr>
<th class="catalogue" scope="row" id="<!--TMPL_VAR Name="rowvalue"-->"> <!--TMPL_VAR Name="rowlib" ESCAPE=HTML--> <br /><input type="checkbox" name="<!--TMPL_VAR Name="rowvalue"-->" OnClick="check_row('<!--TMPL_VAR Name="rowvalue"-->')" />
</th>
<!--TMPL_LOOP Name="cells"-->
<td headers="<!--TMPL_VAR Name="rowvalue"--> <!--TMPL_VAR Name="colvalue"-->">
<span TITLE="<!--TMPL_LOOP Name="libs" --><!--TMPL_VAR Name="lib" ESCAPE=HTML--> - <!--/TMPL_LOOP-->">
<!--TMPL_VAR Name="celvalue"--> <br /><input type="checkbox" name="<!--TMPL_VAR Name="celvalue"-->" value="<!--TMPL_VAR Name="celvalue"-->" />
</span>
</td>
<!--/TMPL_LOOP-->
</tr>
<!--/TMPL_LOOP-->
</table>
<!--/TMPL_IF-->
<!--TMPL_IF Name="Lists" -->
<h2 class="catalogue">s&eacute;lection au moyen d'une liste de descripteurs</h2>
<!--TMPL_LOOP name="Lists"-->
<h3 class="catalogue"><!--TMPL_VAR name="lib"--></h3>
<!--TMPL_LOOP name=liblist -->
<a href="#<!--TMPL_VAR Name="listvalue"-->" onclick="javascript:check_multiple(<!--TMPL_VAR Name="listvalue"-->)"> <!--TMPL_VAR name="listlib" escape=html--></a><br />
<!--/TMPL_LOOP-->
<!--/TMPL_LOOP-->
<!--/TMPL_IF-->
<!--TMPL_UNLESS Name="Table"-->
<!-- Listes simples :Onglets 0 et 9-->
<!--TMPL_LOOP Name="lines"-->
<h3><!--TMPL_VAR Name="rowvalue" ESCAPE=HTML-->&nbsp;-&nbsp;<!--TMPL_VAR Name="rowlib" ESCAPE=HTML-->&nbsp;<input type="checkbox" name="<!--TMPL_VAR Name="rowvalue"-->" OnClick="javascript:check_row('<!--TMPL_VAR Name="rowvalue"-->')" /></h3>
<!--TMPL_LOOP Name="cells"-->
<p><!--TMPL_VAR Name="celvalue" ESCAPE=HTML-->&nbsp;-&nbsp;<!--TMPL_LOOP Name="libs" -->
<!--TMPL_VAR Name="lib" ESCAPE=HTML--> &nbsp;
<!--/TMPL_LOOP-->
<input type="checkbox" name="<!--TMPL_VAR Name="celvalue"-->" value="<!--TMPL_VAR Name="celvalue"-->" />
</p>
<!--/TMPL_LOOP-->
<!--/TMPL_LOOP-->
<!--/TMPL_UNLESS-->
</div>
<!-- /TMPL_LOOP -->
</div>
</form>
<script language="JavaScript" type="text/javascript">
function Activate(numlayer)
{
for (var i=0; i <= 9 ; i++ ) {
var ong = i+"XX";
var link = "link"+i;
if (numlayer==i) {
with(document){
if (document.getElementById(ong)){
document.getElementById(ong).style.visibility="visible";
}
if(document.getElementById(link)){
document.getElementById(link).style.color="#000066";
document.getElementById(link).style.backgroundColor="#FFFFCC";
}
}
} else {
with(document){
if (document.getElementById(ong)){
document.getElementById(ong).style.visibility="hidden";
}
if (document.getElementById(link)) {
document.getElementById(link).style.color="#669999";
document.getElementById(link).style.backgroundColor="#D8DEB8";
}
}
}
}
}
function add_macles(myvalue)
{
var myinputs=document.getElementsByTagName("input");
var mycountMACLESgen=0;
var tab = new Array();
for (var i=0;i<myinputs.length;i++){
if (myinputs[i].checked) {
tab[mycountMACLESgen]=myinputs[i].value;
mycountMACLESgen++;
}
}
if (mycountMACLESgen==1){opener.document.f.field_value[<!-- TMPL_VAR name="index" -->].value = tab[0];
} else {
var mytags=opener.document.getElementsByName("tag");
var mycountMACLESinit=0;
var indexmin=0
//Compter le nombre de MACLES present
for (i=0;i<mytags.length;i++){
if (mytags[i].value==myvalue) {
if (indexmin==0){
indexmin=i
}
mycountMACLESinit++;
}
}
// Si Nombre de Macles <Nombre de cases cochees, ajouter le nombre de champ manquant
if (mycountMACLESinit < mycountMACLESgen){
//for (i=0;i< (mycountMACLESgen - mycountMACLESinit);i++){
// PluginAddField(myvalue);
//}
alert("veuillez d'abord creer le nombre de champs necessaires ");
} else {
// Pour chaque valeur cochee, ajouter la valeur dans un noeud MACLES.
k=indexmin;
for (i=0;i<tab.length;i++){
// Se positionner sur le prochain noeud MACLES
opener.document.f.field_value[k].value = tab[i];
k=k+2;
}
}
}
window.close();
return false;
}
function uncheck_tab(number)
{
var myinputs=document.getElementsByTagName("input");
var myRegEx=new RegExp(number+"..");
for(i=0;i<myinputs.length;i++){
if ((myinputs[i].name.search(myRegEx)>=0) && myinputs[i].checked == true) {
myinputs[i].checked = false;
}
}
}
function check_col(col)
{
var myref=document.getElementsByName(col);
var myinputs=document.getElementsByTagName("input");
var myRegEx=new RegExp(col);
for(i=0;i<myinputs.length;i++){
if (myinputs[i].name.search(myRegEx)>=0) {
if (myref[0].checked){
myinputs[i].checked = true;
} else {
myinputs[i].checked = false;
}
}
}
return false;
}
function check_multiple()
{
for(myi=0;myi<check_multiple.arguments.length;myi++){
var myinput=document.getElementsByName(""+check_multiple.arguments[myi]);
myinput[0].checked=true;
}
return false;
}
function check_row(row)
{
var myref=document.getElementsByName(row);
var myinputs=document.getElementsByTagName("input");
var myRegEx=new RegExp(row);
// alert myRegEx;
for(i=0;i<myinputs.length;i++){
if (myinputs[i].name.search(myRegEx)>=0){
if (myref[0].checked){
myinputs[i].checked = true;
} else {
myinputs[i].checked = false;
}
}
}
return false;
}
function load_macles(myvalue)
{
document.forms.f_pop.reset;
var mystart=<!-- TMPL_VAR name="index" -->;
var descent=mystart;
var countchecked=0;
// Remonter a la source
while (opener.document.f.tag[descent].value==myvalue && descent>0){
var checkvalue=opener.document.f.field_value[descent].value;
var myinput=document.getElementsByName(checkvalue);
if (myinput.length>0){
myinput[0].checked=true;
countchecked++;
}
descent = descent - 2;
}
// Continuer jusqu'a la fin
var ascent=mystart+2;
while (opener.document.f.tag[ascent].value==myvalue && ascent>0){
var checkvalue=opener.document.f.field_value[ascent].value;
var myinput=document.getElementsByName(checkvalue);
if (myinput.length>0){
myinput[0].checked=true;
countchecked++;
}
ascent=ascent+2;
}
return false;
}
</script>
</body>
</html>