/** * Check and load counties */ function ukrainerayons_loadcounties() { $counties = ukrainerayons_listcounties(); static $dao = NULL; if (!$dao) { $dao = new CRM_Core_DAO(); } // go state-by-state to check existing counties foreach ($counties as $id => $state) { $check = "SELECT name FROM civicrm_county WHERE state_province_id = {$id}"; $results = CRM_Core_DAO::executeQuery($check); $existing = array(); while ($results->fetch()) { $existing[] = $results->name; } // identify counties needing to be loaded $add = array_diff($state, $existing); $insert = array(); foreach ($add as $county) { $countydao = $dao->escape($county); $insert[] = "('{$countydao}', {$id})"; } // put it into queries of 50 counties each for ($i = 0; $i < count($insert); $i = $i + 50) { $inserts = array_slice($insert, $i, 50); $query = "INSERT INTO civicrm_county (name, state_province_id) VALUES "; $query .= implode(', ', $inserts); CRM_Core_DAO::executeQuery($query); } } }
function setUp() { parent::setUp(); $baoObj = new CRM_Core_DAO(); $baoObj->createTestObject('CRM_Pledge_BAO_Pledge', array(), 1, 0); $baoObj->createTestObject('CRM_Core_BAO_Phone', array(), 1, 0); $this->hookClass = CRM_Utils_Hook::singleton(); $config = CRM_Core_Config::singleton(); $config->userPermissionClass->permissions = array(); }
/** * Function to set variables up before form is built * * @return void * @access public */ public function preProcess() { $values = $ids = array(); $params = array('id' => $this->get('id')); CRM_Pledge_BAO_Pledge::getValues($params, $values, $ids); $values['frequencyUnit'] = ts('%1(s)', array(1 => $values['frequency_unit'])); if (isset($values["honor_contact_id"]) && $values["honor_contact_id"]) { $sql = "SELECT display_name FROM civicrm_contact WHERE id = " . $values["honor_contact_id"]; $dao = new CRM_Core_DAO(); $dao->query($sql); if ($dao->fetch()) { $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$values['honor_contact_id']}"); $values["honor_display"] = "<A href = {$url}>" . $dao->display_name . "</A>"; } $honor = CRM_Core_PseudoConstant::get('CRM_Pledge_DAO_Pledge', 'honor_type_id'); $values['honor_type'] = $honor[$values['honor_type_id']]; } //handle custom data. $groupTree = CRM_Core_BAO_CustomGroup::getTree('Pledge', $this, $params['id']); CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree); if (!empty($values['contribution_page_id'])) { $values['contribution_page'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $values['contribution_page_id'], 'title'); } $values['financial_type'] = CRM_Utils_Array::value($values['financial_type_id'], CRM_Contribute_PseudoConstant::financialType()); if ($values['status_id']) { $values['pledge_status'] = CRM_Utils_Array::value($values['status_id'], CRM_Contribute_PseudoConstant::contributionStatus()); } $url = CRM_Utils_System::url('civicrm/contact/view/pledge', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"); $recentOther = array(); if (CRM_Core_Permission::checkActionPermission('CiviPledge', CRM_Core_Action::UPDATE)) { $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/pledge', "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"); } if (CRM_Core_Permission::checkActionPermission('CiviPledge', CRM_Core_Action::DELETE)) { $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/pledge', "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"); } $displayName = CRM_Contact_BAO_Contact::displayName($values['contact_id']); $this->assign('displayName', $displayName); $title = $displayName . ' - (' . ts('Pledged') . ' ' . CRM_Utils_Money::format($values['pledge_amount']) . ' - ' . $values['financial_type'] . ')'; // add Pledge to Recent Items CRM_Utils_Recent::add($title, $url, $values['id'], 'Pledge', $values['contact_id'], NULL, $recentOther); // Check if this is default domain contact CRM-10482 if (CRM_Contact_BAO_Contact::checkDomainContact($values['contact_id'])) { $displayName .= ' (' . ts('default organization') . ')'; } // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container CRM_Utils_System::setTitle(ts('View Pledge by') . ' ' . $displayName); //do check for campaigns if ($campaignId = CRM_Utils_Array::value('campaign_id', $values)) { $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId); $values['campaign'] = $campaigns[$campaignId]; } $this->assign($values); }
function setDefaultValues() { $defaults = parent::setDefaultValues(); if (!CRM_Utils_Array::value('weight', $defaults)) { $query = "SELECT max( `weight` ) as weight FROM `civicrm_booking_resource_config_set`"; $dao = new CRM_Core_DAO(); $dao->query($query); $dao->fetch(); $defaults['weight'] = $dao->weight + 1; } return $defaults; }
/** * Create a Drupal user and return Drupal ID * * @param email email address of new user * * @return res Drupal ID for new user or FALSE if error */ function civicrm_drupal_create_user($email, $rid = NULL) { $email = trim($email); if (empty($email)) { return FALSE; } $user_tab = _civicrm_get_user_table_name(); // If user already exists, return Drupal id $uid = db_result(db_query("SELECT uid FROM {$user_tab} WHERE mail = '%s'", $email)); if ($uid) { return $uid; } // escape email to prevent sql injection $dao = new CRM_Core_DAO(); $email = $dao->escape($email); // Default values for new user $params = array(); //WARNING -- this is likely *wrong* since it will crash Drupal 6. //calling conventions for Drupal 7 are different, as well. //$params['uid'] = db_next_id('{users}_uid'); $params['name'] = $email; $params['pass'] = md5(uniqid(rand(), TRUE)); $params['mail'] = $email; $params['mode'] = 0; $params['access'] = 0; // don't allow user to login until verified $params['status'] = 0; $params['init'] = $email; $params['created'] = time(); $db_fields = '('; $db_values = '('; foreach ($params as $key => $value) { $db_fields .= "{$key},"; $db_values .= "'{$value}',"; } $db_fields = rtrim($db_fields, ","); $db_values = rtrim($db_values, ","); $db_fields .= ')'; $db_values .= ')'; $q = "INSERT INTO {$user_tab} {$db_fields} VALUES {$db_values}"; db_query($q); if ($rid) { // Delete any previous roles entry before adding the role id //NOTE: weirdly, D7 schema from alpha 3 allows the following: db_query('DELETE FROM {users_roles} WHERE uid = %d', $params['uid']); db_query('INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)', $params['uid'], $rid); } return $params['uid']; }
/** * Test the to csv function. * * @param string $fileName * * @dataProvider getCsvFiles */ public function testToCsv($fileName) { $dataSource = new CRM_Import_DataSource_Csv(); $params = array('uploadFile' => array('name' => __DIR__ . '/' . $fileName), 'skipColumnHeader' => TRUE); // Get the PEAR::DB object $dao = new CRM_Core_DAO(); $db = $dao->getDatabaseConnection(); $form = new CRM_Contact_Import_Form_DataSource(); $form->controller = new CRM_Contact_Import_Controller(); $dataSource->postProcess($params, $db, $form); $tableName = $form->get('importTableName'); $this->assertEquals(4, CRM_Core_DAO::singleValueQuery("SELECT LENGTH(last_name) FROM {$tableName}"), $fileName . ' failed on last_name'); $this->assertEquals(21, CRM_Core_DAO::singleValueQuery("SELECT LENGTH(email) FROM {$tableName}"), $fileName . ' failed on email'); CRM_Core_DAO::executeQuery("DROP TABLE {$tableName}"); }
/** * Set up permissions for test. */ public function setUp() { $this->useTransaction(TRUE); parent::setUp(); $individualID = $this->individualCreate(); $daoObj = new CRM_Core_DAO(); $this->callAPISuccess('Attachment', 'create', array('entity_table' => 'civicrm_contact', 'entity_id' => $individualID, 'mime_type' => 'k', 'name' => 'p', 'content' => 'l')); $daoObj->createTestObject('CRM_Activity_BAO_Activity', array(), 1, 0); $daoObj->createTestObject('CRM_Case_BAO_Case', array(), 1, 0); $entities = $this->getTagOptions(); foreach ($entities as $key => $entity) { $this->callAPISuccess('Tag', 'create', array('used_for' => $key, 'name' => $entity, 'description' => $entity)); } CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM'); }
/** * Example: Run an external SQL script when the module is uninstalled * public function uninstall() { $this->executeSqlFile('sql/myuninstall.sql'); } /** * Example: Run a simple query when a module is enabled * public function enable() { CRM_Core_DAO::executeQuery('UPDATE foo SET is_active = 1 WHERE bar = "whiz"'); } /** * Example: Run a simple query when a module is disabled * public function disable() { CRM_Core_DAO::executeQuery('UPDATE foo SET is_active = 0 WHERE bar = "whiz"'); } /** * Example: Add start and and date for job roles * * @return TRUE on success * @throws Exception * */ public function upgrade_1001() { $this->ctx->log->info('Applying update for job role start and end dates'); CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_hrjobroles` ADD COLUMN `start_date` timestamp DEFAULT 0 COMMENT 'Start Date of the job role'"); CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_hrjobroles` ADD COLUMN `end_date` timestamp DEFAULT 0 COMMENT 'End Date of the job role'"); return TRUE; }
/** * Browse all event templates. */ public function browse() { //get all event templates. $allEventTemplates = array(); $eventTemplate = new CRM_Event_DAO_Event(); $eventTypes = CRM_Event_PseudoConstant::eventType(); $participantRoles = CRM_Event_PseudoConstant::participantRole(); $participantListings = CRM_Event_PseudoConstant::participantListing(); //find all event templates. $eventTemplate->is_template = TRUE; $eventTemplate->find(); while ($eventTemplate->fetch()) { CRM_Core_DAO::storeValues($eventTemplate, $allEventTemplates[$eventTemplate->id]); //get listing types. if ($eventTemplate->participant_listing_id) { $allEventTemplates[$eventTemplate->id]['participant_listing'] = $participantListings[$eventTemplate->participant_listing_id]; } //get participant role if ($eventTemplate->default_role_id) { $allEventTemplates[$eventTemplate->id]['participant_role'] = $participantRoles[$eventTemplate->default_role_id]; } //get event type. if (isset($eventTypes[$eventTemplate->event_type_id])) { $allEventTemplates[$eventTemplate->id]['event_type'] = $eventTypes[$eventTemplate->event_type_id]; } //form all action links $action = array_sum(array_keys($this->links())); //add action links. $allEventTemplates[$eventTemplate->id]['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $eventTemplate->id), ts('more'), FALSE, 'eventTemplate.manage.action', 'Event', $eventTemplate->id); } $this->assign('rows', $allEventTemplates); $session = CRM_Core_Session::singleton(); $session->pushUserContext(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1&action=browse')); }
/** * Function for building Pledge Name combo box */ function pledgeName(&$config) { $getRecords = FALSE; if (isset($_GET['name']) && $_GET['name']) { $name = CRM_Utils_Type::escape($_GET['name'], 'String'); $name = str_replace('*', '%', $name); $whereClause = "p.creator_pledge_desc LIKE '%{$name}%' "; $getRecords = TRUE; } if (isset($_GET['id']) && is_numeric($_GET['id'])) { $pledgeId = CRM_Utils_Type::escape($_GET['id'], 'Integer'); $whereClause = "p.id = {$pledgeId} "; $getRecords = TRUE; } if ($getRecords) { $query = "\nSELECT p.creator_pledge_desc, p.id\nFROM civicrm_pb_pledge p\nWHERE {$whereClause}\n"; $dao = CRM_Core_DAO::executeQuery($query); $elements = array(); while ($dao->fetch()) { $elements[] = array('name' => $dao->creator_pledge_desc, 'value' => $dao->id); } } if (empty($elements)) { $name = $_GET['name']; if (!$name && isset($_GET['id'])) { $name = $_GET['id']; } $elements[] = array('name' => trim($name, '*'), 'value' => trim($name, '*')); } echo CRM_Utils_JSON::encode($elements, 'value'); CRM_Utils_System::civiExit(); }
/** * Test creating an index. * * We want to be sure it creates an index and exits gracefully if the index * already exists. */ public function testCombinedIndex() { $tables = array('civicrm_uf_join' => array('weight')); CRM_Core_BAO_SchemaHandler::createIndexes($tables); $tables = array('civicrm_uf_join' => array(array('weight', 'module'))); CRM_Core_BAO_SchemaHandler::createIndexes($tables); $dao = CRM_Core_DAO::executeQuery("SHOW INDEX FROM civicrm_uf_join"); $weightCount = 0; $combinedCount = 0; $indexes = array(); while ($dao->fetch()) { if ($dao->Column_name == 'weight') { $weightCount++; $indexes[$dao->Key_name] = $dao->Key_name; } if ($dao->Column_name == 'module') { $combinedCount++; $this->assertArrayHasKey($dao->Key_name, $indexes); } } foreach (array_keys($indexes) as $index) { CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_uf_join DROP INDEX " . $index); } $this->assertEquals(2, $weightCount); }
/** * 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 */ public function preProcess() { //fetch the dedupe exception contacts. $dedupeExceptions = array(); $exception = new CRM_Dedupe_DAO_Exception(); $exception->find(); $contactIds = array(); while ($exception->fetch()) { $key = "{$exception->contact_id1}_{$exception->contact_id2}"; $contactIds[$exception->contact_id1] = $exception->contact_id1; $contactIds[$exception->contact_id2] = $exception->contact_id2; $dedupeExceptions[$key] = array('main' => array('id' => $exception->contact_id1), 'other' => array('id' => $exception->contact_id2)); } //get the dupe contacts display names. if (!empty($dedupeExceptions)) { $sql = 'select id, display_name from civicrm_contact where id IN ( ' . implode(', ', $contactIds) . ' )'; $contact = CRM_Core_DAO::executeQuery($sql); $displayNames = array(); while ($contact->fetch()) { $displayNames[$contact->id] = $contact->display_name; } foreach ($dedupeExceptions as $key => &$values) { $values['main']['name'] = CRM_Utils_Array::value($values['main']['id'], $displayNames); $values['other']['name'] = CRM_Utils_Array::value($values['other']['id'], $displayNames); } } $this->assign('dedupeExceptions', $dedupeExceptions); }
/** * Build the form - it consists of * - displaying the QILL (query in local language) * - displaying elements for saving the search * * @access public * @return void */ function buildQuickForm() { CRM_Utils_System::setTitle(ts('Smart Group')); require_once "CRM/Event/BAO/Query.php"; // get the qill $query =& new CRM_Event_BAO_Query($this->get('formValues')); $qill = $query->qill(); // need to save qill for the smarty template $this->assign('qill', $qill); // the name and description are actually stored with the group and not the saved search $this->add('text', 'title', ts('Name'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'title'), true); $this->addElement('text', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'description')); // get the group id for the saved search $groupId = null; if (isset($this->_id)) { $params = array('saved_search_id' => $this->_id); require_once "CRM/Contact/BAO/Group.php"; CRM_Contact_BAO_Group::retrieve($params, $values); $groupId = $values['id']; $this->addDefaultButtons(ts('Update Smart Group')); } else { $this->addDefaultButtons(ts('Save Smart Group')); } $this->addRule('title', ts('Name already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Group', $groupId, 'title')); }
/** * Build the form object. */ public function buildQuickForm() { $config = CRM_Core_Config::singleton(); CRM_Utils_System::setTitle(ts('Settings - Localization')); $warningTitle = json_encode(ts("Warning")); $defaultLocaleOptions = CRM_Admin_Form_Setting_Localization::getDefaultLocaleOptions(); $domain = new CRM_Core_DAO_Domain(); $domain->find(TRUE); if ($domain->locales) { // add language limiter and language adder $this->addCheckBox('languageLimit', ts('Available Languages'), array_flip($defaultLocaleOptions), NULL, NULL, NULL, NULL, ' '); $this->addElement('select', 'addLanguage', ts('Add Language'), array_merge(array('' => ts('- select -')), array_diff(CRM_Core_I18n::languages(), $defaultLocaleOptions))); // add the ability to return to single language $warning = ts('This will make your CiviCRM installation a single-language one again. THIS WILL DELETE ALL DATA RELATED TO LANGUAGES OTHER THAN THE DEFAULT ONE SELECTED ABOVE (and only that language will be preserved).'); $this->assign('warning', $warning); $warning = json_encode($warning); $this->addElement('checkbox', 'makeSinglelingual', ts('Return to Single Language'), NULL, array('onChange' => "if (this.checked) CRM.alert({$warning}, {$warningTitle})")); } else { $warning = ts('Enabling multiple languages changes the schema of your database, so make sure you know what you are doing when enabling this function; making a database backup is strongly recommended.'); $this->assign('warning', $warning); $warning = json_encode($warning); $validTriggerPermission = CRM_Core_DAO::checkTriggerViewPermission(TRUE); if ($validTriggerPermission && !$config->logging) { $this->addElement('checkbox', 'makeMultilingual', ts('Enable Multiple Languages'), NULL, array('onChange' => "if (this.checked) CRM.alert({$warning}, {$warningTitle})")); } } $this->addElement('select', 'contact_default_language', ts('Default Language for users'), CRM_Admin_Form_Setting_Localization::getDefaultLanguageOptions()); $includeCurrency =& $this->addElement('advmultiselect', 'currencyLimit', ts('Available Currencies') . ' ', self::getCurrencySymbols(), array('size' => 5, 'style' => 'width:150px', 'class' => 'advmultiselect')); $includeCurrency->setButtonAttributes('add', array('value' => ts('Add >>'))); $includeCurrency->setButtonAttributes('remove', array('value' => ts('<< Remove'))); $this->addFormRule(array('CRM_Admin_Form_Setting_Localization', 'formRule')); parent::buildQuickForm(); }
/** * set up variables to build the form * * @param null * * @return void * @acess protected */ function preProcess() { $this->_fid = $this->get('fid'); $this->_title = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', $this->_fid, 'label', 'id'); $this->assign('title', $this->_title); CRM_Utils_System::setTitle(ts('Confirm Price Field Delete')); }
/** * Function to build the form * * @return None * @access public */ public function buildQuickForm() { parent::buildQuickForm(); if ($this->_action & CRM_Core_Action::DELETE) { return; } $this->applyFilter('__ALL__', 'trim'); $this->add('text', 'label_a_b', ts('Relationship Label-A to B'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_RelationshipType', 'label_a_b'), true); $this->addRule('label_a_b', ts('Label already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_RelationshipType', $this->_id, 'label_a_b')); $this->add('text', 'label_b_a', ts('Relationship Label-B to A'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_RelationshipType', 'label_b_a')); $this->addRule('label_b_a', ts('Label already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_RelationshipType', $this->_id, 'label_b_a')); $this->add('text', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_RelationshipType', 'description')); require_once 'CRM/Contact/BAO/ContactType.php'; $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(); // add select for contact type $contactTypeA =& $this->add('select', 'contact_types_a', ts('Contact Type A') . ' ', array('' => ts('- select -')) + $contactTypes); $contactTypeB =& $this->add('select', 'contact_types_b', ts('Contact Type B') . ' ', array('' => ts('- select -')) + $contactTypes); $isActive =& $this->add('checkbox', 'is_active', ts('Enabled?')); //only selected field should be allow for edit, CRM-4888 if ($this->_id && CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $this->_id, 'is_reserved')) { foreach (array('contactTypeA', 'contactTypeB', 'isActive') as $field) { ${$field}->freeze(); } } if ($this->_action & CRM_Core_Action::VIEW) { $this->freeze(); $url = CRM_Utils_System::url('civicrm/admin/reltype&reset=1'); $location = "window.location='{$url}'"; $this->addElement('button', 'done', ts('Done'), array('onclick' => $location)); } }
function run() { $sql = "SELECT * FROM civicrm_metrics_server ORDER BY site_name, timestamp"; $dao =& CRM_Core_DAO::executeQuery($sql); $rows = array(); while ($dao->fetch()) { $row = array(); $row['id'] = $dao->id; $row['site_name'] = $dao->site_name; $row['site_url'] = $dao->site_url; $row['timestamp'] = $dao->timestamp; $row['type'] = $dao->type; $row['data'] = $dao->data; $rows[] = $row; } if (array_key_exists("export", $_REQUEST) && $_REQUEST['export'] == 'csv') { header('Content-type: text/csv'); header('Content-disposition: attachment;filename=metrics_data_' . date("Ymd_HiO") . '.csv'); $output = fopen('php://output', 'w'); $headers = array("Id", "Site Name", "Site URL", "Timestamp", "Metric Type", "Metric Data"); fputcsv($output, $headers); foreach ($rows as $row) { fputcsv($output, $row); } fclose($output); die; } else { CRM_Utils_System::setTitle(ts('Metrics Report')); $this->assign('data', $rows); $this->assign('headers', array_keys($rows[0])); parent::run(); } }
/** * Function to build the form * * @return void * @access public */ public function buildQuickForm() { parent::buildQuickForm(); if ($this->_action & CRM_Core_Action::DELETE) { return; } CRM_Utils_System::setTitle(ts('Dropdown Options')); $this->applyFilter('__ALL__', 'trim'); $this->add('text', 'name', ts('Name'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionGroup', 'name'), TRUE); $this->addRule('name', ts('Name already exists in Database.'), 'objectExists', array('CRM_Core_DAO_OptionGroup', $this->_id)); $this->add('text', 'title', ts('Group Title'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionGroup', 'title')); $this->add('text', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionGroup', 'description')); $element = $this->add('checkbox', 'is_active', ts('Enabled?')); if ($this->_action & CRM_Core_Action::UPDATE) { if (in_array($this->_values['name'], array('encounter_medium', 'case_type', 'case_status'))) { static $caseCount = NULL; if (!isset($caseCount)) { $caseCount = CRM_Case_BAO_Case::caseCount(NULL, FALSE); } if ($caseCount > 0) { $element->freeze(); } } if (!empty($this->_values['is_reserved'])) { $this->freeze(array('name', 'is_active')); } } $this->assign('id', $this->_id); }
/** * Create a new bounce event, update the email address if necessary */ function &create(&$params) { $q =& CRM_Mailing_Event_BAO_Queue::verify($params['job_id'], $params['event_queue_id'], $params['hash']); if (!$q) { return null; } CRM_Core_DAO::transaction('BEGIN'); $bounce =& new CRM_Mailing_Event_BAO_Bounce(); $bounce->time_stamp = date('YmdHis'); $bounce->copyValues($params); $bounce->save(); $bounceTable = CRM_Mailing_Event_BAO_Bounce::getTableName(); $bounceType = CRM_Mailing_DAO_BounceType::getTableName(); $emailTable = CRM_Core_BAO_Email::getTableName(); $queueTable = CRM_Mailing_Event_BAO_Queue::getTableName(); $bounce->reset(); // might want to put distinct inside the count $query = "SELECT count({$bounceTable}.id) as bounces,\n {$bounceType}.hold_threshold as threshold\n FROM {$bounceTable}\n INNER JOIN {$bounceType}\n ON {$bounceTable}.bounce_type_id = {$bounceType}.id\n INNER JOIN {$queueTable}\n ON {$bounceTable}.event_queue_id = {$queueTable}.id\n INNER JOIN {$emailTable}\n ON {$queueTable}.email_id = {$emailTable}.id\n WHERE {$emailTable}.id = {$q->email_id}\n AND ({$emailTable}.reset_date IS NULL\n OR {$bounceTable}.time_stamp >= {$emailTable}.reset_date)\n GROUP BY {$bounceTable}.bounce_type_id\n ORDER BY threshold, bounces desc"; $bounce->query($query); while ($bounce->fetch()) { if ($bounce->bounces >= $bounce->threshold) { $email =& new CRM_Core_BAO_Email(); $email->id = $q->email_id; $email->on_hold = true; $email->hold_date = date('YmdHis'); $email->save(); break; } } CRM_Core_DAO::transaction('COMMIT'); }
/** * Build the form object. */ public function buildQuickForm() { parent::buildQuickForm(); if ($this->_action & CRM_Core_Action::DELETE) { $formatName = CRM_Core_BAO_PdfFormat::getFieldValue('CRM_Core_BAO_PdfFormat', $this->_id, 'name'); $this->assign('formatName', $formatName); return; } $attributes = CRM_Core_DAO::getAttribute('CRM_Core_BAO_PdfFormat'); $this->add('text', 'name', ts('Name'), $attributes['name'], TRUE); $this->add('text', 'description', ts('Description'), array('size' => CRM_Utils_Type::HUGE)); $this->add('checkbox', 'is_default', ts('Is this PDF Page Format the default?')); $this->add('select', 'paper_size', ts('Paper Size'), array(0 => ts('- default -')) + CRM_Core_BAO_PaperSize::getList(TRUE), FALSE, array('onChange' => "selectPaper( this.value );")); $this->add('static', 'paper_dimensions', NULL, ts('Width x Height')); $this->add('select', 'orientation', ts('Orientation'), CRM_Core_BAO_PdfFormat::getPageOrientations(), FALSE, array('onChange' => "updatePaperDimensions();")); $this->add('select', 'metric', ts('Unit of Measure'), CRM_Core_BAO_PdfFormat::getUnits(), FALSE, array('onChange' => "selectMetric( this.value );")); $this->add('text', 'margin_left', ts('Left Margin'), array('size' => 8, 'maxlength' => 8), TRUE); $this->add('text', 'margin_right', ts('Right Margin'), array('size' => 8, 'maxlength' => 8), TRUE); $this->add('text', 'margin_top', ts('Top Margin'), array('size' => 8, 'maxlength' => 8), TRUE); $this->add('text', 'margin_bottom', ts('Bottom Margin'), array('size' => 8, 'maxlength' => 8), TRUE); $this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Core_BAO_PdfFormat', 'weight'), TRUE); $this->addRule('name', ts('Name already exists in Database.'), 'objectExists', array('CRM_Core_BAO_PdfFormat', $this->_id)); $this->addRule('margin_left', ts('Margin must be numeric'), 'numeric'); $this->addRule('margin_right', ts('Margin must be numeric'), 'numeric'); $this->addRule('margin_top', ts('Margin must be numeric'), 'numeric'); $this->addRule('margin_bottom', ts('Margin must be numeric'), 'numeric'); $this->addRule('weight', ts('Weight must be integer'), 'integer'); }
/** * Build the form object. * * * @return void */ public function buildQuickForm() { if ($this->_search) { return; } $attributes = CRM_Core_DAO::getAttribute('CRM_Campaign_DAO_Survey'); $this->add('text', 'petition_title', ts('Title'), $attributes['title']); //campaigns $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE); $this->add('select', 'petition_campaign_id', ts('Campaign'), array('' => ts('- select -')) + $campaigns); $this->set('petitionCampaigns', $campaigns); $this->assign('petitionCampaigns', json_encode($campaigns)); //build the array of all search params. $this->_searchParams = array(); foreach ($this->_elements as $element) { $name = $element->_attributes['name']; $label = $element->_label; if ($name == 'qfKey') { continue; } $this->_searchParams[$name] = $label ? $label : $name; } $this->set('searchParams', $this->_searchParams); $this->assign('searchParams', json_encode($this->_searchParams)); }
/** * Browse all mail settings. */ public function browse() { //get all mail settings. $allMailSettings = array(); $mailSetting = new CRM_Core_DAO_MailSettings(); $allProtocols = CRM_Core_PseudoConstant::get('CRM_Core_DAO_MailSettings', 'protocol'); //multi-domain support for mail settings. CRM-5244 $mailSetting->domain_id = CRM_Core_Config::domainID(); //find all mail settings. $mailSetting->find(); while ($mailSetting->fetch()) { //replace protocol value with name $mailSetting->protocol = CRM_Utils_Array::value($mailSetting->protocol, $allProtocols); CRM_Core_DAO::storeValues($mailSetting, $allMailSettings[$mailSetting->id]); //form all action links $action = array_sum(array_keys($this->links())); // disallow the DELETE action for the default set of settings if ($mailSetting->is_default) { $action &= ~CRM_Core_Action::DELETE; } //add action links. $allMailSettings[$mailSetting->id]['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $mailSetting->id), ts('more'), FALSE, 'mailSetting.manage.action', 'MailSetting', $mailSetting->id); } $this->assign('rows', $allMailSettings); }
/** * Pre processing work done here. * * gets session variables for group or field id * * @return void */ public function preProcess() { // get the controller vars $this->_groupId = $this->get('groupId'); $this->_fieldId = $this->get('fieldId'); if ($this->_fieldId) { // field preview $defaults = array(); $params = array('id' => $this->_fieldId); $fieldDAO = new CRM_Core_DAO_CustomField(); CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomField', $params, $defaults); if (!empty($defaults['is_view'])) { CRM_Core_Error::statusBounce(ts('This field is view only so it will not display on edit form.')); } elseif (CRM_Utils_Array::value('is_active', $defaults) == 0) { CRM_Core_Error::statusBounce(ts('This field is inactive so it will not display on edit form.')); } $groupTree = array(); $groupTree[$this->_groupId]['id'] = 0; $groupTree[$this->_groupId]['fields'] = array(); $groupTree[$this->_groupId]['fields'][$this->_fieldId] = $defaults; $this->_groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $this); $this->assign('preview_type', 'field'); } else { $groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail($this->_groupId); $this->_groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, TRUE, $this); $this->assign('preview_type', 'group'); } }
/** * Add relationships from form. */ public function addRelationships() { if (!is_array($this->_contactIds)) { // Could this really happen? return; } $relationshipTypeParts = explode('_', $this->params['relationship_type_id']); $params = array('relationship_type_id' => $relationshipTypeParts[0], 'is_active' => 1); $secondaryRelationshipSide = $relationshipTypeParts[1]; $primaryRelationshipSide = $relationshipTypeParts[2]; $primaryFieldName = 'contact_id_' . $primaryRelationshipSide; $secondaryFieldName = 'contact_id_' . $secondaryRelationshipSide; $relationshipLabel = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $params['relationship_type_id'], "label_{$secondaryRelationshipSide}_{$primaryRelationshipSide}"); $params[$secondaryFieldName] = $this->_contactIds; $params[$primaryFieldName] = $this->params['contact_check']; $outcome = CRM_Contact_BAO_Relationship::createMultiple($params, $primaryRelationshipSide); $relatedContactName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $params[$primaryFieldName], 'display_name'); $status = array(ts('%count %2 %3 relationship created', array('count' => $outcome['valid'], 'plural' => '%count %2 %3 relationships created', 2 => $relationshipLabel, 3 => $relatedContactName))); if ($outcome['duplicate']) { $status[] = ts('%count was skipped because the contact is already %2 %3', array('count' => $outcome['duplicate'], 'plural' => '%count were skipped because the contacts are already %2 %3', 2 => $relationshipLabel, 3 => $relatedContactName)); } if ($outcome['invalid']) { $status[] = ts('%count relationship was not created because the contact is not of the right type for this relationship', array('count' => $outcome['invalid'], 'plural' => '%count relationships were not created because the contact is not of the right type for this relationship')); } $status = '<ul><li>' . implode('</li><li>', $status) . '</li></ul>'; CRM_Core_Session::setStatus($status, ts('Relationship created.', array('count' => $outcome['valid'], 'plural' => 'Relationships created.')), 'success', array('expires' => 0)); }
/** * Function to build the form * * @return None * @access public */ public function buildQuickForm() { parent::buildQuickForm(); if ($this->_action & CRM_Core_Action::DELETE) { return; } $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_PreferencesDate'); $this->applyFilter('__ALL__', 'trim'); $name =& $this->add('text', 'name', ts('Name'), $attributes['name'], true); $name->freeze(); $this->add('text', 'description', ts('Description'), $attributes['description'], false); $this->add('text', 'start', ts('Start Offset'), $attributes['start'], true); $this->add('text', 'end', ts('End Offset'), $attributes['end'], true); $formatType = CRM_Core_Dao::getFieldValue('CRM_Core_DAO_PreferencesDate', $this->_id, 'name'); if ($formatType == 'creditCard') { $this->add('text', 'date_format', ts('Format'), $attributes['date_format'], true); } else { $this->add('select', 'date_format', ts('Format'), array('' => ts('- default input format -')) + CRM_Core_SelectValues::getDatePluginInputFormats()); $this->add('select', 'time_format', ts('Time'), array('' => ts('- none -')) + CRM_Core_SelectValues::getTimeFormats()); } $this->addRule('start', ts('Value should be a positive number'), 'positiveInteger'); $this->addRule('end', ts('Value should be a positive number'), 'positiveInteger'); // add a form rule $this->addFormRule(array('CRM_Admin_Form_PreferencesDate', 'formRule')); }
/** * Alter display of rows. * * Iterate through the rows retrieved via SQL and make changes for display purposes, * such as rendering contacts as links. * * @param array $rows * Rows generated by SQL, with an array for each row. */ public function alterDisplay(&$rows) { // cache for id → is_deleted mapping $isDeleted = array(); foreach ($rows as &$row) { if (!isset($isDeleted[$row['civicrm_contact_is_deleted']])) { $isDeleted[$row['civicrm_contact_is_deleted']] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $row['civicrm_contact_altered_contact_id'], 'is_deleted') !== '0'; } if (!$isDeleted[$row['civicrm_contact_is_deleted']]) { $row['civicrm_contact_altered_contact_display_name_link'] = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $row['log_civicrm_contribution_contact_id']); $row['civicrm_contact_altered_contact_display_name_hover'] = ts('Go to contact summary'); } $row['civicrm_contact_altered_by_display_name_link'] = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $row['log_civicrm_contribution_log_user_id']); $row['civicrm_contact_altered_by_display_name_hover'] = ts('Go to contact summary'); if ($row['civicrm_contact_altered_contact_is_deleted'] and $row['log_civicrm_contribution_log_action'] == 'Update') { $row['log_civicrm_contribution_log_action'] = ts('Delete'); } if ($row['log_civicrm_contribution_log_action'] == 'Update') { $q = "reset=1&log_conn_id={$row['log_civicrm_contribution_log_conn_id']}&log_date={$row['log_civicrm_contribution_log_date']}"; if ($this->cid) { $q .= '&cid=' . $this->cid; } $url = CRM_Report_Utils_Report::getNextUrl('logging/contribute/detail', $q, FALSE, TRUE); $row['log_civicrm_contribution_log_action_link'] = $url; $row['log_civicrm_contribution_log_action_hover'] = ts('View details for this update'); $row['log_civicrm_contribution_log_action'] = '<div class="icon ui-icon-zoomin"></div> ' . ts('Update'); } unset($row['log_civicrm_contribute_log_user_id']); unset($row['log_civicrm_contribute_log_conn_id']); } }
/** * Get the AppMeta for an existing connection. * * @param string $cxnId * @return array * @throws \Civi\Cxn\Rpc\Exception\CxnException */ public static function getAppMeta($cxnId) { $appMetaJson = CRM_Core_DAO::getFieldValue('CRM_Cxn_DAO_Cxn', $cxnId, 'app_meta', 'cxn_guid', TRUE); $appMeta = json_decode($appMetaJson, TRUE); \Civi\Cxn\Rpc\AppMeta::validate($appMeta); return $appMeta; }
/** * Adjust Metadata for Create action. * * The metadata is used for setting defaults, documentation & validation. * * @param array $params * Array of parameters determined by getfields. */ function _civicrm_api3_custom_search_create_spec(&$params) { require_once 'api/v3/OptionValue.php'; _civicrm_api3_option_value_create_spec($params); $params['option_group_id']['api.default'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'custom_search', 'id', 'name'); $params['name']['api.aliases'] = array('class_name'); }
/** * Build all the data structures needed to build the form. * * @return void */ public function preProcess() { $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE); if ($id) { $this->_contributionIds = array($id); $this->_componentClause = " civicrm_contribution.id IN ( {$id} ) "; $this->_single = TRUE; $this->assign('totalSelectedContributions', 1); } else { parent::preProcess(); } // check that all the contribution ids have pending status $query = "\nSELECT count(*)\nFROM civicrm_contribution\nWHERE contribution_status_id != 1\nAND {$this->_componentClause}"; $count = CRM_Core_DAO::singleValueQuery($query); if ($count != 0) { CRM_Core_Error::statusBounce("Please select only online contributions with Completed status."); } // we have all the contribution ids, so now we get the contact ids parent::setContactIDs(); $this->assign('single', $this->_single); $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this); $urlParams = 'force=1'; if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams .= "&qfKey={$qfKey}"; } $url = CRM_Utils_System::url('civicrm/contribute/search', $urlParams); $breadCrumb = array(array('url' => $url, 'title' => ts('Search Results'))); CRM_Utils_System::appendBreadCrumb($breadCrumb); CRM_Utils_System::setTitle(ts('Print Contribution Receipts')); }
/** * Creates or updates a participant payment record. * * @param array $params * of values to initialize the record with. * @param array $ids * with one values of id for this participantPayment record (for update). * * @return object * the partcipant payment record */ public static function create(&$params, &$ids) { if (isset($ids['id'])) { CRM_Utils_Hook::pre('edit', 'ParticipantPayment', $ids['id'], $params); } else { CRM_Utils_Hook::pre('create', 'ParticipantPayment', NULL, $params); } $participantPayment = new CRM_Event_BAO_ParticipantPayment(); $participantPayment->copyValues($params); if (isset($ids['id'])) { $participantPayment->id = CRM_Utils_Array::value('id', $ids); } else { $participantPayment->find(TRUE); } $participantPayment->save(); if (isset($ids['id'])) { CRM_Utils_Hook::post('edit', 'ParticipantPayment', $ids['id'], $participantPayment); } else { CRM_Utils_Hook::post('create', 'ParticipantPayment', NULL, $participantPayment); } //generally if people are creating participant_payments via the api they won't be setting the line item correctly - we can't help them if they are doing complex transactions // but if they have a single line item for the contribution we can assume it should refer to the participant line $lineItemCount = CRM_Core_DAO::singleValueQuery("select count(*) FROM civicrm_line_item WHERE contribution_id = %1", array(1 => array($participantPayment->contribution_id, 'Integer'))); if ($lineItemCount == 1) { $sql = "UPDATE civicrm_line_item li\n SET entity_table = 'civicrm_participant', entity_id = %1\n WHERE contribution_id = %2 AND entity_table = 'civicrm_contribution'"; CRM_Core_DAO::executeQuery($sql, array(1 => array($participantPayment->participant_id, 'Integer'), 2 => array($participantPayment->contribution_id, 'Integer'))); } return $participantPayment; }