|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * OS2Web_Print_Send_to_Friend |
| 5 | + * |
| 6 | + * PHP version 5 |
| 7 | + * |
| 8 | + * @category OS2Web |
| 9 | + * @package OS2Web_Print_Send_to_Friend |
| 10 | + * @author Stanislav Kutasevits < [email protected]> |
| 11 | + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 |
| 12 | + * @link http://bellcom.dk |
| 13 | + */ |
| 14 | + |
| 15 | +/** |
| 16 | + * Implementation of hook_menu(). |
| 17 | + * |
| 18 | + * @return array of links. |
| 19 | + */ |
| 20 | +function os2web_print_send_to_friend_menu() { |
| 21 | + $items = array(); |
| 22 | + |
| 23 | + $items['dagsorden_punkt/%/print'] = array( |
| 24 | + 'title' => 'Print Dagsorden Punkt', |
| 25 | + 'type' => MENU_CALLBACK, |
| 26 | + 'page callback' => 'os2web_print_send_to_friend_print_bullet_point', |
| 27 | + 'page arguments' => array(1), |
| 28 | + 'access arguments' => array(1), |
| 29 | + 'access callback' => 'os2web_print_send_to_friend_bullet_point_access', |
| 30 | + ); |
| 31 | + |
| 32 | + $items['dagsorden_punkt/%/send_to_friend_form'] = array( |
| 33 | + 'title' => 'Send dagsorden punkt til venner', |
| 34 | + 'type' => MENU_CALLBACK, |
| 35 | + 'page callback' => 'os2web_print_send_to_friend_send_to_friend_form', |
| 36 | + 'page arguments' => array(1), |
| 37 | + 'access arguments' => array(1), |
| 38 | + 'access callback' => 'os2web_print_send_to_friend_bullet_point_access', |
| 39 | + ); |
| 40 | + |
| 41 | + $items['dagsorden_punkt/%/send_to_friend_service'] = array( |
| 42 | + 'title' => 'Dagsorden Punkt Send til venner', |
| 43 | + 'type' => MENU_CALLBACK, |
| 44 | + 'page callback' => 'os2web_print_send_to_friend_send_to_friend', |
| 45 | + 'page arguments' => array(1), |
| 46 | + 'access arguments' => array(1), |
| 47 | + 'access callback' => 'os2web_print_send_to_friend_bullet_point_access', |
| 48 | + ); |
| 49 | + |
| 50 | + return $items; |
| 51 | +} |
| 52 | + |
| 53 | +/** |
| 54 | + * Creates a light version of the bullet point for printing |
| 55 | + * |
| 56 | + * @param int $bullet_point_id bullet point id |
| 57 | + * |
| 58 | + */ |
| 59 | +function os2web_print_send_to_friend_print_bullet_point($bullet_point_id) { |
| 60 | + $bullet_point = node_load($bullet_point_id); |
| 61 | + if (strcmp($bullet_point->type, 'bullet_point') == 0) { |
| 62 | + $html = '<h1>' . $bullet_point->title . '</h1>'; |
| 63 | + |
| 64 | + foreach ($bullet_point->field_ref_attachment['und'] as $attachment_id) { |
| 65 | + $attachment = node_load($attachment_id['target_id']); |
| 66 | + $html .= '<h3>' . $attachment->title . '</h3>'; |
| 67 | + $html .= $attachment->field_bpa_body['und'][0]['value']; |
| 68 | + } |
| 69 | + } |
| 70 | + return ('<div class="node" id="content">' . $html . '</div>'); |
| 71 | +} |
| 72 | + |
| 73 | +/** |
| 74 | + * Creates a form that allows to send the content of the bullet point to an email addess. |
| 75 | + * |
| 76 | + * @param int $bullet_point_id bullet point id |
| 77 | + * |
| 78 | + */ |
| 79 | +function os2web_print_send_to_friend_send_to_friend_form($bullet_point_id) { |
| 80 | + //adding css that tweaks the elements for the modal window |
| 81 | + drupal_add_css(drupal_get_path('module', 'os2web_print_send_to_friend') . '/css/os2web_print_send_to_friend.css'); |
| 82 | + |
| 83 | + drupal_add_js(drupal_get_path('module', 'os2web_print_send_to_friend') . '/js/os2web_print_send_to_friend.js'); |
| 84 | + |
| 85 | + $html = t('Fill out the fields below and press "Send", when you want to send the e-mail'); |
| 86 | + $html .= '<form id="send_to_friend_form">'; |
| 87 | + $html .= '<label>' . t('Your name') . ':</label><input type="text" name="name" />'; |
| 88 | + $html .= '<label>' . t('Message') . ':</label><textarea name="message"> </textarea>'; |
| 89 | + $html .= '<label>' . t('Recipients email') . ':</label><input type="text" name="email" id="field_send_to_friend_email" />'; |
| 90 | + $html .= '<input type="hidden" name="base_url" value="' . $GLOBALS['base_url'] . '" />'; |
| 91 | + $html .= '<input type="hidden" name="bullet_point_id" id="field_bullet_point_id" value="' . $bullet_point_id . '" />'; |
| 92 | + $html .= '<button type="submit" id="btn_send_to_friend">Send</button>'; |
| 93 | + $html .= '<div class="throbber"></div>'; |
| 94 | + $html .= '</form>'; |
| 95 | + |
| 96 | + return '<div class="bullet-point-send-to-friend-form ajax-progress">' . $html . '</div>'; |
| 97 | +} |
| 98 | + |
| 99 | +function os2web_print_send_to_friend_bullet_point_access($bullet_point_id) { |
| 100 | + $bullet_point = node_load($bullet_point_id); |
| 101 | + |
| 102 | + if (strcmp($bullet_point->type, 'bullet_point') == 0) { |
| 103 | + if ($bullet_point->field_bul_point_closed['und'][0]['value']) |
| 104 | + return TRUE; |
| 105 | + else |
| 106 | + return FALSE; |
| 107 | + } |
| 108 | + return FALSE; |
| 109 | +} |
| 110 | + |
| 111 | +/** |
| 112 | + * Does the actual sending to the provided email |
| 113 | + * |
| 114 | + * @param int $bullet_point_id bullet point id |
| 115 | + * @patam string $email email |
| 116 | + * |
| 117 | + */ |
| 118 | +function os2web_print_send_to_friend_send_to_friend($bullet_point_id) { |
| 119 | + $query = new EntityFieldQuery(); |
| 120 | + $result = array_pop($query->entityCondition('entity_type', 'node') |
| 121 | + ->propertyCondition('type', 'meeting') |
| 122 | + ->fieldCondition('field_ref_bullet_points', 'target_id', $bullet_point_id, '=') |
| 123 | + ->execute()); |
| 124 | + $meeting_id = (int) is_array($result) ? array_pop($result)->nid : null; |
| 125 | + |
| 126 | + $bullet_point = node_load($bullet_point_id); |
| 127 | + $subject = 'Dagsorden Punkt: ' . $bullet_point->title; |
| 128 | + |
| 129 | + $body = "Hej \n\n" . $_POST['name'] . " har sendt dig et dagsordenspunkt. \n\n"; |
| 130 | + |
| 131 | + if (is_numeric($meeting_id)) { |
| 132 | + $url = url('node/' . $meeting_id, array('absolute' => TRUE)); |
| 133 | + $body .= 'Mødet hvor punktet indgår, kan ses på ' . $url . "\n\n"; |
| 134 | + } |
| 135 | + |
| 136 | + $body .= "Med beskeden:\n" . trim($_POST['message']) . "\n\n"; |
| 137 | + |
| 138 | + $body .= os2web_print_send_to_friend_print_bullet_point($bullet_point_id); |
| 139 | + |
| 140 | + $from = variable_get('system_mail'); |
| 141 | + $message = array( |
| 142 | + 'id' => 'send_to_friend_', |
| 143 | + |
| 144 | + 'subject' => $subject, |
| 145 | + 'body' => array($body), |
| 146 | + 'headers' => array( |
| 147 | + 'From' => $from, |
| 148 | + 'Sender' => $from, |
| 149 | + 'Return-Path' => $from, |
| 150 | + 'Content-Type' => 'text/plain; charset=UTF-8;', |
| 151 | + 'Content-Transfer-Encoding' => '8Bit', |
| 152 | + ), |
| 153 | + ); |
| 154 | + $system = drupal_mail_system("os2web_print_send_to_friend", ""); |
| 155 | + |
| 156 | + // The format function must be called before calling the mail function. |
| 157 | + $message = $system->format($message); |
| 158 | + |
| 159 | + $system->mail($message); |
| 160 | +} |
0 commit comments