/** * Returns all the rows in the given offset and rowCount. * * @param string $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 string $output * What should the result set include (web/email/csv). * * @return int * the total number of rows for this action */ public 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 { 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 (in_array($row['status'], array('Complete', 'Canceled')) && !$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_MailingJob::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; }