/** * Validate the information the user submitted * @return boolean Whether the form data validated OK. */ function Validate() { global $session, $c; $session->Dbg("OrganisationPlus", "Validate: Validating registration"); $valid = $this->validation->Validate($this); if (!$this->AllowedTo('edit_extras')) { if (isset($_POST['org_type']) || isset($_POST['current_sla']) || isset($_POST['debtor_no']) || isset($_POST['work_rate'])) { $c->messages[] = "ERROR: You may not modify that data."; $valid = false; } } if (!$this->AllowedTo('see_other_orgs')) { if (isset($_POST['org_code']) && $_POST['org_code'] != $session->org_code) { $c->messages[] = "ERROR: You may not modify that data."; $valid = false; } } // Password changing is a little special... if ($_POST['new_password'] != "******" && $_POST['new_password'] != "") { if ($_POST['new_password'] == $_POST['confirm_password']) { $this->Set('password', $_POST['new_password']); } else { $c->messages[] = "ERROR: The new password must match the confirmed password."; $valid = false; } } if (floatval($_POST['work_rate']) == 0) { $_POST['work_rate'] = $session->work_rate; } $this->Set("role", 'C'); // This user will always have coordinate role to start with $this->Set("email_ok", date('Y-m-d H:i:s')); $this->Set("usr_active", true); $this->Set("organisation_specific", true); $this->Set("system_active", true); $this->Set("org_active", true); $session->Dbg("OrganisationPlus", "Validate: OrganisationPlus %s validation", $valid ? "passed" : "failed"); return $valid; }
/** * Save conversation from form submission. * * @since 2.0.0 * @access public * * @param array $FormPostValues Values submitted via form. * @param object $MessageModel Message starting the conversation. * @return int Unique ID of conversation created or updated. */ public function Save($FormPostValues, $MessageModel) { $Session = Gdn::Session(); // Define the primary key in this model's table. $this->DefineSchema(); $MessageModel->DefineSchema(); if (!GetValue('RecipientUserID', $FormPostValues) && isset($FormPostValues['To'])) { $To = explode(',', $FormPostValues['To']); $To = array_map('trim', $To); $RecipientUserIDs = $this->SQL->Select('UserID')->From('User')->WhereIn('Name', $To)->Get(); $RecipientUserIDs = ConsolidateArrayValuesByKey($RecipientUserIDs, 'UserID'); $FormPostValues['RecipientUserID'] = $RecipientUserIDs; } // Add & apply any extra validation rules: $this->Validation->ApplyRule('Body', 'Required'); $MessageModel->Validation->ApplyRule('Body', 'Required'); // Make sure that there is at least one recipient $this->Validation->AddRule('OneOrMoreArrayItemRequired', 'function:ValidateOneOrMoreArrayItemRequired'); $this->Validation->ApplyRule('RecipientUserID', 'OneOrMoreArrayItemRequired'); // Add insert/update fields $this->AddInsertFields($FormPostValues); $this->AddUpdateFields($FormPostValues); // Validate the form posted values $ConversationID = FALSE; if ($this->Validate($FormPostValues) && $MessageModel->Validate($FormPostValues)) { $Fields = $this->Validation->ValidationFields(); // All fields on the form that relate to the schema // Define the recipients, and make sure that the sender is in the list $RecipientUserIDs = GetValue('RecipientUserID', $Fields, 0); if (!in_array($Session->UserID, $RecipientUserIDs)) { $RecipientUserIDs[] = $Session->UserID; } // Also make sure there are no duplicates in the recipient list $RecipientUserIDs = array_unique($RecipientUserIDs); sort($RecipientUserIDs); $Fields = $this->Validation->SchemaValidationFields(); // All fields on the form that relate to the schema $Fields['Contributors'] = Gdn_Format::Serialize($RecipientUserIDs); $ConversationID = $this->SQL->Insert($this->Name, $Fields); $FormPostValues['ConversationID'] = $ConversationID; $MessageID = $MessageModel->Save($FormPostValues); $this->SQL->Update('Conversation')->Set('FirstMessageID', $MessageID)->Where('ConversationID', $ConversationID)->Put(); // Now that the message & conversation have been inserted, insert all of the recipients foreach ($RecipientUserIDs as $UserID) { $CountReadMessages = $UserID == $Session->UserID ? 1 : 0; $this->SQL->Options('Ignore', TRUE)->Insert('UserConversation', array('UserID' => $UserID, 'ConversationID' => $ConversationID, 'LastMessageID' => $MessageID, 'CountReadMessages' => $CountReadMessages, 'DateConversationUpdated' => $FormPostValues['DateUpdated'])); } // And update the CountUnreadConversations count on each user related to the discussion. $this->UpdateUserUnreadCount($RecipientUserIDs, TRUE); // Add notifications (this isn't done by the conversationmessagemodule // because the conversation has not yet been created at the time they are // inserted) $UnreadData = $this->SQL->Select('uc.UserID')->From('UserConversation uc')->Where('uc.ConversationID', $ConversationID)->Where('uc.UserID <>', $Session->UserID)->Get(); $ActivityModel = new ActivityModel(); foreach ($UnreadData->Result() as $User) { // Notify the users of the new message. $ActivityID = $ActivityModel->Add($Session->UserID, 'ConversationMessage', '', $User->UserID, '', "/messages/{$ConversationID}#{$MessageID}", FALSE); $Story = ArrayValue('Body', $FormPostValues, ''); $ActivityModel->SendNotification($ActivityID, $Story); } } else { // Make sure that all of the validation results from both validations are present for view by the form foreach ($MessageModel->ValidationResults() as $FieldName => $Results) { foreach ($Results as $Result) { $this->Validation->AddValidationResult($FieldName, $Result); } } } return $ConversationID; }
/** * A convenience method to check that the form-posted data is valid; just * in case you don't want to jump directly to the save if the data *is* * valid. * * @param string $FormPostValues * @todo $FormPostValues needs a description and correct variable type. */ public function Validate($FormPostValues) { $this->Validation->ApplySchema($this->Data); // Validate the form posted values return $this->Validation->Validate($FormPostValues); }
/** * @param unknown_type $FormPostValues * @param unknown_type $Insert * @return unknown * @todo add doc */ public function Validate($FormPostValues, $Insert = FALSE) { return $this->Validation->Validate($FormPostValues, $Insert); }
/** * check method - checks if the provided code matches the previosly generated catpcha * * @param string $userCode * @param boolean $caseInsensitive * @return boolean */ function check($userCode, $caseInsensitive = true) { return $this->visualCaptcha->Validate($userCode, $caseInsensitive); }
/** * Default implementation of Validate * * @see \rakelley\jhframe\interfaces\action\IRequiresValidation::Validate() */ public function Validate() { $this->input = $this->formValidator->Validate($this->view); $this->validateInput(); return true; }