Example #1
0
 function copy($id = FALSE)
 {
     if ($_POST) {
         unset($_POST['send']);
         $id = $_POST['id'];
         unset($_POST['id']);
         $_POST['datetime'] = time();
         $_POST = array_map('htmlspecialchars', $_POST);
         unset($_POST['files']);
         if (isset($_POST['tasks'])) {
             unset($_POST['tasks']);
             $tasks = TRUE;
         }
         $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 ($tasks) {
             unset($_POST['tasks']);
             $source_project = Project::find_by_id($id);
             foreach ($source_project->project_has_tasks as $row) {
                 $attributes = array('project_id' => $project->id, 'name' => $row->name, 'user_id' => '', 'status' => 'open', 'public' => $row->public, 'datetime' => $project->start, 'due_date' => $project->end, 'description' => $row->description, 'value' => $row->value, 'priority' => $row->priority);
                 ProjectHasTask::create($attributes);
             }
         }
         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('projects/view/' . $id);
     } else {
         $this->view_data['companies'] = Company::find('all', array('conditions' => array('inactive=?', '0')));
         $this->view_data['project'] = Project::find($id);
         $this->theme_view = 'modal';
         $this->view_data['title'] = $this->lang->line('application_copy_project');
         $this->view_data['form_action'] = 'projects/copy';
         $this->content_view = 'projects/_copy';
     }
 }