public function login() { $success = false; if (!$this->session->userdata('is_session')) { $this->load->helper('MY_email'); $session = true; $fatalErr = false; $email = false; $pass = false; $errMsg = 'Error in Email address or password'; if (valid_edu_email($this->input->post('email'))) { $email = $this->input->post('email'); } if (strlen($this->input->post('pass')) >= 4) { $pass = $this->input->post('pass'); } if ($email && $pass) { $agent = $this->Agents_mod->login($email, $pass); if ($agent['status'] == 0) { $errMsg = 'Your account was suspended. Please contact the Administrator.'; } if ($agent && $agent['status'] != 0) { $agent['is_session'] = true; $agent['a_session'] = true; //Lo uso para individualizar en el web front end. $this->session->set_userdata($agent); //Me fijo si hay una session cargada pero con un edit de un completed bb, si es asi la elimino y creo una blanca. $this->Buybacks_mod->removeBuybackSession(true); //Creo la BuybackSession en la db. $session = $this->Agents_mod->startAgentBuybackSession($agent['id_a']); //Si no existe ninguna session este metodo crea y carga en la cookie session, y si habia solo la carga en la cookie session if ($session) { //Agrego login Logs $args['id_s'] = $this->session->userdata('id_s'); $args['id_a'] = $this->session->userdata('id_a'); $args['type'] = 'ACP'; $args['name'] = $this->session->userdata('fullname'); $args['mail'] = $email; $args['ip'] = $_SERVER['REMOTE_ADDR']; $args['date'] = time(); $this->Agents_mod->addAgentLog($args); $success = true; } else { //Si entro aca es que hubo 'error' en la transacción. $errMsg = 'Error setting session (code bbs-001). We sorry PLEASE contact the Administrator and copy de error code.'; $fatalErr = true; //(TODO: ver que hacer ante esta excepcion) } } } echo json_encode(array('success' => $success, 'fatalErr' => $fatalErr, 'errMsg' => $errMsg)); } else { //Si entro aca ya estaba logueado echo json_encode(array('success' => $success, 'session' => true, 'errMsg' => 'Already logged')); } }
public function createBuyback() { $this->_existSession($this->uri->segment(3)); $success = false; $receipt = ''; $amount = ''; $studentName = $this->input->post('fullname'); $studentEmail = $this->input->post('email'); $gradYear = $this->input->post('grad_year'); $payPeriod = $this->input->post('pay_period'); $streetAddress = !$this->input->post('street_address') ? '' : $this->input->post('street_address'); $phone = $this->input->post('phone'); $city = !$this->input->post('city') ? '' : $this->input->post('city'); //Tiene tambien State y ZIP, va todo junto $editFlag = $this->session->userdata('editing') ? true : false; $errMsg = ''; if (empty($phone) || is_int($phone) || strlen($phone) != 10) { $errMsg .= "Phone must be a number with 10 digits required.</br>"; } if (empty($studentName)) { $errMsg .= "Student Name required.</br>"; } $requireEdu = $this->Applicants_mod->getOption($optionName = 'require_edu', $optionDefaultValue = '1'); if ($requireEdu) { if (empty($studentEmail) || !valid_edu_email($studentEmail)) { $errMsg .= "Student Email required (domain .edu).</br>"; } } else { if (empty($studentEmail) || !valid_edu_email_without_edu($studentEmail)) { $errMsg .= "Student Email required.</br>"; } } if ($gradYear == 'none' || empty($gradYear)) { $errMsg .= "Grad Year required.</br>"; } if ($payPeriod == 'none' || empty($payPeriod)) { $errMsg .= "Payment Period required.</br>"; } if (empty($errMsg)) { //Devuelve en esta variable ($createdBuyback) el idBB creado recien. $createdBuyback = $this->Buybacks_mod->setCompletedBuyback(array('student_name' => $studentName, 'student_email' => $studentEmail, 'grad_year' => $gradYear, 'payment_period' => $payPeriod, 'street_address' => $streetAddress, 'student_phone' => $phone, 'city_state_zip' => $city), $editFlag); if (!$createdBuyback) { $errMsg = 'Error (code: bbs-002) creating buyback. We sorry PLEASE contact the Administrator and copy de error code.'; } else { $this->Buybacks_mod->addBuybackBookToHistoryLog($createdBuyback); if (!$this->Agents_mod->startAgentBuybackSession($this->session->userdata('id_a'))) { //Algo salio mal. Quito de la session el id_bb que usaba para edit. $this->session->unset_userdata('id_bb'); $errMsg = "Buyback created but cannot create new session. Please relogin and contact to adminitrator. Warning code (code: bbs-003)"; } else { //Quito de la session el id_bb que usaba para edit. $this->session->unset_userdata('id_bb'); } $prepareEmail['type'] = 1; //Le digo al modelo de envio de mail que es un bb completed (2 es hired mail) $prepareEmail['student_email'] = $studentEmail; $prepareEmail['student_name'] = $studentName; $prepareEmail['books_list'] = array(); if ($this->Buybacks_mod->getBuybackBooksList($createdBuyback)) { $bbData = $this->Buybacks_mod->getAdminBuybackDataForEdit($createdBuyback); $prepareEmail['payment_period'] = $bbData->payment_period == 1 ? 'December' : 'January'; $prepareEmail['payment_field'] = $bbData->payment_period; $prepareEmail['receipt'] = $bbData->receipt; $prepareEmail['books_list'] = $this->Buybacks_mod->getBuybackBooksList($createdBuyback); $receipt = $bbData->receipt; $amount = $bbData->amount; $this->Emails_mod->sendEmail($prepareEmail); } $success = true; //$errMsg = 'Buyback Completed</br>Congratulations!'; $errMsg = 'Buyback completed!'; // Send sms by Twilio api if (!empty($phone)) { require $_SERVER['DOCUMENT_ROOT'] . '/dbk/resources/twilio-php-master/Services/Twilio.php'; // set your AccountSid and AuthToken from www.twilio.com/user/account $AccountSid = "AC2ca2a16f8fba758c7df15a7178714099"; $AuthToken = "604b18ccc747a16db4aa145c264659bb"; $client = new Services_Twilio($AccountSid, $AuthToken); try { $message = $client->account->messages->create(array("From" => "(763) 710-2665", "To" => $phone, "Body" => "Your BeerForTextbooks buyback " . $receipt . " was \$" . $amount . " - check your inbox for an email and get paid ASAP! Questions? questions@beerfortextbooks.com")); /*$errMsg .= "<br>Receipt: <h3><span class='label label-default'>$receipt</span></h3>"; $errMsg .= "<br>Sent message {$message->sid}";*/ $errMsg = "**RECEIPT number {$receipt}**<br><br>Buyback completed!<br>Email and text message has been sent to the buyback customer successfully."; } catch (Exception $e) { $success = false; $errMsg = $e->getMessage() . "\n"; } } } } echo json_encode(array('success' => $success, 'session' => true, 'errMsg' => $errMsg, 'receipt' => $receipt)); exit; }
public function saveAdminBuybackChanges() { $this->_existsKarolSession($this->uri->segment(3)); $success = false; $receipt = ''; $data['id_bb'] = $this->input->post('id_bb'); $data['id_a'] = $this->input->post('id_a'); $data['id_s'] = $this->input->post('id_s'); //Por las dudas $data['student_name'] = $this->input->post('student_name'); $data['student_email'] = $this->input->post('student_email'); $data['street_address'] = $this->input->post('street_address'); $data['student_phone'] = $this->input->post('student_phone'); $data['city_state_zip'] = $this->input->post('city'); $data['grad_year'] = $this->input->post('grad_year'); $data['timestamp'] = time(); $data['payment_period'] = $this->input->post('payment_period'); $errMsg = ''; if (empty($data['student_name'])) { $errMsg .= "Student Name required.</br>"; } $requireEdu = $this->Applicants_mod->getOption($optionName = 'require_edu', $optionDefaultValue = '1'); if ($requireEdu) { if (empty($data['student_email']) || !valid_edu_email($data['student_email'])) { $errMsg .= "Student Email required (domain .edu).</br>"; } } else { if (empty($data['student_email']) || !valid_edu_email_without_edu($data['student_email'])) { $errMsg .= "Student Email required.</br>"; } } if ($data['grad_year'] == 'none') { $errMsg .= "Grad Year required.</br>"; } if ($data['payment_period'] == 'none') { $errMsg .= "Payment Period required.</br>"; } if (empty($errMsg)) { $editFlag = $this->input->post('edit_flag') == 'yes' ? true : false; $result = $this->Buybacks_mod->saveAdminBuybackChanges($data, $editFlag); if ($result) { $success = true; if (!$editFlag) { $receipt = $this->Buybacks_mod->getBuybackReceipt($result); } //$result si salio todo bien trae el id_bb sobre el que se trabajo $errMsg = $editFlag ? 'Buyback updated successfully' : 'Buyback Created successfully <br> <h3><span class="label label-default">' . $receipt . '</span></h3>'; } else { $success = false; $errMsg = 'Cannot create or edit Buyback. Error (code: ads-009)'; } } echo json_encode(array('success' => $success, 'session' => true, 'errMsg' => $errMsg, 'receipt' => $receipt)); }
public function createBuyback() { $this->_existSession($this->uri->segment(3)); $success = false; $studentName = $this->input->post('fullname'); $studentEmail = $this->input->post('email'); $gradYear = $this->input->post('grad_year'); $payPeriod = $this->input->post('pay_period'); $streetAddress = !$this->input->post('street_address') ? '' : $this->input->post('street_address'); $city = !$this->input->post('city') ? '' : $this->input->post('city'); //Tiene tambien State y ZIP, va todo junto $editFlag = $this->input->post('edit_flag') == 'yes' ? true : false; //Si viene true edito (TODO: Terminar de modificar la edicion!!!) $errMsg = ''; if (empty($studentName)) { $errMsg .= "Student Name required.</br>"; } if (empty($studentEmail)) { $errMsg .= "Student Email required (domain .edu).</br>"; } if (!valid_edu_email($studentEmail)) { $errMsg .= "Student Email required (domain .edu).</br>"; } if ($gradYear == 'none') { $errMsg .= "Grad Year required.</br>"; } if ($payPeriod == 'none') { $errMsg .= "Payment Period required.</br>"; } if (empty($errMsg)) { //Devuelve en esta variable ($createdBuyback) el idBB creado recien. $createdBuyback = $this->Buybacks_mod->setCompletedBuyback(array('student_name' => $studentName, 'student_email' => $studentEmail, 'grad_year' => $gradYear, 'payment_period' => $payPeriod, 'street_address' => $streetAddress, 'city_state_zip' => $city), $editFlag); if (!$createdBuyback) { $errMsg = 'Error (code: bbs-002) creating buyback. We sorry PLEASE contact the Administrator and copy de error code.'; } else { $this->Buybacks_mod->addBuybackBookToHistoryLog($createdBuyback); if (!$this->Agents_mod->startAgentBuybackSession($this->session->userdata('id_a'))) { //Algo salio mal. Quito de la session el id_bb que usaba para edit. $this->session->unset_userdata('id_bb'); $errMsg = "Buyback created but cannot create new session. Please relogin and contact to adminitrator. Warning code (code: bbs-003)"; } else { //Quito de la session el id_bb que usaba para edit. $this->session->unset_userdata('id_bb'); } /*$prepareEmail['student_email'] = $studentEmail; $prepareEmail['student_name'] = $studentName; $prepareEmail['books_list'] = array();*/ if ($this->Buybacks_mod->getBuybackBooksList($createdBuyback)) { $bbData = $this->Buybacks_mod->getAdminBuybackDataForEdit($createdBuyback); $prepareEmail['payment_period'] = $bbData->payment_period == 1 ? 'Dec' : 'Jan'; $prepareEmail['payment_field'] = $bbData->payment_period; $prepareEmail['receipt'] = $bbData->receipt; $prepareEmail['books_list'] = $this->Buybacks_mod->getBuybackBooksList($createdBuyback); //$this->Emails_mod->sendEmail($prepareEmail); } $success = true; $errMsg = 'Buyback Completed</br>Congratulations!'; } } echo json_encode(array('success' => $success, 'session' => true, 'errMsg' => $errMsg)); }
public function login() { $success = false; if (!$this->session->userdata('is_session')) { $this->load->helper('MY_email'); $session = true; $fatalErr = false; $email = false; $pass = false; $errMsg = 'Error in Email address or password'; $requireEdu = $this->Applicants_mod->getOption($optionName = 'require_edu', $optionDefaultValue = '1'); if ($requireEdu) { if (valid_edu_email($this->input->post('email'))) { $email = $this->input->post('email'); } } else { if (valid_edu_email_without_edu($this->input->post('email'))) { $email = $this->input->post('email'); } } if (strlen($this->input->post('pass')) >= 4) { $pass = $this->input->post('pass'); } if (trim($email) && trim($pass)) { $agent = $this->Agents_mod->login($email, $pass); if ($agent) { //Es agent if ($agent['status'] != 0) { //$agent['is_session'] = true; //OJOOOO! en muchos lugares estoy validadno con is_session y esta se genera cuando se crea cualquier session por defecto, cambiar eso en los metodos! $agent['a_session'] = true; $agent['home_location'] = 'buybacks/bbCreateView'; $this->session->set_userdata($agent); //Me fijo si hay una session cargada pero con un edit de un completed bb, si es asi la elimino y creo una blanca. $this->Buybacks_mod->removeBuybackSession(true); //Creo la BuybackSession en la db. $session = $this->Agents_mod->startAgentBuybackSession($agent['id_a']); //Si no existe ninguna session este metodo crea y carga en la cookie session, y si habia solo la carga en la cookie session if ($session) { //Agrego login Logs $args['id_s'] = $this->session->userdata('id_s'); $args['id_a'] = $this->session->userdata('id_a'); $args['type'] = 'ACP'; $args['name'] = $this->session->userdata('fullname'); $args['mail'] = $email; $args['ip'] = $_SERVER['REMOTE_ADDR']; $args['date'] = time(); $this->Agents_mod->addAgentLog($args); $success = true; } else { //Si entro aca es que hubo 'error' en la transacción. $errMsg = 'Error setting session (code bbs-001). We sorry PLEASE contact the Administrator and copy de error code.'; $fatalErr = true; //(TODO: ver que hacer ante esta excepcion) } } else { $errMsg = 'Your account was suspended. Please contact the Administrator.'; } } else { // Para applicants $applicant = $this->Applicants_mod->login($email, $pass); //Si es applicant vienen los datos if ($applicant) { $applicant['app_session'] = true; $applicant['home_location'] = 'applicants/applicantProgressView'; $applicant['tut_progress'] = 0; $applicant['last_slide'] = $this->Tutorials_mod->getLastSlide(); $this->session->set_userdata($applicant); $success = true; } } } echo json_encode(array('success' => $success, 'fatalErr' => $fatalErr, 'errMsg' => $errMsg, 'location' => $this->session->userdata('home_location'))); } else { //Si entro aca ya estaba logueado echo json_encode(array('success' => $success, 'session' => true, 'errMsg' => 'Already logged', 'location' => $this->session->userdata('home_location'))); } }