Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

cgi, perl and mySQL question

  • 05-03-2008 10:28am
    #1
    Registered Users, Registered Users 2 Posts: 26,584 ✭✭✭✭


    hey guys im developing this program that uses cgi/perl/mySQL to record generic problems (ie. "there is a problem with server" and it's "john"'s job to fix it only they are a little more complex than this)
    there is a table that stores all this info (table: problem) and inside the createContent subroutine i select the needed info and email it to the user

    i have a button on the website which when pressed calls a perl script (problem.pl) that contains createContent.

    here's the createContent subroutine.
    sub createContent
    {
        #connect to database, omitting code as it works.
            
        my $content="";
        
        #if date field is blank set it a date that won't happen for a long time
        if($emaildate eq "")
        {
            $emaildate="9999-12-31";
        }
        
        #select the problems, if the date field is left blank then it will select all the problems 
        #that have status of open/new. no problems that have the status of closed/duplicate/cancelled are sent by email.
        my $selectQuery = "SELECT id,source,problem,improvement,action,responsible,artifact,benefit,comment,followupdate,status,priority FROM problem WHERE area='$emailarea' && forum='$emailforum' && followupdate <= '$emaildate' ORDER BY id";
        my $sth = $dbh->prepare($selectQuery) or print "Error in preparation";
        $sth->execute() or print "0 sth Error in execution: ($selectQuery)";
        
        my $to;
        my $cc;
        my $subject;
        my $from;
            
        my @result;
        while(@result=$sth->fetchrow_array())
        {
            #split the responsible field if more than one ID exsists
            my @extras = split(/ /, $result[5]);
            
            foreach my $recipient (@extras)
            {
                if( $result[10] eq "new" || $result[10] eq "open" )
                {
                    $content.= "------------------ Problem ".$result[0]." -------------------------\n";
                    $content.= "source: ".$result[1]."\n";
                    $content.= "problem: ".$result[2]."\n";
                    $content.= "improvement: ".$result[3]."\n";
                    $content.= "action: ".$result[4]."\n";
                    $content.= "responsible: ".$result[5]."\n";
                    $content.= "artifact: ".$result[6]."\n";
                    $content.= "benefit: ".$result[7]."\n";
                    $content.= "comment: ".$result[8]."\n";
                    $content.= "follow-up date: ".$result[9]."\n";
                    $content.= "status: ".$result[10]."\n";
                    $content.= "priority: ".$result[11]."\n";
                    $content.= "--------------------------------------------------\n\n";
                                            
                    #create an array with any id in the responsible field converted to an email add.
                    my @emailadd=getEmailAddresses(@extras);
                                            
                    #for every email address we have, append it to the to: field.
                    $to="";
                    foreach my $email (@emailadd)
                    {
                        $to.=$email;
                    }
                    
                    $cc=$user_addresses;
                    $subject="mail test";
                    $from = 'asdf@jkl.com';                
                }
            }
        }
        email($subject, $content, $to, $cc, $from);        
    }
    
    bit of background:

    emailarea/emailforum/emaildate are all sent to the problem.pl script and basically just tell the script what exactly to email.

    the responsible column in the database stores the user's ID which is then is passed to a sub routine called getEmailAddresses().
    this sub routine can take a string of space delimited IDs, an array of IDs and return an array of the email addresses.

    now this will send an email to the person who is in the responsible field, but the problem arises as there can be more than one person in this field.

    say for example we have a problem that is responsible person is "john" and "bill", and we have another problem that only "john" is responsible for.
    i want the email to "john to have two problems contained in the email, and one email to "bill" with the problem he is responsible for.

    what the above is doing now is if i have two problems in a certain area (say: admin) and one belongs to "john" and the other belongs to "neil" (me) i will get an email with "john"'s problem and my own.


Advertisement