Exemplo n.º 1
0
 /**
  * Returns whether or not this OpenID is allowed to login
  *
  * @param  string  $identity_url the OpenID to check
  *
  * @return boolean
  * @access public
  * @static
  */
 static function isAllowedToLogin($identity_url)
 {
     $openId = new CRM_Core_DAO_OpenID();
     $openId->openid = $identity_url;
     if ($openId->find(true)) {
         return $openId->allowed_to_login == 1;
     }
     return false;
 }
Exemplo n.º 2
0
 /**
  * Returns whether or not this OpenID is allowed to login.
  *
  * @param string $identity_url
  *   The OpenID to check.
  *
  * @return bool
  */
 public static function isAllowedToLogin($identity_url)
 {
     $openId = new CRM_Core_DAO_OpenID();
     $openId->openid = $identity_url;
     if ($openId->find(TRUE)) {
         return $openId->allowed_to_login == 1;
     }
     return FALSE;
 }
Exemplo n.º 3
0
 /**
  * Global validation rules for the form.
  *
  * @param array $fields
  *   Posted values of the form.
  * @param array $errors
  *   List of errors to be posted back to the form.
  * @param int $contactId
  *   Contact id if doing update.
  *
  * @return bool
  *   email/openId
  */
 public static function formRule($fields, &$errors, $contactId = NULL)
 {
     $config = CRM_Core_Config::singleton();
     // validations.
     //1. for each block only single value can be marked as is_primary = true.
     //2. location type id should be present if block data present.
     //3. check open id across db and other each block for duplicate.
     //4. at least one location should be primary.
     //5. also get primaryID from email or open id block.
     // take the location blocks.
     $blocks = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_edit_options', TRUE, NULL, FALSE, 'name', TRUE, 'AND v.filter = 1');
     $otherEditOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_edit_options', TRUE, NULL, FALSE, 'name', TRUE, 'AND v.filter = 0');
     //get address block inside.
     if (array_key_exists('Address', $otherEditOptions)) {
         $blocks['Address'] = $otherEditOptions['Address'];
     }
     $openIds = array();
     $primaryID = FALSE;
     foreach ($blocks as $name => $label) {
         $hasData = $hasPrimary = array();
         $name = strtolower($name);
         if (!empty($fields[$name]) && is_array($fields[$name])) {
             foreach ($fields[$name] as $instance => $blockValues) {
                 $dataExists = self::blockDataExists($blockValues);
                 if (!$dataExists && $name == 'address') {
                     $dataExists = CRM_Utils_Array::value('use_shared_address', $fields['address'][$instance]);
                 }
                 if ($dataExists) {
                     // skip remaining checks for website
                     if ($name == 'website') {
                         continue;
                     }
                     $hasData[] = $instance;
                     if (!empty($blockValues['is_primary'])) {
                         $hasPrimary[] = $instance;
                         if (!$primaryID && in_array($name, array('email', 'openid')) && !empty($blockValues[$name])) {
                             $primaryID = $blockValues[$name];
                         }
                     }
                     if (empty($blockValues['location_type_id'])) {
                         $errors["{$name}[{$instance}][location_type_id]"] = ts('The Location Type should be set if there is  %1 information.', array(1 => $label));
                     }
                 }
                 if ($name == 'openid' && !empty($blockValues[$name])) {
                     $oid = new CRM_Core_DAO_OpenID();
                     $oid->openid = $openIds[$instance] = CRM_Utils_Array::value($name, $blockValues);
                     $cid = isset($contactId) ? $contactId : 0;
                     if ($oid->find(TRUE) && $oid->contact_id != $cid) {
                         $errors["{$name}[{$instance}][openid]"] = ts('%1 already exist.', array(1 => $blocks['OpenID']));
                     }
                 }
             }
             if (empty($hasPrimary) && !empty($hasData)) {
                 $errors["{$name}[1][is_primary]"] = ts('One %1 should be marked as primary.', array(1 => $label));
             }
             if (count($hasPrimary) > 1) {
                 $errors["{$name}[" . array_pop($hasPrimary) . "][is_primary]"] = ts('Only one %1 can be marked as primary.', array(1 => $label));
             }
         }
     }
     //do validations for all opend ids they should be distinct.
     if (!empty($openIds) && count(array_unique($openIds)) != count($openIds)) {
         foreach ($openIds as $instance => $value) {
             if (!array_key_exists($instance, array_unique($openIds))) {
                 $errors["openid[{$instance}][openid]"] = ts('%1 already used.', array(1 => $blocks['OpenID']));
             }
         }
     }
     // street number should be digit + suffix, CRM-5450
     $parseStreetAddress = CRM_Utils_Array::value('street_address_parsing', CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options'));
     if ($parseStreetAddress) {
         if (isset($fields['address']) && is_array($fields['address'])) {
             $invalidStreetNumbers = array();
             foreach ($fields['address'] as $cnt => $address) {
                 if ($streetNumber = CRM_Utils_Array::value('street_number', $address)) {
                     $parsedAddress = CRM_Core_BAO_Address::parseStreetAddress($address['street_number']);
                     if (empty($parsedAddress['street_number'])) {
                         $invalidStreetNumbers[] = $cnt;
                     }
                 }
             }
             if (!empty($invalidStreetNumbers)) {
                 $first = $invalidStreetNumbers[0];
                 foreach ($invalidStreetNumbers as &$num) {
                     $num = CRM_Contact_Form_Contact::ordinalNumber($num);
                 }
                 $errors["address[{$first}][street_number]"] = ts('The street number you entered for the %1 address block(s) is not in an expected format. Street numbers may include numeric digit(s) followed by other characters. You can still enter the complete street address (unparsed) by clicking "Edit Complete Street Address".', array(1 => implode(', ', $invalidStreetNumbers)));
             }
         }
     }
     return $primaryID;
 }
Exemplo n.º 4
0
 /**
  * Returns the list of fields that can be exported
  *
  * @param bool $prefix
  *
  * @return array
  */
 static function &export($prefix = false)
 {
     if (!self::$_export) {
         self::$_export = array();
         $fields = self::fields();
         foreach ($fields as $name => $field) {
             if (CRM_Utils_Array::value('export', $field)) {
                 if ($prefix) {
                     self::$_export['openid'] =& $fields[$name];
                 } else {
                     self::$_export[$name] =& $fields[$name];
                 }
             }
         }
     }
     return self::$_export;
 }
Exemplo n.º 5
0
 /**
  * Combine all the exportable fields from the lower levels object.
  *
  * Currently we are using importable fields as exportable fields
  *
  * @param int|string $contactType contact Type
  * @param bool $status
  *   True while exporting primary contacts.
  * @param bool $export
  *   True when used during export.
  * @param bool $search
  *   True when used during search, might conflict with export param?.
  *
  * @param bool $withMultiRecord
  *
  * @return array
  *   array of exportable Fields
  */
 public static function &exportableFields($contactType = 'Individual', $status = FALSE, $export = FALSE, $search = FALSE, $withMultiRecord = FALSE)
 {
     if (empty($contactType)) {
         $contactType = 'All';
     }
     $cacheKeyString = "exportableFields {$contactType}";
     $cacheKeyString .= $export ? '_1' : '_0';
     $cacheKeyString .= $status ? '_1' : '_0';
     $cacheKeyString .= $search ? '_1' : '_0';
     //CRM-14501 it turns out that the impact of permissioning here is sometimes inconsistent. The field that
     //calculates custom fields takes into account the logged in user & caches that for all users
     //as an interim fix we will cache the fields by contact
     $cacheKeyString .= '_' . CRM_Core_Session::getLoggedInContactID();
     if (!self::$_exportableFields || !CRM_Utils_Array::value($cacheKeyString, self::$_exportableFields)) {
         if (!self::$_exportableFields) {
             self::$_exportableFields = array();
         }
         // check if we can retrieve from database cache
         $fields = CRM_Core_BAO_Cache::getItem('contact fields', $cacheKeyString);
         if (!$fields) {
             $fields = CRM_Contact_DAO_Contact::export();
             // The fields are meant for contact types.
             if (in_array($contactType, array('Individual', 'Household', 'Organization', 'All'))) {
                 $fields = array_merge($fields, CRM_Core_OptionValue::getFields('', $contactType));
             }
             // add current employer for individuals
             $fields = array_merge($fields, array('current_employer' => array('name' => 'organization_name', 'title' => ts('Current Employer'))));
             $locationType = array('location_type' => array('name' => 'location_type', 'where' => 'civicrm_location_type.name', 'title' => ts('Location Type')));
             $IMProvider = array('im_provider' => array('name' => 'im_provider', 'where' => 'civicrm_im.provider_id', 'title' => ts('IM Provider')));
             $locationFields = array_merge($locationType, CRM_Core_DAO_Address::export(), CRM_Core_DAO_Phone::export(), CRM_Core_DAO_Email::export(), $IMProvider, CRM_Core_DAO_IM::export(TRUE), CRM_Core_DAO_OpenID::export());
             $locationFields = array_merge($locationFields, CRM_Core_BAO_CustomField::getFieldsForImport('Address'));
             foreach ($locationFields as $key => $field) {
                 $locationFields[$key]['hasLocationType'] = TRUE;
             }
             $fields = array_merge($fields, $locationFields);
             //add world region
             $fields = array_merge($fields, CRM_Core_DAO_Worldregion::export());
             $fields = array_merge($fields, CRM_Contact_DAO_Contact::export());
             //website fields
             $fields = array_merge($fields, CRM_Core_DAO_Website::export());
             if ($contactType != 'All') {
                 $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport($contactType, $status, FALSE, $search, TRUE, $withMultiRecord));
             } else {
                 foreach (array('Individual', 'Household', 'Organization') as $type) {
                     $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport($type, FALSE, FALSE, $search, TRUE, $withMultiRecord));
                 }
             }
             //fix for CRM-791
             if ($export) {
                 $fields = array_merge($fields, array('groups' => array('title' => ts('Group(s)'), 'name' => 'groups'), 'tags' => array('title' => ts('Tag(s)'), 'name' => 'tags'), 'notes' => array('title' => ts('Note(s)'), 'name' => 'notes')));
             } else {
                 $fields = array_merge($fields, array('group' => array('title' => ts('Group(s)'), 'name' => 'group'), 'tag' => array('title' => ts('Tag(s)'), 'name' => 'tag'), 'note' => array('title' => ts('Note(s)'), 'name' => 'note')));
             }
             //Sorting fields in alphabetical order(CRM-1507)
             foreach ($fields as $k => $v) {
                 $sortArray[$k] = CRM_Utils_Array::value('title', $v);
             }
             $fields = array_merge($sortArray, $fields);
             //unset the field which are not related to their contact type.
             if ($contactType != 'All') {
                 $commonValues = array('Individual' => array('household_name', 'legal_name', 'sic_code', 'organization_name', 'email_greeting_custom', 'postal_greeting_custom', 'addressee_custom'), 'Household' => array('first_name', 'middle_name', 'last_name', 'formal_title', 'job_title', 'gender_id', 'prefix_id', 'suffix_id', 'birth_date', 'organization_name', 'legal_name', 'legal_identifier', 'sic_code', 'home_URL', 'is_deceased', 'deceased_date', 'current_employer', 'email_greeting_custom', 'postal_greeting_custom', 'addressee_custom', 'prefix_id', 'suffix_id'), 'Organization' => array('first_name', 'middle_name', 'last_name', 'formal_title', 'job_title', 'gender_id', 'prefix_id', 'suffix_id', 'birth_date', 'household_name', 'email_greeting_custom', 'postal_greeting_custom', 'prefix_id', 'suffix_id', 'gender_id', 'addressee_custom', 'is_deceased', 'deceased_date', 'current_employer'));
                 foreach ($commonValues[$contactType] as $value) {
                     unset($fields[$value]);
                 }
             }
             CRM_Core_BAO_Cache::setItem($fields, 'contact fields', $cacheKeyString);
         }
         self::$_exportableFields[$cacheKeyString] = $fields;
     }
     if (!$status) {
         $fields = self::$_exportableFields[$cacheKeyString];
     } else {
         $fields = array_merge(array('' => array('title' => ts('- Contact Fields -'))), self::$_exportableFields[$cacheKeyString]);
     }
     return $fields;
 }
Exemplo n.º 6
0
 /**
  * combine all the exportable fields from the lower levels object
  * 
  * currentlty we are using importable fields as exportable fields
  *
  * @param int     $contactType contact Type
  * $param boolean $status true while exporting primary contacts
  * $param boolean $export true when used during export
  *
  * @return array array of exportable Fields
  * @access public
  */
 function &exportableFields($contactType = 'Individual', $status = false, $export = false)
 {
     if (empty($contactType)) {
         $contactType = 'All';
     }
     $cacheKeyString = "exportableFields {$contactType}";
     $cacheKeyString .= $export ? "_1" : "_0";
     $cacheKeyString .= $status ? "_1" : "_0";
     if (!self::$_exportableFields || !CRM_Utils_Array::value($cacheKeyString, self::$_exportableFields)) {
         if (!self::$_exportableFields) {
             self::$_exportableFields = array();
         }
         // check if we can retrieve from database cache
         require_once 'CRM/Core/BAO/Cache.php';
         $fields =& CRM_Core_BAO_Cache::getItem('contact fields', $cacheKeyString);
         if (!$fields) {
             $fields = array();
             $fields = array_merge($fields, CRM_Contact_DAO_Contact::export());
             // the fields are meant for contact types
             if (in_array($contactType, array('Individual', 'Household', 'Organization', 'All'))) {
                 require_once 'CRM/Core/OptionValue.php';
                 $fields = array_merge($fields, CRM_Core_OptionValue::getFields('', $contactType));
             }
             // add current employer for individuals
             $fields = array_merge($fields, array('current_employer' => array('name' => 'organization_name', 'title' => ts('Current Employer'))));
             $locationType = array();
             if ($status) {
                 $locationType['location_type'] = array('name' => 'location_type', 'where' => 'civicrm_location_type.name', 'title' => ts('Location Type'));
             }
             $IMProvider = array();
             if ($status) {
                 $IMProvider['im_provider'] = array('name' => 'im_provider', 'where' => 'im_provider.name', 'title' => ts('IM Provider'));
             }
             $locationFields = array_merge($locationType, CRM_Core_DAO_Address::export(), CRM_Core_DAO_Phone::export(), CRM_Core_DAO_Email::export(), $IMProvider, CRM_Core_DAO_IM::export(true), CRM_Core_DAO_OpenID::export());
             foreach ($locationFields as $key => $field) {
                 $locationFields[$key]['hasLocationType'] = true;
             }
             $fields = array_merge($fields, $locationFields);
             //add world region
             require_once "CRM/Core/DAO/Worldregion.php";
             $fields = array_merge($fields, CRM_Core_DAO_Worldregion::export());
             $fields = array_merge($fields, CRM_Contact_DAO_Contact::export());
             if ($contactType != 'All') {
                 $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport($contactType, $status, true));
             } else {
                 foreach (array('Individual', 'Household', 'Organization') as $type) {
                     $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport($type));
                 }
             }
             //fix for CRM-791
             if ($export) {
                 $fields = array_merge($fields, array('groups' => array('title' => ts('Group(s)')), 'tags' => array('title' => ts('Tag(s)')), 'notes' => array('title' => ts('Note(s)'))));
             } else {
                 $fields = array_merge($fields, array('group' => array('title' => ts('Group(s)')), 'tag' => array('title' => ts('Tag(s)')), 'note' => array('title' => ts('Note(s)'))));
             }
             //Sorting fields in alphabetical order(CRM-1507)
             foreach ($fields as $k => $v) {
                 $sortArray[$k] = CRM_Utils_Array::value('title', $v);
             }
             $fields = array_merge($sortArray, $fields);
             //unset the field which are not related to their contact type.
             if ($contactType != 'All') {
                 $commonValues = array('Individual' => array('household_name', 'legal_name', 'sic_code', 'organization_name', 'email_greeting_custom', 'postal_greeting_custom', 'addressee_custom'), 'Household' => array('first_name', 'middle_name', 'last_name', 'job_title', 'gender_id', 'birth_date', 'organization_name', 'legal_name', 'legal_identifier', 'sic_code', 'home_URL', 'is_deceased', 'deceased_date', 'current_employer', 'email_greeting_custom', 'postal_greeting_custom', 'addressee_custom', 'individual_prefix', 'individual_suffix', 'gender'), 'Organization' => array('first_name', 'middle_name', 'last_name', 'job_title', 'gender_id', 'birth_date', 'household_name', 'email_greeting', 'postal_greeting', 'email_greeting_custom', 'postal_greeting_custom', 'individual_prefix', 'individual_suffix', 'gender', 'addressee_custom', 'is_deceased', 'deceased_date', 'current_employer'));
                 foreach ($commonValues[$contactType] as $value) {
                     unset($fields[$value]);
                 }
             }
             CRM_Core_BAO_Cache::setItem($fields, 'contact fields', $cacheKeyString);
         }
         self::$_exportableFields[$cacheKeyString] = $fields;
     }
     if (!$status) {
         $fields = self::$_exportableFields[$cacheKeyString];
     } else {
         $fields = array_merge(array('' => array('title' => ts('- Contact Fields -'))), self::$_exportableFields[$cacheKeyString]);
     }
     return $fields;
 }
Exemplo n.º 7
0
 function postProcess()
 {
     $formValues = $this->controller->exportValues($this->_name);
     require_once 'CRM/Standalone/User.php';
     require_once 'CRM/Utils/System/Standalone.php';
     require_once 'CRM/Core/BAO/OpenID.php';
     $user = new CRM_Standalone_User($formValues['user_unique_id'], $formValues['email'], $formValues['first_name'], $formValues['last_name']);
     CRM_Utils_System_Standalone::getUserID($user);
     require_once 'CRM/Core/Session.php';
     $session = CRM_Core_Session::singleton();
     $contactId = $session->get('userID');
     $query = "SELECT count(id) FROM civicrm_uf_match";
     $ufCount = CRM_Core_DAO::singleValueQuery($query);
     if ($ufCount == 1 || defined('ALLOWED_TO_LOGIN')) {
         $openId = new CRM_Core_DAO_OpenID();
         $openId->contact_id = $contactId;
         $openId->find(true);
         $openId->allowed_to_login = 1;
         $openId->update();
     }
     // add first user to admin group
     if ($ufCount == 1) {
         require_once 'CRM/Contact/BAO/GroupContact.php';
         require_once 'CRM/Contact/DAO/Group.php';
         $group = new CRM_Contact_DAO_Group();
         $group->name = 'Administrators';
         $group->is_active = 1;
         if ($group->find(true)) {
             $contactIds = array($contactId);
             CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $group->id, 'Web', 'Added');
         }
     } else {
         if ($ufCount > 1 && !defined('CIVICRM_ALLOW_ALL')) {
             $session->set('msg', 'You are not allowed to login. Login failed. Contact your Administrator.');
             $session->set('goahead', "no");
         }
     }
     // Set this to false if the registration is successful
     $session->set('new_install', false);
     header("Location: index.php");
     CRM_Utils_System::civiExit();
 }