public function updateAction() { $frmUseruserForm = new Form_User(); $frmUseruserForm->setAction('/user/update'); $frmUseruserForm->removeElement('password'); $mdlUseruserModel = new Model_User(); if ($this->_request->isPost()) { if ($frmUseruserForm->isValid($_POST)) { $mdlUseruserModel->updateUser($frmUseruserForm->getValue('id'), $frmUseruserForm->getValue('username'), $frmUseruserForm->getValue('first_name'), $frmUseruserForm->getValue('last_name'), $frmUseruserForm->getValue('role')); return $this->_forward('list'); } } else { $id = $this->_request->getParam('id'); $currentUser = $mdlUseruserModel->find($id)->current(); $frmUseruserForm->populate($currentUser->toArray()); } $this->view->form = $frmUseruserForm; }
$u = $p = ""; if (isset($_POST['edit_user'])) { if ($_POST['txtuser'] == NULL) { $error[] = "Please input your username"; } else { $u = $_POST['txtuser']; } if ($_POST['txtpass'] != $_POST['txtrepass']) { $error[] = "Password not match"; } else { if ($_POST['txtpass'] != "") { $p = $_POST['txtpass']; } else { $p = "none"; } } $l = $_POST['level']; if ($u && $p && $l) { $muser->setUsername($u); $muser->setPassword($p); $muser->setLevel($l); if ($muser->checkUsername($id) == true) { $muser->updateUser($id); redirect("{$baseurl}/user/list"); } else { $error[] = "Your user name has been registed"; } } } $data = $muser->getUserById($id); require "views/user/edit_view.php";
public function ussdProgress($user, $message) { $menu_item_id = $user->menu_item_id; // print_r($menu_item_id); // exit; $step = $user->step; $menuModel = new Model_Menu(); $menu = $menuModel->getMenu($menu_item_id); // print_r($menu); // exit; if ($menu['id'] == 0) { $reply = "We could not understand your response"; $output = $this->mainMenu($user, $user['phoneno']); return $reply . PHP_EOL . $output; } // $menuType = $menu->type; // print_r($menuType); // exit; // print_r($step); // exit; if ($menuType == 2) { //no verification but feed it response and update step as you move on if ($step > 0) { $message = strtolower($message); //feed the response to the table // print_r($message); // exit; $valid = 1; $valid = $this->validateResponse($menu->id, $message, $step); // print_r($valid); // exit; if (is_array($valid) && $valid['valid'] == 0) { $output = $valid['message']; //print_r($output); return $output; } $dataa = array('user_id' => $user['id'], 'menu_id' => $menu_item_id, 'step' => $step, 'response' => $message); //print_r($dataa); //exit; $Response_Model = new Model_Response(); $result = $Response_Model->createResponse($dataa); // print_r($result); // exit; if ($result) { //check if we have another step, if we do, request, if we dont, compile the summary and confirm $next_step = $step + 1; // print_r($step); // exit; $menuItemsModel = new Model_MenuItems(); $menuItem = $menuItemsModel->getNextMenuStep($menu_item_id, $next_step); // print_r($menuItem); // exit; if ($menuItem['id'] != 0) { //update user data and next request and send back $userModel = new Model_User(); $result = $userModel->updateUserMenuStep($user['id'], $next_step); //$menuItem = $menuItemsModel -> getNextMenuStep($menu_item_id,$step); return $menuItem->description; //exit; } else { //compile summary for confirmation //$menuItemsModel = new Model_MenuItems(); $MenuItems = $menuItemsModel->getMenuItems($menu_item_id); //print_r($MenuItems); //exit; //build up the responses $confirmation = "Confirm?: " . $menu->description; foreach ($MenuItems as $key => $value) { // print_r($value); // exit; //print_r($confirmation); //exit; //select the corresponding response if ($value[4] != 'PIN') { $phrase = $value[4]; //print_r($value[4]); //$menu_item_id = $value[''] $response = $Response_Model->getResponse($user['id'], $menu_item_id, $value[3]); //print_r($response['response']."<br>"); if ($value[4] == 'Gender') { if ($response['response'] == 1) { $response['response'] = 'Male'; } elseif ($response['response'] == 2) { $response['response'] = 'Female'; } } elseif ($value[4] == 'Language') { if ($response['response'] == 1) { $response['response'] = 'English'; } elseif ($response['response'] == 2) { $response['response'] = 'Kiswahili'; } } elseif ($value[4] == 'Card') { if ($response['response'] == 1) { $response['response'] = 'Bebapay'; } elseif ($response['response'] == 2) { $response['response'] = 'Abiria'; } elseif ($response['response'] == 3) { $response['response'] = '1963'; } } $confirmation = $confirmation . PHP_EOL . $value[4] . ": " . $response['response']; //print_r($response['response']); //exit; } } // print_r($confirmation); // exit; //update the status to waiting for confirmation $userModel = new Model_User(); $data = array('session' => 2, 'confirm_from' => $menu->id); //print_r($user['id']); //exit; $result = $userModel->updateUserData($data, $user['id']); //print_r($result); //exit; //$result = $userModel -> updateUserSession($user['id'],2); return $confirmation . PHP_EOL . "1. Yes" . PHP_EOL . "2. No"; //exit; } //print_r($menuItem); //exit; } } else { //when the user has not started the steps $userModel = new Model_User(); $result = $userModel->updateUserMenuStep($user['id'], 1); $menuItemsModel = new Model_MenuItems(); $menuItem = $menuItemsModel->getNextMenuStep($menu_item_id, 1); return $menuItem->description; //exit; } } else { //verify response $menuItemsModel = new Model_MenuItems(); $MenuItems = $menuItemsModel->getMenuItems($menu_item_id); //now we have the menu items it is time to create the USSD Menu // print_r($message); // exit; if (empty($MenuItems)) { $selected_option = $message; } else { // echo "hapa"; // exit; $message = strtolower($message); // print_r($message); // exit; foreach ($MenuItems as $key => $value) { //check if they are equal // print_r($value); // exit; if (trim(strtolower($key)) == $message) { //foreach ($value as $key1 => $value1) { $selected_option = $key; $next_menu_id = $value[2]; //check for the type of menu_item_id if ($value[5] == 3) { //survey $output = $this->takeSurvey($user, $message); return $output; } } if (empty($selected_option)) { foreach ($value as $key1 => $value1) { //print_r($value1); //exit; if (trim(strtolower($value1)) == $message) { $selected_option = $value1; } } } } } // print_r($selected_option); // exit; // if (empty($selected_option)) { $selected_option = 0; } if (empty($next_menu_id)) { $next_menu_id = 0; } //update the progress with the next menu id $userModel = new Model_User(); $no = $user['phoneno']; $result = $userModel->updateUser($next_menu_id, $no); if ($result) { $menuModel = new Model_Menu(); $reply = ""; //print_r($user); //exit; if ($next_menu_id == 0) { //if ($menu['id'] == 0) { $reply = "We could not understand your response"; $next_menu_id = $user['menu_item_id']; //$output = $this->mainMenu($user, $user['phoneno']); //return $reply.PHP_EOL.$output; //} } //print_r($next_menu_id); //exit; $menu = $menuModel->getMenu($next_menu_id); //print_r($menu); //exit; $menu_id = $menu['id']; $menuType = $menu['type']; // print_r($step); // exit; if ($menuType == 2) { //$menu // print_r($menu); // exit; $output = $this->singleProcess($menu_id, $user); //$output = $this->singleProcess($menu_item_id); return $output; } else { //get the description $description = $menu->description; //build up the options $menuItemsModel = new Model_MenuItems(); $menuOptions = $menuItemsModel->getMenuOptions($menu_id); return $description . PHP_EOL . $menuOptions; //exit; } } } }
public function updateEnterpriseTransaction($ficha, $enterpriseRow, $addressEnterpriseRow, $presidentRow, $addressPresidentRow, $userRow) { $User = new Model_User(); $President = new Model_President(); $PresidentProgram = new Model_PresidentProgram(); //$Eligibility = new Model_Eligibility(); $AddressEnterprise = new Model_AddressEnterprise(); $AddressPresident = new Model_AddressPresident(); $modelEntCatAwardCompetition = new Model_EnterpriseCategoryAwardCompetition(); $modelLogCadastroEmpresa = new Model_LogCadastroEmpresa(); // dados Empresa $registerEnterpriseData = $ficha['enterprise']; // dados endereço da empresa $registerAddressEnterpriseData = $ficha['addressEnterprise']; $registerAddressPresidentData = $ficha['addressPresident']; $registerAddressEnterpriseData['enterprise_id'] = $enterpriseRow->getId(); $registerAddressPresidentData['president_id'] = $presidentRow->getId(); // dados do presidente da empresa $registerPresidentData = $ficha['president']; $registerPresidentData['enterprise_id'] = $enterpriseRow->getId(); $registerPresidentData['hasnt_email'] = isset($ficha['enterprise']['hasnt_email']) ? $ficha['enterprise']['hasnt_email'] : 0; // dados do programa do presidente da empresa $registerPresidentProgramData = isset($ficha['presidentProgram']) ? $ficha['presidentProgram'] : null; // dados do usuário $registerUserData = isset($ficha['user']) ? $ficha['user'] : array(); $registerUserData['first_name'] = $registerPresidentData['name']; $registerUserData['surname'] = $registerPresidentData['nick_name']; $registerUserData['email'] = $registerPresidentData['email']; $registerUserData['login'] = $registerPresidentData['cpf']; $registerLogCadastro = $ficha['log_empresa']; $presidentId = $presidentRow->getId(); // start transaction externo Zend_Registry::get('db')->beginTransaction(); try { $hasntEmail = $registerPresidentData['hasnt_email']; $enterpriseEmail = isset($ficha['enterprise']['email_default']) ? $ficha['enterprise']['email_default'] : ''; $this->validateEmail($enterpriseRow->getId(), $enterpriseEmail, $hasntEmail); $this->validateLandline($ficha['enterprise']['phone']); $programaId = Zend_Registry::get('configDb')->competitionId; // Validação Categoria do Premio $updateCategoryAward = $this->validCategoryAward($registerEnterpriseData); if (!$updateCategoryAward['status']) { throw new Vtx_UserException($updateCategoryAward['messageError'], 10); } // 1.1 Empresa $updateEnterprise = $this->updateEnterprise($enterpriseRow, $registerEnterpriseData); if (!$updateEnterprise['status']) { throw new Vtx_UserException($updateEnterprise['messageError'], 10); } // elegibilidade para questionario de diagnostico //$Eligibility->doDiagnosticoEligibility($updateEnterprise['row']); // 1.2 Endereço da Empresa $updateAddressEnterprise = $AddressEnterprise->updateAddressEnterprise($addressEnterpriseRow, $registerAddressEnterpriseData); if (!$updateAddressEnterprise['status']) { throw new Vtx_UserException($updateAddressEnterprise['messageError'], 10); } // validação dos campos NewsLetter da Candidata (President) $newsLetterValid = $President->isValidNewsletter($ficha['newsletter'], $registerPresidentData); if (!$newsLetterValid['status']) { throw new Vtx_UserException($newsLetterValid['messageError']); } // 2.1 Presidente da Empresa $registerPresidentData['agree'] = $presidentRow->getAgree(); $updatePresident = $President->updatePresident($presidentRow, $registerPresidentData); if (!$updatePresident['status']) { throw new Vtx_UserException($updatePresident['messageError']); } // 2.2 Endereço da Presidente (candidata) $updateAddressPresident = $AddressPresident->updateAddressPresident($addressPresidentRow, $registerAddressPresidentData); if (!$updateAddressPresident['status']) { throw new Vtx_UserException($updateAddressPresident['messageError']); } // 2.3 Programa do Presidente da Empresa if ($registerPresidentProgramData) { $PresidentProgram->deleteAllPresidentProgramByPresidentId($presidentId); $createPresidentProgram = $PresidentProgram->createPresidentProgramByPresidentId($registerPresidentProgramData, $presidentId); if (!$createPresidentProgram['status']) { throw new Vtx_UserException($createPresidentProgram['messageError']); } } $enterpriseId = $enterpriseRow->getId(); $hasCurrentECAC = $modelEntCatAwardCompetition->hasECAC($enterpriseId, $programaId); if (!$hasCurrentECAC) { $registerECAC = array(); $registerECAC['enterprise_id'] = $enterpriseId; $registerECAC['competition_id'] = $programaId; $registerECAC['category_award_id'] = $registerEnterpriseData['category_award_id']; $insertECAC = $modelEntCatAwardCompetition->createECAC($registerECAC); if (!$insertECAC['status']) { throw new Vtx_UserException($insertECAC['messageError']); } // Log Cadastro da Empresa - ACEITE $logCadastroEmpresa['user_id_log'] = $registerLogCadastro['user_id_log']; $logCadastroEmpresa['enterprise_id'] = $enterpriseId; $logCadastroEmpresa['programa_id'] = $programaId; $logCadastroEmpresa['acao'] = 'aceite'; $insertlogCadastroEmpresa = $modelLogCadastroEmpresa->createLogCadastroEmpresa($logCadastroEmpresa); if (!$insertlogCadastroEmpresa['status']) { throw new Vtx_UserException($insertlogCadastroEmpresa['messageError']); } } // 3.1 Usuário (nome + sobrenome) $updateUser = $User->updateUser($userRow, $registerUserData); if (!$updateUser['status']) { throw new Vtx_UserException($updateUser['messageError']); } // Envia email com login/senha pro responsavel pelo cadastro $pass = isset($registerUserData['keypass']) ? $registerUserData['keypass'] : null; $enterpriseEmail = $registerEnterpriseData['email_default']; $presidentEmail = $registerPresidentData['email']; if ($enterpriseEmail != '') { $this->sendMailEdit($enterpriseEmail, $registerUserData['first_name'], $registerUserData['login'], $pass, $enterpriseId); if ($enterpriseEmail != $presidentEmail) { $this->sendMailEdit($presidentEmail, $registerPresidentData['name'], $registerPresidentData['cpf'], $pass, $enterpriseId); } } // Log Cadastro da Empresa - EDICAO CADASTRO $logCadastroEmpresa['user_id_log'] = $registerLogCadastro['user_id_log']; $logCadastroEmpresa['enterprise_id'] = $enterpriseId; $logCadastroEmpresa['programa_id'] = $programaId; $logCadastroEmpresa['acao'] = 'edicao_cadastro'; $insertlogCadastroEmpresaCad = $modelLogCadastroEmpresa->createLogCadastroEmpresa($logCadastroEmpresa); if (!$insertlogCadastroEmpresaCad['status']) { throw new Vtx_UserException($insertlogCadastroEmpresaCad['messageError']); } // update // end transaction externo Zend_Registry::get('db')->commit(); return array('status' => true); } catch (Vtx_UserException $e) { Zend_Registry::get('db')->rollBack(); return array('status' => false, 'messageError' => $e->getMessage(), 'errorCode' => $e->getCode()); } catch (Exception $e) { Zend_Registry::get('db')->rollBack(); throw new Exception($e); } }