CRM-13026 fix
authorPratik Joshi <pratik.joshi@webaccess.co.in>
Tue, 27 Aug 2013 14:10:00 +0000 (19:40 +0530)
committerPratik Joshi <pratik.joshi@webaccess.co.in>
Tue, 27 Aug 2013 14:10:00 +0000 (19:40 +0530)
CRM/Contact/Form/Search.php
CRM/Mailing/BAO/Query.php
CRM/Mailing/Form/Task.php [new file with mode: 0644]
CRM/Mailing/Form/Task/Print.php [new file with mode: 0644]
CRM/Mailing/Selector/Search.php [new file with mode: 0644]
CRM/Mailing/Task.php [new file with mode: 0644]
templates/CRM/Contact/Form/Search/AdvancedCriteria.tpl
templates/CRM/Mailing/Form/Selector.tpl [new file with mode: 0644]
templates/CRM/Mailing/Form/Task.tpl [new file with mode: 0644]
templates/CRM/Mailing/Form/Task/Print.tpl [new file with mode: 0644]
templates/CRM/common/searchResultTasks.tpl

index ba5f08eed13c7fa100e3d44901f58c6103ec3801..adb3c512ef2a038e6c5f32afeacdcebe24db6d9b 100644 (file)
@@ -324,6 +324,15 @@ class CRM_Contact_Form_Search extends CRM_Core_Form {
           'resultContext' => NULL,
           'taskClassName' => 'CRM_Contact_Task',
         ),
+        8 => array(
+          'selectorName' => 'CRM_Mailing_Selector_Search',
+          'selectorLabel' => ts('Mailings'),
+          'taskFile' => "CRM/common/searchResultTasks.tpl",
+          'taskContext' => NULL,
+          'resultFile' => 'CRM/Mailing/Form/Selector.tpl',
+          'resultContext' => 'Search',
+          'taskClassName' => 'CRM_Mailing_Task',
+        ),
       );
     }
   }
index 1ede65d83250eb44da28322838c8bdace24d908a..8636f4118521ee18f84f11c55ef33334f049b92b 100644 (file)
@@ -44,7 +44,9 @@ class CRM_Mailing_BAO_Query {
         'where' => 'civicrm_mailing.id',
       );
     }
+
     return self::$_mailingFields;
+
   }
 
   /**
@@ -58,8 +60,59 @@ class CRM_Mailing_BAO_Query {
     if ($query->_mode & CRM_Contact_BAO_Query::MODE_MAILING) {
       $query->_select['mailing_id'] = "civicrm_mailing.id as mailing_id";
       $query->_element['mailing_id'] = 1;
+
       $query->_tables['civicrm_mailing'] = 1;
       $query->_whereTables['civicrm_mailing'] = 1;
+
+      // during display search strictly display contacts inside mailing
+      $query->_tables['civicrm_mailing_event_queue'] = $query->_whereTables['civicrm_mailing_event_queue'] =
+        " INNER JOIN civicrm_mailing_event_queue ON civicrm_mailing_event_queue.contact_id = contact_a.id ";
+
+      $query->_tables['civicrm_mailing_job'] = $query->_whereTables['civicrm_mailing_job'] = 1;
+
+      // get mailing name
+      if (CRM_Utils_Array::value('mailing_name', $query->_returnProperties)) {
+        $query->_select['mailing_name']  = "civicrm_mailing.name as mailing_name";
+        $query->_element['mailing_name'] = 1;
+      }
+
+      // get mailing subject
+      if (CRM_Utils_Array::value('mailing_subject', $query->_returnProperties)) {
+        $query->_select['mailing_subject']  = "civicrm_mailing.subject as mailing_subject";
+        $query->_element['mailing_subject'] = 1;
+      }
+
+      // get mailing status
+      if (CRM_Utils_Array::value('mailing_job_status', $query->_returnProperties)) {
+        $query->_select['mailing_job_status']  = "civicrm_mailing_job.status as mailing_job_status";
+        $query->_element['mailing_job_status'] = 1;
+      }
+
+      // get email on hold
+      if (CRM_Utils_Array::value('email_on_hold', $query->_returnProperties)) {
+        $query->_select['email_on_hold'] = "recipient_email.on_hold as email_on_hold";
+        $query->_element['email_on_hold'] = 1;
+        $query->_tables['recipient_email'] = $query->_whereTables['recipient_email'] = 1;
+      }
+
+      // get recipient email
+      if (CRM_Utils_Array::value('email', $query->_returnProperties)) {
+        $query->_select['email'] = "recipient_email.email as email";
+        $query->_element['email'] = 1;
+        $query->_tables['recipient_email'] = $query->_whereTables['recipient_email'] = 1;
+      }
+
+      // get user opt out
+      if (CRM_Utils_Array::value('contact_opt_out', $query->_returnProperties)) {
+        $query->_select['contact_opt_out'] = "contact_a.is_opt_out as contact_opt_out";
+        $query->_element['contact_opt_out'] = 1;
+      }
+
+      // mailing job end date / completed date
+      if (CRM_Utils_Array::value('mailing_job_end_date', $query->_returnProperties)) {
+        $query->_select['mailing_job_end_date']  = "civicrm_mailing_job.end_date as mailing_job_end_date";
+        $query->_element['mailing_job_end_date'] = 1;
+      }
     }
   }
 
@@ -81,6 +134,7 @@ class CRM_Mailing_BAO_Query {
 
   static function from($name, $mode, $side) {
     $from = NULL;
+
     switch ($name) {
       case 'civicrm_mailing_event_queue':
         $from = " $side JOIN civicrm_mailing_event_queue ON civicrm_mailing_event_queue.contact_id = contact_a.id";
@@ -103,6 +157,9 @@ class CRM_Mailing_BAO_Query {
       case 'civicrm_mailing_event_trackable_url_open':
         $from = " $side JOIN $name ON $name.event_queue_id = civicrm_mailing_event_queue.id";
         break;
+
+      case 'recipient_email':
+        $from = " $side JOIN civicrm_email recipient_email ON recipient_email.id = civicrm_mailing_event_queue.email_id";
     }
 
     return $from;
@@ -114,7 +171,19 @@ class CRM_Mailing_BAO_Query {
 
     $properties = NULL;
     if ($mode & CRM_Contact_BAO_Query::MODE_MAILING) {
-      $properties = array('mailing_id' => 1);
+      $properties = array(
+        'mailing_id' => 1,
+        'mailing_name' => 1,
+        'sort_name' => 1,
+        'email' => 1,
+        'mailing_subject' => 1,
+        'email_on_hold' => 1,
+        'contact_opt_out' => 1,
+        'mailing_job_status' => 1,
+        'mailing_job_end_date' => 1,
+        'contact_type' => 1,
+        'contact_sub_type' => 1
+      );
     }
     return $properties;
   }
diff --git a/CRM/Mailing/Form/Task.php b/CRM/Mailing/Form/Task.php
new file mode 100644 (file)
index 0000000..7076b29
--- /dev/null
@@ -0,0 +1,165 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.4                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2013                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM 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 Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+*/
+
+/**
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC (c) 2004-2013
+ * $Id$
+ *
+ */
+
+/**
+ * This class generates form components for relationship
+ *
+ */
+class CRM_Mailing_Form_Task extends CRM_Core_Form {
+
+  /**
+   * the task being performed
+   *
+   * @var int
+   */
+  protected $_task;
+
+  /**
+   * The additional clause that we restrict the search with
+   *
+   * @var string
+   */
+  protected $_componentClause = NULL;
+
+  /**
+   * The array that holds all the component ids
+   *
+   * @var array
+   */
+  protected $_componentIds;
+
+  /**
+   * The array that holds all the contact ids
+   *
+   * @var array
+   */
+  public $_contactIds;
+
+  /**
+   * build all the data structures needed to build the form
+   *
+   * @param
+   *
+   * @return void
+   * @access public
+   */
+  function preProcess() {
+    self::preProcessCommon($this);
+  }
+
+  static function preProcessCommon(&$form, $useTable = FALSE) {
+    $form->_contactIds = array();
+
+    $values = $form->controller->exportValues($form->get('searchFormName'));
+
+    $form->_task = CRM_Utils_Array::value('task', $values);
+    $mailingTasks = CRM_Mailing_Task::tasks();
+    $form->assign('taskName', CRM_Utils_Array::value('task', $values));
+
+    $ids = array();
+    if ($values['radio_ts'] == 'ts_sel') {
+      foreach ($values as $name => $value) {
+        if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) {
+          $ids[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN);
+        }
+      }
+    }
+    else {
+      $queryParams = $form->get('queryParams');
+      $sortOrder = null;
+      if ( $form->get( CRM_Utils_Sort::SORT_ORDER  ) ) {
+        $sortOrder = $form->get( CRM_Utils_Sort::SORT_ORDER );
+      }
+
+      $query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE,
+        CRM_Contact_BAO_Query::MODE_MAILING
+      );
+
+      $result = $query->searchQuery(0, 0, $sortOrder);
+      while ($result->fetch()) {
+        $ids[] = $result->contact_id;
+      }
+      $form->assign('totalSelectedMailingRecipients', $form->get('rowCount'));
+    }
+
+    if (!empty($ids)) {
+      $form->_componentClause =  ' contact_a.id IN ( ' . implode(',', $ids) . ' ) ';
+    }
+
+    $form->_contactIds = $ids;
+    //set the context for redirection for any task actions
+    $session = CRM_Core_Session::singleton();
+
+    $fragment = 'search';
+    if ($form->_action == CRM_Core_Action::ADVANCED) {
+      $fragment .= '/advanced';
+    }
+
+    $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $form);
+    $urlParams = 'force=1';
+    if (CRM_Utils_Rule::qfKey($qfKey)) {
+      $urlParams .= "&qfKey=$qfKey";
+    }
+
+    $url = CRM_Utils_System::url('civicrm/contact/' . $fragment, $urlParams);
+    $session = CRM_Core_Session::singleton();
+    $session->replaceUserContext($url);
+  }
+
+  /**
+   * simple shell that derived classes can call to add buttons to
+   * the form with a customized title for the main Submit
+   *
+   * @param string $title title of the main button
+   * @param string $type  button type for the form after processing
+   *
+   * @return void
+   * @access public
+   */
+  function addDefaultButtons($title, $nextType = 'next', $backType = 'back', $submitOnce = FALSE) {
+    $this->addButtons(array(
+        array(
+          'type' => $nextType,
+          'name' => $title,
+          'isDefault' => TRUE,
+        ),
+        array(
+          'type' => $backType,
+          'name' => ts('Cancel'),
+        ),
+      )
+    );
+  }
+}
\ No newline at end of file
diff --git a/CRM/Mailing/Form/Task/Print.php b/CRM/Mailing/Form/Task/Print.php
new file mode 100644 (file)
index 0000000..8743b7b
--- /dev/null
@@ -0,0 +1,107 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.4                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2013                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM 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 Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+*/
+
+/**
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC (c) 2004-2013
+ * $Id$
+ *
+ */
+
+/**
+ * This class provides the functionality to print contribution records
+ */
+class CRM_Mailing_Form_Task_Print extends CRM_Mailing_Form_Task {
+
+  /**
+   * build all the data structures needed to build the form
+   *
+   * @return void
+   * @access public
+   */
+  function preProcess() {
+    parent::preprocess();
+
+    // set print view, so that print templates are called
+    $this->controller->setPrint(1);
+
+    // get the formatted params
+    $queryParams = $this->get('queryParams');
+
+    $sortID = NULL;
+    if ($this->get(CRM_Utils_Sort::SORT_ID)) {
+      $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
+        $this->get(CRM_Utils_Sort::SORT_DIRECTION)
+      );
+    }
+
+    $selector = new CRM_Mailing_Selector_Search($queryParams, $this->_action, $this->_componentClause);
+    $controller = new CRM_Core_Selector_Controller($selector, NULL, $sortID, CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::SCREEN);
+    $controller->setEmbedded(TRUE);
+    $controller->run();
+  }
+
+  /**
+   * Build the form - it consists of
+   *    - displaying the QILL (query in local language)
+   *    - displaying elements for saving the search
+   *
+   * @access public
+   *
+   * @return void
+   */
+  function buildQuickForm() {
+    //
+    // just need to add a javacript to popup the window for printing
+    //
+    $this->addButtons(array(
+        array(
+          'type' => 'next',
+          'name' => ts('Print Mailing Recipients'),
+          'js' => array('onclick' => 'window.print()'),
+          'isDefault' => TRUE,
+        ),
+        array(
+          'type' => 'back',
+          'name' => ts('Done'),
+        ),
+      )
+    );
+  }
+
+  /**
+   * process the form after the input has been submitted and validated
+   *
+   * @access public
+   *
+   * @return void
+   */
+  public function postProcess() {
+    // redirect to the main search page after printing is over
+  }
+}
\ No newline at end of file
diff --git a/CRM/Mailing/Selector/Search.php b/CRM/Mailing/Selector/Search.php
new file mode 100644 (file)
index 0000000..e9b20e2
--- /dev/null
@@ -0,0 +1,401 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.4                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2013                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM 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 Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+*/
+
+/**
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC (c) 2004-2013
+ * $Id$
+ *
+ */
+
+/**
+ * This class is used to retrieve and display a range of
+ * contacts that match the given criteria (specifically for
+ * results of advanced search options.
+ *
+ */
+class CRM_Mailing_Selector_Search extends CRM_Core_Selector_Base implements CRM_Core_Selector_API {
+
+  /**
+   * This defines two actions- View and Edit.
+   *
+   * @var array
+   * @static
+   */
+  static $_links = NULL;
+
+  /**
+   * we use desc to remind us what that column is, name is used in the tpl
+   *
+   * @var array
+   * @static
+   */
+  static $_columnHeaders;
+
+  /**
+   * Properties of contact we're interested in displaying
+   * @var array
+   * @static
+   */
+  static $_properties = array(
+    'contact_id',
+    'mailing_id',
+    'mailing_name',
+    'sort_name',
+    'email',
+    'mailing_subject',
+    'email_on_hold',
+    'contact_opt_out',
+    'mailing_job_status',
+    'mailing_job_end_date'
+  );
+
+  /**
+   * are we restricting ourselves to a single contact
+   *
+   * @access protected
+   * @var boolean
+   */
+  protected $_single = FALSE;
+
+  /**
+   * are we restricting ourselves to a single contact
+   *
+   * @access protected
+   * @var boolean
+   */
+  protected $_limit = NULL;
+
+  /**
+   * what context are we being invoked from
+   *
+   * @access protected
+   * @var string
+   */
+  protected $_context = NULL;
+
+  /**
+   * what component context are we being invoked from
+   *
+   * @access protected
+   * @var string
+   */
+  protected $_compContext = NULL;
+
+  /**
+   * queryParams is the array returned by exportValues called on
+   * the HTML_QuickForm_Controller for that page.
+   *
+   * @var array
+   * @access protected
+   */
+  public $_queryParams;
+
+  /**
+   * represent the type of selector
+   *
+   * @var int
+   * @access protected
+   */
+  protected $_action;
+
+  /**
+   * The additional clause that we restrict the search with
+   *
+   * @var string
+   */
+  protected $_mailingClause = NULL;
+
+  /**
+   * The query object
+   *
+   * @var string
+   */
+  protected $_query;
+
+  /**
+   * Class constructor
+   *
+   * @param array $queryParams array of parameters for query
+   * @param int   $action - action of search basic or advanced.
+   * @param string   $mailingClause if the caller wants to further restrict the search (used in contributions)
+   * @param boolean $single are we dealing only with one contact?
+   * @param int     $limit  how many mailing do we want returned
+   *
+   * @return CRM_Contact_Selector
+   * @access public
+   */
+  function __construct(&$queryParams,
+    $action = CRM_Core_Action::NONE,
+    $mailingClause = NULL,
+    $single = FALSE,
+    $limit = NULL,
+    $context = 'search',
+    $compContext = NULL
+  ) {
+    // submitted form values
+    $this->_queryParams = &$queryParams;
+
+    $this->_single      = $single;
+    $this->_limit       = $limit;
+    $this->_context     = $context;
+    $this->_compContext = $compContext;
+
+    $this->_mailingClause = $mailingClause;
+
+    // type of selector
+    $this->_action = $action;
+
+    $this->_query = new CRM_Contact_BAO_Query($this->_queryParams,
+      CRM_Mailing_BAO_Query::defaultReturnProperties(CRM_Contact_BAO_Query::MODE_MAILING,
+        FALSE
+      ),
+      NULL, FALSE, FALSE,
+      CRM_Contact_BAO_Query::MODE_MAILING
+    );
+  }
+  //end of constructor
+
+  /**
+   * This method returns the links that are given for each search row.
+   * currently the links added for each row are
+   *
+   * - View
+   * - Edit
+   *
+   * @return array
+   * @access public
+   *
+   */
+  static function &links() {
+    if (!(self::$_links)) {
+    list($context, $key) = func_get_args();
+    $extraParams = ($key) ? "&key={$key}" : NULL;
+    $searchContext = ($context) ? "&context=$context" : NULL;
+
+    self::$_links = array(
+      CRM_Core_Action::VIEW => array(
+        'name' => ts('View'),
+        'url' => 'civicrm/contact/view',
+        'qs' => "reset=1&cid=%%cid%%{$searchContext}{$extraParams}",
+        'title' => ts('View Contact Details'),
+      ),
+      CRM_Core_Action::UPDATE => array(
+        'name' => ts('Edit'),
+        'url' => 'civicrm/contact/add',
+        'qs' => "reset=1&action=update&cid=%%cid%%{$searchContext}{$extraParams}",
+        'title' => ts('Edit Contact Details'),
+      ),
+      CRM_Core_Action::DELETE => array(
+        'name' => ts('Delete'),
+        'url' => 'civicrm/contact/view/delete',
+        'qs' => "reset=1&delete=1&cid=%%cid%%{$searchContext}{$extraParams}",
+        'title' => ts('Delete Contact'),
+      ),
+    );
+    }
+    return self::$_links;
+  }
+  //end of function
+
+  /**
+   * getter for array of the parameters required for creating pager.
+   *
+   * @param
+   * @access public
+   */
+  function getPagerParams($action, &$params) {
+    $params['status'] = ts('Mailing Recipient') . ' %%StatusMessage%%';
+    $params['csvString'] = NULL;
+    if ($this->_limit) {
+      $params['rowCount'] = $this->_limit;
+    }
+    else {
+      $params['rowCount'] = CRM_Utils_Pager::ROWCOUNT;
+    }
+
+    $params['buttonTop'] = 'PagerTopButton';
+    $params['buttonBottom'] = 'PagerBottomButton';
+  }
+  //end of function
+
+  /**
+   * Returns total number of rows for the query.
+   *
+   * @param
+   *
+   * @return int Total number of rows
+   * @access public
+   */
+  function getTotalCount($action) {
+    return $this->_query->searchQuery(0, 0, NULL,
+      TRUE, FALSE,
+      FALSE, FALSE,
+      FALSE,
+      $this->_mailingClause
+    );
+  }
+
+  /**
+   * returns all the rows in the given offset and rowCount
+   *
+   * @param enum   $action   the action being performed
+   * @param int    $offset   the row number to start from
+   * @param int    $rowCount the number of rows to return
+   * @param string $sort     the sql string that describes the sort order
+   * @param enum   $output   what should the result set include (web/email/csv)
+   *
+   * @return int   the total number of rows for this action
+   */
+  function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
+    $result = $this->_query->searchQuery($offset, $rowCount, $sort,
+      FALSE, FALSE,
+      FALSE, FALSE,
+      FALSE,
+      $this->_mailingClause
+    );
+
+    // process the result of the query
+    $rows = array();
+    $permissions = array(CRM_Core_Permission::getPermission());
+    if (CRM_Core_Permission::check('delete contacts')) {
+      $permissions[] = CRM_Core_Permission::DELETE;
+    }
+    $mask = CRM_Core_Action::mask($permissions);
+    $qfKey = $this->_key;
+
+    While ($result->fetch()) {
+      $row = array();
+      // the columns we are interested in
+      foreach (self::$_properties as $property) {
+        if (property_exists($result, $property)) {
+          $row[$property] = $result->$property;
+        }
+      }
+
+      $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->contact_id;
+
+      $actions = array(
+        'cid' => $result->contact_id,
+        'cxt' => $this->_context,
+      );
+
+      $row['action'] = CRM_Core_Action::formLink(
+        self::links($qfKey, $this->_context),
+        $mask, $actions
+      );
+      $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ?
+        $result->contact_sub_type : $result->contact_type, FALSE, $result->contact_id
+      );
+
+      $rows[] = $row;
+    }
+    return $rows;
+  }
+
+  /**
+   *
+   * @return array   $qill         which contains an array of strings
+   * @access public
+   */
+
+  // the current internationalisation is bad, but should more or less work
+  // for most of "European" languages
+  public function getQILL() {
+    return $this->_query->qill();
+  }
+
+  /**
+   * returns the column headers as an array of tuples:
+   * (name, sortName (key to the sort array))
+   *
+   * @param string $action the action being performed
+   * @param enum   $output what should the result set include (web/email/csv)
+   *
+   * @return array the column headers that need to be displayed
+   * @access public
+   */
+  public function &getColumnHeaders($action = NULL, $output = NULL) {
+    if (!isset(self::$_columnHeaders)) {
+      self::$_columnHeaders = array(
+        array('desc' => ts('Contact Type')),
+        array(
+          'name' => ts('Name'),
+          'sort' => 'sort_name',
+          'direction' => CRM_Utils_Sort::DONTCARE,
+        ),
+        array(
+          'name' => ts('Email'),
+          'sort' => 'email',
+          'direction' => CRM_Utils_Sort::DONTCARE,
+        ),
+        array(
+          'name' => ts('Mailing Name'),
+          'sort' => 'mailing_name',
+          'direction' => CRM_Utils_Sort::DONTCARE,
+        ),
+        array(
+          'name' => ts('Mailing Subject'),
+          'sort' => 'mailing_subject',
+          'direction' => CRM_Utils_Sort::DONTCARE,
+        ),
+        array(
+          'name' => ts('Mailing Status'),
+          'sort' => 'mailing_job_status',
+          'direction' => CRM_Utils_Sort::DONTCARE,
+        ),
+        array(
+          'name' => ts('Completed Date'),
+          'sort' => 'mailing_job_end_date',
+          'direction' => CRM_Utils_Sort::DONTCARE,
+        ),
+        array('desc' => ts('Actions')),
+      );
+    }
+    return self::$_columnHeaders;
+  }
+
+  function alphabetQuery() {
+    return $this->_query->searchQuery(NULL, NULL, NULL, FALSE, FALSE, TRUE);
+  }
+
+  function &getQuery() {
+    return $this->_query;
+  }
+
+  /**
+   * name of export file.
+   *
+   * @param string $output type of output
+   *
+   * @return string name of the file
+   */
+  function getExportFileName($output = 'csv') {
+    return ts('CiviCRM Mailing Search');
+  }
+}
\ No newline at end of file
diff --git a/CRM/Mailing/Task.php b/CRM/Mailing/Task.php
new file mode 100644 (file)
index 0000000..746f1aa
--- /dev/null
@@ -0,0 +1,129 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.4                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2013                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM 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 Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+*/
+
+/**
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC (c) 2004-2013
+ * $Id$
+ *
+ */
+
+/**
+ * class to represent the actions that can be performed on a group of contacts
+ * used by the search forms
+ *
+ */
+class CRM_Mailing_Task {
+  /**
+   * the task array
+   *
+   * @var array
+   * @static
+   */
+  static $_tasks = NULL;
+
+  /**
+   * the optional task array
+   *
+   * @var array
+   * @static
+   */
+  static $_optionalTasks = NULL;
+
+  /**
+   * These tasks are the core set of tasks that the user can perform
+   * on a contact / group of contacts
+   *
+   * @return array the set of tasks for a group of contacts
+   * @static
+   * @access public
+   */
+  static function &tasks() {
+    if (!(self::$_tasks)) {
+      self::$_tasks = array(
+        1 => array('title' => ts('Print Mailing Recipients'),
+          'class' => 'CRM_Mailing_Form_Task_Print',
+          'result' => FALSE,
+        ),
+      );
+
+      CRM_Utils_Hook::searchTasks('mailing', self::$_tasks);
+      asort(self::$_tasks);
+    }
+
+    return self::$_tasks;
+  }
+
+  /**
+   * These tasks are the core set of task titles
+   * on contributors
+   *
+   * @return array the set of task titles
+   * @static
+   * @access public
+   */
+  static function &taskTitles() {
+    return array();
+  }
+
+  /**
+   * show tasks selectively based on the permission level
+   * of the user
+   *
+   * @param int $permission
+   *
+   * @return array set of tasks that are valid for the user
+   * @access public
+   */
+  static function &permissionedTaskTitles($permission) {
+    $task = array();
+    return $task;
+  }
+
+  /**
+   * These tasks are the core set of tasks that the user can perform
+   * on contributors
+   *
+   * @param int $value
+   *
+   * @return array the set of tasks for a group of contributors
+   * @static
+   * @access public
+   */
+  static function getTask($value) {
+    self::tasks();
+    if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) {
+      // make the print task by default
+      $value = 1;
+    }
+    return array(
+      self::$_tasks[$value]['class'],
+      self::$_tasks[$value]['result'],
+    );
+  }
+}
\ No newline at end of file
index e309a4e97ca79d5e44c953768ecefd7f89765624..8782a520c86aa829f80b9d27daefecd9641bfbdc 100644 (file)
@@ -63,6 +63,7 @@ cj(function($) {
     '4': 'activity',
     '5': 'CiviMember',
     '6': 'CiviCase',
+    '8': 'CiviMail'
   };
   // Handle change of results mode
   $('#component_mode').change(function() {
diff --git a/templates/CRM/Mailing/Form/Selector.tpl b/templates/CRM/Mailing/Form/Selector.tpl
new file mode 100644 (file)
index 0000000..824e64c
--- /dev/null
@@ -0,0 +1,80 @@
+{*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.4                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2013                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM 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 Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+*}
+{if $context EQ 'Search'}
+    {include file="CRM/common/pager.tpl" location="top"}
+{/if}
+
+{strip}
+<table class="selector">
+  <thead class="sticky">
+  <tr>
+    {if $context eq 'Search' }
+        <th scope="col" title="Select Rows">{$form.toggleSelect.html}</th>
+    {/if}
+    {foreach from=$columnHeaders item=header}
+        <th scope="col">
+        {if $header.sort}
+          {assign var='key' value=$header.sort}
+          {$sort->_response.$key.link}
+        {else}
+          {$header.name}
+        {/if}
+        </th>
+    {/foreach}
+  </tr>
+  </thead>
+
+  {counter start=0 skip=1 print=false}
+  {foreach from=$rows item=row}
+  <tr id="rowid{$row.contact_id}">
+    {if $context eq 'Search'}
+      {assign var=cbName value=$row.checkbox}
+      <td>{$form.$cbName.html}</td>
+    {/if}
+    <td>{$row.contact_type}</td>
+    <td><a href="{crmURL p='civicrm/contact/view' q="reset=1&cid=`$row.contact_id`&key=`$qfKey`&context=`$context`"}">{$row.sort_name}</a></td>
+    <td {if ($row.email_on_hold eq 1) or ($row.contact_opt_out eq 1)}class='font-red'{/if}>{$row.email}</td>
+    <td>{$row.mailing_name}</td>
+    <td>{$row.mailing_subject}</td>
+    <td>{$row.mailing_job_status}</td>
+    <td class="crm-mailing-end_date">{$row.mailing_job_end_date|crmDate}</td>
+    <td>{$row.action|replace:'xx':$row.contact_id}</td>
+  </tr>
+  {/foreach}
+</table>
+{/strip}
+
+{if $context EQ 'Search'}
+ <script type="text/javascript">
+ {* this function is called to change the color of selected row(s) *}
+    var fname = "{$form.formName}";
+    on_load_init_checkboxes(fname);
+ </script>
+{/if}
+
+{if $context EQ 'Search'}
+    {include file="CRM/common/pager.tpl" location="bottom"}
+{/if}
diff --git a/templates/CRM/Mailing/Form/Task.tpl b/templates/CRM/Mailing/Form/Task.tpl
new file mode 100644 (file)
index 0000000..d976e32
--- /dev/null
@@ -0,0 +1,41 @@
+{*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.4                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2013                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM 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 Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+*}
+{ts 1=$totalSelectedMailingRecipients}Number of selected Mailing Recipients: %1{/ts}
+
+{if $rows } 
+<div class="crm-block crm-form-block crm-mailing-task-form-block">
+<table width="30%">
+  <tr class="columnheader">
+    <th>{ts}Name{/ts}</th>
+  </tr>
+{foreach from=$rows item=row}
+<tr class="{cycle values="odd-row,even-row"}">
+<td>{$row.displayName}</td>
+</tr>
+{/foreach}
+</table>
+</div>
+{/if}
diff --git a/templates/CRM/Mailing/Form/Task/Print.tpl b/templates/CRM/Mailing/Form/Task/Print.tpl
new file mode 100644 (file)
index 0000000..07a850e
--- /dev/null
@@ -0,0 +1,65 @@
+{*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.4                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2013                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM 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 Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+*}
+<p>
+
+{if $rows} 
+<div class="form-item crm-block crm-form-block crm-mailing-form-block">
+     <span class="element-right">{$form.buttons.html}</span>
+</div>
+<div class="spacer"></div>
+<br />
+<p>
+<table>
+  <tr class="columnheader">
+    <th>{ts}Name{/ts}</th>
+    <th>{ts}Email{/ts}</th>
+    <th>{ts}Mailing Name{/ts}</th>
+    <th>{ts}Mailing Subject{/ts}</th>
+    <th>{ts}Mailing Status{/ts}</th>
+    <th>{ts}Completed Date{/ts}</th>
+  </tr>
+{foreach from=$rows item=row}
+    <tr class="{cycle values="odd-row,even-row"} crm-mailing">       
+      <td class='crm-mailing-sort_name'>{$row.sort_name}</td>
+      <td {if ($row.email_on_hold eq 1) or ($row.contact_opt_out eq 1)}class='font-red'{/if}>{$row.email}</td>
+      <td class='crm-mailing-mailing_name'>{$row.mailing_name}</td>
+      <td class='crm-mailing-mailing_subject'>{$row.mailing_subject}</td>
+      <td class='crm-mailing-mailing_job_status'>{$row.mailing_job_status}</td>
+      <td class="crm-mailing-end_date">{$row.mailing_job_end_date|crmDate}</td>
+    </tr>
+{/foreach}
+</table>
+
+<div class="form-item">
+     <span class="element-right">{$form.buttons.html}</span>
+</div>
+
+{else}
+   <div class="messages status no-popup">
+     <div class="icon inform-icon"/>
+        {ts}There are no records selected for Print.{/ts}
+   </div>
+{/if}
index 9e372473af2877f28540aee0a1de6891bfe60647..5c22ff479faca1fe16e8927c922dea8b304744a1 100644 (file)
     {else}
        {$form._qf_Search_next_print.html} &nbsp; &nbsp;
      {/if}
-     {$form.task.html}
-    {if $actionButtonName}
-       {$form.$actionButtonName.html} &nbsp; &nbsp;
-    {else}
-     {$form._qf_Search_next_action.html}
-   {/if}
+   
+      <span id='task-section'>
+        {$form.task.html}
+        {if $actionButtonName}
+          {$form.$actionButtonName.html} &nbsp; &nbsp;
+        {else}
+          {$form._qf_Search_next_action.html}
+        {/if}
+      </span>
     </td>
   </tr>
   </table>
 {literal}
 <script type="text/javascript">
 toggleTaskAction( );
+cj(function() {
+  if (cj('#task option').length == 1 && !cj('#task option').val()) {
+    cj('#task-section').remove();
+  }
+});
 </script>
 {/literal}