Codigo en foro de desarrollo

B

#28: No lo había leído, cuando he escrito eso pensé en que quizás haya algún tipo de código liberado, adaptable a esto para el resaltado. No sé si me he explicado bien xD

-
Probando!

Edit: Wooou!!! Genial! ^^
eagLe__
Estaría bien usar un sistema de quotes tmb XD, es decir, poder "remarcar" un texto
ElRuso

Probando con codigos largos:

*Nota colorea los #numeros como si es un quote y los links.

#!/usr/bin/perl -wT

#Chek if cookoie is set, if not send it
if ($ENV{"HTTP_COOKIE"}){
                #Getting cookie from browser, storing unique id in oUniqid variable for future use
                ($cookie_name, $oUniqid) = split(/=/, $ENV{"HTTP_COOKIE"});
}
else {

    print "Set-Cookie: user=";
    #GENERATE UNIQUE ID BASED ON TIME
    $uniqid = time;
    print $uniqid;
    print "\n";
}

print "Content-Type: text/html;charset=ISO-8859-1\n\n";

#read and sepparate data entered by user into the form using post method
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

   @pairs = split(/&/, $buffer);

   foreach $pair (@pairs) {

   ($name, $value) = split(/=/, $pair);

   $value =~ tr/+/ /;
   $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
   $name =~ tr/+/ /;
   $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

   $FORM{$name} = $value;
   }
$method = $ENV{'REQUEST_METHOD'};
print qq~
       <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
       <html>
       <head>
       <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
       <Title>New User</title>
       <style type="text/css">
       <!--
       body,td,th {
               color: #A0522D;
       }
       body {
               background-color: #D7C5AB;
       }
       .style1 {
               font-family: Verdana, Arial, Helvetica, sans-serif;
               font-weight: bold;
       }
       .style2 {color: #000000}
       -->
       </style></head>

   <body>
   <table bgcolor="#D8C09E" width="800" border="1"  align="center" bordercolor="#FF0000">
     <tr border="1">
       <td colspan="2" ><center><img src="../../icons/top1.jpg" width="800" height="100"></center></td>
     </tr>
     <tr>
       <td width="324" height="358"  align="center" valign="top"  bordercolor="#000000"bgcolor="#D8C09E"><h3> </h3>
        <h3> </h3>
      <font size="2" font="verdana" color=black>
~;
######################################################
@button = split(/=/, $buffer);
my $buyitem = substr($button[0], 6, length($button[0]));

if ( $FORM{"submit$buyitem"} eq "Add to Cart"){
        &BuyProduct;
}
if ($FORM{"checkout"} || $FORM{"submit$buyitem"} eq "Delete"){
        &checkout();
}

if ($FORM{"update$buyitem"}){
        &update;
}
if ($FORM{"confirm"}){
        &confirm;
}

&head;

sub head {
#print $buyitem, "<br>", $buffer;
if (open (DB, "../db/items.db")) {
#OPENED - YES. Do main code here
        ####working with file, storing data to array######
&outputDB("items.db", "Add to Cart");

sub outputDB{
        open (DB, "../db/$_[0]");
                @records = <DB>;
        flock(DB,2);
        while (<DB>){
                chomp;
                @records = <DB>;
        }
        print "<font size=3><table border=1>\n<tr bgcolor=yellow><td nowrap align=center>[b]Image[/b]</td><td nowrap width=90 align=center>[b]Name[/b]</td><td nowrap width=90 align=center>[b]Price[/b]</td><td nowrap width=90 align=center>[b]Stock[/b]</td><td nowrap width=90 align=center>[b]Item#[/b]</td><td>[b]Quantity[/b]</td><td bgcolor=\"#D8C051\"></td>\n</tr></font>\n";
        #print "<form action=buy.cgi method=post>";
        close (DB);
        ######set record counter#######
        $instance=0;
        #####searching the array for inputed gender######
        foreach $i (@records){
                        ########new array for separate cells
                        my @row =split(/:/, $i);
                        #:pop(@row);
                        print "<tr>";
                        #####outputing data found to the table
                        print "<form action=buy.cgi method=post name=fq$instance>";
                        $img=0;
                        foreach (@row){
                                if ($img eq "0") {
                                        print "<td nowrap><center><img src=../icons/", $_, "></center></td>\n";
                                }
                                elsif ($img eq 2) {
                                        print "<td nowrap><center>\$", $_, "</center></td>\n";
                                }
                                elsif ($img eq "5") {}

                            else {
                                    print "<td nowrap><center>", $_, "</center></td>\n";
                            }
                            $img++;
                    }
                    print "<td align=center><input type=text name=quatty$instance value=";
                    print $row[5];
                    if ($row[5] eq ""){
                            print $row[5], " size=2 maxlength=4></td>";
                    }
                    else{
                            print "1 size=2 maxlength=4></td>";
                    }
                    print "<input type=HIDDEN name=hidden$instance value=";
                    pop(@row);
                    foreach (@row){
                            print $_,":";
                    }
                    print  ">";
                    print "<td><input type=submit name=submit$instance value=\"$_[1]\"><br><br>";
                    if ($_[1] eq "Delete"){
                            print "<input type=submit name=update$instance value=Update></td>";
                    }
                    else {
                            print "</td>";
                    }
                    print "</form>";
                    print "</tr>";
                    #####record found
                    $instance++;

    }
    print "</table>\n";
}
######outputing number of records found
print "<form action=buy.cgi method=post name=Form$instance>";
print "<br><br>";
print "<center><input type=submit name=checkout value=\"Check Out\">";
print "</form></center>";
print &total;
#####################################
&GoToEnd;
}
else {
#OPENED - NO. Do exit subroutine
        print "Page could not be opened. \n $!";
        &GoToEnd;
}
}
##################################################################################################################
####################################################################################################################


################################ MODIFY BEGINS ###########################
sub BuyProduct {

    if ($oUniqid =~ /(^[0-9]+$)/){
            $oUniqid=$1;
    }

    #if ($method eq 'POST' && $FORM{"modify$uniqid"} eq "Modify"){
    open (DB, "../db/items.db");
    open (DBw, ">>../db/$oUniqid.shoplist");
    flock(DB,2);
    flock(DBw,2);
    @txt=<DB>;
    $ins=0;
    chop(@txt);
    foreach $i (@txt){
            if ($buyitem eq $ins){
                    print DBw $i, $FORM{"quatty$buyitem"},"\n";
            }
    $ins++;
    }
    close (DB);
    close (DBw);
#use File::Copy;
#move("../../db/temp.db", "../../db/items.db");
        print "<font color=green size=+1 align=center>The item was added to your Shopping Cart!</font>";
        &head;
}
sub checkout {
        if ( $FORM{"submit$buyitem"} eq "Delete") {
                open (DBtw, ">>../db/tempi.db");
                open (DBow, "../db/$oUniqid.shoplist");
                flock(DBtw,2);
                flock(DBow,2);
                @txt=<DBow>;
                $ins=0;
                #chop(@txt);
                $totalprice=0;
                foreach $i (@txt){
                        if ($buyitem ne $ins){
                                print DBtw $i;
                                @it =split(/:/,$i);
                                $totalprice=$totalprice + $it[2]*$it[5];
                        }
                        $ins++;
                }
                close (DBtw);
                close (DBow);
        print $oUniqid,"fddsi<br>", $buyitem, "ada";
        if ($oUniqid =~ /(^[0-9]+$)/){
                $oUniqid=$1;
        }
        $ENV{"PATH"} = '/bin';
        system ("/bin/mv ../db/tempi.db ../db/$oUniqid.shoplist");
        }
        &outputDB("$oUniqid.shoplist","Delete");
        print "<form name=ok action=buy.cgi method=post><center><input type=submit name=add value=\"Continue Shopping\"></br><p align=right>Please provide your Credit Card number: <input type=text name=visa><br>";
        print "Please provide your e-mail for further confirmation: <input type=text name=email><br><input type=submit name=confirm value=Confirm></p></form>";
        print &total;
        if ( $FORM{'add'}){
                &head;
        }
        if ( $FORM{'ok'}){
        #       &buyproduct;
        #       &report;
        }
        &GoToEnd;
        if ($FORM{'update'}){
                print $buffer;
                exit;
        }
}

sub update {
         open (DBtw, ">>../db/tempi.db");
         open (DBow, "../db/$oUniqid.shoplist");
         flock(DBtw,2);
         flock(DBow,2);
         @txt=<DBow>;
         $ins=0;
         #chop(@txt);
         foreach $i (@txt){
                if ($buyitem ne $ins){
                        print DBtw $i;

             }
            else {
                    print DBtw $FORM{"hidden$buyitem"}, $FORM{"quatty$buyitem"}, "\n";
            }
            $ins++;
     }
    close (DBtw);
    close (DBow);
    if ($oUniqid =~ /(^[0-9]+$)/){
            $oUniqid=$1;
    }
    $ENV{"PATH"} = '/bin';
    system ("/bin/mv ../db/tempi.db ../db/$oUniqid.shoplist");
    &checkout;
}

sub confirm {
         open (DBow, "../db/$oUniqid.shoplist");
         flock(DBow,2);
         @txt=<DBow>;
        print "<font size=-1><table cellspacing=50><tr>";
         foreach $i (@txt){
                @it =split(/:/,$i);
         print "<td nowrap>Item Name: [b]$it[1][/b] <hr><br>Quantity: [b]$it[5][/b] <hr><br>Price for each: [b]$it[2][/b]</td>";
        }
        print "</tr></table></font>";
        print &total;
        printf("%s%.2f", ", including tax: \$",&total("tax"));
        print "<br>The money will be taken from Card Number: $FORM{'visa'}";
        &GoToEnd;
        }

sub total {
         open (DBow, "../db/$oUniqid.shoplist");
         flock(DBow,2);
         @txt=<DBow>;
        foreach $i (@txt){
                @it =split(/:/,$i);
                $totalprice=$totalprice + $it[2]*$it[5];
        }
        close (DBow);
        $tax=$totalprice*15/100/2;
        $t=$totalprice/2 + $tax;
        if ($_[0] eq "tax"){
                return $t;
        }
        else{
                return "<font color=blue>The total price of your purchase is: \$$totalprice";
        }
}



sub GoToEnd{
print qq~
         </tr>
         <tr>
           <td height="23" colspan="2" bordercolor="#DEB887"  bgcolor="#D8C051"  cellspacing="5"><div align="center">Saveliev Vladimir (020-945-051) Stanislavs Motovs (065-320-046) </div></td>
         </tr>
       </table>
       <br>
       <center><font size="2" color="#919191" face="Verdana">[b][u]Disclaimer[/u][/b]</font></center><blockquote><p align=center><font face="Verdana" size="1" color="#919191">This site is a student project only. Any opinions, statements or claims expressed here are that of this site creator and are not necessarily those of Seneca College or of any Student Council or Student Association.</font></p></blockquote></BODY></HTML>
       </body>
       </html>
~;
exit;
}

Muy buen trabajo.

dagavi

¿No te ha estropeado el código?

Es que ahora que me fijo, si quieres código HTML:

[b]Esto va entre B[/b]

Y en tu código largo hay varias cosas en negrita, lo que supongo son < b>< /b>

ElRuso

#35
Pues ta bastante bien, creo que todas las tabulaciones estan bien y lo demas tb.

Aunque si me fijo, tienes razon, los < b > < /b > lee como codigo del foro y lo pone en negrito.

dagavi

Bueno, tampoco importa mucho, la mayoría de los códigos que ponemos en el foro no necesitan para nada < b>< /b> así que tampoco es un problema xD

dr_Rouman

Muchas gracias pollo :)

/********/

10: Home
20: Sweet
30: GOTO 10

Usuarios habituales