#-------------------------------------------------------------------- Variablen
$_uid = (split(/\//,$htx))[1];# bp_Account
$bp_url = (split(/\//,$_link))[2];# URL des bp
#-------------------------------------------------------------------- Subroutinen
$bei123_DATA_HTX="http://baseportal.de/files/bei123/hash.txt";
#--------------------------------------------------------------------
sub bei123
{##
&bei123_GetHash();
#-------------------------------------------
if($_cgi{modus} ne "")
{#------------------------ modus-Subroutinen
if($modus eq "ADMIN")
{&bei123_Admin();
}
elsif($modus eq "HASH")
{&bei123_Hash();
}
else
{}
}
else #---------------------- kein modus
{#
$bei123_output=${${$bei123{$key}}{Data_content}}[${${$bei123{$key}}{_FID}}{$_ID}];
&bei123_eval(&um_laut4ajax(&bei123_entities("$bei123_output")));
#--------------------------------------------
$myOUT=qq(
\n);
$myOUT;
}#
}##
sub bei123_Hash
{##
out(qq|document.getElementById("bei123_OUT").innerHTML="HASH";|);
}##
sub bei123_Admin
{##
my $line=qq(-----------------------------------------------------------------------------);
my $error=0;
my $alertinfo=qq($key $cmd($_ID) erledigt/done);
#---------------------------
if($_cgi{cmd} eq "do_del")
{
$cmd="";
out(qq|if(confirm("** Achtung/Attention !! ** \\n\\nLoeschen/Delete $key(ID: $_ID) ?\\n$line\\n"+document.getElementById("Data_name").value+"")){bei123("modus=ADMIN&key=$key&_ID=$_ID&cmd=del");}|);
}
if($cmd ne "")
{#----------------------------------------------------------------
if($cmd eq "add" || $cmd eq "mod")
{
#--------------------------------------------
if($Data_name eq "" || $Data_content eq "")
{
$alertinfo=qq($key $cmd($_ID) FEHLER/ERROR\\n$line\\nFehlende Eingaben/missing entries\\nData_name or Data_content ? );
$error=1;
}
}
#-----------------------------
out(qq|alert("$alertinfo");|);
#-----------------------------
unless($error)
{####################################################################
%_VAL=();
$ttime=time();
$_VAL{Data_time}=$ttime;
$_VAL{Data_name}= convert_utf8($Data_name);
$_VAL{Data_content}=&um_laut4ajax(convert_utf8($Data_content));
@CMS_FIELDS=("Data_name","Data_content");
%_DB=&bei123_DataHash("$key","$cmd","$_ID");
$bei123{$key}=\%_DB;
###################################
if($_cgi{cmd} ne "")
{
mod serial(%bei123), "$bei123_DATA_HTX" ;
# mod serial(%bei123), "bei123_$modus.htx" ;
}
if($cmd eq "add" || $cmd eq "del")
{###
$_cgi{cmd}="";
$_ID="";
}###
}##################################################################
}#------------------------------------------------------------ENDE cmd
if($_ID ne "") # ein DatenSatz gewählt
{#
$_Data_content = ${${$bei123{$key}}{Data_content}}[${${$bei123{$key}}{_FID}}{$_ID}];
$_Data_content =~ sÞ\\Þ\\\\Þg;
$_Data_content =~ sÞ\nÞ\\nÞg;
$_Data_content =~ sÞ\"Þ\\"Þg;
$_Data_name = ${${$bei123{$key}}{Data_name}}[${${$bei123{$key}}{_FID}}{$_ID}];
$_Data_date = ${${$bei123{$key}}{Data_time}}[${${$bei123{$key}}{_FID}}{$_ID}];
$_Data_date = datum("$_Data_date","lang");
$SELECT_FORM = &bei123_SelectForm();
$INPUT_FORM = &bei123_InputForm();
$EXE_FORM = &bei123_ExeForm();
#-------------------------------
out(qq|document.getElementById("bei123_SELECTFORM").innerHTML="$SELECT_FORM";|);
out(qq|document.getElementById("bei123_INPUTFORM").innerHTML="$INPUT_FORM";|);
out(qq|document.getElementById("bei123_EXEFORM").innerHTML="$EXE_FORM";|);
out(qq|document.getElementById("Data_content").value="$_Data_content";|);
out(qq|document.getElementById("Data_name").value="$_Data_name";|);
out(qq|document.getElementById("Data_date").value="$_Data_date";|);
}
else
{
&bei123_Form();
}#
}##
sub bei123_Form
{## Admin Formulareingabe
$myOF=&bei123_OutForm();
#-------------------------------
out(qq|document.getElementById("bei123_OUT").innerHTML="$myOF";|);
}##
sub bei123_OutForm
{##
$SELECT_FORM=&bei123_SelectForm();
$SELECT_FORM=qq($SELECT_FORM
);
$INPUT_FORM=&bei123_InputForm();
$INPUT_FORM=~ sÞ\nÞ\\nÞg;
$INPUT_FORM=qq($INPUT_FORM
);
$EXE_FORM=&bei123_ExeForm();
$EXE_FORM=qq($EXE_FORM
);
#-----------------------------------------
$myOF=$SELECT_FORM.$INPUT_FORM.$EXE_FORM;
return($myOF)
}##
sub bei123_SelectForm
{##
&bei123_GetHash();
#-----------------
@IDOPT=map{qq()}@{${$bei123{$key}}{_ID}};
$IDOPT="@IDOPT";
#-----------------------------------------------------------------------------------------------
$mySF=qq();
$mySF.=qq()if($key ne "");
$mySF.=qq() ;
$mySF.=qq(
);
$mySF.=qq();
$mySF.=qq();
#-----------------------------
$mySF=&um_laut4ajax($mySF);
#-----------------------------
return($mySF);
}
sub bei123_InputForm
{##
$myIF=qq();
#---------------
return($myIF);
}##
sub bei123_ExeForm
{##
$mycmd=($_ID ne "" ? "mod":"add");
$myEF=qq();
$myEF.=qq([ID: $_ID]) if($_ID ne "");
$myEF.=qq();
#-----------------------------
$myEF=&um_laut4ajax($myEF);
#-----------------------------
return($myEF);
}##
sub bei123_GetHash
{##
%bei123=eval get "$bei123_DATA_HTX";
$key=$_cgi{key}||"Home";
%_DB=%{$bei123{$key}};
}##
sub bei123_DataHash
{###################################################### es wird immer ein Hash %_VAL erwartet
#
$___key=$_[0];
$___cmd=$_[1];
$___id =$_ID;
#-------------------------------------------------------
$___cmd=uc($___cmd);
############################ ## Datenbank einlesen
#%bei123=eval get "$bei123_DATA_HTX";
%_DB=%{$bei123{$___key}};
############################ ## Feldnamen festlegen
if(@{$_DB{"_ID"}}<1)
{#-------------------------------------------------------------- falls bisher nicht angelegt
@{$_DB{_FIELDS}}=@CMS_FIELDS;
push(@{$_DB{_FIELDS}},"Data_time");
map{@{$_DB{"$_"}}=("")}@CMS_FIELDS;
}#------------------------------------------------------------------- ## Indexierung
@_FNR{(0..(@{$_DB{"_ID"}}-1))}=@{$_DB{"_ID"}};
%_FID =reverse(%_FNR);
$_DB{"_FNR"} =\%_FNR;
$_DB{"_FID"} =\%_FID;
#-------------------------------------------------------------------- ## NEU/add ausführen
if($___cmd eq "ADD")#------------- neue _ID um 1 höher als die letzte alte
{push(@{$_DB{"_ID"}},${$_DB{"_ID"}}[$#{$_DB{"_ID"}}]+1);
#---------------------------------------------------------------- neu indexieren
@_FNR{(0..(@{$_DB{"_ID"}}-1))}=@{$_DB{"_ID"}};
%_FID =reverse(%_FNR);
$_DB{"_FNR"} =\%_FNR;
$_DB{"_FID"} =\%_FID;
#------------------------------------------------------------------ Felderwerte aufnehmen
map{${$_DB{"$_"}}[$_FID{${$_DB{"_ID"}}[$#{$_DB{"_ID"}}]}]=$_VAL{"$_"}}(@{$_DB{_FIELDS}});
#----------------------------------------------------------------------------------------
}
#-------------------------------------------------------------------- ## ÄNDERN/mod
if($___cmd eq "MOD")
{
map{${$_DB{"$_"}}[$_FID{$___id}]=$_VAL{"$_"}}(@{$_DB{_FIELDS}});
}
#---------------------------------------------------------------------## LÖSCHEN/del
if($___cmd eq "DEL")
{ #--------------------------------------------------------- 1.) Feldwerte löschen
map{delete ${$_DB{$_}}[$_FID{$___id}]}(@{$_DB{_FIELDS}});
foreach $i(@{$_DB{_FIELDS}})
{#-------------------------------------------------------- 2.) Arrays glätten, 'undef' entfernen
map{@{$_DB{"$i"}}=grep{$_ unless undef;}@{$_DB{"$i"}}}(@{$_DB{_ID}});
}#
#--------------------------------------------------------- 3.) _ID löschen
delete ${$_DB{_ID}}[$_FID{$___id}];
#--------------------------------------------------------- 4.)Array glätten, 'undef' entfernen
@{$_DB{"_ID"}}=grep{$_ ne "";}@{$_DB{"_ID"}};
#--------------------------------------------------------- 5.) neu indexieren
@_FNR{(0..(@{$_DB{"_ID"}}))}=@{$_DB{"_ID"}};
%_FID =reverse(%_FNR);
delete $_FID{""};
%_FNR =reverse(%_FID);
$_DB{"_FNR"} =\%_FNR;
$_DB{"_FID"} =\%_FID;
}
#------------------------------
$_DB{_AMOUNT} =@{$_DB{"_ID"}}; ## Anzahl Datensätze
#------------------------------
if($_DB{_AMOUNT}<1)
{
%_DB=();# wenn kein Datensatz, dann leerer Hash
}
###
return(%_DB); # Rückgabe des Hash zur WEITERVERARBEITUNG oder Speicherung in der o.g. db
}#############
sub bei123_entities
{##
my $ent=$_[0];
#--------------
map{$ent =~ sÞ&bei123_${${$bei123{ENTITY}}{Data_name}}[${${$bei123{ENTITY}}{_FID}}{$_}];Þ&bei123_esc(${${$bei123{ENTITY}}{Data_content}}[${${$bei123{ENTITY}}{_FID}}{$_}])Þgime} @{${$bei123{ENTITY}}{_ID}};
#--------------
return("$ent");
}##
sub bei123_esc
{##
my $_esc=$_[0];
$_esc=~ sÞ\"Þ\\\"Þgim;
$_esc=&bei123_entities("$_esc");
return($_esc);
}##
sub bei123_eval
{##
$eval_cnt =$_[0];
$eval_cnt =~ sÞ\'Þ'Þg;
$ist1 = "";
$soll1 = "\nEOF";
$ist2 = "";
$soll2 = "out<\n$eval_cnt\n);
eval qq(out<\n$eval_cnt\n\nEOF\n);
}##
sub um_laut4ajax
{## Sonderzeichen umwandeln #
@Umlaute=("ä","ö","ü","Ä","Ö","Ü","ß");
my $_um=$_[0];
map{$_um =~ s#$_#convert_html($_)#ge}@Umlaute;
return("$_um");
}##
sub no_null_begin
{## Leerzeichen am Anfang entfernen
my $field=$_[0];
$field =~ s/\A\s*//;
return($field);
}##
sub no_null_end
{## Leerzeichen am Ende entfernen
my $field=$_[0];
$field =~ s/\s*\Z//;
return($field);
}##
sub text2split
{## Bsp.: @ARRAY=&text2split("was#wer#wo","#") :--#
my ($text,$item)=@_;
my @array = split(/$item/,$text);
return(@array);
}##
sub compare2arrays
{## Bsp.: ($union,$intersection,$difference)=&compare2arrays(\@DIRPAGES,\@_ID);
my @Arr1=@{$_[0]};
my @Arr2=@{$_[1]};
@union = @intersection = @difference = ();
%count = ();
foreach $element (@Arr1,@Arr2) { $count{$element}++ }
foreach $element (keys %count) {
push @union, $element;
push @{ $count{$element} > 1 ? \@intersection : \@difference }, $element;}
return(\@union,\@intersection ,\@difference); # return von Referenzen
}##
sub array2join
{## Bsp.: @array=("wer","was","wo"); $STRING=&array_join(\@array,"#"); :-->
my @array=@{$_[0]};
my $item=$_[1];
my $string = join("$item",@array);
return($string);
}##
sub random3value
{## für Generierung ZufallsZahl
($n,$h,$x)=@_;
%zufall= map{$_=>int(rand($h+1-$n)+$n)}(1..$x) ;
@zzahlen=values(%zufall);
return(@zzahlen);
}##
sub color4text
{## Farbe ins Spiel bringen
my($str,$left,$right,$size)=@_;
my @step;
$step[$_] = ($right->[$_] - $left->[$_]) / (length($str) - 1) for (0 .. 2);
my @chars = split //, $str;
@chars=map{sprintf(qq($chars[$_]), $size, $left->[0] + $_ * $step[0], $left->[1] + $_ * $step[1], $left->[2] + $_ * $step[2])}(0 .. $#chars);
return join("", @chars);
}##
sub html2text
{## entfernt html-tags und gibt nur Text ohne HTML zurück
my $html=$_[0];
($text = $html) =~ s/<(\/|!)?[-.a-zA-Z0-9]*.*?>//g;
return($text);
}##
out<
Ajax-Office($bp_url/$_uid) :: Alles aus baseportal herausholen
EOF
out qq(\n);
out &bei123();
out qq(