Create directory structure when creating a project or trial

This commit is contained in:
Karsten Heiken
2011-08-01 16:31:54 +02:00
parent 40406456cb
commit 4ce4e8c9e0
2 changed files with 56 additions and 41 deletions

View File

@@ -70,12 +70,9 @@ class Projects extends CI_Controller {
$this->form_validation->set_rules($config);
if ($this->form_validation->run() == FALSE)
{
if ($this->form_validation->run() == FALSE) {
$this->load->view('project/new');
}
else
{
} else {
// TODO: handle file upload
$data = array(
@@ -85,15 +82,23 @@ class Projects extends CI_Controller {
'defaultconfig' => "todo",
);
$result = $this->project->create($data);
if($result)
redirect('/projects/detail/' . $result, 301);
else {
$data['project_id'] = $this->project->create($data);
if ($data['project_id']) {
$userpath = FCPATH . 'uploads/' . $this->session->userdata('user_id') . '/';
$projectpath = $userpath . $data['project_id'] . '/';
if (!is_dir($projectpath))
if(!is_dir($userpath))
mkdir($userpath, 0777);
mkdir($projectpath, 0777);
chmod($userpath, 0777);
chmod($projectpath, 0777);
$this->messages->add($projectpath, 'notice');
redirect('/projects/detail/' . $data['project_id'], 301);
} else {
$this->messages->add('Das Projekt konnte nicht gespeichert werden.', 'error');
$this->load->view('project/new');
}
}
}
public function index() {
@@ -118,4 +123,5 @@ class Projects extends CI_Controller {
$tpl['jobsDone'] = null;
$this->load->view('project/detail', $tpl);
}
}

View File

@@ -71,14 +71,11 @@ class Trials extends CI_Controller {
$this->form_validation->set_rules($config);
if ($this->form_validation->run() == FALSE)
{
if ($this->form_validation->run() == FALSE) {
$tpl['parameters'] = $parameters;
$tpl['programs'] = $programs;
$this->load->view('trial/new', $tpl);
}
else
{
} else {
// TODO: handle file upload
$data = array(
@@ -89,13 +86,25 @@ class Trials extends CI_Controller {
);
$result = $this->trial->create($data);
if($result)
if ($result) {
$userpath = FCPATH . 'uploads/' . $this->session->userdata('user_id') . '/';
$projectpath = $userpath . $data['project_id'] . '/';
$trialpath = $projectpath . $data['trial_id'] . '/';
if(!is_dir($trialpath))
if (!is_dir($projectpath))
if(!is_dir($userpath))
mkdir($userpath);
mkdir($projectpath);
mkdir($trialpath);
chmod($userpath, 0777);
chmod($projectpath, 0777);
chmod($trialpath, 0777);
redirect('/trial/detail/' . $result, 'refresh');
else {
} else {
$tpl['error'][] = "Der Versuch konnte nicht gespeichert werden.";
$this->load->view('trial/new', $tpl);
}
}
}
}