Пример #1
0
 public function courseAction($iId = 0)
 {
     if ($iId !== 0 and !isset($_POST['submit'])) {
         // edycja skladnika
         $bDelete = func_get_arg(0) == 'delete';
         if ($bDelete) {
             $iId = func_get_arg(1);
         }
         $iId = (int) $iId;
         $oModel = new Model_Course($iId);
         $aRows = $oModel->getRow();
         $this->mTemplate->sSectionTitle = $this->getLang('section_title_courseedit');
         if ($iId and !empty($aRows) and $aRows['account_id'] == $this->oCurrentUser->account_id) {
             if ($bDelete) {
                 if (func_num_args() == 4 and $this->oAuth->isValidToken(func_get_arg(2))) {
                     if ($oModel->delete()) {
                         $aMeta = $this->mTemplate->aMeta;
                         $aMeta[] = '<meta http-equiv="refresh" content="1;url=' . $this->mTemplate->anchor('/account/courses/') . '" />';
                         $this->mTemplate->aMeta = $aMeta;
                         $aData['info'] = $this->getLang('delete_course_successful');
                     } else {
                         $aData['info'] = $this->getLang('delete_course_failed');
                     }
                 } else {
                     // potwierdzenie usuniecia
                     $aData = array('sQuestion' => $this->getLang('delete_course_question', $aRows['name']), 'sTextYes' => $this->getLang('Catering.ok'), 'sLinkYes' => '/account/course/delete/' . $iId . '/' . $this->oAuth->getSecurityToken() . '/', 'sTextNo' => $this->getLang('Catering.cancel'), 'sLinkNo' => '/account/courses/');
                 }
                 $this->mTemplate->sSectionTitle = $this->getLang('section_title_coursedelete');
             } else {
                 // edycja
                 $oType = new Model_Type();
                 $aTypes = $oType->where('account_id', (int) $this->oCurrentUser->account_id)->getAll();
                 // gdy nie zdefiniowano jeszcze typow przekierowujemy
                 if (!count($aTypes)) {
                     $this->redirect('/account/types/');
                     echo ' ';
                 }
                 // budujemy opcje select'a
                 foreach ($aTypes as $aType) {
                     $aOptions[] = array('value' => $aType['type_id'], 'name' => $aType['name']);
                 }
                 $aInputs[] = array('type' => 'text', 'label' => $this->getLang('course_name'), 'name' => 'name', 'value' => $aRows['name']);
                 $aInputs[] = array('type' => 'text', 'label' => $this->getLang('course_price'), 'name' => 'price', 'value' => $aRows['price']);
                 $aInputs[] = array('type' => 'select', 'label' => $this->getLang('course_optional'), 'name' => 'optional', 'value' => $aRows['optional'], 'items' => array(array('value' => 0, 'name' => $this->getLang('Catering.no')), array('value' => 1, 'name' => $this->getLang('Catering.yes'))));
                 $aInputs[] = array('type' => 'text', 'label' => $this->getLang('course_discount'), 'name' => 'discount', 'value' => $aRows['discount']);
                 $aInputs[] = array('type' => 'select', 'label' => $this->getLang('course_type'), 'name' => 'type', 'value' => $aRows['type_id'], 'items' => $aOptions);
                 $aData = array('sTextDelete' => $this->getLang('Catering.delete'), 'sLinkDelete' => '/account/course/delete/' . $aRows['course_id'] . '/', 'item_id' => $aRows['course_id'], 'aInputs' => $aInputs);
                 $aData['bPrintForm'] = true;
             }
         } else {
             $aData['info'] = $this->getLang('course_not_found');
         }
         $this->mTemplate->sSectionTitle = $this->getLang('section_title_courseedit');
     } elseif (isset($_POST['submit'])) {
         // zapis posilku
         $iId = (int) $iId;
         $this->saveCourse($iId);
         return;
     } else {
         // akcja domyślna czyli dodawanie
         $oType = new Model_Type();
         $aTypes = $oType->where('account_id', (int) $this->oCurrentUser->account_id)->getAll();
         // gdy nie zdefiniowano jeszcze typow przekierowujemy
         if (!count($aTypes)) {
             $this->redirect('/account/types/');
             echo ' ';
         }
         // budujemy opcje select'a
         foreach ($aTypes as $aType) {
             $aOptions[] = array('value' => $aType['type_id'], 'name' => $aType['name']);
         }
         $aInputs[] = array('type' => 'text', 'label' => $this->getLang('course_name'), 'name' => 'name', 'value' => '');
         $aInputs[] = array('type' => 'text', 'label' => $this->getLang('course_price'), 'name' => 'price', 'value' => '');
         $aInputs[] = array('type' => 'select', 'label' => $this->getLang('course_optional'), 'name' => 'optional', 'value' => 0, 'items' => array(array('value' => 0, 'name' => $this->getLang('Catering.no')), array('value' => 1, 'name' => $this->getLang('Catering.yes'))));
         $aInputs[] = array('type' => 'text', 'label' => $this->getLang('course_discount'), 'name' => 'discount', 'value' => '');
         $aInputs[] = array('type' => 'select', 'label' => $this->getLang('course_type'), 'name' => 'type', 'value' => $aTypes[0]['type_id'], 'items' => $aOptions);
         $aData = array('aInputs' => $aInputs, 'bPrintForm' => true);
         $this->mTemplate->sSectionTitle = $this->getLang('section_title_courseadd');
     }
     $aData['submit'] = $this->getLang('Catering.save');
     $this->mTemplate->content = View::factory('account/item_edit', $aData)->render();
 }