2009-07-22 20:49:46 +00:00
< ? php defined ( " SYSPATH " ) or die ( " No direct script access. " );
/**
* Gallery - a web based photo album viewer and editor
2011-01-22 07:12:44 +00:00
* Copyright ( C ) 2000 - 2011 Bharat Mediratta
2009-07-22 20:49:46 +00:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 2 of the License , or ( at
* your option ) any later version .
*
* This program is distributed in the hope that it will be useful , but
* WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
* General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 51 Franklin Street - Fifth Floor , Boston , MA 02110 - 1301 , USA .
*/
class ContactOwner_Controller extends Controller {
2011-03-22 01:23:30 +00:00
static function get_email_form ( $user_id , $item_id ) {
2010-10-07 19:54:56 +00:00
// Determine name of the person the message is going to.
$str_to_name = " " ;
if ( $user_id == - 1 ) {
$str_to_name = module :: get_var ( " contactowner " , " contact_owner_name " );
} else {
// Locate the record for the user specified by $user_id,
// use this to determine the user's name.
$userDetails = ORM :: factory ( " user " )
-> where ( " id " , " = " , $user_id )
-> find_all ();
$str_to_name = $userDetails [ 0 ] -> name ;
2009-07-22 20:49:46 +00:00
}
2009-07-23 02:17:57 +00:00
2011-03-22 01:23:30 +00:00
// If item_id is set, include a link to the item.
$email_body = " " ;
if ( $item_id <> " " ) {
$item = ORM :: factory ( " item " , $item_id );
$email_body = " This message refers to <a href= \" " . url :: abs_site ( " { $item -> type } s/ { $item -> id } " ) . " \" >this page</a>. " ;
}
2009-07-22 20:49:46 +00:00
// Make a new form with a couple of text boxes.
2010-10-07 19:54:56 +00:00
$form = new Forge ( " contactowner/sendemail/ { $user_id } " , " " , " post " ,
2009-10-04 20:40:59 +00:00
array ( " id " => " g-contact-owner-send-form " ));
2009-07-22 20:49:46 +00:00
$sendmail_fields = $form -> group ( " contactOwner " );
2010-10-07 19:54:56 +00:00
$sendmail_fields -> input ( " email_to " )
-> label ( t ( " To: " )) -> value ( $str_to_name )
-> id ( " g-contactowner-to-name " );
$sendmail_fields -> input ( " email_from " )
-> label ( t ( " From: " )) -> value ( identity :: active_user () -> email )
-> id ( " g-contactowner-from-email " )
-> rules ( 'required|valid_email' )
-> error_messages ( " required " , t ( " You must enter a valid email address " ))
-> error_messages ( " valid_email " , t ( " You must enter a valid email address " ))
-> error_messages ( " invalid " , t ( " You must enter a valid email address " ));
$sendmail_fields -> input ( " email_subject " )
-> label ( t ( " Subject: " )) -> value ( " " )
-> id ( " g-contactowner-subject " )
-> rules ( 'required' )
-> error_messages ( " required " , t ( " You must enter a subject " ));
$sendmail_fields -> textarea ( " email_body " )
-> label ( t ( " Message: " ))
2011-03-22 01:23:30 +00:00
-> value ( $email_body )
2010-10-07 19:54:56 +00:00
-> id ( " g-contactowner-email-body " )
-> rules ( 'required' )
-> error_messages ( " required " , t ( " You must enter a message " ));
// Add a captcha, if there's an active captcha module.
module :: event ( " captcha_protect_form " , $form );
2009-07-22 20:49:46 +00:00
// Add a save button to the form.
$sendmail_fields -> submit ( " SendMessage " ) -> value ( t ( " Send " ));
2010-10-07 19:54:56 +00:00
return $form ;
}
2011-03-22 01:23:30 +00:00
public function emailowner ( $item_id ) {
2010-10-07 19:54:56 +00:00
// Display a form that a vistor can use to contact the site owner.
// If this page is disabled, show a 404 error.
if ( module :: get_var ( " contactowner " , " contact_owner_link " ) != true ) {
throw new Kohana_404_Exception ();
}
2009-07-22 20:49:46 +00:00
// Set up and display the actual page.
2009-11-17 22:06:04 +00:00
$template = new Theme_View ( " page.html " , " other " , " Contact " );
2009-07-22 20:49:46 +00:00
$template -> content = new View ( " contactowner_emailform.html " );
2011-03-22 01:23:30 +00:00
$template -> content -> sendmail_form = $this -> get_email_form ( " -1 " , $item_id );
2009-07-22 20:49:46 +00:00
print $template ;
}
2011-03-22 01:23:30 +00:00
public function emailid ( $user_id , $item_id ) {
2009-07-22 20:49:46 +00:00
// Display a form that a vistor can use to contact a registered user.
2009-12-23 05:31:03 +00:00
2009-07-22 20:49:46 +00:00
// If this page is disabled, show a 404 error.
if ( module :: get_var ( " contactowner " , " contact_user_link " ) != true ) {
2009-12-24 04:52:09 +00:00
throw new Kohana_404_Exception ();
2009-07-22 20:49:46 +00:00
}
2009-12-23 05:31:03 +00:00
2009-07-22 20:49:46 +00:00
// Set up and display the actual page.
2009-11-17 22:06:04 +00:00
$template = new Theme_View ( " page.html " , " other " , " Contact " );
2009-07-22 20:49:46 +00:00
$template -> content = new View ( " contactowner_emailform.html " );
2011-03-22 01:23:30 +00:00
$template -> content -> sendmail_form = $this -> get_email_form ( $user_id , $item_id );
2009-07-22 20:49:46 +00:00
print $template ;
}
2010-10-07 19:54:56 +00:00
public function sendemail ( $user_id ) {
// Validate the form, then send the actual email.
// If this page is disabled, show a 404 error.
if (( $user_id == " -1 " ) && ( module :: get_var ( " contactowner " , " contact_owner_link " ) != true )) {
throw new Kohana_404_Exception ();
} elseif (( $user_id >= 0 ) && ( module :: get_var ( " contactowner " , " contact_user_link " ) != true )) {
throw new Kohana_404_Exception ();
}
// Make sure the form submission was valid.
$form = $this -> get_email_form ( $user_id );
$valid = $form -> validate ();
if ( $valid ) {
2009-12-30 06:10:55 +00:00
// Copy the data from the email form into a couple of variables.
$str_emailsubject = Input :: instance () -> post ( " email_subject " );
$str_emailfrom = Input :: instance () -> post ( " email_from " );
$str_emailbody = Input :: instance () -> post ( " email_body " );
// Add in some <br> tags to the message body where ever there are line breaks.
$str_emailbody = str_replace ( " \n " , " \n <br/> " , $str_emailbody );
// Gallery's Sendmail library doesn't allow for custom from addresses,
// so add the from email to the beginning of the message body instead.
// Also add in the admin-defined message header.
$str_emailbody = module :: get_var ( " contactowner " , " contact_owner_header " ) . " <br/> \r \n " . " Message Sent From " . $str_emailfrom . " <br/> \r \n <br/> \r \n " . $str_emailbody ;
// Figure out where the email is going to.
$str_emailto = " " ;
2010-10-07 19:54:56 +00:00
if ( $user_id == - 1 ) {
2009-12-30 06:10:55 +00:00
// If the email id is "-1" send the message to a pre-determined
// owner email address.
$str_emailto = module :: get_var ( " contactowner " , " contact_owner_email " );
} else {
// or else grab the email from the user table.
$userDetails = ORM :: factory ( " user " )
2010-10-07 19:54:56 +00:00
-> where ( " id " , " = " , $user_id )
2009-12-30 06:10:55 +00:00
-> find_all ();
$str_emailto = $userDetails [ 0 ] -> email ;
}
// Send the email message.
Sendmail :: factory ()
-> to ( $str_emailto )
-> subject ( $str_emailsubject )
-> header ( " Mime-Version " , " 1.0 " )
-> header ( " Content-type " , " text/html; charset=utf-8 " )
-> message ( $str_emailbody )
-> send ();
// Display a message telling the visitor that their email has been sent.
$template = new Theme_View ( " page.html " , " other " , " Contact " );
$template -> content = new View ( " contactowner_emailform.html " );
$template -> content -> sendmail_form = t ( " Your Message Has Been Sent. " );
print $template ;
2010-10-07 19:54:56 +00:00
} else {
// Set up and display the actual page.
$template = new Theme_View ( " page.html " , " other " , " Contact " );
$template -> content = new View ( " contactowner_emailform.html " );
$template -> content -> sendmail_form = $form ;
2009-12-30 06:10:55 +00:00
print $template ;
2009-07-22 20:49:46 +00:00
}
}
2010-10-07 19:54:56 +00:00
}