public function settingsAction() { // sprawdzamy czy zalogowany if (!$this->oAuth->isLoggedIn()) { $this->redirect('/'); echo ' '; return; } $this->mTemplate->sSectionTitle = 'Ustawienia'; $oLayout = new Model_Layout(); $aLayouts = $oLayout->getAll(); if (isset($_POST['submit'])) { $sResult = $this->saveSettings($aLayouts); if ($sResult === true) { $aData['sInfo'] = 'Ustawienia zapisane pomyslenie.'; } else { $aData['sInfo'] = $sResult; } } $aOption = array(); foreach ($aLayouts as $aLayout) { $aOption[] = array('value' => $aLayout['layout_id'], 'text' => $aLayout['name']); } $aData['aChangePassForm'] = array('sTitle' => 'Zmiana hasla', 'sOldPass' => 'Stare haslo', 'sNewPass' => 'Nowe haslo', 'sNewPassConfirm' => 'Powtorz nowe haslo', 'sSubmit' => 'Zmien'); $aData['aLayoutForm'] = array('sTitle' => 'Wybor layout\'u', 'sNull' => '', 'value' => (int) $this->oCurrentUser->layout_id, 'sSubmit' => 'Zapisz', 'aOptions' => $aOption); $this->mTemplate->content = View::factory('user/settings', $aData)->render(); }
public function init() { $this->oAuth = new Module_Auth(); if ($iSessionTimeout = $this->oLithium->getConfig('General.Session_timeout')) { $this->oAuth->setTimeout($iSessionTimeout); } // load xajax lib Loader::loadClass('Library_Xajax', 'LXajax'); $this->oXajax = new LXajax(); // if xajax call end executing rest of code if ($this->isAjaxCall()) { parent::init(); return; } // sprawdzanie czy uzytkownik niezalogowany if (!$this->oAuth->isLoggedIn()) { // przed wywolaniem konstruktora rodzica ustawiamy sciezke do layoutu View::setDefaultTemplateDir('ciao_new/'); parent::init(); // wiadomosc powitalna $this->mTemplate->aWelcomeMessage = array('sDinnersFullName' => '', 'sText' => $this->getLang('catering.welcome_text_not_loggedin')); $aMenu['Menu uzytkownika']['login'] = array('sTarget' => '/user/login/', 'sText' => $this->getLang('user.login')); // $aMenu[ 'Menu uzytkownika' ][] = array(); // $aMenu['Menu uzytkownika']['register'] = array('sTarget' => '/user/register/', 'sText' => $this->getLang('user.register')); } else { // logged in $this->oCurrentUser = $this->oAuth->getLoggedInUser(); if (!empty($this->aRolesAllowed) && !in_array($this->oCurrentUser->get('role_id')->name, $this->aRolesAllowed)) { $this->redirect('/'); echo ' '; } if (is_null($sLayout = $this->oCurrentUser->propertie('template'))) { $iLayoutId = (int) $this->oCurrentUser->layout_id; if ($iLayoutId != 0) { $oLayout = new Model_Layout($iLayoutId); $aLayout = $oLayout->getRow(); $this->oCurrentUser->propertie('template', $aLayout['path']); } else { $this->oCurrentUser->propertie('template', ''); } } View::setDefaultTemplateDir($this->oCurrentUser->propertie('template')); parent::init(); //dodajemy info o posilku na dzis $this->showOrdersForToday(); $this->mTemplate->header_username = $this->getLang('catering.header_username', $this->oCurrentUser->name); $aMenu['Menu uzytkownika'][] = array('sTarget' => '/', 'sText' => 'Strona glowna'); $aMenu['Menu uzytkownika'][] = array(); $aMenu['Menu uzytkownika'][] = array('sTarget' => '/catering/enrol/', 'sText' => $this->getLang('catering.enrol')); $aMenu['Menu uzytkownika'][] = array(); $aMenu['Menu uzytkownika'][] = array('sTarget' => '/user/settings/', 'sText' => 'Ustawienia'); $aMenu['Menu uzytkownika'][] = array(); $aMenu['Menu uzytkownika']['login'] = array('sTarget' => '/user/logout/', 'sText' => $this->getLang('user.logout')); $this->sRole = $this->oCurrentUser->get('role_id')->name; switch ($this->sRole) { case 'admin': $sTitle = $this->getLang('account.administration'); $aMenu[$sTitle][] = array('sTarget' => '/account/', 'sText' => $this->getLang('account.settings')); $aMenu[$sTitle][] = array(); $aMenu[$sTitle][] = array('sTarget' => '/account/user/', 'sText' => $this->getLang('account.add_user')); $aMenu[$sTitle][] = array(); $aMenu[$sTitle][] = array('sTarget' => '/account/users/', 'sText' => $this->getLang('account.user_list')); case 'moderator': $sTitle = $this->getLang('account.dinners_menu'); $aMenu[$sTitle][] = array('sTarget' => '/account/types/', 'sText' => 'Typy skladnikow'); $aMenu[$sTitle][] = array(); $aMenu[$sTitle][] = array('sTarget' => '/account/course/', 'sText' => 'Dodaj skladnik'); $aMenu[$sTitle][] = array(); $aMenu[$sTitle][] = array('sTarget' => '/account/courses/', 'sText' => 'Lista skladnikow'); $aMenu[$sTitle][] = array(); $aMenu[$sTitle][] = array('sTarget' => '/account/meals/', 'sText' => 'Dania'); $aMenu[$sTitle][] = array(); $aMenu[$sTitle][] = array('sTarget' => '/account/orders/', 'sText' => 'Edycja zamowien'); $sTitle = $this->getLang('account.summary_menu'); $aMenu[$sTitle][] = array('sTarget' => '/account/summary/users/', 'sText' => 'Kosztow na dzien'); $aMenu[$sTitle][] = array(); $aMenu[$sTitle][] = array('sTarget' => '/account/summary/', 'sText' => 'Zamowienia'); break; } } // set images for sorter Module_Sorter::setImageUrl('arrow-sort-up.gif', Module_Sorter::SORT_ASC); Module_Sorter::setImageUrl('arrow-sort-down.gif', Module_Sorter::SORT_DESC); $this->mTemplate->aMeta = array(); $this->mTemplate->title = 'Catering'; $this->mTemplate->menu = $aMenu; }
public function userAction($iId = null) { $this->mTemplate->sSectionTitle = $this->getLang('section_title_useredit'); // sprawdzamy czy user jest adminem if ($this->sRole !== 'admin') { $aData['info'] = $this->getLang('access_denied'); $this->mTemplate->content = View::factory('account/item_edit', $aData)->render(); return; } if (isset($iId) and $iId !== 0 and !isset($_POST['submit'])) { // edycja usera $bDelete = func_get_arg(0) == 'delete'; if ($bDelete) { $iId = func_get_arg(1); } $iId = (int) $iId; $oUser = new Model_User($iId); $aUser = $oUser->getRow(); if ($iId and !empty($aUser) and $aUser['account_id'] == $this->oCurrentUser->account_id) { if ($bDelete) { // usuwanie uzytkownika if (func_num_args() == 4 and $this->oAuth->isValidToken(func_get_arg(2))) { if ($oUser->delete()) { $aMeta = $this->mTemplate->aMeta; $aMeta[] = '<meta http-equiv="refresh" content="1;url=' . $this->mTemplate->anchor('/account/users/') . '" />'; $this->mTemplate->aMeta = $aMeta; $aData['info'] = $this->getLang('delele_user_successfull'); } else { $aData['info'] = $this->getLang('delele_user_failed'); } } else { // potwierdzenie usuniecia $aData = array('sQuestion' => $this->getLang('delele_user_question', $aUser['name']), 'sTextYes' => $this->getLang('Catering.ok'), 'sLinkYes' => '/account/user/delete/' . $iId . '/' . $this->oAuth->getSecurityToken() . '/', 'sTextNo' => $this->getLang('Catering.cancel'), 'sLinkNo' => '/account/user/' . $iId . '/'); } $this->mTemplate->sSectionTitle = $this->getLang('section_title_userdelete'); } else { // edycja danych $aOptions = array(); $aLayoutList = array(); $oRole = new Model_Role(); $aRoles = $oRole->getAll(); foreach ($aRoles as $aRole) { $aOptions[] = array('value' => $aRole['role_id'], 'name' => $aRole['name']); } // pobieramy dostepne layouty $oLayout = new Model_Layout(); $aLayouts = $oLayout->getAll(); foreach ($aLayouts as $aLayout) { $aLayoutList[] = array('value' => $aLayout['layout_id'], 'name' => $aLayout['name']); } $aInputs[] = array('type' => 'text', 'label' => $this->getLang('first_name'), 'name' => 'fname', 'value' => $aUser['fname']); $aInputs[] = array('type' => 'text', 'label' => $this->getLang('sure_name'), 'name' => 'name', 'value' => $aUser['name']); $aInputs[] = array('type' => 'text', 'label' => $this->getLang('email'), 'name' => 'email', 'value' => $aUser['email']); $aInputs[] = array('type' => 'password', 'label' => $this->getLang('password'), 'name' => 'pass', 'value' => ''); $aInputs[] = array('type' => 'text', 'label' => $this->getLang('registered'), 'name' => 'since', 'value' => $aUser['since'], 'disabled' => true); $aInputs[] = array('type' => 'text', 'label' => $this->getLang('last_login'), 'name' => 'last_login', 'value' => $aUser['last_login'], 'disabled' => true); $aInputs[] = array('type' => 'select', 'label' => $this->getLang('layout'), 'name' => 'layout', 'value' => $aUser['layout_id'], 'items' => $aLayoutList); $aInputs[] = array('type' => 'select', 'label' => $this->getLang('role'), 'name' => 'role', 'value' => $aUser['role_id'], 'items' => $aOptions); $aInputs[] = array('type' => 'hidden', 'name' => 'user_id', 'value' => $aUser['user_id']); $aData = array('bPrintForm' => true, 'aInputs' => $aInputs, 'sTextDelete' => $this->getLang('delete'), 'sLinkDelete' => '/account/user/delete/' . $aUser['user_id'] . '/'); $this->mTemplate->sSectionTitle = $this->getLang('section_title_useredit'); } } else { $aData['info'] = $this->getLang('user_not_found'); } } elseif (isset($_POST['submit'])) { // zapis usera $sFName = $this->post('fname'); $sName = $this->post('name'); $sPass = $this->post('pass'); $sEmail = $this->post('email'); $iRole = $this->post('role'); $iLayout = $this->post('layout'); $user_id = $this->post('user_id'); $oValidator = new Module_Validator(); $oValidator->field('first_name', $sFName)->rules('required'); $oValidator->field('sure_name', $sName)->rules('required'); $oValidator->field('email', $sEmail)->rules('required|email'); $oValidator->field('layout', $iLayout)->rules('required|toint'); $oValidator->field('role', $iRole)->rules('required|toint'); $oValidator->field('user_id', $user_id)->rules('toint'); if ($user_id == 0) { $oValidator->field($this->getLang('password'), $sPass)->rules('required|md5'); } elseif (strlen($sPass)) { $oValidator->field($this->getLang('password'), $sPass)->rules('md5'); } if ($oValidator->validate()) { if ($user_id == 0) { //zapis nowego usera $oUser = new Model_User(); $oUser->fname = $sFName; $oUser->name = $sName; $oUser->email = $sEmail; $oUser->password = $sPass; $oUser->layout_id = $iLayout; $oUser->role_id = $iRole; $oUser->account_id = $this->oCurrentUser->account_id; if ($oUser->save()) { $aMeta = $this->mTemplate->aMeta; $aMeta[] = '<meta http-equiv="refresh" content="1;url=' . $this->mTemplate->anchor('/account/users/') . '" />'; $this->mTemplate->aMeta = $aMeta; $aData['info'] = $this->getLang('save_user_successfull'); } else { $aData['info'] = $this->getLang('save_user_failed'); } } else { // zapis edytowanego usera $oUser = new Model_User($user_id); $aUser = $oUser->getRow(); if (!empty($aUser) and $aUser['account_id'] == $this->oCurrentUser->account_id) { $oUser->fname = $sFName; $oUser->name = $sName; $oUser->email = $sEmail; $oUser->layout_id = $iLayout; $oUser->role_id = $iRole; if (!empty($sPass)) { $oUser->password = $sPass; } if ($oUser->save()) { $aMeta = $this->mTemplate->aMeta; $aMeta[] = '<meta http-equiv="refresh" content="1;url=' . $this->mTemplate->anchor('/account/users/') . '" />'; $this->mTemplate->aMeta = $aMeta; $aData['info'] = $this->getLang('save_user_successfull'); } else { $aData['info'] = $this->getLang('save_user_failed'); } } } } else { $aErrors = $oValidator->getError(); foreach ($aErrors as $sField => $aError) { $sMsg .= '<br />' . $this->getLang($aError['msg'], $this->getLang($sField)); } $aData['info'] = $sMsg; } $this->mTemplate->sSectionTitle = $this->getLang('section_title_user_save'); } else { // akcja domyślna czyli dodawanie usera $aOptions = array(); $aLayoutList = array(); // pobieramy dostepne role $oRole = new Model_Role(); $aRoles = $oRole->getAll(); foreach ($aRoles as $aRole) { $aOptions[] = array('value' => $aRole['role_id'], 'name' => $aRole['name']); } // pobieramy dostepne layouty $oLayout = new Model_Layout(); $aLayouts = $oLayout->getAll(); foreach ($aLayouts as $aLayout) { $aLayoutList[] = array('value' => $aLayout['layout_id'], 'name' => $aLayout['name']); } $aInputs[] = array('type' => 'text', 'label' => $this->getLang('first_name'), 'name' => 'fname', 'value' => ''); $aInputs[] = array('type' => 'text', 'label' => $this->getLang('sure_name'), 'name' => 'name', 'value' => ''); $aInputs[] = array('type' => 'text', 'label' => $this->getLang('email'), 'name' => 'email', 'value' => ''); $aInputs[] = array('type' => 'password', 'label' => $this->getLang('password'), 'name' => 'pass', 'value' => ''); $aInputs[] = array('type' => 'select', 'label' => $this->getLang('layout'), 'name' => 'layout', 'value' => 2, 'items' => $aLayoutList); $aInputs[] = array('type' => 'select', 'label' => $this->getLang('role'), 'name' => 'role', 'value' => 3, 'items' => $aOptions); $aData = array('bPrintForm' => true, 'aInputs' => $aInputs); $this->mTemplate->sSectionTitle = $this->getLang('section_title_user_add'); } $aData['submit'] = $this->getLang('Catering.save'); $this->mTemplate->content = View::factory('/account/item_edit', $aData)->render(); }