public function postProcess() { $params = $this->_submitValues; $batchDetailsSql = " UPDATE civicrm_batch SET "; $batchDetailsSql .= " title = %1 "; $batchDetailsSql .= " , description = %2 "; $batchDetailsSql .= " , banking_account = %3 "; $batchDetailsSql .= " , banking_date = %4 "; $batchDetailsSql .= " , exclude_from_posting = %5 "; $batchDetailsSql .= " , contribution_type_id = %6 "; $batchDetailsSql .= " , payment_instrument_id = %7 "; $batchDetailsSql .= " WHERE id = %8 "; $bankingDate = CRM_Utils_Date::processDate($params['banking_date']); $sqlParams = array(); $sqlParams[1] = array((string) $params['batch_title'], 'String'); $sqlParams[2] = array((string) $params['description'], 'String'); $sqlParams[3] = array((string) $params['banking_account'], 'String'); $sqlParams[4] = array((string) $bankingDate, 'String'); $sqlParams[5] = array((string) $params['exclude_from_posting'], 'String'); $sqlParams[6] = array((string) $params['contribution_type_id'], 'String'); $sqlParams[7] = array((string) $params['payment_instrument_id'], 'String'); $sqlParams[8] = array((int) $params['id'], 'Integer'); CRM_Core_DAO::executeQuery($batchDetailsSql, $sqlParams); drupal_goto('civicrm/batch/process', array('query' => array('bid' => $params['id'], 'reset' => '1'))); CRM_Utils_System::civiExit(); }
/** * Set the default form values. * * @return array * the default array reference */ public function setDefaultValues() { $defaults = array(); // note we intentionally overwrite value since we use it as defaults // and its all pass by value // we need to figure out the type, so we can either set an array element // or a scalar -- FIX ME sometime please foreach ($_GET as $key => $value) { if (substr($key, 0, 7) == 'custom_' || $key == "preferred_communication_method") { if (strpos($value, CRM_Core_DAO::VALUE_SEPARATOR) !== FALSE) { $v = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value); $value = array(); foreach ($v as $item) { if ($item) { $value[$item] = $item; } } } } elseif ($key == 'group' || $key == 'tag') { $v = explode(',', $value); $value = array(); foreach ($v as $item) { $value[$item] = 1; } } elseif (in_array($key, array('birth_date', 'deceased_date'))) { list($value) = CRM_Utils_Date::setDateDefaults($value); } $defaults[$key] = $value; } return $defaults; }
static function postProcessStudent($pickupName, $studentID, $atSchoolMeeting = false) { static $_now = null; static $_date = null; if (!$_now) { $_now = CRM_Utils_Date::getToday(null, 'YmdHis'); } if (!$_date) { $_date = CRM_Utils_Date::getToday(null, 'Y-m-d'); } $atSchoolMeeting = $atSchoolMeeting ? '1' : '0'; $sql = "\nSELECT e.id, e.class\nFROM civicrm_value_extended_care_signout e\nWHERE entity_id = %1\nAND DATE(signin_time) = %2\nAND ( is_morning = 0 OR is_morning IS NULL )\n"; $params = array(1 => array($studentID, 'Integer'), 2 => array($_date, 'String')); $dao = CRM_Core_DAO::executeQuery($sql, $params); $params = array(1 => array($studentID, 'Integer'), 2 => array($pickupName, 'String'), 3 => array($_now, 'Timestamp'), 4 => array($atSchoolMeeting, 'Integer')); $class = null; if ($dao->fetch()) { $class = $dao->class; $sql = "\nUPDATE civicrm_value_extended_care_signout\nSET pickup_person_name = %2,\n signout_time = %3,\n at_school_meeting = %4\nWHERE id = %5\n"; $params[5] = array($dao->id, 'Integer'); } else { $sql = "\nINSERT INTO civicrm_value_extended_care_signout\n( entity_id, pickup_person_name, signout_time, at_school_meeting, is_morning )\nVALUES\n( %1, %2, %3, %4, 0 )\n"; } CRM_Core_DAO::executeQuery($sql, $params); return $class; }
/** * Function for building Event combo box */ function event() { $name = trim(CRM_Utils_Type::escape($_GET['s'], 'String')); if (!$name) { $name = '%'; } $whereClause = " title LIKE '{$name}%' AND ( civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0 )"; $includeOld = CRM_Utils_Request::retrieve('includeOld', 'Boolean', CRM_Core_DAO::$_nullObject, FALSE, TRUE); if (!$includeOld) { $whereClause .= " AND ( end_date IS NULL OR end_date >= NOW() )"; } $query = "\n SELECT civicrm_event.title AS title,\n civicrm_event.id AS id,\n civicrm_address.city AS city,\n civicrm_event.start_date\n FROM civicrm_event\n LEFT JOIN civicrm_loc_block ON\n civicrm_event.loc_block_id = civicrm_loc_block.id\n LEFT JOIN civicrm_address ON\n civicrm_loc_block.address_id = civicrm_address.id\n WHERE\n {$whereClause}\n ORDER BY\n civicrm_event.title\n"; $dao = CRM_Core_DAO::executeQuery($query); $results = array(); while ($dao->fetch()) { $fields = array(); foreach (array('title', 'city') as $field) { if (isset($dao->{$field})) { array_push($fields, $dao->{$field}); } } if (isset($dao->start_date)) { array_push($fields, CRM_Utils_Date::customFormat($dao->start_date)); } $results[$dao->id] = implode(' - ', $fields); } CRM_Core_Page_AJAX::autocompleteResults($results); }
/** * Convert the date string "YYYY-MM-DD" to "MM<long> DD, YYYY". * * @param string $dateString date which needs to converted to human readable format * * @return string human readable date format | invalid date message * @access public */ function smarty_modifier_crmDate($dateString, $dateFormat = null) { if ($dateString) { return CRM_Utils_Date::customFormat($dateString, $dateFormat); } return ''; }
/** * @param string $fieldName * @param $field * @param $defaults * * @return bool */ public static function dateParam($fieldName, &$field, &$defaults) { // type = 12 (datetime) is not recognized by Utils_Type::escape() method, // and therefore the below hack $type = 4; $from = self::getTypedValue("{$fieldName}_from", $type); $to = self::getTypedValue("{$fieldName}_to", $type); $relative = CRM_Utils_Array::value("{$fieldName}_relative", $_GET); if ($relative) { list($from, $to) = CRM_Report_Form::getFromTo($relative, NULL, NULL); $from = substr($from, 0, 8); $to = substr($to, 0, 8); } if (!($from || $to)) { return FALSE; } if ($from !== NULL) { $dateFrom = CRM_Utils_Date::setDateDefaults($from); if ($dateFrom !== NULL && !empty($dateFrom[0])) { $defaults["{$fieldName}_from"] = $dateFrom[0]; } } if ($to !== NULL) { $dateTo = CRM_Utils_Date::setDateDefaults($to); if ($dateTo !== NULL && !empty($dateTo[0])) { $defaults["{$fieldName}_to"] = $dateTo[0]; } } }
/** * Set default values for the form. For edit/view mode * the default values are retrieved from the database * * * @return array */ public function setDefaultValues() { $defaults = array(); //Always pass current event's start date by default $currentEventStartDate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_id, 'start_date', 'id'); list($defaults['repetition_start_date'], $defaults['repetition_start_date_time']) = CRM_Utils_Date::setDateDefaults($currentEventStartDate, 'activityDateTime'); $recurringEntityDefaults = CRM_Core_Form_RecurringEntity::setDefaultValues(); return array_merge($defaults, $recurringEntityDefaults); }
/** * Get a standardized array of <select> options for "Event Title" * filter values. * @return Array */ function getEventFilterOptions() { $events = array(); $query = "\n select id, start_date, title from civicrm_event\n where (is_template IS NULL OR is_template = 0) AND is_active\n order by title ASC, start_date\n "; $dao = CRM_Core_DAO::executeQuery($query); while ($dao->fetch()) { $events[$dao->id] = "{$dao->title} - " . CRM_Utils_Date::customFormat(substr($dao->start_date, 0, 10)) . " (ID {$dao->id})"; } return $events; }
/** * Enforce valid date ranges. * * Borrowed from CRM_Report_Form_Contribute_Repeat::formRule(). * * @param array $fields * Fields from the form. * @param array $files * Not used. * @param object $self * Not used. * * @return array * Array of errors. */ public static function formRule($fields, $files, $self) { $errors = $checkDate = $errorCount = array(); if ($fields['event_start_date1_relative'] == '0') { $checkDate['event_start_date1']['event_start_date1_from'] = $fields['event_start_date1_from']; $checkDate['event_start_date1']['event_start_date1_to'] = $fields['event_start_date1_to']; } if ($fields['event_start_date2_relative'] == '0') { $checkDate['event_start_date2']['event_start_date2_from'] = $fields['event_start_date2_from']; $checkDate['event_start_date2']['event_start_date2_to'] = $fields['event_start_date2_to']; } foreach ($checkDate as $date_range => $range_data) { foreach ($range_data as $key => $value) { if (CRM_Utils_Date::isDate($value)) { $errorCount[$date_range][$key]['valid'] = 'true'; $errorCount[$date_range][$key]['is_empty'] = 'false'; } else { $errorCount[$date_range][$key]['valid'] = 'false'; $errorCount[$date_range][$key]['is_empty'] = 'true'; if (is_array($value)) { foreach ($value as $v) { if ($v) { $errorCount[$date_range][$key]['is_empty'] = 'false'; } } } elseif (!isset($value)) { $errorCount[$date_range][$key]['is_empty'] = 'false'; } } } } $errorText = ts("Select valid date range"); foreach ($errorCount as $date_range => $error_data) { if ($error_data[$date_range . '_from']['valid'] == 'false' && $error_data[$date_range . '_to']['valid'] == 'false') { if ($error_data[$date_range . '_from']['is_empty'] == 'true' && $error_data[$date_range . '_to']['is_empty'] == 'true') { $errors[$date_range . '_relative'] = $errorText; } if ($error_data[$date_range . '_from']['is_empty'] == 'false') { $errors[$date_range . '_from'] = $errorText; } if ($error_data[$date_range . '_to']['is_empty'] == 'false') { $errors[$date_range . '_to'] = $errorText; } } elseif ($error_data[$date_range . '_from']['valid'] == 'true' && $error_data[$date_range . '_to']['valid'] == 'false') { if ($error_data[$date_range . '_to']['is_empty'] == 'false') { $errors[$date_range . '_to'] = $errorText; } } elseif ($error_data[$date_range . '_from']['valid'] == 'false' && $error_data[$date_range . '_to']['valid'] == 'true') { if ($error_data[$date_range . '_from']['is_empty'] == 'false') { $errors[$date_range . '_from'] = $errorText; } } } return $errors; }
/** * Evaluate the content of a single token. * * @param \Civi\Token\TokenRow $row * The record for which we want token values. * @param string $entity * @param string $field * The name of the token field. * @param mixed $prefetch * Any data that was returned by the prefetch(). * * @return mixed */ public function evaluateToken(\Civi\Token\TokenRow $row, $entity, $field, $prefetch = NULL) { $actionSearchResult = $row->context['actionSearchResult']; if (in_array($field, array('start_date', 'end_date', 'join_date'))) { $row->tokens($entity, $field, \CRM_Utils_Date::customFormat($actionSearchResult->{$field})); } elseif (isset($actionSearchResult->{$field})) { $row->tokens($entity, $field, $actionSearchResult->{$field}); } else { $row->tokens($entity, $field, ''); } }
/** * Test the ajax function to get financial transactions. * * Test focus is on ensuring changes to how labels are retrieved does not cause regression. */ public function testGetFinancialTransactionsList() { $individualID = $this->individualCreate(); $this->contributionCreate($individualID); $batch = $this->callAPISuccess('Batch', 'create', array('title' => 'test', 'status_id' => 'Open')); CRM_Core_DAO::executeQuery("\n INSERT INTO civicrm_entity_batch (entity_table, entity_id, batch_id)\n values('civicrm_financial_trxn', 1, 1)\n "); $_REQUEST['sEcho'] = 1; $_REQUEST['entityID'] = $batch['id']; $json = CRM_Financial_Page_AJAX::getFinancialTransactionsList(TRUE); $this->assertEquals($json, '{"sEcho": 1, "iTotalRecords": 1, "iTotalDisplayRecords": 1, "aaData": [ ["","<a href=\\"/index.php?q=civicrm/profile/view&reset=1&gid=7&id=3&snippet=4\\" class=\\"crm-summary-link\\"><div' . ' class=\\"icon crm-icon Individual-icon\\"></div></a>","<a href=/index.php?q=civicrm/contact/view&reset=1&cid=3>Anderson, Anthony</a>","$ 100.00","12345","' . CRM_Utils_Date::customFormat(date('Ymd')) . ' 12:00 AM",' . '"Credit Card","Completed","Donation","<span><a href=\\"http://FIX ME/index.php?q=civicrm/contact/view/contribution&reset=1&id=1&cid=3&action=view&context=contribution&' . 'selectedChild=contribute\\" class=\\"action-item crm-hover-button\\" title=\'View Contribution\' >View</a></span>"]] }'); }
/** * Function to set variables up before form is built * * @return void * @access public */ public function preProcess() { $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0); $this->assign('bookingId', $this->_id); $config = CRM_Core_Config::singleton(); /** * [dateformatDatetime] => %B %E%f, %Y %l:%M %P * [dateformatFull] => %B %E%f, %Y * [dateformatPartial] => %B %Y * [dateformatYear] => %Y * [dateformatTime] => %l:%M %P */ $this->crmDateFormat = $config->dateformatDatetime; //retrieve crmDateFormat $this->assign('dateFormat', $this->crmDateFormat); $days = CRM_Booking_Utils_DateTime::getDays(); $months = CRM_Utils_Date::getFullMonthNames(); $years = CRM_Booking_Utils_DateTime::getYears(); $this->assign('days', $days); $this->assign('months', $months); $this->assign('years', $years); $config = CRM_Core_Config::singleton(); $currencySymbols = ""; if (!empty($config->currencySymbols)) { $currencySymbols = $config->currencySymbols; } else { $currencySymbols = $config->defaultCurrencySymbol; } $resourceTypes = CRM_Booking_BAO_Resource::getResourceTypes(); $resources = array(); foreach ($resourceTypes as $key => $type) { $result = CRM_Booking_BAO_Resource::getResourcesByType($key); $rTypekey = trim(strtolower($key . '_' . $type['label'])); $resources[$rTypekey]['label'] = $type['label']; $resources[$rTypekey]['child'] = $result; } $this->assign('resources', $resources); $this->assign('currencySymbols', $currencySymbols); $config = CRM_Booking_BAO_BookingConfig::getConfig(); $this->assign('colour', CRM_Utils_Array::value('slot_new_colour', $config)); list($xStart, $xSize, $xStep) = CRM_Booking_Utils_DateTime::getCalendarTime(); $this->assign('xStart', $xStart); $this->assign('xSize', $xSize); $this->assign('xStep', $xStep); $this->assign('timeOptions', CRM_Booking_Utils_DateTime::getTimeRange()); if ($this->_id && $this->_action == CRM_Core_Action::UPDATE) { $title = CRM_Core_DAO::getFieldValue('CRM_Booking_BAO_Booking', $this->_id, 'title', 'id'); CRM_Utils_System::setTitle(ts('Edit Booking') . " - {$title}"); } else { CRM_Utils_System::setTitle(ts('New Booking')); } self::registerScripts(); }
/** * Test setValues() and GetValues() methods with custom Date field */ public function testSetGetValuesDate() { $params = array(); $contactID = $this->individualCreate(); //create Custom Group $customGroup = $this->customGroupCreate(array('is_multiple' => 1)); //create Custom Field of data type Date $fields = array('custom_group_id' => $customGroup['id'], 'data_type' => 'Date', 'html_type' => 'Select Date', 'default_value' => ''); $customField = $this->customFieldCreate($fields); // Retrieve the field ID for sample custom field 'test_Date' $params = array('label' => 'test_Date'); $field = array(); CRM_Core_BAO_CustomField::retrieve($params, $field); $fieldID = $customField['id']; // Set test_Date to a valid date value $date = '20080608000000'; $params = array('entityID' => $contactID, 'custom_' . $fieldID => $date); $result = CRM_Core_BAO_CustomValueTable::setValues($params); $this->assertEquals($result['is_error'], 0, 'Verify that is_error = 0 (success).'); // Check that the date value is stored $values = array(); $params = array('entityID' => $contactID, 'custom_' . $fieldID => 1); $values = CRM_Core_BAO_CustomValueTable::getValues($params); $this->assertEquals($values['is_error'], 0, 'Verify that is_error = 0 (success).'); $this->assertEquals($values['custom_' . $fieldID . '_1'], CRM_Utils_Date::mysqlToIso($date), 'Verify that the date value is stored for contact ' . $contactID); // Now set test_Date to an invalid date value and try to reset $badDate = '20080631000000'; $params = array('entityID' => $contactID, 'custom_' . $fieldID => $badDate); CRM_Core_TemporaryErrorScope::useException(); $message = NULL; try { CRM_Core_BAO_CustomValueTable::setValues($params); } catch (Exception $e) { $message = $e->getMessage(); } $errorScope = NULL; // Check that an exception has been thrown $this->assertNotNull($message, 'Verify than an exception is thrown when bad date is passed'); $params = array('entityID' => $contactID, 'custom_' . $fieldID => 1); $values = CRM_Core_BAO_CustomValueTable::getValues($params); $this->assertEquals($values['custom_' . $fieldID . '_1'], CRM_Utils_Date::mysqlToIso($date), 'Verify that the date value has NOT been updated for contact ' . $contactID); // Test setting test_Date to null $params = array('entityID' => $contactID, 'custom_' . $fieldID => NULL); $result = CRM_Core_BAO_CustomValueTable::setValues($params); // Check that the date value is empty $params = array('entityID' => $contactID, 'custom_' . $fieldID => 1); $values = CRM_Core_BAO_CustomValueTable::getValues($params); $this->assertEquals($values['is_error'], 0, 'Verify that is_error = 0 (success).'); // Cleanup $this->customFieldDelete($customField); $this->customGroupDelete($customGroup['id']); $this->contactDelete($contactID); }
/** * 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; }
/** * Build all the data structures needed to build the form. * * @return void */ public function preProcess() { parent::preProcess(); $rows = array(); // display name and participation details of participants $participantIDs = implode(',', $this->_participantIds); $query = "\n SELECT p.fee_amount as amount,\n p.register_date as register_date,\n p.source as source,\n ct.display_name as display_name\n FROM civicrm_participant p\n INNER JOIN civicrm_contact ct ON ( p.contact_id = ct.id )\n WHERE p.id IN ( {$participantIDs} )"; $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); while ($dao->fetch()) { $rows[] = array('display_name' => $dao->display_name, 'amount' => $dao->amount, 'register_date' => CRM_Utils_Date::customFormat($dao->register_date), 'source' => $dao->source); } $this->assign('rows', $rows); }
/** * build all the data structures needed to build the form * * @return void * @access public */ function preProcess() { parent::preProcess(); $rows = array(); // display name and membership details of all selected contacts $memberIDs = implode(',', $this->_memberIds); $query = "\n SELECT mem.start_date as start_date,\n mem.end_date as end_date,\n mem.source as source, \n ct.display_name as display_name \nFROM civicrm_membership mem\nINNER JOIN civicrm_contact ct ON ( mem.contact_id = ct.id ) \nWHERE mem.id IN ( {$memberIDs} )"; $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); while ($dao->fetch()) { $rows[] = array('display_name' => $dao->display_name, 'start_date' => CRM_Utils_Date::customFormat($dao->start_date), 'end_date' => CRM_Utils_Date::customFormat($dao->end_date), 'source' => $dao->source); } $this->assign('rows', $rows); }
/** * This function is called prior to building and submitting the form and after the preProcess */ function setDefaultValues() { $defaults = array(); $defaults = $this->_values; // current employer id $defaults['current_employer_id'] = trim($defaults['employer_id']); // datum in dienst if (isset($defaults['Datum_in_dienst'])) { list($defaults['Datum_in_dienst']) = CRM_Utils_Date::setDateDefaults($defaults['Datum_in_dienst']); // list is needed or else it does not work } return $defaults; }
/** * build all the data structures needed to build the form * * @return void * @access public */ function preProcess() { parent::preProcess(); $rows = array(); // display name and pledge details of all selected contacts $pledgeIDs = implode(',', $this->_pledgeIds); $query = "\n SELECT plg.amount as amount,\n plg.create_date as create_date,\n ct.display_name as display_name\n FROM civicrm_pledge plg\nINNER JOIN civicrm_contact ct ON ( plg.contact_id = ct.id ) \n WHERE plg.id IN ( {$pledgeIDs} )"; $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); while ($dao->fetch()) { $rows[] = array('display_name' => $dao->display_name, 'amount' => $dao->amount, 'create_date' => CRM_Utils_Date::customFormat($dao->create_date)); } $this->assign('rows', $rows); }
function testSetGetValuesDate() { $params = array(); $contactID = Contact::createIndividual(); //create Custom Group $customGroup = Custom::createGroup($params, 'Individual', true); //create Custom Field of data type Date $fields = array('groupId' => $customGroup->id, 'dataType' => 'Date', 'htmlType' => 'Select Date'); $customField = Custom::createField($params, $fields); // Retrieve the field ID for sample custom field 'test_Date' $params = array('label' => 'test_Date'); $field = array(); require_once 'CRM/Core/BAO/CustomField.php'; CRM_Core_BAO_CustomField::retrieve($params, $field); $fieldID = $field['id']; // Set test_Date to a valid date value $date = '20080608000000'; $params = array('entityID' => $contactID, 'custom_' . $fieldID => $date); require_once 'CRM/Core/BAO/CustomValueTable.php'; $result = CRM_Core_BAO_CustomValueTable::setValues($params); $this->assertEquals($result['is_error'], 0, 'Verify that is_error = 0 (success).'); // Check that the date value is stored $values = array(); $params = array('entityID' => $contactID, 'custom_' . $fieldID => 1); $values = CRM_Core_BAO_CustomValueTable::getValues($params); $this->assertEquals($values['is_error'], 0, 'Verify that is_error = 0 (success).'); require_once 'CRM/Utils/Date.php'; $this->assertEquals($values['custom_' . $fieldID . '_1'], CRM_Utils_Date::mysqlToIso($date), 'Verify that the date value is stored for contact ' . $contactID); // Now set test_Date to an invalid date value and try to reset $badDate = '20080631000000'; $params = array('entityID' => $contactID, 'custom_' . $fieldID => $badDate); require_once 'CRM/Core/BAO/CustomValueTable.php'; $result = CRM_Core_BAO_CustomValueTable::setValues($params); // Check that the error flag is set AND that custom date value has not been modified $this->assertEquals($result['is_error'], 1, 'Verify that is_error = 1 when bad date is passed.'); $params = array('entityID' => $contactID, 'custom_' . $fieldID => 1); $values = CRM_Core_BAO_CustomValueTable::getValues($params); $this->assertEquals($values['custom_' . $fieldID . '_1'], CRM_Utils_Date::mysqlToIso($date), 'Verify that the date value has NOT been updated for contact ' . $contactID); // Test setting test_Date to null $params = array('entityID' => $contactID, 'custom_' . $fieldID => null); require_once 'CRM/Core/BAO/CustomValueTable.php'; $result = CRM_Core_BAO_CustomValueTable::setValues($params); // Check that the date value is empty $params = array('entityID' => $contactID, 'custom_' . $fieldID => 1); $values = CRM_Core_BAO_CustomValueTable::getValues($params); $this->assertEquals($values['is_error'], 0, 'Verify that is_error = 0 (success).'); // Cleanup Custom::deleteField($customField); Custom::deleteGroup($customGroup); Contact::delete($contactID); }
/** * Function to actually build the form * * @return void * @access public */ function buildQuickForm() { $this->assignToTemplate(); $productID = $this->get('productID'); $option = $this->get('option'); if ($productID) { require_once 'CRM/Contribute/BAO/Premium.php'; CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, false, $productID, $option); } $this->assign('trxn_id', $this->_params['trxn_id']); $this->assign('receive_date', CRM_Utils_Date::mysqlToIso($this->_params['receive_date'])); // can we blow away the session now to prevent hackery $this->controller->reset(); }
/** * @param $rows */ function alterDisplay(&$rows) { // cache for id → is_deleted mapping $isDeleted = array(); $newRows = array(); foreach ($rows as $key => &$row) { if (!isset($isDeleted[$row['log_civicrm_entity_altered_contact_id']])) { $isDeleted[$row['log_civicrm_entity_altered_contact_id']] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $row['log_civicrm_entity_altered_contact_id'], 'is_deleted') !== '0'; } if (!empty($row['log_civicrm_entity_altered_contact']) && !$isDeleted[$row['log_civicrm_entity_altered_contact_id']]) { $row['log_civicrm_entity_altered_contact_link'] = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $row['log_civicrm_entity_altered_contact_id']); $row['log_civicrm_entity_altered_contact_hover'] = ts("Go to contact summary"); $entity = $this->getEntityValue($row['log_civicrm_entity_id'], $row['log_civicrm_entity_log_type'], $row['log_civicrm_entity_log_date']); if ($entity) { $row['log_civicrm_entity_altered_contact'] = $row['log_civicrm_entity_altered_contact'] . " [{$entity}]"; } } $row['altered_by_contact_display_name_link'] = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $row['log_civicrm_entity_log_user_id']); $row['altered_by_contact_display_name_hover'] = ts("Go to contact summary"); if ($row['log_civicrm_entity_is_deleted'] and 'Update' == CRM_Utils_Array::value('log_civicrm_entity_log_action', $row)) { $row['log_civicrm_entity_log_action'] = ts('Delete (to trash)'); } if ('Contact' == CRM_Utils_Array::value('log_type', $this->_logTables[$row['log_civicrm_entity_log_type']]) && CRM_Utils_Array::value('log_civicrm_entity_log_action', $row) == 'Insert') { $row['log_civicrm_entity_log_action'] = ts('Update'); } if ($newAction = $this->getEntityAction($row['log_civicrm_entity_id'], $row['log_civicrm_entity_log_conn_id'], $row['log_civicrm_entity_log_type'], CRM_Utils_Array::value('log_civicrm_entity_log_action', $row))) { $row['log_civicrm_entity_log_action'] = $newAction; } $row['log_civicrm_entity_log_type'] = $this->getLogType($row['log_civicrm_entity_log_type']); $date = CRM_Utils_Date::isoToMysql($row['log_civicrm_entity_log_date']); if ('Update' == CRM_Utils_Array::value('log_civicrm_entity_log_action', $row)) { $q = "reset=1&log_conn_id={$row['log_civicrm_entity_log_conn_id']}&log_date=" . $date; if ($this->cid) { $q .= '&cid=' . $this->cid; } $q .= !empty($row['log_civicrm_entity_altered_contact']) ? '&alteredName=' . $row['log_civicrm_entity_altered_contact'] : ''; $q .= !empty($row['altered_by_contact_display_name']) ? '&alteredBy=' . $row['altered_by_contact_display_name'] : ''; $q .= !empty($row['log_civicrm_entity_log_user_id']) ? '&alteredById=' . $row['log_civicrm_entity_log_user_id'] : ''; $url1 = CRM_Report_Utils_Report::getNextUrl('logging/contact/detail', "{$q}&snippet=4§ion=2&layout=overlay", FALSE, TRUE); $url2 = CRM_Report_Utils_Report::getNextUrl('logging/contact/detail', "{$q}§ion=2", FALSE, TRUE); $row['log_civicrm_entity_log_action'] = "<a href='{$url1}' class='crm-summary-link'><div class='icon details-icon'></div></a> <a title='View details for this update' href='{$url2}'>" . ts('Update') . '</a>'; } $key = $date . '_' . $row['log_civicrm_entity_log_type'] . '_' . $row['log_civicrm_entity_log_conn_id'] . '_' . $row['log_civicrm_entity_log_user_id'] . '_' . $row['log_civicrm_entity_altered_contact_id']; $newRows[$key] = $row; unset($row['log_civicrm_entity_log_user_id']); unset($row['log_civicrm_entity_log_conn_id']); } krsort($newRows); $rows = $newRows; }
/** * Build all the data structures needed to build the form. * * @return void */ public function preProcess() { parent::preProcess(); $rows = array(); // display name and email of all contact ids $caseIDs = implode(',', $this->_caseIds); $statusId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'case_status', 'id', 'name'); $query = "\nSELECT ct.display_name as display_name,\n cs.start_date as start_date,\n ov.label as status\n\nFROM civicrm_case cs\nINNER JOIN civicrm_case_contact cc ON ( cs.id = cc.case_id)\nINNER JOIN civicrm_contact ct ON ( cc.contact_id = ct.id)\nLEFT JOIN civicrm_option_value ov ON (cs.status_id = ov.value AND ov.option_group_id = {$statusId} )\nWHERE cs.id IN ( {$caseIDs} )"; $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); while ($dao->fetch()) { $rows[] = array('display_name' => $dao->display_name, 'start_date' => CRM_Utils_Date::customFormat($dao->start_date), 'status' => $dao->status); } $this->assign('rows', $rows); }
/** * Heart of the viewing process. The runner gets all the meta data for * the contact and calls the appropriate type of page to view. * * @return void * @access public * */ function preProcess() { CRM_Utils_System::setTitle(ts('CiviContribute')); $startToDate = array(); $yearToDate = array(); $monthToDate = array(); $status = array('Valid', 'Cancelled'); $startDate = null; $config =& CRM_Core_Config::singleton(); $currentMonth = date('m'); $currentDay = date('d'); if ((int) $config->fiscalYearStart['M'] > $currentMonth || (int) $config->fiscalYearStart['M'] == $currentMonth && (int) $config->fiscalYearStart['d'] > $currentDay) { $year = date('Y') - 1; } else { $year = date('Y'); } $year = array('Y' => $year); $yearDate = $config->fiscalYearStart; $yearDate = array_merge($year, $yearDate); $yearDate = CRM_Utils_Date::format($yearDate); $monthDate = date('Ym') . '01000000'; $prefixes = array('start', 'month', 'year'); $status = array('Valid', 'Cancelled'); $yearNow = $yearDate + 10000; $yearNow .= '000000'; $yearDate = $yearDate . '000000'; // we are specific since we want all information till this second $now = date('YmdHis'); require_once 'CRM/Contribute/BAO/Contribution.php'; foreach ($prefixes as $prefix) { $aName = $prefix . 'ToDate'; $dName = $prefix . 'Date'; if ($prefix == 'year') { $now = $yearNow; } foreach ($status as $s) { ${$aName}[$s] = CRM_Contribute_BAO_Contribution::getTotalAmountAndCount($s, ${$dName}, $now); ${$aName}[$s]['url'] = CRM_Utils_System::url('civicrm/contribute/search', "reset=1&force=1&status=1&start={${$dName}}&end={$now}&test=0"); } $this->assign($aName, ${$aName}); } // Check for admin permission to see if we should include the Manage Contribution Pages action link $isAdmin = 0; require_once 'CRM/Core/Permission.php'; if (CRM_Core_Permission::check('administer CiviCRM')) { $isAdmin = 1; } $this->assign('isAdmin', $isAdmin); }
function testGetAllRows() { $mailchimp_sync_log = CRM_CiviMailchimp_BAO_SyncLogTest::createTestLogMessage('This is a test error message'); $details = unserialize($mailchimp_sync_log->details); $details = print_r($details, TRUE); $timestamp = date('c', $mailchimp_sync_log->timestamp); $timestamp = CRM_Utils_Date::customFormat($timestamp); $rows = CRM_CiviMailchimp_Page_SyncLog::getAllRows(); $this->assertCount(1, $rows); $this->assertEquals($mailchimp_sync_log->id, $rows[0]['id']); $this->assertEquals('Error', $rows[0]['type']); $this->assertEquals('CiviCRM to Mailchimp', $rows[0]['direction']); $this->assertEquals($mailchimp_sync_log->message, $rows[0]['message']); $this->assertEquals($details, $rows[0]['details']); $this->assertEquals($timestamp, $rows[0]['timestamp']); }
/** * Convert the date string "YYYY-MM-DD" to "MM<long> DD, YYYY". * * @param string $dateString date which needs to converted to human readable format * * @return string human readable date format | invalid date message * @access public */ function smarty_modifier_crmDate($dateString, $dateFormat = null, $onlyTime = false) { if ($dateString) { // this check needs to be type sensitive // CRM-3689, CRM-2441 if ($dateFormat === 0) { $dateFormat = null; } if ($onlyTime) { $config = CRM_Core_Config::singleton(); $dateFormat = $config->dateformatTime; } return CRM_Utils_Date::customFormat($dateString, $dateFormat); } return ''; }
public function generateLabel($participant) { $x = $this->pdf->GetAbsX(); $y = $this->pdf->GetY(); $this->printBackground(TRUE); $this->pdf->SetLineStyle(array('width' => 0.1, 'cap' => 'round', 'join' => 'round', 'dash' => '2,2', 'color' => array(0, 0, 200))); $this->pdf->SetFontSize(8); $this->pdf->MultiCell($this->pdf->width - $this->lMarginLogo, 0, $participant['event_title'], $this->border, "L", 0, 1, $x + $this->lMarginLogo, $y); $this->pdf->SetXY($x, $y + $this->pdf->height - 5); $date = CRM_Utils_Date::customFormat($participant['event_start_date'], "%e %b"); $this->pdf->Cell($this->pdf->width, 0, $date, $this->border, 2, "R"); $this->pdf->SetFontSize(15); $this->pdf->MultiCell($this->pdf->width, 10, $participant['display_name'], $this->border, "C", 0, 1, $x, $y + $this->tMarginName); $this->pdf->SetFontSize(10); $this->pdf->MultiCell($this->pdf->width, 0, $participant['current_employer'], $this->border, "C", 0, 1, $x, $this->pdf->getY()); }
/** * @param $participant */ public function generateLabel($participant) { $date = CRM_Utils_Date::customFormat($participant['event_start_date'], "%e %b"); $this->pdf->SetFontSize(8); $y = $this->pdf->GetY(); $x = $this->pdf->GetAbsX(); $this->pdf->Cell($this->pdf->width, $this->pdf->lineHeight, $participant['event_title'], 0, 1, "L"); $this->pdf->SetXY($x, $y + 4); $this->pdf->Cell($this->pdf->width, $this->pdf->lineHeight, $date, 0, 2, "R"); $this->pdf->SetFontSize(12); $this->pdf->SetXY($x, $this->pdf->GetY() + 5); $this->pdf->Cell($this->pdf->width, $this->pdf->lineHeight, $participant['display_name'], 0, 2, "C"); $this->pdf->SetFontSize(10); $this->pdf->SetXY($x, $this->pdf->GetY() + 2); $this->pdf->Cell($this->pdf->width, $this->pdf->lineHeight, $participant['current_employer'], 0, 2, "C"); //$this->pdf->MultiCell ($this->pdf->width, $this->pdf->lineHeight, $txt,1,"L"); }
public function releaseRespondent() { require_once 'CRM/Core/PseudoConstant.php'; require_once 'CRM/Campaign/BAO/Survey.php'; $activityStatus = CRM_Core_PseudoConstant::activityStatus('name'); $reserveStatusId = array_search('Scheduled', $activityStatus); $surveyActivityTypes = CRM_Campaign_BAO_Survey::getSurveyActivityType(); $surveyActivityTypesIds = array_keys($surveyActivityTypes); //retrieve all survey activities related to reserve action. $releasedCount = 0; if ($reserveStatusId && !empty($surveyActivityTypesIds)) { $query = ' SELECT activity.id as id, activity.activity_date_time as activity_date_time, survey.id as surveyId, survey.release_frequency as release_frequency FROM civicrm_activity activity INNER JOIN civicrm_survey survey ON ( survey.id = activity.source_record_id ) WHERE activity.is_deleted = 0 AND activity.status_id = %1 AND activity.activity_type_id IN ( ' . implode(', ', $surveyActivityTypesIds) . ' )'; $activity = CRM_Core_DAO::executeQuery($query, array(1 => array($reserveStatusId, 'Positive'))); $releasedIds = array(); while ($activity->fetch()) { if (!$activity->release_frequency) { continue; } $reservedSeconds = CRM_Utils_Date::unixTime($activity->activity_date_time); $releasedSeconds = $activity->release_frequency * 24 * 3600; $totalReservedSeconds = $reservedSeconds + $releasedSeconds; if ($totalReservedSeconds < time()) { $releasedIds[$activity->id] = $activity->id; } } //released respondent. if (!empty($releasedIds)) { $query = ' UPDATE civicrm_activity SET is_deleted = 1 WHERE id IN ( ' . implode(', ', $releasedIds) . ' )'; CRM_Core_DAO::executeQuery($query); $releasedCount = count($releasedIds); } } echo "<br /><br />Number of respondents released = {$releasedCount}"; }
function __construct(&$formValues) { $this->_formValues = $formValues; $this->_columns = array(ts('Contact Id') => 'contact_id', ts('Name') => 'display_name', ts('Donation Count') => 'donation_count', ts('Donation Amount') => 'donation_amount'); $this->_amounts = array('min_amount_1' => ts('Min Amount One'), 'max_amount_1' => ts('Max Amount One'), 'min_amount_2' => ts('Min Amount Two'), 'max_amount_2' => ts('Max Amount Two'), 'exclude_min_amount' => ts('Exclusion Min Amount'), 'exclude_max_amount' => ts('Exclusion Max Amount')); $this->_dates = array('start_date_1' => ts('Start Date One'), 'end_date_1' => ts('End Date One'), 'start_date_2' => ts('Start Date Two'), 'end_date_2' => ts('End Date Two'), 'exclude_start_date' => ts('Exclusion Start Date'), 'exclude_end_date' => ts('Exclusion End Date')); $this->_checkboxes = array('is_first_amount' => ts('First Donation?')); foreach ($this->_amounts as $name => $title) { $this->{$name} = CRM_Utils_Array::value($name, $this->_formValues); } foreach ($this->_checkboxes as $name => $title) { $this->{$name} = CRM_Utils_Array::value($name, $this->_formValues, FALSE); } foreach ($this->_dates as $name => $title) { if (CRM_Utils_Array::value($name, $this->_formValues)) { $this->{$name} = CRM_Utils_Date::processDate($this->_formValues[$name]); } } }
function postProcess() { $params = $this->controller->exportValues($this->_name); $parent = $this->controller->getParent(); if (!empty($params)) { $fields = array('mailing_name', 'mailing_from', 'mailing_to', 'sort_name'); foreach ($fields as $field) { if (isset($params[$field]) && !CRM_Utils_System::isNull($params[$field])) { if (substr($field, 7) != 'name') { $parent->set($field, CRM_Utils_Date::unformat(CRM_Utils_Date::processDate($params[$field]), '')); } else { $parent->set($field, $params[$field]); } } else { $parent->set($field, null); } } } }