<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 431,  comments - 344,  trackbacks - 0

    在使用action和workflow時候,突然想到怎么給一個角色組里的所以人發(fā)email,然后在主站上找到了一篇文章介紹怎么實現(xiàn)http://drupal.org/node/48738,添加以后,按照步驟,進入action設(shè)置那里添加所要的功能,然后設(shè)置發(fā)送的角色組。這時候突然想到之前實現(xiàn)的日歷事件,然后就決定實現(xiàn)這樣一個效果,我添加一個事件,例如添加一個會議通知,然后通過email形式發(fā)送到角色組里的成員郵件里,這樣就要去workflow里面創(chuàng)建一個工作流,添加action,然后把這工作流添加到event 的node type上!這樣就可以了!
    要在action.module里面添加如下的代碼:

    function action_send_email_torolegroup($op, $edit = array(), $node) {
      switch($op) {
        case 'metadata':
          return array(
            'description' => t('Send Email to a role group'),
            'type' => t('Email'),
            'batchable' => false,
            'configurable' => true,
          );

        case 'do':
          // note this is the user who owns the node, not global $user
          $user = user_load(array('uid' => $node->uid));
          $site_name = variable_get('site_name', 'Drupal');
          $from = "$site_name <" . variable_get('site_mail', ini_get('sendmail_from')) . '>';
          $subject = $edit['subject'];
          $message = $edit['message'];
         
          foreach($edit['recipients'] as $rid => $chose_role) {
            if ($chose_role) {
              $recipient_roles[] = $rid;
            }
           
          }
         
          $recipient_addresses = array();
         
          if ($recipient_roles[2]) { //email every one! wow. that's why a watchdog is invoked

            watchdog('action', t('Sent an email to every single registered user. Use with caution.'));
           
            $result = db_query('SELECT mail FROM {users} WHERE uid > 0');
            while($account = db_fetch_object($result)) {
              $recipient_addresses[] = $account->mail;
            }
          } else {
            $roles = implode(',', $recipient_roles);   
            $result = db_query('SELECT DISTINCT u.mail FROM {users} u INNER JOIN {users_roles} r ON u.uid = r.uid WHERE r.rid IN (%s)', $roles);
            while($account = db_fetch_object($result)) {
              $recipient_addresses[] = $account->mail;
      
            }
          }
         
          if (isset($node) && is_object($node)) {
            $variables = array(
              '%site_name' => $site_name,
              '%username' => $user->name,
              '%uid' => $node->uid,
              '%node_url' => url('node/' . $node->nid, NULL, NULL, TRUE),
              '%node_type' => $node->type,
              '%title' => $node->title,
              '%teaser' => strip_tags($node->teaser),
              '%body' => strip_tags($node->body)
               );

            $message = strtr($message, $variables);
          }
          foreach ($recipient_addresses as $recipient) {
            if (user_mail($recipient, $subject, $message, "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from" )) {
              watchdog('action', t('Sent email to %recipient', array('%recipient' => $recipient)));
            }
            else {
              watchdog('error', t('Unable to send email to %recipient', array('%recipient' => $recipient)));
            }
          }
          break;

        // return an HTML config form for the action
        case 'form':
          // default values for form
          //  if (!isset($edit['recipients'])) $edit['recipients'] = '';
          if (!isset($edit['subject'])) $edit['subject'] = '';
          if (!isset($edit['message'])) $edit['message'] = '';
          $form = array();
          $roles = user_roles();
          unset($roles[1]); // good bye anonymous users!
          //unset($roles[2]); // good bye authenticated users!
               
          $form['recipients'] = array(
            '#type' => 'checkboxes',
            '#title' => t('Recipient Role Groups'),
            '#default_value' => $edit['recipients'],
            '#options' => $roles,
            '#description' => t('Select which roles should receive this email.'),
        );
         
          $form['subject'] = array(
            '#type' => 'textfield',
            '#title' => t('Subject'),
            '#default_value' => $edit['subject'],
            '#size' => '20',
            '#maxlength' => '254',
            '#description' => t('The subject of the message.'),
          );
          $form['message'] = array(
            '#type' => 'textarea',
            '#title' => t('Message'),
            '#default_value' => $edit['message'],
            '#cols' => '80',
            '#rows' => '20',
            '#description' => t('The message that should be sent.  You may include the following variables: %site_name, %username, %node_url, %node_type, %title, %teaser, %body'),
          );
          return $form;

         // validate the HTML form
        case 'validate':
          $errors = array();
         
          $roleselected = false;
          foreach($edit['recipients'] as $rid => $selected) {
            if ($selected) {
              $roleselected = true;
            }
          }
          if (!$roleselected) {
            $errors['recipients'] = t('Please enter at least one recipient role group');
          }
         
          foreach ($errors as $name => $message) {
            form_set_error($name, $message);
          }

          return count($errors) == 0;

        // process the HTML form to store configuration
        case 'submit':

          $params = array(
            'recipients' => $edit['recipients'],
            'subject'   => $edit['subject'],
            'message'   => $edit['message']);
          return $params;
      }
    }

    /**
    * Send an e-mail message.
    */
    function user_mail($mail, $subject, $message, $header) {
      if (variable_get('smtp_library', '') && file_exists(variable_get('smtp_library', ''))) {
        include_once variable_get('smtp_library', '');
        return user_mail_wrapper($mail, $subject, $message, $header);
      }
      else {
        return mail(
          check_email_header($mail),
          mime_header_encode(check_email_header($subject)),
          str_replace("\r", '', $message),
          "MIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8; format=flowed\nContent-transfer-encoding: 8Bit\n" . check_email_header($header)
        );
      }
    }

    function check_email_header($val)
    {
       if (strpos($value, "\r") !== false || strpos($value, "\n") !== false)
       {
         die("Why ?? :(");
       }

       return $val;
    }

    posted on 2007-11-21 19:14 周銳 閱讀(265) 評論(0)  編輯  收藏 所屬分類: PHP
    主站蜘蛛池模板: 成人毛片18女人毛片免费96| 亚洲精品乱码久久久久久不卡| 亚洲精品无码永久在线观看男男| 亚洲M码 欧洲S码SSS222| 成人片黄网站色大片免费观看APP| 亚洲视频一区在线| 全部免费毛片免费播放| 亚洲精品免费视频| 国产亚洲午夜精品| 亚洲宅男永久在线| 国产91在线免费| 18禁成人网站免费观看| 免费看黄网站在线看| 亚洲精品乱码久久久久久下载| 国产伦一区二区三区免费| 无码精品人妻一区二区三区免费看 | 希望影院高清免费观看视频| 国产精品亚洲专区无码牛牛 | 亚洲VA综合VA国产产VA中| 2020因为爱你带字幕免费观看全集 | 亚洲国产日韩综合久久精品| 亚洲日本乱码在线观看| 日韩一区二区a片免费观看 | 亚洲制服在线观看| 亚洲精品无码久久久久去q | 亚洲精品无码久久久久sm| 在线播放免费播放av片| 久久午夜无码免费| 亚洲免费在线观看| 亚洲av中文无码乱人伦在线观看 | 亚洲国产美女福利直播秀一区二区| 亚洲日本韩国在线| 永久免费观看的毛片的网站| 国产在线jyzzjyzz免费麻豆| 两个人看www免费视频| 高潮毛片无遮挡高清免费视频| 91亚洲国产成人久久精品网址 | 久久久久亚洲精品日久生情 | 美女被艹免费视频| 久久亚洲精品国产亚洲老地址| 亚洲尹人九九大色香蕉网站 |