/** * Build the form object. * * @return void */ public function buildQuickForm() { // add the email address $this->add('text', 'email', ts('Email'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', 'email'), TRUE); $this->addRule('email', ts("Please enter a valid email address."), 'email'); if (!$this->_groupID) { // create a selector box of all public groups $groupTypeCondition = CRM_Contact_BAO_Group::groupTypeCondition('Mailing'); $query = "\nSELECT id, title, description\n FROM civicrm_group\n WHERE ( saved_search_id = 0\n OR saved_search_id IS NULL )\n AND visibility != 'User and User Admin Only'\n AND {$groupTypeCondition}\nORDER BY title"; $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); $rows = array(); while ($dao->fetch()) { $row = array(); $row['id'] = $dao->id; $row['title'] = $dao->title; $row['description'] = $dao->description; $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $row['id']; $this->addElement('checkbox', $row['checkbox'], NULL, NULL); $rows[] = $row; } if (empty($rows)) { CRM_Core_Error::fatal(ts('There are no public mailing list groups to display.')); } $this->assign('rows', $rows); $this->addFormRule(array('CRM_Mailing_Form_Subscribe', 'formRule')); } $addCaptcha = TRUE; // if recaptcha is not configured, then dont add it // CRM-11316 Only enable ReCAPTCHA for anonymous visitors $config = CRM_Core_Config::singleton(); $session = CRM_Core_Session::singleton(); $contactID = $session->get('userID'); if (empty($config->recaptchaPublicKey) || empty($config->recaptchaPrivateKey) || $contactID) { $addCaptcha = FALSE; } else { // if this is POST request and came from a block, // lets add recaptcha only if already present // gross hack for now if (!empty($_POST) && !array_key_exists('recaptcha_challenge_field', $_POST)) { $addCaptcha = FALSE; } } if ($addCaptcha) { // add captcha $captcha = CRM_Utils_ReCAPTCHA::singleton(); $captcha->add($this); $this->assign('isCaptcha', TRUE); } $this->addButtons(array(array('type' => 'next', 'name' => ts('Subscribe'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); }
/** * Get all permissioned groups from database * * The static array group is returned, and if it's * called the first time, the <b>Group DAO</b> is used * to get all the groups. * * Note: any database errors will be trapped by the DAO. * * @access public * @static * * @return array - array reference of all groups. * */ public static function &staticGroup($onlyPublic = FALSE, $groupType = NULL, $excludeHidden = TRUE) { if (!self::$staticGroup) { $condition = 'saved_search_id = 0 OR saved_search_id IS NULL'; if ($onlyPublic) { $condition .= " AND visibility != 'User and User Admin Only'"; } if ($groupType) { $condition .= ' AND ' . CRM_Contact_BAO_Group::groupTypeCondition($groupType); } if ($excludeHidden) { $condition .= ' AND is_hidden != 1 '; } self::populate(self::$staticGroup, 'CRM_Contact_DAO_Group', FALSE, 'title', 'is_active', $condition, 'title'); } return self::$staticGroup; }
/** * Get all permissioned groups from database * * The static array group is returned, and if it's * called the first time, the <b>Group DAO</b> is used * to get all the groups. * * Note: any database errors will be trapped by the DAO. * * @access public * @static * * @return array - array reference of all groups. * */ public static function &staticGroup($onlyPublic = false, $groupType = null) { if (!self::$staticGroup) { $condition = 'saved_search_id = 0 OR saved_search_id IS NULL'; if ($onlyPublic) { $condition .= " AND visibility != 'User and User Admin Only'"; } if ($groupType) { require_once 'CRM/Contact/BAO/Group.php'; $condition .= ' AND ' . CRM_Contact_BAO_Group::groupTypeCondition($groupType); } self::populate(self::$staticGroup, 'CRM_Contact_DAO_Group', false, 'title', 'is_active', $condition, 'title'); } return self::$staticGroup; }