/**
  * Add existing member to group rather than creating a new member
  */
 function addtogroup()
 {
     // Protect against CSRF on destructive action
     $token = $this->getForm()->getSecurityToken();
     if (!$token->checkRequest($this->controller->getRequest())) {
         return $this->httpError(400);
     }
     $data = $_REQUEST;
     $groupID = isset($data['ctf']['ID']) ? $data['ctf']['ID'] : null;
     if (!is_numeric($groupID)) {
         FormResponse::status_messsage(_t('MemberTableField.ADDINGFIELD', 'Adding failed'), 'bad');
         return;
     }
     // Get existing record either by ID or unique identifier.
     $identifierField = Member::get_unique_identifier_field();
     $className = self::$data_class;
     $record = null;
     if (isset($data[$identifierField])) {
         $record = DataObject::get_one($className, sprintf('"%s" = \'%s\'', $identifierField, $data[$identifierField]));
         if ($record && !$record->canEdit()) {
             return $this->httpError('401');
         }
     }
     // Fall back to creating a new record
     if (!$record) {
         $record = new $className();
     }
     // Update an existing record, or populate a new one.
     // If values on an existing (autocompleted) record have been changed,
     // they will overwrite current data. We need to unset 'ID'
     // record as it points to the group rather than the member record, and would
     // cause the member to be written to a potentially existing record.
     unset($data['ID']);
     $record->update($data);
     // Validate record, mainly password restrictions.
     // Note: Doesn't use Member_Validator
     $valid = $record->validate();
     if ($valid->valid()) {
         $record->write();
         $record->Groups()->add($groupID);
         $this->sourceItems();
         // TODO add javascript to highlight added row (problem: might not show up due to sorting/filtering)
         FormResponse::update_dom_id($this->id(), $this->renderWith($this->template), true);
         FormResponse::status_message(_t('MemberTableField.ADDEDTOGROUP', 'Added member to group'), 'good');
     } else {
         $message = sprintf(_t('MemberTableField.ERRORADDINGUSER', 'There was an error adding the user to the group: %s'), Convert::raw2xml($valid->starredList()));
         FormResponse::status_message($message, 'bad');
     }
     return FormResponse::respond();
 }
	/**
	 * Add existing member to group rather than creating a new member
	 */
	function addtogroup() {
		$data = $_REQUEST;
		unset($data['ID']);
		$ctfID = isset($data['ctf']) ? $data['ctf']['ID'] : null;

		if(!is_numeric($ctfID)) {
			FormResponse::status_messsage(_t('MemberTableField.ADDINGFIELD', 'Adding failed'), 'bad');
		}

		$className = Object::getCustomClass($this->stat('data_class'));
		$record = new $className();

		$record->update($data);
		
		$valid = $record->validate();

		if($valid->valid()) {
			$record->write();
			$record->Groups()->add($ctfID);

			$this->sourceItems();

			// TODO add javascript to highlight added row (problem: might not show up due to sorting/filtering)
			FormResponse::update_dom_id($this->id(), $this->renderWith($this->template), true);
			FormResponse::status_message(_t('MemberTableField.ADDEDTOGROUP','Added member to group'), 'good');
		
		} else {
			FormResponse::status_message(Convert::raw2xml("I couldn't add that user to this group:\n\n" . $valid->starredlist()), 'bad');
		}

		return FormResponse::respond();
	}
 /**
  * Add existing member to group rather than creating a new member
  */
 function addtogroup()
 {
     $data = $_REQUEST;
     unset($data['ID']);
     if (!is_numeric($data['ctf']['ID'])) {
         FormResponse::status_messsage(_t('MemberTableField.ADDINGFIELD', 'Adding failed'), 'bad');
     }
     $className = $this->stat('data_class');
     $record = new $className();
     $record->update($data);
     $record->write();
     // To Avoid duplication in the Group_Members table if the ComponentSet.php is not modified just uncomment le line below
     //if( ! $record->isInGroup( $data['ctf']['ID'] ) )
     $record->Groups()->add($data['ctf']['ID']);
     $this->sourceItems();
     // TODO add javascript to highlight added row (problem: might not show up due to sorting/filtering)
     FormResponse::update_dom_id($this->id(), $this->renderWith($this->template), true);
     FormResponse::status_message(_t('MemberTableField.ADDEDTOGROUP', 'Added member to group'), 'good');
     return FormResponse::respond();
 }