What I am trying to do is develop a manager for  albums and songlist. I have
gotten most of it done. However, here I am having problems with Perl keeping
the values set via a form hidden field.  --

this is how the link looks when the script is called..
song_admin.cgi?name=Test&file=Test.txt&artists=teste

the file is what opendir uses to obtain the records..  etc etc..

here are the hidden fields that get their values once the &parseform sub is
done..

print "<input type=\"hidden\" name=\"name\" value\"$nameHead\">";
print "<input type=\"hidden\" name=\"file\" value\"$filename\">";
print "<input type=\"hidden\" name=\"artists\" value\"$Artist\">";

this is what gets returned when I do a get after I try to delete the data
song_admin.cgi?name=&file=&artists=&item=1&delete=delete


What I would expect as a return value is

song_admin.cgi?name=Test&file=Test.txt&artists=teste&item=1&delete=delete


this way it still reads from the same file.

Let me know thanks..

Ray





#written by Ray Alba - link manager for#file called group_view.cgi
#written Feb 19,2002

use CGI;


my (
 $filename,
 $delete,
 $item,
 $new_row,
 $fields,
 $groupTab,
 $nameGroup,
 @nline,
 @line,
 $results,
 $path,
 $nameHead,
 $Artist
);

&parse_form(*thisform);

$path = "your path"; # has to change when we move the site to server..
$fields = 5;                       # Number of fields in each record
$results = 1000;               # maximum number of results to display

print "Content-type: text/html\n\n";

#must do to check etc..

if($nameGroup ne "") {
 $filename = "$nameGroup";      # The database text file
}else{
 &print_error;
}

&open_file("FILE1","",$filename);


print "<html><head><title>DELETE EM</title>";
print "<script language=JavaScript>\n\n \n\n";
print "function confirmME() { confirm(\"Are you sure you want to delete this
record\");}\n</script>\n\n";
print "</head><body bgcolor=ffffff>";
print "<form  method=\"GET\" action=\"song_admin.cgi\" name=\"delLink\">\n";

print "<table border=1 width=90%>";
print "<tr>";


print "<td height=40 colspan=5 align=left valign=bottom>
<blockquote><h3>$nameHead - $Artist</h3></blockquote>
</td></tr>";


print "<input type=\"hidden\" name=\"name\" value\"$nameHead\">";
print "<input type=\"hidden\" name=\"file\" value\"$filename\">";
print "<input type=\"hidden\" name=\"artists\" value\"$Artist\">";

$count =0;

while ((@line = &read_file(FILE1)) && ($count < $results)) {

 @nline = @line;
 $count++;

}

#read lines in as an array
#@nline = sort {$a cmp $b} @nline;
#sort lines
 # how data is stored song|songtime|theme|style|lyrics|realname|mpname

for ($i =0; $i < scalar(@nline); $i++) {
  @tab =  split(/\s*\|\s*/,$nline[$i],$fields);
  $song = $tab[0];
  $songtime = $tab[1];
  $theme = $tab[2];
  $style = $tab[3];
  $lyrics = $tab[4];
  $realname = $tab[5];
  $mpname = $tab[6];
  $vocals = $tab[7];



#put here to show array count to determine record id
 &print_file;
}

print "</td></tr></table><p><p><p><p align=center> <input type=submit
name=\"delete\" value=\"delete\"
onClick=\"confirmME()\"></p></form></body><html>";


if($count ==0) {
 &print_error;
}


sub print_file {
  $newCount = $i + 1;

  print "<tr>\n
  <td colspan=5 align=left valign=top  ><input type=\"radio\" name=\"item\"
value=\"$newCount\" onClick=\"dimDelOff()\"> delete   &lt;<a
href=sdfasx.cgi?item=$count>edit</a>&gt;<center>\n
  <table width=90% cellspacing=0 cellpadding=5 border=0>\n
  <tr bgcolor=\"#abcdef\">\n
  <td align=right valign=top width=35><div type=\"text/css\"
style=\"font-size: 16px;\"><b>$newCount.</b> </div></td>\n
  <td align=left valign=top><div type=\"text/css\" style=\"font-size:
16px;\"><b>$song</b></div></td>\n
  <td align=right valign=top>$songtime</td></tr>\n
  <tr>\n
  <td>&nbsp;</td>\n
  <td valign=top align=left>";


  if($vocals) {
   print "Lead Vocals: " . $vocals . "<br>";
  }

  print "Style:  $style<br>Theme:  $theme<br><center>\n";

  $song =~ s/'//g;

   print "<A
HREF=\"javascript:displayme('mp3/$mpname','100','100','$song','mp3')\">MP3</
a> &nbsp;-&nbsp\n";

   if(stat("$path/real/$realname")) {

   print "<A
HREF=\"javascript:displayme('real/$realname','100','100','$song','real')\">R
eal</a>&nbsp;-&nbsp;\n";
   }


  if($lyrics) {
   print "<a
href=\"javascript:displaylyrics('lyric_popup.shtml?pos=$i&file=$filename')\"
>Lyrics</a></center><br><br>\n";
  }else{
   print "no lyrics";
  }

  print "</td></tr></table>";
}


sub open_file {
  ($filevar, $filemode, $filename) = @_;

  if(open ($filevar,$filemode . $filename) ){
     open ($filevar,$filemode . $filename)
  }else {
   &print_error;
 }
}


sub open_file1 {
  ($filevar, $filemode, $groupTab) = @_;

  if(open ($filevar,$filemode . $groupTab) ){
     open ($filevar,$filemode . $groupTab)
  }else {
   &print_error;
 }
}


sub read_file {

  local ($filevar) = @_;

  <$filevar>;
}

sub print_error {
 print "<h3>Sorry there are no links at this time for this
category<br></h3>";
 exit;
}

#for parsing form data
sub parse_form {


 local (*FORM_DATA) = @_;
 local ($method,$query,@key_value_pairs,$key_value,$key,$value);

   $method = $ENV{'REQUEST_METHOD'};

  if ($method eq "GET") {
     $query = $ENV{'QUERY_STRING'};
  }elsif($method eq "POST") {
      read(STDIN, $query, $ENV{'CONTENT_LENGTH'});
  }else{
   print "ERROR unsupported method";
  }

  #print $query , "\n";
   @key_value_pairs = split (/&/, $query);

     foreach $key_value (@key_value_pairs) {


     ($key, $value) = split(/=/, $key_value);
     $value =~ tr/+/ /;
    #print $key_value;
     $value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack("C", hex ($1))/eg;

     $FORM_DATA{$key} = $value;

     #print "$key = $value<br>";
     #print "$FORM_DATA{formname}";

     $item = $FORM_DATA{'item'};

    #changing the file so that the value is more consistant.
    $nameGroup = $FORM_DATA{'file'};
    $nameHead = $FORM_DATA{'name'};
    $Artist = $FORM_DATA{'artists'};
    #convert tags with HTML
    $nameGroup =~ s/</\&lt;/g;




     if ($value eq "$FORM_DATA{'delete'}")  {
      $delete =  $FORM_DATA{'delete'};
       #print "DELETE <br>";
       $nameGroup = $FORM_DATA{'file'};
     $nameHead = $FORM_DATA{'name'};
     $Artist = $FORM_DATA{'artists'};
     #convert tags with HTML
     $nameGroup =~ s/</\&lt;/g;

       &delete_from;
     exit;
     }


   }

}

sub delete_from {

#print "Content-type: text/html\n\n";

#$filename = "albums.txt";      # The database text file
$path ="/home/dots/public_html/gagorder/webdocs/gagorder"; #used to unlink
media files


&open_file("FILE1","",$filename);

while (@line = &read_file(FILE1)){


 $item =$item - 1;

 #print "item =" .$item;
 @database_row = @line;
    $x = $database_row[$item];

    @new_tab =  split(/\|/ , $x );

    #get name of group for use after we close this file
 $groupTab = "$new_tab[1].txt";

 #here now we must delete the album cover
 @getAlbumCover =  split(/\s*\|\s*/,$database_row[$item]);


 unlink("$path/image_media/$getAlbumCover[4]");

 #now delete the song list record by using the delete function

    delete($database_row[$item]);

   #print out the new values

   for($i = 0; $i <= scalar(@database_row); $i++) {
    if ($i == 0) {
     open (FILE1, ">$filename") ||  die "Cannot open File";
   print FILE1 "$database_row[$i]";
 }else{
  print FILE1 "$database_row[$i]";
 }
  }

  close (FILE1);

} # End of while (<FILE1>)
close (FILE1);

    if (-e $groupTab) {
   #print "grouptab = $groupTab";
   &delete_song_list;
 }


}#close sub


sub delete_song_list {
 $path ="yourpath"; #used to unlink media files
 #if a song list exist for this album, we must delete all the media files
associated with these items.
 #the real and mp3 files are indexes 5 and 6 in the songs list file must
read in file then delete files then unlink
 #$realname = $tab[5];
 #$mpname = $tab[6];

 &open_file("MUSICFILE","",$groupTab);
 while ($songline = &read_file(MUSICFILE)){
  @songtab =  split(/\s*\|\s*/,$songline);

  unlink("$path/real/$songtab[5]");
  unlink("$path/mp3/$songtab[6]");
 }

   close (MUSICFILE);

 unlink($groupTab);
}








-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to