Ejemplo n.º 1
0
 /**
  * Form rule to validate the date selector and/or if we should deliver
  * immediately.
  *
  * Warning: if you make changes here, be sure to also make them in
  * Retry.php
  * 
  * @param array $params     The form values
  * @return boolean          True if either we deliver immediately, or the
  *                          date is properly set.
  * @static
  */
 function &formRule(&$params)
 {
     if ($params['now']) {
         return true;
     }
     if (!CRM_Utils_Rule::qfDate($params['start_date'])) {
         return array('start_date' => ts('Start date is not valid.'));
     }
     if (CRM_Utils_Date::format($params['start_date']) < date('YmdHi00')) {
         return array('start_date' => ts('Start date cannot be earlier than the current time.'));
     }
     return true;
 }
 /**
  * Function for validation
  *
  * @param array $params (ref.) an assoc array of name/value pairs
  *
  * @return mixed true or array of errors
  * @access public
  * @static
  */
 static function formRule($params)
 {
     $errors = array();
     if (!isset($params['_qf_MembershipType_refresh']) || !$params['_qf_MembershipType_refresh']) {
         if (!$params['name']) {
             $errors['name'] = ts('Please enter a membership type name.');
         }
         if (!CRM_Utils_Array::value('contact_check', $params) && $params['action'] != CRM_Core_Action::UPDATE) {
             $errors['member_org'] = ts('Please select the membership organization');
         }
         if (empty($params['contribution_type_id'])) {
             $errors['contribution_type_id'] = ts('Please enter a contribution type.');
         }
         if ($params['minimum_fee'] > 0 && !$params['contribution_type_id']) {
             $errors['contribution_type_id'] = ts('Please enter the contribution type.');
         }
         if (empty($params['duration_unit'])) {
             $errors['duration_unit'] = ts('Please enter a duration unit.');
         }
         if (empty($params['duration_interval']) and $params['duration_unit'] != 'lifetime') {
             $errors['duration_interval'] = ts('Please enter a duration interval.');
         }
         if (in_array(CRM_Utils_Array::value('auto_renew', $params), array(1, 2))) {
             if ($params['duration_interval'] > 1 && $params['duration_unit'] == 'year' || $params['duration_interval'] > 12 && $params['duration_unit'] == 'month') {
                 $errors['duration_unit'] = ts('Automatic renewals are not supported by the currently available payment processors when the membership duration is greater than 1 year / 12 months.');
             }
         }
         if (empty($params['period_type'])) {
             $errors['period_type'] = ts('Please select a period type.');
         }
         if ($params['period_type'] == 'fixed' && $params['duration_unit'] == 'day') {
             $errors['period_type'] = ts('Period type should be Rolling when duration unit is Day');
         }
         $config = CRM_Core_Config::singleton();
         if ($params['period_type'] == 'fixed' && $params['duration_unit'] == 'year') {
             $periods = array('fixed_period_start_day', 'fixed_period_rollover_day');
             foreach ($periods as $period) {
                 $month = $params[$period]['M'];
                 $date = $params[$period]['d'];
                 if (!$month || !$date) {
                     switch ($period) {
                         case 'fixed_period_start_day':
                             $errors[$period] = ts('Please enter a valid fixed period start day');
                             break;
                         case 'fixed_period_rollover_day':
                             $errors[$period] = ts('Please enter a valid fixed period rollover day');
                             break;
                     }
                 }
             }
         }
     }
     if ($params['fixed_period_start_day'] && !empty($params['fixed_period_start_day'])) {
         $params['fixed_period_start_day']['Y'] = date('Y');
         if (!CRM_Utils_Rule::qfDate($params['fixed_period_start_day'])) {
             $errors['fixed_period_start_day'] = ts('Please enter valid Fixed Period Start Day');
         }
     }
     if ($params['fixed_period_rollover_day'] && !empty($params['fixed_period_rollover_day'])) {
         $params['fixed_period_rollover_day']['Y'] = date('Y');
         if (!CRM_Utils_Rule::qfDate($params['fixed_period_rollover_day'])) {
             $errors['fixed_period_rollover_day'] = ts('Please enter valid Fixed Period Rollover Day');
         }
     }
     $renewalReminderDay = CRM_Utils_Array::value('renewal_reminder_day', $params);
     $renewalMsgId = CRM_Utils_Array::value('renewal_msg_id', $params);
     $autoRenewalMsgId = CRM_Utils_Array::value('autorenewal_msg_id', $params);
     // FIXME: Commented out this form rule for 4.2 so that admins can disable existing membership type based renewal reminders when they
     // implement the new reminder method via Schedule Reminders. CRM-8359 dgg
     /*
     if (!((($renewalReminderDay && $renewalMsgId)) || (!$renewalReminderDay && !$renewalMsgId))) {
       if (!$renewalReminderDay) {
         $errors['renewal_reminder_day'] = ts('Please enter renewal reminder days.');
       }
       elseif (!$renewalMsgId && (isset($params['autorenewal_msg_id']) && !$autoRenewalMsgId)) {
         $errors['renewal_msg_id'] = ts('Please select renewal message.');
       }
     }
     */
     return empty($errors) ? TRUE : $errors;
 }
Ejemplo n.º 3
0
 /**
  * Validation.
  *
  * @param array $params
  *   (ref.) an assoc array of name/value pairs.
  *
  * @return bool|array
  *   mixed true or array of errors
  */
 public static function formRule($params)
 {
     $errors = array();
     if (!$params['name']) {
         $errors['name'] = ts('Please enter a membership type name.');
     }
     if ($params['minimum_fee'] > 0 && !$params['financial_type_id']) {
         $errors['financial_type_id'] = ts('Please enter the financial Type.');
     }
     if (empty($params['duration_interval']) and $params['duration_unit'] != 'lifetime') {
         $errors['duration_interval'] = ts('Please enter a duration interval.');
     }
     if (in_array(CRM_Utils_Array::value('auto_renew', $params), array(1, 2))) {
         if ($params['duration_interval'] > 1 && $params['duration_unit'] == 'year' || $params['duration_interval'] > 12 && $params['duration_unit'] == 'month') {
             $errors['duration_unit'] = ts('Automatic renewals are not supported by the currently available payment processors when the membership duration is greater than 1 year / 12 months.');
         }
     }
     if ($params['period_type'] == 'fixed' && $params['duration_unit'] == 'day') {
         $errors['period_type'] = ts('Period type should be Rolling when duration unit is Day');
     }
     if ($params['period_type'] == 'fixed' && $params['duration_unit'] == 'year') {
         $periods = array('fixed_period_start_day', 'fixed_period_rollover_day');
         foreach ($periods as $period) {
             $month = $params[$period]['M'];
             $date = $params[$period]['d'];
             if (!$month || !$date) {
                 switch ($period) {
                     case 'fixed_period_start_day':
                         $errors[$period] = ts('Please enter a valid fixed period start day');
                         break;
                     case 'fixed_period_rollover_day':
                         $errors[$period] = ts('Please enter a valid fixed period rollover day');
                         break;
                 }
             }
         }
     }
     if ($params['fixed_period_start_day'] && !empty($params['fixed_period_start_day'])) {
         $params['fixed_period_start_day']['Y'] = date('Y');
         if (!CRM_Utils_Rule::qfDate($params['fixed_period_start_day'])) {
             $errors['fixed_period_start_day'] = ts('Please enter valid Fixed Period Start Day');
         }
     }
     if ($params['fixed_period_rollover_day'] && !empty($params['fixed_period_rollover_day'])) {
         $params['fixed_period_rollover_day']['Y'] = date('Y');
         if (!CRM_Utils_Rule::qfDate($params['fixed_period_rollover_day'])) {
             $errors['fixed_period_rollover_day'] = ts('Please enter valid Fixed Period Rollover Day');
         }
     }
     return empty($errors) ? TRUE : $errors;
 }
Ejemplo n.º 4
0
 /**
  * Function for validation
  *
  * @param array $params (ref.) an assoc array of name/value pairs
  *
  * @return mixed true or array of errors
  * @access public
  * @static
  */
 public function formRule(&$params)
 {
     require_once 'CRM/Utils/Rule.php';
     $errors = array();
     if (!isset($params['_qf_MembershipType_refresh']) || !$params['_qf_MembershipType_refresh']) {
         if (!$params['name']) {
             $errors['name'] = ts('Please enter a membership type name.');
         }
         if (!CRM_Utils_Array::value('contact_check', $params) && $params['action'] != CRM_Core_Action::UPDATE) {
             $errors['member_org'] = ts('Please select the membership organization');
         }
         if (empty($params['contribution_type_id'])) {
             $errors['contribution_type_id'] = ts('Please enter a contribution type.');
         }
         if ($params['minimum_fee'] > 0 && !$params['contribution_type_id']) {
             $errors['contribution_type_id'] = ts('Please enter the contribution type.');
         }
         if (empty($params['duration_unit'])) {
             $errors['duration_unit'] = ts('Please enter a duration unit.');
         }
         if (empty($params['duration_interval']) and $params['duration_unit'] != 'lifetime') {
             $errors['duration_interval'] = ts('Please enter a duration interval.');
         }
         if (empty($params['period_type'])) {
             $errors['period_type'] = ts('Please select a period type.');
         }
         if ($params['period_type'] == 'fixed' && $params['duration_unit'] == 'day') {
             $errors['period_type'] = ts('Period type should be Rolling when duration unit is Day');
         }
         $config =& CRM_Core_Config::singleton();
         if ($params['period_type'] == 'fixed' && $params['duration_unit'] == 'year') {
             $periods = array('fixed_period_start_day', 'fixed_period_rollover_day');
             foreach ($periods as $period) {
                 $month = $params[$period][$config->dateformatMonthVar];
                 $date = $params[$period]['d'];
                 if (!$month || !$date) {
                     switch ($period) {
                         case 'fixed_period_start_day':
                             $errors[$period] = ts('Please enter a valid fixed period start day');
                             break;
                         case 'fixed_period_rollover_day':
                             $errors[$period] = ts('Please enter a valid fixed period rollover day');
                             break;
                     }
                 }
             }
         }
     }
     if ($params['fixed_period_start_day'] && !empty($params['fixed_period_start_day'])) {
         $params['fixed_period_start_day']['Y'] = date('Y');
         if (!CRM_Utils_Rule::qfDate($params['fixed_period_start_day'])) {
             $errors['fixed_period_start_day'] = ts('Please enter valid Fixed Period Start Day');
         }
     }
     if ($params['fixed_period_rollover_day'] && !empty($params['fixed_period_rollover_day'])) {
         $params['fixed_period_rollover_day']['Y'] = date('Y');
         if (!CRM_Utils_Rule::qfDate($params['fixed_period_rollover_day'])) {
             $errors['fixed_period_rollover_day'] = ts('Please enter valid Fixed Period Rollover Day');
         }
     }
     $renewalReminderDay = CRM_Utils_Array::value('renewal_reminder_day', $params);
     $renewalMsgId = CRM_Utils_Array::value('renewal_msg_id', $params);
     if (!($renewalReminderDay && $renewalMsgId || !$renewalReminderDay && !$renewalMsgId)) {
         if (!$renewalReminderDay) {
             $errors['renewal_reminder_day'] = ts('Please enter renewal reminder days.');
         } elseif (!$renewalMsgId) {
             $errors['renewal_msg_id'] = ts('Please select renewal message.');
         }
     }
     return empty($errors) ? true : $errors;
 }
/**
 * take the input parameter list as specified in the data model and
 * convert it into the same format that we use in QF and BAO object
 *
 * @param array  $params       Associative array of property name/value
 *                             pairs to insert in new contact.
 * @param array  $values       The reformatted properties that we can use internally
 *                            '
 *
 * @return array|CRM_Error
 * @access public
 */
function _civicrm_relationship_format_params(&$params, &$values)
{
    // copy all the relationship fields as is
    $fields = CRM_Contact_DAO_Relationship::fields();
    _civicrm_store_values($fields, $params, $values);
    $relationTypes = CRM_Core_PseudoConstant::relationshipType('name', TRUE);
    foreach ($params as $key => $value) {
        // ignore empty values or empty arrays etc
        require_once 'CRM/Utils/System.php';
        if (CRM_Utils_System::isNull($value)) {
            continue;
        }
        switch ($key) {
            case 'contact_id_a':
            case 'contact_id_b':
                require_once 'CRM/Utils/Rule.php';
                if (!CRM_Utils_Rule::integer($value)) {
                    return civicrm_create_error("contact_id not valid: {$value}");
                }
                $dao = new CRM_Core_DAO();
                $qParams = array();
                $svq = $dao->singleValueQuery("SELECT id FROM civicrm_contact WHERE id = {$value}", $qParams);
                if (!$svq) {
                    return civicrm_create_error("Invalid Contact ID: There is no contact record with contact_id = {$value}.");
                }
                break;
            case 'start_date':
            case 'end_date':
                if (!CRM_Utils_Rule::qfDate($value)) {
                    return civicrm_create_error("{$key} not a valid date: {$value}");
                }
                break;
            case 'relationship_type':
                foreach ($relationTypes as $relTypId => $relValue) {
                    if (CRM_Utils_Array::key(ucfirst($value), $relValue)) {
                        $relationshipTypeId = $relTypId;
                        break;
                    }
                }
                if ($relationshipTypeId) {
                    if (CRM_Utils_Array::value('relationship_type_id', $values) && $relationshipTypeId != $values['relationship_type_id']) {
                        return civicrm_create_error('Mismatched Relationship Type and Relationship Type Id');
                    }
                    $values['relationship_type_id'] = $params['relationship_type_id'] = $relationshipTypeId;
                } else {
                    return civicrm_create_error('Invalid Relationship Type');
                }
            case 'relationship_type_id':
                if ($key == 'relationship_type_id' && !array_key_exists($value, $relationTypes)) {
                    return civicrm_create_error("{$key} not a valid: {$value}");
                }
                // execute for both relationship_type and relationship_type_id
                $relation = $relationTypes[$params['relationship_type_id']];
                require_once 'CRM/Contact/BAO/Contact.php';
                if ($relation['contact_type_a'] && $relation['contact_type_a'] != CRM_Contact_BAO_Contact::getContactType($params['contact_id_a'])) {
                    return civicrm_create_error("Contact ID :{$params['contact_id_a']} is not of contact type {$relation['contact_type_a']}");
                }
                if ($relation['contact_type_b'] && $relation['contact_type_b'] != CRM_Contact_BAO_Contact::getContactType($params['contact_id_b'])) {
                    return civicrm_create_error("Contact ID :{$params['contact_id_b']} is not of contact type {$relation['contact_type_b']}");
                }
                break;
            default:
                break;
        }
    }
    if (array_key_exists('note', $params)) {
        $values['note'] = $params['note'];
    }
    _civicrm_custom_format_params($params, $values, 'Relationship');
    return array();
}
Ejemplo n.º 6
0
 /**
  * Form rule to validate the date selector and/or if we should deliver
  * immediately.
  *
  * Warning: if you make changes here, be sure to also make them in
  * Retry.php
  * 
  * @param array $params     The form values
  * @return boolean          True if either we deliver immediately, or the
  *                          date is properly set.
  * @static
  */
 public static function formRule(&$params, &$files, &$self)
 {
     if ($params['_qf_Schedule_submit']) {
         //when user perform mailing from search context
         //redirect it to search result CRM-3711.
         $ssID = $self->get('ssID');
         $context = $self->get('context');
         if ($ssID && $context == 'search') {
             if ($self->_action == CRM_Core_Action::BASIC) {
                 $fragment = 'search';
             } else {
                 if ($self->_action == CRM_Core_Action::PROFILE) {
                     $fragment = 'search/builder';
                 } else {
                     if ($self->_action == CRM_Core_Action::ADVANCED) {
                         $fragment = 'search/advanced';
                     } else {
                         $fragment = 'search/custom';
                     }
                 }
             }
             $draftURL = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1');
             $status = ts("Your mailing has been saved. You can continue later by clicking the 'Continue' action to resume working on it.<br /> From <a href='%1'>Draft and Unscheduled Mailings</a>.", array(1 => $draftURL));
             CRM_Core_Session::setStatus($status);
             //replace user context to search.
             $url = CRM_Utils_System::url("civicrm/contact/" . $fragment, "force=1&reset=1&ssID={$ssID}");
             CRM_Utils_System::redirect($url);
         } else {
             CRM_Core_Session::setStatus(ts("Your mailing has been saved. Click the 'Continue' action to resume working on it."));
             $url = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1');
             CRM_Utils_System::redirect($url);
         }
     }
     if (isset($params['now']) || $params['_qf_Schedule_back'] == '<< Previous') {
         return true;
     }
     if (!CRM_Utils_Rule::qfDate($params['start_date'])) {
         return array('start_date' => ts('Scheduled date is not valid.'));
     }
     if (CRM_Utils_Date::format(CRM_Utils_Date::processDate($params['start_date'])) < date('YmdHi00')) {
         return array('start_date' => ts('Start date cannot be earlier than the current time.'));
     }
     return true;
 }