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; $invest->project_name = $projectData->name; if ($invest->save($errors)) { $invest->urlOK = SEC_URL . "/invest/done/{$invest->id}"; $invest->urlNOK = SEC_URL . "/invest/fail/{$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 'axes': $viewData = array('invest' => $invest); $view = new View("view/invest/axes.html.php", $viewData); return $view; break; case 'cash': $invest->setStatus('1'); throw new Redirection($invest->urlOK); 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"); }