public function add() { if(loggedin() ) { if($this->input->post()) { $this->load->model('Events_model'); $_POST['user_id'] = $_SESSION['id']; $_POST['week'] = $this->Events_model->calculate_week(); if($this->input->post('neweventtype') != "") { $result = $this->Events_model->new_eventtype(); if($result) { $_POST['eventtype_id'] = get_last_inserted_id(); } } unset($_POST['neweventtype']); unset($_POST['addevent']); $this->Events_model->save(); redirect(base_url().'event/listing', 'refresh'); } else { $data['content'] = 'event'; $this->load->model('Events_model'); $data['eventtypes'] = $this->Events_model->get_eventtypes(); $this->load->view('template', $data); } } else { redirect(base_url().'news/', 'refresh'); } }
function save_image($connection) { $file = $_FILES["image"]; $image_id = $_REQUEST['imageId']; $title = $_REQUEST['title']; $section_id = $_REQUEST['sectionId']; $file_path = basename($file["name"]); $connection->begin_transaction(); if ($image_id > 0) { $old_image = get_image($connection, $id); if ($file_path != "" && $old_image != $file_path) { remove_image_file($old_image); do_file_move($file); $update_section_image_stmt = update_section_image_stmt($connection); $update_section_image_stmt->bind_param("ssi", $file_path, $title, $id); catch_execution_error($update_section_image_stmt->execute(), $connection); } else { $update_section_image_stmt = update_section_image_stmt($connection); $update_section_image_stmt->bind_param("ssi", $old_image, $title, $id); catch_execution_error($update_section_image_stmt->execute(), $connection); } print '[["SUCCESS"],["Image saved successfully"]]'; } else { do_file_move($file); $next = get_next_order($connection, "section_to_image"); $insert_section_image_stmt = insert_section_image_stmt($connection); $insert_section_image_stmt->bind_param("iiss", $section_id, $next, $file_path, $title); catch_execution_error($insert_section_image_stmt->execute(), $connection); print "[[\"SUCCESS\"],{\"id\": " . get_last_inserted_id($connection) . ", \"sectionId\": {$section_id}, \"title\": \"{$title}\", \"filePath\": \"{$file_path}\"}]"; } $connection->commit(); }