Пример #1
0
 protected function getGroupIdByMemberGroupId($member_group_id, $member_group_name)
 {
     $custom = 'custom_' . $this->group_custom_field;
     try {
         $group_params = array();
         $group_params[1] = array($member_group_id, 'Integer');
         $groupId = CRM_Core_DAO::singleValueQuery("SELECT entity_id FROM `civicrm_value_myemma_group` WHERE `{$this->group_custom_field_name}` = %1", $group_params);
     } catch (Exception $e) {
         //not found do nothing
         throw $e;
     }
     if ($groupId) {
         civicrm_api3('Group', 'create', array('id' => $groupId, 'title' => $member_group_name, 'group_type' => CRM_Core_DAO::VALUE_SEPARATOR . '2' . CRM_Core_DAO::VALUE_SEPARATOR));
     } else {
         $group_params = array();
         $group_params[$custom] = $member_group_id;
         $group_params['title'] = $member_group_name;
         $group_params['group_type'] = CRM_Core_DAO::VALUE_SEPARATOR . '2' . CRM_Core_DAO::VALUE_SEPARATOR;
         //mailing list
         if ($this->parent_group_id) {
             $group_params['parents'] = $this->parent_group_id;
         }
         $result = civicrm_api3('Group', 'create', $group_params);
         $groupId = $result['id'];
     }
     return $groupId;
 }
 function tearDown()
 {
     parent::tearDown();
     CRM_Core_DAO::singleValueQuery('DELETE FROM civicrm_managed');
     CRM_Core_DAO::singleValueQuery('DELETE FROM civicrm_option_value WHERE name like "CRM_Example_%"');
     \Civi\Core\Container::singleton(TRUE);
 }
Пример #3
0
 /**
  * Upgrades for adding a Bussiness Coordinator in the Business case
  * @return bool
  */
 public function upgrade_1007()
 {
     $gid = CRM_Core_DAO::singleValueQuery("SELECT id from civicrm_custom_group where name = 'Add_Keyqualifications'");
     CRM_Core_DAO::executeQuery("UPDATE `civicrm_custom_field` SET label = 'Assessment SC/BC' WHERE `name` = 'Assessment_SC' AND custom_group_id = '" . $gid . "'");
     CRM_Core_DAO::executeQuery("UPDATE `civicrm_custom_field` SET label = 'Remarks SC/BC' WHERE `name` = 'Remarks' AND custom_group_id = '" . $gid . "'");
     CRM_Utils_System::flushCache();
     CRM_Core_DAO::executeQuery("UPDATE `civicrm_option_value` SET label = 'Request Approval Business Programme BC' WHERE label = 'Request Approval Business Programme SC' and option_group_id = 2");
     CRM_Core_DAO::executeQuery("UPDATE `civicrm_option_value` SET label = 'Business Debriefing BC', name = 'Business Debriefing BC' WHERE name = 'Business Debriefing SC' and option_group_id = 2");
     CRM_Utils_System::flushCache();
     $this->executeCustomDataFile('xml/request_approval_bc.xml');
     CRM_Utils_System::flushCache();
     $this->executeCustomDataFile('xml/request_approval_cc.xml');
     CRM_Utils_System::flushCache();
     $checkQry = 'SELECT COUNT(*) AS relCount FROM civicrm_relationship_type WHERE name_a_b = %1';
     $countRelType = CRM_Core_DAO::singleValueQuery($checkQry, array(1 => array('Business Coordinator', 'String')));
     if ($countRelType == 0) {
         CRM_Core_DAO::executeQuery("INSERT INTO civicrm_relationship_type\n        (name_a_b, label_a_b, name_b_a, label_b_a, description, contact_type_a, contact_type_b, contact_sub_type_a, contact_sub_type_b, is_reserved, is_active)\n        VALUES\n        ('Business Coordinator', 'Business Coordinator', 'Business Coordinator', 'Business Coordinator', 'Business Coordinator relationship', NULL, 'Individual', NULL, NULL, NULL, '1')");
     }
     CRM_Utils_System::flushCache();
     $gid = CRM_Core_DAO::singleValueQuery("SELECT id from civicrm_custom_group where name = 'Business_Data'");
     $fid = CRM_Core_DAO::singleValueQuery("SELECT id from civicrm_custom_field where custom_group_id = '" . $gid . "' and name = 'Position_of_Visitors'");
     if ($fid) {
         civicrm_api3('CustomField', 'delete', array('id' => $fid));
     }
     return true;
 }
Пример #4
0
 /**
  * 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'));
 }
 public function buildForm($formName, &$form)
 {
     if ($formName != 'CRM_Contribute_Form_Contribution') {
         return;
     }
     if (!CRM_Core_Permission::check('edit memberships')) {
         return;
     }
     $contact_id = $form->getVar('_contactID');
     if (!$contact_id) {
         return;
     }
     $current_membership_id = false;
     $contribution_id = $form->getVar('_id');
     if ($contribution_id) {
         $current_membership_id = CRM_Core_DAO::singleValueQuery("SELECT membership_id FROM civicrm_membership_payment where contribution_id = %1", array(1 => array($contribution_id, 'Integer')));
     }
     $memberships = array('' => ts('-- None --')) + $this->getMembershipsForContact($contact_id);
     $snippet['template'] = 'CRM/Membershippayment/Contribution/Form.tpl';
     $snippet['contact_id'] = $contact_id;
     $form->add('select', 'membership_id', ts('Membership'), $memberships);
     if ($current_membership_id) {
         $defaults['membership_id'] = $current_membership_id;
         $form->setDefaults($defaults);
     }
     CRM_Core_Region::instance('page-body')->add($snippet);
 }
Пример #6
0
 /**
  * build all the data structures needed to build the form
  *
  * @return void
  * @access 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 != 2\nAND    {$this->_componentClause}";
     $count = CRM_Core_DAO::singleValueQuery($query, CRM_Core_DAO::$_nullArray);
     if ($count != 0) {
         CRM_Core_Error::statusBounce(ts('Please select only online contributions with Pending status.'));
     }
     // ensure that all contributions are generated online by pay later
     $query = "\nSELECT DISTINCT( source ) as source\nFROM   civicrm_contribution\nWHERE  {$this->_componentClause}";
     $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
     while ($dao->fetch()) {
         if (strpos($dao->source, ts('Online Contribution')) === false && strpos($dao->source, ts('Online Event Registration')) === false) {
             CRM_Core_Error::statusBounce("<strong>Update Pending Contribution Status</strong> can only be used for pending online contributions (made using the 'Pay Later' option). The Source for these contributions starts with 'Online ...'. Please de-select any offline contributions and try again.");
         }
     }
     // we have all the contribution ids, so now we get the contact ids
     parent::setContactIDs();
     $this->assign('single', $this->_single);
 }
Пример #7
0
 /**
  * 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;
 }
Пример #8
0
 /**
  * get financial accounts of required account relationship.
  * $financialAccountType array with key account relationship and value financial account type option groups
  *
  * @param $config
  */
 public static function jqFinancial($config)
 {
     if (!isset($_GET['_value']) || empty($_GET['_value'])) {
         CRM_Utils_System::civiExit();
     }
     $defaultId = NULL;
     if ($_GET['_value'] == 'select') {
         $result = CRM_Contribute_PseudoConstant::financialAccount();
     } else {
         $financialAccountType = array('5' => 5, '3' => 1, '1' => 3, '6' => 1, '7' => 4, '8' => 1, '9' => 3, '10' => 2);
         $financialAccountType = CRM_Utils_Array::value($_GET['_value'], $financialAccountType);
         $result = CRM_Contribute_PseudoConstant::financialAccount(NULL, $financialAccountType);
         if ($financialAccountType) {
             $defaultId = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_financial_account WHERE is_default = 1 AND financial_account_type_id = {$financialAccountType}");
         }
     }
     $elements = array(array('name' => ts('- select -'), 'value' => 'select'));
     if (!empty($result)) {
         foreach ($result as $id => $name) {
             $selectedArray = array();
             if ($id == $defaultId) {
                 $selectedArray['selected'] = 'Selected';
             }
             $elements[] = array('name' => $name, 'value' => $id) + $selectedArray;
         }
     }
     CRM_Utils_JSON::output($elements);
 }
Пример #9
0
 function postProcess()
 {
     $values = $this->exportValues();
     $title = str_replace("'", "''", $values['title']);
     $params = array(1 => array($title, 'String'), 2 => array($values['widget'], 'Integer'));
     if (isset($this->_id)) {
         $params += array(3 => array($this->_id, 'Integer'));
         $sql = "UPDATE civicrm_wci_embed_code SET name = %1, widget_id = %2 where id = %3";
     } else {
         $sql = "INSERT INTO civicrm_wci_embed_code (name, widget_id)VALUES (%1, %2)";
     }
     $errorScope = CRM_Core_TemporaryErrorScope::useException();
     try {
         $transaction = new CRM_Core_Transaction();
         CRM_Core_DAO::executeQuery($sql, $params);
         $transaction->commit();
         CRM_Core_Session::setStatus(ts('Embed code created successfully'), '', 'success');
         if (isset($_REQUEST['_qf_NewEmbedCode_next'])) {
             isset($this->_id) ? $embed_id = $this->_id : ($embed_id = CRM_Core_DAO::singleValueQuery('SELECT LAST_INSERT_ID()'));
             CRM_Utils_System::redirect('?action=update&reset=1&id=' . $embed_id);
         } else {
             CRM_Utils_System::redirect('embed-code?reset=1');
         }
     } catch (Exception $e) {
         CRM_Core_Session::setStatus(ts('Failed to create embed code'), '', 'error');
         $transaction->rollback();
     }
     parent::postProcess();
 }
/**
 * Implements hook_civicrm_navigationMenu().
 */
function eventpermissions_civicrm_navigationMenu(&$params)
{
    $searchParams = array('url' => 'civicrm/eventpermissions?reset=1');
    $menuItems = array();
    CRM_Core_BAO_Navigation::retrieve($searchParams, $menuItems);
    if (!empty($menuItems)) {
        return;
    }
    $searchParams = array('url' => 'civicrm/admin/options/participant_role?reset=1');
    $menuItems = array();
    CRM_Core_BAO_Navigation::retrieve($searchParams, $menuItems);
    $parent = CRM_Utils_Array::value('parent_id', $menuItems);
    $navId = CRM_Core_DAO::singleValueQuery("SELECT max(id) FROM civicrm_navigation");
    if (is_int($navId)) {
        $navId++;
    }
    $basicAttrs = array('label' => ts('Event Permissions', array('domain' => 'com.aghstrategies.eventpermissions')), 'name' => 'Event Permissions', 'url' => 'civicrm/eventpermissions?reset=1', 'permission' => 'administer CiviCRM', 'active' => 1, 'navID' => $navId, 'parentID' => $parent);
    $searchParams = array('id' => $parent);
    $menuItems = array();
    CRM_Core_BAO_Navigation::retrieve($searchParams, $menuItems);
    if (empty($menuItems['parent_id'])) {
        $params[$parent]['child'][$navId] = $basicAttrs;
    } else {
        $params[$menuItems['parent_id']]['child'][$parent]['child'][$navId] = array('attributes' => $basicAttrs);
    }
}
Пример #11
0
function DataModelImprovements_preWebformRegSite()
{
    //Improvements that convert data collected on registered site before we had the webform to the same format that would be expected now that the webform is in place.
    //These are needed because we are going to ask all registered sites to update via the webform.
    //
    //Specifically, we want the ensure the following
    //
    // * All registered sites are all End Users
    // * All registered sites have a register your site activitiy recorded for them (at an appropriate time)
    // * All registered sites are no longer in the Registered site Organisations group (since we now track this with an activity)
    //
    //Update the contact sub type for all Organisations in the Register your site Organisations group where the contact subtype is NULL and they areto 'End users'
    $query = "UPDATE civicrm_contact AS cc\n        JOIN civicrm_group_contact AS cgc ON cgc.contact_id = cc.id AND cgc.group_id=15\n        SET contact_sub_type = 'End_user'\n        WHERE contact_sub_type IS NULL";
    CRM_Core_DAO::singleValueQuery($query);
    //Remove all organisations that are service providers from the list of registered sites
    //a. Mark all organisations that are tagged as ServiceProvider and EndUsers as just ServiceProvider
    $query = "UPDATE civicrm_contact AS cc\n        JOIN civicrm_value_civicrm_site_registration_4 AS cd ON cd.entity_id = cc.id\n        SET contact_sub_type ='Service_provider'\n        WHERE contact_sub_type = 'Service_providerEnd_user'";
    $result = CRM_Core_DAO::ExecuteQuery($query);
    //b. Remove all service providers from the group 'Register your site Organisations' (id 15)
    $query = "DELETE cgc\n        FROM civicrm_contact AS cc\n        JOIN civicrm_group_contact AS cgc\n        ON cc.id=cgc.contact_id\n        WHERE group_id=15 AND contact_sub_type LIKE '%Service%'";
    $result = CRM_Core_DAO::ExecuteQuery($query);
    //Create 'Registered site' (id 12) relationships for all organisations in the group 'Register your site Organisations' (id 15)
    // a. For all orgs that have exactly one employee, assume this is the person that entered the site and create the relationship
    $query = "\n        INSERT INTO civicrm_relationship(\n        SELECT\n            NULL,\n            cr.contact_id_a,\n            cr.contact_id_b,\n            12,\n            NULL,\n            NULL,\n            1,\n            NULL,\n            1,\n            0,\n            NULL\n        FROM civicrm_group_contact AS cgc\n        JOIN civicrm_relationship AS cr ON cr.contact_id_b = cgc.contact_id AND group_id=15 AND relationship_type_id=4 AND is_active\n        LEFT JOIN civicrm_relationship AS cra ON cr.contact_id_a=cra.contact_id_a AND cr.contact_id_b=cra.contact_id_b AND cra.relationship_type_id=12\n        WHERE cra.id IS NULL\n        GROUP BY contact_id\n        HAVING count(*)=1\n    )";
    $result = CRM_Core_DAO::ExecuteQuery($query);
    // b. For all orgs where there is more than one individual, see if one of those is in the registered sites individuals, find the individual that is in the Register your site Individuals list
    $query = "\n        SELECT\n            cr.contact_id_b as id\n        FROM civicrm_group_contact AS cgc\n        JOIN civicrm_relationship AS cr\n            ON cr.contact_id_b = cgc.contact_id AND group_id=15 AND relationship_type_id=4 AND is_active\n        LEFT JOIN civicrm_relationship AS cra ON cr.contact_id_a=cra.contact_id_a AND cr.contact_id_b=cra.contact_id_b AND cra.relationship_type_id=12\n        WHERE cra.id IS NULL\n        GROUP BY contact_id\n        HAVING count( * ) >1\n        ";
    $org = CRM_Core_DAO::ExecuteQuery($query);
    while ($org->fetch()) {
        $query = "SELECT cc.id FROM\n            civicrm_contact AS cc JOIN\n            civicrm_group_contact AS cgc ON cc.id=cgc.contact_id AND group_id=16 AND employer_id={$org->id}\n            ";
        $ind = CRM_Core_DAO::ExecuteQuery($query);
        if ($ind->N > 0) {
            $ind->fetch();
        } else {
            $query = "SELECT cc.id FROM civicrm_contact AS cc WHERE employer_id={$org->id} ";
            $ind = CRM_Core_DAO::ExecuteQuery($query);
            if ($ind->N > 0) {
                $ind->fetch();
            }
        }
        if ($ind->N > 0) {
            $params = array('version' => 3, 'sequential' => 1, 'contact_id_a' => $ind->id, 'contact_id_b' => $org->id, 'relationship_type_id' => 12);
            $result = civicrm_api('Relationship', 'create', $params);
        } else {
            print_r($org_id);
        }
        //print_r($params);
        //print_r($result);
    }
    //ensure all registered by relationships are permissioned
    //     SELECT
    // cc.display_name, count(activity_id)
    // FROM civicrm_contact AS cc
    // JOIN civicrm_activity_contact AS cac
    // 	ON cc.id=cac.contact_id
    // WHERE cc.employer_id=???
    // GROUP BY cc.id
    // record activities for all organisations in the registered sites group that don't have that type of activity recorded and assign to the individual that registered the site as well
    return;
}
Пример #12
0
 /**
  * Lets do permission checking here
  * First check for valid mailing, if false return fatal
  * Second check for visibility
  * Call a hook to see if hook wants to override visibility setting
  */
 function checkPermission()
 {
     if (!$this->_mailing) {
         return false;
     }
     // check for visibility, if visibility is user pages
     // return true
     if ($this->_mailing->visibility == 'Public Pages') {
         return true;
     }
     // if user is an admin, return true
     require_once 'CRM/Core/Permission.php';
     if (CRM_Core_Permission::check('administer CiviCRM') || CRM_Core_Permission::check('access CiviMail')) {
         return true;
     }
     // if anon user return false
     if (empty($this->_contactID)) {
         return false;
     }
     // if user has recd this mailing return true, else return false
     // check in mailing event table for this contact
     $sql = "\nSELECT     id\nFROM       civicrm_mailing_event_queue q\nINNER JOIN civicrm_mailing_job j ON q.job_id = j.id\nWHERE      j.mailing_id = %1\nAND        q.contact_id = %2\n";
     $params = array(1 => array($this->_mailingID, 'Integer'), 2 => array($this->_contactID, 'Integer'));
     return CRM_Core_DAO::singleValueQuery($sql, $params) ? true : false;
 }
/**
 * Implementation of hook_civicrm_check().
 *
 * Add a check to the status page/System.check results if $snafu is TRUE.
 */
function zombiefinder_civicrm_check(&$messages)
{
    // The API should be able to provide this (as below), but there are problems
    // in both 4.6 and 4.7 with finding privacy preferences (Do not mail, etc.)
    // that are null using the API.
    //
    // try {
    //   $result = civicrm_api3('Contact', 'getcount', array(
    //     'is_deceased' => array('IS NULL' => 1),
    //   ));
    // }
    // catch (CiviCRM_API3_Exception $e) {
    //   CRM_Core_Error::debug_log_message($e->getMessage());
    // }
    // Check for zombies.
    $fieldsToCheck = CRM_Core_SelectValues::privacy();
    $fieldsToCheck['is_deceased'] = ts('Is Deceased');
    $fieldsToCheck['is_deleted'] = ts('Deleted');
    $found = array();
    foreach ($fieldsToCheck as $fieldName => $displayName) {
        $sql = "SELECT COUNT(id) FROM civicrm_contact WHERE {$fieldName} IS NULL";
        if (CRM_Core_DAO::singleValueQuery($sql)) {
            $found[] = $displayName;
        }
    }
    if (count($found)) {
        $tsParams = array(1 => implode(', ', $found), 2 => 'http://civicrm.stackexchange.com/a/7396/44', 'domain' => 'com.aghstrategies.zombiefinder');
        $details = ts('Zombies found.  You have contacts who are undead or have null privacy options.  One or more contacts have null values in the following fields: %1.  <a href="%2">Read more about how to solve this.</a>', $tsParams);
        $messages[] = new CRM_Utils_Check_Message('zombiefinder_found', $details, ts('Gaaargh! Braaaains!', array('domain' => 'com.aghstrategies.zombiefinder')), \Psr\Log\LogLevel::WARNING, 'fa-user-times');
    }
}
Пример #14
0
 /**
  * Returns the related tables groups for which a contact has any info entered
  */
 static function getActiveRelTables($cid)
 {
     $cid = (int) $cid;
     $groups = array();
     $relTables =& self::relTables();
     $cidRefs =& self::cidRefs();
     $eidRefs =& self::eidRefs();
     foreach ($relTables as $group => $params) {
         $sqls = array();
         foreach ($params['tables'] as $table) {
             if (isset($cidRefs[$table])) {
                 foreach ($cidRefs[$table] as $field) {
                     $sqls[] = "SELECT COUNT(*) AS count FROM {$table} WHERE {$field} = {$cid}";
                 }
             }
             if (isset($eidRefs[$table])) {
                 foreach ($eidRefs[$table] as $entityTable => $entityId) {
                     $sqls[] = "SELECT COUNT(*) AS count FROM {$table} WHERE {$entityId} = {$cid} AND {$entityTable} = 'civicrm_contact'";
                 }
             }
             foreach ($sqls as $sql) {
                 if (CRM_Core_DAO::singleValueQuery($sql, CRM_Core_DAO::$_nullArray) > 0) {
                     $groups[] = $group;
                 }
             }
         }
     }
     return array_unique($groups);
 }
Пример #15
0
 /**
  * This function sets the default values for the form.
  * default values are retrieved from the database
  *
  * @access public
  *
  * @return None
  */
 function setDefaultValues()
 {
     if (!$this->_defaults) {
         $this->_defaults = array();
         $formArray = array('Component', 'Localization');
         $formMode = FALSE;
         if (in_array($this->_name, $formArray)) {
             $formMode = TRUE;
         }
         CRM_Core_BAO_ConfigSetting::retrieve($this->_defaults);
         CRM_Core_Config_Defaults::setValues($this->_defaults, $formMode);
         $list = array_flip(CRM_Core_OptionGroup::values('contact_autocomplete_options', FALSE, FALSE, TRUE, NULL, 'name'));
         $cRlist = array_flip(CRM_Core_OptionGroup::values('contact_reference_options', FALSE, FALSE, TRUE, NULL, 'name'));
         $listEnabled = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_autocomplete_options');
         $cRlistEnabled = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_reference_options');
         $autoSearchFields = array();
         if (!empty($list) && !empty($listEnabled)) {
             $autoSearchFields = array_combine($list, $listEnabled);
         }
         $cRSearchFields = array();
         if (!empty($cRlist) && !empty($cRlistEnabled)) {
             $cRSearchFields = array_combine($cRlist, $cRlistEnabled);
         }
         //Set defaults for autocomplete and contact reference options
         $this->_defaults['autocompleteContactSearch'] = array('1' => 1) + $autoSearchFields;
         $this->_defaults['autocompleteContactReference'] = array('1' => 1) + $cRSearchFields;
         $this->_defaults['enableSSL'] = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enableSSL', NULL, 0);
         $this->_defaults['verifySSL'] = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'verifySSL', NULL, 1);
         $sql = "\nSELECT time_format\nFROM   civicrm_preferences_date\nWHERE  time_format IS NOT NULL\nAND    time_format <> ''\nLIMIT  1\n";
         $this->_defaults['timeInputFormat'] = CRM_Core_DAO::singleValueQuery($sql);
     }
     return $this->_defaults;
 }
Пример #16
0
 function postProcess()
 {
     $vals = $this->controller->exportValues($this->_name);
     CRM_Core_Session::setStatus(ts('You saved a new room </br>' . 'label: %1 </br>' . 'room_no: %2 </br>' . 'floor: %3 </br>' . 'ext: %4', array(1 => $vals['label'], 2 => $vals['room_no'], 3 => $vals['floor'], 4 => $vals['ext'])));
     $query = "INSERT INTO civicrm_room (label, room_no, floor, ext) " . "VALUES ('{$vals['label']}', '{$vals['room_no']}', '{$vals['floor']}','{$vals['ext']}')";
     $count = CRM_Core_DAO::singleValueQuery($query);
     parent::postProcess();
 }
Пример #17
0
 /**
  * @param int $id
  * @param $oldCount
  */
 public function DashboardDelete($id, $oldCount)
 {
     $params = array('version' => 3, 'id' => $id);
     $dashboardget = $this->callAPISuccess('dashboard', 'get', $params);
     $this->assertEquals($id, $dashboardget['id']);
     $dashboard = $this->callAPISuccess('dashboard', 'delete', $params);
     $newCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_dashboard');
     $this->assertEquals($oldCount, $newCount);
 }
 function run()
 {
     // get the requested action
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
     // assign vars to templates
     $this->assign('action', $action);
     $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0);
     if ($action & CRM_Core_Action::UPDATE) {
         $controller = new CRM_Core_Controller_Simple('CRM_Wci_Form_ProgressBar', 'Edit Progressbar', CRM_Core_Action::UPDATE);
         $controller->set('id', $id);
         $controller->process();
         return $controller->run();
     } elseif ($action & CRM_Core_Action::COPY) {
         try {
             $sql = "INSERT INTO civicrm_wci_progress_bar (name, starting_amount, goal_amount)\n        SELECT concat(name, '-', (SELECT MAX(id) FROM civicrm_wci_progress_bar)),\n        starting_amount, goal_amount FROM civicrm_wci_progress_bar\n        WHERE id=%1";
             CRM_Core_DAO::executeQuery($sql, array(1 => array($id, 'Integer')));
             $new_pb_id = CRM_Core_DAO::singleValueQuery('SELECT LAST_INSERT_ID()');
             $sql = "INSERT INTO civicrm_wci_progress_bar_formula\n            (contribution_page_id, financial_type_id, progress_bar_id, start_date, end_date, percentage)\n            SELECT contribution_page_id, financial_type_id, %1, start_date,\n            end_date, percentage FROM civicrm_wci_progress_bar_formula WHERE progress_bar_id=%2";
             CRM_Core_DAO::executeQuery($sql, array(1 => array($new_pb_id, 'Integer'), 2 => array($id, 'Integer')));
         } catch (Exception $e) {
             CRM_Core_Session::setStatus(ts('Failed to create Progress bar. ') . $e->getMessage(), '', 'error');
             $transaction->rollback();
         }
     } elseif ($action & CRM_Core_Action::DELETE) {
         $errorScope = CRM_Core_TemporaryErrorScope::useException();
         try {
             $transaction = new CRM_Core_Transaction();
             $sql = "DELETE FROM civicrm_wci_progress_bar_formula where progress_bar_id = %1";
             $params = array(1 => array($id, 'Integer'));
             CRM_Core_DAO::executeQuery($sql, $params);
             $sql = "DELETE FROM civicrm_wci_progress_bar where id = %1";
             $params = array(1 => array($id, 'Integer'));
             CRM_Core_DAO::executeQuery($sql, $params);
             $transaction->commit();
         } catch (Exception $e) {
             $errmgs = $e->getMessage() . ts('. Check whether progressbar is used by any widget or not');
             CRM_Core_Session::setStatus($errmgs, '', 'error');
             $transaction->rollback();
         }
     }
     // Example: Set the page-title dynamically; alternatively, declare a static title in xml/Menu/*.xml
     CRM_Utils_System::setTitle(ts('Progress Bar List'));
     $query = "SELECT * FROM civicrm_wci_progress_bar";
     $params = array();
     $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Wci_DAO_ProgressBar');
     while ($dao->fetch()) {
         $con_page[$dao->id] = array();
         CRM_Core_DAO::storeValues($dao, $con_page[$dao->id]);
         $action = array_sum(array_keys($this->actionLinks()));
         //build the normal action links.
         $con_page[$dao->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('id' => $dao->id));
     }
     if (isset($con_page)) {
         $this->assign('rows', $con_page);
     }
     return parent::run();
 }
 static function deleteOldMessages()
 {
     $query = "\n      SELECT\n        timestamp\n      FROM \n        civimailchimp_sync_log\n      ORDER BY\n        timestamp DESC\n      LIMIT 1 OFFSET 99;\n    ";
     $timestamp = CRM_Core_DAO::singleValueQuery($query);
     if ($timestamp) {
         $query = "\n        DELETE FROM\n          civimailchimp_sync_log\n        WHERE \n          timestamp < {$timestamp};\n      ";
         CRM_Core_DAO::executeQuery($query);
     }
 }
 /**
  * Build all the data structures needed to build the form.
  *
  * @param
  *
  * @return void
  */
 public function preProcess()
 {
     $this->_selectAll = FALSE;
     $this->_exportMode = self::RELATIONSHIP_EXPORT;
     $this->_componentIds = array();
     $this->_componentClause = NULL;
     // we need to determine component export
     $stateMachine = $this->controller->getStateMachine();
     $formName = CRM_Utils_System::getClassName($stateMachine);
     $componentName = explode('_', $formName);
     $className = "CRM_Relationship_Form_Task";
     $className::preProcessCommon($this, TRUE);
     $values = $this->controller->exportValues('Search');
     $count = 0;
     $this->_matchingContacts = FALSE;
     if (CRM_Utils_Array::value('radio_ts', $values) == 'ts_sel') {
         foreach ($values as $key => $value) {
             if (strstr($key, 'mark_x')) {
                 $count++;
             }
             if ($count > 2) {
                 $this->_matchingContacts = TRUE;
                 break;
             }
         }
     }
     $this->_task = $values['task'];
     $this->assign('taskName', "Export {$componentName['1']}");
     $className = "CRM_{$componentName[1]}_Task";
     $componentTasks = $className::tasks();
     $taskName = $componentTasks[$this->_task];
     $component = TRUE;
     if ($this->_componentTable) {
         $query = "SELECT count(*) FROM {$this->_componentTable}";
         $totalSelectedRecords = CRM_Core_DAO::singleValueQuery($query);
     } else {
         $totalSelectedRecords = count($this->_componentIds);
     }
     $this->assign('totalSelectedRecords', $totalSelectedRecords);
     $this->assign('taskName', $taskName);
     $this->assign('component', $component);
     // all records actions = save a search
     if ($values['radio_ts'] == 'ts_all') {
         $this->_selectAll = TRUE;
         $rowCount = $this->get('rowCount');
         if ($rowCount > 2) {
             $this->_matchingContacts = TRUE;
         }
         $this->assign('totalSelectedRecords', $rowCount);
     }
     $this->assign('matchingContacts', $this->_matchingContacts);
     $this->set('componentIds', $this->_componentIds);
     $this->set('selectAll', $this->_selectAll);
     $this->set('exportMode', $this->_exportMode);
     $this->set('componentClause', $this->_componentClause);
     $this->set('componentTable', $this->_componentTable);
 }
Пример #21
0
 /**
  * Test fixValues function.
  *
  * @dataProvider getSavedSearches
  */
 public function testGetFormValues($formValues, $expectedResult, $searchDescription)
 {
     CRM_Core_DAO::executeQuery("INSERT INTO civicrm_saved_search (form_values) VALUES('" . serialize($formValues) . "')");
     $result = CRM_Contact_BAO_SavedSearch::getFormValues(CRM_Core_DAO::singleValueQuery('SELECT LAST_INSERT_ID()'));
     $this->assertEquals(array('membership_type_id', 'membership_status_id'), array_keys($result));
     foreach ($result as $key => $value) {
         $this->assertEquals($expectedResult, $value, 'failure on set ' . $searchDescription);
     }
 }
/**
 * Implementation of hook_civicrm_install
 */
function omnipaymultiprocessor_civicrm_install()
{
    CRM_Core_DAO::executeQuery("\n    ALTER TABLE `civicrm_payment_processor`\n    CHANGE COLUMN `signature` `signature` LONGTEXT NULL DEFAULT NULL;\n  ");
    $logExists = CRM_Core_DAO::singleValueQuery("SHOW TABLES LIKE 'log_civicrm_payment_processor'");
    if ($logExists) {
        CRM_Core_DAO::executeQuery("\n    ALTER TABLE `log_civicrm_payment_processor`\n    CHANGE COLUMN `signature` `signature` LONGTEXT NULL DEFAULT NULL;\n  ");
    }
    return _omnipaymultiprocessor_civix_civicrm_install();
}
Пример #23
0
 /**
  * Method to determine if the customer approves the expert
  *
  * @param int $caseId
  * @return string
  */
 public function customApprovesExpert($caseId)
 {
     if (!empty($caseId)) {
         $query = "SELECT " . $this->_customerApprovesColumn . " FROM " . $this->_customerApprovesCustomGroup['table_name'] . " WHERE entity_id = %1";
         $params = array(1 => array($caseId, "Integer"));
         return CRM_Core_DAO::singleValueQuery($query, $params);
     }
     return "n/a";
 }
Пример #24
0
 function testUpdateSettingsFalse()
 {
     $params = array('display_membership' => 0, 'display_contribution_total' => 0);
     CRM_Training_Form_Setting::updateSettings($params);
     $isMemBlock = CRM_Core_DAO::singleValueQuery("SELECT value FROM civicrm_training_settings WHERE name = 'display_membership'");
     $this->assertEquals(0, $isMemBlock);
     $isContribBlock = CRM_Core_DAO::singleValueQuery("SELECT value FROM civicrm_training_settings WHERE name = 'display_contribution_total'");
     $this->assertEquals(0, $isContribBlock);
 }
 /**
  * Obtain the title of page associated with a pcp.
  *
  * @param int $pcpId
  * @param $component
  *
  * @return int
  */
 public static function getContributionPageTitle($pcpId, $component)
 {
     if ($component == 'contribute') {
         $query = "\n\t\t\tSELECT cp.title\n\t\t\tFROM civicrm_pcp pcp\n\t\t\tLEFT JOIN civicrm_contribution_page as cp ON ( cp.id =  pcp.page_id )\n\t\t\tWHERE pcp.id = %1";
     } elseif ($component == 'event') {
         $query = "\n\t\t\tSELECT ce.title\n\t\t\tFROM civicrm_pcp pcp\n\t\t\tLEFT JOIN civicrm_event as ce ON ( ce.id =  pcp.page_id )\n\t\t\tWHERE pcp.id = %1";
     }
     $params = array(1 => array($pcpId, 'Integer'));
     return CRM_Core_DAO::singleValueQuery($query, $params);
 }
Пример #26
0
/**
 * Implementation of hook_civicrm_navigationMenu
 *
 * Adds entries to the navigation menu
 * @param unknown $menu
 */
function csvimport_civicrm_navigationMenu(&$menu)
{
    $maxID = CRM_Core_DAO::singleValueQuery("SELECT max(id) FROM civicrm_navigation");
    $administerMenuId = CRM_Core_DAO::getFieldValue('CRM_Core_BAO_Navigation', 'Administer', 'id', 'name');
    if (!$administerMenuId) {
        return;
    }
    $navId = $maxID + 1;
    $menu[$navId] = array('attributes' => array('label' => 'API csv Import', 'name' => 'CSV to api bridge', 'url' => 'civicrm/csvimporter/import', 'permission' => 'administer CiviCRM', 'operator' => null, 'separator' => null, 'parentID' => $administerMenuId, 'active' => 1, 'navID' => $navId));
}
Пример #27
0
 public function checkMysqlTime()
 {
     $messages = array();
     $phpNow = date('Y-m-d H:i');
     $sqlNow = CRM_Core_DAO::singleValueQuery("SELECT date_format(now(), '%Y-%m-%d %H:%i')");
     if (!CRM_Utils_Time::isEqual($phpNow, $sqlNow, 2.5 * 60)) {
         $messages[] = new CRM_Utils_Check_Message('checkMysqlTime', ts('Timestamps reported by MySQL (eg "%2") and PHP (eg "%3" ) are mismatched.<br /><a href="%1">Read more about this warning</a>', array(1 => CRM_Utils_System::getWikiBaseURL() . 'checkMysqlTime', 2 => $sqlNow, 3 => $phpNow)), ts('Environment Settings'));
     }
     return $messages;
 }
Пример #28
0
 static function getGrade($id)
 {
     static $_cache = array();
     if (!array_key_exists($id, $_cache)) {
         $sql = "\nSELECT grade\nFROM   civicrm_value_school_information\nWHERE  entity_id = %1\n";
         $params = array(1 => array($id, 'Integer'));
         $_cache[$id] = CRM_Core_DAO::singleValueQuery($sql, $params);
     }
     return $_cache[$id];
 }
 function testDashboardContactCreate()
 {
     $dashParams = array('version' => 3, 'label' => 'New Dashlet element', 'name' => 'New Dashlet element', 'url' => 'civicrm/report/list&compid=99&reset=1&snippet=5', 'fullscreen_url' => 'civicrm/report/list&compid=99&reset=1&snippet=5&context=dashletFullscreen');
     $dashresult = $this->callAPISuccess('dashboard', 'create', $dashParams);
     $contact = $this->callAPISuccess('contact', 'create', array('first_name' => 'abc1', 'contact_type' => 'Individual', 'last_name' => 'xyz1', 'email' => '*****@*****.**'));
     $oldCount = CRM_Core_DAO::singleValueQuery("select count(*) from civicrm_dashboard_contact where contact_id = {$contact['id']} AND is_active = 1 AND dashboard_id = {$dashresult['id']}");
     $params = array('version' => 3, 'contact_id' => $contact['id'], 'dashboard_id' => $dashresult['id'], 'is_active' => 1);
     $dashboradContact = $this->callAPISuccess('dashboard_contact', 'create', $params);
     $newCount = CRM_Core_DAO::singleValueQuery("select count(*) from civicrm_dashboard_contact where contact_id = {$contact['id']} AND is_active = 1 AND dashboard_id = {$dashresult['id']}");
     $this->assertEquals($oldCount + 1, $newCount);
 }
 protected function geinteresseerden(&$values, $cids, $job = null, $tokens = array(), $context = null)
 {
     $cg = civicrm_api3('CustomGroup', 'getsingle', array('name' => 'Broodfonds'));
     $cf = civicrm_api3('CustomField', 'getsingle', array('custom_group_id' => $cg['id'], 'name' => 'Interresse'));
     $cf_values = array(1 => array('Ik ga mee doen met het broodfonds', 'String'), 2 => array('Ik heb interesse om mee te doen en houd mij op de hoogte', 'String'));
     $sql = "SELECT COUNT(*) FROM `" . $cg['table_name'] . "` WHERE `" . $cf['column_name'] . "` = %1 OR `" . $cf['column_name'] . "` = %2";
     $geinteresserden = CRM_Core_DAO::singleValueQuery($sql, $cf_values);
     foreach ($cids as $cid) {
         $this->setValue($values, $cid, 'broodfonds.geinteresseerden', $geinteresserden);
     }
 }