function create() { if ($_POST) { unset($_POST['send']); $_POST['datetime'] = time(); $_POST = array_map('htmlspecialchars', $_POST); $project = Project::create($_POST); $new_project_reference = $_POST['reference'] + 1; $project_reference = Setting::first(); $project_reference->update_attributes(array('project_reference' => $new_project_reference)); if (!$project) { $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_create_project_error')); } else { $this->session->set_flashdata('message', 'success:' . $this->lang->line('messages_create_project_success')); $project_last = Project::last(); $sql = "INSERT INTO `project_has_workers` (`project_id`, `user_id`) VALUES (" . $project_last->id . ", " . $this->user->id . ")"; $query = $this->db->query($sql); } redirect('projects'); } else { $this->view_data['companies'] = Company::find('all', array('conditions' => array('inactive=?', '0'))); $this->view_data['next_reference'] = Project::last(); $this->theme_view = 'modal'; $this->view_data['title'] = $this->lang->line('application_create_project'); $this->view_data['form_action'] = 'projects/create'; $this->content_view = 'projects/_project'; } }
function create() { if ($_POST) { unset($_POST['send']); unset($_POST['files']); $_POST['reference_photo'] = ''; $config['upload_path'] = './files/media/projects/references/'; $config['encrypt_name'] = TRUE; $config['allowed_types'] = '*'; $this->load->library('upload', $config); if ($this->upload->do_upload()) { $data = array('upload_data' => $this->upload->data()); $_POST['reference_photo'] = $data['upload_data']['file_name']; } unset($_POST['userfile']); unset($_POST['dummy']); $_POST['datetime'] = time(); $_POST['company_id'] = $this->client->company->id; $_POST = array_map('htmlspecialchars', $_POST); $_POST['phases'] = $this->projectlib->getProjectPhasesByTypeId($_POST['project_type_id']); $_POST['media_phases'] = $this->projectlib->getProjectPhasesByTypeId($_POST['project_type_id'], 'media'); $project = Project::create($_POST); $new_project_reference = $_POST['reference'] + 1; $project_reference = Setting::first(); $project_reference->update_attributes(array('project_reference' => $new_project_reference)); if (!$project) { $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_create_project_error')); } else { $this->session->set_flashdata('message', 'success:' . $this->lang->line('messages_create_project_success')); //$attributes = array('project_id' => $project->id, 'user_id' => $this->user->id); //ProjectHasWorker::create($attributes); } redirect('cprojects'); } else { $this->view_data['companies'] = Company::find('all', array('conditions' => array('inactive=?', '0'))); $this->view_data['project_types'] = ProjectType::find('all', array('conditions' => array('inactive=?', '0'))); $this->view_data['shipping_methods'] = ShippingMethod::find('all', array('conditions' => array('inactive=?', '0'))); $this->view_data['next_reference'] = Project::last(); $this->theme_view = 'modal'; $this->view_data['title'] = $this->lang->line('application_create_project'); $this->view_data['form_action'] = 'cprojects/create'; $this->content_view = 'projects/_cproject'; } }