Ejemplo n.º 1
0
 /**
  * This function provides the HTML form elements
  *
  * @param object $form form object
  * @param int $inlineEditMode ( 1 for contact summary
  * top bar form and 2 for display name edit )
  *
  * @access public
  * @return void
  */
 static function buildQuickForm(&$form, $contactID)
 {
     // We provide a value for oplock_ts to client, but JS uses it carefully
     // -- i.e.  when loading the first inline form, JS copies oplock_ts to a
     // global value, and that global value is used for future form submissions.
     // Any time a form is submitted, the value will be updated.  This
     // handles cases like:
     // - V1:open V1.phone:open V1.email:open V1.email:submit V1.phone:submit
     // - V1:open E1:open E1:submit V1.email:open V1.email:submit
     // - V1:open V1.email:open E1:open E1:submit V1.email:submit V1:lock
     $timestamps = CRM_Contact_BAO_Contact::getTimestamps($contactID);
     $form->addElement('hidden', 'oplock_ts', $timestamps['modified_date'], array('id' => 'oplock_ts'));
     $form->addFormRule(array('CRM_Contact_Form_Inline_Lock', 'formRule'), $contactID);
 }
Ejemplo n.º 2
0
 /**
  * Function to create Form for CMS user using Profile
  *
  * @param object  $form
  * @param integer $gid id of group of profile
  * @param string $emailPresent true, if the profile field has email(primary)
  *
  * @access public
  * @static
  */
 static function buildForm(&$form, $gid, $emailPresent, $action = CRM_Core_Action::NONE)
 {
     $config = CRM_Core_Config::singleton();
     $showCMS = FALSE;
     $isDrupal = $config->userSystem->is_drupal;
     $isJoomla = ucfirst($config->userFramework) == 'Joomla' ? TRUE : FALSE;
     $isWordPress = $config->userFramework == 'WordPress' ? TRUE : FALSE;
     //if CMS is configured for not to allow creating new CMS user,
     //don't build the form,Fixed for CRM-4036
     if ($isJoomla) {
         $userParams = JComponentHelper::getParams('com_users');
         if (!$userParams->get('allowUserRegistration')) {
             return FALSE;
         }
     } elseif ($isDrupal && !variable_get('user_register', TRUE)) {
         return FALSE;
     } elseif ($isWordPress && !get_option('users_can_register')) {
         return FALSE;
     }
     if ($gid) {
         $isCMSUser = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $gid, 'is_cms_user');
     }
     // $cms is true when there is email(primary location) is set in the profile field.
     $session = CRM_Core_Session::singleton();
     $userID = $session->get('userID');
     $showUserRegistration = FALSE;
     if ($action) {
         $showUserRegistration = TRUE;
     } elseif (!$action && !$userID) {
         $showUserRegistration = TRUE;
     }
     if ($isCMSUser && $emailPresent) {
         if ($showUserRegistration) {
             if ($isCMSUser != 2) {
                 $extra = array('onclick' => "return showHideByValue('cms_create_account','','details','block','radio',false );");
                 $form->addElement('checkbox', 'cms_create_account', ts('Create an account?'), NULL, $extra);
                 $required = FALSE;
             } else {
                 $form->add('hidden', 'cms_create_account', 1);
                 $required = TRUE;
             }
             $form->assign('isCMS', $required);
             if (!$userID || $action & CRM_Core_Action::PREVIEW || $action & CRM_Core_Action::PROFILE) {
                 $form->add('text', 'cms_name', ts('Username'), NULL, $required);
                 if ($isDrupal && !variable_get('user_email_verification', TRUE) or $isJoomla or $isWordPress) {
                     $form->add('password', 'cms_pass', ts('Password'));
                     $form->add('password', 'cms_confirm_pass', ts('Confirm Password'));
                 }
                 $form->addFormRule(array('CRM_Core_BAO_CMSUser', 'formRule'), $form);
             }
             $showCMS = TRUE;
         }
     }
     $loginUrl = $config->userFrameworkBaseURL;
     if ($isJoomla) {
         $loginUrl = str_replace('administrator/', '', $loginUrl);
         $loginUrl .= 'index.php?option=com_users&view=login';
     } elseif ($isDrupal) {
         $loginUrl .= 'user';
         // append destination so user is returned to form they came from after login
         $destination = $config->userSystem->getLoginDestination($form);
         if (!empty($destination)) {
             $loginUrl .= '?destination=' . urlencode($destination);
         }
     }
     $form->assign('loginUrl', $loginUrl);
     $form->assign('showCMS', $showCMS);
 }
Ejemplo n.º 3
0
 /**
  * Function to create Form for CMS user using Profile
  *
  * @param object  $form
  * @param integer $gid id of group of profile
  * @param string $emailPresent true, if the profile field has email(primary)
  *
  * @access public
  * @static
  */
 static function buildForm(&$form, $gid, $emailPresent, $action = CRM_Core_Action::NONE)
 {
     $config =& CRM_Core_Config::singleton();
     $showCMS = false;
     $isDrupal = ucfirst($config->userFramework) == 'Drupal' ? TRUE : FALSE;
     $isJoomla = ucfirst($config->userFramework) == 'Joomla' ? TRUE : FALSE;
     //if CMS is configured for not to allow creating new CMS user,
     //don't build the form,Fixed for CRM-4036
     if ($isJoomla) {
         $userParams =& JComponentHelper::getParams('com_users');
         if (!$userParams->get('allowUserRegistration')) {
             return false;
         }
     } else {
         if ($isDrupal && !variable_get('user_register', TRUE)) {
             return false;
         }
     }
     // if cms is drupal having version greater than equal to 5.1
     // we also need email verification enabled, else we dont do it
     // then showCMS will true
     if ($isDrupal or $isJoomla) {
         if ($gid) {
             $isCMSUser = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $gid, 'is_cms_user');
         }
         // $cms is true when there is email(primary location) is set in the profile field.
         $session =& CRM_Core_Session::singleton();
         $userID = $session->get('userID');
         $showUserRegistration = false;
         if ($action) {
             $showUserRegistration = true;
         } elseif (!$action && !$userID) {
             $showUserRegistration = true;
         }
         if ($isCMSUser && $emailPresent) {
             if ($showUserRegistration) {
                 if ($isCMSUser != 2) {
                     $extra = array('onclick' => "return showHideByValue('cms_create_account','','details','block','radio',false );");
                     $form->addElement('checkbox', 'cms_create_account', ts('Create an account?'), null, $extra);
                     $required = false;
                 } else {
                     $form->add('hidden', 'cms_create_account', 1);
                     $required = true;
                 }
                 $form->assign('isCMS', $required);
                 require_once 'CRM/Core/Action.php';
                 if (!$userID || $action & CRM_Core_Action::PREVIEW || $action & CRM_Core_Action::PROFILE) {
                     $form->add('text', 'cms_name', ts('Username'), null, $required);
                     if ($isDrupal && !variable_get('user_email_verification', TRUE) or $isJoomla) {
                         $form->add('password', 'cms_pass', ts('Password'));
                         $form->add('password', 'cms_confirm_pass', ts('Confirm Password'));
                     }
                     $form->addFormRule(array('CRM_Core_BAO_CMSUser', 'formRule'), $form);
                 }
                 $showCMS = true;
             }
         }
     }
     $loginUrl = $config->userFrameworkBaseURL;
     if ($isJoomla) {
         $loginUrl = str_replace('administrator/', '', $loginUrl);
         $loginUrl .= 'index.php?option=com_user&view=login';
     } elseif ($isDrupal) {
         $loginUrl .= 'user';
         // For Drupal we can redirect user to current page after login by passing it as destination.
         require_once 'CRM/Utils/System.php';
         $args = null;
         $id = $form->get('id');
         if ($id) {
             $args .= "&id={$id}";
         } else {
             $gid = $form->get('gid');
             if ($gid) {
                 $args .= "&gid={$gid}";
             } else {
                 // Setup Personal Campaign Page link uses pageId
                 $pageId = $form->get('pageId');
                 if ($pageId) {
                     $args .= "&pageId={$pageId}&action=add";
                 }
             }
         }
         if ($args) {
             // append destination so user is returned to form they came from after login
             $destination = CRM_Utils_System::currentPath() . "?reset=1" . $args;
             $loginUrl .= '?destination=' . urlencode($destination);
         }
     }
     $form->assign('loginUrl', $loginUrl);
     $form->assign('showCMS', $showCMS);
 }