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')); }
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); } }
protected function upload_file($id) { $upload_config = array('upload_path' => Questionnaire::PATH_TO_UPLOAD_FOLDER . $id . DIRECTORY_SEPARATOR, 'allowed_types' => 'gif|jpg|png', 'max_size' => '1024', 'max_width' => '1024', 'max_height' => '1024', 'overwrite' => true); $this->load->library('upload', $upload_config); @mkdir($upload_config['upload_path'], DIR_WRITE_MODE, TRUE); if ($this->upload->do_upload('file')) { add_success_flash_message('Súbor sa úspešne podarilo nahrať.'); return true; } else { add_error_flash_message('Súbor sa nepodarilo nahrať, vznikla nasledujúca chyba:' . $this->upload->display_errors('<br /><br />', '')); return false; } }
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')); }
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)); } }
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(); } }
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')); }
public function delete_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->include_related_count('service_usage', 'service_usages_count'); $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')); } if ((int) $service->service_usages_count > 0) { $this->db->trans_rollback(); add_error_flash_message('Nie je možné vymazať službu, ktorá bola už použitá v operáciách s LEDCOIN-om.'); redirect(site_url('services')); } $success_message = 'Služba <strong>' . $service->title . '</strong> s ID <strong>' . $service->id . '</strong> bola úspešne vymazaná.'; $error_message = 'Službu <strong>' . $service->title . '</strong> s ID <strong>' . $service->id . '</strong> sa nepodarilo vymazať.'; if ($service->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('services')); }
public function logout() { auth_remove_authentification(); add_success_flash_message('Odhlásenie úspešné.'); redirect('/'); }