private function process_userPersonal(&$project, &$errors) { if (!isset($_POST['process_userPersonal'])) { return false; } // campos que guarda este paso $fields = array('contract_name', 'contract_nif', 'contract_email', 'phone', 'contract_birthdate', 'address', 'zipcode', 'location', 'country'); $personalData = array(); foreach ($fields as $field) { if (isset($_POST[$field])) { $project->{$field} = $_POST[$field]; $personalData[$field] = $_POST[$field]; } } if (!$_POST['secondary_address']) { $project->post_address = null; $project->post_zipcode = null; $project->post_location = null; $project->post_country = null; } // actualizamos estos datos en los personales del usuario if (!empty($personalData)) { Model\User::setPersonal($project->owner, $personalData, true); } // cuentas bancarias $ppacc = !empty($_POST['paypal']) ? $_POST['paypal'] : ''; $bankacc = !empty($_POST['bank']) ? $_POST['bank'] : ''; // primero checkeamos si la cuenta Paypal es tipo email if (!Check::mail($ppacc)) { $project->errors['userPersonal']['paypal'] = Text::get('validate-project-paypal_account'); } else { $project->okeys['userPersonal']['paypal'] = true; } $accounts = Model\Project\Account::get($project->id); $accounts->paypal = $ppacc; $accounts->bank = $bankacc; $accounts->save($project->errors['userPersonal']); return true; }
public function index($project = null) { if (empty($project)) { throw new Redirection('/discover', Redirection::TEMPORARY); } $message = ''; $projectData = Model\Project::get($project); $methods = static::_methods(); // si no está en campaña no pueden esta qui ni de coña if ($projectData->status != 3) { throw new Redirection('/project/' . $project, Redirection::TEMPORARY); } if ($_SERVER['REQUEST_METHOD'] == 'POST') { $errors = array(); $los_datos = $_POST; $method = \strtolower($_POST['method']); if (!isset($methods[$method])) { Message::Error(Text::get('invest-method-error')); throw new Redirection(SEC_URL . "/project/{$project}/invest/?confirm=fail", Redirection::TEMPORARY); } if (empty($_POST['amount'])) { Message::Error(Text::get('invest-amount-error')); throw new Redirection(SEC_URL . "/project/{$project}/invest/?confirm=fail", Redirection::TEMPORARY); } // dirección de envio para las recompensas // o datoas fiscales del donativo $address = array('name' => $_POST['fullname'], 'nif' => $_POST['nif'], 'address' => $_POST['address'], 'zipcode' => $_POST['zipcode'], 'location' => $_POST['location'], 'country' => $_POST['country']); if ($projectData->owner == $_SESSION['user']->id) { Message::Error(Text::get('invest-owner-error')); throw new Redirection(SEC_URL . "/project/{$project}/invest/?confirm=fail", Redirection::TEMPORARY); } // añadir recompensas que ha elegido $chosen = $_POST['selected_reward']; if ($chosen == 0) { // renuncia a las recompensas, bien por el/ella $resign = true; $reward = false; } else { // ya no se aplica esto de recompensa es de tipo Reconocimiento para donativo $resign = false; $reward = true; } // insertamos los datos personales del usuario si no tiene registro aun Model\User::setPersonal($_SESSION['user']->id, $address, false); $invest = new Model\Invest(array('amount' => $_POST['amount'], 'user' => $_SESSION['user']->id, 'project' => $project, 'method' => $method, 'status' => '-1', 'invested' => date('Y-m-d'), 'anonymous' => $_POST['anonymous'], 'resign' => $resign)); if ($reward) { $invest->rewards = array($chosen); } $invest->address = (object) $address; if ($invest->save($errors)) { $invest->urlOK = SEC_URL . "/invest/confirmed/{$project}/{$invest->id}"; $invest->urlNOK = SEC_URL . "/invest/fail/{$project}/{$invest->id}"; Model\Invest::setDetail($invest->id, 'init', 'Se ha creado el registro de aporte, el usuario ha clickado el boton de tpv o paypal. Proceso controller/invest'); switch ($method) { case 'tpv': // redireccion al tpv if (Tpv::preapproval($invest, $errors)) { die; } else { Message::Error(Text::get('invest-tpv-error_fatal')); } break; case 'paypal': // Petición de preapproval y redirección a paypal if (Paypal::preapproval($invest, $errors)) { die; } else { Message::Error(Text::get('invest-paypal-error_fatal')); } break; case 'cash': // En betatest aceptamos cash para pruebas if (GOTEO_ENV != 'real') { $invest->setStatus('1'); throw new Redirection($invest->urlOK); } else { throw new Redirection('/'); } break; } } else { Message::Error(Text::get('invest-create-error')); } } else { Message::Error(Text::get('invest-data-error')); } throw new Redirection("/project/{$project}/invest/?confirm=fail"); }
/** * Tratamiendo del formulario de datos personales * * @param string(59) $id del usuario logueado * @param array $errors (por referencia) * @param string $log_action (por referencia) * @return boolean si se guarda bien */ public static function process_personal($id, &$errors, &$log_action) { $fields = array('contract_name', 'contract_nif', 'phone', 'address', 'zipcode', 'location', 'country'); $personalData = array(); foreach ($fields as $field) { $personalData[$field] = $_POST[$field]; } // actualizamos estos datos en los personales del usuario if (Model\User::setPersonal($id, $personalData, true, $errors)) { Message::Info(Text::get('user-personal-saved')); $log_action = 'Modificado sus datos personales'; //feed admin return true; } else { Message::Error(Text::get('user-save-fail')); $log_action = '¡ERROR! al modificar sus datos personales'; //feed admin return false; } }