Beispiel #1
0
 /**
  * Get the rows for a browse operation
  *
  * @param int $offset       The row number to start from
  * @param int $rowCount     The nmber of rows to return
  * @param string $sort      The sql string that describes the sort order
  * 
  * @return array            The rows
  * @access public
  */
 function &getRows($offset, $rowCount, $sort)
 {
     $mailing = CRM_Mailing_BAO_Mailing::getTableName();
     $job = CRM_Mailing_BAO_Job::getTableName();
     $session =& CRM_Core_Session::singleton();
     $domain_id = $session->get('domainID');
     $query = "\n            SELECT      {$mailing}.id,\n                        {$mailing}.name, \n                        {$job}.status, \n                        MIN({$job}.scheduled_date) as scheduled_date, \n                        MIN({$job}.start_date) as start_date,\n                        MAX({$job}.end_date) as end_date\n            FROM        {$mailing}\n            INNER JOIN  {$job}\n                    ON  {$job}.mailing_id = {$mailing}.id\n            WHERE       {$mailing}.domain_id = {$domain_id}\n            GROUP BY    {$mailing}.id\n            ORDER BY    {$mailing}.id, {$job}.end_date";
     if ($rowCount) {
         $query .= " LIMIT {$offset}, {$rowCount} ";
     }
     $this->query($query);
     $rows = array();
     while ($this->fetch()) {
         $rows[] = array('id' => $this->id, 'name' => $this->name, 'status' => CRM_Mailing_BAO_Job::status($this->status), 'scheduled' => CRM_Utils_Date::customFormat($this->scheduled_date), 'scheduled_iso' => $this->scheduled_date, 'start' => CRM_Utils_Date::customFormat($this->start_date), 'end' => CRM_Utils_Date::customFormat($this->end_date));
     }
     return $rows;
 }
Beispiel #2
0
 /**
  * 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)
 {
     static $actionLinks = null;
     if (empty($actionLinks)) {
         $cancelExtra = ts('Are you sure you want to cancel this mailing?');
         $deleteExtra = ts('Are you sure you want to delete this mailing?');
         $archiveExtra = ts('Are you sure you want to archive this mailing?');
         $actionLinks = array(CRM_Core_Action::VIEW => array('name' => ts('Report'), 'url' => 'civicrm/mailing/report', 'qs' => 'mid=%%mid%%&reset=1', 'title' => ts('View Mailing Report')), CRM_Core_Action::UPDATE => array('name' => ts('Re-Use'), 'url' => 'civicrm/mailing/send', 'qs' => 'mid=%%mid%%&reset=1', 'title' => ts('Re-Send Mailing')), CRM_Core_Action::DISABLE => array('name' => ts('Cancel'), 'url' => 'civicrm/mailing/browse', 'qs' => 'action=disable&mid=%%mid%%&reset=1', 'extra' => 'onclick="if (confirm(\'' . $cancelExtra . '\')) this.href+=\'&confirmed=1\'; else return false;"', 'title' => ts('Cancel Mailing')), CRM_Core_Action::PREVIEW => array('name' => ts('Continue'), 'url' => 'civicrm/mailing/send', 'qs' => 'mid=%%mid%%&continue=true&reset=1', 'title' => ts('Continue Mailing')), CRM_Core_Action::DELETE => array('name' => ts('Delete'), 'url' => 'civicrm/mailing/browse', 'qs' => 'action=delete&mid=%%mid%%&reset=1', 'extra' => 'onclick="if (confirm(\'' . $deleteExtra . '\')) this.href+=\'&confirmed=1\'; else return false;"', 'title' => ts('Delete Mailing')), CRM_Core_Action::RENEW => array('name' => ts('Archive'), 'url' => 'civicrm/mailing/browse/archived', 'qs' => 'action=renew&mid=%%mid%%&reset=1', 'extra' => 'onclick="if (confirm(\'' . $archiveExtra . '\')) this.href+=\'&confirmed=1\'; else return false;"', 'title' => ts('Archive Mailing')));
     }
     $mailing =& new CRM_Mailing_BAO_Mailing();
     $params = array();
     $whereClause = ' AND ' . $this->whereClause($params);
     if (empty($params)) {
         $this->_parent->assign('isSearch', 0);
     } else {
         $this->_parent->assign('isSearch', 1);
     }
     $rows =& $mailing->getRows($offset, $rowCount, $sort, $whereClause, $params);
     //get the search base mailing Ids, CRM-3711.
     $searchMailings = $mailing->searchMailingIDs();
     //check for delete CRM-4418
     require_once 'CRM/Core/Permission.php';
     $allowToDelete = CRM_Core_Permission::check('delete in CiviMail');
     if ($output != CRM_Core_Selector_Controller::EXPORT) {
         foreach ($rows as $key => $row) {
             $actionMask = null;
             if (!($row['status'] == 'Not scheduled')) {
                 $actionMask = CRM_Core_Action::VIEW;
                 if (!in_array($row['id'], $searchMailings)) {
                     $actionMask |= CRM_Core_Action::UPDATE;
                 }
             } else {
                 //FIXME : currently we are hiding continue action for
                 //search base mailing, we should handle it when we fix CRM-3876
                 if (!in_array($row['id'], $searchMailings)) {
                     $actionMask = CRM_Core_Action::PREVIEW;
                 }
             }
             if (in_array($row['status'], array('Scheduled', 'Running', 'Paused'))) {
                 $actionMask |= CRM_Core_Action::DISABLE;
             }
             if ($row['status'] == 'Complete' && !$row['archived']) {
                 $actionMask |= CRM_Core_Action::RENEW;
             }
             //check for delete permission.
             if ($allowToDelete) {
                 $actionMask |= CRM_Core_Action::DELETE;
             }
             //get status strings as per locale settings CRM-4411.
             $rows[$key]['status'] = CRM_Mailing_BAO_Job::status($row['status']);
             $rows[$key]['action'] = CRM_Core_Action::formLink($actionLinks, $actionMask, array('mid' => $row['id']));
             //unset($rows[$key]['id']);
             // if the scheduled date is 0, replace it with an empty string
             if ($rows[$key]['scheduled_iso'] == '0000-00-00 00:00:00') {
                 $rows[$key]['scheduled'] = '';
             }
             unset($rows[$key]['scheduled_iso']);
         }
     }
     // also initialize the AtoZ pager
     $this->pagerAtoZ();
     return $rows;
 }
 /**
  * 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)
 {
     static $actionLinks = NULL;
     if (empty($actionLinks)) {
         $cancelExtra = ts('Are you sure you want to cancel this mailing?');
         $deleteExtra = ts('Are you sure you want to delete this mailing?');
         $archiveExtra = ts('Are you sure you want to archive this mailing?');
         $actionLinks = array(CRM_Core_Action::ENABLE => array('name' => ts('Approve/Reject'), 'url' => 'civicrm/mailing/approve', 'qs' => 'mid=%%mid%%&reset=1', 'title' => ts('Approve/Reject Mailing')), CRM_Core_Action::VIEW => array('name' => ts('Report'), 'url' => 'civicrm/mailing/report', 'qs' => 'mid=%%mid%%&reset=1', 'title' => ts('View Mailing Report')), CRM_Core_Action::UPDATE => array('name' => ts('Re-Use'), 'url' => 'civicrm/mailing/send', 'qs' => 'mid=%%mid%%&reset=1', 'title' => ts('Re-Send Mailing')), CRM_Core_Action::DISABLE => array('name' => ts('Cancel'), 'url' => 'civicrm/mailing/browse', 'qs' => 'action=disable&mid=%%mid%%&reset=1', 'extra' => 'onclick="if (confirm(\'' . $cancelExtra . '\')) this.href+=\'&confirmed=1\'; else return false;"', 'title' => ts('Cancel Mailing')), CRM_Core_Action::PREVIEW => array('name' => ts('Continue'), 'url' => 'civicrm/mailing/send', 'qs' => 'mid=%%mid%%&continue=true&reset=1', 'title' => ts('Continue Mailing')), CRM_Core_Action::DELETE => array('name' => ts('Delete'), 'url' => 'civicrm/mailing/browse', 'qs' => 'action=delete&mid=%%mid%%&reset=1', 'extra' => 'onclick="if (confirm(\'' . $deleteExtra . '\')) this.href+=\'&confirmed=1\'; else return false;"', 'title' => ts('Delete Mailing')), CRM_Core_Action::RENEW => array('name' => ts('Archive'), 'url' => 'civicrm/mailing/browse/archived', 'qs' => 'action=renew&mid=%%mid%%&reset=1', 'extra' => 'onclick="if (confirm(\'' . $archiveExtra . '\')) this.href+=\'&confirmed=1\'; else return false;"', 'title' => ts('Archive Mailing')));
     }
     $allAccess = TRUE;
     $workFlow = $showApprovalLinks = $showScheduleLinks = $showCreateLinks = FALSE;
     if (CRM_Mailing_Info::workflowEnabled()) {
         $allAccess = FALSE;
         $workFlow = TRUE;
         //supercedes all permission
         if (CRM_Core_Permission::check('access CiviMail')) {
             $allAccess = TRUE;
         }
         if (CRM_Core_Permission::check('approve mailings')) {
             $showApprovalLinks = TRUE;
         }
         if (CRM_Core_Permission::check('create mailings')) {
             $showCreateLinks = TRUE;
         }
         if (CRM_Core_Permission::check('schedule mailings')) {
             $showScheduleLinks = TRUE;
         }
     }
     $mailing = new CRM_Mailing_BAO_Mailing();
     $params = array();
     $whereClause = ' AND ' . $this->whereClause($params);
     if (empty($params)) {
         $this->_parent->assign('isSearch', 0);
     } else {
         $this->_parent->assign('isSearch', 1);
     }
     $rows =& $mailing->getRows($offset, $rowCount, $sort, $whereClause, $params);
     //get the search base mailing Ids, CRM-3711.
     $searchMailings = $mailing->searchMailingIDs();
     //check for delete CRM-4418
     $allowToDelete = CRM_Core_Permission::check('delete in CiviMail');
     if ($output != CRM_Core_Selector_Controller::EXPORT) {
         //create the appropriate $op to use for hook_civicrm_links
         $pageTypes = array('view', 'mailing', 'browse');
         if ($this->_parent->_unscheduled) {
             $pageTypes[] = 'unscheduled';
         }
         if ($this->_parent->_scheduled) {
             $pageTypes[] = 'scheduled';
         }
         if ($this->_parent->_archived) {
             $pageTypes[] = 'archived';
         }
         $opString = implode('.', $pageTypes);
         foreach ($rows as $key => $row) {
             $actionMask = NULL;
             if ($row['sms_provider_id']) {
                 $actionLinks[CRM_Core_Action::PREVIEW]['url'] = 'civicrm/sms/send';
             }
             if (!($row['status'] == 'Not scheduled') && !$row['sms_provider_id']) {
                 if ($allAccess || $showCreateLinks) {
                     $actionMask = CRM_Core_Action::VIEW;
                 }
                 if (!in_array($row['id'], $searchMailings)) {
                     if ($allAccess || $showCreateLinks) {
                         $actionMask |= CRM_Core_Action::UPDATE;
                     }
                 }
             } else {
                 //FIXME : currently we are hiding continue action for
                 //search base mailing, we should handle it when we fix CRM-3876
                 if (!in_array($row['id'], $searchMailings)) {
                     if ($allAccess || ($showCreateLinks || $showScheduleLinks)) {
                         $actionMask = CRM_Core_Action::PREVIEW;
                     }
                 }
             }
             if (in_array($row['status'], array('Scheduled', 'Running', 'Paused'))) {
                 if ($allAccess || $showApprovalLinks && $showCreateLinks && $showScheduleLinks) {
                     $actionMask |= CRM_Core_Action::DISABLE;
                 }
                 if ($row['status'] == 'Scheduled' && empty($row['approval_status_id'])) {
                     if ($workFlow && ($allAccess || $showApprovalLinks)) {
                         $actionMask |= CRM_Core_Action::ENABLE;
                     }
                 }
             }
             if ($row['status'] == 'Complete' && !$row['archived']) {
                 if ($allAccess || $showCreateLinks) {
                     $actionMask |= CRM_Core_Action::RENEW;
                 }
             }
             //check for delete permission.
             if ($allowToDelete) {
                 $actionMask |= CRM_Core_Action::DELETE;
             }
             if ($actionMask == NULL) {
                 $actionMask = CRM_Core_Action::ADD;
             }
             //get status strings as per locale settings CRM-4411.
             $rows[$key]['status'] = CRM_Mailing_BAO_Job::status($row['status']);
             $rows[$key]['action'] = CRM_Core_Action::formLink($actionLinks, $actionMask, array('mid' => $row['id']), "more", FALSE, $opString, "Mailing", $row['id']);
             //unset($rows[$key]['id']);
             // if the scheduled date is 0, replace it with an empty string
             if ($rows[$key]['scheduled_iso'] == '0000-00-00 00:00:00') {
                 $rows[$key]['scheduled'] = '';
             }
             unset($rows[$key]['scheduled_iso']);
         }
     }
     // also initialize the AtoZ pager
     $this->pagerAtoZ();
     return $rows;
 }