Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

$in (inroom) in a drop down menue?????can it be done? 3

Status
Not open for further replies.

MAWarGod

Programmer
Feb 15, 2002
352
US
sub FindOnline{
dbmopen(%li,"$htmlpath/login",0644);
my $time = time;
$li{$cookie{'CHATUSER'}} = $time;
foreach $i (keys %li){
$mt = $time - $li{$i};
($mt < ($refresh * 2))?((push(@occ,$i))&&($uo++)):(($uol=1)&&(delete($li{$i})));
}
dbmclose %li;
&cuol;
$in{'inroom'} = join(" | ",@occ);
}

ok sorta defined

I get it to print out this way

<p align="left"><font color="white"><b>In Room:</b> in(inroom)</td>

it works fine til say there's like 20 people in room and it
starts misshaping banner so is there a way I can put these in a drop down box? I have tried for two days I know its probably simple html but I can not from it to work
 
Code:
$in{'inroom'} = '<select name="inroom">' . "\n"
   . "<option>" . join ("[COLOR=red]</option>\n<option>[/color]",[COLOR=blue]@occ[/color])
   . "</option>\n</select>";

output
Code:
<select name="inroom">
<option>[COLOR=blue]some name[/color][COLOR=red]</option>
<option>[/color][COLOR=blue]some name[/color][COLOR=red]</option>
<option>[/color][COLOR=blue]some name[/color][COLOR=red]</option>
<option>[/color][COLOR=blue]some name[/color][COLOR=red]</option>
<option>[/color][COLOR=blue]some name[/color][COLOR=red]</option>
<option>[/color]</option>
</select>

-------------
Cuvou.com | The NEW Kirsle.net
 
Actually, that way would leave a blank option at the end. Here's a less of a one-liner way to do it...

Code:
$in{'inroom'} = '<select name="inroom">' . "\n";
foreach (@occ) {
   $in{'inroom'} .= "<option>$_</option>\n";
}
$in{'inroom'} .= '</select>';

That would leave no extra HTML (no blank options).

-------------
Cuvou.com | The NEW Kirsle.net
 
Thank You Kirsle

Code:
<select name="inroom">
<option>some name</option>
<option>some name</option>
<option>some name</option>
<option>some name</option>
<option>some name</option>
<option></option>
</select>
Code:
sub FindOnline{
dbmopen(%li,"$htmlpath/login",0644);
my $time = time;
$li{$cookie{'CHATUSER'}} = $time;
foreach $i (keys %li){
$mt = $time - $li{$i};
  ($mt < ($refresh * 2))?((push(@occ,$i))&&($uo++)):(($uol=1)&&(delete($li{$i})));
  }
dbmclose %li;
&cuol;

$in{'Occupants'} = '<select name="Occupants">' . "\n";
foreach (@occ) {
   $in{'Occupants'} .= "<option>$_</option>\n";
}
$in{'Occupants'} .= '</select>';

}
is there a way either in this sub or makeing a new sub
when some name 1 is talking to some name 2 that I can give value to each like I think $sn1, $sn2, $sn3, $sn4, $sn5

each string I guess would = the values that are generated in the dropdown

or would I have to open dbm and have it writen to a file
I am lost on how to do this

MA WarGod

I believe if someone can think it, it can be programmed
 
Code:
$in{'Occupants'} = '<select name="Occupants">' . "\n";
foreach (@occ) {
   $in{'Occupants'} .= qq~<option value="$foo">$_</option>\n~;
}
$in{'Occupants'} .= '</select>';

where $foo can be used to change the values of each option item. Of course like this all items will have the value of $foo, using a hash linked to @occ values would work well:

Code:
$in{'Occupants'} = '<select name="Occupants">' . "\n";
foreach (@occ) {
   $in{'Occupants'} .= qq~<option value="$hash{$_}">$_</option>\n~;
}
$in{'Occupants'} .= '</select>';

- Kevin, perl coder unexceptional!
 
ok the value $hash or $foo would give say $u to be able to appear to be speaking to $hash or $foo
Code:
open(MSGT,">$htmlpath/mymgfile.cgi.tmp");

print MSGT qq|<TABLE WIDTH="92%" border=0 cellpadding=0 cellspacing=0><TR><TD><font color="$c"><b>$u:</b>$in{'m'}</TD></TR></TABLE>\n|;
$u = user1 or you in chat
in('m') is the message
$c is color code

so do I add $hash

Code:
sub WriteToChat{
(!$in{'m'})&&(exit);
&GetCookies;
if($in{'color'}){
  $c = $in{'color'};
  }
else{
  $c = $cookie{'CHATCOLOR'};
  }
$u = $cookie{'CHATUSER'};
if($flock){
  open(LCK,">$htmlpath/mylockfile");
  flock(LCK,2);
  }

open(MSGT,">$htmlpath/mymsgfile.cgi.tmp");

print MSGT qq|<TABLE WIDTH="92%" border=0 cellpadding=0 cellspacing=0><TR><TD><font color="$c"><b>$u:</b>$in{'m'}</TD></TR></TABLE>\n|;

open(MSG,"<$htmlpath/mymsgfile.cgi");
while(<MSG>){
  last if $. > 50;
  print MSGT;
  }
close MSG;
close MSGT;


rename("$htmlpath/mymsgfile.cgi.tmp","$htmlpath/mymsgfile.cgi");

if($flock){
  flock(LCK,8);
  close LCK;
  }


}

ok here's My sub I tryed added $hash maybe I am not following this

confussed

MA WarGod

I believe if someone can think it, it can be programmed
 
I think I'm more confused than you are, maybe Kirsle will understand your question.

- Kevin, perl coder unexceptional!
 
Code:
<select name="inroom">
<option>some name1</option>
<option>some name2</option>
<option>some name3</option>
<option>some name4</option>
<option>some name5</option>
<option></option>
</select>

ok when you enter the chat you are $U
so I want to make it so $u or default user can talk each otheir user or some name 1,2,3,4, ect.

like some name1 says to some name2 hello
the way its phased now when $u speaks in forum $u speaks to ALL in forum

Code:
|<TABLE WIDTH="92%" border=0 cellpadding=0 cellspacing=0><TR><TD><font color="$c"><b>$u:</b>says to $user1 $in{'m'}</TD></TR></TABLE>\n|;
<b>$u:</b>says to $user1
being the name selected in dropdown

so I guess My question is can you define $foo or $hash while or after it returns data???


I hope I fromed that correctly and am not confussing You.

MA WarGod

I believe if someone can think it, it can be programmed
 
where do you get the list of names that will populate the select menu?

<select name="inroom">
<option>some name</option>
<option>some name</option>
<option>some name</option>
<option>some name</option>
<option>some name</option>
<option></option>
</select>

you will have to have a file or table that has those names stored in it to dynamically insert them into the menu as you build it.



- Kevin, perl coder unexceptional!
 
Code:
sub Getlogin{
&GetCookies;
if(!$cookie{'CHATUSER'}){
  print "\n";
  $in{'UserName'} = $ENV{'REMOTE_USER'};
  &PageOut("$htmlpath/defaultlogin");
  exit;
  }
else{
  $time = time;
  dbmopen(%li,"$htmlpath/login",0644);
  $li{$cookie{'CHATUSER'}} = $time;
  dbmclose %li;
  }
}

sub login{
$in{'UserName'} = $ENV{'REMOTE_USER'};
&PageOut("$htmlpath/defaultlogin");
exit;
}

sub FindOnline{
dbmopen(%li,"$htmlpath/login",0644);
my $time = time;
$li{$cookie{'CHATUSER'}} = $time;
foreach $i (keys %li){
$mt = $time - $li{$i};
  ($mt < ($refresh * 2))?((push(@occ,$i))&&($uo++)):(($uol=1)&&(delete($li{$i})));
  }
dbmclose %li;
&cuol;

$in{'Occupants'} = '<select name="Occupants">' . "\n";
foreach (@occ) {
   $in{'Occupants'} .= qq~<option value="$hash{$_}">$_</option>\n~;
}
$in{'Occupants'} .= '</select>';

}

sub cuol{
($in{'command'} ne 'body')&&(return);
($uo > (3))&&(&PError("User limited reached. Unable to log on"));
}
sub PageOut{
#format
local($file) = @_;
open(OUT,"$file");
while(<OUT>){
$_ =~ s/in\((.+?)\)/$in{$1}/g;
print;
}
close OUT;
}
1;

Code:
sub getdata{
local($usecgi)=@_;
if($usecgi){
use CGI;
$query = new CGI;
@names = $query->param;
foreach $i (@names){
  @values = $query->param("$i");
  if($#values > 0){
  $in{$i} = join('\0',@values);
  }
  else{
  $in{$i} = $query->param("$i");
  }
 
  }
}
else{
# Read in text
  if ($ENV{'REQUEST_METHOD'} eq "GET") {
    $in = $ENV{'QUERY_STRING'};
  } elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
    for ($i = 0; $i < $ENV{'CONTENT_LENGTH'}; $i++) {
      $in .= getc;
    }
  } 

  @in = split(/&/,$in);

  foreach $i (0 .. $#in) {
    # Convert plus's to spaces
    $in[$i] =~ s/\+/ /g;

    # Convert %XX from hex numbers to alphanumeric
    $in[$i] =~ s/%(..)/pack("c",hex($1))/ge;

    # Split into key and value.
    $loc = index($in[$i],"=");
    $key = substr($in[$i],0,$loc);
    $val = substr($in[$i],$loc+1);
    $in{$key} .= '\0' if (defined($in{$key})); # \0 is the multiple separator
    $in{$key} .= $val;
    }
}
}

plus in this sub I am haveing trouble with $loc = index($in[$i],"="); "=" stops the name input of = key or sign

so tags or html in like
Code:
<img src= [URL unfurl="true"]http://www.freespaces.com/realitygonewild/wg1.jpg[/URL] align=left><center></img><br><center><FONT FACE=garamond><FONT COLOR =silver><FONT SIZE=4>WarGod of Venna<br><br><FONT FACE =garamond><FONT COLOR =blue><FONT SIZE=3>
can not be put in forum it stops at <img src= of the = sign or key

MA WarGod

I believe if someone can think it, it can be programmed
 
Where have you defined the values for %hash that you are using here:

Code:
foreach (@occ) {
   $in{'Occupants'} .= qq~<option value="[b]$hash{$_}[/b]">$_</option>\n~;
}

if you had been using "strict" as you should be, but appear not to be, your script would exit with an error.

maybe you should just be doing this:

Code:
foreach (@occ) {
   $in{'Occupants'} .= qq~<option value="[b]$_[/b]">$_</option>\n~;
}


The entire getdata subroutine is rather unusual.

- Kevin, perl coder unexceptional!
 
Kevin I can post full script on My forum if You need a clear look at what I am trying to do? trying to follow this sites rules..so not posting email or contact
this way I can lock the forum to provent script getting to otheir chat sites




MA WarGod

I believe if someone can think it, it can be programmed
 
No,I don't want to see the entire script. I will be glad to help you with questions you post here though.

If the project interested me I would consider it, but a perl based internet chat script is a good 10+ years behind the times and is something I would have worked on long ago. In fact I wrote some commercial perl based bulletin board/chat scripts back in the day when they were still in vogue and did well selling them for a few years.

But the internet has turned over a few times since then and perl has really become the ugly cousin for stuff like that, where PHP is now the prom queen and IM's replaced chat scripts years ago.

You keep working on it and it will be your baby, plus you are learning as you go, so version 2 will probably be much better written if you stick with perl and continue to learn.

- Kevin, perl coder unexceptional!
 
Thank You I feel like I am slaming My head off a wall here lol..

but sometimes I'll have that

and Yes I am trying to learn just getting fusterated I guess...

all I want is a simple html chat yes its years behide the time and I guess thats why there are none out there anymore and this is why I am trying to make one I can run on the web shell I have

see the old ones only had two frame well with .net now they need 3 frames I have the old magma software but its so out dated and I know it can be done in perl/cgi with some java tossed in but its forming it..so I learn nods


MA WarGod

I believe if someone can think it, it can be programmed
 
scraps scripts goes back to drawing board

MA WarGod

I believe if someone can think it, it can be programmed
 
>> scraps scripts goes back to drawing board

This time start using "warnings" and "stict"

Code:
#!/usr/bin/perl

use strict;
use warnings;

and start with the CGI module as the foundation for your script. Dump all this ancient baggage:

Code:
else{
# Read in text
  if ($ENV{'REQUEST_METHOD'} eq "GET") {
    $in = $ENV{'QUERY_STRING'};
  } elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
    for ($i = 0; $i < $ENV{'CONTENT_LENGTH'}; $i++) {
      $in .= getc;
    }
  }

  @in = split(/&/,$in);

  foreach $i (0 .. $#in) {
    # Convert plus's to spaces
    $in[$i] =~ s/\+/ /g;

    # Convert %XX from hex numbers to alphanumeric
    $in[$i] =~ s/%(..)/pack("c",hex($1))/ge;

    # Split into key and value.
    $loc = index($in[$i],"=");
    $key = substr($in[$i],0,$loc);
    $val = substr($in[$i],$loc+1);
    $in{$key} .= '\0' if (defined($in{$key})); # \0 is the multiple separator
    $in{$key} .= $val;
    }
}
}

logging off for now.....



- Kevin, perl coder unexceptional!
 
Code:
#/usr/bin/perl

use strict;
use warnings;
use CGI qw(:standard);


my $filename = '\path\to\my\file.txt';

&noFileData() unless(defined(param('fileData')));

&updateFile();

sub noFileData
{
    open FILE, "<$filename" or die "Cannot open $filename: $!";
    my @lines = <FILE>;
    close FILE;
    
    form(join("",@lines))
    ;
    exit;
}

sub updateFile
{
    my $name = param('fileData');
    
    open FILE, ">$filename" or die "Cannot open $filename: $!";
    print FILE $name;
    close FILE;
    
    form($name);
    print "<BR><CENTER>File Updated at ".localtime()."</CENTER>\n";
}

sub form
{
my $name = shift;
print qq ~Content-type: text/html

<HTML>
<HEAD>
<TITLE> test names </TITLE>
<BODY  TEXT = '#FFFFFF' LINK = '#FFCC66' VLink = '#99CC66' ALINK = '#FF0000'>
<center><img src = ""></a> 
<CENTER>
<FORM METHOD="post" ACTION="cvchat.cgi">
<TEXTAREA NAME=fileData ROWS=8 COLS=50 WRAP>$name</TEXTAREA>
<BR><BR>
<INPUT TYPE="submit">
</FORM>
</CENTER>
~;
}

ok thanks I made it this far
from a old thread on here where someone was helping now if I can this to work lol on My server lol

MA WarGod

I believe if someone can think it, it can be programmed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top