/**
  * Function to build Pledge Block in Contribution Pages
  *
  * @param obj $form
  * @static
  */
 static function buildPledgeBlock($form)
 {
     //build pledge payment fields.
     if (!empty($form->_values['pledge_id'])) {
         //get all payments required details.
         $allPayments = array();
         $returnProperties = array('status_id', 'scheduled_date', 'scheduled_amount', 'currency');
         CRM_Core_DAO::commonRetrieveAll('CRM_Pledge_DAO_PledgePayment', 'pledge_id', $form->_values['pledge_id'], $allPayments, $returnProperties);
         //get all status
         $allStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
         $nextPayment = array();
         $isNextPayment = FALSE;
         $overduePayments = array();
         $now = date('Ymd');
         foreach ($allPayments as $payID => $value) {
             if ($allStatus[$value['status_id']] == 'Overdue') {
                 $overduePayments[$payID] = array('id' => $payID, 'scheduled_amount' => CRM_Utils_Rule::cleanMoney($value['scheduled_amount']), 'scheduled_amount_currency' => $value['currency'], 'scheduled_date' => CRM_Utils_Date::customFormat($value['scheduled_date'], '%B %d'));
             } elseif (!$isNextPayment && $allStatus[$value['status_id']] == 'Pending') {
                 //get the next payment.
                 $nextPayment = array('id' => $payID, 'scheduled_amount' => CRM_Utils_Rule::cleanMoney($value['scheduled_amount']), 'scheduled_amount_currency' => $value['currency'], 'scheduled_date' => CRM_Utils_Date::customFormat($value['scheduled_date'], '%B %d'));
                 $isNextPayment = TRUE;
             }
         }
         //build check box array for payments.
         $payments = array();
         if (!empty($overduePayments)) {
             foreach ($overduePayments as $id => $payment) {
                 $key = ts("%1 - due on %2 (overdue)", array(1 => CRM_Utils_Money::format(CRM_Utils_Array::value('scheduled_amount', $payment), CRM_Utils_Array::value('scheduled_amount_currency', $payment)), 2 => CRM_Utils_Array::value('scheduled_date', $payment)));
                 $payments[$key] = CRM_Utils_Array::value('id', $payment);
             }
         }
         if (!empty($nextPayment)) {
             $key = ts("%1 - due on %2", array(1 => CRM_Utils_Money::format(CRM_Utils_Array::value('scheduled_amount', $nextPayment), CRM_Utils_Array::value('scheduled_amount_currency', $nextPayment)), 2 => CRM_Utils_Array::value('scheduled_date', $nextPayment)));
             $payments[$key] = CRM_Utils_Array::value('id', $nextPayment);
         }
         //give error if empty or build form for payment.
         if (empty($payments)) {
             CRM_Core_Error::fatal(ts("Oops. It looks like there is no valid payment status for online payment."));
         } else {
             $form->assign('is_pledge_payment', TRUE);
             $form->addCheckBox('pledge_amount', ts('Make Pledge Payment(s):'), $payments);
         }
     } else {
         $pledgeBlock = self::getPledgeBlock($form->_id);
         //build form for pledge creation.
         $pledgeOptions = array('0' => ts('I want to make a one-time contribution'), '1' => ts('I pledge to contribute this amount every'));
         $form->addRadio('is_pledge', ts('Pledge Frequency Interval'), $pledgeOptions, NULL, array('<br/>'));
         $form->addElement('text', 'pledge_installments', ts('Installments'), array('size' => 3));
         if (!empty($pledgeBlock['is_pledge_interval'])) {
             $form->assign('is_pledge_interval', CRM_Utils_Array::value('is_pledge_interval', $pledgeBlock));
             $form->addElement('text', 'pledge_frequency_interval', NULL, array('size' => 3));
         } else {
             $form->add('hidden', 'pledge_frequency_interval', 1);
         }
         //Frequency unit drop-down label suffixes switch from *ly to *(s)
         $freqUnitVals = explode(CRM_Core_DAO::VALUE_SEPARATOR, $pledgeBlock['pledge_frequency_unit']);
         $freqUnits = array();
         $frequencyUnits = CRM_Core_OptionGroup::values('recur_frequency_units');
         foreach ($freqUnitVals as $key => $val) {
             if (array_key_exists($val, $frequencyUnits)) {
                 $freqUnits[$val] = !empty($pledgeBlock['is_pledge_interval']) ? "{$frequencyUnits[$val]}(s)" : $frequencyUnits[$val];
             }
         }
         $form->addElement('select', 'pledge_frequency_unit', NULL, $freqUnits);
     }
 }
Beispiel #2
0
 /**
  *
  * @param obj $criteria
  * @param str $perm_name
  */
 public function setGrantedObjectsCriteria(&$criteria, $perm_name)
 {
     $icmspermissions_handler = new icms_ipf_permission_Handler($this);
     $grantedItems = $icmspermissions_handler->getGrantedItems($perm_name);
     if (count($grantedItems) > 0) {
         $criteria->add(new icms_db_criteria_Item($this->keyName, '(' . implode(', ', $grantedItems) . ')', 'IN'));
         return true;
     } else {
         return false;
     }
 }
/**
 * Prepare the user nicename for updating if applicable.
 *
 * The actual updating is handled by WP as long as no errors are thrown
 * by WP, some third party, or us.
 *
 * @since 0.1.0
 *
 * @param obj $errors WP_Errors object
 * @param bool $update Are we updating?
 * @param obj WP_User object
 *
 * @uses check_admin_referer() To verify the nonce and check referer.
 * @uses ba_eas_can_edit_author_slug() To verify current user can edit the author slug.
 * @uses get_userdata() To get the user data.
 * @uses WP_Errors::add() To add Edit Author Slug specific errors.
 * @uses sanitize_title() Used to sanitize user_nicename.
 * @uses remove_action() To remove the 'ba_eas_auto_update_user_nicename_single' and prevent looping.
 * @uses get_user_by() To see if the nicename is already in use.
 * @uses add_action() To add the 'ba_eas_auto_update_user_nicename_single' back.
 */
function ba_eas_update_user_nicename($errors, $update, $user)
{
    // We shouldn't be here if we're not updating
    if (!$update) {
        return;
    }
    // Check the nonce
    check_admin_referer('update-user_' . $user->ID);
    // Bail early if user can't edit the slug
    if (!ba_eas_can_edit_author_slug()) {
        return;
    }
    // Setup the user_id
    $user_id = (int) $user->ID;
    // Stash the original user object
    $_user = $user;
    // Check for a custom author slug
    if (!empty($_POST['ba_eas_author_slug']) && isset($_POST['ba_eas_author_slug_custom']) && '\\c\\u\\s\\t\\o\\m' == stripslashes($_POST['ba_eas_author_slug'])) {
        $_POST['ba_eas_author_slug'] = $_POST['ba_eas_author_slug_custom'];
    }
    // Setup the author slug
    $author_slug = '';
    if (isset($_POST['ba_eas_author_slug'])) {
        $author_slug = trim(stripslashes($_POST['ba_eas_author_slug']));
    }
    // Do we have an author slug?
    if (empty($author_slug)) {
        $errors->add('ba_edit_author_slug', __('<strong>ERROR</strong>: An author slug cannot be blank. Please try again.'));
        return;
    }
    // Prepare the author slug
    $author_slug = sanitize_title($author_slug);
    // Don't run the auto-update when the current user can update nicenames
    remove_action('profile_update', 'ba_eas_auto_update_user_nicename_single');
    // Maybe update the author slug?
    if ($author_slug != $_user->user_nicename) {
        // Add the wpdb global only when necessary
        global $wpdb;
        // Do we have an author slug?
        if (empty($author_slug)) {
            $errors->add('ba_edit_author_slug', __('<strong>ERROR</strong>: That author slug appears to be invalid. Please try something different.'));
            return;
        }
        // Does this author slug already exist?
        if (get_user_by('slug', $author_slug) && (int) get_user_by('slug', $author_slug)->ID !== $user_id) {
            $errors->add('ba_edit_author_slug', sprintf(__('<strong>ERROR</strong>: The author slug, %1$s, already exists. Please try something different.'), '<strong><em>' . esc_attr($author_slug) . '</em></strong>'));
            return;
        }
        // Looks like we made it, so let's update
        $user->user_nicename = $author_slug;
        // Update the nicename cache
        add_action('profile_update', 'ba_eas_update_nicename_cache', 10, 2);
    }
}