function get_search_tags($search) { if (!is_null($search) && !empty($search)) { $result = split_tags($search); } else { $result = array(); } return $result; }
public function submit() { if ($this->ion_auth->logged_in()) { $this->load->model('browse_model'); $this->load->helper('browse'); //Pobierz dane zalogowanego użytkownika $user = $this->ion_auth->user()->row(); if (!is_null($this->uri->segment(3))) { $uri_image_id = intval($this->uri->segment(3)); $image = $this->browse_model->get_image($uri_image_id); //#todo // ...można by pokusić się o dokładną informację na temat błedu oraz // przekierowanie na stronę główną... if ($image === FALSE || $user->id !== $image->user_id) { // praca nie wystepuje w bazie lub nie należy do zalogowanego użytkownika... show_404(); } } $this->form_validation->set_rules('title', 'Tytuł', 'required'); $this->form_validation->set_rules('category_id', 'Kategoria', 'required|is_natural_no_zero|callback__category_exist'); $this->form_validation->set_rules('statement', 'Oświadczenie', 'required'); if ($this->form_validation->run() == TRUE) { //Walidacja OK! $user_tags = split_tags(strtolower($this->input->post('tags'))); $tags = split_tags(strtolower($this->input->post('title') . ' ' . $this->input->post('description'))); $user_data = array('user_id' => $user->id, 'title' => $this->input->post('title'), 'category_id' => $this->input->post('category_id'), 'description' => $this->input->post('description'), 'can_comment' => (bool) $this->input->post('allow_comments') ? 1 : 0, 'can_evaluated' => (bool) $this->input->post('allow_evaluated') ? 1 : 0, 'plus_18' => (bool) $this->input->post('mature') ? 1 : 0, 'statement' => 1); if (isset($image)) { $this->db->trans_begin(); $this->db->update('images', $user_data, array('id' => $image->id)); if (!$this->browse_model->associate_tags_object($image->id, 'image', array_unique(array_merge($user_tags, $tags)), $user_tags) || $this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $this->session->set_flashdata(array('type' => 'error', 'msg' => 'Niestety nie udało się zaktualizować danych pracy...')); redirect("profile/submit/{$image->id}", 'refresh'); } else { $this->db->trans_commit(); $this->session->set_flashdata(array('type' => 'info', 'msg' => 'Dane pracy zostały zaktualizowane...')); redirect("profile/submit/{$image->id}", 'refresh'); } } else { // Dodawanie nowej pracy $this->db->trans_begin(); $this->db->insert('images', $user_data); $id = $this->db->insert_id(); $file_name = (string) $id; $upload_config['file_name'] = $file_name; $upload_config['upload_path'] = './' . $this->uploads_path; $upload_config['allowed_types'] = $this->uploads_file_type; $upload_config['max_size'] = $this->uploads_file_max_size; $upload_config['max_filename'] = $this->uploads_file_max_filename; $this->load->library('upload', $upload_config); if (!$this->upload->do_upload('file')) { // Bład przy wczytywaniu pliku... $this->db->trans_rollback(); $this->session->set_flashdata(array('type' => 'error', 'msg' => $this->upload->display_errors('', ''))); redirect('profile/submit/', 'refresh'); } // Pobierz dane wczytanego pliku $uploaded_file_data = $this->upload->data(); // Przygotowanie danych do bazy $image_data = array('file_name' => $uploaded_file_data['file_name'], 'file_type' => $uploaded_file_data['file_type'], 'orig_name' => $uploaded_file_data['orig_name'], 'client_name' => $uploaded_file_data['client_name'], 'file_ext' => $uploaded_file_data['file_ext'], 'file_size' => $uploaded_file_data['file_size'], 'is_image' => $uploaded_file_data['is_image'], 'image_width' => $uploaded_file_data['image_width'], 'image_height' => $uploaded_file_data['image_height'], 'image_type' => $uploaded_file_data['image_type']); // Zapis danych do bazy $this->db->update('images', $image_data, array('id' => $id)); // Generowanie miniatur $this->load->library('image_lib'); // ...miniatura 108x100px if (!$this->generate_thumb($uploaded_file_data['full_path'], $this->thumbs2col_path, $uploaded_file_data['file_name'], $uploaded_file_data['file_type'], $this->browse_thumb_width, $this->browse_thumb_height, $uploaded_file_data['image_width'], $uploaded_file_data['image_height'])) { $this->db->trans_rollback(); unlink($uploaded_file_data['full_path']); //$this->session->set_flashdata(array('type' => 'error', 'msg' => $this->image_lib->display_errors('', '<br />'))); $this->session->set_flashdata(array('type' => 'error', 'msg' => 'Cos z thumbsami')); //$this->thumbs_error)); @todo redirect('profile/submit/', 'refresh'); } // ...miniatura 45x56px if (!$this->generate_thumb($uploaded_file_data['full_path'], $this->thumbs1col_path, $uploaded_file_data['file_name'], $uploaded_file_data['file_type'], $this->mini_thumb_width, $this->mini_thumb_height, $uploaded_file_data['image_width'], $uploaded_file_data['image_height'])) { $this->db->trans_rollback(); unlink($uploaded_file_data['full_path']); unlink($this->thumbs2col_path . $uploaded_file_data['file_name']); $this->session->set_flashdata(array('type' => 'error', 'msg' => $this->image_lib->display_errors('', '<br />'))); redirect('profile/submit/', 'refresh'); } // ...miniatura 675x550px if (!$this->generate_thumb($uploaded_file_data['full_path'], $this->thumbs11col_path, $uploaded_file_data['file_name'], $uploaded_file_data['file_type'], $this->preview_thumb_width, $this->preview_thumb_height, $uploaded_file_data['image_width'], $uploaded_file_data['image_height'])) { $this->db->trans_rollback(); unlink($uploaded_file_data['full_path']); unlink($this->thumbs2col_path . $uploaded_file_data['file_name']); unlink($this->thumbs1col_path . $uploaded_file_data['file_name']); $this->session->set_flashdata(array('type' => 'error', 'msg' => $this->image_lib->display_errors('', '<br />'))); redirect('profile/submit/', 'refresh'); } if (!$this->browse_model->associate_tags_object($id, 'image', array_unique(array_merge($user_tags, $tags)), $user_tags) || $this->db->trans_status() === FALSE) { unlink($uploaded_file_data['full_path']); unlink($this->thumbs1col_path . $uploaded_file_data['file_name']); unlink($this->thumbs2col_path . $uploaded_file_data['file_name']); unlink($this->thumbs11col_path . $uploaded_file_data['file_name']); $this->db->trans_rollback(); $this->session->set_flashdata(array('type' => 'error', 'msg' => 'Niestety nie udało się dodać pracy...')); redirect('profile/submit/', 'refresh'); } else { $this->db->trans_commit(); $this->session->set_flashdata(array('type' => 'info', 'msg' => 'Praca została dodana...')); redirect('profile/submit/', 'refresh'); } } } else { $this->data['message'] = array('type' => $this->session->flashdata('type'), 'msg' => $this->session->flashdata('msg')); $this->data['form_attr'] = array('id' => isset($image) ? 'profile-edit-image' : 'profile-upload-image', 'class' => 'form-horizontal'); $this->data['title'] = array('name' => 'title', 'id' => 'title', 'class' => 'span5', 'type' => 'text', 'value' => $this->form_validation->set_value('title', isset($image) ? $image->title : '')); $this->data['title_label'] = array('for' => 'title', 'text' => 'Tytuł', 'attributes' => array('class' => 'control-label')); $this->data['categories_label'] = array('for' => 'categories', 'text' => 'Kategoria', 'attributes' => array('class' => 'control-label')); if (!$this->input->post('category_id')) { $this->data['category_id'] = array('category_id' => isset($image) ? $image->category_id : ''); } else { if (form_error('category_id')) { $this->data['category_id'] = array('category_id' => ''); } else { $this->data['category_id'] = array('category_id' => $this->form_validation->set_value('category_id')); } } $cat_id = $this->data['category_id']['category_id']; if ($cat_id !== '') { $path = array(); foreach ($this->browse_model->build_path_cats($cat_id, 'images', TRUE) as $level) { $path[] = $level['name_cat']; } $this->data['category_path'] = implode(' > ', $path); } else { $this->data['category_path'] = 'Wybierz kategorię...'; } $this->data['description'] = array('name' => 'description', 'id' => 'description', 'class' => 'span5', 'rows' => '3', 'value' => $this->form_validation->set_value('description', isset($image) ? $image->description : '')); $this->data['description_label'] = array('for' => 'description', 'text' => 'Opis', 'attributes' => array('class' => 'control-label')); $this->data['file'] = array('name' => 'file', 'id' => 'file', 'class' => 'input-file'); $this->data['file_label'] = array('for' => 'file', 'text' => 'Plik', 'attributes' => array('class' => 'control-label')); $this->data['tags'] = array('name' => 'tags', 'id' => 'tags', 'class' => 'span5', 'value' => $this->form_validation->set_value('tags', isset($image) ? $this->get_image_user_tags($image->id, 'image') : '')); $this->data['tags_label'] = array('for' => 'tags', 'text' => 'Słowa kluczowe', 'attributes' => array('class' => 'control-label')); $this->data['allow_comments'] = array('name' => 'allow_comments', 'id' => 'allow_comments', 'class' => 'checkbox', 'value' => '1', 'checked' => (bool) set_checkbox('allow_comments', '1', isset($image) ? (bool) $image->can_comment : '')); $this->data['allow_comm_label'] = array('for' => 'allow_comments', 'text' => 'Komentarze', 'attributes' => array('class' => 'control-label')); $this->data['allow_evaluated'] = array('name' => 'allow_evaluated', 'id' => 'allow_evaluated', 'class' => 'checkbox', 'value' => '1', 'checked' => (bool) set_checkbox('allow_evaluated', '1', isset($image) ? (bool) $image->can_evaluated : '')); $this->data['allow_eval_label'] = array('for' => 'allow_evaluated', 'text' => 'Ocenianie', 'attributes' => array('class' => 'control-label')); $this->data['mature'] = array('name' => 'mature', 'id' => 'mature', 'class' => 'checkbox', 'value' => '1', 'checked' => (bool) set_checkbox('mature', '1', isset($image) ? (bool) $image->plus_18 : '')); $this->data['mature_label'] = array('for' => 'mature', 'text' => '18+', 'attributes' => array('class' => 'control-label')); $this->data['statement'] = array('name' => 'statement', 'id' => 'statement', 'class' => 'checkbox', 'value' => '1', 'checked' => (bool) set_checkbox('statement', '1', isset($image) ? (bool) $image->statement : '')); $this->data['statement_label'] = array('for' => 'statement', 'text' => 'Oświadczenie', 'attributes' => array('class' => 'control-label')); $this->data['control_groups'] = array('title' => form_error('title') ? ' error' : '', 'categories' => form_error('category_id') ? ' error' : '', 'file' => form_error('file') ? ' error' : '', 'statement' => form_error('statement') ? ' error' : ''); if (isset($image)) { $this->data['image'] = $image; } // wybór kategorii i walidacja formularza $this->data['js'][] = 'widget.js'; $this->data['js'][] = 'submit.js'; $this->render(); //$cats_uri_rows = $this->browse_model->get_cats_uri_rows($this->browse_model->build_path_cats($image->category_id)); //$cats_path = $this->browse_model->create_hierarchical_path(base_url() . 'browse/', $cats_uri_rows); } } else { redirect('user/login', 'refresh'); } }
$a_total = $conn->query($a_check); $a_rows = $a_total->num_rows; echo 'attachments_map has ' . $a_rows . ' rows<br/>'; if (empty($a_rows)) { $attach_check = split_attachments(); echo '-- attachments_map updated<br/>'; } else { echo '-- attachments_map NOT updated<br/>'; } // check tags_map $t_check = "SELECT * FROM tags_map"; $t_total = $conn->query($t_check); $t_rows = $t_total->num_rows; echo 'tags_map has ' . $t_rows . ' rows<br/>'; if (empty($t_rows)) { $tags_check = split_tags(); echo '-- tags_map updated<br/>'; } else { echo '-- tags_map NOT updated<br/>'; } // update settings $s_check = "SELECT * FROM settings"; $s_total = $conn->query($s_check); $s_rows = $s_total->num_rows; echo 'settings has ' . $s_rows . ' rows<br/>'; $update_result = $conn->query($update); if (!$update_result) { echo '-- settings not copied over<br />'; } else { echo '-- copying settings over -> success<br/>'; $rename = 'RENAME TABLE ww_config TO ww_migrated_config';