diff --git a/docs/create.sql b/docs/create.sql index b0fdd3f20..9783fbbc7 100644 --- a/docs/create.sql +++ b/docs/create.sql @@ -195,6 +195,7 @@ CREATE TABLE event ( description text, startDate int(11) default NULL, endDate int(11) default NULL, + recurringEventId int(11) NOT NULL default '0', PRIMARY KEY (eventId) ) TYPE=MyISAM; @@ -370,6 +371,7 @@ INSERT INTO incrementer VALUES ('eventId',1); INSERT INTO incrementer VALUES ('linkId',1); INSERT INTO incrementer VALUES ('questionId',1); INSERT INTO incrementer VALUES ('submissionId',1); +INSERT INTO incrementer VALUES ('recurringEventId',1); # # Table structure for table 'link' @@ -518,7 +520,7 @@ INSERT INTO settings VALUES ('maxAttachmentSize','300'); INSERT INTO settings VALUES ('lib','/extras'); INSERT INTO settings VALUES ('sessionTimeout','28000'); INSERT INTO settings VALUES ('attachmentDirectoryLocal','/data/WebGUI/uploads'); -INSERT INTO settings VALUES ('smtpServer','smtp.mycompany.com'); +INSERT INTO settings VALUES ('smtpServer','localhost'); INSERT INTO settings VALUES ('companyEmail','info@mycompany.com'); INSERT INTO settings VALUES ('ldapURL','ldap://ldap.mycompany.com:389/o=MyCompany'); INSERT INTO settings VALUES ('companyName','My Company'); diff --git a/docs/upgrade_1.3.0-1.3.1.sql b/docs/upgrade_1.3.0-1.3.1.sql deleted file mode 100644 index e69de29bb..000000000 diff --git a/docs/upgrade_1.3.1-2.0.0.sql b/docs/upgrade_1.3.1-2.0.0.sql new file mode 100644 index 000000000..759deae88 --- /dev/null +++ b/docs/upgrade_1.3.1-2.0.0.sql @@ -0,0 +1,2 @@ +alter table event add column recurringEventId int not null; +INSERT INTO incrementer VALUES ('recurringEventId',1); diff --git a/lib/WebGUI.pm b/lib/WebGUI.pm index dc1d682a3..cae2422d1 100644 --- a/lib/WebGUI.pm +++ b/lib/WebGUI.pm @@ -1,5 +1,5 @@ package WebGUI; -our $VERSION = "1.3.1"; +our $VERSION = "2.0.0"; #------------------------------------------------------------------- # WebGUI is Copyright 2001 Plain Black Software. diff --git a/lib/WebGUI/Mail.pm b/lib/WebGUI/Mail.pm index 9a7199e21..317ec7281 100644 --- a/lib/WebGUI/Mail.pm +++ b/lib/WebGUI/Mail.pm @@ -10,28 +10,35 @@ package WebGUI::Mail; # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- +use Net::SMTP; use strict; +use WebGUI::ErrorHandler; use WebGUI::Session; #------------------------------------------------------------------- #eg: send("jt@jt.com","hi, how are you","this is my message","bob@bob.com"); +#eg: send(to,subject,message,cc); sub send { my ($smtp); $smtp = Net::SMTP->new($session{setting}{smtpServer}); # connect to an SMTP server - $smtp->mail($session{setting}{companyEmail}); # use the sender's address here - $smtp->to($_[0]); # recipient's address - $smtp->data(); # Start the mail - # Send the header. - $smtp->datasend("To: ".$_[0]."\n"); - $smtp->datasend("From: $session{setting}{companyName} <$session{setting}{companyEmail}>\n"); - $smtp->datasend("CC: $_[3]\n") if ($cc); - $smtp->datasend("Subject: ".$_[1]."\n"); - $smtp->datasend("\n"); - # Send the body. - $smtp->datasend($_[2]); - $smtp->datasend("\n\n $session{setting}{companyName}\n $setting{setting}{companyEmail}\n $session{setting}{companyURL}\n"); - $smtp->dataend(); # Finish sending the mail - $smtp->quit; # Close the SMTP connection + if (defined $smtp) { + $smtp->mail($session{setting}{companyEmail}); # use the sender's address here + $smtp->to($_[0]); # recipient's address + $smtp->data(); # Start the mail + # Send the header. + $smtp->datasend("To: ".$_[0]."\n"); + $smtp->datasend("From: $session{setting}{companyName} <$session{setting}{companyEmail}>\n"); + $smtp->datasend("CC: $_[3]\n") if ($_[3]); + $smtp->datasend("Subject: ".$_[1]."\n"); + $smtp->datasend("\n"); + # Send the body. + $smtp->datasend($_[2]); + $smtp->datasend("\n\n $session{setting}{companyName}\n $session{setting}{companyEmail}\n $session{setting}{companyURL}\n"); + $smtp->dataend(); # Finish sending the mail + $smtp->quit; # Close the SMTP connection + } else { + WebGUI::ErrorHandler::warn("Couldn't connect to mail server: ".$session{setting}{smtpServer}); + } } diff --git a/lib/WebGUI/Operation/Account.pm b/lib/WebGUI/Operation/Account.pm index 124454bfd..2b577556a 100644 --- a/lib/WebGUI/Operation/Account.pm +++ b/lib/WebGUI/Operation/Account.pm @@ -15,7 +15,9 @@ use Exporter; use Net::LDAP; use strict; use URI; +use WebGUI::ErrorHandler; use WebGUI::Form; +use WebGUI::Mail; use WebGUI::Privilege; use WebGUI::Session; use WebGUI::SQL; @@ -84,7 +86,12 @@ sub www_createAccount { $output .= ''.WebGUI::Form::submit("create").''; $output .= ''; $output .= ' '; - $output .= '
'; + $output .= '
'; } return $output; } @@ -167,7 +174,9 @@ sub www_displayLogin { if ($session{setting}{anonymousRegistration} eq "yes") { $output .= '
  • Create a new account.'; } - $output .= '
  • I forgot my password.'; + if ($session{setting}{authMethod} eq "WebGUI") { + $output .= '
  • I forgot my password.'; + } $output .= ''; } return $output; @@ -190,8 +199,10 @@ sub www_login { $ldap->unbind; if ($auth->code == 48 || $auth->code == 49) { $error = "The account information you supplied is invalid. Either the account does not exist or the username/password combination was incorrect."; + WebGUI::ErrorHandler::warn("Invalid login for user account: ".$session{form}{username}); } elsif ($auth->code > 0) { $error .= 'LDAP error "'.$ldapStatusCode{$auth->code}.'" occured. Please contact your system administrator for assistance. '; + WebGUI::ErrorHandler::warn("LDAP error: ".$ldapStatusCode{$auth->code}); } else { $success = 1; } @@ -200,13 +211,13 @@ sub www_login { $success = 1; } else { $error = "The account information you supplied is invalid. Either the account does not exist or the username/password combination was incorrect."; + WebGUI::ErrorHandler::warn("Invalid login for user account: ".$session{form}{username}); } } if ($success) { _login($uid,$pass); return ""; } else { - WebGUI::ErrorHandler::warn($error); return "

    Error

    ".$error.www_displayLogin(); } } @@ -252,7 +263,7 @@ sub www_recoverPasswordFinish { $encryptedPassword = Digest::MD5::md5_base64($password); WebGUI::SQL->write("update users set identifier='$encryptedPassword' where userId='$userId'",$session{dbh}); $flag = 1; - $message = 'Someone (probably you) requested your account information be sent. Your password has been reset. The following information represents your new account information:\nUser: '.$username.'\nPass: '.$password.'\n'; + $message = "Someone (probably you) requested your account information be sent. Your password has been reset. The following represents your new account information:\nUser: ".$username."\nPass: ".$password."\n"; WebGUI::Mail::send($session{form}{email},"Account Information",$message); } $sth->finish(); @@ -292,8 +303,10 @@ sub www_saveAccount { $auth = $ldap->bind(dn=>$connectDN, password=>$session{form}{ldapPassword}); if ($auth->code == 48 || $auth->code == 49) { $error .= "Either your ".$session{setting}{ldapIdName}." or ".$session{setting}{ldapPasswordName}." were invalid. "; + WebGUI::ErrorHandler::warn("Invalid LDAP information for registration of LDAP ID: ".$session{form}{ldapId}); } elsif ($auth->code > 0) { $error .= 'LDAP error "'.$ldapStatusCode{$auth->code}.'" occured. Please contact your system administrator for assistance. '; + WebGUI::ErrorHandler::warn("LDAP error: ".$ldapStatusCode{$auth->code}); } $ldap->unbind; } @@ -306,7 +319,6 @@ sub www_saveAccount { $output .= 'Account created successfully!

    '; $output .= www_displayAccount(); } else { - WebGUI::ErrorHandler::warn($error); $output = "

    Error

    ".$error.www_createAccount(); } return $output; diff --git a/lib/WebGUI/Utility.pm b/lib/WebGUI/Utility.pm index 023f8cc26..bbfd89ffb 100644 --- a/lib/WebGUI/Utility.pm +++ b/lib/WebGUI/Utility.pm @@ -18,7 +18,7 @@ use WebGUI::Session; use WebGUI::SQL; our @ISA = qw(Exporter); -our @EXPORT = qw(&getNextId &saveAttachment &round &urlizeTitle "e); +our @EXPORT = qw(&randint &getNextId &saveAttachment &round &urlizeTitle "e); #------------------------------------------------------------------- sub getNextId { @@ -35,6 +35,15 @@ sub quote { return $session{dbh}->quote($value); } +#------------------------------------------------------------------- +sub randint { + my ($low, $high) = @_; + $low = 0 unless defined $low; + $high = 1 unless defined $high; + ($low, $high) = ($high,$low) if $low > $high; + return $low + int( rand( $high - $low + 1 ) ); +} + #------------------------------------------------------------------- sub round { return sprintf("%.0f", $_[0]); diff --git a/lib/WebGUI/Widget/EventsCalendar.pm b/lib/WebGUI/Widget/EventsCalendar.pm index 0a0615ed7..c264258da 100644 --- a/lib/WebGUI/Widget/EventsCalendar.pm +++ b/lib/WebGUI/Widget/EventsCalendar.pm @@ -65,7 +65,9 @@ sub www_addSave { #------------------------------------------------------------------- sub www_addEvent { - my ($output, $today); + my ($output, $today, %recursEvery); + tie %recursEvery, 'Tie::IxHash'; + %recursEvery = ('never'=>'Happens Only Once','day'=>'Day','week'=>'Week'); if (WebGUI::Privilege::canEditPage()) { ($today) = epochToSet(time()); $output = '

    Add Event

    '; @@ -76,6 +78,7 @@ sub www_addEvent { $output .= 'Description'.WebGUI::Form::textArea("description",'',50,10,1).''; $output .= 'Start Date'.WebGUI::Form::text("startDate",20,30,$today,1).''; $output .= 'End Date'.WebGUI::Form::text("endDate",20,30,$today,1).''; + $output .= 'Recurs every'.WebGUI::Form::selectList("recursEvery",\%recursEvery).' until '.WebGUI::Form::text("until",20,30,$today,1).''; $output .= ''.WebGUI::Form::submit("save").''; $output .= '
    '; return $output; @@ -87,10 +90,36 @@ sub www_addEvent { #------------------------------------------------------------------- sub www_addEventSave { - my ($eventId); + my ($i, $recurringEventId, @startDate, @endDate, @eventId, $until); if (WebGUI::Privilege::canEditPage()) { - $eventId = getNextId("eventId"); - WebGUI::SQL->write("insert into event values ($eventId, $session{form}{wid}, ".quote($session{form}{name}).", ".quote($session{form}{description}).", '".setToEpoch($session{form}{startDate})."', '".setToEpoch($session{form}{endDate})."')",$session{dbh}); + $startDate[0] = setToEpoch($session{form}{startDate}); + $endDate[0] = setToEpoch($session{form}{endDate}); + $until = setToEpoch($session{form}{until}); + $eventId[0] = getNextId("eventId"); + if ($session{form}{recursEvery} eq "never") { + $recurringEventId = 0; + } elsif ($session{form}{recursEvery} eq "day") { + $recurringEventId = getNextId("recurringEventId"); + while ($startDate[$i] < $until) { + $i++; + $eventId[$i] = getNextId("eventId"); + $startDate[$i] = $startDate[0] + (86400 * $i); + $endDate[$i] = $endDate[0] + (86400 * $i); + } + } elsif ($session{form}{recursEvery} eq "week") { + $recurringEventId = getNextId("recurringEventId"); + while ($startDate[$i] < $until) { + $i++; + $eventId[$i] = getNextId("eventId"); + $startDate[$i] = $startDate[0] + (604800 * $i); + $endDate[$i] = $endDate[0] + (604800 * $i); + } + } + $i = 0; + while ($eventId[$i] > 0) { + WebGUI::SQL->write("insert into event values ($eventId[$i], $session{form}{wid}, ".quote($session{form}{name}).", ".quote($session{form}{description}).", '".$startDate[$i]."', '".$endDate[$i]."', $recurringEventId)",$session{dbh}); + $i++; + } return www_edit(); } else { return WebGUI::Privilege::insufficient(); @@ -102,7 +131,11 @@ sub www_deleteEvent { my ($output); if (WebGUI::Privilege::canEditPage()) { $output = '

    Please Confirm

    '; - $output = 'Are you certain that you want to delete this event?

    Yes, I\'m sure.   No, I made a mistake.
    '; + $output .= 'Are you certain that you want to delete this event'; + if ($session{form}{rid} > 0) { + $output .= ' and all of its recurring events'; + } + $output .= '?

    Yes, I\'m sure.   No, I made a mistake.
    '; return $output; } else { return WebGUI::Privilege::insufficient(); @@ -113,7 +146,11 @@ sub www_deleteEvent { sub www_deleteEventConfirm { my ($output); if (WebGUI::Privilege::canEditPage()) { - WebGUI::SQL->write("delete from event where eventId=$session{form}{eid}",$session{dbh}); + if ($session{form}{rid} > 0) { + WebGUI::SQL->write("delete from event where recurringEventId=$session{form}{rid}",$session{dbh}); + } else { + WebGUI::SQL->write("delete from event where eventId=$session{form}{eid}",$session{dbh}); + } return www_edit(); } else { return WebGUI::Privilege::insufficient(); @@ -138,9 +175,9 @@ sub www_edit { $output .= ''; $output .= '

    Add New Event

    '; $output .= ''; - $sth = WebGUI::SQL->read("select eventId, name from event where widgetId='$session{form}{wid}' order by startDate",$session{dbh}); + $sth = WebGUI::SQL->read("select eventId, name, recurringEventId from event where widgetId='$session{form}{wid}' order by startDate",$session{dbh}); while (@event = $sth->array) { - $output .= ''; + $output .= ''; } $sth->finish; $output .= '
    '.$event[1].'
    '.$event[1].'
    '; diff --git a/lib/WebGUI/Widget/FAQ.pm b/lib/WebGUI/Widget/FAQ.pm index f28aecd33..739a962ac 100644 --- a/lib/WebGUI/Widget/FAQ.pm +++ b/lib/WebGUI/Widget/FAQ.pm @@ -110,7 +110,7 @@ sub www_deleteQuestion { my ($output); if (WebGUI::Privilege::canEditPage()) { $output = '

    Please Confirm

    '; - $output = 'Are you certain that you want to delete this question?

    Yes, I\'m sure.   No, I made a mistake.
    '; + $output .= 'Are you certain that you want to delete this question?

    Yes, I\'m sure.   No, I made a mistake.
    '; return $output; } else { return WebGUI::Privilege::insufficient(); diff --git a/lib/WebGUI/Widget/LinkList.pm b/lib/WebGUI/Widget/LinkList.pm index 92fbc0ac9..c1168fbff 100644 --- a/lib/WebGUI/Widget/LinkList.pm +++ b/lib/WebGUI/Widget/LinkList.pm @@ -111,7 +111,7 @@ sub www_deleteLink { my ($output); if (WebGUI::Privilege::canEditPage()) { $output = '

    Please Confirm

    '; - $output = 'Are you certain that you want to delete this link?

    Yes, I\'m sure.   No, I made a mistake.
    '; + $output .= 'Are you certain that you want to delete this link?

    Yes, I\'m sure.   No, I made a mistake.
    '; return $output; } else { return WebGUI::Privilege::insufficient();