コード例 #1
0
ファイル: groups.php プロジェクト: andrejjursa/lstme-ledcoin
 public function update_group($group_id = NULL)
 {
     if (is_null($group_id)) {
         add_error_flash_message('Skupina sa nenašla.');
         redirect(site_url('groups'));
     }
     $group = new Group();
     $group->get_by_id((int) $group_id);
     if (!$group->exists()) {
         add_error_flash_message('Skupina sa nenašla.');
         redirect(site_url('groups'));
     }
     build_validator_from_form($this->get_form());
     if ($this->form_validation->run()) {
         $group_data = $this->input->post('group');
         $group->from_array($group_data, array('title'));
         if ($group->save()) {
             add_success_flash_message('Skupina s ID <strong>' . $group->id . '</strong> bola úspešne upravená.');
             redirect(site_url('groups'));
         } else {
             add_error_flash_message('Skupina s ID <strong>' . $group->id . '</strong> nebola upravená.');
             redirect(site_url('groups/edit_group/' . (int) $group_id));
         }
     } else {
         $this->edit_group($group_id);
     }
 }
コード例 #2
0
 public function update_service($service_id = NULL)
 {
     if (is_null($service_id)) {
         add_error_flash_message('Služba sa nenašla.');
         redirect(site_ur('services'));
     }
     $this->db->trans_begin();
     $service = new Service();
     $service->get_by_id((int) $service_id);
     if (!$service->exists()) {
         $this->db->trans_rollback();
         add_error_flash_message('Služba sa nenašla.');
         redirect(site_ur('services'));
     }
     build_validator_from_form($this->get_form());
     if ($this->form_validation->run()) {
         $service_data = $this->input->post('service');
         $service->from_array($service_data, array('title', 'price'));
         if ($service->save() && $this->db->trans_status()) {
             $this->db->trans_commit();
             add_success_flash_message('Služba s ID <strong>' . $service->id . '</strong> bola úspešne upravená.');
             redirect(site_url('services'));
         } else {
             $this->db->trans_rollback();
             add_error_flash_message('Službu s ID <strong>' . $service->id . '</strong> sa nepodarilo upraviť.');
             redirect(site_url('services/edit_service/' . (int) $service->id));
         }
     } else {
         $this->db->trans_rollback();
         $this->edit_service($service->id);
     }
 }
コード例 #3
0
 public function update_workplace($workplace_id = NULL)
 {
     if (is_null($workplace_id)) {
         add_error_flash_message('Zamestnanie sa nenašlo.');
         redirect(site_url('workplaces'));
     }
     $this->db->trans_begin();
     $workplace = new Workplace();
     $workplace->get_by_id((int) $workplace_id);
     if (!$workplace->exists()) {
         $this->db->trans_rollback();
         add_error_flash_message('Zamestnanie sa nenašlo.');
         redirect(site_url('workplaces'));
     }
     build_validator_from_form($this->get_form());
     if ($this->form_validation->run()) {
         $workplace_data = $this->input->post('workplace');
         $workplace->from_array($workplace_data, array('title'));
         if ($workplace->save() && $this->db->trans_status()) {
             $this->db->trans_commit();
             add_success_flash_message('Zamestnanie s ID <strong>' . $workplace->id . '</strong> bolo úspešne upravené.');
             redirect(site_url('workplaces'));
         } else {
             $this->db->trans_rollback();
             add_error_flash_message('Zamestnanie s ID <strong>' . $workplace->id . '</strong> sa nepodarilo upraviť.');
             redirect(site_url('workplaces/edit_workspace/' . (int) $workplace->id));
         }
     } else {
         $this->db->trans_rollback();
         $this->edit_workplace($workplace_id);
     }
 }
コード例 #4
0
ファイル: ledcoin.php プロジェクト: andrejjursa/lstme-ledcoin
 public function save_questionnaire($id)
 {
     auth_redirect_if_not_authentificated('errormessage/no_auth');
     $this->db->trans_begin();
     $person = new Person();
     $person->get_by_id(auth_get_id());
     $questionnaire = $this->get_questionnaire_for_current_person($id);
     if (!$questionnaire->exists()) {
         add_error_flash_message('Dotazník sa nenašieľ alebo nie je zverejnený.');
         redirect('ledcoin/questionnaires');
     }
     if (!is_null($questionnaire->attempts) && $questionnaire->max_answer_number >= $questionnaire->attempts) {
         add_error_flash_message(sprintf('Dotazník <strong>%s</strong> už nemôžeš vyplniť. Dosiahol si maximálneho počtu pokusov.', htmlspecialchars($questionnaire->title)));
         redirect('ledcoin/questionnaires');
     }
     $form = $questionnaire->get_form_config();
     build_validator_from_form($form);
     if ($this->form_validation->run()) {
         $questionnaire_data = $this->input->post('question');
         $questionnaire_answer = new Questionnaire_answer();
         $questionnaire_answer->answers = serialize($questionnaire_data);
         $questionnaire_answer->answer_number = $questionnaire->max_answer_number + 1;
         if ($questionnaire_answer->save(array($person, $questionnaire))) {
             $this->db->trans_commit();
             add_success_flash_message('Odpovede z dotazníka boli uložené.');
         } else {
             $this->db->trans_rollback();
             add_error_flash_message('Odpovede z dotazníka sa nepodarilo uložiť.');
         }
         redirect('ledcoin/questionnaires');
     } else {
         $this->db->trans_rollback();
         $this->answer_questionnaire($id);
     }
 }
コード例 #5
0
 public function show_questionnaire($id)
 {
     $questionnaire = new Questionnaire();
     $questionnaire->get_by_id((int) $id);
     if (!$questionnaire->exists()) {
         add_error_flash_message('Dotazník sa nenašiel.');
         redirect('questionnaires');
     }
     $form = $questionnaire->get_form_config();
     if (!empty($this->input->post())) {
         build_validator_from_form($form);
         $this->form_validation->run();
     }
     $this->parser->parse('web/controllers/questionnaires/show_questionnaire.tpl', array('form' => $form, 'title' => 'Administrácia / Dotazníky / Náhľad dotazníka', 'back_url' => site_url('questionnaires'), 'questionnaire' => $questionnaire));
 }
コード例 #6
0
ファイル: persons.php プロジェクト: andrejjursa/lstme-ledcoin
 public function update_person($person_id = NULL)
 {
     if (is_null($person_id)) {
         add_error_flash_message('Osoba sa nenašla.');
         redirect(site_url('persons'));
     }
     $this->db->trans_begin();
     $person = new Person();
     $person->get_by_id((int) $person_id);
     if (!$person->exists()) {
         $this->db->trans_rollback();
         add_error_flash_message('Osoba sa nenašla.');
         redirect(site_url('persons'));
     }
     $form = $this->get_edit_form($person);
     build_validator_from_form($form);
     if ($this->form_validation->run()) {
         $person_data = $this->input->post('person');
         if (auth_get_id() == $person->id && $person_data['admin'] != 1) {
             $this->db->trans_rollback();
             add_error_flash_message('Nie je možné odobrať oprávnenie administrátora vlastnému účtu.');
             redirect(site_url('persons/edit_person/' . $person->id));
         }
         if (auth_get_id() == $person->id && $person_data['enabled'] != 1) {
             $this->db->trans_rollback();
             add_error_flash_message('Nie je možné odobrať oprávnenie na prihlasovanie sa vlastnému účtu.');
             redirect(site_url('persons/edit_person/' . $person->id));
         }
         if ($person_data['password'] != '') {
             $person->password = sha1($person_data['password']);
         }
         $person->from_array($person_data, array('name', 'surname', 'login', 'organisation', 'admin', 'enabled', 'number', 'email'));
         //edit
         $group = new Group();
         if ($person_data['group_id'] != '') {
             $group->get_by_id((int) $person_data['group_id']);
         }
         if ($person->save($group) && $this->db->trans_status()) {
             $this->db->trans_commit();
             add_success_flash_message('Osoba s ID <strong>' . $person->id . '</strong> bola úspešne aktualizovaná.');
             redirect(site_url('persons'));
         } else {
             $this->db->trans_rollback();
             add_error_flash_message('Osobu s ID <strong>' . $person->id . '</strong> sa nepodarilo aktualizovať.');
             redirect(site_url('persons/edit_person/' . (int) $person->id));
         }
     } else {
         $this->db->trans_rollback();
         $this->edit_person($person_id);
     }
 }
コード例 #7
0
 public function do_batch_ledcoin_addition()
 {
     $this->load->helper('operations');
     $this->db->trans_begin();
     build_validator_from_form($this->get_batch_ledcoin_addition_form());
     if ($this->form_validation->run()) {
         $batch_amount_data = $this->input->post('batch_amount');
         $person_amount_data = $this->input->post('person_amount');
         $workplace = new Workplace();
         if ((int) $batch_amount_data['workplace_id'] > 0) {
             $workplace->get_by_id((int) $batch_amount_data['workplace_id']);
             if (!$workplace->exists()) {
                 $this->db->trans_rollback();
                 add_error_flash_message('Zamestnanie sa nenašlo.');
                 redirect(site_url('operations/batch_ledcoin_addition'));
             }
         }
         $persons = new Person();
         $persons->where('admin', 0);
         $persons->get_iterated();
         $total_added = 0;
         foreach ($persons as $person) {
             if (array_key_exists($person->id, $person_amount_data) && (double) $person_amount_data[$person->id] > 0) {
                 $total_added += (double) $person_amount_data[$person->id];
             }
         }
         $remaining = 0;
         if ($total_added > 0 && $batch_amount_data['addition_type'] == Operation::ADDITION_TYPE_TRANSFER && !operations_ledcoin_addition_possible($total_added, $remaining)) {
             $this->db->trans_rollback();
             add_error_flash_message('Nedá sa prideliť <strong>' . $total_added . '</strong> ' . get_inflection_ledcoin($total_added) . ', na účte vedúcich zostáva iba <strong>' . $remaining . '</strong> ' . get_inflection_ledcoin($remaining) . '.');
             redirect('operations');
             return;
         }
         $persons = new Person();
         $persons->where('admin', 0);
         $persons->get_iterated();
         $successful_count = 0;
         $error_count = 0;
         $successful_messages = array();
         $error_messages = array();
         $total_added = 0;
         foreach ($persons as $person) {
             if (array_key_exists($person->id, $person_amount_data) && (double) $person_amount_data[$person->id] > 0) {
                 $operation = new Operation();
                 $operation->admin_id = auth_get_id();
                 $operation->amount = (double) $person_amount_data[$person->id];
                 $operation->type = Operation::TYPE_ADDITION;
                 $operation->subtraction_type = Operation::SUBTRACTION_TYPE_DIRECT;
                 $operation->addition_type = $batch_amount_data['addition_type'];
                 $operation->comment = @$batch_amount_data['comment'];
                 if ($operation->save(array('person' => $person, 'workplace' => $workplace))) {
                     $total_added += (double) $operation->amount;
                     $successful_messages[] = 'Účastník <strong>' . $person->name . ' ' . $person->surname . '</strong> dostal <strong>' . (double) $operation->amount . '</strong> ' . get_inflection_ledcoin((double) $operation->amount) . '.';
                     $successful_count++;
                 } else {
                     $error_count++;
                     $error_messages[] = 'Účastníkovi <strong>' . $person->name . ' ' . $person->surname . '</strong> sa nepodarilo prideliť LEDCOIN.';
                 }
             }
         }
         if ($total_added > 0 && $batch_amount_data['addition_type'] == Operation::ADDITION_TYPE_TRANSFER && !operations_ledcoin_limit_check($total_added)) {
             add_common_flash_message('Pozor, celkovým pridaním ' . $total_added . ' LEDCOIN-ov bol prekročený denný limit. Pred pridaním už bolo pridaných ' . operations_ledcoin_added_in_day() . ' z ' . operations_ledcoin_daily_limit() . ' LEDCOIN-ov!');
         }
         if ($successful_count == 0 && $error_count == 0) {
             $this->db->trans_rollback();
             add_error_flash_message('Nikomu nebol pridelený LEDCOIN, nakoľko bol odoslaný prázdny formulár.');
             redirect(site_url('operations'));
         } elseif ($successful_count == 0 && $error_count > 0) {
             $this->db->trans_rollback();
             add_error_flash_message('Nepodarilo sa nikomu pridať LEDCOIN:<br /><br />' . implode('<br />', $error_messages));
         } else {
             $this->db->trans_commit();
             if ($successful_count > 0) {
                 add_success_flash_message('LEDCOIN bol pridelený <strong>' . $successful_count . '</strong> ' . get_inflection_by_numbers($successful_count, 'účastníkom', 'účastníkovi', 'účastníkom', 'účastníkom', 'účastníkom', 'účastníkom') . ':<br /><br />' . implode('<br />', $successful_messages));
             }
             if ($error_count > 0) {
                 add_error_flash_message('LEDCOIN sa nepodarilo udeliť <strong>' . $error_count . '</strong> ' . get_inflection_by_numbers($error_count, 'účastníkom', 'účastníkovi', 'účastníkom', 'účastníkom', 'účastníkom', 'účastníkom') . ':<br /><br />' . implode('<br />', $error_messages));
             }
             redirect(site_url('operations'));
         }
     } else {
         $this->db->trans_rollback();
         $this->batch_ledcoin_addition();
     }
 }
コード例 #8
0
ファイル: limits.php プロジェクト: andrejjursa/lstme-ledcoin
 public function update_limit($limit_id = null)
 {
     if (is_null($limit_id)) {
         add_error_flash_message('Denný limit sa nenašiel.');
         redirect(site_url('limits'));
     }
     $this->db->trans_begin();
     $limit = new Limit();
     $limit->get_by_id((int) $limit_id);
     if (!$limit->exists()) {
         $this->db->trans_rollback();
         add_error_flash_message('Denný limit sa nenašiel.');
         redirect(site_url('limits'));
     }
     if (date('Y-m-d') > $limit->date) {
         $this->db->trans_rollback();
         add_error_flash_message('Nie je povolené upravovať staršie limity ako dnešné.');
         redirect(site_url('limits'));
     }
     build_validator_from_form($this->get_form(TRUE));
     if ($this->form_validation->run()) {
         $limit_data = $this->input->post('limit');
         $limit->daily_limit = $limit_data['daily_limit'];
         if ($limit->save()) {
             $this->db->trans_commit();
             add_success_flash_message('Limit na dátum <strong>' . date('d. m. Y', strtotime($limit->date)) . '</strong> bol nastavený na <strong>' . $limit->daily_limit . '</strong> LEDCOIN-ov.');
         } else {
             $this->db->trans_rollback();
             add_error_flash_message('Limit na dátum <strong>' . date('d. m. Y', strtotime($limit->date)) . '</strong> sa nepodarilo uložiť pri úprave.');
         }
         redirect(site_url('limits'));
     } else {
         $this->db->trans_rollback();
         $this->edit_limit($limit_id);
     }
 }
コード例 #9
0
 public function do_batch_stock_addition()
 {
     $this->db->trans_begin();
     build_validator_from_form($this->get_batch_stock_addition_form());
     if ($this->form_validation->run()) {
         $products = new Product();
         $products->get_iterated();
         $product_quantity_data = $this->input->post('product_quantity_addition');
         $success_messages = array();
         $error_messages = array();
         $added = 0;
         $failed = 0;
         foreach ($products as $product) {
             if (isset($product_quantity_data[$product->id]['quantity']) && (int) $product_quantity_data[$product->id]['quantity'] > 0) {
                 $product_quantity = new Product_quantity();
                 $product_quantity->type = Product_quantity::TYPE_ADDITION;
                 $product_quantity->quantity = (int) $product_quantity_data[$product->id]['quantity'];
                 $product_quantity->price = NULL;
                 $product_quantity->operation_id = NULL;
                 if ($product_quantity->save($product) && $this->db->trans_status()) {
                     $added++;
                     $success_messages[] = 'Produktu <strong>' . $product->title . '</strong> ' . get_inflection_by_numbers((int) $product_quantity->quantity, 'bolo pridaných', 'bol pridaný', 'boli pridané', 'boli pridané', 'boli pridané', 'bolo pridaných') . ' <strong>' . $product_quantity->quantity . '</strong> ' . get_inflection_by_numbers((int) $product_quantity->quantity, 'kusov', 'kus', 'kusy', 'kusy', 'kusy', 'kusov') . ' zásob na sklad.';
                 } else {
                     $failed++;
                     $error_messages[] = 'Produktu <strong>' . $product->title . '</strong> sa nepodarilo pridať <strong>' . $product_quantity->quantity . '</strong> ' . get_inflection_by_numbers((int) $product_quantity->quantity, 'kusov', 'kus', 'kusy', 'kusy', 'kusy', 'kusov') . ' zásob na sklad.';
                 }
             }
         }
         if ($added == 0 && $failed == 0) {
             $this->db->trans_rollback();
             add_common_flash_message('Nebolo nič pridané, keďže bol odoslaný prázdny formulár.');
             redirect(site_url('products'));
         } elseif ($added == 0 && $failed > 0) {
             $this->db->trans_rollback();
             add_error_flash_message('Nepodarilo sa pridať žiadne zásoby na sklad:<br /><br />' . implode('<br />', $error_messages));
             redirect(site_url('products/batch_stock_addition'));
         } else {
             $this->db->trans_commit();
             if ($added > 0) {
                 add_success_flash_message('Boli pridané zásoby k celkovo <strong>' . $added . '</strong> ' . get_inflection_by_numbers($added, 'produktom', 'produktu', 'produktom', 'produktom', 'produktom', 'produktom') . ':<br /><br />' . implode('<br />', $success_messages));
             }
             if ($failed > 0) {
                 add_error_flash_message('K <strong>' . $failed . '</strong> ' . get_inflection_by_numbers($failed, 'produktom', 'produktu', 'produktom', 'produktom', 'produktom', 'produktom') . ' sa nepodarilo pridat zásoby:<br /><br />' . implode('<br />', $error_messages));
             }
             redirect(site_url('products'));
         }
     } else {
         $this->db->trans_rollback();
         $this->batch_stock_addition();
     }
 }