| 1 |
<?php |
<?php |
| 2 |
// $Id: ecard.module,v 1.1.2.3 2008/11/11 12:51:01 karst Exp $ |
// $Id: ecard.module,v 1.3 2008/12/04 11:50:38 karst Exp $ |
| 3 |
/** |
/** |
| 4 |
* @file |
* @file |
| 5 |
* This module can be used to send any node as an ecard |
* This module can be used to send any node as an ecard |
| 47 |
'path' => 'ecard/thanks', |
'path' => 'ecard/thanks', |
| 48 |
'callback' => 'ecard_thanks', |
'callback' => 'ecard_thanks', |
| 49 |
'type' => MENU_CALLBACK, |
'type' => MENU_CALLBACK, |
| 50 |
'access' => user_access('view ecards') |
'access' => user_access('send ecards') |
| 51 |
); |
); |
| 52 |
} |
} |
| 53 |
return $items; |
return $items; |
| 81 |
'#default_value' => variable_get('ecard_letter', _ecard_letter()), |
'#default_value' => variable_get('ecard_letter', _ecard_letter()), |
| 82 |
'#cols' => 70, |
'#cols' => 70, |
| 83 |
'#rows' => 5, |
'#rows' => 5, |
| 84 |
'#description' => t('This text is the body of the email that the card recipient will see. These are the variables you may use: %site = your site name, %site_url = your site URL, %site_mail = your site email address, %card_url = the URL for the ecard, %sender = sender name, %recipient = recipient email, '), |
'#description' => t('This text is the body of the email that the card recipient will see. These are the variables you may use: %site = your site name, %site_url = your site URL, %site_mail = your site email address, %card_url = the URL for the ecard, %sender = sender name, %recipient = recipient email, '), |
| 85 |
); |
); |
| 86 |
|
|
|
|
|
| 87 |
$form['notify'] = array( |
$form['notify'] = array( |
| 88 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 89 |
'#title' => t('Notification email customization'), |
'#title' => t('Notification email customization'), |
| 155 |
if (!in_array($node->type, $types_to_ecard)) { |
if (!in_array($node->type, $types_to_ecard)) { |
| 156 |
break; |
break; |
| 157 |
} |
} |
| 158 |
|
|
| 159 |
// Add our form as a content item. |
// Add our form as a content item. |
| 160 |
if ($teaser == FALSE) { |
if ($teaser == FALSE) { |
| 161 |
$node->content['ecard_form'] = array( |
$node->content['ecard_form'] = array( |
| 162 |
'#value' => drupal_get_form('ecard_form', $node), |
'#value' => drupal_get_form('ecard_form', $node), |
| 163 |
'#weight' => 100 |
'#weight' => 100 |
| 164 |
); |
); |
| 165 |
} |
} |
| 166 |
} |
} |
| 167 |
} |
} |
| 169 |
* Define the form |
* Define the form |
| 170 |
*/ |
*/ |
| 171 |
function ecard_form($node=NULL, $form_values=NULL) { |
function ecard_form($node=NULL, $form_values=NULL) { |
| 172 |
if ($node == NULL) |
if ($node == NULL) { |
| 173 |
drupal_goto(); |
drupal_goto(); |
| 174 |
|
} |
| 175 |
|
|
| 176 |
if ($_SESSION['message']!=NULL) { |
if ($_SESSION['message']!=NULL) { |
| 177 |
$form['view_message'] = array( |
$form['view_message'] = array( |
| 178 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 187 |
unset($_SESSION['message']); |
unset($_SESSION['message']); |
| 188 |
} |
} |
| 189 |
|
|
| 190 |
|
//only show the send form if the role is really can send cards! |
| 191 |
|
if (!user_access('send ecards')) { |
| 192 |
|
return $form; |
| 193 |
|
} |
| 194 |
|
|
| 195 |
// Things to happen if step is 1 |
// Things to happen if step is 1 |
| 196 |
//make a fieldset |
//make a fieldset |
| 197 |
$form['block'] = array( |
$form['block'] = array( |
| 207 |
'#title' => t('Your name'), |
'#title' => t('Your name'), |
| 208 |
'#type' => 'textfield' |
'#type' => 'textfield' |
| 209 |
); |
); |
| 210 |
|
|
| 211 |
//sending from |
//sending from |
| 212 |
$form['block']['from_email'] = array( |
$form['block']['from_email'] = array( |
| 213 |
'#title' => t('Your email'), |
'#title' => t('Your email'), |
| 214 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 215 |
); |
); |
| 216 |
|
|
| 217 |
//checking whether session variable is set if so extract emails and unset variables |
//checking whether session variable is set if so extract emails and unset variables |
| 218 |
if (isset($_SESSION['emails'])) { |
if (isset($_SESSION['emails'])) { |
| 219 |
$emails = implode("\n", (array)($_SESSION['emails'])); |
$emails = implode("\n", (array)($_SESSION['emails'])); |
| 220 |
unset($_SESSION['emails']); |
unset($_SESSION['emails']); |
| 221 |
} |
} |
| 222 |
|
|
| 223 |
//display box to type recipients emails |
//display box to type recipients emails |
| 224 |
$form['block']['to_email'] = array( |
$form['block']['to_email'] = array( |
| 225 |
'#title' => t('E-mail(s) of recipient(s)'), |
'#title' => t('E-mail(s) of recipient(s)'), |
| 228 |
'#default_value' => $emails, |
'#default_value' => $emails, |
| 229 |
'#description' => t('You may enter multiple emails') |
'#description' => t('You may enter multiple emails') |
| 230 |
); |
); |
| 231 |
|
|
| 232 |
//display textarea to type message |
//display textarea to type message |
| 233 |
$form['block']['message'] = array( |
$form['block']['message'] = array( |
| 234 |
'#title' => t('Type your message'), |
'#title' => t('Type your message'), |
| 235 |
'#type' => 'textarea', |
'#type' => 'textarea', |
| 236 |
'#description' => t('Whatever you type here will be attached to ecard') |
'#description' => t('Whatever you type here will be attached to ecard') |
| 237 |
); |
); |
| 238 |
|
|
| 239 |
$form['block']['notify']=array( |
$form['block']['notify']=array( |
| 240 |
'#type' => 'checkbox', |
'#type' => 'checkbox', |
| 241 |
'#title' => t('Notify me when the card is picked'), |
'#title' => t('Notify me when the card is picked'), |
| 247 |
'#weight' => 10, |
'#weight' => 10, |
| 248 |
'#value' => t('Send this card') |
'#value' => t('Send this card') |
| 249 |
); |
); |
| 250 |
|
|
| 251 |
$form['nid'] = array( |
$form['nid'] = array( |
| 252 |
'#type' => 'value', |
'#type' => 'value', |
| 253 |
'#value' => $node->nid |
'#value' => $node->nid |
| 269 |
$valid_emails[] = $email; |
$valid_emails[] = $email; |
| 270 |
} |
} |
| 271 |
else { |
else { |
| 272 |
$failed_emails[] = $email; |
//If this is not an email maybe its a Username. So check the table and load the double opted email of an active user |
| 273 |
|
$res = db_query('SELECT mail FROM {users} WHERE status = 1 AND name = "%s"', $email); |
| 274 |
|
if ($resolved_email = db_result($res)) { |
| 275 |
|
$valid_emails[] = $resolved_email; |
| 276 |
|
} |
| 277 |
|
else { |
| 278 |
|
$failed_emails[] = $email; |
| 279 |
|
} |
| 280 |
} |
} |
| 281 |
} |
} |
| 282 |
} |
} |
| 283 |
if (count($failed_emails)) { |
if (count($failed_emails)) { |
| 284 |
form_set_error('to_email', t('This email has an error "@email"', array('@email' => $failed_emails[0]))); |
form_set_error('to_email', t('This email has an error "@email"', array('@email' => $failed_emails[0]))); |
| 285 |
} |
} |
| 286 |
|
|
| 287 |
|
//resolved user emails maye duplicates so I reuse array_unique |
| 288 |
|
$valid_emails = array_unique($valid_emails); |
| 289 |
return $valid_emails; |
return $valid_emails; |
| 290 |
} |
} |
| 291 |
/* |
/* |
| 329 |
$card_copy_url = $base .'ecard/view/'. $random; |
$card_copy_url = $base .'ecard/view/'. $random; |
| 330 |
|
|
| 331 |
//making a copy for you else if you click any other recp link it will mail notification |
//making a copy for you else if you click any other recp link it will mail notification |
| 332 |
//also there is some problem while we produce random |
//also there is some problem while we produce random |
| 333 |
db_query( |
db_query( |
| 334 |
"INSERT into {ecard} (random, nid, sender_name, sender_mail, recp_mail, message, send_time,send,notify) values ('%s','%d','%s','%s','%s','%s','%d','%s','%s')", |
"INSERT into {ecard} ( |
| 335 |
|
random, |
| 336 |
|
nid, |
| 337 |
|
sender_name, |
| 338 |
|
sender_mail, |
| 339 |
|
recp_mail, |
| 340 |
|
message, |
| 341 |
|
send_time, |
| 342 |
|
send, |
| 343 |
|
notify |
| 344 |
|
) values ('%s','%d','%s','%s','%s','%s','%d','%s','%s')", |
| 345 |
$random, |
$random, |
| 346 |
$form_values['nid'], |
$form_values['nid'], |
| 347 |
$form_values['name'], |
$form_values['name'], |
| 353 |
$notify |
$notify |
| 354 |
); |
); |
| 355 |
|
|
| 356 |
$cardid=$random; |
$cardid = $random; |
| 357 |
//iterate through each emails and send them and store a random number for each |
//iterate through each emails and send them and store a random number for each |
| 358 |
foreach ($form_values['valid_emails'] as $email) { |
foreach ($form_values['valid_emails'] as $email) { |
| 359 |
if ($form_values['notify'] == 1) { |
if ($form_values['notify'] == 1) { |
| 361 |
$cardid = $random . $start;//append start value to random number to get cardid |
$cardid = $random . $start;//append start value to random number to get cardid |
| 362 |
$start = $start+1; // making some number in increment order |
$start = $start+1; // making some number in increment order |
| 363 |
db_query( |
db_query( |
| 364 |
"INSERT into {ecard} (random, nid,sender_name,sender_mail,recp_mail,message,send_time,send,notify) values ('%s','%d','%s','%s','%s','%s','%d','%s','%s')", |
"INSERT into {ecard} ( |
| 365 |
|
random, |
| 366 |
|
nid, |
| 367 |
|
sender_name, |
| 368 |
|
sender_mail, |
| 369 |
|
recp_mail, |
| 370 |
|
message, |
| 371 |
|
send_time, |
| 372 |
|
send, |
| 373 |
|
notify |
| 374 |
|
) values ('%s','%d','%s','%s','%s','%s','%d','%s','%s')", |
| 375 |
$cardid, |
$cardid, |
| 376 |
$form_values['nid'], |
$form_values['nid'], |
| 377 |
$form_values['name'], |
$form_values['name'], |
| 400 |
|
|
| 401 |
$body = strtr(variable_get('ecard_letter', _ecard_letter()), $variables); |
$body = strtr(variable_get('ecard_letter', _ecard_letter()), $variables); |
| 402 |
$subject = strtr(variable_get('ecard_subject', 'An Ecard from %sender_name'), $variables); |
$subject = strtr(variable_get('ecard_subject', 'An Ecard from %sender_name'), $variables); |
| 403 |
$from=$form_values['from_email']; |
$from = $form_values['from_email']; |
| 404 |
$headers['Reply-To']=$form_values['from_email']; |
$headers['Reply-To'] = $form_values['from_email']; |
| 405 |
|
|
| 406 |
drupal_mail('ecard-mail', $recipient, $subject, wordwrap($body, 72), $from, $headers); |
drupal_mail('ecard-mail', $recipient, $subject, wordwrap($body, 72), $from, $headers); |
| 407 |
|
|
| 408 |
} |
} |
| 409 |
drupal_set_message(t('Your ecard has been sent and a copy is stored for your reference.<br />You can view the copy <a href="!card_copy_url">here</a>', array('!card_copy_url' => $card_copy_url))); |
drupal_set_message(t('Your ecard has been sent and a copy is stored for your reference.<br />You can view the copy <a href="!card_copy_url">here</a>', array('!card_copy_url' => $card_copy_url))); |
| 410 |
|
|
|
|
|
| 411 |
$site_email = variable_get('site_email', 'root@localhost'); |
$site_email = variable_get('site_email', 'root@localhost'); |
| 412 |
$headers['Reply-To']=$site_email; |
$headers['Reply-To']=$site_email; |
| 413 |
|
|
| 421 |
return $output; |
return $output; |
| 422 |
} |
} |
| 423 |
//function to view the ecard , it also send an email to the sender to know the card is picked |
//function to view the ecard , it also send an email to the sender to know the card is picked |
| 424 |
function ecard_view($arg1=NULL) { |
function ecard_view($arg1 = NULL) { |
| 425 |
global $base_url; |
global $base_url; |
| 426 |
// set the base variable from the clean url value |
// set the base variable from the clean url value |
| 427 |
if (variable_get('clean_url', 0)) { |
if (variable_get('clean_url', 0)) { |
| 432 |
} |
} |
| 433 |
|
|
| 434 |
if (isset($arg1)) { |
if (isset($arg1)) { |
| 435 |
$sql = db_query("SELECT random,nid,message,sender_name,sender_mail,recp_mail,notify FROM {ecard} n WHERE n.random = '%s'", $arg1); |
$sql = db_query("SELECT |
| 436 |
|
random, |
| 437 |
|
nid, |
| 438 |
|
message, |
| 439 |
|
sender_name, |
| 440 |
|
sender_mail, |
| 441 |
|
recp_mail, |
| 442 |
|
notify |
| 443 |
|
FROM {ecard} n |
| 444 |
|
WHERE n.random = '%s'", $arg1); |
| 445 |
$result = db_fetch_object($sql); |
$result = db_fetch_object($sql); |
| 446 |
if ($result != NULL) { |
if ($result != NULL) { |
| 447 |
$node=node_load($result->nid); |
$node=node_load($result->nid); |
| 473 |
} |
} |
| 474 |
} |
} |
| 475 |
else { |
else { |
| 476 |
return t("Your ecard id is not valid either it may be an error or it expired"); |
return t("Your ecard id is not valid either it may be an error or it expired"); |
| 477 |
} |
} |
| 478 |
|
|
| 479 |
return $output; |
return $output; |