Exemplo n.º 1
0
 public function login()
 {
     $redirect_url = $this->input->post('return_url');
     $login = $this->input->post('login');
     if (auth_authentificate($login['login'], $login['password'])) {
         add_success_flash_message('Prihlásenie úspešné. Vitaj ' . auth_get_name() . '!');
     } else {
         add_error_flash_message('Prihlásenie neúspešné. Chybné meno alebo heslo.');
     }
     redirect($redirect_url);
 }
Exemplo n.º 2
0
 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);
     }
 }
Exemplo n.º 3
0
 public function delete_group($group_id = NULL)
 {
     if (is_null($group_id)) {
         add_error_flash_message('Skupina sa nenašla.');
         redirect(site_url('groups'));
     }
     $this->db->trans_begin();
     $group = new Group();
     $persons_count = $group->person;
     $persons_count->select_func('COUNT', array('@id'), 'persons_count');
     $persons_count->where_related_group('id', '${parent}.id');
     $group->select_subquery($persons_count, 'persons_count');
     $group->select('*');
     $group->get_by_id((int) $group_id);
     if (!$group->exists()) {
         $this->db->trans_rollback();
         add_error_flash_message('Skupina sa nenašla.');
         redirect(site_url('groups'));
     }
     if ((int) $group->persons_count > 0) {
         $this->db->trans_rollback();
         add_error_flash_message('Nie je možné vymazať skupinu, ktorá má členov.');
         redirect(site_url('groups'));
     }
     $success_message = 'Skupina <strong>' . $group->title . '</strong> s ID <strong>' . $group->id . '</strong> bola vymazaná úspešne.';
     $error_message = 'Skupinu <strong>' . $group->title . '</strong> s ID <strong>' . $group->id . '</strong> sa nepodarilo vymazať.';
     if ($group->delete() && $this->db->trans_status()) {
         $this->db->trans_commit();
         add_success_flash_message($success_message);
     } else {
         $this->db->trans_rollback();
         add_error_flash_message($error_message);
     }
     redirect(site_url('groups'));
 }
Exemplo n.º 4
0
 public function delete_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->include_related_count('operation', 'operations_count');
     $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'));
     }
     if ((int) $workplace->operations_count > 0) {
         $this->db->trans_rollback();
         add_error_flash_message('Nie je možné vymazať zamestnanie ak bolo použité v operácii s LEDCOIN-om.');
         redirect(site_url('workplaces'));
     }
     $success_message = 'Zamestnanie <strong>' . $workplace->title . '</strong> s ID <strong>' . $workplace->id . '</strong> bolo úspešne vymazané.';
     $error_message = 'Zamestnanie <strong>' . $workplace->title . '</strong> s ID <strong>' . $workplace->id . '</strong> sa nepodarilo vymazať.';
     if ($workplace->delete() && $this->db->trans_status()) {
         $this->db->trans_commit();
         add_success_flash_message($success_message);
     } else {
         $this->db->trans_rollback();
         add_error_flash_message($error_message);
     }
     redirect(site_url('workplaces'));
 }
Exemplo n.º 5
0
 protected function rename_upload_folder($old_id, $new_id)
 {
     $old_folder = Questionnaire::PATH_TO_UPLOAD_FOLDER . $old_id;
     $new_folder = Questionnaire::PATH_TO_UPLOAD_FOLDER . $new_id;
     if (file_exists($old_folder) && is_dir($old_folder)) {
         if (!file_exists($new_folder)) {
             if (@rename($old_folder, $new_folder)) {
                 return true;
             }
         }
     } else {
         return true;
     }
     add_error_flash_message('Nie je možné premenovať adresár so súbormi. Pravdepodobne sa stratia všetky väzby na súbory.');
     return false;
 }
Exemplo n.º 6
0
 public function upload_photo($person_id = NULL)
 {
     if (is_null($person_id)) {
         add_error_flash_message('Osoba sa nenašla.');
         redirect(site_url('persons'));
     }
     $person = new Person();
     $person->get_by_id((int) $person_id);
     if (!$person->exists()) {
         add_error_flash_message('Osoba sa nenašla.');
         redirect(site_url('persons'));
     }
     $upload_config = array('upload_path' => 'user/photos/data/' . (int) $person->id . '/', 'allowed_types' => 'jpg|png', 'max_size' => '1024', 'max_width' => '1024', 'max_height' => '1024', 'file_name' => 'temp_photo.png', 'overwrite' => TRUE);
     $this->load->library('upload', $upload_config);
     @mkdir($upload_config['upload_path'], DIR_WRITE_MODE, TRUE);
     if ($this->upload->do_upload('photo')) {
         $resize_config = array('image_library' => 'gd2', 'source_image' => $upload_config['upload_path'] . $upload_config['file_name'], 'create_thumb' => FALSE, 'maintain_ratio' => TRUE, 'width' => 256, 'height' => 256, 'quality' => '90%', 'new_image' => $upload_config['upload_path'] . 'photo.png');
         $this->load->library('image_lib', $resize_config);
         if ($this->image_lib->resize()) {
             $resize_config['width'] = 64;
             $resize_config['height'] = 64;
             $resize_config['new_image'] = $upload_config['upload_path'] . 'photo_min.png';
             @unlink($upload_config['new_image']);
             $this->image_lib->initialize($resize_config);
             $this->image_lib->resize();
             @unlink($resize_config['source_image']);
             add_success_flash_message('Súbor úspešne nahraný.');
             redirect(site_url('persons/edit_photo/' . (int) $person->id));
         } else {
             @unlink($resize_config['source_image']);
             add_error_flash_message('Súbor sa nepodarilo preškálovať:' . $this->image_lib->display_errors('<br /><br />', ''));
             redirect(site_url('persons/edit_photo/' . (int) $person->id));
         }
     } else {
         add_error_flash_message('Súbor sa nepodarilo nahrať, vznikla nasledujúca chyba:' . $this->upload->display_errors('<br /><br />', ''));
         redirect(site_url('persons/edit_photo/' . (int) $person->id));
     }
 }
Exemplo n.º 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();
     }
 }
Exemplo n.º 8
0
 public function delete_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é vymazávať staršie limity ako dnešné.');
         redirect(site_url('limits'));
     }
     $date = date('d. m. Y', strtotime($limit->date));
     $daily_limit = $limit->daily_limit;
     if ($limit->delete() && $this->db->trans_status()) {
         $this->db->trans_commit();
         add_success_flash_message('Limit s dátumom <strong>' . $date . '</strong> a hodnotou <strong>' . $daily_limit . '</strong> bol úspešne vymazaný.');
     } else {
         $this->db->trans_rollback();
         add_error_flash_message('Nepodarilo sa vymazať limit s dátumom <strong>' . $date . '</strong> a hodnotou <strong>' . $daily_limit . '</strong>!');
     }
     redirect(site_url('limits'));
 }
Exemplo n.º 9
0
 public function overview($service_id = NULL)
 {
     if (is_null($service_id)) {
         add_error_flash_message('Služba sa nenašla.');
         redirect(site_ur('services'));
     }
     $service = new Service();
     $service->get_by_id((int) $service_id);
     if (!$service->exists()) {
         add_error_flash_message('Služba sa nenašla.');
         redirect(site_ur('services'));
     }
     $service_usages = new Service_usage();
     $service_usages->where_related_service($service);
     $service_usages->include_related('operation', array('id', 'type', 'created'));
     $service_usages->include_related('operation/person', array('name', 'surname'));
     $service_usages->include_related('operation/admin', array('name', 'surname'));
     $service_usages->include_related('operation/workplace', array('title'));
     $service_usages->order_by('created', 'desc');
     $service_usages->order_by_related('operation', 'created', 'desc');
     $service_usages->get_iterated();
     $this->parser->parse('web/controllers/services/overview.tpl', array('title' => 'Administrácia / Služby / Prehľad služby / ' . $service->title, 'service' => $service, 'service_usages' => $service_usages, 'back_url' => site_url('services')));
 }